var curQ = 0;
var lastQ = 0;
var skipQ = new Array();
var qListString = [];

var hideSchoolLogoDesc = false;
var useInlineErrorMessages = false;
var useSeperateMatchAndPII = false;
var errors =[];
var messages = [];
window.formFamily = "DegreesInfo";
//window.dhtmlHistoryDisabled = true; don't need to define, can be defined in the form or in the html

function resizeDisplayWindow(){
  var screenWidth = screen.availWidth;
  var screenHeight = screen.availHeight;
  if(screenWidth <=0) {
      screenWidth = 800;
  }
  if(screenHeight <=0) {
      screenHeight = 600;
  }
  window.moveTo(0,0);
  window.resizeTo(screenWidth-10,screenHeight-10);
  if(window.focus) {
    window.focus();
  }
}

var checkQueryString = window.location.search;
if(checkQueryString.indexOf("resizeDisplay=true")>=0) {
  resizeDisplayWindow();
}

//show q=shownQ or such group, hide q=hiddenQ or such group
function showHideQ(shownQ, hiddenQ) {
  if (window.qListGroups) {
    var qListStringGroup = window.qListGroups[hiddenQ];
    if (qListStringGroup) {
      for (var j=0;j<qListStringGroup.length;++j) {
        //alert("hide: " + qListStringGroup[j]);
        hide(qListStringGroup[j]);
      }
    }
    qListStringGroup = window.qListGroups[shownQ];
    if (qListStringGroup) {
      for (var j=0;j<qListStringGroup.length;++j) {
        //alert("show: " + qListStringGroup[j]);
        show(qListStringGroup[j]);
      }
    }
    
    hideEmailField("1");//in case we show email in the group
  } 
  else {
     var hiddenField = qListString[hiddenQ];
     if (hiddenField) {
       hide(hiddenField);
     }
     var shownField = qListString[shownQ];
     if (shownField) {
       show(shownField);
     }
  }
}
function showNextQ(field) {
   var isSubmitPage = true;
   
   if (window.qListGroups) {
      if (curQ < window.qListGroups.length) {
        var qListStringGroup = window.qListGroups[curQ];
        if (qListStringGroup) { 
          for (var i=0;i<qListStringGroup.length;++i) {
//            field = window.document.form1.elements[qListStringGroup[i]];
            //alert("check field: " + field.name + " for: " + qListStringGroup[i]);
        	  if(!validateGroupElement(qListStringGroup[i])) {
        		return false;  
        	  }
           }
           if (curQ < window.qListGroups.length - 1) {
             lastQ = curQ;
             curQ = curQ + 1;
             
             showHideQ(curQ, lastQ);
             
             if (!window.dhtmlHistoryDisabled) {
               dhtmlHistory.add("HQ"+curQ, curQ);
             }
             isSubmitPage = false;
           }
        }
        else {
          isSubmitPage = false;
        }
      }
    }
    else {
      if(field && !validate(field)) {
        return;
      }
        
      lastQ = curQ;
      curQ++;

      if(curQ<qListString.length) {
        showHideQ(curQ, lastQ); 
 
        if (!window.dhtmlHistoryDisabled) {
          dhtmlHistory.add("HQ"+curQ, curQ);
        }
        isSubmitPage = false;
      }
    }
    
    if (isSubmitPage) {
      finalize();
      submitForm();
    }
}

function validateGroupElement(groupElement) {
	var fieldsInDiv = getFieldsWithinDiv(groupElement);
	if(fieldsInDiv && fieldsInDiv.length > 0) {
    	var field = getFormField(fieldsInDiv[0].name);
        if(field && !validate(field)) {
          return false;
         }
	}
	return true;
}

function finalize() {
    var highestEd = window.document.form1.DDI_EDUCATION_01;
    if(highestEd != undefined && highestEd != null && highestEd.options[highestEd.selectedIndex].value == 'none') {
        highestEd.options[highestEd.selectedIndex].disabled = false;
    }
}
function adchemyBack() {
  if (!window.dhtmlHistoryDisabled) {
    history.back();
  } else {
    displayPreviousQ();
  }
}
function showPreviousQ(field) {
    if(curQ == 0) {
    alert("Already at beginning of form");
        return;
    }

    showHideQ(lastQ, curQ);

    curQ = lastQ;
    lastQ = lastQ - 1;
    
    if (!window.dhtmlHistoryDisabled) {
      dhtmlHistory.add("HQ"+curQ, curQ);
    }
    
    //Reset if: 1 - we don't deal with grouped questions
    // 2 - we have a group consisting of a single question
    if (!window.qListGroups || window.qListGroups[curQ].length == 1) {
      resetFieldValue();
    }
}

function validate(field) {
	if (formSubmitted == true) {
		//don't validate fields if we submit a form by form1.submit() method
		return true;
	}
    if(field==window.document.form1.DDI_AOS_01) {
        return validate_DDI_AOS_01();
    } else if(field==window.document.form1.DDI_AGE_01) {
        return validate_DDI_AGE_01();
    } else if(field==window.document.form1.DDI_GRADYEAR_01) {
        return validate_DDI_GRADYEAR_01();
    } else if(field==window.document.form1.DDI_EDUCATION_01) {
        return validate_DDI_EDUCATION_01();
    } else if(field==window.document.form1.DDI_START_PERIOD_01) {
        return validate_DDI_START_PERIOD_01();
    } else if(field==window.document.form1.COUNTRY_01) {
        return validate_DDI_COUNTRY_01();
    } else if(field==window.document.form1.USCITIZEN_01) {
        return validate_DDI_USCITIZEN_01();
    } else if(field==window.document.form1.DDI_MILITARYBRANCH_01) {
        return validate_DDI_MILITARYBRANCH_01();
    } else if (field==window.document.form1.ZIP_01) {
	    return validate_ZIP_01(window.document.form1);
    } else if(field==window.document.form1.EMAIL_01 && isEmailVisible()) {
        var isValid = validate_EMAIL_01(window.document.form1);
        if (!window.qListGroups && isValid) {
          isValid = validate_ZIP_01(window.document.form1);
        }
        return isValid;
    } else if(field==window.document.form1.DDI_EARN_YEARLY_01) {
        return validate_DDI_EARN_YEARLY_01();
    }

    return true;
}

function hideAll() {
    i=0;
    while(i<qListString.length) {
        hide(qListString[i]);
        i++;
    }
}

function associatesOrGreater() {
  if(window.document.form1 && window.document.form1.DDI_ASSOCIATESORGREATER && window.document.form1.DDI_ASSOCIATESORGREATER.value == 'true') {
    return true;
  } else {
    return false;
  }
}

function filterAlreadySelected() {
  if(window.document.form1.MATCH_FILTERS_SELECTED) {
    if(window.document.form1.MATCH_FILTERS_SELECTED.value == 'true') {
      return true;
    }
  }
  return false;
}

function isKeiserBSN(school,field) {
    if(school == 'keiser') {
      if(field.selectedIndex >=0 && field.options[field.selectedIndex].text == 'Registered Nurse to BS in Nursing') {
        return true;
      }
    }
    return false;
}

function isPhoenixOnlineBSN(school,field) {
    if(school == 'phoenixonline') {
      if(field.selectedIndex >=0 && field.options[field.selectedIndex].text == 'RN to B.S. in Nursing') {
        return true;
      }
    }
    return false;
}

function isSouthUniversityBSN(school,field) {
    if(school == 'southuniversity') {
      if(field.selectedIndex >=0 && field.options[field.selectedIndex].text == 'B.S. Degree Completion Program (RN to BSN)') {
        return true;
      }
    }
    return false;
}

function isAIUSounthFloridaBSN(school,field) {
    if(school == 'aiucampus-southflorida') {
      if(field.selectedIndex >=0 && field.options[field.selectedIndex].text == 'Bachelor of Science in Nursing Management (BSNM)') {
        return true;
      }
    }
    return false;
}

function filterSelected(school) {
    field = document.getElementById("element_MATCH_"+school);
    value = getFieldValueLB(field)
    displaySchools(school);
    showOptionalQuestions();
}

function showAccreditation() {
    if(document.getElementById("AIU_ACCREDITATION") == null) {
        return;
    }
    hide("AIU_ACCREDITATION");
    var schoolList = readSchoolList();
    for(i=0;i<schoolList.length;i++) {
        var school = schoolList[i];
        if(school != null && school.length >= 3 && (school == 'aiu' || school.substring(0, 3) == 'aiu')) {
            show("AIU_ACCREDITATION");
            return;
        }
    }
}

function showOptionalQuestions() {
    hideAllOptional();
    var schoolList = readSchoolList();
    for(i=0;i<schoolList.length;i++) {
      field = document.getElementById("element_MATCH_"+schoolList[i]);
      if (field) {
      	value = getFieldValueLB(field)
      	if(validateIsRequired(value)) {
        	showOptionalQuestionsForSchool(schoolList[i]);
        	showOptionalQuestionsForProgram(schoolList[i],field);
      	}
      }
    }
}

// Server-side maps use '<school>:<program-hash>', whereas the
// client-side uses '<school>:<field>' where field is the option.value for
// the program.
function showOptionalQuestionsForProgram(school,field) {
  
  if(school != null && field != null) {
      var value = getFieldValueLB(field);
      var key = school+":"+value;
      var questions = programMap[key];
      if(questions != null && questions.length > 0) {
        for(var index=0;index<questions.length;index++) {
            show("optQ_"+questions[index]);
        }
      }
  }
}

function showOptionalQuestionsForSchool(school) {
  var questions = schoolMap[school];
  if(questions != null && questions.length > 0) {
    for(var index=0;index<questions.length;index++) {
        show("optQ_"+questions[index]);
    }
  }

  highlightSchool(school);
}

function highlightSchool(school) {
  var foundSchool = false;
  var foundNextSchool = false;
  var schoolList = readSchoolList();
  for(i=0;i<schoolList.length;i++) {
    if(schoolList[i] == school) {
      foundSchool = true;
      field = document.getElementById("element_MATCH_"+schoolList[i]);
      value = getFieldValueLB(field);
      if(!validateIsRequired(value)) {
        document.getElementById('cell_'+schoolList[i]).className = "rowOn";
        foundNextSchool = true;
        field.focus();
      } else {
        document.getElementById('cell_'+schoolList[i]).className = "rowOff";
        for(var z=i;z<schoolList.length;z++) {
          field2 = document.getElementById("element_MATCH_"+schoolList[z]);
          value2 = getFieldValueLB(field2);
          if(!validateIsRequired(value2) && !foundNextSchool) {
            document.getElementById('cell_'+schoolList[z]).className = "rowOn";
            foundNextSchool=true;
            field2.focus();
          } else {
            document.getElementById('cell_'+schoolList[z]).className = "rowOff";
          }
        }
        for(var z=0;z<i;z++) {
          field2 = document.getElementById("element_MATCH_"+schoolList[z]);
          value2 = getFieldValueLB(field2);
          if(!validateIsRequired(value2) && !foundNextSchool) {
            document.getElementById('cell_'+schoolList[z]).className = "rowOn";
            foundNextSchool=true;
            field2.focus();
          } else {
            document.getElementById('cell_'+schoolList[z]).className = "rowOff";
          }
        }
      }
    return;
    }
  }
}

function displaySchools(school) {
    var schoolList = readSchoolList();
    if (schoolList) {
      for (i = 0; i < schoolList.length; i++) {
        var schoolSection = document.getElementById("tr_"+schoolList[i]);
        if (schoolSection) {
          schoolSection.style.display = "block";
          if (schoolList[i] == school) {
            var nextSchoolIdx = i + 1;
            if (nextSchoolIdx < schoolList.length) {
                var nextSchoolSection = document.getElementById("tr_"+schoolList[nextSchoolIdx]);
                nextSchoolSection.style.display = "block";
            }
            return;
          }
        }
      }
    }
}

function displayAllSchools() {
    var schoolList = readSchoolList();
    if (schoolList) {
      for (i = 0; i < schoolList.length; i++) {
        var schoolSection = document.getElementById("tr_"+schoolList[i]);
        if (schoolSection) {
          schoolSection.style.display = "block";
        }
      }
    }
}

function validate_DDI_USCITIZEN_01() {
    optField = window.document.form1.USCITIZEN_01;
    optValue = getFieldValueRB(optField);
    if(!validateIsRequired(optValue)) {
      return alertError(window.document.form1.USCITIZEN_01[0], "You must indicate whether you are a U.S. Citizen.");
    }
    return true;
}
function initRematch() {
  var isRematchPage = (window.document.form1.Rematch.value == 'true');
  if (isRematchPage) {
    var piiTable = document.getElementById("PIITable");
    if (piiTable) {
      piiTable.style.display="none";
    }
    var matchImageObj = document.getElementById("matchImage");
    if (matchImageObj) {
      matchImageObj.style.display = "none";
    }
    matchImageObj = document.getElementById("match");
    if (matchImageObj) {
      matchImageObj.style.display = "none";
    }
    matchImageObj = document.getElementById("match-img");
    if (matchImageObj) {
      matchImageObj.style.display = "none";
    }
  }
  
}
function initDefaults() {
    if(associatesOrGreater()) {
        var field = window.document.form1.DDI_NURSEORASSOCIATES_01;
        if(field != undefined && field != null)
            selectValueRB(field,'YES');
    }
    if (window.document.form1.Rematch) {
      initRematch();
    }
}


function initHistory() {
  try {
    //initialize our DHTML history
    dhtmlHistory.initialize();

    //subscribe to DHTML history change events
    dhtmlHistory.addListener(historyChange);
    //alert("isSafari: " + dhtmlHistory.isSafari + " isIe: " + dhtmlHistory.isIE + " isOP: " + dhtmlHistory.isOpera + " isKOnq: " + dhtmlHistory.isKonquerer + " isGecko: " + dhtmlHistory.isGecko);

    if (dhtmlHistory.isSafari) {
     window.dhtmlHistoryDisabled = true;
    }
  } catch(e) {
    //alert("exception while init");
    window.dhtmlHistoryDisabled = true;
    try {
         var reasonMes = "reason: " + reason + "problem: " + e.name + ": ";
         if (e.message) {
           reasonMes += " message: " + e.message;
         }
         if (e.description) {
           reasonMes += " desc: " + e.description;
         }
         if (e.lineNumber) {
           reasonMes += " line number: " + e.lineNumber;
         }

         reasonMes = "can't initialize dhtmlHistory: " + ", " + reasonMes;
         
         params = "type=jsProblem&field=dhtmlHistory" + "&reason=" + encodeURIComponent(reasonMes);
         
         AjaxObject.getReq().open("POST", ValidationTracker.reportedUrl, false); 
         AjaxObject.getReq().setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
         AjaxObject.getReq().setRequestHeader("Cache-Control", "no-cache"); 
    
         AjaxObject.getReq().send(params);
         
       } catch(e) {}
  }
}

function historyChange(newLocation,historyData) {
  if (window.dhtmlHistoryDisabled) {
    return;
  }
  
  //alert("history change: " + newLocation + " historyData: " + historyData + " curQ: " + curQ);
  var newL = null;
  if(historyData && newLocation && newLocation!=""){
    newL=parseInt(newLocation.substring(2));
    if(!isNaN(newL)) {
      if (newL > curQ) { //going forward, doesn't do anything
          //alert("going forward");
          if (window.inReset) {//reset function was called
            var length4CurQ = qListString.length;
            if (window.qListGroups) {
              length4CurQ = window.qListGroups.length;
            }
            var tempCurQ = curQ;
            while (curQ < newL && curQ < length4CurQ) {
              displayNextQ(window.document.form1.Submit);
              if (curQ <= tempCurQ) { //if for some reason we don't increase curQ
                tempCurQ = curQ;
                curQ++;
              }
            }
            window.inReset = false;
          }
          else {
            dhtmlHistory.add("HQ"+ curQ, (curQ+1)); 
            history.back();
          }
      } 
      else {//going back
        //alert("going back");
        while (curQ > newL && curQ >0) {
          displayPreviousQ();
        }
      }
    }
  }
  if (null == newL || isNaN(newL)) {
    while (curQ > 0) {
      displayPreviousQ();
    }
  }

}


var areaOfStudyToSelect ='';
function initFirstPage() {
  initHistory();
  
  hideEmailField("1");
  initFunctionWasCalled();

  initializeGroups(window.qListGroups);  
  
  var areaOfStudy = queryString("_AOS");
  if(validateIsRequired(areaOfStudy)) {
    selectValueRB(window.document.form1.DDI_AOS_01,areaOfStudy);
    return true;
  } else {
    var occupation = queryString("_OCC");
    if(validateIsRequired(occupation)) {
      areaOfStudy = getAreaOfStudyByOccupation(occupation);
      if(validateIsRequired(areaOfStudy)) {
        selectValueRB(window.document.form1.DDI_AOS_01,areaOfStudy);
        return true;
      }
    }
    if(validateIsRequired(areaOfStudyToSelect)) {
      selectValueRB(window.document.form1.DDI_AOS_01,areaOfStudyToSelect);
      return true;
    }
  }
  
	
}

function initSecondPage() {
	hideEmailField("2");
	hideZipCodeField();
  initFunctionWasCalled();
}

var _initFunctionWasCalled=false;
function initFunctionWasCalled() {
  _initFunctionWasCalled=true;
}

function getAreaOfStudyByOccupation(occupation) {
  if(occupation == "accountant") {
      return "business";
  } else if (occupation == "bounty hunter") {
      return "criminal justice";
  } else if (occupation == "chef") {
      return "culinary arts";
  } else if (occupation == "counselor") {
      return "health and human services";
  } else if (occupation == "cpa") {
      return "business";
  } else if (occupation == "criminal investigator") {
      return "criminal justice";
  } else if (occupation == "database administrator") {
      return "computer science";
  } else if (occupation == "detective") {
      return "criminal justice";
  } else if (occupation == "developer") {
      return "computer science";
  } else if (occupation == "engineer") {
      return "computer science";
  } else if (occupation == "financier") {
      return "business";
  } else if (occupation == "graphic designer") {
      return "graphic design";
  } else if (occupation == "healthcare manager") {
      return "health and human services";
  } else if (occupation == "HR officer") {
      return "business";
  } else if (occupation == "manager") {
      return "business";
  } else if (occupation == "marketer") {
      return "business";
  } else if (occupation == "network specialist") {
      return "computer science";
  } else if (occupation == "paralegal") {
      return "criminal justice";
  } else if (occupation == "patient advocate") {
      return "health and human services";
  } else if (occupation == "police") {
      return "criminal justice";
  } else if (occupation == "project manager") {
      return "business";
  } else if (occupation == "psychologist") {
      return "psychology";
  } else if (occupation == "sales person") {
      return "business";
  } else if (occupation == "social worker") {
      return "health and human services";
  } else if (occupation == "software professional") {
      return "computer science";
  } else if (occupation == "teacher") {
      return "education";
  } else if (occupation == "therapist") {
      return "health and human services";
  } else if (occupation == "pr specialist") {
      return "general studies and communication";
  } else if (occupation == "author") {
      return "general studies and communication";
  } else if (occupation == "hotel manager") {
      return "hotel hospitality";
  } else {
      return "";
  }
}

function hideAllOptional() {
  try {//when optionalQuestionDivs is not declared
  	for(var i=0;i<optionalQuestionDivs.length;i++) {
    	hide(optionalQuestionDivs[i]);
  	}
  } catch (e) {}
}

function writeInsideMatchImage() {
    var schoolList = readSchoolList();
    if(document.getElementById("matchImage") != null) {
        document.getElementById("matchImage").src = matchImageBase + schoolList.length+".gif";
    }
}

function readSchoolList() {
    if(window.document.form1.DEGREES_INFO_MATCHED_SCHOOLS != undefined &&
      window.document.form1.DEGREES_INFO_MATCHED_SCHOOLS != null)
        return window.document.form1.DEGREES_INFO_MATCHED_SCHOOLS.value.split(",");
    else
        return new Array();
}

function resetSchoolList(schoolList) {
    if(window.document.form1.DEGREES_INFO_MATCHED_SCHOOLS != undefined &&
      window.document.form1.DEGREES_INFO_MATCHED_SCHOOLS != null) {
        return window.document.form1.DEGREES_INFO_MATCHED_SCHOOLS.value = schoolList;
    }
}

var warnedUserAboutProgram = false;
function warnSelectMorePrograms(fieldToShow, school, message) {
   warnedUserAboutProgram = true;
   
   alert(message);
   highlightSchool(school);
   
   try {
     DdiTracker.trackLink('ddiReminder');
   } catch(e) {}
   
   var sendingUrl = "/forms/form.jsp";
   try {
     AjaxObject.getReq().open("POST", sendingUrl, false); 
     AjaxObject.getReq().setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
     AjaxObject.getReq().setRequestHeader("Cache-Control", "no-cache"); 
    
     AjaxObject.getReq().send("AJAX_REMINDER=true&" + AjaxObject.getParams(window.document.form1));
   } catch(e) {}
   
   return false;
}

function validateOptInput(optInput) {
    if(optInput[0].type == 'radio') {
        var value = getFieldValueRB(optInput);
        return validateIsRequired(value);
    }
    else if(optInput[0].type == 'text') {
        var value = getFieldValueTF(optInput[0]);
        return validateIsRequired(value);
    }
    else if(optInput[0].type == 'select-one') {
        var value = getFieldValueLB(optInput[0]);
        return validateIsRequired(value);
    }
    else {
        return true;
    }
}

function validate_OPT_QUESTIONS() {
    var schoolList = readSchoolList();
    var verifiedSchoolList = null;
    var alertField = null;
    var alertMessage = null;
    for(var i=0;i<schoolList.length;i++) {
        var school = schoolList[i];
        var validationFailed = false;
        var field = document.getElementById("element_MATCH_"+school);
        var program = getFieldValueLB(field);
        if(validateIsRequired(program)) {
            // this school has a program selected.
            var schoolQuestions = schoolMap[school];
            var schoolQCount = schoolQuestions == null?0:schoolQuestions.length;
            var key = school+":"+program;
            var programQuestions = programMap[key];
            var programQCount = programQuestions==null?0:programQuestions.length;
            for(var j=0;j<schoolQCount;j++){
                var optInput = window.document.getElementsByName(schoolQuestions[j]);
                if(!validateOptInput(optInput)) {
                    if (alertField == null) {
                        alertField = field;
                        alertMessage = optQuestionIsRequired[schoolQuestions[j]];
                    }
                    validationFailed = true;
                }
            }
            for(var k=0;k<programQCount;k++){
                var optInput = window.document.getElementsByName(programQuestions[k]);
                if(!validateOptInput(optInput)) {
                     if (alertField == null) {
                        alertField = field;
                        alertMessage = optQuestionIsRequired[programQuestions[k]];
                    }
                    validationFailed = true;
                }
            }
        }
       
        if (!validationFailed) {
            if (verifiedSchoolList == null) {
                verifiedSchoolList = school;
            } else {
                verifiedSchoolList += "," + school;
            }
        }
    }

    if (alertField != null && alertMessage != null) {
        alertError(alertField, alertMessage);
        ajaxFormSubmit(schoolList, verifiedSchoolList);
        return false;
    }

    return true;
}

var ajaxFormSubmitted = false;
function ajaxFormSubmit(schoolList, verifiedSchoolList) {
   if (ajaxFormSubmitted || verifiedSchoolList == null) {
     return;
   }

  resetSchoolList(verifiedSchoolList);      

   var sendingUrl = "/forms/form.jsp";
   try {
     AjaxObject.getReq().open("POST", sendingUrl, false); 
     AjaxObject.getReq().setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
     AjaxObject.getReq().setRequestHeader("Cache-Control", "no-cache"); 
    
     AjaxObject.getReq().send("AJAX_FORM_SUBMIT=true&" + AjaxObject.getParams(window.document.form1));
   } catch(e) {}

   resetSchoolList(schoolList);   

   ajaxFormSubmitted = true;
}

function validate_FILTERMATCHLIST() {
    var selectedProgramCount=0;
    if(filterAlreadySelected()) {
      return true;
    }
    var schoolList = readSchoolList();
    var fieldToShow = 0;
    for(i=0;i<schoolList.length;i++) {
        field = document.getElementById("element_MATCH_"+schoolList[i]);
        value = getFieldValueLB(field)
        if(validateIsRequired(value)) {
            selectedProgramCount++;
        } else if(fieldToShow == 0) {
            fieldToShow = i;
        }
    }
    
    if(selectedProgramCount == 0) {
      warnedUserAboutProgram = true;
      var isValid = alertError(document.getElementById("element_MATCH_"+schoolList[0]), "Please select at least 1 Program." );
      highlightSchool(schoolList[0]);
      return isValid;
    } else {
      return true;
    }
}

function validate_FILTERMATCHLISTWarn() {
    var selectedProgramCount=0;
    if(filterAlreadySelected()) {
      return true;
    }
   // if we have seperate Match & PII, then reminder is not needed as it could appear on the wrong page
   if(typeof(setSeperateMatchAndPII) != 'undefined' && setSeperateMatchAndPII==true){
      return true;
   }
    var schoolList = readSchoolList();
    var fieldToShow = 0;
    for(i=0;i<schoolList.length;i++) {
        field = document.getElementById("element_MATCH_"+schoolList[i]);
        value = getFieldValueLB(field)
        if(validateIsRequired(value)) {
            selectedProgramCount++;
        } else if(fieldToShow == 0) {
            fieldToShow = i;
        }
    }
    
    if(warnedUserAboutProgram != true && ((selectedProgramCount == 1 && schoolList.length > 1) || (selectedProgramCount == 2 && schoolList.length >= 4))) {
      return warnSelectMorePrograms(document.getElementById("element_MATCH_"+schoolList[fieldToShow]), schoolList[fieldToShow], 
      "You have more options available and can select a program for each matching school.");
    } else {
      return true;
    }
}


function validate_DDI_AOS_01() {
    var cbField = window.document.form1.DDI_AOS_01;
    var isFind = false;
    for(var i=0;i<cbField.length;i++) {
        if(cbField[i].checked) {
            isFind = true;
        }
    }
    if (!isFind) {
      if(window.document.form1.career_display_for_aos){
	    alertError(window.document.form1.career_display_for_aos, "Please select a Career of Interest"); // Added for LDG-65
      }else{
	    alertError(window.document.form1.DDI_AOS_01[0], "Please Select an Area of Study");
      }
      return false;
    }
    else {
     return true;
    }
}

function validate_DDI_AGE_01() {
    field = window.document.form1.DDI_AGE_01;
    value = getFieldValueLB(field)
    if(!validateIsRequired(value)) {
      return alertError(field, "Please indicate your age." );
    }
    return true;
}

function validate_DDI_GRADYEAR_01() {
    field = window.document.form1.DDI_GRADYEAR_01;
    value = getFieldValueLB(field)
    if(!validateIsRequired(value)) {
        return alertError(field, "Please indicate the year you graduated." );
    }
    if ("9999" == value) {
      formSubmitted = true;
      window.document.form1.submit();
    }
    return true;
}

function validate_DDI_COUNTRY_01() {
    field = window.document.form1.COUNTRY_01;
    value = getFieldValueRB(field);
	if (!validateIsRequired(value)) {
	   return alertError(field, "Please indicate what Country you reside in." );
	}
    if (!("USA" == value) && !("CAN" == value)) {
      formSubmitted = true;
      window.document.form1.submit();
    }
    return true;
}

function notUSAOrCanCountry() {
  formSubmitted = true;
  window.document.form1.submit();
    
  return true;
}
function validate_ZIP_01(form) {
    value = getFieldValueTF(form.ZIP_01);
    if(!validateIsRequired(value)) {
        return alertError(form.ZIP_01,  "Please enter a valid Zip Code." );
    } 
    
    countryValue = getCountryValue(window.document.form1.COUNTRY_01);
    if(countryValue == "USA") {
        if(!isUSZip(value)) {
            return alertError(form.ZIP_01,  "Please enter a valid Zip Code." );
        }
    } else if(countryValue == "CAN") {
        if(!isCANZip(value)) {
            return alertError(form.ZIP_01,  "Please enter a valid Zip Code." );
        }
    }
    return true;
}

function validate_DDI_EDUCATION_01() {
    field = window.document.form1.DDI_EDUCATION_01;
    value = getFieldValueLB(field)
    if(!validateIsRequired(value)) {
        return alertError(field, "Please indicate your level of Education." );
    }

    return true;
}
function validate_DDI_MILITARYBRANCH_01() {
    field = window.document.form1.DDI_MILITARYBRANCH_01;
    value = getFieldValueLB(field)
    if(!validateIsRequired(value)) {
        return alertError(field, "Please indicate Military status." );
    }
    return true;
}

function validate_PROVINCE_01(form) {
    var countryValue = getCountryValue(window.document.form1.COUNTRY_01);
    if(countryValue == "USA" || countryValue == "CAN") {
        return true;
    }
    var value = getFieldValueTF(form.PROVINCE_01)
    if(!validateIsRequired(value)) {
       return alertError(form.PROVINCE_01, "Please select your State or Province." );
    }
    return true;
}

function validate_DDI_START_PERIOD_01() {
    field = window.document.form1.DDI_START_PERIOD_01;
    value = getFieldValueLB(field)
    if(!validateIsRequired(value)) {
        return alertError(field, "Please indicate when you plan to enroll." );
    }

    return true;
}

function validate_DDI_EARN_YEARLY_01() {
    field = window.document.form1.DDI_EARN_YEARLY_01;
    value = getFieldValueLB(field)
    if(!validateIsRequired(value)) {
        return alertError(field, "Please select how much would you like to earn per year." );
    }

    return true;
}

function validate_PHONE_DAY_COUNTRY_01(form) {
    var countryValue = getCountryValue(window.document.form1.COUNTRY_01);
    if(countryValue == "USA" || countryValue == "CAN") {
        return true;
    }
    var field = window.document.form1.PHONE_DAY_COUNTRY_01;
    var value = getFieldValueTF(field);
    if(!validateIsRequired(value)) {
        return alertError(field, "Please enter a valid preferred phone number." );
    }
    return true;
}

function validate_PHONE_EVENING_COUNTRY_01(form) {
    var countryValue = getCountryValue(window.document.form1.COUNTRY_01);
    if(countryValue == "USA" || countryValue == "CAN") {
        return true;
    }
    var field = window.document.form1.PHONE_EVENING_COUNTRY_01;
    var value = getFieldValueTF(field);
    if(!validateIsRequired(value)) {
        return alertError(field, "Please enter a valid alternate phone number." );
    }
    return true;
}

function validate_PHONE_ALTERN_01(form) {
    var value = getFieldValueTF(form.PHONE_EVENING_PREFIX_01) + getFieldValueTF(form.PHONE_EVENING_SUFFIX_01);
    
    return validate_PHONE_EVENING_01_with_params(form, value, form.PHONE_EVENING_PREFIX_01, "Please enter a valid alternate phone number.");
}

function validate_PHONE_PREF_01(form) {
    var value = getFieldValueTF(form.PHONE_DAY_PREFIX_01) + getFieldValueTF(form.PHONE_DAY_SUFFIX_01);
    
    return validate_PHONE_DAY_01_with_params(form, value, form.PHONE_DAY_PREFIX_01, "Please enter a valid preferred phone number.");
}

function validateDayPhone(form) {
  if(!validate_PHONE_DAY_COUNTRY_01(form)) {
    return false;
  } else if(!validate_PHONE_DAY_AREA_01_with_messages(form, "Please enter your Area Code.", "Please enter a valid preferred phone number.")) {
    return false;
  } else if (!validate_PHONE_PREF_01(form)) {
    return false;
  }
  
  return true;
}
function validateEvePhone(form) {
  if(!validate_PHONE_EVENING_COUNTRY_01(form)) {
    return false;
  } else if(!validate_PHONE_EVENING_AREA_01_with_messages(form, "Please enter your Area Code.", "Please enter a valid alternate phone number.")) {
    return false;
  } else if (!validate_PHONE_ALTERN_01(form)) {
    return false;
  }
  
  return true;
}

var isAskEnterDayPhone = false;
var isAskEnterEvePhone = true; // set to true so that the dialog box requesting eve phone doesn't show up

function validatePhones(form) {
      var valid = true;
      var phoneDayParts = ["PHONE_DAY_AREA_01", "PHONE_DAY_PREFIX_01", "PHONE_DAY_SUFFIX_01"];
      dayPhone = 0;
      for (i=0;i<phoneDayParts.length;++i) {
        fieldObj = form.elements.namedItem(phoneDayParts[i]);
        dayPhone += (fieldObj && fieldObj.value && fieldObj.value.length>0)? 1: 0;
      }
      
      var phoneEveParts = ["PHONE_EVENING_AREA_01", "PHONE_EVENING_PREFIX_01", "PHONE_EVENING_SUFFIX_01"];
      evePhone = 0;
      for (i=0;i<phoneEveParts.length;++i) {
        fieldObj = form.elements.namedItem(phoneEveParts[i]);
        evePhone += (fieldObj && fieldObj.value && fieldObj.value.length>0)? 1: 0;
      }

      if (0 == dayPhone && 0 == evePhone) { //there is nothing in all fields
          return alertError(form.PHONE_DAY_AREA_01, "Please enter your preferred phone number." );
      }
      else {
          if (dayPhone > 0 && 0 == evePhone) {
            valid = validateDayPhone(form);
            if (valid && !isAskEnterEvePhone) {
              var isValid = alertError(form.PHONE_DAY_AREA_01, "Please enter your alternate phone number.");
              isAskEnterEvePhone = true;
              return isValid;
            }
          }
          else if (evePhone > 0 && 0 == dayPhone) {
            valid = validateEvePhone(form);
            if (valid && !isAskEnterDayPhone) {
              var isValid = alertError(form.PHONE_DAY_AREA_01, "Please enter your preferred phone number.");
              isAskEnterDayPhone = true;
              return isValid;
            }
          } else {
            valid = validateDayPhone(form);
            if (valid) {
              valid = validateEvePhone(form);
            }
          }
      }

      return valid;
}

function validate_CONFIRM_CONTACT() {
    var cbField = window.document.form1.confirm_contact;
    if(cbField) {
      if(cbField.checked == false) {
        return alertError(window.document.form1.confirm_contact, "Please check the box indicating your acknowledgment to be contacted.");
      }
    }
    return true;
}

function showUSStates() {
    var stateField = window.document.form1.STATE_01;
    stateField.enabled = true;
    stateField.length=0;
    stateField.options[stateField.length] = new Option("Select State","");    
    stateField.options[stateField.length] = new Option("Alabama","AL");
    stateField.options[stateField.length] = new Option("Alaska","AK");
    stateField.options[stateField.length] = new Option("American Samoa ","AS");
    stateField.options[stateField.length] = new Option("Arizona","AZ");
    stateField.options[stateField.length] = new Option("Arkansas","AR");
    stateField.options[stateField.length] = new Option("Armed Forces Americas","AA");
    stateField.options[stateField.length] = new Option("Armed Forces Canada","AE");
    stateField.options[stateField.length] = new Option("Armed Forces Europe","AE");
    stateField.options[stateField.length] = new Option("Armed Forces Middle East","AE");
    stateField.options[stateField.length] = new Option("Armed Forces Pacific","AP");
    stateField.options[stateField.length] = new Option("California","CA");
    stateField.options[stateField.length] = new Option("Colorado","CO");
    stateField.options[stateField.length] = new Option("Connecticut","CT");
    stateField.options[stateField.length] = new Option("Delaware","DE");
    stateField.options[stateField.length] = new Option("District of Columbia","DC");
    stateField.options[stateField.length] = new Option("Florida","FL");
    stateField.options[stateField.length] = new Option("Georgia","GA");
    stateField.options[stateField.length] = new Option("Guam","GU");
    stateField.options[stateField.length] = new Option("Hawaii","HI");
    stateField.options[stateField.length] = new Option("Idaho","ID");
    stateField.options[stateField.length] = new Option("Illinois","IL");
    stateField.options[stateField.length] = new Option("Indiana","IN");
    stateField.options[stateField.length] = new Option("Iowa","IA");
    stateField.options[stateField.length] = new Option("Kansas","KS");
    stateField.options[stateField.length] = new Option("Kentucky","KY");
    stateField.options[stateField.length] = new Option("Louisiana","LA");
    stateField.options[stateField.length] = new Option("Maine","ME");
    stateField.options[stateField.length] = new Option("Maryland","MD");
    stateField.options[stateField.length] = new Option("Massachusetts","MA");
    stateField.options[stateField.length] = new Option("Michigan","MI");
    stateField.options[stateField.length] = new Option("Minnesota","MN");
    stateField.options[stateField.length] = new Option("Mississippi","MS");
    stateField.options[stateField.length] = new Option("Missouri","MO");
    stateField.options[stateField.length] = new Option("Montana","MT");
    stateField.options[stateField.length] = new Option("Nebraska","NE");
    stateField.options[stateField.length] = new Option("Nevada","NV");
    stateField.options[stateField.length] = new Option("New Hampshire","NH");
    stateField.options[stateField.length] = new Option("New Jersey","NJ");
    stateField.options[stateField.length] = new Option("New Mexico","NM");
    stateField.options[stateField.length] = new Option("New York","NY");
    stateField.options[stateField.length] = new Option("North Carolina","NC");
    stateField.options[stateField.length] = new Option("North Dakota","ND");
    stateField.options[stateField.length] = new Option("Northern Mariana Islands","MP");
    stateField.options[stateField.length] = new Option("Ohio","OH");
    stateField.options[stateField.length] = new Option("Oklahoma","OK");
    stateField.options[stateField.length] = new Option("Oregon","OR");
    stateField.options[stateField.length] = new Option("Palau","PW");
    stateField.options[stateField.length] = new Option("Pennsylvania","PA");
    stateField.options[stateField.length] = new Option("Puerto Rico","PR");
    stateField.options[stateField.length] = new Option("Rhode Island","RI");
    stateField.options[stateField.length] = new Option("South Carolina","SC");
    stateField.options[stateField.length] = new Option("South Dakota","SD");
    stateField.options[stateField.length] = new Option("Tennessee","TN");
    stateField.options[stateField.length] = new Option("Texas","TX");
    stateField.options[stateField.length] = new Option("U.S. Virgin Islands","VI");
    stateField.options[stateField.length] = new Option("Utah","UT");
    stateField.options[stateField.length] = new Option("Vermont","VT");
    stateField.options[stateField.length] = new Option("Virginia","VA");
    stateField.options[stateField.length] = new Option("Washington","WA");
    stateField.options[stateField.length] = new Option("West Virginia","WV");
    stateField.options[stateField.length] = new Option("Wisconsin","WI");
    stateField.options[stateField.length] = new Option("Wyoming","WY");
}

function showCANStates() {
    var stateField = window.document.form1.STATE_01;
    stateField.enabled = true;
    stateField.length=0;
    stateField.options[stateField.length] = new Option("Select State","");
    stateField.options[stateField.length] = new Option("Alberta","AB");
    stateField.options[stateField.length] = new Option("British Columbia","BC");
    stateField.options[stateField.length] = new Option("Manitoba","MB");
    stateField.options[stateField.length] = new Option("New Brunswick","NB");
    stateField.options[stateField.length] = new Option("Newfoundland","NF");
    stateField.options[stateField.length] = new Option("Northwest Territories","NT");
    stateField.options[stateField.length] = new Option("Nova Scotia","NS");
    stateField.options[stateField.length] = new Option("Ontario","ON");
    stateField.options[stateField.length] = new Option("Prince Edward Island","PE");
    stateField.options[stateField.length] = new Option("Quebec","QC");
    stateField.options[stateField.length] = new Option("Saskatchewan","SK");
    stateField.options[stateField.length] = new Option("Yukon Territory","YT");
    }

function initState() {
	if (window.document.form1.COUNTRY_01) {
        var countryValue = getCountryValue(window.document.form1.COUNTRY_01);
    	var stateField = window.document.form1.STATE_01;
    	var value = getFieldValueLB(stateField);
    	if(countryValue == "USA") {
     		showUSStates();
     		show("div_STATE_01");
     		hide("div_PROVINCE_01");
    	} else if (countryValue == "CAN") {
        	showCANStates();
        	show("div_STATE_01");
        	hide("div_PROVINCE_01");
    	}  else {
        	hide("div_STATE_01");
        	show("div_PROVINCE_01");
        	stateField.length=0;
    		stateField.options[stateField.length] = new Option("Select State","");    
        	stateField.disabled = true;
       	 	return;
    	}
    	selectValue(stateField,value);
    	stateField.disabled = false;
    	return;
    }
}

function filterHighestEd() {
    var gradYr = getFieldValueLB(window.document.form1.DDI_GRADYEAR_01);
    if (gradYr == '9999') {
    	formSubmitted = true;
        window.document.form1.submit();
    }
    
    var eduLevel = getFieldValueLB(window.document.form1.DDI_EDUCATION_01);
    if (eduLevel == 'none') {
    	formSubmitted = true;
    	window.document.form1.submit();
    }
    return;
}

function selectValue(field, value) {
    for (var i = 0; i < field.options.length; i++) {
        if (field.options[i].value == value) {
        field.options[i].selected = true
                return;
        }
    }
    return;
}

function selectValueRB(field, value) {
    for (var i = 0; i < field.length; i++) {
        if (field[i].value == value) {
            field[i].checked = true;
            return;
        }
    }
    return;
}

function getFieldValueRB ( field )
{
    if(field.value) {
      return field.value;
    }
    for (i = 0; i < field.length; i++)
    {
        if (field[i].checked == true) return field[i].value;
    } 
    return "";
}

function PageQuery(q) {
  if(q.length > 1) this.q = q.substring(1, q.length);
  else this.q = null;
  this.keyValuePairs = new Array();
  if(q) {
    for(var i=0; i < this.q.split("&").length; i++) {
      this.keyValuePairs[i] = this.q.split("&")[i];
    }
  }
  this.getKeyValuePairs = function() { return
  this.keyValuePairs; }
  this.getValue = function(s) {
    for(var j=0; j < this.keyValuePairs.length; j++) {
      if(this.keyValuePairs[j].split("=")[0] == s) {
        if(this.keyValuePairs[j].split("=").length>1)
        {
          return this.keyValuePairs[j].split("=")[1];
        }
      }
    }
    return "";
  }
  this.getParameters = function() {
    var a = new Array(this.getLength());
    for(var j=0; j < this.keyValuePairs.length; j++) {
      a[j] = this.keyValuePairs[j].split("=")[0];
    }
    return a;
  }
  this.getLength = function() { return
  this.keyValuePairs.length; }
}

function queryString(key){
  var page = new PageQuery(window.location.search);
  return unescape(page.getValue(key));
}

var templateStyle = '001';
var enableOCC = false;

function getLineTypeHeadline(){
  if(enableOCC) {
    var occType = queryString("_OCC");
    if(occType == 'accountant') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occAccountant'+'.g'+'if" />';
    } else if (occType == 'bounty hunter') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occBounty'+'.g'+'if" />';
    } else if (occType == 'chef') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occChef'+'.g'+'if" />';
    } else if (occType == 'counselor') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occCounselor'+'.g'+'if" />';
    } else if (occType == 'cpa') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occCPA'+'.g'+'if" />';
    } else if (occType == 'criminal investigator') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occCriminal'+'.g'+'if" />';
    } else if (occType == 'database administrator') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occDatabase'+'.g'+'if" />';
    } else if (occType == 'detective') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occDetective'+'.g'+'if" />';
    } else if (occType == 'developer') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occDeveloper'+'.g'+'if" />';
    } else if (occType == 'engineer') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occEngineer'+'.g'+'if" />';
    } else if (occType == 'financier') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occFinancier'+'.g'+'if" />';
    } else if (occType == 'graphic designer') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occGraphic'+'.g'+'if" />';
    } else if (occType == 'healthcare manager') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occHealthcare'+'.g'+'if" />';
    } else if (occType == 'HR officer') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occHuman'+'.g'+'if" />';
    } else if (occType == 'manager') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occManager'+'.g'+'if" />';
    } else if (occType == 'marketer') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occMarketer'+'.g'+'if" />';
    } else if (occType == 'network specialist') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occNetwork'+'.g'+'if" />';
    } else if (occType == 'paralegal') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occParalegal'+'.g'+'if" />';
    } else if (occType == 'patient advocate') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occPatient'+'.g'+'if" />';
    } else if (occType == 'police') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occPolice'+'.g'+'if" />';
    } else if (occType == 'project manager') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occProject'+'.g'+'if" />';
    } else if (occType == 'psychologist') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occPsychologist'+'.g'+'if" />';
    } else if (occType == 'sales person') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occSales'+'.g'+'if" />';
    } else if (occType == 'social worker') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occSocial'+'.g'+'if" />';
    } else if (occType == 'software professional') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occSoftware'+'.g'+'if" />';
    } else if (occType == 'teacher') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occTeacher'+'.g'+'if" />';
    } else if (occType == 'therapist') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occTherapist'+'.g'+'if" />';
    } else if (occType == 'psychologist') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occPsychologist'+'.g'+'if" />';
    } else if (occType == 'developer') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occDeveloper'+'.g'+'if" />';
    } else if (occType == 'detective') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occDetective'+'.g'+'if" />';
    } else if (occType == 'medical billing specialist') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occMedicalBilling'+'.g'+'if" />';
    } else if (occType == 'medical officer manager') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occMedicalOfficer'+'.g'+'if" />';
    } else if (occType == 'medical coding specialist') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occMedicalCoding'+'.g'+'if" />';
    } else if (occType == 'pharmacy technician') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_occPharmacy'+'.g'+'if" />';
    }
  }

  var aosType = queryString("_AOS");
  if(aosType == 'business') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accBusiness'+'.g'+'if" />';
  } else if(aosType == 'computer science') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accComputer'+'.g'+'if" />';
  } else if(aosType == 'criminal justice') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accCriminal'+'.g'+'if" />';
  } else if(aosType == 'culinary arts') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accCulinary'+'.g'+'if" />';
  } else if(aosType == 'graphic design') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accDesign'+'.g'+'if" />';
  } else if(aosType == 'education') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accEducation'+'.g'+'if" />';
  } else if(aosType == 'health and human services') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accHealth'+'.g'+'if" />';
  } else if(aosType == 'nursing') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accNursing'+'.g'+'if" />';
  } else if(aosType == 'science and engineering') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accScience'+'.g'+'if" />';
  } else if(aosType == 'psychology') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accPsychology'+'.g'+'if" />';
  } else if(aosType == 'liberal arts') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accLiberalArts'+'.g'+'if" />';
  } else if(aosType == 'technology') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accInformationTech'+'.g'+'if" />';
  } else if(aosType == 'culinary arts') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accCulinary'+'.g'+'if" />';
  } else if(aosType == 'medical') {
    return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accMedical'+'.g'+'if" />';
  } else {
    var levType = queryString("_LEV");
    if(levType == 'associates') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accAssociates'+'.g'+'if" />';
    } else if(levType == 'certificates') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accCertificates'+'.g'+'if" />';
    } else if(levType == 'bachelors') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accBachelors'+'.g'+'if" />';
    } else if(levType == 'masters') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accMasters'+'.g'+'if" />';
    } else if(levType == 'doctoral') {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accDoctorate'+'.g'+'if" />';
    } else {
      return '<im'+'g sr'+'c="/images/degreesInfo/'+templateStyle+'/headline_accelerate'+'.g'+'if" />';
    }
  }
}

function initField(field, value) {
    if(field[0].type == 'radio')
        setFieldValueRB(field, value);
    else if(field[0].type == 'text')
        setFieldValueTF(field[0], value);
    else if(field[0].type == 'select-one')
        setFieldValueLB(field[0], value);
    else if(field[0].type == 'checkbox')
        setFieldValueCB(field, value);
    else if(field[0].type == 'hidden')
        setFieldValueTF(field[0], value); 
    else {
        return;
    }
    
    if(field[0].onclick != undefined && field[0].onclick != null)
        field[0].onclick();
    if(field[0].onchange != undefined && field[0].onchange != null)
        field[0].onchange();
}

function initParams() {
    var relation = new Array();
    relation['web design'] = "graphic design";// if web design will be in the url we will use graphic design
    relation['arts'] = "graphic design";
    var urlParamMap = new Array();
    urlParamMap['_AOS'] = "DDI_AOS_01";
    
    var q = window.location.search;
    
	if(q != null && q.length > 1) {
        q = q.substring(1, q.length);
        var keyValuePairs = q.split("&");
        for(var index=0; index < keyValuePairs.length; index++) {
            var delim = keyValuePairs[index].indexOf("=");
            if(delim > 0 && delim < (keyValuePairs[index].length - 1)) {
                var name = keyValuePairs[index].substring(0,delim);
                var value = keyValuePairs[index].substring(++delim,keyValuePairs[index].length);
                value = replaceSpecialSymbols(value);
                if (relation[value]) {
                	value = relation[value];
                }
                if (urlParamMap[name]) {
                	name = urlParamMap[name];
                }
                var field = window.document.getElementsByName(name);
                if(field != null && field.length > 0)
                    initField(field, value);
            }
        }
    }
}
function replaceSpecialSymbols(value) {
 if (value && value.length) {
  var re = /%20/gi;
  value = value.replace(re, " ");
  re = /\+/gi;
  value = value.replace(re, " ");
  re = /%25/gi;
  value = value.replace(re, "%");
  re = /%26/gi;
  value = value.replace(re, "&");
  re = /%A9/gi;
  value = value.replace(re, "@");
  re = /%3B/gi;
  value = value.replace(re, ";");
  re = /%3C/gi;
  value = value.replace(re, "<");
  re = /%3E/gi;
  value = value.replace(re, ">");
 }
 return value;
}

function getDivByField(field) {
  if(field=='DDI_AGE_01') {
    return "div_DDI_AGE";
  } else if(field=='DDI_GRADYEAR_01') {
    return "div_DDI_GRADYEAR";
  } else if(field=='DDI_AOS_01') {
    return "div_DDI_AOS";
  } else if(field=='EMAIL_01') {
      var obj = document.getElementById("div_"+field);
      if (obj != undefined && obj != null) {
          return "div_"+field;
      }
      
      return "div_ZIP_01";
  } else {
    return "div_"+field;
  }
}

function showErrorQuestions() {
//ZIP and email are validated together so if both are errors only use one.
  var emailError = false;
  var zipError = false;
  
  for(i=0;i<errors.length;i++) {
    if(errors[i]=='EMAIL_01') {
      emailError=true;
     } else if(errors[i]=='ZIP_01') {
      zipError=true;
     }
  }
  showHideQ(null, 0);
  var group = [];
  if (window.qListGroups) {
     window.qListGroups.length = 0;
  } else {
    qListString.length = 0;
  }
  
  for(i=0;i<errors.length;i++) {
    if (window.qListGroups) {
      //alert(errors[i]);
//      window.qListGroups[0][window.qListGroups[0].length] = getDivByField(errors[i]);
      group[group.length] = getDivByField(errors[i]);
    } else {
      if(zipError == true && emailError == true && errors[i] == 'EMAIL_01') {
      } else {
        var fieldIndex = qListString.length;
        qListString[fieldIndex] = getDivByField(errors[i]);
        resetFieldQuestion(qListString[fieldIndex]);
      }
    }
  }
  
  if(window.qListGroups) {
	 window.qListGroups[0] = group;
  }
  
  showHideQ(0, null);
}
function resetFields() {
    if(errors && errors.length > 0) {
        showErrorQuestions();
        return;
    }
    isReset = false;
    if (!window.dhtmlHistoryDisabled && window.dhtmlHistory && window.dhtmlHistory.currentLocation && !window.qListGroups) {//reset all fields greater than currentLocation question
       window.inReset = true;
       currentQ=parseInt(dhtmlHistory.currentLocation.substring(2));
       if(!isNaN(currentQ)) {
         for(var i=currentQ;i<qListString.length;++i) {
           resetFieldQuestion(qListString[i]);
         }
       }
       
      isReset = true;
    }
    if (window.qListGroups) {//do not reset for groups
      window.inReset = true;
      isReset = true;
    }
    if (!isReset) {
    if (window.document.form1.DDI_AGE_01)
      window.document.form1.DDI_AGE_01.options[0].selected = true;
    if (window.document.form1.DDI_GRADYEAR_01)
      window.document.form1.DDI_GRADYEAR_01.options[0].selected = true;
    if (window.document.form1.DDI_EDUCATION_01)
      window.document.form1.DDI_EDUCATION_01.options[0].selected = true;
    if (window.document.form1.COUNTRY_01)
      window.document.form1.COUNTRY_01[0].checked = false;
      window.document.form1.COUNTRY_01[1].checked = false;
      window.document.form1.COUNTRY_01[2].checked = false;
    if (window.document.form1.USCITIZEN_01) {
      window.document.form1.USCITIZEN_01[0].checked = false;
      window.document.form1.USCITIZEN_01[1].checked = false;
    }
    if (window.document.form1.DDI_MILITARYBRANCH_01)
      window.document.form1.DDI_MILITARYBRANCH_01.options[0].selected = true;
      
    if (window.document.form1.DDI_START_PERIOD_01) {
      window.document.form1.DDI_START_PERIOD_01.options[0].selected = true;
    }
    if (window.document.form1.DDI_EARN_YEARLY_01) {
      window.document.form1.DDI_EARN_YEARLY_01.options[0].selected = true;
    }
    }
}

//function resetThisFieldValue(index) {
//    if(qListString[index] == 'div_DDI_AGE') {
//        window.document.form1.DDI_AGE_01.options[0].selected = true;
//    } else if(qListString[index] == 'div_DDI_GRADYEAR') {
//        window.document.form1.DDI_GRADYEAR_01.options[0].selected = true;
//    } else if(qListString[index] == 'div_DDI_EDUCATION_01') {
//        window.document.form1.DDI_EDUCATION_01.options[0].selected = true;
//    } else if(qListString[index] == 'div_DDI_START_PERIOD_01') {
//        window.document.form1.DDI_START_PERIOD_01.options[0].selected = true;
//    } else if(qListString[index] == 'div_DDI_EARN_YEARLY_01') {
//        window.document.form1.DDI_EARN_YEARLY_01.options[0].selected = true;
//    } else if(qListString[index] == 'div_COUNTRY_01') {
//        window.document.form1.COUNTRY_01[0].checked = false;
//        window.document.form1.COUNTRY_01[1].checked = false;
//        window.document.form1.COUNTRY_01[2].checked = false;
//    } else if(qListString[index] == 'div_USCITIZEN_01') {
//        window.document.form1.USCITIZEN_01[0].checked = false;
//        window.document.form1.USCITIZEN_01[1].checked = false;
//    } else if(qListString[index] == 'div_DDI_MILITARYBRANCH_01') {
//        window.document.form1.DDI_MILITARYBRANCH_01.options[0].selected = true;
//    }
//}

function resetFieldQuestion(divId) {
    if(divId == 'div_DDI_AGE') {
        window.document.form1.DDI_AGE_01.options[0].selected = true;
    } else if(divId == 'div_DDI_GRADYEAR') {
        window.document.form1.DDI_GRADYEAR_01.options[0].selected = true;
    } else if(divId == 'div_DDI_EDUCATION_01') {
        window.document.form1.DDI_EDUCATION_01.options[0].selected = true;
    } else if(divId == 'div_DDI_START_PERIOD_01') {
        window.document.form1.DDI_START_PERIOD_01.options[0].selected = true;
    } else if(divId == 'div_DDI_EARN_YEARLY_01') {
        window.document.form1.DDI_EARN_YEARLY_01.options[0].selected = true;
    } else if(divId == 'div_COUNTRY_01') {
        window.document.form1.COUNTRY_01[0].checked = false;
        window.document.form1.COUNTRY_01[1].checked = false;
        window.document.form1.COUNTRY_01[2].checked = false;
    } else if(divId == 'div_USCITIZEN_01') {
        window.document.form1.USCITIZEN_01[0].checked = false;
        window.document.form1.USCITIZEN_01[1].checked = false;
    } else if(divId == 'div_DDI_MILITARYBRANCH_01') {
        window.document.form1.DDI_MILITARYBRANCH_01.options[0].selected = true;
    }
}

function resetFieldValue() {
	if(window.qListGroups) {
		resetFieldQuestion(window.qListGroups[curQ]);
	}
	else if(qListString){
		resetFieldQuestion(qListString[curQ]);
	}
}

function highlightSubmissionError(field,message)
{
    var ancestor = field.parentNode;
    if (!ancestor) return false;
    if(field.name.indexOf('PHONE_DAY_')==0 || field.name.indexOf('PHONE_EVENING_')==0) {
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
    }
    if(field.name.indexOf('DDI_AOS_01')==0) {
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
    }
    if(!isErrorClass(ancestor)) {
        addErrorClass(ancestor);
        var errorMessage = document.createElement("span");
        errorMessage.id=field.name+"_errorMsg";
        errorMessage.className='warning';
        errorMessage.innerHTML = '<br>'+message;
        ancestor.appendChild(errorMessage);
    }
  if (window.formFamily && window.formFamily == "DegreesInfo") {
    var fieldName = "UNKNOWN";
    
    if (field) {
        if (field.length && field.length >0 && field[0].name && field[0].name!=null) {
          fieldName = field[0].name;
        }
        else if (field.name && field.name!=null){
          fieldName = field.name;
        }
    }
    
    ValidationTracker.trackAlert(fieldName, message);
  }
    
}

function removeSubmissionError(field)
{
    var ancestor = field.parentNode;
    if (!ancestor) return false;
    if(field.name.indexOf('PHONE_DAY_')==0 || field.name.indexOf('PHONE_EVENING_')==0) {
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
    }
    if(field.name.indexOf('DDI_AOS_01')==0) {
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
        ancestor = ancestor.parentNode;
    }
    if(isErrorClass(ancestor)) {
        removeErrorClass(ancestor);
    }
    elementToRemove=document.getElementById(field.name+"_errorMsg");
    if(elementToRemove) {
      ancestor.removeChild(elementToRemove);
    }
}

function addErrorClass(element) {
  if(element)
  {
    element.className+=element.className?' ddierror':'ddierror';
  }
}

function removeErrorClass(element) {
  if(element)
  {
    if(element.className) {
      var rep=element.className.match(' ddierror')?' ddierror':'ddierror';
      element.className=element.className.replace(rep,'');
    }
  }
}

function isErrorClass(element) {
  if(element)
  {
    if(element.className) {
      return element.className.indexOf('ddierror')>=0;
    }
  }
}

function alertErrors() {
  for(i=0;i<errors.length;i++) {
    var yourElement = errors[i];
    var yourMessage = messages[i];
    highlightSubmissionError(yourElement,yourMessage);
  }
  
  return false;
}

function alertErrorsFromIds() {
  for(i=0;i<errors.length;i++) {
    var yourElement = document.getElementById(errors[i]);
    var yourElementToHide = document.getElementById(errors[i]+"_errorMsg2");
    if(yourElementToHide && yourElementToHide.className) {
      yourElementToHide.className='hidden';
    }
    errors[i]=yourElement;
  }
  
  return alertErrors();
}
function displayMatchAndHidePII() {
    // Change the match table to 'show' and PII table to 'hide', also make sure, the match tables button is visible ('show')
    if(document.getElementById("PIITable") == null) {
       return;
    }
    show("MatchTable");
    show("continueButton");
    hide("PIITable");
    hide("requestInfoTable");
}

function displayPIIAndHideMatch() {
    if(document.getElementById("MatchTable") == null) {
       return;
    }
    if(validate_FILTERMATCHLIST()){
        hide("MatchTable");
        hide("continueButton");
        show("PIITable");
        show("requestInfoTable");
        show("backbutton");
        return true;
    }else{
        return false;
    }
}
function clearErrors() {
  for(i=0;i<errors.length;i++) {
    var yourElement = errors[i];
    removeSubmissionError(yourElement);
  }
  errors =[];
  messages = [];
}

//overrides what is in validateFields.js
function alertError(field, message) {
  var fieldName = "UNKNOWN";
    
  if (field) {
      if (field.length && field.length >0 && field[0].name && field[0].name!=null) {
        fieldName = field[0].name;
      }
      else if (field.name && field.name!=null){
        fieldName = field.name;
      }
  }

  if(typeof(useInlineErrorMessages) != 'undefined' && useInlineErrorMessages==true) {
      errors[errors.length]=field;
      messages[messages.length]=message;
      return false;
  } else {
    alert(message);
    if (field) {
      if (field.focus) {
        field.focus();
      }
    }
  }
  if (window.formFamily && window.formFamily == "DegreesInfo") {
    ValidationTracker.trackAlert(fieldName, message);
  }
  return false;
}

function updateProgressBar()
{
    if(curQ==0) {
       hide("backbutton");
    } else {
       show("backbutton");
    }

    divProgress = window.document.getElementById("div_progress");
    if (window.qListGroups) {
      divProgress.style.width = Math.round(curQ/window.qListGroups.length * 100) + "%";
    }
    else {
       divProgress.style.width = Math.round(curQ/qListString.length * 100) + "%";
    }
}

function hideZipCodeField() {
	var zipErrorOn = false;
 	if(errors) {
			var errorIndex = errors.length - 1;
			while(errorIndex >= 0 && !zipErrorOn) {
				if(errors[errorIndex] == "ZIP_01") {
					zipErrorOn = true;	
				}

				errorIndex--;
			}
 	}
 	
	if(!zipErrorOn) {
      	hide("HIDDEN_ZIP_01");
	}
}

function isZipCodeVisible() {
	return isVisible("HIDDEN_ZIP_01");
}

function hideEmailField(pageNumber) {
	var emailPageNo = document.getElementsByName("EMAIL_PAGE_NO");
	if(emailPageNo && emailPageNo.length > 0) {
		emailPageNo = emailPageNo[0].value;
	}

	if(emailPageNo != pageNumber) {
		hide("div_EMAIL_01");	
	}
}

function isEmailVisible() {
	return isVisible("div_EMAIL_01");
}

function initializeGroups(groupMatrix) {
	if(!groupMatrix) {
		return;
	}

	var nextButtonId = "div_NEXT_BTN";
	//ATTACH next button and remove ONCHANGE events where necessary
	for(var i = 0; i < groupMatrix.length; i++) {
		var group = groupMatrix[i]

		//if group has several elements, add Next button and remove onchange/onclick events
		if(group.length > 1) {
			for(var j = 0; j < group.length; j++) {
				removeEvents(group[j]);
			}
			group[group.length] = nextButtonId;
		} 
		//else if group has a single element, add Next button if required, keep onchange events
		else if(group.length == 1) {
			if(isNextBtnRequired(group[0])) {
				group[group.length] = nextButtonId;
			}
		}
	}

	//Show first group elements
	firstGroup = groupMatrix[0];
	for(var i = 0; i < firstGroup.length; i++) {
		var div = document.getElementById(firstGroup[i]);
		if(div) {
			div.className = div.className.replace(/hidden/, "visible"); 
		}
	}
	
	qListString = null;
}	

function removeEvents(divId) {
	var fields = getFieldsWithinDiv(divId);
	for(var i = 0; i < fields.length; i++) {
		fields[i].onchange = null;
		fields[i].onclick = null;
	}
}

function isNextBtnRequired(divId) {
	var requiresBtn = false;
	
	if(divId == 'div_DDI_AOS' || divId == 'div_EMAIL_01' || divId == 'div_ZIP_01') {
		requiresBtn = true;
	}
	
	return requiresBtn;
}

function getFieldsWithinDiv(divId) {
	var fieldName = divId;
	if(fieldName.indexOf('_01') == -1) {
		fieldName = fieldName + '_01';
	}
	
	if(fieldName.indexOf('div_') == 0) {
		fieldName = fieldName.substring(4);
	}
	
	var fields = document.getElementsByName(fieldName);
	
	return fields;
}

function getFormField(fieldName) {
	return eval("window.document.form1." + fieldName);
}

//	if(hasRealGroups(groupMatrix)) {
//		window.qListGroups = groupMatrix;
//		qListString = null;
//	}
//	//it is a regular form_field_sequence
//	else {
//		qListString = convertGroupToSequence(groupMatrix);
//		window.qListGroups = null;
//	}



//function hasRealGroups(groupMatrix) {
//	var realGroupsExist = false;
//	//verify if there's at least one group with multiple elements
//	for(var i = 0; i < groupMatrix.length; i++) {
//		var groupI = groupMatrix[i];
//		if(groupI.length > 1) {
//			realGroupsExist = true;
//		}
//	}
//	
//	return realGroupsExist;
//}
//
//function convertGroupToSequence(groupMatrix) {
//	var sequence = [];
//	for(var i = 0; i < groupMatrix.length; i++) {
//		var groupI = groupMatrix[i];
//		sequence[i] = groupI[0];
//	}
//	
//	return sequence;
//}
