//-------------------------------------------------------------------------------------
// Contains JavaScript specific to the Request Information "form".
//-------------------------------------------------------------------------------------

//-------------------------------------------------------------------------------------
// Attach events.
//-------------------------------------------------------------------------------------
window.onload = InitPage;
window.onbeforeprint = ShowPrintWarning;

//-------------------------------------------------------------------------------------
// Module level variables.
//-------------------------------------------------------------------------------------
var moMain = top.frames;
//var moThisDialog = parent.document.getElementById("ReqInfoFrame");	

var msCurrentPanel = "0";

var mbSaveUsingProxy = false;
var mbSavePending = false;
var mbInfoSaved = false;
var mbSaving = false;
var mbSavingApp = false;
var mbLoading = false;
var mbSaveAndClear = false;
var mbSettingFieldValues = false;

var msFldDelim = "::";
var msRecDelim = ":|:";

var mbEventHandlersAttached = false; //Ensures event handlers are not attached multiple times.

var moXHR = "";
var msXHRResponseFormat = "Text";

var mbTeachProgram = false;         //True if visitor selected the TEACH or PACT program.
var mbSavedApp = false;             //True if visitor is returning to complete the application.

//-------------------------------------------------------------------------------------
// Automatically enable or disable tabbing for specific UI elements/objects based on the
// order they appear in the ASP file in conjunction with the elements CSS class name. 
//
// Note: This function assumes a fairly basic top-to-bottom page layout using the CSS
// rules identified in the UIFields stylesheet. Furthermore, this function relies on the 
// page elements to be rendered in the same order in which they appear in the ASP file.
// In some cases the browser may not render the items in the same order in which the 
// elements occur in the ASP file. As a result, you may need to bypass use of this 
// function and assign tab indexes explicitly.
//-------------------------------------------------------------------------------------
function AssignTabIndexes() {

    var iTab = 0;
    //var oFields = document.all;
    var oFields = document.getElementsByTagName("*");

    for (var i=0; i<oFields.length; i++) {
        sClass = oFields[i].className;
        if (sClass == "FieldValReadOnly") continue;
        if (sClass.substr(0,8) == "FieldVal" || 
            sClass == "FieldAction" || 
            sClass == "ActionLink") 
        {
            iTab++;
            oFields[i].tabIndex = iTab;
        }    
    }

}

//-------------------------------------------------------------------------------------
// Attach event handlers to specific elements/objects. NOTE: Where possible, the 
// older, more compatible method is used for binding an object to an event handler, 
// rather than using the "attachEvent" method, which is IE specific, or the newer W3C
// "addEventListener" method, which is not yet supported by all browsers.
//-------------------------------------------------------------------------------------
function AttachEventHandlers() {

    //If the event handlers have already been attached, get outta here.
    if (mbEventHandlersAttached) return;

    mbEventHandlersAttached = true;
    
    //Set-up input field highlighting and SAVE PENDING trigger.
    var aTags = new Array("INPUT", "SELECT", "TEXTAREA", "DIV");
    for (var t=0; t<aTags.length; t++) {
        var oFields = document.getElementsByTagName(aTags[t]);
        for (var i=0; i<oFields.length; i++) {
            var oField = oFields[i];
            if (oField.className.substr(0,8) == "FieldVal") {
                if (oField.type == "select-one") {
                    //alert("SetSave set for SELECT onchange on: " + oField.id);
                    //oField.attachEvent("onchange", SetSave);
                    //oField.attachEvent("onfocus", SetInputFieldHilite);
                    //oField.attachEvent("onblur", SetInputFieldHilite);
                    AddEvt(oField, "change", SetSave);
                    AddEvt(oField, "focus", SetInputFieldHilite);
                    AddEvt(oField, "blur", SetInputFieldHilite);
                    //NOTE: Next line prevents inadvertant scrolling by the user. Use caution 
                    //when enabling this functionality since it will disrupt normal tabbing 
                    //sequence.
                    //oField.attachEvent("onchange", RemoveElementFocus);
                }
                else if ((oField.type == "text") || (oField.type == "textarea")) {
                    //alert("SetSave set for TEXTAREA or INPUT onkeydown on: " + oField.id);
                    //oField.attachEvent("onkeydown", SetSave);
                    //oField.attachEvent("onfocus", SetInputFieldHilite);
                    //oField.attachEvent("onblur",  SetInputFieldHilite);
                    AddEvt(oField, "keydown", SetSave);
                    AddEvt(oField, "focus", SetInputFieldHilite);
                    AddEvt(oField, "blur", SetInputFieldHilite);
                    //if (oField.getAttribute("maxlength")) oField.onkeydown = UserInputCheckLength;
                    if (oField.getAttribute("maxlength")) AddEvt(oField, "keydown", UserInputCheckLength);
                    //Check for numeric, date, or money input formats.
                    if (oField.className == "FieldValNumeric") {
                        //oField.attachEvent("onkeypress", KeyNumericOnly);
                        AddEvt(oField, "keypress", KeyNumericOnly);
                    }
                    else if (oField.className == "FieldValDate") {
                        //oField.attachEvent("onkeypress", KeyDateOnly);
                        AddEvt(oField, "keypress", KeyDateOnly);
                    }
                    else if (oField.className == "FieldValMoney") {
                        //oField.attachEvent("onkeypress", KeyMoneyOnly);
                        AddEvt(oField, "keypress", KeyMoneyOnly);
                    }
                }
                else if (oField.type == "checkbox") {
                   // alert("SetSave set for checkbox onclick on: " + oField.id);
                    //oField.attachEvent("onclick", SetSave);
                    AddEvt(oField, "click", SetSave);
                }
                else if (oField.tagName == "DIV") { //Div containers
                    //oField.attachEvent("onfocus", SetInputFieldHilite);
                    //oField.attachEvent("onblur",  SetInputFieldHilite);
                    AddEvt(oField, "focus", SetInputFieldHilite);
                    AddEvt(oField, "blur", SetInputFieldHilite);
                    oField.hideFocus = true;
                }
                else {
                    alert("Unable to set event handlers on input field type: " + oField.type);
                }
            }
        }
    }
 
    //General housekeeping event handlers.
    //document.body.onselectstart = CancelEvent; 
    //document.body.onclick = CancelEvent; 
    //document.body.oncontextmenu = CancelEvent;    
    
    AddEvt($("ActionSubmit"),	"click",	 SaveInfo); 
    AddEvt($("ActionSubmit"),	"mouseover", SetFieldActionHilite); 
    AddEvt($("ActionSubmit"),	"mouseout",  SetFieldActionHilite); 
    
    AddEvt($("ActionCancel"),	"click",	 CancelApp); 
    AddEvt($("ActionCancel"),	"mouseover", SetFieldActionHilite); 
    AddEvt($("ActionCancel"),	"mouseout",  SetFieldActionHilite);

    AddEvt($("ActionSave"), "click",        SaveAppInit);
    //AddEvt($("ActionSave"), "mouseover",    SetFieldActionHilite);
    //AddEvt($("ActionSave"), "mouseout",     SetFieldActionHilite);

    AddEvt($("PrefPgm"), "change", SetChangeToProgram);

    AddEvt($("ActionTeachInit"), "click",       InitTeach);
    AddEvt($("ActionTeachInit"), "mouseover",   SetFieldActionHilite);
    AddEvt($("ActionTeachInit"), "mouseout",    SetFieldActionHilite);

    AddEvt($("ActionTeachClose"), "click",      CancelTeach);
    AddEvt($("ActionTeachClose"), "mouseover",  SetFieldActionHilite);
    AddEvt($("ActionTeachClose"), "mouseout",   SetFieldActionHilite);

    AddEvt($("ActionSaveOK"), "click",          SaveApp);
    AddEvt($("ActionSaveOK"), "mouseover",      SetFieldActionHilite);
    AddEvt($("ActionSaveOK"), "mouseout",       SetFieldActionHilite);

    AddEvt($("ActionSaveClose"), "click",       SaveAppCancel);
    AddEvt($("ActionSaveClose"), "mouseover",   SetFieldActionHilite);
    AddEvt($("ActionSaveClose"), "mouseout",    SetFieldActionHilite);

    AddEvt($("ActionBack"), "click", ShowPanelPrev);
//    AddEvt($("ActionTeachClose"), "mouseover", SetFieldActionHilite);
//    AddEvt($("ActionTeachClose"), "mouseout", SetFieldActionHilite);
    //
    AddEvt($("ActionNext"), "click", ShowPanelNext);

    AddEvt($("ConductAccept"),  "click", SetChangeToConductAnswer);
    AddEvt($("ConductDecline"), "click", SetChangeToConductAnswer);
}

//-------------------------------------------------------------------------------------
// Attach event handlers to action links/spots.
//-------------------------------------------------------------------------------------
function AttachActionLinkEventHandlers(sID, oAction) {
        
    var oHilite = ($(sID).className == "FieldAction") ? SetFieldActionHilite : SetActionHilite;

    with ($(sID)) {
        onmouseover = oHilite;
        onmouseout  = oHilite;
        onfocus     = oHilite;
        onblur      = oHilite;
        onclick     = oAction;
        onkeydown   = oAction;
        hideFocus   = true;
    }
}
    	
//-------------------------------------------------------------------------------------
// Builds a single fieldname-value pair for a single field.
//-------------------------------------------------------------------------------------
function BuildFieldValItem(sName, sVal) {

	return sName + "=" + sVal + "\n";

}

//-------------------------------------------------------------------------------------
// Build fieldname-value pair string for all fields in the "theForm" form.
//-------------------------------------------------------------------------------------
function BuildFieldValString() {

    var sStr = "";
    var sVal = "";

    var oForm = $("theForm");

    for (var i = 0; i < oForm.length; i++) {
        var oField = oForm[i];
        if (oField.type == "checkbox") {
            sVal = (oField.checked) ? "1" : "0";
            sStr += oField.id + "=" + sVal + "|";
        }
        else {
            sStr += oField.id + "=" + oField.value + "|";
        }
    }

    return sStr;

}


//-------------------------------------------------------------------------------------
// Build email body.
//-------------------------------------------------------------------------------------
function BuildEmailBody() {

	var sVal;
	var bIsBold = true;
	var bIsNotBold = false;
	var bIsLink = true;
	var bIsNotLink = false;
	var bSkipLine = true;
	var bNextLine = false;
	
	//var sReturning = ($("Returning").checked == true) ? "Yes" : "No";
	
	var sHTML = "";
	msDataOnly = "";
	
	//Do Not Reply message.
	sHTML += BuildEmailLine("-- Do Not Reply To This Email --", "Alert", bIsBold, bNextLine);

    sHTML += BuildEmailLine("Selected Program : ", GetSelectText($("PrefPgm")), bIsNotBold, bSkipLine);

	sHTML += BuildEmailLine("Returning Student: ", GetSelectText($("Returning")), bIsNotBold, bSkipLine);
    
    sHTML += BuildEmailLine("First Name  :",	$("FirstName").value, bIsNotBold, bSkipLine); 
    sHTML += BuildEmailLine("Pref Name   :",	$("PrefName").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Middle Name : ",	$("MidName").value, bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Last Name   : ",	$("LastName").value, bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Maiden Name : ",	$("MaidName").value, bIsNotBold, bNextLine); 
     
	sHTML += BuildEmailLine("Home Phone  :",	$("PhoneHome").value, bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("Work Phone  :",	$("PhoneWork").value, bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Email Addr  :",	$("EmailAddr").value, bIsNotBold, bNextLine); 
     
	sHTML += BuildEmailLine("Address     :",	$("Addr1").value, bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City        :",	$("City").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State       :",	$("State").value, bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Zip         :",	$("Zip").value, bIsNotBold, bNextLine);

	sHTML += BuildEmailLine("Gender      :",	GetSelectText($("Gender")), bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("Birth Date  :",	$("Birth").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Marital     :",	GetSelectText($("Marital")), bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Ethnic      :",	GetSelectText($("Ethnic")), bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Denomination:",	GetSelectText($("Denom")), bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Veteran	 :",	$("Veteran").value, bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Branch      :",	$("Branch").value, bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Discharged  :",	$("Discharge").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("US Citizen? :",    GetSelectText($("QCitizenAnswr")), bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Birth Country:",   GetSelectText($("QCountryAnswr")), bIsNotBold, bNextLine); 
     
	sHTML += BuildEmailLine("Graduate/Undergraduate Studies", "SectionTitle", bIsBold, bSkipLine); 
	
	sHTML += BuildEmailLine("Credits    :",		GetSelectText($("Credits")),  bIsNotBold, bSkipLine);
	 
	sHTML += BuildEmailLine("College #1 :",		$("CollegeName1").value,  bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City		:",		$("CollegeCity1").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State	    :",		$("CollegeState1").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Degree	    :",		$("CollegeDegree1").value,  bIsNotBold, bNextLine); 
	
	sHTML += BuildEmailLine("College #2 :",		$("CollegeName2").value,  bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City		:",		$("CollegeCity2").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State	    :",		$("CollegeState2").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Degree	    :",		$("CollegeDegree2").value,  bIsNotBold, bNextLine);
	 
	sHTML += BuildEmailLine("College #3 :",		$("CollegeName3").value,  bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City		:",		$("CollegeCity3").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State	    :",		$("CollegeState3").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Degree	    :",		$("CollegeDegree3").value,  bIsNotBold, bNextLine); 
	
	sHTML += BuildEmailLine("College #4 :",		$("CollegeName4").value,  bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City		:",		$("CollegeCity4").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State	    :",		$("CollegeState4").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Degree	    :",		$("CollegeDegree4").value,  bIsNotBold, bNextLine); 
     
	sHTML += BuildEmailLine("Educational Preferences", "SectionTitle", bIsBold, bSkipLine); 
	sHTML += BuildEmailLine("Location   :",		$("PrefLoc").value, bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("Start Month:",		GetSelectText($("PrefMonth")), bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Start Year	:",		$("PrefYear").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Loan/Grants:",		$("PrefAid").value,  bIsNotBold, bNextLine); 
	//sHTML += BuildEmailLine("Program    :",		GetSelectText($("PrefPgm")),  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Heard About:",		GetSelectText($("PrefRef")),  bIsNotBold, bNextLine); 
     
//	sHTML += BuildEmailLine("Work Experience", "SectionTitle", bIsBold, bSkipLine); 
//	 
//	sHTML += BuildEmailLine("Employer #1 :",	$("WorkEmp1").value,  bIsNotBold, bSkipLine); 
//	sHTML += BuildEmailLine("Begin Date  :",	$("WorkStart1").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("End Date    :",	$("WorkEnd1").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("Job Descrip.:",	$("WorkDesc1").value,  bIsNotBold, bNextLine); 
//	 
//	sHTML += BuildEmailLine("Employer #2 :",	$("WorkEmp2").value,  bIsNotBold, bSkipLine); 
//	sHTML += BuildEmailLine("Begin Date  :",	$("WorkStart2").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("End Date    :",	$("WorkEnd2").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("Job Descrip.:",	$("WorkDesc2").value,  bIsNotBold, bNextLine); 
//	 
//	sHTML += BuildEmailLine("Employer #3 :",	$("WorkEmp3").value,  bIsNotBold, bSkipLine); 
//	sHTML += BuildEmailLine("Begin Date  :",	$("WorkStart3").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("End Date    :",	$("WorkEnd3").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("Job Descrip.:",	$("WorkDesc3").value,  bIsNotBold, bNextLine); 
//	 
//	sHTML += BuildEmailLine("Employer #4 :",	$("WorkEmp4").value,  bIsNotBold, bSkipLine); 
//	sHTML += BuildEmailLine("Begin Date  :",	$("WorkStart4").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("End Date    :",	$("WorkEnd4").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("Job Descrip.:",	$("WorkDesc4").value,  bIsNotBold, bNextLine); 
//	 
//	sHTML += BuildEmailLine("Employer #5 :",	$("WorkEmp5").value,  bIsNotBold, bSkipLine); 
//	sHTML += BuildEmailLine("Begin Date  :",	$("WorkStart5").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("End Date    :",	$("WorkEnd5").value,  bIsNotBold, bNextLine); 
//	sHTML += BuildEmailLine("Job Descrip.:",	$("WorkDesc5").value,  bIsNotBold, bNextLine); 
     
	sHTML += BuildEmailLine("Referrals", "SectionTitle", bIsBold, bSkipLine); 
	
    sHTML += BuildEmailLine("Full Name  :",		$("RefName").value, bIsNotBold, bSkipLine); 
    sHTML += BuildEmailLine("Address    :",		$("RefAddr").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Phone      : ",	$("RefPhone").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Email      : ",    $("RefEmail").value, bIsNotBold, bNextLine);

    //If the program is not one of the special advanced teaching programs, we're done.
	if (!mbTeachProgram) {
	    sHTML = sHTML.substr(4); //Strip-off leading line break.
	    return sHTML;
	}

	var sQues;
	var sAns;

	sHTML += BuildEmailLine("TEACH/PACT Questionnaire", "SectionTitle", bIsBold, bSkipLine);
	
	//Repeat some input from above.
	sHTML += BuildEmailLine("Selected Program : ", GetSelectText($("PrefPgm")), bIsNotBold, bSkipLine);
	
	sHTML += BuildEmailLine("Returning Student: ", GetSelectText($("Returning")), bIsNotBold, bSkipLine);
	
	sHTML += BuildEmailLine("First Name  : ", $("FirstName").value, bIsNotBold, bSkipLine);
	sHTML += BuildEmailLine("Last Name   : ", $("LastName").value, bIsNotBold, bNextLine);

	sHTML += BuildEmailLine("Gender      : ", GetSelectText($("Gender")), bIsNotBold, bSkipLine);
	sHTML += BuildEmailLine("Birth Date  : ", $("Birth").value, bIsNotBold, bNextLine); 
	
	sHTML += BuildEmailLine("Home Phone  : ", $("PhoneHome").value, bIsNotBold, bSkipLine);
	sHTML += BuildEmailLine("Work Phone  : ", $("PhoneWork").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Email Addr  : ", $("EmailAddr").value, bIsNotBold, bNextLine);

	sHTML += BuildEmailLine("Address     : ", $("Addr1").value, bIsNotBold, bSkipLine);
	sHTML += BuildEmailLine("City        : ", $("City").value,  bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("State       : ", $("State").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Zip         : ", $("Zip").value,   bIsNotBold, bNextLine);
	
	sHTML += BuildEmailLine("US Citizen?  : ", GetSelectText($("QCitizenAnswr")), bIsNotBold, bSkipLine);
	sHTML += BuildEmailLine("Birth Country: ", GetSelectText($("QCountryAnswr")), bIsNotBold, bNextLine);

	sQues = $("Q1Hdr").innerHTML;
	sAns = $("Q1Answr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q1aHdr").innerHTML;
	sAns = GetSelectText($("Q1aAnswr"));
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q2Hdr").innerHTML;
	sAns = $("Q2Answr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q3Hdr").innerHTML;
	sAns = $("Q3Answr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q4Hdr").innerHTML;
	sAns = $("Q4Answr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q5Hdr").innerHTML;
	sAns = GetSelectText($("Q5Answr1")) + ". " + $("Q5Answr2").value; 
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q6Hdr").innerHTML;
	sAns = GetSelectText($("Q6Answr1")) + ". " + $("Q6Answr2").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

//	sQues = $("Q7Hdr").innerHTML;
//	sAns = GetSelectText($("Q7Answr"));
//	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = "Code of Conduct Agreement: ";
	sAns = "(no answer)"
	if ($("ConductAccept").checked) sAns = $("ConductAcceptHdr").innerHTML;
	if ($("ConductDecline").checked) sAns = $("ConductDeclineHdr").innerHTML;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);
		
	//Add link to body.
	//var sHostname = window.location.hostname;
	//var sURL = "http://";
	//sURL += sHostname;
	//sURL += "/ReqInfo/ApplyOnline.asp";
	//sHTML += BuildEmailLine("Click here to view the Apply Online form", sURL, bIsBold, bSkipLine, bIsLink); 
	
	//Strip-off leading line break.
	sHTML = sHTML.substr(4); 

	//Return result.
	return sHTML;

}
    	
//-------------------------------------------------------------------------------------
// Builds a basic line of information to be inserted into email body. Values passed can
// be a field-value pair or a link.
//-------------------------------------------------------------------------------------
function BuildEmailLine(sLabel, sValue, bBoldVal, bSkipLine, bIsLink) {

    var sStyle = "font-family:Tahoma,Verdana;font-size:10pt;";
   
    if (sValue == "Alert") {
		sValue = "";
        var sStyleLabel = sStyle + "color:red;font-weight:bold;";
    }
    else if (sValue == "SectionTitle") {
		sValue = "";
        var sStyleLabel = sStyle + "color:black;font-weight:bold;width:500px;";
    }
    else {
        var sStyleLabel = sStyle + "color:black;font-weight:normal;width:120px;";
    }
    var sStyleValue = sStyle + "color:blue;font-weight:" + ((bBoldVal) ? "bold" : "normal") + ";";
	var sStyleLink  = sStyle + "color:orange;font-weight:bold;";
	
    var sHTML = (bSkipLine) ? "<br><br>" : "<br>";

    if (bIsLink) {
        sHTML += '<a style="' + sStyleLink + '" href="' + sValue + '">' + sLabel + '</a>';
    }
    else {
        sHTML += '<label style="' + sStyleLabel + '">' + sLabel + '</label>';  		
        sHTML += '<label style="' + sStyleValue + '">' + sValue + '</label>';
    }
    
    return sHTML;
}

//-------------------------------------------------------------------------------------
// Builds a basic line of information to be inserted into email body for the Questionarire
// section of the form. Values passed can be a field-value pair or a link.
//-------------------------------------------------------------------------------------
function BuildEmailLineForQues(iQuesLevel, sLabel, sValue,  bBoldVal, bSkipLine, bIsLink) {

    var sStyle = "font-family:Tahoma,Verdana;font-size:10pt;";

    if (sValue == "Alert") {
        sValue = "";
        var sStyleLabel = sStyle + "color:red;font-weight:bold;";
    }
    else if (sValue == "SectionTitle") {
        sValue = "";
        var sStyleLavel = sStyle + "color:black;font-weight:bold;width:500px;";
    }
    else {
        if (iQuesLevel == 2) {
            var sStyleLabel = sStyle + "color:black;font-weight:normal;";
        }
        else {
            var sStyleLabel = sStyle + "color:black;font-weight:normal;width:500px;";
        }
    }

    var sStyleValue = sStyle + "color:blue;width:500px;font-weight:" + ((bBoldVal) ? "bold" : "normal") + ";";
    
    var sStyleLink = sStyle + "color:orange;font-weight:bold;";

    var sHTML = (bSkipLine) ? "<br><br>" : "<br>";

    if (bIsLink) {
        sHTML += '<a style="' + sStyleLink + '" href="' + sValue + '">' + sLabel + '</a>';
    }
    else {
        if (iQuesLevel == 2) {
            sHTML += '<label style="' + sStyleLabel + '">' + sLabel + '</label>';
            sHTML += '<label style="' + sStyleValue + '">' + sValue + '</label>';
        }
        else {
            sHTML += '<label style="' + sStyleLabel + '">' + sLabel + '</label>';
            sHTML += "<br>";
            sHTML += '<textarea rows="5" cols="70" style="' + sStyleValue + '">' + sValue + '</textarea>';
        }
    }

    return sHTML;
}

//-------------------------------------------------------------------------------------
// Go back to originating page or close the window, depending on the method used to 
// display the online application. If the application was launched in a separate browser
// window, there will be no history, so close the window. Otherwise, assume the online
// application has been displayed in the current browser instance and go back to the 
// previous page.
//-------------------------------------------------------------------------------------
function CancelApp() {

    //alert("History items = " + history.length);

    //If no history, close the browser window, otherwise, go back to previous page.
    if (history.length == 0) {
        window.close();
    }
    else {
        history.back();
    }
}

//-------------------------------------------------------------------------------------
// Cancels the TEACH/PACT process and resets the Program of Interest dropdown.
//-------------------------------------------------------------------------------------
function CancelTeach() {

    HideTeachPopover();

    $("PrefPgm").style.visibility = "visible";

    SetSelectValue($("PrefPgm"), "");
    
    //Set the buttons.
}

//-------------------------------------------------------------------------------------
// Cancel a specific event.
//-------------------------------------------------------------------------------------
function CancelEvent() {
    
    switch (event.type) {
        case "click":
            if(event.ctrlKey) document.selection.empty();
            break;
        case "contextmenu":
            return false;
            break;
        case "selectstart":
            if ((event.srcElement.className.indexOf("FieldVal") < 0) ||
                (event.srcElement.tagName == "DIV"))    
            {
                window.event.returnValue = false;
            }
            break;
    } 
    
}

//-------------------------------------------------------------------------------------
// Close the dialog. 
//-------------------------------------------------------------------------------------
function Close(oOtherDialog) {

    //If triggered by a keydown event, only allow the ENTER key.
    if (event) {
        //If object had focus and user hit the ENTER key
        if (event.type == "keydown" && event.keyCode != 13) return; 
        
    }
	
	//If changes have been made, prompt user to save changes to database.
	if ((mbSavePending)) {
	    if (!confirm("You have not submitted your request. Close anyway?")) return;
	}
	
	//Hide this dialog.
	Hide();
}

//-------------------------------------------------------------------------------------
// Shows or hides the TEACH/PACT popover.
//-------------------------------------------------------------------------------------
function HideTeachPopover(bShow) {

    HideCloak();

    $("TeachPopover").style.visibility = "hidden";

    //Unhide the State dropdown. It was temporarily hidden so it would not "bleed thru"
    //in IE6.
    $("State").style.visibility = "visible";

}

//-------------------------------------------------------------------------------------
// Initializes the page, fires immediately after the browser loads page. 
//-------------------------------------------------------------------------------------
function InitPage() {

	//if (parseInt($("OfferID").value) == 0) return;
    
    //Automatically assign tab indexes.
    AssignTabIndexes();
	
    //Attach event handlers on specific page objects/elements.
    AttachEventHandlers();
    
    //ShowPanel();

    SetActionMsg("", false);
    
    $("ActionBack").style.visibility = "hidden";
    $("ActionNext").style.visibility = "hidden";
    $("ActionSubmit").style.visibility = "visible";
    $("SaveBox").style.visibility = "hidden";

    msCurrentPanel = "0";
    ShowPanel();

    $("GeneralBox").style.visibility = "visible";
    $("GeneralBox").style.display = "block";
    
    $("InterviewBox").style.visibility = "hidden";
    $("InterviewBox").style.display = "none";
    
    $("ConductBox").style.visibility = "hidden";
    $("ConductBox").style.display = "none";

    if ($("FirstName").value.length > 0) $("ActionSubmit").style.visibility = "hidden";

    //If this is an existing online application, load the data.
    var sAppID = $("AppID").value;
    if (sAppID != "0") {
        mbSavedApp = true;
        LoadOnlineApp(sAppID);
    }
    else {
        var sAppType = $("AppType").value;
   }

}

//-------------------------------------------------------------------------------------
// Initiates the TEACH/PACT user interface.
//-------------------------------------------------------------------------------------
function InitTeach() {

    if (!mbSavedApp) HideTeachPopover();
    
    $("TopBox").style.height = "90px";

    $("PrefPgmHdr").style.visibility = "hidden";
    $("PrefPgm").style.visibility = "hidden";
    
    $("PrefPgmPickHdr").style.visibility = "visible";
    $("PrefPgmPick").style.visibility = "visible";
    $("PrefPgmPick").innerHTML = GetSelectText($("PrefPgm"));
    
    $("ActionBack").style.visibility = "visible";
    $("ActionNext").style.visibility = "visible";
    $("ActionSubmit").style.visibility = "hidden";
    $("SaveBox").style.visibility = "visible";

    //Set the buttons

}

//-------------------------------------------------------------------------------------
// Returns visibility status of this foatiframe/dialog. 
//-------------------------------------------------------------------------------------
function IsVisible() {

	return (moThisDialog.style.visibility == "visible") ? true : false;
}

//-------------------------------------------------------------------------------------
// Initiates AJAX request to retrieve online application data.
//-------------------------------------------------------------------------------------
function LoadOnlineApp(sAppID) {
    
    
    $("PrefPgmBox").style.visibility = "hidden";
    $("LoadingMsg").style.visibility = "visible";

    //Build parms string.
    var sParms = "app=" + sAppID;

    var sURL = "ApplyOnlineGet.asp";

    //Initiate XMLHttpRequest call to local remote call proxy.
    var bSuccess = XHRSend("POST", sURL, sParms, OnOnlineAppLoaded);
    if (!bSuccess) {
        var sMsg = "Error attempting to initiate retrieval of your online application"
        $("LoadingMsg").innerHTML = sMsg;
    }

}

//-------------------------------------------------------------------------------------
// Processes/monitors call to load/retrieve the data for an existing application. 
//-------------------------------------------------------------------------------------
function OnOnlineAppLoaded() {

    if (moXHR.readyState == 4) {
        if (moXHR.status != 200) {
            var sErrMsg = "Action failed. Error: " + moXHR.status + "\n\n";
            sErrMsg += "Error Details: " + moXHR.statusText;
            alert(sErrMsg);
            mbLoading = false;
            //SetActionMsg("We are unable to process your request at this time (E01). Please try again later.", true);
            //$("ActionMsg").title = sErrMsg;
            //$("ActionSubmit").value = "Submit Application";
            return;
        }

        var sResult = "";

        if (msXHRResponseFormat == "XML") {
            var sXML = oXHR.responseXML;
            if (window.ActiveXObject) {
                sResult = sXML.childNodes[1].firstChild.nodeValue;
            }
            else {
                sResult = sXML.childNodes[0].firstChild.nodeValue;
            }
        }
        else {
            sResult = moXHR.responseText;
        }


        //If no results to display, clear the status message and get outta here.
        if (!sResult) {
            mbLoading = false;
            var sMsg = "Error attempting to retrieve your online application (E02)"
            alert(sMsg);
            //SetActionMsg("We are unable to process your request at this time (E02). Please try again.", true);
            //$("ActionSubmit").value = "Submit Application";
            return;
        }

        var bError = (sResult.indexOf("Error") >= 0) ? true : false;
        if (bError) {
            mbLoading = false;
            var sMsg = "Error attempting to retrieve your online application (E03) \n" + sResult;
            alert(sMsg);
            //SetActionMsg(sMsg, true);
            //$("ActionSubmit").value = "Submit Application";
            return;
        }

        //SetActionMsg(sResult, "details");

        //Success! Reset flags.
        mbLoading = false;

        //Populate form with data retrieved.
        sResult = sResult.substr(16);
        PopulateApp(sResult);
    }

}

//-------------------------------------------------------------------------------------
// Processes/monitors call to save Lead data. 
//-------------------------------------------------------------------------------------
function OnOnlineAppSaved() 
{  
	if (moXHR.readyState == 4) 
	{
		if (moXHR.status != 200)
		{
			var sErrMsg = "Action failed. Error: " + moXHR.status + "\n\n";
			sErrMsg += "Error Details: " + moXHR.statusText;
			alert(sErrMsg);
			mbSaving = false;
			SetActionMsg("We are unable to save your application at this time (E01). Please try again later.", true);
			$("ActionMsg").title = sErrMsg;	
			$("ActionSubmit").value = "Submit Application";   
			return;		
		}  		 
		 
		var sResult = "";
		
		if (msXHRResponseFormat == "XML")
		{
			var sXML = oXHR.responseXML;    
			if (window.ActiveXObject)    
			{        
				sResult = sXML.childNodes[1].firstChild.nodeValue;     
			}    
			else    
			{        
				sResult = sXML.childNodes[0].firstChild.nodeValue;    
			}        
		}
		else
		{	
			sResult = moXHR.responseText;
		}
		
		
		//If no results to display, clear the status message and get outta here.
		if (!sResult) 
		{
			mbSaving = false;
			SetActionMsg("We are unable to save your application at this time (E02). Please try again.", true);
			//$("ActionSubmit").value = "Submit Application";   
			return;
		}
		
		var bError = (sResult.indexOf("Error") >= 0) ? true : false;
		if (bError) 
		{
			mbSaving = false;
			alert(sResult);
			sMsg = "Unable to save your application at this time (E03). Please try again later.";
			SetActionMsg(sMsg, true);
			//$("ActionSubmit").value = "Submit Application";  
			return; 
		}
		
		//SetActionMsg(sResult, "details");
		
		//Success! Reset flags.
		mbInfoSaved = true;
		mbSavePending = false;
		mbSaving = false;
		
		//Disable Submit button.
		//$("ActionSubmit").style.visibility = "hidden";
		//$("ActionSubmit").value = "Application Submitted";   
		//$("ActionSubmit").disabled = "true";
		
		//Show "Thank You".
		ShowThankYou(true);
	} 
	
}

//-------------------------------------------------------------------------------------
// Processes/monitors call to save Lead data. 
//-------------------------------------------------------------------------------------
function OnOnlineAppSubmitted() {
    if (moXHR.readyState == 4) {
        if (moXHR.status != 200) {
            var sErrMsg = "Action failed. Error: " + moXHR.status + "\n\n";
            sErrMsg += "Error Details: " + moXHR.statusText;
            alert(sErrMsg);
            mbSaving = false;
            SetActionMsg("We are unable to process your request at this time (E01). Please try again later.", true);
            $("ActionMsg").title = sErrMsg;
            $("ActionSubmit").value = "Submit Application";
            return;
        }

        var sResult = "";

        if (msXHRResponseFormat == "XML") {
            var sXML = oXHR.responseXML;
            if (window.ActiveXObject) {
                sResult = sXML.childNodes[1].firstChild.nodeValue;
            }
            else {
                sResult = sXML.childNodes[0].firstChild.nodeValue;
            }
        }
        else {
            sResult = moXHR.responseText;
        }


        //If no results to display, clear the status message and get outta here.
        if (!sResult) {
            mbSaving = false;
            SetActionMsg("We are unable to process your request at this time (E02). Please try again.", true);
            $("ActionSubmit").value = "Submit Application";
            return;
        }

        var bError = (sResult.indexOf("Error") >= 0) ? true : false;
        if (bError) {
            mbSaving = false;
            alert(sResult);
            sMsg = "Unable to process your application at this time (E03). Please try again later.";
            SetActionMsg(sMsg, true);
            $("ActionSubmit").value = "Submit Application";
            return;
        }

        //SetActionMsg(sResult, "details");

        //Success! Reset flags.
        mbInfoSaved = true;
        mbSavePending = false;
        mbSaving = false;

        //Disable Submit button.
        //$("ActionSubmit").style.visibility = "hidden";
        $("ActionSubmit").value = "Application Submitted";
        $("ActionSubmit").disabled = "true";

        //Show "Thank You".
        ShowThankYou();
    }

}

//-------------------------------------------------------------------------------------
// Populates fields with data retrieved from server. 
//-------------------------------------------------------------------------------------
function PopulateApp(sData) {

    //alert(sData);
    
    mbSavePending = true;

    $("LoadingMsg").style.visibility = "hidden";
    $("PrefPgmBox").style.visibility = "visible";

    var aFieldVals = sData.split("|");

    //First field is the chosen degree program.
    var aField = aFieldVals[0].split("=");
    var sFieldName = aField[0];
    var sFieldVal = aField[1];

    //The first field is the Program of Interest selected by the user, originally.
    mbTeachProgram = false;
    SetSelectValue($("PrefPgm"), sFieldVal);
    if (sFieldVal == "TEACH" || sFieldVal == "PACT" || sFieldVal == "ME-TLS") {
        mbTeachProgram = true;
        
        //Set default values for Certification Level field.
        SetCertLevelOptions(sFieldVal);
        
        InitTeach();
    }
    
    //Spin thru the field-value pairs, setting the appropriate UI field values.
    var sTag;
    var sType;
    var oField;
    for (var i = 1; i < aFieldVals.length-1; i++) {
        aField = aFieldVals[i].split("=");
        sFieldName = aField[0];
        sFieldVal = aField[1];
        oField = $(sFieldName);
        try {
            sType = oField.type;
        }
        catch (e) {
            //skip it
            continue;
        }
        sTag = oField.tagName;
        if (sType == "text" || sType == "textarea") {
            oField.value = sFieldVal;
        }
        else if (sType == "checkbox") {
            oField.checked = (sFieldVal == "1") ? true : false;
        }
        else if (sType == "select" || sType == "select-one") {
            //alert("Setting select field " + oField.id + " to " + sFieldVal);
            SetSelectValue(oField, sFieldVal);
        }
    }

}

//-------------------------------------------------------------------------------------
// Remove focus from the element by setting focus on its parent/containing element. 
// This is a useful function to invoke via the ONCHANGE event for a single-select SELECT
// element to prevent inadvertant scrolling by the user.
//-------------------------------------------------------------------------------------
function RemoveElementFocus() {

    event.srcElement.parentElement.focus();
}

//-------------------------------------------------------------------------------------
// Shows or hides the Save Application popover.
//-------------------------------------------------------------------------------------
function SaveAppInit() {

    if ($("EmailAddr").value.length > 0) $("SaveEmail").value = $("EmailAddr").value;

    ShowCloak("container", "5000");

    var iLeft = $("container").offsetLeft;
    var iTop = $("BottomBox").offsetTop - 80;

    $("SaveAppPopover").style.zIndex = "10000";
    $("SaveAppPopover").style.left = iLeft + 250 + "px";
    $("SaveAppPopover").style.top = iTop + "px";
    $("SaveAppPopover").style.visibility = "visible";

}

//-------------------------------------------------------------------------------------
// Shows or hides the Save Application popover.
//-------------------------------------------------------------------------------------
function SaveApp() {

    HideCloak();

    $("SaveAppPopover").style.visibility = "hidden";

    SubmitOnlineApp(true);

}

//-------------------------------------------------------------------------------------
// Hides the Save Application popover.
//-------------------------------------------------------------------------------------
function SaveAppCancel() {

    HideCloak();
    
    $("SaveAppPopover").style.visibility = "hidden";

}

//-------------------------------------------------------------------------------------
// Submits the information to the leads management service.
//-------------------------------------------------------------------------------------
function SaveInfo(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;

    //If a SAVE action is in progress, get outta here.
    if (mbSaving) return;

    //If triggered by a keydown event, only allow the ENTER key.
    if (evt) {
        if (sType == "keydown" && evt.keyCode != 13) return;
    }

    if (!ValidateUserInput()) return;

    //If cloak is displayed, ignore this action.
    //if (IsCloaked()) return;

    //If no changes have been made, get outta here.
    if (!mbSavePending) {
        mbSaveAndClear = false;
        sMsg = "No data has been entered or modified. \n\n";
        //sMsg += "Please fill in the appropriate fields and then click SUBMIT to \n";
        //sMsg += "submit your online application.";
        alert(sMsg);
        return;
    }

    //Visual flag and visual cues to indicate a SAVE action is in progress.
    mbSaving = true;
    mbInfoSaved = false;

    //Initiate database action.
    SubmitOnlineApp();

}

//-------------------------------------------------------------------------------------
// Shows Offer Details UI.
//-------------------------------------------------------------------------------------
function SetActionMsg(sMsg, bError, sColor, bBold) {

    //Message text.
    $("ActionMsg").innerHTML = sMsg;

    //Color.
    var sMsgColor = (bError) ? "red" : "green";
    sMsgColor = (sColor) ? sColor : sMsgColor;
    $("ActionMsg").style.color = sMsgColor;

    //Font weight.
    $("ActionMsg").style.fontWeight = (bBold) ? "bold" : "bold";
}

//-------------------------------------------------------------------------------------
// Set the options to be displayed in the Certification Level dropdown based on the 
// selected Program Type.
//-------------------------------------------------------------------------------------
function SetCertLevelOptions(sProgram) {
    
    
    var oField = $("Q1aAnswr");
    
    oField.innerHTML = "";

    if (sProgram == "PACT") {
	    AddSelectOption(document,oField, "EC-6 Elementary Generalist", "EC-6", 0);
	}
	else {
        var iIndex = 0;
	    AddSelectOption(document,oField, "", "", iIndex++);
	    AddSelectOption(document,oField, "EC-6 Elementary Generalist", "EC-6", iIndex++);
	    AddSelectOption(document,oField, "4-8 Generalist / Middle School (Combination in Language Arts, Math, Science, Social Studies)", "4-8Gen",  iIndex++);
	    AddSelectOption(document,oField, "4-8 Subject Specific / Middle School (Language Arts)", "4-8LA",  iIndex++);
	    AddSelectOption(document,oField, "4-8 Subject Specific / Middle School (Math)", "4-8Mth",  iIndex++);
	    AddSelectOption(document,oField, "4-8 Subject Specific / Middle School (Science)", "4-8Sci",  iIndex++);
	    AddSelectOption(document,oField, "4-8 Subject Specific / Middle School (Social Studies)", "4-8SS",  iIndex++);
	    AddSelectOption(document,oField, "8-12 Subject Specific / High School (Language Arts)", "8-12LA",  iIndex++);
	    AddSelectOption(document,oField, "8-12 Subject Specific / High School (Math)", "8-12Mth",  iIndex++);
	    AddSelectOption(document,oField, "8-12 Subject Specific / High School (Science)", "8-12Sci",  iIndex++);
	    AddSelectOption(document,oField, "8-12 Subject Specific / High School (Social Studies)", "8-12SS",  iIndex++);
	}
	
	//Default to the first item in the dropdown list.    
	oField.selectedIndex = 0;

}

//-------------------------------------------------------------------------------------
// Sets change to Program of Interest.
//-------------------------------------------------------------------------------------
function SetChangeToProgram(e) {

    var sVal = $("PrefPgm").value;

    if ((sVal == "TEACH") || (sVal == "PACT") || (sVal == "ME-TLS")) {
    
        mbTeachProgram = true;
        
        //Set default values for Certification Level field.
        SetCertLevelOptions(sVal);
            
        //Set default for Preferred Campus Location field.
        if ((sVal == "PACT") || (sVal == "ME-TLS")) {
            SetSelectText($("PrefLoc"), "Online");
            $("PrefLoc").disabled = true;
        }
        else {
            SetSelectText($("PrefLoc"), "");
            $("PrefLoc").disabled = false;
        }
        
        //Show notice regarding the TEACH/PACT application process.
        ShowTeachPopover();
    }
    else {
        mbTeachProgram = false;

        if ((sVal == "ME-CIS") || (sVal == "ME-EA")) {
            SetSelectText($("PrefLoc"), "Online");
            $("PrefLoc").disabled = true;
        }
        else {
            SetSelectText($("PrefLoc"), "");
            $("PrefLoc").disabled = false;
        }
        
        $("TopBox").style.height = "90px";
        $("PrefPgmHdr").style.visibility = "hidden";
        $("PrefPgm").style.visibility = "hidden";
        
        $("PrefPgmPickHdr").style.visibility = "visible";
        $("PrefPgmPick").style.visibility = "visible";
        $("PrefPgmPick").innerHTML = GetSelectText($("PrefPgm"));

        $("ActionBack").disabled = true;
        $("ActionBack").style.visibility = "hidden";
        $("ActionNext").disabled = true;
        $("ActionNext").style.visibility = "hidden";
        $("ActionSubmit").disabled = false;
        $("ActionSubmit").style.visibility = "visible";
        
        $("ActionSubmit").style.left = "230px";
        $("ActionCancel").style.left = "340px";
        $("ActionMsg").style.left = "230px";
        
        HideTeachPopover();
    }
    
}

//-------------------------------------------------------------------------------------
// Applies changes to the Code of Conduct Agree/Decline checkboxes.
//-------------------------------------------------------------------------------------
function SetChangeToConductAnswer(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;

    if (oSrc.id == "ConductAccept") {
        if (oSrc.checked == true) {
            $("ConductDecline").checked = false;
        }
    }
    else if (oSrc.id == "ConductDecline") {
        if (oSrc.checked == true) {
            $("ConductAccept").checked = false;
        }
    }     
       
}

//-------------------------------------------------------------------------------------
// Hilites/unhilites the CLOSE action link.
//-------------------------------------------------------------------------------------
function SetCloseActionHilite(e) {

	var evt = window.event || e;
	var oSrc = evt.srcElement || e.target;
	var sType = evt.type || e.type;
	
	if (sType == "mouseover" || sType == "focus") {
	    oSrc.style.color = "orange";
	}    
	else {
	    oSrc.style.color = "rgb(164,164,164)";
	}
}

//-------------------------------------------------------------------------------------
// Set field default values.
//-------------------------------------------------------------------------------------
function SetFieldDefaults() {

//	$("FirstName").value = (sFirstName) ? sFirstName : "";
//	$("LastName").value  = (sLastName)  ? sLastName : "";
//	$("Addr1").value = "";
//	$("Addr2").value = "";
//	$("City").value = "";
//	$("State").options(0).selected = true;
//	$("Zip").value = "";
//	$("Country").value = "USA";

}

//-------------------------------------------------------------------------------------
// Hilites an action link and retains the original/default color in an attribute.
//-------------------------------------------------------------------------------------
function SetFieldActionHilite(e) {

    var evt = window.event || e;
    var oSrc = evt.srcElement || e.target;
    var sType = evt.type || e.type;

    if (sType == "mouseover" || sType == "focus") {
	    //oSrc.setAttribute("DefaultColor", oSrc.style.color);
	    oSrc.style.color = "orange";
	}    
	else {
	    //oSrc.style.color = oSrc.getAttribute("DefaultColor");
	    oSrc.style.color = "blue";
	}    
}

//-------------------------------------------------------------------------------------
// Hilites/unhilites the Panel Navigation action links.
//-------------------------------------------------------------------------------------
function SetPanelActionHilite(e) {

	var evt = window.event || e;
	var oSrc = evt.srcElement || e.target;
	var sType = evt.type || e.type;
	
	if (sType == "mouseover" || sType == "focus") {
	    oSrc.style.color = "orange";
	}    
	else {
	    oSrc.style.color = "rgb(0,255,0)";
	}
	    
} 

//-------------------------------------------------------------------------------------
// Set SAVE PENDING flags.
//-------------------------------------------------------------------------------------
function SetSave(arg1, arg2) {
                    
    //SetActionMsg("", false);

	var sSwitch = "";
	
	//If running FireFox browser.
	if (typeof(arg1) == "object") 
	{
		sSwitch = arg2;
		var evt = window.event || arg1;
		var oSrc = evt.srcElement || arg1.target;
		var sType = evt.type || arg1.type;
	}
	else
	{
		sSwitch = arg1;
	}

    if (sSwitch == "off") {
        mbSavePending = false;
        return;
    }
    
    //If tabkey, ignore.
    if (oSrc) {
        if (evt.keyCode == 9) return;
    }

    mbSavePending = true;
}

//-------------------------------------------------------------------------------------
// Shows the next panel of input or information fields.
//-------------------------------------------------------------------------------------
function ShowPanel(sMoveTo) {

	//Clear the message area.
	SetActionMsg("", false);

	//Display the appropriate panel after validating the current panel's data.
	switch (msCurrentPanel) 
	{
		case "0":
			$("GeneralBox").style.visibility = "visible";
			$("GeneralBox").style.display = "block";
			$("InterviewBox").style.visibility = "hidden";
			$("InterviewBox").style.display = "none";
			$("ConductBox").style.visibility = "hidden";
			$("ConductBox").style.display = "none";
			
			$("ActionBack").disabled = true;
			$("ActionNext").disabled = false;
			$("ActionSubmit").style.visibility = "hidden";

			$("ApplyNowHdr").focus();
		    
            msCurrentPanel = "1";
            break;
			
		case "1":
			if (!ValidateUserInput()) return;
		    $("GeneralBox").style.visibility = "hidden";
		    $("GeneralBox").style.display = "none";
		    $("InterviewBox").style.visibility = "visible";
		    $("InterviewBox").style.display = "block";
		    $("ConductBox").style.visibility = "hidden";
		    $("ConductBox").style.display = "none";

		    $("ActionBack").disabled = false;
		    $("ActionNext").disabled = false;
		    $("ActionSubmit").style.visibility = "hidden";
		    
		    $("ApplyNowHdr").focus();

		    //Fix for Quirk/Bug in IE7 to get dropdown at top of page (Citizen?) to display contents properly. 
		    //Not sure why this resolves the issue, but not enough time to research it more thoroughly. 
		    $("Q1Hdr").innerHTML = $("Q1Hdr").innerHTML;
		    			
            msCurrentPanel = "2";
            break;
			
		case "2":
		    if (sMoveTo == "next") 
			{
				if (!ValidateUserInput()) return;
			    $("GeneralBox").style.visibility = "hidden";
			    $("GeneralBox").style.display = "none";
			    $("InterviewBox").style.visibility = "hidden";
			    $("InterviewBox").style.display = "none";
			    $("ConductBox").style.visibility = "visible";
			    $("ConductBox").style.display = "block";

			    $("ActionBack").disabled = false;
			    $("ActionNext").style.visibility = "hidden";
			    $("ActionSubmit").style.visibility = "visible";
			    				
                msCurrentPanel = "3";
			}
			else 
			if (sMoveTo == "prev") 
			{
			    $("GeneralBox").style.visibility = "visible";
			    $("GeneralBox").style.display = "block";
			    $("InterviewBox").style.visibility = "hidden";
			    $("InterviewBox").style.display = "none";
			    $("ConductBox").style.visibility = "hidden";
			    $("ConductBox").style.display = "none";

			    $("ActionBack").disabled = true;
			    $("ActionNext").disabled = false;
		        $("ActionNext").style.visibility = "visible";
		        $("ActionSubmit").style.visibility = "hidden";
				
				msCurrentPanel = "1";
			}
			    
			$("ApplyNowHdr").focus();
			break;
			
		case "3":
			if (sMoveTo == "next") 
			{
				if (!mbInfoSaved)
				{
					if (!ValidateUserInput) return;
					//SubmitInfo();
				}
				else 
				{
//					$("Panel1").style.visibility = "hidden";
//					$("Panel2").style.visibility = "hidden";
//					$("Panel3").style.visibility = "hidden";
//					$("Panel4").style.visibility = "visible";
//					$("ActionBack").style.visibility = "hidden";
//					$("ActionNext").style.visibility = "hidden";
//					$("ActionSubmit").style.visibility = "hidden";
//					SetActionMsg("Thank You!", false, "rgb(0,0,255)", true);
//					msCurrentPanel = "4";
				}
			}
			else 
			if (sMoveTo == "prev") 
			{
			    $("GeneralBox").style.visibility = "hidden";
			    $("GeneralBox").style.display = "none";
			    $("InterviewBox").style.visibility = "visible";
			    $("InterviewBox").style.display = "block";
			    $("ConductBox").style.visibility = "hidden";
			    $("ConductBox").style.display = "none";

			    $("ActionBack").disabled = false;
			    $("ActionNext").style.visibility = "visible";
			    $("ActionNext").disabled = false;
			    $("ActionSubmit").style.visibility = "hidden";
			    
			    $("ApplyNowHdr").focus();
			    
			    msCurrentPanel = "2";
			}
			break;
	}
			
}

//-------------------------------------------------------------------------------------
// Move to the next panel.
//-------------------------------------------------------------------------------------
function ShowPanelNext() {

	ShowPanel("next");
    
}

//-------------------------------------------------------------------------------------
// Move to the previous panel.
//-------------------------------------------------------------------------------------
function ShowPanelPrev() {

	ShowPanel("prev");
    
}

//-------------------------------------------------------------------------------------
// Dislays warning about sending printed versions of this online application.
//-------------------------------------------------------------------------------------
function ShowPrintWarning() {

    var sMsg;
    
    sMsg  = "For proper assessment, LeTourneau University requires all interviews to be \n";
    sMsg += "submitted online. Please note that hard copies will not be accepted.\n\n";
    sMsg += "Thank you!";

    alert(sMsg);

}

//-------------------------------------------------------------------------------------
// Shows or hides the TEACH/PACT popover.
//-------------------------------------------------------------------------------------
function ShowTeachPopover(bShow) {

    ShowCloak("container", "5000");

    //Hide the State dropdown temporarily so it doesn't get in the way in IE6.
    $("State").style.visibility = "hidden";

    var iLeft = $("container").offsetLeft;

    $("PrefPgm").style.visibility = "hidden";
    
    $("TeachPopover").style.zIndex = "10000";
    $("TeachPopover").style.left = iLeft + 160 + "px";
    $("TeachPopover").style.visibility = "visible";

}

//-------------------------------------------------------------------------------------
// Shows Thank You page.
//-------------------------------------------------------------------------------------
function ShowThankYou(bSaveOnly) {

    //Clear the message area.
    if (bSaveOnly) {
        SetActionMsg("Thank You! Your application has been saved.", false);
        window.location = "ApplyOnlineThankYou.asp?type=save";
    }
    else {
        SetActionMsg("Thank You! Your application has been submitted.", false);
        window.location = "ApplyOnlineThankYou.asp?type=apply";
    }
}

//-------------------------------------------------------------------------------------
// Submits AJAX request to send lead info to appropriate email recipient.
//-------------------------------------------------------------------------------------
function SubmitOnlineApp(bSaveOnly) {

    //If submitting the app (not just saving it), then validate the field values.
    if (!bSaveOnly) {
        if (!ValidateUserInput()) return;
    }

	//Display status message.
	if (bSaveOnly) {
	    //$("ActionSave").value = "Saving...";
	    SetActionMsg("Saving your application, please wait...", "", false);
	    var sUserEmail = $("SaveEmail").value;
        var sParms = "AppAction=Save&SaveUserEmail=" + sUserEmail;
	}
	else {
	    $("ActionSubmit").value = "Processing...";
        SetActionMsg("Submitting your application, please wait...", "", false);
	    var sParms = "AppAction=Submit&AppType=apply";
	}
    
    //Append EmailBody to parm string.
    var sEmailBody = BuildEmailBody();
    sEmailBody = sEmailBody.replace(/&/g,"and"); //Remove ampersands user may have entered.
	sParms += "&EmailBody=" + encodeURI(sEmailBody);
    
    //Append data fieldname-value pairs to parm string.
    var sData = BuildFieldValString();
    sData = sData.replace(/&/g,"and"); 
	sParms += "&DataOnly=" + encodeURI(sData);
		
	//Set URL/URI. If using a cross-domain server-side proxy, modify the URL and establish the
	//URL/URI for the server-side proxy.
	//var sURL = $("LeadMgmtSiteURL").value + "ReqInfo/ApplyOnlineSubmit.asp";
	var sURL = "ApplyOnlineSubmit.asp";

	//Initiate XMLHttpRequest call to local remote call proxy.
	if (bSaveOnly) {
	    var bSuccess = XHRSend("POST", sURL, sParms, OnOnlineAppSaved);
	}
	else {
	    var bSuccess = XHRSend("POST", sURL, sParms, OnOnlineAppSubmitted);
	}
	
	//If not initiated, clear all status messages.
	if (!bSuccess) {
	    var sText = (bSaveOnly) ? "save" : "submit";
	    SetActionMsg("Error attempting to " + sText + " your online application", true);
	}

}

//-------------------------------------------------------------------------------------
// Validates user input.
//-------------------------------------------------------------------------------------
function ValidateUserInput() {

    var da = document.all;
    var oBox;
    var sMsg;
    var oField;
    var sFieldName;
    var sVal = " ";
    var iBlankFieldCnt = 0;
    var iInvalidCnt = 0;
    var oBlankField;
    var oInvalidField;
    var bShow = true;
    var aMsgs = new Array();
    
    SetActionMsg("", false);

    //Validate Panel/Page 1 user input.
    if (msCurrentPanel == "1") {

        //First Name. 
        oField = $("FirstName");
        if (oField.value.length == 0) {
            SetActionMsg("You must enter your first name", true);
            return false;
        }

        //Last Name. 
        oField = $("LastName");
        if (oField.value.length == 0) {
            SetActionMsg("You must enter your last name", true);
            return false;
        }

        //Phone or Email.
        var sPhoneHome = $("PhoneHome").value;
        var sPhoneWork = $("PhoneWork").value;
        var sEmailAddr = $("EmailAddr").value;
        if ((sPhoneHome.length == 0) && (sPhoneWork.length == 0) && (sEmailAddr.length == 0)) {
            SetActionMsg("You must enter your phone number or your email address", true);
            return false;
        }

        //Citizenship.
        oField = $("QCitizenAnswr");
        if (oField.value.length == 0) {
            SetActionMsg('You must specify your "US Citizenship"', true);
            return false;
        }

        //Birth Country.
        oField = $("QCountryAnswr");
        if (oField.value.length == 0) {
            SetActionMsg('You must specify "Your Birth Country"', true);
            return false;
        }

    }

    //Validate Questionnaire (Page 2) user input.
    if (msCurrentPanel == "2") {

        var sMsg = "Please provide an answer for each question on this page. Incomplete interviews cannot be submitted for assessment. Thank you.";

        //Questions 1 thru 4.
        for (var i = 1; i <= 4; i++) {
            oField = $("Q" + i + "Answr");
            if (oField.value.length == 0) {
                SetActionMsg(sMsg, true);
                return false;
            }
        }

        //Question #1 Part 2. 
        oField = $("Q1aAnswr");
        if (oField.value.length == 0) {
            SetActionMsg(sMsg, true);
            return false;
        }

        //Question #5 Part 1. 
        oField = $("Q5Answr1");
        if (oField.value.length == 0) {
            SetActionMsg(sMsg, true);
            return false;
        }
        else if (oField.value == "Yes") {
            //Question #5 Part 2.
            oField = $("Q5Answr2");
            if (oField.value.length == 0) {
                SetActionMsg(sMsg, true);
                return false;
            }
        }

        //Question #6 Part 1. 
        oField = $("Q6Answr1");
        if (oField.value.length == 0) {
            SetActionMsg(sMsg, true);
            return false;
        }
        else if (oField.value == "Yes") {
            //Question #6 Part 2.
            oField = $("Q6Answr2");
            if (oField.value.length == 0) {
                SetActionMsg(sMsg, true);
                return false;
            }
        }

    }
	
    //Success.
    return true;
}

//-------------------------------------------------------------------------------------
// Returns new XMLHttpRequest object. 
//-------------------------------------------------------------------------------------
function XHRCreate() 
{        
	if (window.XMLHttpRequest)         
	{      
		//IE 7, FireFox          
		return oXHR = new XMLHttpRequest();         
	}       
	else if (window.ActiveXObject) 
	{   
		//IE 6.x           
		return oXHR = new ActiveXObject("Microsoft.XMLHTTP");       
	} 
}

//-------------------------------------------------------------------------------------
// Initiate XMLHttpRequest call to specified URL/URI. 
//-------------------------------------------------------------------------------------
function XHRSend(sType, sURL, sParms, oCallback){    

	//Create XmlHttpRequest object.
	moXHR = XHRCreate();
	
	//If error creating XHR object, get outta here.
	if (!moXHR)
	{
		alert("Error: Unable to create XHR object.");
		return false;
	}   
	
	if (sType == "POST") 
	{	
		//Set POST properties and send HTTP request.
		//moXHR.onreadystatechange = OnAjaxStateChange;    
		moXHR.onreadystatechange = oCallback;    
		moXHR.open("POST", sURL, true);  
		moXHR.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
		moXHR.setRequestHeader("Content-length", sParms.length);
		moXHR.send(sParms);
	}
	else
	{
		alert("XHR GET-style call not implemented. Request cancelled.");
		return false;
	}
	
	return true;
}