function HideShowClick(tagId)
{
    var e = document.getElementById(tagId);
    
    if (e.style.display == 'block')
        e.style.display = 'none';
    else
        e.style.display = 'block';
}

function CenterNewPopupWindow(myPage,myName,w,h,features) 
{
	if(screen.width)
	{
		var winl = (screen.width-w)/2;
		var wint = (screen.height-h)/2;
	}
	else
	{
		winl = 0;wint = 0;
	}

	if (winl < 0) winl = 0;
	if (wint < 0) wint = 0;
				
	var windowSettings = 'height=' + h + ',';
	    windowSettings += 'width=' + w + ',';
	    windowSettings += 'top=' + wint + ',';
	    windowSettings += 'left=' + winl + ',';
	    windowSettings += features;
	
	win = window.open(myPage,myName,windowSettings);
	
	win.window.focus()
}		

function ClearForm()
{
    var form = document.getElementById("aspnetForm");
    
    for(x = 0; x < form.elements.length; x++)
    {
        switch(form.elements[x].type)
        {
            case "text":
                form.elements[x].value = "";
                break;
            case "textarea":
                form.elements[x].value = "";
                break;
            case "select-one":
                form.elements[x].selectedIndex = -1;
                break;
            case "select-multiple":
                form.elements[x].selectedIndex = -1;
                break;
            case "radio":
                form.elements[x].checked = false;
                break;
        }
    }
}

function ShowProgressPopup(type)
{
    var popup = $find("ctl00_uxUpdateProgress1_uxPopupMdl");
    var lbl = eval(document.getElementById("ctl00_uxUpdateProgress1_uxMessageLbl"));
    
    switch (type)
    {
        case "save":
            lbl.innerHTML = "Saving Data";
            break;
        case "delete":
            lbl.innerHTML = "Deleting Data";
            break;
        case "retrieve":
            lbl.innerHTML = "Retrieving Data";
            break;
        case "wait":
            lbl.innerHTML = "Please wait";
        case "add":
            lbl.innerHTML = "Adding Data";
    }
    
    popup.show();
}

function ShowPopup()
{
    var popup = $find("ctl00_uxUpdateProgress1_uxPopupMdl");
    
    popup.show();
}

function HidePopup()
{
    var popup = $find("ctl00_uxUpdateProgress1_uxPopupMdl");
    
    popup.hide();
}

function ConfirmDeleteWithAJAX() {
    if (confirm("This entry will be deleted.  Are you sure?")) {
        ShowProgressPopup('delete');
        return true;
    }
    else {
        return false;
    }
}

function ConfirmUnDeleteWithAJAX() {
    if (confirm("This entry will be undeleted.  Are you sure?")) {
        ShowProgressPopup('undelete');
        return true;
    }
    else {
        return false;
    }
}

function SetDebtServiceScheduleTotal(gridViewName, targetLabelName, targetTotalType, columnNumber) {
    //Used on all Debt Management pages that have a Debt Service Schedule
    var table = document.getElementById(gridViewName);
    var cell;
    var parField;
    var total = 0;
    var lblString;

    for (x = 1; x < table.rows.length; x++) {
        cell = table.rows[x].cells[columnNumber];

        for (y = 0; y < cell.childNodes.length; y++) {
            if (cell.childNodes[y].type == "text") {
                parField = cell.childNodes[y];
                break;
            }
        }

        if (parField != null) {
            if (parField.value.length > 0) {
                total += parseFloat(parField.value.replace("$", "").replace(",", "").replace(",", "").replace(",", ""));
            }
        }
    }

    switch (targetTotalType) {
        case "ParValue":
            lblString = "Total Principal Amount:";
            break;
        case "Interest":
            lblString = "Total Interest Amount:";
            break;
        case "Total":
            lblString = "Total Amount:";
    }

    var formattedTotal = FormatCurrencyReturnValue(total);
    
    if (formattedTotal == "")
    {
        formattedTotal = "$0.00";
    }

    document.getElementById(targetLabelName).innerHTML = lblString + " " + formattedTotal;
}