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_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_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 PopUpCIP() {
    window.open("/resources/def/cip.aspx", "", "scrollbars=yes,location=no,resizable=yes,top=0,left=0,height=525,width=610,toolbar=yes,menubar=yes");
}

function PopUpTERMS() {
    window.open("/resources/def/dictionary.aspx", "", "scrollbars=yes,location=no,resizable=yes,top=0,left=0,height=425,width=610,toolbar=yes,menubar=yes");
}

function PopUpKEY() {
    window.open("/files/ftkey.aspx", "", "scrollbars=yes,location=no,resizable=yes,top=0,left=0,height=200,width=300,toolbar=yes,menubar=yes");
}

function formHandler(form) {
    var windowprops = "height=600,width=800,location=no,"
+ "scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes";

    var URL = form.site.options[form.site.selectedIndex].value;
    popup = window.open(URL, "MenuPopup", windowprops);
}

//	popupAnyUrl - load the contents of a specified URL
//	args:
//		ddlElement - passed in as "this"
//
//	return value: false
//
function popupDropdown(ddlElement) {
    if (ddlElement.value != "") {
        var urlValue = ddlElement.value;
        ddlElement.selectedIndex = 0;
        popupAnyUrl(urlValue);
    }
    return false;
}

//	popupAnyUrl - load the contents of a specified URL
//	args:
//		urlOpen - URL-encoded string
//    xdim - optional x dimension (default: 800)
//    ydim - optional y dimension (default: 600)
//
//	return value: reference to new window
//
function popupAnyUrl(urlOpen, xdim, ydim) {
    if (xdim == null) xdim = 800;
    if (ydim == null) ydim = 600;
    var windowprops = "height=" + ydim + ",width=" + xdim + ",location=no,scrollbars=yes,menubar=yes,toolbar=yes,resizable=yes";
    popup = window.open(convertFromURL(urlOpen), "MenuPopup", windowprops);
    //bring to front of stack if at back
    popup.focus();
    return popup;
}

//	popupMenuUrl - load the contents of a specified URL, from menu link
//	args:
//		urlOpen - URL-encoded string
//
//	return value: nothing, to use in hrefs
//
function popupMenuUrl(urlOpen, xdim, ydim) {
    popupAnyUrl(urlOpen);
}

//	convertToURL - encodes a string in the URL format
//	args:
//		strInput - string to encode
//
//	return value: URL encoded output
//
function convertToURL(strInput) {
    var result = "";
    var strCopyInput = new String(strInput);

    /*for (i = 0; i < strInput.length; i++)
    {
    if (strInput.charAt(i) == " ")
    {
    result += "+";
    } else {
    result += strInput.charAt(i);
    }
    }*/
    result = strCopyInput.replace(" ", "+");
    return (escape(result));
}

//	convertFromURL - decodes a URL string
//	args:
//		strInput - string to decode
//
//	return value: URL decoded output
//
function convertFromURL(strInput) {
    var result = strInput.replace(/\+/g, " ");

    return (unescape(result));
}

// cross-browser function to change the inner content
// of an element
function changeInnerHTML(doc, divId, html) {
    var element = doc.getElementById(divId);
    if (element != null) {
        var tagname = element.tagName.toLowerCase();
        //alert('tag: ' + tagname);
        // If it's a SPAN
        if (tagname == 'span' || tagname == 'div' || tagname == 'a') {
            element.childNodes.item(0).nodeValue = html;
        } else if (tagname == 'input' && element.type == 'text') {
            element.value = html;
        } else {
            alert('unsupported tag: ' + tagname);
        }
    } else {
        alert('element with id ' + divId + ' does not exist');
    }
}

// cross-browser function to get the internal value
// of an element
function getInnerValue(id) {
    var elem = document.getElementById(id);
    if (elem != null) {
        return elem.childNodes.item(0).nodeValue;
    } else {
        return '';
    }
}

function PopupCLG() {
    return popupAnyUrl("/data/defs/Clgcode.aspx", 610, 325);
}

function PopupCIP() {
    return popupAnyUrl("/data/defs/cipcode.aspx", 610, 325);
}

function PopupPROG() {
    return popupAnyUrl("/data/defs/Progname.aspx", 610, 325);
}

function PopupPROGAREA() {
    return popupAnyUrl("/data/defs/ProgArea.aspx", 610, 325);
}

function PopupHANDICAPPED() {
    return popupAnyUrl("/data/defs/handicapped.aspx", 610, 325);
}
function PopupDELYR() {
    return popupAnyUrl("/data/defs/delyr.aspx", 610, 325);
}

function PopupSTATUS() {
    return popupAnyUrl("/data/defs/status.aspx", 610, 325);
}
function PopupDEGLVL() {
    return popupAnyUrl("/data/defs/Deglvl.aspx", 610, 325);
}
function PopupCREDITS() {
    return popupAnyUrl("/data/defs/Credits.aspx", 610, 325);
}
function PopupTUITION() {
    return popupAnyUrl("/data/defs/tuition.aspx", 610, 325);
}
function PopupADD() {
    return popupAnyUrl("/data/defs/Add.aspx", 610, 325);
}
function PopupSBE() {
    return popupAnyUrl("/data/defs/Sbe.aspx", 610, 325);
}
function PopupOCC() {
    return popupAnyUrl("/data/defs/Occ.aspx", 610, 325);
}
function PopupCERT() {
    return popupAnyUrl("/data/defs/Cert.aspx", 610, 325);
}
function PopupPIN() {
    return popupAnyUrl("/data/defs/Pin.aspx", 610, 325);
}
function PopupYRTBE() {
    return popupAnyUrl("/data/defs/yrtbe.aspx", 610, 325);
}
function PopupNONTRAD() {
    return popupAnyUrl("/data/defs/NonTrad.aspx", 610, 325);
}
function PopupDR() {
    return popupAnyUrl("/data/defs/Dr.aspx", 610, 325);
}
function PopupDE() {
    return popupAnyUrl("/data/defs/De.aspx", 610, 325);
}
function PopupALIEN() {
    return popupAnyUrl("/data/defs/alien.aspx", 610, 325);
}
function PopupBNH() {
    return popupAnyUrl("/data/defs/blackaa.aspx", 610, 325);
}
function PopupAIAN() {
    return popupAnyUrl("/data/defs/aian.aspx", 610, 325);
}
function PopupAPI() {
    return popupAnyUrl("/data/defs/api.aspx", 610, 325);
}
function PopupASIAN() {
    return popupAnyUrl("/data/defs/asian.aspx", 610, 325);
}
function PopupHISPANIC() {
    return popupAnyUrl("/data/defs/hispanic.aspx", 610, 325);
}
function PopupWNH() {
    return popupAnyUrl("/data/defs/white.aspx", 610, 325);
}
function PopupUNKNOWN() {
    return popupAnyUrl("/data/defs/unknown.aspx", 610, 325);
}
function PopupHAWAIIANPACIFICISLANDER() {
    return popupAnyUrl("/data/defs/hawaiianpacificislander.aspx", 610, 325);
}
function PopupTWOORMORE() {
    return popupAnyUrl("/data/defs/twoormore.aspx", 610, 325);
}
function PopupHWSD() {
    return popupAnyUrl("/data/defs/HDWSD.aspx", 610, 325);
}
function PopupIWD() {
    return popupAnyUrl("/data/defs/iwd.aspx", 610, 325);
}
function PopupECONOMICALLY() {
    return popupAnyUrl("/data/defs/economically.aspx", 610, 325);
}
function PopupSINGLE() {
    return popupAnyUrl("/data/defs/single.aspx", 610, 325);
}
function PopupDISPLACED() {
    return popupAnyUrl("/data/defs/displaced.aspx", 610, 325);
}
function PopupLEP() {
    return popupAnyUrl("/data/defs/lep.aspx", 610, 325);
}
function PopupEDUCATIONALLY() {
    return popupAnyUrl("/data/defs/educationally.aspx", 610, 325);
}
function PopupHandicapped() {
    return popupAnyUrl("/data/defs/handicapped.aspx", 610, 325);
}
function PopupNONTRAD2() {
    return popupAnyUrl("/data/defs/nontrad2.aspx", 610, 325);
}
function PopupDSS() {
    return popupAnyUrl("/data/defs/dss.aspx", 610, 325);
}
function PopUpEventUL() {
    return popupAnyUrl("/admin/events/uploadfile.aspx", 610, 425);
}

function PopupCIP2() {
    return popupAnyUrl("/data/defs/2digitcipcode.aspx", 610, 325);
}

function PopupCIP4() {
    return popupAnyUrl("/data/defs/4digitcipcode.aspx", 610, 325);
}

function PopupTECPREP() {
    return popupAnyUrl("/data/defs/tecprep.aspx", 610, 325);
}

function PopupMANDATORYFEES() {
    return popupAnyUrl("/data/defs/MandatoryFees.aspx", 610, 325);
}

function PopupCONTACTHOUR() {
    return popupAnyUrl("/data/defs/ContactHour.aspx", 610, 325);
}

function PopupCREDITHOUR() {
    return popupAnyUrl("/data/defs/CreditHour.aspx", 610, 325);
}

function PopupYEAR() {
    return popupAnyUrl("/data/defs/year.aspx", 610, 325);
}
//cteConcentrators

function PopupCTECON() {
    return popupAnyUrl("/data/defs/cteConcentrators.aspx", 610, 325);
}


function ValidateNumeric() {
    var keyCode = window.event.keyCode;
    if (keyCode > 57 || keyCode < 48) {
        alert("Enter Numeric Values Only")
        window.event.returnValue = false;
    }
    else {
        window.event.returnValue = true;
    }
}
//	forceDefaultEnterButtonClick - forces a certain button to be clicked on an enter from a textbox or other form input
//	args:
//		evtKey - event raised from some element
//		idDesiredButton - id of button to raise click() event for
//		
//	return value: true for any button pressed besides enter, false otherwise to stop regular submit
//
function forceDefaultEnterButtonClick(evtKey, idDesiredButton) {
    if (isEventEnterKey(evtKey) == true) {
        document.getElementById(idDesiredButton).click();
        return false;
    }
    else {
        return true;
    }
}

//	isEventEnterKey - checks to see whether an event is an enter key
//	args:
//		evtKey - event raised from some element
//		
//	return value: true for any button pressed besides enter, false otherwise to stop regular submit
//
function isEventEnterKey(evtKey) {
    if (getEventCharacterCode(evtKey) == 13) {
        return true;
    } else {
        return false;
    }
}

//	getEventCharacterCode - checks to see whether an event is an enter key
//	args:
//		evtKey - event raised from some element
//		
//	return value: whatever the character code entered is
//
function getEventCharacterCode(evtKey) {
    if (evtKey && evtKey.which) {
        evtKey = evtKey;
        //character code is contained in NN4's which property
        return evtKey.which;
    } else {
        if (event) {
            evtKey = event;
            //character code is contained in IE's keyCode property
            return evtKey.keyCode;
        } else {
            return -1;
        }
    }
}

/*
This method is used in the 2P1 screen
It takes any number of arguments
It sums the arguments values and returns the result in the last argument
*/
function caclulateSum() {
    var i = 0;
    document.getElementById(arguments[arguments.length - 1]).value = 0 * 1;
    for (i = 0; i < arguments.length - 1; i++) {
        document.getElementById(arguments[arguments.length - 1]).value = document.getElementById(arguments[arguments.length - 1]).value * 1 + document.getElementById(arguments[i]).value * 1;
    }
}
/*
This method is used in the 1P1 screen
It takes four arguments
The last argument value = second argument / first argument 
Check for division by Zero
Fire the onchange of the third argument manually cause it is disabled
The onchange of the third argument calls the calculatesum method of the column it lies in
*/

function calculate1P1_LOP() {
    //SM - the logic for calculating 1P1 Level of Performance = PA / TA
    //Order of arguments coming in: (TA, PA, LOP)
    if (document.getElementById(arguments[0]).value * 1 != 0) {
        document.getElementById(arguments[2]).value =
            ((document.getElementById(arguments[1]).value /
                (document.getElementById(arguments[0]).value * 1)) * 100).toFixed(2);

        //document.getElementById(arguments[3]).onchange();     
    }
    else document.getElementById(arguments[2]).value = 0;
    //alert ('Division by Zero');        
}


/*
This method is used in the 2P1 screen
It takes four arguments
The last argument value = first argument / (second argument + third argument)
Check for division by Zero
Fire the onchange of the third argument manually cause it is disabled
The onchange of the third argument calls the calculatesum method of the column it lies in
*/

function caclulateLOP() {
    //SM - the logic for calculating 2P1 Level of Performance = RIRCCD / (LPEWA + LPEWOA)
    //Order of arguments coming in: (RIRCCD, LPEWA, LPEWOA, LOP)
    // 07-25-08 formula changed 
    //SM - the logic for calculating NEW 2P1 Level of Performance = LPEWA / RIRCCD
    //Order of arguments coming in: (RIRCCD, LPEWA, LPEWOA, LOP)
    if (document.getElementById(arguments[0]).value * 1 != 0) {
        document.getElementById(arguments[3]).value =
            ((document.getElementById(arguments[1]).value /
                (document.getElementById(arguments[0]).value * 1)) * 100).toFixed(2);

        //document.getElementById(arguments[3]).onchange();     
    }
    else document.getElementById(arguments[3]).value = 0;
    //alert ('Division by Zero');        
}

/*
This method is used in the 3P1 screen
It takes five arguments
The last(fifth) argument value = (second argument + third argument)/ fourth argument
Check for division by Zero
Fire the onchange of the third argument manually cause it is disabled
The onchange of the third argument calls the calculatesum method of the column it lies in
*/

function calcThreePOneLOP() {
    //SM - the logic for calculating 3P1 Level of Performance = (RE + TRN) / NRIRCCD
    //Order of arguments coming in: (EPF, RE, TRN, NRIRCCD, LOP)
    // 07-25-08 formula changed 
    //SM - the logic for calculating NEW 3P1 Level of Performance = (RE + TRN) / EPF
    //Order of arguments coming in: (EPF, RE, TRN, NRIRCCD, LOP)
    if (document.getElementById(arguments[0]).value * 1 != 0) {
        document.getElementById(arguments[4]).value =
            (((document.getElementById(arguments[1]).value * 1 + document.getElementById(arguments[2]).value * 1) /
                (document.getElementById(arguments[0]).value * 1)) * 100).toFixed(2);

        //document.getElementById(arguments[4]).onchange();     
    }
    else document.getElementById(arguments[4]).value = 0;
    //alert ('Division by Zero');
}

/*
This method is used in the 4P1 screen
It takes five arguments
The last(fifth) argument value = (second argument + third argument + fourth argument)/ first argument
Check for division by Zero
Fire the onchange of the third argument manually cause it is disabled
The onchange of the third argument calls the calculatesum method of the column it lies in
*/

function calcFourPOneLOP() {
    //SM - the logic for calculating 4P1 Level of Performance = (EMP + MIL + APPSHIP) / LEP
    //Order of arguments coming in: (LEP, EMP, MIL, APPSHIP, NRESP, LOP)

    //for (i=0; i<arguments.length;i++) alert (arguments[i] + '-' + document.getElementById(arguments[i] ).value);

    if (document.getElementById(arguments[0]).value * 1 - document.getElementById(arguments[4]).value * 1 > 0) {
        document.getElementById(arguments[5]).value =
            (((document.getElementById(arguments[1]).value * 1 + document.getElementById(arguments[2]).value * 1 + document.getElementById(arguments[3]).value * 1) /
                (document.getElementById(arguments[0]).value * 1 - document.getElementById(arguments[4]).value * 1)) * 100).toFixed(2);

        //document.getElementById(arguments[4]).onchange();     
    }
    else document.getElementById(arguments[5]).value = 0;
    //alert ('Division by Zero');
}

/*
This method takes a control client id
it will loop on the controls and fire the "onchange" event for each one
*/

function fireOnChange(clientId) {
    document.getElementById(clientId).onchange();
}

//	formatClean - takes commas and other junk out of a string and returns it
//	args:
//		stringInput - string value containing number, zero or more commas
//
//	return value: stripped string
//
function formatClean(num) {
    var sVal = '';
    var nVal = num.length;
    var sChar = '';
    var minus = '-';

    //iterate through each character in the string, allowing only numbers and the period character into the result
    for (i = 0; i < nVal; i++) {
        sChar = num.charAt(i);
        nChar = sChar.charCodeAt(0);
        //if((nChar==48){}
        if ((nChar >= 48) && (nChar <= 57)) { sVal += num.charAt(i); }
        if (sChar == '.') { sVal += sChar; }
    }
    var newsVal = sVal;
    if (Number(sVal) != 0) {
        for (i = 0; i < sVal.length; i++) {
            sChar = sVal.charAt(i);
            nChar = sChar.charCodeAt(0);
            if (nChar != 48) {
                break;
            }
            else {
                newsVal = sVal.substring(i + 1, sVal.length);
            }
        }
        sVal = newsVal;
    }

    //deal with empty string (bad input)
    if (sVal == '') { sVal = '0'; }
    //add leading zero
    if (sVal.indexOf('.') == 0) { sVal = '0' + sVal; }
    //deal with minus character
    if (num.indexOf(minus) == 0) { sVal = minus + sVal; }
    //alert("result of formatClean function: " + sVal);
    return sVal;
}

//	cleanNumber - uses formatClean, then returns as a number instead of a string
//	args:
//		stringInput - string value containing number
//
//	return value: numeric representation for use in calculations
//
function cleanNumber(stringInput) {
    return (Number(formatClean(stringInput)));
}

//	formatNumber - puts proper commas into numeric data
//	args:
//		num - guess
//		numFixedPrecision - how many digits to also display
//
//	return value: formatted string representation of number
//
function formatNumber(num, numFixedPrecision) {
    var sVal = '';
    var minus = '-';
    var CommaDelimiter = ',';
    var intVersion = 0;
    var numVersion = 0;
    var stringNum;

    intVersion = Math.abs(parseInt(num));
    if (numFixedPrecision == null) {
        numVersion = Math.abs(Number(num));
    } else {
        numVersion = Math.abs(Number(num)).toFixed(numFixedPrecision);
    }
    stringNum = new String(numVersion);

    var samount = new String(intVersion);
    for (var i = 0; i < Math.floor((samount.length - (1 + i)) / 3); i++) {
        samount = samount.substring(0, samount.length - (4 * i + 3)) + CommaDelimiter + samount.substring(samount.length - (4 * i + 3));
    }
    if (stringNum.indexOf('.') > 0) {
        samount = samount + stringNum.substring(stringNum.indexOf('.'));
    }
    if (Number(num) < 0) {
        samount = minus + samount;
    }
    return (samount);
}

//	autoCleanInput - uses formatNumber and cleanNumber to prettify input in a text box
//	args:
//		inputElement - element with a value that can be cleaned
//		numFixedPrecision - optional number of digits after decimal point to show
//
//	return value: none
//
function autoCleanInput(inputElement, numFixedPrecision) {
    if (numFixedPrecision == null) numFixedPrecision = 0;
    var intermediateValue = inputElement.value;
    inputElement.value = formatNumber(cleanNumber(intermediateValue), numFixedPrecision).replace(',','');
    return;
}