var step = 0; 
function toNxtStep(curStep, nextStep,ctl)
{    
    if(toNextStep(curStep, nextStep))
    {
        document.getElementById(ctl).disabled = true;
        return true;
    }
    else
        return false;
}
function toNextStep(curStep, nextStep) {

   var url = 'nextStep.asp'; 
   if(curStep == 0) {
      curStep = step; 
      }
   else {
      var readyToGo = checkStep(curStep); 
      if(!readyToGo) {
         return false; 
         }
      }
   var pars = "nextStep=" + nextStep + "&"; 
   pars += "curStep=" + curStep + "&"; 
   //for(i = 1; i <= 5; i ++) {
   // menuitem = document.getelementbyid("menu" + i);
   //if(i == nextstep) {
   // menuitem.classname = "formmenuitemon";
   //} else {
   // menuitem.classname = "formmenuitemoff";
   // }
   // }
  
   var form = document.forms[0]; 
   for(thing in form) {
      if(form[thing] != null) {
         if(form[thing].tagName == "INPUT") {
            if(form[thing].type == "text" || form[thing].type == "hidden") {
               fieldValue = form[thing].value; 
               var escapedValue = ""; 
               var escapedChar = 32; 
               for(i = 0; i <= fieldValue.length - 1; i++) {
                  if(fieldValue.charCodeAt(i) == 8216) {
                     //‘
                     escapedChar = 39; 
                     //'
                     }
                  else if(fieldValue.charCodeAt(i) == 8217) {
                     //’
                     escapedChar = 39; 
                     //'
                     }
                  else if(fieldValue.charCodeAt(i) == 8220) {
                     //“
                     escapedChar = 39; 
                     //'
                     }
                  else if(fieldValue.charCodeAt(i) == 8221) {
                     //”
                     escapedChar = 39; 
                     //'
                     }
                  else {
                     escapedChar = fieldValue.charCodeAt(i); 
                     }
                  escapedValue += String.fromCharCode(escapedChar); 
                  }
               pars += thing + "=" + escapedValue + "&"; 
               }
               
            }
             
         else if(form[thing].tagName == "TEXTAREA") {
            fieldValue = form[thing].value; 
            var escapedValue = ""; 
            var escapedChar = 32; 
            for(i = 0; i <= fieldValue.length - 1; i++) {
               if(fieldValue.charCodeAt(i) == 8216) {
                  //‘
                  escapedChar = 39; 
                  //'
                  }
               else if(fieldValue.charCodeAt(i) == 8217) {
                  //’
                  escapedChar = 39; 
                  //'
                  }
               else if(fieldValue.charCodeAt(i) == 8220) {
                  //“
                  escapedChar = 39; 
                  //'
                  }
               else if(fieldValue.charCodeAt(i) == 8221) {
                  //”
                  escapedChar = 39; 
                  //'
                  }
               else {
                  escapedChar = fieldValue.charCodeAt(i); 
                  }
               escapedValue += String.fromCharCode(escapedChar); 
               }
            pars += thing + "=" + escapedValue + "&"; 
            }
         }
      }
      
   return true;   
   }
function showResponse (originalRequest) {
    var myStep = 0; 
    var newData = originalRequest.responseText; 
    var haf = document.getElementById("theAppForm"); 
    haf.innerHTML = newData; 
   }
function checkStep(stepToCheck) {
   var labelTags = document.getElementsByTagName("label"); 
   for(curLabel in labelTags) {
      labelTags[curLabel].className = "validField"; 
      }
   if(stepToCheck == 1) {
      var FirstNameValid = highlightLabel("FirstName", textFieldValid("jobForm", "FirstName", "text")); 
      var LastNameValid = highlightLabel("LastName", textFieldValid("jobForm", "LastName", "text")); 
      var GenderValid = highlightLabel("Gender", textFieldValid("jobForm", "Gender", "text")); 
      var DateOfBirthValid = highlightLabel("DateOfBirth", textFieldValid("jobForm", "DateOfBirth", "date")); 
      var NationalityValid = highlightLabel("Nationality", textFieldValid("jobForm", "Nationality", "text")); 
      
      var PersonalEmailValid = highlightLabel("personalEmail", textFieldValid("jobForm", "personalEmail", "email")); 
      var UniversityEmailValid = highlightLabel("workEmail", textFieldValid("jobForm", "workEmail", "email")); 
      
      var CurrentAddr1Valid = highlightLabel("CurrentAddr1", textFieldValid("jobForm", "CurrentAddr1", "text")); 
      var CityValid = highlightLabel("City", textFieldValid("jobForm", "City", "text")); 
      var PostalCodeValid = highlightLabel("PostalCode", textFieldValid("jobForm", "PostalCode", "text")); 
      var CountryValid = highlightLabel("Country", textFieldValid("jobForm", "Country", "text")); 
      
      var telephoneValid = highlightLabel("telephone", textFieldValid("jobForm", "telephone", "telephone")); 
      var mobilephoneValid = highlightLabel("mobilephone", textFieldValid("jobForm", "mobilephone", "mobilephone")); 

      if(FirstNameValid && LastNameValid && GenderValid && DateOfBirthValid && NationalityValid && PersonalEmailValid && UniversityEmailValid && CurrentAddr1Valid && CityValid && PostalCodeValid && CountryValid && telephoneValid && mobilephoneValid ) {
         return true; 
         }
      else {
         return false; 
         }
      }
   else if(stepToCheck == 2) {
      var AppliedPositionValid = highlightLabel("AppliedPosition", textFieldValid("jobForm", "AppliedPosition", "text")); 
      var AvailableDateFromValid = highlightLabel("AvailableDateFrom", textFieldValid("jobForm", "AvailableDateFrom", "date")); 
      var AvailableDateToValid = highlightLabel("AvailableDateTo", textFieldValid("jobForm", "AvailableDateTo", "date")); 
      var DestinationTypeValid = highlightLabel("DestinationType", textFieldValid("jobForm", "DestinationType", "text")); 
      var locationPref1Valid = highlightLabel("locationPref1", textFieldValid("jobForm", "locationPref1", "text")); 
      var locationPref2Valid = highlightLabel("locationPref2", textFieldValid("jobForm", "locationPref2", "text")); 
      var locationPref3Valid = highlightLabel("locationPref3", textFieldValid("jobForm", "locationPref3", "text")); 
      var WorkedInEFValid = highlightLabel("WorkedInEF", textFieldValid("jobForm", "WorkedInEF", "text")); 
      if(AppliedPositionValid && AvailableDateFromValid && AvailableDateToValid && DestinationTypeValid && locationPref1Valid && locationPref2Valid && locationPref3Valid && WorkedInEFValid) {
         if(document.forms["jobForm"].elements["WorkedInEF"].value == "yes") {
            var WorkedWhereValid = highlightLabel("WorkedWhere", textFieldValid("jobForm", "WorkedWhere", "text")); 
            var WorkedWhenValid = highlightLabel("WorkedWhen", textFieldValid("jobForm", "WorkedWhen", "text")); 
            var WorkedPositionValid = highlightLabel("WorkedPosition", textFieldValid("jobForm", "WorkedPosition", "text")); 
            if(!WorkedWhereValid || !WorkedWhenValid || !WorkedPositionValid) {
               return false; 
               }
            }
         return true; 
         }
      else {
         return false; 
         }
      }
   else if(stepToCheck == 3) {
      var StudentValid = highlightLabel("Student", textFieldValid("jobForm", "Student", "text")); 
      if(document.forms["jobForm"].elements["Student"].value == "yes") {
         var studentYes = true; 
         var GraduateDateValid = highlightLabel("GraduateDate", textFieldValid("jobForm", "GraduateDate", "text")); 
         var UniversityValid = highlightLabel("University", textFieldValid("jobForm", "University", "text")); 
         var QualificationValid = highlightLabel("Qualification", textFieldValid("jobForm", "Qualification", "text")); 
         }
      else {
         var studentYes = false; 
         }
      var TEFLValid = highlightLabel("TEFL", textFieldValid("jobForm", "TEFL", "text")); 
       var TEFLCourse = highlightLabel("TEFLCourse", textFieldValid("jobForm", "TEFLCourse", "text")); 
    
      //var language1Valid = highlightLabel("language1",textFieldValid("jobForm","language1","text"));
      //var language2Valid = highlightLabel("language2",textFieldValid("jobForm","language2","text"));
      //var language3Valid = highlightLabel("language3",textFieldValid("jobForm","language3","text"));
      if(!document.forms["jobForm"].elements["FirstAid"].checked)
      {
      var FirstAidValid = highlightLabel("FirstAid", textFieldValid("jobForm", "FirstAid", "text")); 
      }
      if(document.forms["jobForm"].elements["FirstAid"].value == "yes") {
        if(!document.forms["jobForm"].elements["FirstAidExpiredDate"].checked)
         {
         var FirstAidYes = true; 
         var FirstAidExpiredDateValid = highlightLabel("FirstAidExpiredDate", textFieldValid("jobForm", "FirstAidExpiredDate", "date")); 
         }}
      else {
         var FirstAidYes = false; 
         }
         
          if(!document.forms["jobForm"].elements["LifeSaverQualification"].checked)
          {
      var LifeSaverQualificationValid = highlightLabel("LifeSaverQualification", textFieldValid("jobForm", "LifeSaverQualification", "text")); 
          }
      //alert(document.forms["jobForm"].elements["notyetsure_lifesaver"].checked);
      if(document.forms["jobForm"].elements["LifeSaverQualification"].value == "yes") {
      
          if(!document.forms["jobForm"].elements["LifeSaverExpiredDate"].checked)
         { var LifeSaverYes = true; 
         var LifeSaverExpiredDateValid = highlightLabel("LifeSaverExpiredDate", textFieldValid("jobForm", "LifeSaverExpiredDate", "date")); 
         }}
      else {
         var LifeSaverYes = false; 
         }
      var SportQualificationsValid = highlightLabel("SportQualifications", textFieldValid("jobForm", "SportQualifications", "text")); 
      var DrivingLicenseValid = highlightLabel("DrivingLicense", textFieldValid("jobForm", "DrivingLicense", "text")); 
      var OwnCarValid = highlightLabel("OwnCar", textFieldValid("jobForm", "OwnCar", "text")); 
      var MedicalConditionValid = highlightLabel("MedicalCondition", textFieldValid("jobForm", "MedicalCondition", "text")); 
      if(document.forms["jobForm"].elements["MedicalCondition"].value == "yes") {
         var MedicalConditionYes = true; 
         var MedicalCommentsValid = highlightLabel("MedicalComments", textFieldValid("jobForm", "MedicalComments", "text")); 
         }
      else {
         var MedicalConditionYes = false; 
         }
      var LeisureValid = highlightLabel("Leisure", textFieldValid("jobForm", "Leisure", "text")); 
      var ExperienceCommentsValid = highlightLabel("ExperienceComments", textFieldValid("jobForm", "ExperienceComments", "text")); 
      if(StudentValid && TEFLValid && FirstAidValid && LifeSaverQualificationValid && SportQualificationsValid && DrivingLicenseValid && OwnCarValid && MedicalConditionValid && LeisureValid && ExperienceCommentsValid) {
         if(studentYes) {
            if(!GraduateDateValid || !UniversityValid || !QualificationValid) {
               return false; 
               }
            }
         if(FirstAidYes) {
            if(!FirstAidExpiredDateValid) {
               return false; 
               }
            }
         if(LifeSaverYes) {
            if(!LifeSaverExpiredDateValid) {
               return false; 
               }
            }
         if(MedicalConditionYes) {
            if(!MedicalCommentsValid) {
               return false; 
               }
            }
         return true; 
         }
      else {
         return false; 
         }
      }
   else if(stepToCheck == 4) {
      var Ref1_FirstNameValid = highlightLabel("Ref1_FirstName", textFieldValid("jobForm", "Ref1_FirstName", "text")); 
      var Ref1_LastNameValid = highlightLabel("Ref1_LastName", textFieldValid("jobForm", "Ref1_LastName", "text")); 
      var Ref1_EmailValid = highlightLabel("Ref1_Email", textFieldValid("jobForm", "Ref1_Email", "email")); 
      var Ref1_TelephoneValid = highlightLabel("Ref1_Telephone", textFieldValid("jobForm", "Ref1_Telephone", "number")); 
      var Ref2_FirstNameValid = highlightLabel("Ref2_FirstName", textFieldValid("jobForm", "Ref2_FirstName", "text")); 
      var Ref2_LastNameValid = highlightLabel("Ref2_LastName", textFieldValid("jobForm", "Ref2_LastName", "text")); 
      var Ref2_EmailValid = highlightLabel("Ref2_Email", textFieldValid("jobForm", "Ref2_Email", "email")); 
      var Ref2_TelephoneValid = highlightLabel("Ref2_Telephone", textFieldValid("jobForm", "Ref2_Telephone", "ref2_Telephone")); 
      if(Ref1_FirstNameValid && Ref1_LastNameValid && Ref1_EmailValid && Ref1_TelephoneValid && Ref2_FirstNameValid && Ref2_LastNameValid && Ref2_EmailValid && Ref2_TelephoneValid) {
         return true; 
         }
      else {
         return false; 
         }
      }
   else if(stepToCheck == 5) {
      var DeclarationValid = highlightLabel("Declaration", textFieldValid("jobForm", "Declaration", "text")); 
      var CRBcheckedValid = highlightLabel("CRBchecked", textFieldValid("jobForm", "CRBchecked", "text")); 
      if(document.forms["jobForm"].elements["CRBchecked"].value == "yes") {
         var CRBcheckedYes = true; 
         var CRBExpiredDateValid = highlightLabel("CRBExpiredDate", textFieldValid("jobForm", "CRBExpiredDate", "date")); 
         }
      else {
         var CRBcheckedYes = false; 
         }
      var SourceValid = highlightLabel("Source", textFieldValid("jobForm", "Source", "text")); 
      if(DeclarationValid && CRBcheckedValid && SourceValid) {
         if(CRBcheckedYes) {
            if(!CRBExpiredDateValid) {
               return false; 
               }
            }
         return true; 
         }
      else {
         return false; 
         }
      }
   }
function highlightLabel(labelName, boolFlag) {
   if(!boolFlag) {
      var labelTags = document.getElementsByTagName("label"); 
      for(curLabel in labelTags) {
         if(labelTags[curLabel].attributes) {
            if(labelTags[curLabel].attributes["for"].value == labelName) {
               labelTags[curLabel].className = "invalidHighlight"; 
               window.scrollTo(0, 5); 
               return false; 
               }
            }
         else {
            if(labelTags[curLabel].htmlFor == labelName) {
               labelTags[curLabel].className = "invalidHighlight"; 
               window.scrollTo(0, 5); 
               return false; 
               }
            }
         }
      }
   return true; 
   }
function setLocationDropdowns(formName, dataField, clicked) {
   var correctClass = document.forms[formName].elements[dataField].value; 
   var resLoc1 = document.getElementById("resLocationPref1DDID"); 
   var resLoc2 = document.getElementById("resLocationPref2DDID"); 
   var resLoc3 = document.getElementById("resLocationPref3DDID"); 
   var hsLoc1 = document.getElementById("hsLocationPref1DDID"); 
   var hsLoc2 = document.getElementById("hsLocationPref2DDID"); 
   var hsLoc3 = document.getElementById("hsLocationPref3DDID"); 
   if(correctClass == "residential") {
      resLoc1.style.display = "inline"; 
      resLoc2.style.display = "inline"; 
      resLoc3.style.display = "inline"; 
      hsLoc1.style.display = "none"; 
      hsLoc2.style.display = "none"; 
      hsLoc3.style.display = "none"; 
      if(clicked) {
         document.forms["jobForm"].elements["locationPref1"].value = ""; 
         document.forms["jobForm"].elements["locationPref2"].value = ""; 
         document.forms["jobForm"].elements["locationPref3"].value = ""; 
         document.forms["jobForm"].elements["resLocationPref1DD"].selectedIndex = 0; 
         document.forms["jobForm"].elements["resLocationPref2DD"].selectedIndex = 0; 
         document.forms["jobForm"].elements["resLocationPref3DD"].selectedIndex = 0; 
         }
      else {
         setDDSelected("jobForm", "locationPref1", "resLocationPref1DD"); 
         setDDSelected("jobForm", "locationPref2", "resLocationPref2DD"); 
         setDDSelected("jobForm", "locationPref3", "resLocationPref3DD"); 
         }
      }
   else {
      resLoc1.style.display = "none"; 
      resLoc2.style.display = "none"; 
      resLoc3.style.display = "none"; 
      hsLoc1.style.display = "inline"; 
      hsLoc2.style.display = "inline"; 
      hsLoc3.style.display = "inline"; 
      if(clicked) {
         document.forms["jobForm"].elements["locationPref1"].value = ""; 
         document.forms["jobForm"].elements["locationPref2"].value = ""; 
         document.forms["jobForm"].elements["locationPref3"].value = ""; 
         document.forms["jobForm"].elements["hsLocationPref1DD"].selectedIndex = 0; 
         document.forms["jobForm"].elements["hsLocationPref2DD"].selectedIndex = 0; 
         document.forms["jobForm"].elements["hsLocationPref3DD"].selectedIndex = 0; 
         }
      else {
         setDDSelected("jobForm", "locationPref1", "hsLocationPref1DD"); 
         setDDSelected("jobForm", "locationPref2", "hsLocationPref2DD"); 
         setDDSelected("jobForm", "locationPref3", "hsLocationPref3DD"); 
         }
      }
   }
function newsLetterSubmit() {
   var emailAddress = document.forms["newsletterForm"].elements["email"].value; 
   var isValid = textFieldValid("newsletterForm", "email", "email"); 
   if(isValid) {
      var url = '/master/lt/summerjobs/newsletter.asp'; 
      var pars = "email=" + emailAddress; 
      var theDiv = document.getElementById("newsletter"); 
      theDiv.innerHTML = "<div style=\"width:100%; text-align:center\"><br /><br />Loading...</div>"; 
      var myAjax = new Ajax.Request( url, {
         method : 'post', parameters : pars, onComplete : showNewsResponse, encoding : 'UTF-8'}
      ); 
      }
   }
function showNewsResponse (originalRequest) {
   var newData = originalRequest.responseText; 
   var theDiv = document.getElementById("newsletter"); 
   theDiv.innerHTML = newData; 
   }