//-------------------------------------------------------------------------------------
// 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.

var mbLMS_StopOnError = false;      //Stop processing if errors returned from the LMS api?

//-------------------------------------------------------------------------------------
// 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);

    //Add placeholder for Lead ID. The LMS replaces this value with the actual Lead ID.
    sHTML += BuildEmailLine("Lead ID: ***LEADID***", "", bIsBold, bSkipLine);

    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("Citizenship Country: ",    GetSelectText($("QCitizenAnswr")), bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Birth Country: ",   GetSelectText($("QCountryAnswr")), bIsNotBold, bNextLine); 
	
	sHTML += BuildEmailLine("Veteran	 : ",	$("Veteran").value, bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("Branch      : ",	$("Branch").value, bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Discharged  : ",	$("Discharge").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Pay Grade   : ",	$("PayGrade").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Rank        : ",	$("Rank").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Years of Service: ", $("ServiceYrs").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Using VA Benefits? ", $("VaBenefits").value, bIsNotBold, bNextLine);
	
	sHTML += BuildEmailLine("Military Education Office: ", $("EduOffice").value, bIsNotBold, bSkipLine);
	sHTML += BuildEmailLine("Command Duty Station: ", $("DutyStation").value, bIsNotBold, bNextLine);

 	sHTML += BuildEmailLine("Military Training/Cert #1: ",	$("Train1").value, bIsNotBold, bSkipLine); 
 	sHTML += BuildEmailLine("Military Training/Cert #2: ",	$("Train2").value, bIsNotBold, bNextLine); 
 	sHTML += BuildEmailLine("Military Training/Cert #3: ",	$("Train3").value, bIsNotBold, bNextLine); 
 	sHTML += BuildEmailLine("Military Training/Cert #4: ",	$("Train4").value, bIsNotBold, bNextLine); 
 	sHTML += BuildEmailLine("Military Training/Cert #5: ",	$("Train5").value, bIsNotBold, bNextLine); 
 	
	sHTML += BuildEmailLine("Ethnic Questions", "SectionTitle", bIsBold, bSkipLine); 

	sHTML += BuildEmailLine("Hispanic/Latino? ",                       GetSelectText($("EthnicHisp")), bIsNotBold, bSkipLine, false, "100"); 
	sHTML += BuildEmailLine("American Indian or Alaska Native? ",	    (($("EthnicOp1").checked) ? "Yes": "No"), bIsNotBold, bNextLine, false, "220"); 
	sHTML += BuildEmailLine("Asian? ",	                                (($("EthnicOp2").checked) ? "Yes": "No"), bIsNotBold, bNextLine, false, "50"); 
	sHTML += BuildEmailLine("Black or African American? ",	            (($("EthnicOp3").checked) ? "Yes": "No"), bIsNotBold, bNextLine, false, "160"); 
	sHTML += BuildEmailLine("Native Hawaiian or Pacific Islander? ",	(($("EthnicOp4").checked) ? "Yes": "No"), bIsNotBold, bNextLine, false, "220"); 
	sHTML += BuildEmailLine("White? ",	                                (($("EthnicOp5").checked) ? "Yes": "No"), bIsNotBold, bNextLine, false, "50"); 
     
	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("College #5 : ",		$("CollegeName5").value,  bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City		: ",		$("CollegeCity5").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State	    : ",		$("CollegeState5").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Degree	    : ",		$("CollegeDegree5").value,  bIsNotBold, bNextLine); 
	
	sHTML += BuildEmailLine("College #6 : ",		$("CollegeName6").value,  bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City		: ",		$("CollegeCity6").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State	    : ",		$("CollegeState6").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Degree	    : ",		$("CollegeDegree6").value,  bIsNotBold, bNextLine); 
	
	sHTML += BuildEmailLine("College #7 : ",		$("CollegeName7").value,  bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City		: ",		$("CollegeCity7").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State	    : ",		$("CollegeState7").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Degree	    : ",		$("CollegeDegree7").value,  bIsNotBold, bNextLine); 
	
	sHTML += BuildEmailLine("College #8 : ",		$("CollegeName8").value,  bIsNotBold, bSkipLine); 
	sHTML += BuildEmailLine("City		: ",		$("CollegeCity8").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("State	    : ",		$("CollegeState8").value,  bIsNotBold, bNextLine); 
	sHTML += BuildEmailLine("Degree	    : ",		$("CollegeDegree8").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("Referral: Person To Thank", "SectionTitle", bIsBold, bSkipLine); 
	
    sHTML += BuildEmailLine("Full Name  : ",		$("Ref1Name").value, bIsNotBold, bSkipLine); 
    sHTML += BuildEmailLine("Address    : ",		$("Ref1Addr").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Phone      : ",	$("Ref1Phone").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Email      : ",    $("Ref1Email").value, bIsNotBold, bNextLine);
     
	sHTML += BuildEmailLine("Referral: Interested Friend or Relative", "SectionTitle", bIsBold, bSkipLine); 
	
    sHTML += BuildEmailLine("Full Name  : ",		$("Ref2Name").value, bIsNotBold, bSkipLine); 
    sHTML += BuildEmailLine("Address    : ",		$("Ref2Addr").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Phone      : ",	$("Ref2Phone").value, bIsNotBold, bNextLine);
	sHTML += BuildEmailLine("Email      : ",    $("Ref2Email").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("Citizenship Country: ", GetSelectText($("QCitizenAnswr")), bIsNotBold, bSkipLine);
	sHTML += BuildEmailLine("Birth Country: ", GetSelectText($("QCountryAnswr")), bIsNotBold, bNextLine);

	sQues = $("Q1Hdr").innerHTML;
	sAns = GetSelectText($("Q1Ansr"));
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q2Hdr").innerHTML;
	sAns = $("Q2Ansr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q3Hdr").innerHTML;
	sAns = $("Q3Ansr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q4Hdr").innerHTML;
	sAns = $("Q4Ansr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q5Hdr").innerHTML;
	sAns = $("Q5Ansr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q6Hdr").innerHTML;
	sAns = $("Q6Ansr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q7Hdr").innerHTML;
	sAns = $("Q7Ansr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q8Hdr").innerHTML;
	sAns = $("Q8Ansr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q9Hdr").innerHTML;
	sAns = $("Q9Ansr").value;
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

    // Criminal History Questions

	sQues = $("Q10Hdr").innerHTML;
	sAns = GetSelectText($("Q10aAnsr")) + ". " + $("Q10bAnsr").value; 
	sHTML += BuildEmailLineForQues(1, sQues, sAns, bIsNotBold, bSkipLine);

	sQues = $("Q11Hdr").innerHTML;
	sAns = GetSelectText($("Q11aAnsr")) + ". " + $("Q11bAnsr").value; 
	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, sLabelWidth) {

    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 {
        if (!sLabelWidth) sLabelWidth = "120";
        var sStyleLabel = sStyle + "color:black;font-weight:normal;width:" + sLabelWidth + "px;";
    }
    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;
}


//-------------------------------------------------------------------------------------
// Submits AJAX request to send lead info to the LMS.
//-------------------------------------------------------------------------------------
function LMS_SendLead(sAppQuestions, sAppAnswers, sAppEmail) {

	//Display status message.   
	//SetActionMsg("Submitting request, please wait...", "", false);
        
	//Build parms string.
    var sParms	= "";
    
    sParms += "&LeadType="      + encodeURI("StudentApplication");
    
	sParms += "&SubmitMode="	+ encodeURI($("SubmitMode").value);
    sParms += "&ClientCode="	+ encodeURI($("ClientCode").value);
	sParms += "&CampaignCode="	+ encodeURI($("CampaignCode").value);
	sParms += "&LeadSource="	+ encodeURI($("LeadSource").value);
	sParms += "&TimeZone="		+ encodeURI($("TimeZone").value);
	sParms += "&ResponseFormat=" + encodeURI($("ResponseFormat").value);
	sParms += "&IPAddr="		+ encodeURI($("IPAddr").value);

	sParms += "&FirstName="		+ encodeURI($("FirstName").value);
	sParms += "&LastName="		+ encodeURI($("LastName").value);
	sParms += "&Addr1="			+ encodeURI($("Addr1").value);
	//sParms += "&Addr2="			+ encodeURI($("Addr2").value);
	sParms += "&City="			+ encodeURI($("City").value);
	sParms += "&State="			+ encodeURI($("State").value);
	sParms += "&Zip="			+ encodeURI($("Zip").value);
	
	var sCountry = GetSelectText($("QCountryAnswr"));
	sParms += "&Country="		+ encodeURI(sCountry);
	
	var sPhoneHome = $("PhoneHome").value;
	var sPhoneWork = $("PhoneWork").value;
	var sEmailAddr = $("EmailAddr").value;
	
	var sPhone = "";
	var sPhone2 = "";
	var sEmailType = "HTML";
	
	if (sPhoneHome.length > 0) {
	    var sContactMethod = "Phone";
	    sPhone = sPhoneHome;
	}
	else
	if (sPhoneWork.length > 0) {
	    var sContactMethod = "Phone";
	    if (sPhone.length == 0) {
	        sPhone = sPhoneWork;
	    }
	    else {
	        sPhone2 = sPhoneWork;
	    }
	}
	else
	if (sEmailAddr.length > 0) {
	    var sContactMethod = "Email";
	}

	sParms += "&ContactMethod="	+ encodeURI(sContactMethod);
	//sParms += "&PhoneTime="		+ encodeURI($("PhoneTime").value);
	sParms += "&Phone="			+ encodeURI(sPhone);
	sParms += "&Phone2="		+ encodeURI(sPhone2);
	sParms += "&EmailAddr="		+ encodeURI(sEmailAddr);
	sParms += "&EmailType="		+ encodeURI(sEmailType);

	//sParms += "&EduLevel="	+ encodeURI($("EduLevel").value);
	//sParms += "&GradYearHS="	+ encodeURI($("GradYearHS").value);
	
	sPgm = GetSelectText($("PrefPgm"));
	sParms += "&Program="	+ encodeURI(sPgm);
	
	//sParms += "&Comments="	+ encodeURI($("Comments").value);
	
	//Append student application questions to parms.
	///sParms += "&AppQuestions=" + encodeURI(sAppQuestions);
	
	//Append student application answers to parms.
	sParms += "&AppAnswers=" + encodeURI(sAppAnswers);
	
	//Append email parm header to parms, but don't append the actual email until after tweaking
	//the parms for use by the server-side proxy, because we don't want the raw HTML in the email
	//to be corrupted.
	sParms += "&AppEmail=";
    
	//Modify parms string for use by server-side proxy. Replace equal signs and ampersands so proxy 
	//ignores the fieldname-value pairs and passes them on to the remote URL.
	sParms = sParms.replace(/=/g,"|**|");
	sParms = sParms.replace(/&/g,"|*|");
	
	//Now append email HTML to parms.
	sParms += encodeURI(sAppEmail);
	
	//Set URL/URI. Use a cross-domain server-side proxy since the Lead Management site exists
	//on a different domain.
	var sPage = "ProcessNewLead.aspx";
	var sRemoteURL = $("LeadMgmtSiteURL").value + sPage;
	var sURL = "xdp.asp";
	
	msXHRResponseFormat = "Text";
		
	sParms  = "Parms="		+ sParms;
	sParms += "&RemoteURL=" + sRemoteURL;
	sParms += "&Format="	+ msXHRResponseFormat;
	
    //alert("sParms Length=" + sParms.length + ":" + sParms);
	
	//Initiate XMLHttpRequest call to local remote call proxy.
	var bSuccess = XHRSend("POST", sURL, sParms, OnOnlineAppSubmitted);
	
	//If not initiated, display error message. 
	if (!bSuccess) SetActionMsg("Error attempting to submit your online application", true);

}

//-------------------------------------------------------------------------------------
// NOT USED Processes/monitors call to save Lead data to the LMS. 
//-------------------------------------------------------------------------------------
function LMS_SendLeadCallback() 
{  
	var sMsg = "";
	
	if (moXHR.readyState == 4) {
	
	    //If LMS error, continue processing to submit application and send email.
	    
	    //alert("Lead info saved to LMS, submitting application now...");
	
	    SubmitOnlineApp();
	} 
	
}

//-------------------------------------------------------------------------------------
// 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("Bad Request") >= 0 || 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";
            $("ActionMsg").title = sResult;
            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;
    
    //Send lead info to the LMS.
    //LMS_SendLead();

    //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 = $("Q1Ansr");
    
    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;
    }

    var sParms = "";
    
	//Display status message.
	if (bSaveOnly) {
	    //$("ActionSave").value = "Saving...";
	    SetActionMsg("Saving your application, please wait...", "", false);
	    var sUserEmail = $("SaveEmail").value;
        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 sAppEmail = BuildEmailBody();
    sAppEmail = sAppEmail.replace(/&/g,"and"); //Remove ampersands user may have entered.
 	sParms += (bSaveOnly) ? "&EmailBody=" : "&AppEmail=";
	sParms += encodeURI(sAppEmail);
   
    //Append data fieldname-value pairs to parm string.
    var sAppAnswers = BuildFieldValString();
    sAppAnswers = sAppAnswers.replace(/&/g,"and"); 
	sParms += (bSaveOnly) ? "&DataOnly=" : "&AppAnswers=";
	sParms += encodeURI(sAppAnswers);
	
    //Append data fieldname-fieldheader text pairs to parm string. Only sent if submitting, not 
    //saving.
//    if (!bSaveOnly){
            var sAppQuestions = null;
//        var sAppQuestions = BuildFieldHdrTextString();
//        sAppQuestions = sAppQuestions.replace(/&/g,"and"); 
//	    sParms += "&AppQuestions=" + encodeURI(sAppQuestions);
//	}
	
    //*** TO DO ***
    //Append data fieldname-fieldheader text pairs to parm string. Only sent if submitting, not 
    //saving.
    //if (!bSaveOnly){
        //var sFieldLayout = BuildFieldLayoutString();
        //sFieldLayout = sData.replace(/&/g,"and"); 
	    //sParms += "&AppLayout=" + encodeURI(sFieldLayout);
	//}
		
	//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";

	//Initiate XMLHttpRequest call to local remote call proxy.
	if (!bSaveOnly) {
	    LMS_SendLead(sAppQuestions, sAppAnswers, sAppEmail);
	}
	else {
	    //URL only used for temporarily saving student application data on server.
	    var sURL = "ApplyOnlineSubmit.asp";
	    
	    var bSuccess = XHRSend("POST", sURL, sParms, OnOnlineAppSaved);
    	
	    //If not initiated, display error message.
	    if (!bSuccess) SetActionMsg("Error attempting to save 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.";

        //Question #1. 
        oField = $("Q1Ansr");
        if (oField.value.length == 0) {
            SetActionMsg(sMsg, true);
            return false;
        }

        //Questions 2 thru 9.
        for (var i = 2; i <= 9; i++) {
            oField = $("Q" + i + "Ansr");
            if (oField.value.length == 0) {
                SetActionMsg(sMsg, true);
                return false;
            }
        }

        //Question #10 Part 1. 
        oField = $("Q10aAnsr");
        if (oField.value.length == 0) {
            SetActionMsg(sMsg, true);
            return false;
        }
        else if (oField.value == "Yes") {
            //Question #10 Part 2.
            oField = $("Q10bAnsr");
            if (oField.value.length == 0) {
                SetActionMsg(sMsg, true);
                return false;
            }
        }

        //Question #11 Part 1. 
        oField = $("Q11aAnsr");
        if (oField.value.length == 0) {
            SetActionMsg(sMsg, true);
            return false;
        }
        else if (oField.value == "Yes") {
            //Question #11 Part 2.
            oField = $("Q11bAnsr");
            if (oField.value.length == 0) {
                SetActionMsg(sMsg, true);
                return false;
            }
        }

    }

    //Validate Code of Conduct (Page 3) user input.
    if (msCurrentPanel == "3") {

        var sMsg = "Please choose one of the two Code of Conduct options. Thank you.";

        //Must select an option. 
        if ($("ConductAccept").checked == false && $("ConductDecline").checked == false) {
            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;
}