function MM_preloadImages() 
{ //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) 
{ //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImgRestore() 
{ //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() 
{ //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function autofocus(original, mxlen, destination)
{
    if(original.value.length == mxlen)
    {
        destination.focus();
    }
}

function OpenHelp(helpId)
{
    newWindow=window.open(RootPath + "/HelpFiles/DialogHelp.aspx?tid=" + helpId , "help", "scrollbars,height=250,width=300");
}
    
    
function CFRedirect(url)
{
    window.location=ColdFusionPath + url;
}

function CFRedirectNewWindow(url)
{
    window.open(ColdFusionPath + url);
}

// PROPERLY FORMAT A NUMBER STRING FOR DISPLAY
function formatCommas (Val)  {
	OutString="";
	len=Val.length;
	if (len>=3) {
		while (len>0) {
			TempString=Val.substring(len-3, len)
			if (TempString.length==3) {
				OutString=","+TempString+OutString
				len=len-3;
			} else {
				OutString=TempString+OutString
				len=0
			}
		}
		if (OutString.substring(0, 1)==",") 
			Val=OutString.substring (1, OutString.length)
		else
			Val=OutString
	} 
	return (Val);
}

//as - added to format a comma into numerics. This checks to make sure a comma doesn't already exist
// which the function above does not.
function Comma(number) {
    number = '' + number;
    if ((number.length > 3) && (number.indexOf(',') == -1)) {
        var mod = number.length % 3;
        var output = (mod > 0 ? (number.substring(0,mod)) : '');
        for (i=0 ; i < Math.floor(number.length / 3); i++) {
            if ((mod == 0) && (i == 0))
                output += number.substring(mod+ 3 * i, mod + 3 * i + 3);
                else
                output+= ',' + number.substring(mod + 3 * i, mod + 3 * i + 3);
        }
        return (output);
    }
    else return number;
}

function FocusOnEnter(ControlToFocus) {
    if(event.keyCode == 13) 
    {
        $(ControlToFocus).focus();
    }
}

function ClickOnEnter(ControlToClick) {
    if(event.keyCode == 13) 
    {
        $(ControlToClick).focus();
        $(ControlToClick).click();
    }
}

function showWaitingMessage() {
    elt = $('waitingMessage');
    if (elt) {
        elt.style.display = "block";
        elt.focus();
    }
}

function backgroundImageCacheOFF()
{
    try {
      document.execCommand("BackgroundImageCache", false, true);
    } catch(err) {}
}

function addOptionToSelect(selectId, text, value) {
    var eltOption = document.createElement('option');
      eltOption.text = text;
      eltOption.value = value;
      var eltSelect = $(selectId);

      try {
        eltSelect.add(eltOption, null); // standards compliant; doesn't work in IE
      }
      catch(ex) {
        eltSelect.add(eltOption); // IE only
      }
}

function enableOnSelected(selectId, ControlToEnable1, ControlToEnable2) {
    var eltSelect = $(selectId);
    //alert(eltSelect.selectedIndex);
    if (eltSelect.selectedIndex > -1)
    {
        $(ControlToEnable1).disabled = false;
        $(ControlToEnable2).disabled = false;
    } 
}

 
 function DisableCertificationControlScript(chkNoCertify, txtUnSubsidizedLoanAmt, txtSubsidizedLoanAmt, 
        txtSchoolUse2, txtSchoolUse1, txtDisbAmount4, txtDisbAmount3, txtDisbAmount2, txtDisbAmount1,
        txtCertifiedLoanAmt, ddlSerialLoanCode, lnkHoldRelease1, lnkHoldRelease2, lnkHoldRelease3, lnkHoldRelease4, 
        disbursements1Date, disbursements2Date, disbursements3Date, disbursements4Date,
        disbCalendar1, disbCalendar2, disbCalendar3, disbCalendar4, ddlGradeLevel)
 {
    var disable = $F(chkNoCertify);
    EnableDisableControl(txtUnSubsidizedLoanAmt, disable);
    EnableDisableControl(txtSubsidizedLoanAmt, disable);
    EnableDisableControl(txtSchoolUse2, disable);
    EnableDisableControl(txtSchoolUse1, disable);
    EnableDisableControl(txtDisbAmount4, disable);
    EnableDisableControl(txtDisbAmount3, disable);
    EnableDisableControl(txtDisbAmount2, disable);
    EnableDisableControl(txtDisbAmount1, disable);
    EnableDisableControl(txtCertifiedLoanAmt, disable);
    EnableDisableControl(ddlSerialLoanCode, disable);
    EnableDisableControl(lnkHoldRelease1, disable);
    EnableDisableControl(lnkHoldRelease2, disable);
    EnableDisableControl(lnkHoldRelease3, disable);
    EnableDisableControl(lnkHoldRelease4, disable);
    EnableDisableControl(disbursements1Date, disable);
    EnableDisableControl(disbursements2Date, disable);
    EnableDisableControl(disbursements3Date, disable);
    EnableDisableControl(disbursements4Date, disable);
    EnableDisableControl(disbCalendar1, disable);
    EnableDisableControl(disbCalendar2, disable);
    EnableDisableControl(disbCalendar3, disable);
    EnableDisableControl(disbCalendar4, disable);
    EnableDisableControl(ddlGradeLevel, disable);
 }
 
 function EnableDisableControl(controlId, disable)
 {
    var cntrl = $(controlId);
    if(cntrl != null)
    {
        cntrl.disabled = disable;
    }
 }
 
 function HoldReleaseValue(lnkClicked, lnkOther, hfField, hfValue, otherValue)
 {
    $(lnkClicked).removeAttribute("href");   
    $(lnkOther).href="javascript:HoldReleaseValue('" + lnkOther + "', '" + lnkClicked + "', '" + hfField + "', '" + otherValue + "', '" + hfValue+ "')";
    $(hfField).value=hfValue;
  }
  
var reportWindow;

 function openReportWindow(linkParams)
 {
    href = "dashboardReport.aspx?" + linkParams;
    document.body.style.cursor = 'wait';
    my_window = window.open(href, "reportWindow", "resizable=1,width=25,height=25");
    reportWindow = my_window;
 	Event.observe(my_window, 'load', closeReportWindow, false);
    document.body.style.cursor = 'default';
 }
 
	
function closeReportWindow(evt)
{
	//alert('in the close report window method');
	//reportWindow.close();
}

function OpenWindow(url, title, attributes)
{
    newWindow=window.open(RootPath + url, title, attributes);
}

function include(script_filename) {
    document.write('<' + 'script');
    document.write(' language="javascript"');
    document.write(' type="text/javascript"');
    document.write(' src="' + script_filename + '">');
    document.write('</' + 'script' + '>');
}

function getQueryStringVariable(variable) { 
    var query = window.location.search.substring(1); 
    var vars = query.split("&"); 
    for (var i=0;i<vars.length;i++) { 
        var pair = vars[i].split("="); 
        if (pair[0] == variable) { 
            return pair[1]; 
        }
    }
} 

/**
 * Sets a Cookie with the given name and value.
 *
 * name       Name of the cookie
 * value      Value of the cookie
 * [expires]  Expiration date of the cookie (default: end of current session)
 * [path]     Path where the cookie is valid (default: path of calling document)
 * [domain]   Domain where the cookie is valid
 *              (default: domain of calling document)
 * [secure]   Boolean value indicating if the cookie transmission requires a
 *              secure transmission
 */
function setCookie(name, value, expires, path, domain, secure) {
    document.cookie= name + "=" + escape(value) +
        ((expires) ? "; expires=" + expires.toGMTString() : "") +
        ((path) ? "; path=" + path : "") +
        ((domain) ? "; domain=" + domain : "") +
        ((secure) ? "; secure" : "");
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */
function getCookie(name) {
    var dc = document.cookie;
    var prefix = name + "=";
    var begin = dc.indexOf("; " + prefix);
    if (begin == -1) {
        begin = dc.indexOf(prefix);
        if (begin != 0) return null;
    } else {
        begin += 2;
    }
    var end = document.cookie.indexOf(";", begin);
    if (end == -1) {
        end = dc.length;
    }
    return unescape(dc.substring(begin + prefix.length, end));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
function deleteCookie(name, path, domain) {
    if (getCookie(name)) {
        document.cookie = name + "=" +
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}

/* Global function to show the Campus door
 * popup window for transfering the user
 * to the Campus Door, Inc. website
 */
 //mhay  - 5/30/2008 - modified to force server hit and bypass browser cache
function showCampusDoorPopup () {
	var url = "/AppSecure/Common/CampusDoorRedirect.aspx?popup=1" + "&ts=" + generateUniqueID();
	Modalbox.show(url,{title: '', width: 500, overlayClose: false}); 
}

/* Global function to show the Campus door
 * page for transfering the user
 * to the Campus Door, Inc. website
 */
 //mhay  - 5/30/2008 - modified to force server hit and bypass browser cache
function showCampusDoorPage () {

	var url = "/AppSecure/Common/CampusDoorRedirect.aspx" + "?ts=" + generateUniqueID();
	window.location.href = url;
}

/* Function to return a unique ID 
 * Handy to force a URL to override Browser Cache
 */
 function generateUniqueID()
{
var result, i, j;
result = '';
for(j=0; j<10; j++)
{
i = Math.floor(Math.random()*16).toString(16).toUpperCase();
result = result + i;
}
return result
}

// EXTENDEDREPAY - KHB - 8/1/2008 - Defect 8032
// Added here so the file loads early enough in the process
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

