/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */




function emailValidate(field){
     // var regex = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
     // var regex = /^([a-zA-Z]([-._][a-zA-Z0-9])*)+([a-z0-9A-Z]([-._]?[a-z0-9A-Z]))*@([a-zA-Z0-9]+[-.])*([a-zA-Z]){1,3}$/
     var regex = /^([a-zA-Z]([-._][a-zA-Z0-9])*)+([a-z0-9A-Z]([-._]?[a-z0-9A-Z]))*@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
      var email=field.value;
        if(regex.test(email)==false){
        //alert("Please enter valid e-mail address ");
        //field.focus();
        return false;
        }
     return true;
 }

function isNumberKey(evt)
     {
         var charCode = (evt.which) ? evt.which : evt.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

// Function for checking alphanumerics only
function alphaNumeric(ctc){
    var regexname=/^[a-zA-Z0-9][a-zA-Z0-9\s,.]+$/;
    var flag=true;
     if(!regexname.test(ctc.value)){
       //alert("Please Enter CEF No");
       //document.getElementById('cefsno').focus();
       flag=false;
     }
    return flag;
    }
// Function for checking alphabets only
function alphabet(field){
    var regexname=/^[a-zA-Z]+$/;
    var flag=true;
     if(!regexname.test(field.value)){
       flag=false;
     }
    return flag;
    }

// Function for checking alphabets only
function alphabetComma(field){
    var regexname=/^[a-zA-Z][a-zA-Z\s,]+$/;
    var flag=true;
     if(!regexname.test(field.value)){
       flag=false;
     }
    return flag;
    }

// Function for checking alphabets only
function alphabetSpace(field){
    var regexname=/^[a-zA-Z0-9\ ]+$/;
    var flag=true;
     if(!regexname.test(field.value)){
       flag=false;
     }
    return flag;
    }
    

// Function for checking numerics only
function numeric(field){
    var regexname=/^[0-9]+$/;
    var flag=true;
     if(!regexname.test( field.value)){
     /*  alert("Please Enter CEF No");
       document.getElementById('cefsno').focus();
     */
       flag=false;

     }
    return flag;
    }
// Function for checking numerics only
 function checkExtension(fields){
    var field=fields.value;
	//alert(field);

    if(field.lastIndexOf("\\")>0){
	 field=field.substring(field.lastIndexOf("\\"));
	}
    
	if(field.lastIndexOf(".")!=-1){
    var ext=field.substring(field.lastIndexOf('.')+1);
   // alert(ext);
    var flag=true;
      if(!(ext=='doc' || ext=='rtf')){
	   alert("File format should be .doc (or) .rtf");
       flag=false;
      }
    }else{
	 alert("Please enter valid file name");
     flag=false;
	}

    return flag;
    }

/**************************** Hide Section ********************************/
/// Already applied - hiding/unhiding the applied Details

function hideApplied(){

    var fieldRef=document.getElementById('applied');
    var fieldValue=document.getElementById('applied').value;

    if(fieldValue=="No"){
      //alert(fieldRef.value);
      document.getElementById("position").value="";
      document.getElementById("date").value="";
      document.getElementById("result").value="";
      document.getElementById("position").style.backgroundColor ="#EEEEEE";
      document.getElementById("date").style.backgroundColor ="#EEEEEE";
      document.getElementById("result").style.backgroundColor ="#EEEEEE";
      document.getElementById("position").disabled=true;
      document.getElementById("date").disabled=true;
      document.getElementById("result").disabled=true;
      document.getElementById("datebutton").style.visibility="hidden";
//      document.getElementById("f_btn1").disabled=true;
      //document.getElementById("f_btn2").disabled=true;
     }else{
      document.getElementById("position").style.backgroundColor ="#FFFFFF";
      document.getElementById("date").style.backgroundColor ="#FFFFFF";
      document.getElementById("result").style.backgroundColor ="#FFFFFF";
     document.getElementById("position").disabled=false;
     document.getElementById("date").disabled=false;
     document.getElementById("result").disabled=false;
     document.getElementById("datebutton").style.visibility="visible";
//     document.getElementById("f_btn1").disabled=false;
     //document.getElementById("f_btn2").disabled=false;
    }
}



function hideExperience(field){
    var fieldRef=document.getElementById("workexp1");
    var fieldRef2=document.getElementById("workexp2");
    //alert(fieldRef.checked);
    if(field=="workexp1"){
        if(fieldRef.checked){
        fieldRef2.checked=false;
        hidingFunction(true);
        }
    }else if(field=="workexp2"){
        if(fieldRef2.checked){
           fieldRef.checked=false;
           hidingFunction(false);
         }else{
            hidingFunction(true);
         }
     }else if(field=="workexp22"){
        if(fieldRef2.checked){
           fieldRef.checked=false;
           hidingBackupFunction(false);
         }else{
            hidingFunction(true);
         }
     }
 }

function hidingFunction(value){
    HoldDate = new Date();
    var months=HoldDate.getMonth()+1;
   // alert(months);
    var monthsv=(months.toString().length==1)?"0"+months.toString():months.toString();
    //alert(monthsv);
    var curDate=HoldDate.getDate() + "/" + monthsv + "/" + HoldDate.getFullYear();
    //alert(document.getElementById("years").value);

    document.getElementById("years").disabled=value;
    document.getElementById("months").disabled=value;
    //document.getElementById("skills").disabled=value;
    document.getElementById("company").disabled=value;
    document.getElementById("designation").disabled=value;
    document.getElementById("location").disabled=value;
    document.getElementById("workarea").disabled=value;
    document.getElementById("startdate").disabled=value;
    document.getElementById("enddate").disabled=value;
    document.getElementById("ctc").disabled=value;
    document.getElementById("start").style.visibility=value==true?"hidden":"visible";
    document.getElementById("end").style.visibility=value==true?"hidden":"visible";
//    document.getElementById("f_btn1").disabled=value;;
//    document.getElementById("f_btn2").disabled=value;;
     // if(value==false){
        document.getElementById("years")[0].selected=true;
        document.getElementById("months")[0].selected=true;
        //document.getElementById("skills").value="";
        document.getElementById("company").value="";
        document.getElementById("designation").value="";
        document.getElementById("location").value="";
        document.getElementById("workarea")[0].selected=true;
        document.getElementById("startdate").value="";
//        document.getElementById("enddate").value=curDate;
        document.getElementById("enddate").value="";
        document.getElementById("ctc").value="";

        if(value){
            document.getElementById("years").style.backgroundColor ="#EEEEEE";
            document.getElementById("months").style.backgroundColor ="#EEEEEE";
            //document.getElementById("skills").style.backgroundColor ="#EEEEEE";
            document.getElementById("company").style.backgroundColor ="#EEEEEE";
            document.getElementById("designation").style.backgroundColor ="#EEEEEE";
            document.getElementById("location").style.backgroundColor ="#EEEEEE";
            document.getElementById("workarea").style.backgroundColor ="#EEEEEE";
            document.getElementById("startdate").style.backgroundColor ="#EEEEEE";
            document.getElementById("enddate").style.backgroundColor ="#EEEEEE";
            document.getElementById("ctc").style.backgroundColor ="#EEEEEE";

        }else{
            document.getElementById("years").style.backgroundColor ="#FFFFFF";
            document.getElementById("months").style.backgroundColor ="#FFFFFF";
            //document.getElementById("skills").style.backgroundColor ="#FFFFFF";
            document.getElementById("company").style.backgroundColor ="#FFFFFF";
            document.getElementById("designation").style.backgroundColor ="#FFFFFF";
            document.getElementById("location").style.backgroundColor ="#FFFFFF";
            document.getElementById("workarea").style.backgroundColor ="#FFFFFF";
            document.getElementById("startdate").style.backgroundColor ="#FFFFFF";
            document.getElementById("enddate").style.backgroundColor ="#FFFFFF";
            document.getElementById("ctc").style.backgroundColor ="#FFFFFF";


        }

//        document.getElementById("f_btn1").disabled=value;
//        document.getElementById("f_btn2").disabled=value;
      // }
}

function hidingBackupFunction(value){
    HoldDate = new Date();
    var months=HoldDate.getMonth()+1;
   // alert(months);
    var monthsv=(months.toString().length==1)?"0"+months.toString():months.toString();
    //alert(monthsv);
    var curDate=HoldDate.getDate() + "/" + monthsv + "/" + HoldDate.getFullYear();
    //alert(document.getElementById("years").value);

    document.getElementById("years").disabled=value;
    document.getElementById("months").disabled=value;
    //document.getElementById("skills").disabled=value;
    document.getElementById("company").disabled=value;
    document.getElementById("designation").disabled=value;
    document.getElementById("location").disabled=value;
    document.getElementById("workarea").disabled=value;
    document.getElementById("startdate").disabled=value;
    document.getElementById("enddate").disabled=value;
    document.getElementById("ctc").disabled=value;
    document.getElementById("start").style.visibility=value==true?"hidden":"visible";
    document.getElementById("end").style.visibility=value==true?"hidden":"visible";
//    document.getElementById("f_btn1").disabled=value;;
//    document.getElementById("f_btn2").disabled=value;;
     // if(value==false){
        /*document.getElementById("years")[0].selected=true;
        document.getElementById("months")[0].selected=true;
        //document.getElementById("skills").value="";
        document.getElementById("company").value="";
        document.getElementById("designation").value="";
        document.getElementById("location").value="";
        document.getElementById("workarea")[0].selected=true;
        document.getElementById("startdate").value="";
        document.getElementById("enddate").value=curDate;
        document.getElementById("ctc").value="";*/

        if(value){
            document.getElementById("years").style.backgroundColor ="#EEEEEE";
            document.getElementById("months").style.backgroundColor ="#EEEEEE";
            //document.getElementById("skills").style.backgroundColor ="#EEEEEE";
            document.getElementById("company").style.backgroundColor ="#EEEEEE";
            document.getElementById("designation").style.backgroundColor ="#EEEEEE";
            document.getElementById("location").style.backgroundColor ="#EEEEEE";
            document.getElementById("workarea").style.backgroundColor ="#EEEEEE";
            document.getElementById("startdate").style.backgroundColor ="#EEEEEE";
            document.getElementById("enddate").style.backgroundColor ="#EEEEEE";
            document.getElementById("ctc").style.backgroundColor ="#EEEEEE";

        }else{
            document.getElementById("years").style.backgroundColor ="#FFFFFF";
            document.getElementById("months").style.backgroundColor ="#FFFFFF";
            //document.getElementById("skills").style.backgroundColor ="#FFFFFF";
            document.getElementById("company").style.backgroundColor ="#FFFFFF";
            document.getElementById("designation").style.backgroundColor ="#FFFFFF";
            document.getElementById("location").style.backgroundColor ="#FFFFFF";
            document.getElementById("workarea").style.backgroundColor ="#FFFFFF";
            document.getElementById("startdate").style.backgroundColor ="#FFFFFF";
            document.getElementById("enddate").style.backgroundColor ="#FFFFFF";
            document.getElementById("ctc").style.backgroundColor ="#FFFFFF";


        }

//        document.getElementById("f_btn1").disabled=value;
//        document.getElementById("f_btn2").disabled=value;
      // }
}

/**************************** Hide Section ********************************/
/**************************** validate Application form Step-1 Section ********************************/


function checkStep1(){

   var fieldRef=document.getElementById('applied');
   var position=document.getElementById("position");
   var date=document.getElementById("date");
   var result=document.getElementById("result");
   var firstname=document.getElementById("firstname");
   var middle=document.getElementById("middle");
   var lastname=document.getElementById("lastname");
   var dob=document.getElementById("dob");
   var marital=document.getElementById("marital");
   var gender=document.getElementById("gender");
   var nation=document.getElementById("nation");
   var address1=document.getElementById("address1");
   var phone1=document.getElementById("phone1");
   var address2=document.getElementById("address2");
   var phone2=document.getElementById("phone2");
   var city=document.getElementById("city");
   var state=document.getElementById("state");
   var fax=document.getElementById("fax");
   var pin=document.getElementById("pin");
   var email=document.getElementById("email");
//alert(fieldRef.value);
   
   if(fieldRef.value=="Yes" && position.value.length==0 ){
      alert("Please enter position ");
      position.focus();
     return false;
   }else if(fieldRef.value=="Yes" &&  !positionCheck(position)){
       alert("Please enter alphabets only (space/./slash allowed)");
       position.focus();
       return false;
   }else if(fieldRef.value=="Yes" &&  position.value.length>50){
       alert("Position field maximum length should be 50");
       position.focus();
       return false;
   }else if (fieldRef.value=="Yes" &&  date.value.length==0){
      alert("Please enter Date ");
      date.focus();
      return false;
   }else if(fieldRef.value=="Yes" && date.value.indexOf('//')!=-1){
       alert("Continuous slashs(/) not accepted");
       date.focus();
       return false;
   }else if (fieldRef.value=="Yes" && (date.value.length>10 || date.value.length<10)){
      alert("Date field allows only 10 digits");
      date.focus();
      return false;
   }else if (fieldRef.value=="Yes" && !dateValidate(date)){
      // alert("Date field allows only 10 digits");
       date.focus();
       return false;
   }else if (fieldRef.value=="Yes" && !checkWithCurrentDate(date.value)){
       alert("Date should be less than current date");
       date.focus();
       return false;
   }else if (fieldRef.value=="Yes" && result.value.length==0){
      alert("Please enter Result");
      result.focus();
      return false;
   }else if (fieldRef.value=="Yes" && result.value.length>50){
      alert("Result field maximum length should be 50");
      result.focus();
      return false;
   }else if(firstname.value.length==0){
          alert("Please enter First Name");
          firstname.focus();
          return false;
   }else if(!nameCheck(firstname)){
          alert("First Name should be in alphabets (space allowed)");
          firstname.focus();
          return false;
   }else if(firstname.value.length>20){
          alert("First Name maximum length should be 20 only");
          firstname.focus();
          return false;
   }/*else if(middle.value.length==0){
          alert("Please enter Middle Name");
          middle.focus();
          return false;

   }else if(middle.value.length>20){
          alert("Middle Name maximum length should be 20 only");
          middle.focus();
          return false;
   }*/
    else if(middle.value.length!=0 && !nameCheck(middle)){
          alert("Middle Name should be in alphabets (space allowed)");
          middle.focus();
          return false;
   }
    else if(lastname.value.length==0){
          alert("Please enter Last Name");
          lastname.focus();
          return false;

   }else if(!nameCheck(lastname)){
          alert("Last Name should be in alphabets (space allowed)");
          lastname.focus();
          return false;
   }else if(lastname.value.length>20){
          alert("Last Name maximum length should be 20 only");
          lastname.focus();
          return false;
   }else if(dob.value.length==0){
          alert("Please enter Date Of Birth");
          dob.focus();
          return false;
   }else if(dob.value.indexOf('//')!=-1){
       alert("Continuous slashs(/) not accepted");
       dob.focus();
       return false;
   }else if (!dateValidate(dob)){
      // alert("Date field allows only 10 digits");
       dob.focus();
       return false;
   }else if(dob.value.length>10 || dob.value.length<10){
          alert("Date Of Birth length should not exceed 10");
          dob.focus();
          return false;
   }else if(!checkAge(dob)){
           alert("The dob should be 18 years old from current Date");
          dob.focus();
          return false;
   }else if(marital.value.length==0){
          alert("Please select Marital Status");
          dob.focus();
          return false;
   }else if(gender.value.length==0){
          alert("Please select Gender");
          gender.focus();
          return false;
   }else if(nation.value.length==0){
          alert("Please select Nationality");
          nation.focus();
          return false;
   }else if(!nationCheck(nation)){
          alert("Nationality should be in alphabets (space allowed)");
          nation.focus();
          return false;
   }else if(nation.value.length>20){
          alert("Nationality maximum length should be 20 only");
          nation.focus();
          return false;
   }else if(address1.value.length==0){
          alert("Please select Line1");
          address1.focus();
          return false;
   }else if(address1.value.indexOf("  ")>-1){
          alert("Line1 not accepts multiple spaces at a time");
          address1.focus();
          return false;
   } else if(address1.value.length>50){
          alert("Line1 maximum length should be 50 only");
          address1.focus();
          return false;
   }else if(address2.value.length==0){
          alert("Please select Line2");
          address2.focus();
          return false;
   }else if(address2.value.indexOf("  ")>-1){
          alert("Line2 not accepts multiple spaces at a time");
          address2.focus();
          return false;
   }
   else if(address2.value.length>50){
          alert("Line2 maximum length should be 50 only");
          address2.focus();
          return false;
   }else if(city.value.length==0){
          alert("Please select City");
          city.focus();
          return false;
   }else if(!nameCheck(city)){
          alert("City should be in alphabets (space allowed)");
          city.focus();
          return false;
   }else if(city.value.length>50){
          alert("City maximum length should be 50 only");
          city.focus();
          return false;
   }else if(state.value==-1){
          alert("Please select State");
          state.focus();
          return false;
   }else if(!nameCheck(state)){
          alert("State should be in alphabets (space allowed)");
          state.focus();
          return false;
   }else if(state.value.length>50){
          alert("State maximum length should be 50 only");
          state.focus();
          return false;
   }else if(pin.value.length==0 ){
          alert("Please enter pin");
          pin.focus();
          return false;
         
   }else if(pin.value.length<5){
          alert("Pin code minimum length should be 5 ");
          pin.focus();
          return false;
   }else if(pin.value.length>10){
          alert("Pin code maximum length should be 10 ");
          pin.focus();
          return false;
   }else if(!pinCheck(pin)){
          alert("Pin Code should be in alphanumerics\n (space and hyphen allowed)");
          pin.focus();
          return false;
   }/*else if(!numberExists(pin)){
          alert("Pin Code should be in alphanumerics\n (space and hyphen allowed)");
          pin.focus();
          return false;
   }*/
   else if(email.value.length==0 ){
          alert("Please enter E-mail id");
          email.focus();
          return false;
   }else if(!emailValidate(email)){
          alert("Please enter valid E-mail id");
          email.focus();
          return false;
   }else if(phone2.value.length==0 && phone1.value.length==0){
          alert("Please enter either Tel(Home) or Mobile number");
          phone1.focus();
          return false;
   }else if(phone1.value.length>0 && !mobileCheck(phone1)){
          alert("Please enter valid Tel(Home)");
          phone1.focus();
          return false;
   }else if(phone1.value.length>0 && !iszeros(phone1.value)){
          alert("Please enter valid Tel(Home)");
          phone1.focus();
          return false;
   }else if(phone1.value.length>0 && phone1.value.length>14){
          alert("Tel(Home) Number should not exceed the max length 14");
          phone1.focus();
          return false;
   }else if(phone1.value.length>0 && phone1.value.length<6){
          alert("Tel(Home) Number min length should be 6");
          phone1.focus();
          return false;
   }/*else if(phone2.value.length==0){
          alert("Please enter Mobile number");
          phone2.focus();
          return false;
   }else if(phone2.value.length>0 && phone2.value.length<10){
          alert("Mobile Number min length should be 10");
          phone2.focus();
          return false;
   }*/else if(phone2.value.length>0 && phone2.value.length>14){
          alert("Mobile Number should not exceed the max length 14");
          phone2.focus();
          return false;
   }else if(phone2.value.length>0 && !mobileCheck(phone2)){
          alert("Please enter valid Mobile");
          phone2.focus();
          return false;
   }else if(phone2.value.length>0 && !iszeros(phone2.value)){
          alert("Please enter valid Mobile");
          phone2.focus();
          return false;
   }/////
   else if(fax.value.length>0 && !mobileCheck(fax)){
          alert("Please enter valid Fax number");
          fax.focus();
          return false;
   }else if(fax.value.length>0 && fax.value.length>14){
          alert("Fax Number should not exceed the max length 14");
          fax.focus();
          return false;
   }else if(fax.value.length>0 && fax.value.length<6){
          alert("Fax Number min length should be 6");
          fax.focus();
          return false;
   }else if(fax.value.length>0 && !iszeros(fax.value)){
          alert("Please enter valid Fax number");
          fax.focus();
          return false;
   }
}

/**************************** validate Application form Step-1 Section ********************************/


/**************************** validate Application form Step-2 Section ********************************/


function checkStep2(newDob) {
//    alert(newDob);
    var qualification=document.getElementById('qualification');
    var qualitext1=document.getElementById('otherspi1');
    var institute=document.getElementById('institute');
    var passout=document.getElementById('passout');
    var marks=document.getElementById('marks');
    var workexp2=document.getElementById('workexp2');
    var years=document.getElementById('years');
    var months=document.getElementById('months');
    var skills=document.getElementById('skills');
    var company=document.getElementById('company');
    var designation=document.getElementById('designation');
    var location=document.getElementById('location');
    var workarea=document.getElementById('workarea');
    var workareatext1=document.getElementById('otherspi');
    var startdate=document.getElementById('startdate');
    var enddate=document.getElementById('enddate');
    var ctc=document.getElementById('ctc');


    /***************** Qualification ****************/
    if(qualification.value=='Others' && qualitext1.value.length==0){
           alert("Please enter qualification");
           qualitext1.focus();
           return false;
       }else if(qualification.value=='Others' && !alphaNumeric(qualitext1)){
           alert("Please enter alphabets only");
           qualitext1.focus();
           return false;
       }else if(qualitext1.value.length>30){
           alert("Qualification maximum length should be 30");
           qualitext1.focus();
           return false;
       }

    if(institute.value.length==0){
          alert("Please enter institute name");
          institute.focus();
          return false;
       }/*else if(!positionCheck(institute)){
           alert("Please enter alphabets only (space/./slash allowed)");
           institute.focus();
           return false;
       }*/else if(institute.value.length>50){
           alert("Institute name maximum length should be 50");
           institute.focus();
           return false;
       }

       if(passout.value.length==0){
          alert("Please enter Year of Passing");
          passout.focus();
          return false;
       }else if(passout.value.length < 4){
           alert("Year of Passing length should be  4");
           passout.focus();
           return false;
       }
       else if(passout.value.length > 4){
           alert("Year of Passing length should not exceed 4");
           passout.focus();
           return false;
       }else if(!numeric(passout)){
           alert("Please enter numeric only");
           passout.focus();
           return false;
       }else if(!checkYear(passout)){
           alert("Year of Passing should not be greater than current year");
           passout.focus();
           return false;
       }else if(!comparePassoutWithDob(passout.value, newDob)){
            passout.focus();
            return false;
        }

       if(marks.value.length==0){
          alert("Please enter Marks Obtained");
          marks.focus();
          return false;
       }

       /*else if(!numeric(marks)){
           alert("Please enter numeric only");
           marks.focus();
           return false;
       }*/else if(marks.value > 100){
           alert("Percentage should not exceed 100%");
           marks.focus();
           return false;
       }else if(marks.value.length > 5){
           alert("Marks length should not exceed 5");
           marks.focus();
           return false;
       }else if(parseFloat(marks.value)=="0" ){
           alert("Marks value should not be zero");
           marks.focus();
           return false;
       }else if(marks.value.indexOf('..')!=-1){
           alert("Continuous dots(.) not accepted");
           marks.focus();
           return false;
       }else if(parseFloat(marks.value)<1){
           alert("Please enter valid Percentage");
           marks.focus();
           return false;
       }





       var check = '';
       for(var i = 1; i <= 2; i++) {
        var subType = document.getElementById("workexp" + i);
        if(subType.checked)
            check += subType.value + ",";
       }

    if(check.length == 0) {
        alert("Please select either Experience or Fresh Graduate");
        return false;
    }
    
    if(skills.value.length==0){
          alert("Please enter your skills set");
          skills.focus();
          return false;
       }else if(!expCheck(skills)){
           alert("Please enter alphabets only");
           skills.focus();
           return false;
       }else if(skills.value.length>200){
           alert("skills set maximum length should be 200");
           skills.focus();
           return false;
       }

    if(workexp2.checked) {
           satus =1;

       if(years.value == -1) {
            alert("Please select years");
            years.focus();
            return false;
        }

        if(months.value == -1) {
            alert("Please select month");
            months.focus();
            return false;
        }

        

        if(company.value.length==0){
          alert("Please enter company name");
          company.focus();
          return false;
       }else if(!companyCheck(company)){
           alert("Please enter alphabets only");
           company.focus();
           return false;
       }else if(company.value.length>50){
           alert("company name maximum length should be 50");
           company.focus();
           return false;
       }

        if(designation.value.length==0){
          alert("Please enter designation");
          designation.focus();
          return false;
       }else if(!designationCheck(designation)){
           alert("Please enter alphabets only");
           designation.focus();
           return false;
       }else if(designation.value.length>50){
           alert("designation maximum length should be 50");
           designation.focus();
           return false;
       }

       if(location.value.length==0){
          alert("Please enter location");
          location.focus();
          return false;
       }else if(!companyCheck(company)){
           alert("Please enter alphabets only");
           company.focus();
           return false;
       }else if(location.value.length > 50){
           alert("location maximum length should be 50");
           location.focus();
           return false;
       }

       /***************** WorkArea ****************/
    if(workarea.value=='Others' && workareatext1.value.length==0){
           alert("Please enter area of work");
           workareatext1.focus();
           return false;
       }else if(workarea.value=='Others' && !alphaNumeric(workareatext1)){
           alert("Please enter alphabets only");
           workareatext1.focus();
           return false;
       }else if(workareatext1.value.length>30){
           alert("Area of work maximum length should be 30");
           workareatext1.focus();
           return false;
       }

      if (startdate.value.length == 0){
          alert("Please enter start date ");
          startdate.focus();
          return false;
      }else if(startdate.value.indexOf('//')!=-1){
           alert("Continuous slashs(/) not accepted");
           startdate.focus();
           return false;
       }else if (!dateValidate(startdate)){
          // alert("Date field allows only 10 digits");
           startdate.focus();
           return false;
       }else if(!checkWithCurrentDate(startdate.value)){
            alert('Start date must be less than or equal to Current date');
//            alert('DOB '+newDob);
            startdate.focus();
            return false;
        }/*else if(!compareWithDob(startdate.value, newDob)){
            startdate.focus();
            return false;
        }/*else if (!validateToCurrentDate(startdate.value)){
            alert("Start Date should not be greater than Current Date");
            startdate.focus();
            return false;
        }*/

       /*if (enddate.value.length == 0){
          alert("Please enter end date");
          enddate.focus();
          return false;
       }else*/ if(enddate.value.indexOf('//')!=-1){
           alert("Continuous slashs(/) not accepted");
           enddate.focus();
           return false;
       }else if (enddate.value.length != 0 && !dateValidate(enddate)){
      // alert("Date field allows only 10 digits");
           enddate.focus();
           return false;
        }else if(!checkWithCurrentDate(enddate.value)){
            alert('End date must be less than or equal to Current date');
            enddate.focus();
            return false;
        }
        else if (!validateDate(startdate.value, enddate.value)){
            alert("End date must be greater than Start date");
            enddate.focus();
            return false;
        }

        if(ctc.value.length==0){
          alert("Please enter CTC");
          ctc.focus();
          return false;
       }

       else if(!alphaNumeric(ctc)){
           alert("Please enter valid CTC ");
           ctc.focus();
           return false;
       }else if(ctc.value.length > 20){
           alert("CTC length should not exceed 20");
           ctc.focus();
           return false;
       }

    }
    

}

        function checkWithCurrentDate(date){
            var flags = true;
            HoldDate = new Date();
            var curDate=HoldDate.getDate() + "/" + (HoldDate.getMonth()+1) + "/" + HoldDate.getFullYear();
            //alert(curDate);

           // alert("date"+date);
            //alert(date.substring(0,date.indexOf("/")));
           //var days=date.subString(0,date.indexOf("/")+1);

            var day=date.substring(0,2);
            var months=date.substring(3,5);
            var years=date.substring(6,10);
            //alert("-----"+day+"---"+months+"----"+years );
            //var dobDate= new Date(years,day,months);
            var dobDate= new Date();
            dobDate.setFullYear(years,months,day);

            //alert("------"+dobDate);
            //dobDate=dobDate.format("dd/mm/yyyy");
            var txtDate=(dobDate.getMonth()+1) + "/" + dobDate.getDate() + "/" + dobDate.getFullYear();
            //alert(txtDate);
            //dobDate=new Date(dobDate.getFullYear(),dobDate.getDate(),dobDate.getMonth()+1);
           
            if((HoldDate.getFullYear() < dobDate.getFullYear())){
//                if(HoldDate.getDate() < dobDate.getDate()){
               // alert('If month and year equals');
//                    flags = false;
//                }
                //alert("Year"+HoldDate.getFullYear()+"---"+ dobDate.getFullYear());
                flags = false;
            }else if((HoldDate.getFullYear() == dobDate.getFullYear()) && ((HoldDate.getMonth()+1)< (dobDate.getMonth()))){
                flags = false;
                // alert("Year"+HoldDate.getFullYear()+"---"+ dobDate.getFullYear());
                // alert("month"+(HoldDate.getMonth()+1) +"-----" + (dobDate.getMonth()));
            }
            else if((HoldDate.getFullYear() == dobDate.getFullYear()) && ((HoldDate.getMonth()+1) == dobDate.getMonth()) && (HoldDate.getDate() < dobDate.getDate())){
                flags = false;
                //alert("date "+HoldDate.getDate() +"---"+ dobDate.getDate());
            }
            return flags;
        }

        function compareWithDob(textDate, dobDate){
            var flags = true;
            txtDate= new Date(textDate);
            var start_year = txtDate.getFullYear();
//            alert('start_year '+start_year);

            dobDate= new Date(dobDate);
            var dob_year = dobDate.getFullYear();
//            alert('dob_year '+dob_year);
            var difYear = start_year-dob_year;
//            alert('Diff Year '+difYear);

            if(difYear < 18){
                alert('Start Date must be 18 years minimum difference\n with Date Of Birth');
                flags = false;
            }
            return flags;
        }

        function comparePassoutWithDob(textDate, dobDate){
            var flags = true;
            //alert('passout_year '+textDate);

            dobDate= new Date(dobDate);
            var dob_year = dobDate.getFullYear();
           //alert('dob_year '+dob_year);
            var difYear = textDate-dob_year;
            //alert('Diff Year '+difYear);

            if(difYear < 18){
                alert('Passout year must be 18 years minimum difference\n with Date Of Birth');
                flags = false;
            }
            return flags;
        }

/**************************** End validate Application form Step-2 Section ********************************/



/**************************** validate Application form Step-3 Section ********************************/

function checkStep3() {


     var reads=document.getElementById('reads');
     var writes=document.getElementById('writes');
     var speak=document.getElementById('speak');
     var resume=document.getElementById('resume');
     var refname1=document.getElementById('refname1');
     var reftele1=document.getElementById('reftele1');
     var reftele2=document.getElementById('reftele2');

     var refname2=document.getElementById('refname2');
     var reftele3=document.getElementById('reftele3');
     var reftele4=document.getElementById('reftele4');
     var refemail2=document.getElementById('refemail2');


     var refmob1=document.getElementById('refmob1');
     var refemail1=document.getElementById('refemail1');
     var title1=document.getElementById('title1');
     var title2=document.getElementById('title2');
     var titletext1=document.getElementById('otherspi1');
     var titletext2=document.getElementById('otherspi');

    





    if(reads.value.length==0){
          alert("Please enter the languages you can read");
          reads.focus();
          return false;
       }else if(!languageCheck(reads)){
           alert("please enter alphabets only (comma & space allowed)\nfor Language Proficiency (Read)");
           reads.focus();
           return false;
       }else if(reads.value.length>50){
           alert("The languages you can read maximum length should be 50");
           reads.focus();
           return false;
       }

       if(writes.value.length==0){
          alert("Please enter the languages you can write");
          writes.focus();
          return false;
       }else if(!languageCheck(writes)){
           alert("please enter alphabets only (comma & space allowed)\nfor Language Proficiency (Write)");
           writes.focus();
           return false;
       }else if(writes.value.length>50){
           alert("The languages you can write maximum length should be 50");
           writes.focus();
           return false;
       }

       if(speak.value.length==0){
          alert("Please enter the language you can speak");
          speak.focus();
          return false;
       }else if(!languageCheck(speak)){
           alert("please enter alphabets only (comma & space allowed)\nfor Language Proficiency (Speak)");
           speak.focus();
           return false;
       }else if(speak.value.length>50){
           alert("The language you can speak maximum length should be 50");
           speak.focus();
           return false;
       }

       if(resume.value.length==0){
          alert("Please upload resume");
          resume.focus();
          return false;
       }else if(!checkExtension(resume)){
          //alert("Please upload resume");
          resume.focus();
          return false;
       }

        if(title1.value=='Others' && titletext1.value.length==0){
           alert("Please enter Title");
           titletext1.focus();
           return false;
       }else if(title1.value=='Others' && !alphaNumeric(titletext1)){
           alert("Please enter alphabets only");
           titletext1.focus();
           return false;
       }else if(titletext1.value.length>20){
           alert("Title maximum length should be 20");
           titletext1.focus();
           return false;
       }

       if(refname1.value.length==0){
          alert("Please enter name");
          refname1.focus();
          return false;
       }else if(!nameCheck(refname1)){
           alert("Please enter alphabets only");
           refname1.focus();
           return false;
       }else if(refname1.value.length>50){
           alert("name maximum length should be 50");
           refname1.focus();
           return false;
       }

     /*  var chechTele = '';
       for(var i = 1; i <= 2; i++) {
        var reftele = document.getElementById("reftele"+ i);
        if(reftele.length != 0)
            chechTele += reftele.value;
       }
    if(chechTele.length == 0) {

        alert("Please select telephone\\mobile ");
        reftele.focus();
        return false;
    }*/
    else if(reftele1.value.length==0 && reftele2.value.length==0){
          alert("Please enter Mobile/Tel(Home)");
          reftele2.focus();
          return false;

   }else if(reftele1.value.length>0 && !mobileCheck(reftele1)){
          alert("Please enter valid Tel(Home)");
          reftele1.focus();
          return false;
   }else if(reftele1.value.length>0 && !iszeros(reftele1.value)){
          alert("Please enter valid Tel(Home)");
          reftele1.focus();
          return false;
   }else if(reftele1.value.length>0 && reftele1.value.length>14){
          alert("Tel(Home) Number should not exceed the max length 14");
          reftele1.focus();
          return false;
   }else if(reftele1.value.length>0 && reftele1.value.length<6){
          alert("Tel(Home) Number min length should be 6");
          reftele1.focus();
          return false;
   }else if(reftele2.value.length>0 && !mobileCheck(reftele2)){
          //alert(reftele2.value.length);
          alert("Please enter valid Mobile");
          reftele2.focus();
          return false;
   }else if(reftele2.value.length>0 && !iszeros(reftele2.value)){
          //alert(reftele2.value.length);
          alert("Please enter valid Mobile");
          reftele2.focus();
          return false;
   }/*else if(reftele2.value.length>0 && reftele2.value.length<10){
          alert("Mobile Number min length should be 10");
          reftele2.focus();
          return false;
   }*/else if(reftele2.value.length>0 && reftele2.value.length>14){
          alert("Mobile Number should not exceed the max length 14");
          reftele2.focus();
          return false;
   }

   if(refemail1.value.length==0){
          alert("Please enter email id");
          refemail1.focus();
          return false;
   }else if(!emailValidate(refemail1)){
          alert("Please enter valid E-mail id");
          refemail1.focus();
          return false;
   }

   /************************************  Second reference *********************************/

      if(refname2.value.length>0 && !nameCheck(refname2)){
           alert("Please enter alphabets only");
           refname2.focus();
           return false;
       }else if(refname2.value.length>50){
           alert("name length should not exceed 50");
           refname2.focus();
           return false;
       }else if(reftele3.value.length>0 && refname2.value.length==0){
           alert("Please enter reference name");
           refname2.focus();
           return false;
       }else if(reftele4.value.length>0 && refname2.value.length==0){
           alert("Please enter reference name");
           refname2.focus(); 
           return false;
       }else if(refname2.value.length>0 && reftele3.value.length==0 && reftele4.value.length==0){
                  alert("Please enter Mobile/Tel(Home)");
                  reftele4.focus();
                  return false;

           }else if(refname2.value.length>0 && reftele3.value.length>0 && !mobileCheck(reftele3)){
                  alert("Please enter valid Tel(Home)");
                  reftele3.focus();
                  return false;
           }else if(refname2.value.length>0 && reftele3.value.length>0 && !iszeros(reftele3.value)){
                  alert("Please enter valid Tel(Home)");
                  reftele3.focus();
                  return false;
           }else if(refname2.value.length>0 && reftele3.value.length>0 && reftele3.value.length>14){
                  alert("Tel(Home) Number should not exceed the max length 14");
                  reftele3.focus();
                  return false;
           }else if(refname2.value.length>0 && reftele3.value.length>0 && reftele3.value.length<6){
                  alert("Tel(Home) Number min length should be 6");
                  reftele3.focus();
                  return false;
           }else if(refname2.value.length>0 && reftele4.value.length>0 && !mobileCheck(reftele4)){
                  //alert(reftele2.value.length);
                  alert("Please enter valid Mobile");
                  reftele4.focus();
                  return false;
           }else if(refname2.value.length>0 && reftele4.value.length>0 && !iszeros(reftele4.value)){
                  //alert(reftele2.value.length);
                  alert("Please enter valid Mobile");
                  reftele4.focus();
                  return false;
           }/*else if(refname2.value.length>0 && reftele4.value.length>0 && reftele4.value.length<10){
                  alert("Mobile Number min length should be 10");
                  reftele4.focus();
                  return false;
           }*/else if(refname2.value.length>0 && reftele4.value.length>0 && reftele4.value.length>14){
                  alert("Mobile Number should not exceed the max length 14");
                  reftele4.focus();
                  return false;
           }else if(refname2.value.length==0 && reftele3.value.length>0 && !mobileCheck(reftele3)){
                  alert("Please enter valid Tel(Home)");
                  reftele3.focus();
                  return false;
           }else if(refname2.value.length==0 && reftele3.value.length>0 && !iszeros(reftele3.value)){
                  alert("Please enter valid Tel(Home)");
                  reftele3.focus();
                  return false;
           }else if(refname2.value.length==0 && reftele3.value.length>0 && reftele3.value.length>14){
                  alert("Tel(Home) Number should not exceed the max length 14");
                  reftele3.focus();
                  return false;
           }else if(refname2.value.length==0 && reftele3.value.length>0 && reftele3.value.length<6){
                  alert("Tel(Home) Number min length should be 6");
                  reftele3.focus();
                  return false;
           }else if(refname2.value.length==0 && reftele4.value.length>0 && !mobileCheck(reftele4)){
                  //alert(reftele2.value.length);
                  alert("Please enter valid Mobile");
                  reftele4.focus();
                  return false;
           }else if(refname2.value.length==0 && reftele4.value.length>0 && !iszeros(reftele4.value)){
                  //alert(reftele2.value.length);
                  alert("Please enter valid Mobile");
                  reftele4.focus();
                  return false;
           }else if(refname2.value.length==0 && reftele4.value.length>0 && reftele4.value.length<10){
                  alert("Mobile Number min length should be 10");
                  reftele4.focus();
                  return false;
           }else if(refname2.value.length==0 && reftele4.value.length>0 && reftele4.value.length>14){
                  alert("Mobile Number should not exceed the max length 14");
                  reftele4.focus();
                  return false;
           }


           if(refname2.value.length>0 && refemail2.value.length==0){
                  alert("Please enter email id");
                  refemail2.focus();
                  return false;
           }else if(refname2.value.length>0 && !emailValidate(refemail2)){
                  alert("Please enter valid E-mail id");
                  refemail2.focus();
                  return false;
           }else if(refemail2.value==refemail1.value){
                  alert("References E-mail ids should not be same");
                  refemail2.focus();
                  return false;
           }
   /*****************************************************************************************/

       if(title2.value=='Others' && titletext2.value.length==0){
           alert("Please enter Title");
           titletext2.focus();
           return false;
       }else if(title2.value=='Others' && !alphaNumeric(titletext2)){
           alert("Please enter alphabets only");
           titletext2.focus();
           return false;
       }else if(titletext2.value.length>20){
           alert("Title maximum length should be 20");
           titletext2.focus();
           return false;
       }
    //return false;
}





     function isNumberKey(evt) {
         var charCode = (evt.which) ? evt.which : evt.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }

/**************************** End validate Application form Step-3 Section ********************************/

/**************************** Post New Job Validation Begin ***********************************************/

    function finalValidate(){

             var jobcode=document.getElementById('jobcode');
             var position=document.getElementById('position');
             var description=document.getElementById('description');
             var location=document.getElementById('location');
             var experience=document.getElementById('experience');
             var skillset=document.getElementById('skillset');
             var salrange=document.getElementById('salrange');
//             var negotiate=document.getElementById('negotiate');
             var qualification=document.getElementById('qualification');
             var department=document.getElementById('department');
//             alert('negotiate '+negotiate.checked);

            /**************** jobcode ******************/
           if(jobcode.value.length==0){
              alert("Please enter the Job Code");
              jobcode.focus();
              return false;
           }else if(!jobcodeCheck(jobcode)){
              
               alert("Please enter alphabets only");
               jobcode.focus();
               return false;
           }else if(jobcode.value.length>50){
               alert("The Job Code length should not exceed 50");
               jobcode.focus();
               return false;
           }else if(jobcode.value.indexOf("-")==0){
               alert("The Job Code must start with alpha numeric");
               jobcode.focus();
               return false;
           }
           /**************** position ******************/
           /*if(position.value.length==0){
              alert("Please enter the Position");
              position.focus();
              return false;
           }else if(!positionCheck(position)){
               alert("Please enter alphabets only (space/./slash allowed)");
               position.focus();
               return false;
           }else if(position.value.length>50){
               alert("The Job Code maximum length should be 50");
               position.focus();
               return false;
           }*/
           /**************** description ******************/
           /*if(description.value.length==0 || description.value==""){
              alert("Please enter the Description");
              description.focus();
              return false;
           }else if(description.value.length>200){
               alert("The Description maximum length should be 200");
               description.focus();
               return false;
           }*/
           /**************** location ******************/
           /*if(location.value.length==0){
              alert("Please enter the Location");
              location.focus();
              return false;
           }else*/ if(location.value.length>0 && !locationCheck(location)){
               alert("Please enter alphabets only");
               location.focus();
               return false;
           }/*else if(location.value.length>50){
               alert("The Location maximum length should be 50");
               location.focus();
               return false;
           }*/
           /**************** experience ******************/
           /*if(experience.value.length==0){
              alert("Please enter the Experience");
              experience.focus();
              return false;
           }else*/ if(experience.value.length>0 && !expCheck(experience)){
               alert("Experience starts with alphanumerics \n(space,dot,+ also allowed) ");
               experience.focus();
               return false;
           }/*else if(experience.value.length>50){
               alert("The Experience maximum length should be 50");
               experience.focus();
               return false;
           }*/
           /**************** skillset ******************/
           /*if(skillset.value.length==0){
              alert("Please enter the Skillset");
              skillset.focus();
              return false;
           }else if(!expCheck(skillset)){
               alert("Please enter alphabets only");
               skillset.focus();
               return false;
           }else if(skillset.value.length>50){
               alert("The Skillset maximum length should be 50");
               skillset.focus();
               return false;
           }*/
           /**************** Salary Range ******************/
           /*if(salrange.value==-1){
              alert("Please Select Salary Range");
              salrange.focus();
              return false;
           }*/
            /*if(negotiate.checked==true){
                var flag;
                if(salrange.value==-1){
                  alert("Please Select Salary Range");
                  salrange.focus();
                  flag = false;
               }
              return flag;
           }*/
           /**************** qualification ******************/
           /*if(qualification.value.length==0){
              alert("Please enter the Qualification");
              qualification.focus();
              return false;
           }else*/ if(qualification.value.length>0 && !qualificationCheck(qualification)){
               alert("Please enter alphabets only");
               qualification.focus();
               return false;
           }/*else if(qualification.value.length>50){
               alert("The Qualification maximum length should be 50");
               qualification.focus();
               return false;
           }*/
           /**************** department ******************/
          /* if(department.value.length==0){
              alert("Please enter the Department");
              department.focus();
              return false;
           }else if(!locationCheck(department)){
               alert("Please enter alphabets only");
               department.focus();
               return false;
           }else if(department.value.length>50){
               alert("The Department maximum length should be 50");
               department.focus();
               return false;
           }*/
        }


        function jobcodeCheck(field){
        var regexname=/^[a-zA-Z0-9-]+$/;
        var flag=true;
         if(!regexname.test(field.value)){
           flag=false;
         }
        return flag;
        }

        function positionCheck(field){
            var regexname=/^[a-zA-Z][a-zA-Z\s.\/]*$/;
            var flag=true;
             if(!regexname.test(field.value)){
               flag=false;
             }
            return flag;
        }

        function locationCheck(field){
            var regexname=/^[a-zA-Z][a-zA-Z\s]+$/
            var flag=true;
             if(!regexname.test(field.value)){
               flag=false;
             }
            return flag;
        }

        function expCheck(field){
            var regexname=/^[a-zA-Z0-9][a-zA-Z0-9\s+,-\/]+$/
            var flag=true;
             if(!regexname.test(field.value)){
               flag=false;
             }
            return flag;
        }

        function companyCheck(field){
            var regexname=/^[a-zA-Z0-9][a-zA-Z0-9\s.\/-]+$/
            var flag=true;
             if(!regexname.test(field.value)){
               flag=false;
             }
            return flag;
        }

       function mobileCheck(field){
            var regexname=/^([+])?[0-9]{2,3}([-])?[0-9]+$/
           // var regexname=/^\+[0-9]{2}|^\+[0-9]{2}\(0\)|^\(\+[0-9]{2}\)\(0\)|^00[0-9]{2}|^0)([0-9]{9}$|[0-9\-\s]{10}$/
            var flag=true;
             if(!regexname.test(field.value)){
               flag=false;
             }
            return flag;
        }

       function designationCheck(field){
        var regexname=/^[a-zA-Z][a-zA-Z\s\.\/]+$/
        var flag=true;
         if(!regexname.test(field.value)){
           flag=false;
         }
        return flag;
        }

        function qualificationCheck(field){
        var regexname=/^[a-zA-Z][a-zA-Z\s.,\/]+$/
        var flag=true;
         if(!regexname.test(field.value)){
           flag=false;
         }
        return flag;
        }
        function nameCheck(field){
            var regexname=/^[a-zA-Z][a-zA-Z\s]*$/
            var flag=true;
             if(!regexname.test(field.value)){
               flag=false;
             }
            return flag;
        }
        function nationCheck(field){
            var regexname=/^[a-zA-Z][a-zA-Z\s.]*$/
            var flag=true;
             if(!regexname.test(field.value)){
               flag=false;
             }
            return flag;
         }
        function pinCheck(field){
        var regexname=/^([a-zA-Z0-9])+([a-zA-Z0-9]+[- ])*([a-zA-Z0-9])+$/
        var flag=true;
        //alert(field.value);
         if(!regexname.test(field.value)){
           flag=false;
         }
        return flag;
        }
        
        function numberExists(field){
        var fieldvalue=field.value;
        var count=0;
        for(var i=0;i<fieldvalue.length;i++){
           if(isNaN(fieldvalue[i])){
               count++;
           }
         }

        var regexname=/^[a-zA-Z0-9][a-zA-Z0-9\s-]+$/
        var flag=true;
         if(!regexname.test(field.value)){
           flag=false;
         }
        return flag;
        }
/**************************** Post New Job Validation End ***********************************************/


/**************************** Login Validation Begin ***********************************************/
    function loginCheck(){
        var loginid=document.getElementById('loginid');
        var pwd=document.getElementById('pwd');

            /**************** login id ******************/
           if(loginid.value.length==0){
              alert("Please enter the login id");
              loginid.focus();
              return false;
           }else if(!loginIdCheck(loginid)){
               alert("Please enter alphabets only");
               loginid.focus();
               return false;
           }else if(loginid.value.length>20){
               alert("The login id maximum length should be 20");
               loginid.focus();
               return false;
           }
           /**************** password ******************/
           if(pwd.value.length==0){
              alert("Please enter the Password");
              pwd.focus();
              return false;
           }else if(pwd.value.length>20){
               alert("The Password maximum length should be 20");
               pwd.focus();
               return false;
           }
        }
        
        function loginIdCheck(field){
        var regexname=/^[a-zA-Z]+$/;
        var flag=true;
         if(!regexname.test(field.value)){
           flag=false;
         }
        return flag;
        }

       function languageCheck(field){
        var regexname=/^[a-zA-Z][a-zA-Z\s,]+$/;
        var flag=true;
         if(!regexname.test(field.value)){
           flag=false;
         }
        return flag;
        }

       /*function checkAge1(field){
           if (field.value!='' || field.value!=null){
                HoldDate=new Date();
                var dobDate= new Date(field.value);
                var curDate=HoldDate.getDate() + "/" + (HoldDate.getMonth()+1) + "/" + HoldDate.getFullYear();
                 //alert(curDate);
                var curYear=HoldDate.getFullYear();
                var dobYear=dobDate.getFullYear();
                var difYear=curYear-dobYear;
                var size=difYear.toString().length;
                var finaldif=difYear.toString();
    
               if (finaldif < 18) {
                    //alert("The dob should be 15 years old from current Date.");
                    return false;
                    }
              
            }
             return true;
       }*/

       function checkAge(field){
           if (field.value!='' || field.value!=null){
                HoldDate=new Date();

                var currentDate=field.value;

                 var curDay=currentDate.substring(0,2);
                 var curMonth=currentDate.substring(3,5);
                 var currYear=currentDate.substring(6,10);

                var dobDate= new Date();
                dobDate.setFullYear(currYear, curMonth, curDay);
                var curDate=HoldDate.getDate() + "/" + (HoldDate.getMonth()+1) + "/" + HoldDate.getFullYear();
                 //alert(curDate);
                var curYear=HoldDate.getFullYear();
                var dobYear=dobDate.getFullYear();

                var difYear=curYear-dobYear;

                var firstMonth = HoldDate.getMonth()+1;
                var secondMonth = dobDate.getMonth();

                if (firstMonth < secondMonth) { difYear=difYear-1;
                    //alert("a Years Difference = " + (difYear - 1));
                }
                if (firstMonth > secondMonth) { 
                    difYear=difYear;//alert("b Years Difference = " + difYear);
                }
                if (firstMonth == secondMonth) {
                       var firstDay = HoldDate.getDate();
                       var secondDay = dobDate.getDate();
                       if (firstDay < secondDay) { 
                           difYear=difYear-1;//alert("c Years Difference = " + (difYear - 1));
                       }
                       if (firstDay >= secondDay) { 
                           difYear=difYear;//alert("d Years Difference = " + difYear);
                       }
                 }
                
                //var size=difYear.toString().length;
                var finaldif=difYear;

               if (finaldif < 18) {
                    //alert("The dob should be 15 years old from current Date.");
                    return false;
                    }

            }
             return true;
       }


       function validateDate(start,end){
        //        alert(Date.parse(start)+'   '+Date.parse(end));

        if (Date.parse(start) > Date.parse(end)) {
            //alert("The dates are invalid.");
            return false;
            }
            return true;
        }
        function validateToCurrentDate(start){
        //        alert(Date.parse(start)+'   '+Date.parse(end));
        var currentDate=new Date();
        var year=currentDate.getFullYear();
        var month=currentDate.getMonth()+1;
        var currentdate=currentDate.getDate();

        var startdate=new Date(start);
        var startYear=startdate.getFullYear();
        //var startMonth=startdate.getMonth()+1;
        //var startDate=startdate.getDate();
         
       // alert("cyear- "+year+" -gyear "+startYear+" -cmonth "+month+" -gmonth "+startMonth+" -cdate "+currentdate+" -date "+startDate);

        if (startYear>year) {
            //alert("The dates are invalid.");
            return false;
        }/*else if(startMonth>month){
            return false;
        }else if(startDate>currentdate){
            return false;
        }*/

            return true;
        }

/**************************** Login Validation End ***********************************************/



/****** calendar code*****/
//  <!--
//  var g_PopupIFrame;
//
//
//        function IsIE()
//        {
//	        return ( navigator.appName=="Microsoft Internet Explorer" );
//        }
//
//        function ShowPopupDiv(divID)
//        {
//            var divPopup=document.getElementById(divID);
//
//            if (!IsIE())
//            {
//                //Just display the div
//                divPopup.style.visibility ="visible";
//                return;
//		    }
//
//            //Increase default zIndex of div by 1, so that DIV appears before IFrame
//            divPopup.style.zIndex=divPopup.style.zIndex+1;
//
//		    var iFrame = document.createElement("IFRAME");
//	        iFrame.setAttribute("src", "");
//
//	        //Match IFrame position with divPopup
//	        iFrame.style.position="absolute";
//
//            /**/
//	        iFrame.style.left = divPopup.offsetLeft + 'px';
//			iFrame.style.top  = divPopup.offsetTop + 'px';
//            /**/
//
//		    iFrame.style.width  = divPopup.offsetWidth + 'px';
//			iFrame.style.height = divPopup.offsetHeight + 'px';
//
//		    document.body.appendChild(iFrame);
//
//		    //Store iFrame in global variable, so it can get removed when divPopup is hidden
//		    g_PopupIFrame=iFrame;
//
//	        divPopup.style.visibility ="visible";
//	    }
//	     function HidePopupDiv(divID)
//        {
//            var divPopup;
//			divPopup=document.getElementById(divID);
//			divPopup.style.visibility = "hidden";
//
//			if (IsIE())
//		    {
//		    	document.body.removeChild(g_PopupIFrame);
//	            g_PopupIFrame=null;
//	        }
//        }
//
//     -->

 /*** global variables*****/
  var dtCh= "/";
    var minYear=1900;
    var maxYear=2100;

    function isInteger(s){
        var i;
        for (i = 0; i < s.length; i++){
            // Check that current character is number.
            var c = s.charAt(i);
            if (((c < "0") || (c > "9"))) return false;
        }
        // All characters are numbers.
        return true;
    }

    function stripCharsInBag(s, bag){
        var i;
        var returnString = "";
        // Search through string's characters one by one.
        // If character is not in bag, append to returnString.
        for (i = 0; i < s.length; i++){
            var c = s.charAt(i);
            if (bag.indexOf(c) == -1) returnString += c;
        }
        return returnString;
    }

    function daysInFebruary (year){
        // February has 29 days in any year evenly divisible by four,
        // EXCEPT for centurial years which are not also divisible by 400.
        return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
    }
    function DaysArray(n) {
        for (var i = 1; i <= n; i++) {
            this[i] = 31
            if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
            if (i==2) {this[i] = 29}
       }
       return this
    }


 function isDate(dtStr){
        //var dtStr = document.getElementById('date').value;
       // alert('Date '+dtStr);
    var flag=true;
    var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
	var pos2=dtStr.indexOf(dtCh,pos1+1)

	//alert('pos1='+pos1+' pos2='+pos2);
	var strDay=dtStr.substring(0,pos1)

	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear


	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}

	year=parseInt(strYr)
	//alert('Year '+year);
	month=parseInt(strMonth)
	//alert('Month '+month);
	day=parseInt(strDay)
	//alert('Day '+day);

	if (pos1==-1 || pos2==-1){
		alert("The date format should be : dd/mm/yyyy")
		flag=false;
	}else

	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		alert("Please enter a valid 4 digit year between "+minYear+" and "+maxYear)
		flag=false;
	}else

	if (strMonth.length<1 || month<1 || month>12){
		alert("Please enter a valid month")
		return false
	}else

	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		alert("Please enter a valid day")
		flag=false;
	}else
	//alert(dtStr.indexOf(dtCh,pos2+1));
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		alert("Please enter a valid date")
		flag=false;
	}
return flag;
}

function dateValidate(field){
        var dt = field.value;
        var flag=true;
        if (!isDate(dt)){
            //dt.focus()
            flag=false;
        }
        return flag
}

function checkYear(field){
  var dt=new Date();
  var year=dt.getFullYear();
  var flag=true;
  if(field.value>year){
      flag=false;
  }
  return flag;

}
function passedYear(field){
  var dt=new Date();
  //alert(field.value);
  var value=field.value;
  //var datemonth=value.substr(0,value.lastIndexOf("/"));

  var subValue=value.substr(value.lastIndexOf("/")+1);
  //alert(subValue);
  var year=dt.getFullYear();
  var flag=true;
  //alert(year);
  if(subValue>year){
      flag=false;
  }
  return flag;

}

function iszeros(value){
   var number=value;
   //alert(number.indexOf("+"));
   if(number.indexOf("+")==0){
     var actual=number.substring(1);
     //alert(actual);
     if(!isNaN(actual)){
         if(parseFloat(actual)==0){
             return false;
         }
     }
   }else{
       if(!isNaN(number)){
         if(parseFloat(number)==0){
             return false;
         }
     }

   }
  return true;

}


     function isNumberMarks(evt) {
             var charCode = (evt.which) ? evt.which : evt.keyCode
             if (((charCode < 46 && charCode != 8 && charCode != 9) || charCode > 57 ))
                return false;

             return true;
          }

      function isNumberDate(evt) {
         var charCode = (evt.which) ? evt.which : evt.keyCode
         if (((charCode < 47 && charCode != 8 && charCode != 9) || charCode > 57 ))
            return false;

         return true;
      }

/*** global variables*****/


/********** changePassword *********/

function changePassword(){
    var old = document.getElementById('oldPassword');
    var newPass = document.getElementById('newPassword');
    var cfmPass = document.getElementById('cfmPassword');
//    alert(document.getElementById('oldPassword').value);
    if(old.value == '' && old.value.length==0){
        alert('Please Enter Old Password');
        old.focus();
        return false;
    }
    else if(newPass.value == '' && newPass.value.length==0){
        alert('Please Enter New Password');
        newPass.focus();
        return false;
    }
    else if(cfmPass.value == '' && cfmPass.value.length==0){
        alert('Please Enter Confirm Password');
        cfmPass.focus();
        return false;
    }
    else if(cfmPass.value != newPass.value){
        alert('New Password and Confirm Password must be same');
        cfmPass.focus();
        return false;
    }
}

function changeEmail(addr){
	 var field=document.getElementById(addr);
     // var regex = /^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
     // var regex = /^([a-zA-Z]([-._][a-zA-Z0-9])*)+([a-z0-9A-Z]([-._]?[a-z0-9A-Z]))*@([a-zA-Z0-9]+[-.])*([a-zA-Z]){1,3}$/
     var regex = /^([a-zA-Z]([-._][a-zA-Z0-9])*)+([a-z0-9A-Z]([-._]?[a-z0-9A-Z]))*@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/
      var email=field.value;
        if(regex.test(email)==false){
        alert("Please enter valid e-mail address ");
        field.focus();
        return false;
        }
     return true;
}

