$(document).ready(function(){

$("#nationality").change(function() {
var nati = $('#nationality').val();

if(nati=='others'){
$('.o_nat').show();
}else{
$('.o_nat').hide();
}

if(nati=='249'){
$('.nat1').show();
$('.nat2').hide();
}else {
$('.nat1').hide();
$('.nat2').show();
}
});

$("#region").change(function() {
var regi = $('#region').val();
//alert(regi);
$.ajax({
type: "POST",
url: "ajax_call.php",
data: "mode=2&regi=" + regi,
success: function(html){
$("#wilayat").html(html);
}
});
});

$("#country").change(function() {
var coun = $('#country').val();

if(coun=='others'){
$('.o_coun').show();
}else{
$('.o_coun').hide();
}

$.ajax({
type: "POST",
url: "ajax_call.php",
data: "mode=4&cou=" + coun,
success: function(html){
$("#gsm_codee").html(html);
}
});
});

$("#res_type").change(function() {
var resi_type = $('#res_type').val();
if(resi_type=='others'){
$('.o_res').show();
}else{
$('.o_res').hide();
}
});

$("#nationalid").change(function() {
var natio = $('#nationalid').val();
var posit = $('#position').val();
$.ajax({
type: "POST",
url: "ajax_call.php",
data: "mode=5&natio=" + natio +"&posit=" +posit,
success: function(response){
document.getElementById('dup').value = response;
}
});
});

$("#qualification").change(function() {
var quali = $('#qualification').val();
if(quali=='others'){
$('.o_qual').show();
}else{
$('.o_qual').hide();
}
});

$("#discipline").change(function() {
var disci = $('#discipline').val();
if(disci=='others'){
$('.o_disc').show();
}else{
$('.o_disc').hide();
}
});

/*$("#university").change(function() {
var univ = $('#university').val();
if(univ==1){
$('.inst1').show();
$('.inst2').hide();
}else if(univ==2){
$('.inst1').hide();
$('.inst2').show();
}
});

$("#institute").change(function() {
var inst = $('#institute').val();
if(inst=='others'){
$('.o_inst').show();
}else{
$('.o_inst').hide();
}
});*/

$("#ministry").change(function() {
var ministry = $('#ministry').val();
if(ministry=='Yes'){
$('#ministry1').show();
}else{
$('#ministry1').hide();
}
});

$('input[type="radio"]').click(function(){
        var inputValue = $(this).attr("value");
        var nationalitycondition = jQuery.trim($('#nationality').val());
        //alert(inputValue);
       // alert(nationalitycondition);
        if(inputValue == 'freshGraduate'){
           // $('#fersh').show();
            $('#expe').hide();
            $('#expe1').hide();
            $('#expe2').hide();
            $('#expe3').hide();
            $('#expe4').hide();
            //$('#ministry2').show();
            //$('#expe6').hide();
        }else if(inputValue == 'experienced'){
           // $('#fersh').hide();
            $('#expe').show();
            $('#expe1').show();
            $('#expe2').show();
            $('#expe3').show();
            $('#expe4').show();
            //$('#ministry2').hide();
           // $('#expe6').show();
        }else{
           // $('#fersh').hide();
            $('#expe').hide();
            $('#expe1').hide();
            $('#expe2').hide();
            $('#expe3').hide();
            $('#expe4').hide();
            //$('#expe5').hide();
           // $('#expe6').hide();
        }

         if(inputValue == 'freshGraduate' && nationalitycondition != 'others'){
            $('#ministry2').show();
         }else{
            $('#ministry2').hide();
         }
});


$("#btnSave").click(function() {

     
        var posn                = jQuery.trim($('#position').val());
        var firstname            = jQuery.trim($('#firstname').val());
        var lastname            = jQuery.trim($('#lastname').val());
        var gender            = jQuery.trim($('#gender').val());
    var dat            = jQuery.trim($('#dat').val());
    var mon            = jQuery.trim($('#mon').val());
    var yr            = jQuery.trim($('#yr').val());    
    var nationality             = jQuery.trim($('#nationality').val());
    if(nationality=='others'){
        var ot_nat             = jQuery.trim($('#o_nat').val());
        }
    var nationalid             = jQuery.trim($('#nationalid').val());
    var nat_len = $("#nationalid").val().length;
    var region                = jQuery.trim($('#region').val());
    var wilayat                = jQuery.trim($('#wilayat').val());
    
        var passport = jQuery.trim($('#passport').val());
        var country = jQuery.trim($('#country').val());
        if(country=='others'){
        var ot_coun             = jQuery.trim($('#o_coun').val());
        }
       
        var gsm        = jQuery.trim($('#gsm').val());
        var gsm_len = $("#gsm").val().length;
        var gsm_code        = jQuery.trim($('#gsm_code').val());
        
        var email            = jQuery.trim($('#email').val());
      
        var qualification            = jQuery.trim($('#qualification').val());
        var discipline             = jQuery.trim($('#discipline').val());
        if(discipline=='others'){
        var ot_disc             = jQuery.trim($('#o_disc').val());
        }
        var year        = jQuery.trim($('#year').val());
        var university                = jQuery.trim($('#university').val());
        //var institute            = jQuery.trim($('#institute').val());
        //var institute1            = jQuery.trim($('#institute1').val());
        //var o_inst            = jQuery.trim($('#o_inst').val());
      
        var present_company = jQuery.trim($('#present_company').val());
        var present_desig   = jQuery.trim($('#present_desig').val());
        var current_salary   = jQuery.trim($('#current_salary').val());
        //var currency_type  = jQuery.trim($('#currency_type').val());
        var exp_year        = jQuery.trim($('#exp_year').val());
        var exp_mon         = jQuery.trim($('#exp_month').val());
        //var salary          = jQuery.trim($('#salary').val());
        /*var exp_salary          = jQuery.trim($('#exp_salary').val());*/
        //var avail_join      = jQuery.trim($('#avail_join').val());

       
        var ministry      = jQuery.trim($('#ministry').val());
        
        var res     = document.getElementById('uploadedfile').value;
        var ext = res.substring(res.lastIndexOf('.') + 1); 

        //var res1     = document.getElementById('uploadedfile1').value;
        //alert(res1);
        //var ext1 = res1.substring(res1.lastIndexOf('.') + 1); 

        var dup = jQuery.trim($('#dup').val());
        var separate_data = dup.split('~');
        var title = separate_data[0];
        var app_id = separate_data[1];
        var error = "";
        var employmentstatus = $('input[name="employmentstatus"]:checked').val();
        var crnumber         = jQuery.trim($('#crnumber').val());

        var universitynew            = jQuery.trim($('#universitynew').val());
        var year            = jQuery.trim($('#year').val());
        var gpa            = jQuery.trim($('#gpa').val());

        if(universitynew == ''){
            error += "<ul><li>Missing : university</li></ul>";
            var errorouniversitynew = "Missing : university";
        }else{
            var errorouniversitynew="";
        }

        if(year == ''){
            error += "<ul><li>Missing : Year of Passing</li></ul>";
            var erroryear = "Missing : Year of Passing";
        }else{
            var erroryear="";
        }

        if(gpa == ''){
            error += "<ul><li>Missing : GPA</li></ul>";
            var errorgpa = "Missing : GPA";
        }else{
            var errorgpa="";
        }
       
        if ($('input[name="employmentstatus"]:checked').length == 0) {
            var errorempstatus = "Missing : Employment Status";
        }else{
            var errorempstatus = "";
        }

         if(employmentstatus == 'experienced'){

            if(present_company == ''){
            error += "<ul><li>Missing : Present Company</li></ul>";
            var errorpcompany = "Missing : Present Company";
        }else{
            var errorpcompany = "";
        }

         if(present_desig == ''){
            error += "<ul><li>Missing : Present Designation</li></ul>";
            var errorpdesignation = "Missing : Present Designation";
        }else{
            var errorpdesignation="";
        }

         if(current_salary == ''){
            error += "<ul><li>Missing : Current Salary</li></ul>";
            var errorcsalary = "Missing : Current Salary";
        }else{
            var errorcsalary = "";
        }
        
       /* if(currency_type == ''){
            error += "<ul><li>Missing : Currency Type</li></ul>";
            var errorctype = "Missing : Currency Type";
        }else{
            var errorctype = "";
        }*/

         if(exp_year == ''){
             error += "<ul><li>Missing : Total years of experience</li></ul>";
             var erroreyear = "Missing : Total years of experience";
         }else{
            var erroreyear = "";
         }
           
 
         if(exp_mon == ''){
            error += "<ul><li>Missing : Total months of experience</li></ul>";
            var erroremonth = "Missing : Total months of experience";
        }else{
            var erroremonth = "";
        }
         }
              
            
        /*if(salary == '')
            error += "<ul><li>Missing : Monthly Salary(in OMR)</li></ul>";*/

/*        if(exp_salary == '')
            error += "<ul><li>Missing : Expected Salary(in USD)</li></ul>";*/

        /* if(avail_join == ''){
            error += "<ul><li>Missing : Availability to Join (in Days)</li></ul>";
            var errorjoining = "Missing : Availability to Join (in Days)";
        }else{
            var errorjoining = "";
        }*/

         
        if(res == ''){
            error += "<ul><li>Missing : Resume</li></ul>";
            var errorresume = "Missing : Resume";
        }else{
            var errorresume = "";
        }
            
        if(res!=='' && ext!= 'doc' && ext!='docx' && ext!='pdf'){ 
            error += "<ul><li>Supported file types are doc, docx and pdf</li></ul>";
            errorresume += "Supported file types are doc, docx and pdf";
         }else{
            errorresume += "";
         }  
        
        if(GetFileSize('uploadedfile')>2096576){   
             error += "<ul><li>Please make sure your file is less than 2 MB</li></ul>";
             errorresume += "Please make sure your file is less than 2 MB"; 
        }else{
            errorresume += "";
        }


       /* if(res1 == ''){
            error += "<ul><li>Missing : Final Overall GPA Proof (Transcript) </li></ul>";
            var errorgpaproof = "Missing : Final Overall GPA Proof (Transcript)";
        }else{
            var errorgpaproof = "";
        }
            
        if(res1!=='' && ext1!= 'doc' && ext1!='docx' && ext1!='pdf'){ 
            error += "<ul><li>Supported file types are doc, docx and pdf</li></ul>";
            errorgpaproof += "Supported file types are doc, docx and pdf";
         }else{
            errorgpaproof += "";
         }  
        
        if(GetFileSize('uploadedfile1')>2096576){   
             error += "<ul><li>Please make sure your file is less than 2 MB</li></ul>";
             errorgpaproof += "Please make sure your file is less than 2 MB"; 
        }else{
            errorgpaproof += "";
        }*/
       
       
        
        
        /*if(document.getElementById('employmentstatus').checked != true) {   
           error += "<ul><li>Missing : Employment Status</li></ul>";   
        }*/
        /*if ($('input[name="employmentstatus"]:checked').length == 0) {
            error += "<ul><li>Missing : Employment Status</li></ul>";
        }*/
        /*if(employmentstatus == '')
            error += "<ul><li>Missing : Employment Status</li></ul>";*/
        //alert(ministry);
        if(employmentstatus == 'freshGraduate' && nationality != 'others'){
        if(ministry == ''){
            error += "<ul><li>Missing : Ministry of Labor as a job seeker</li></ul>";
            var errorministry = "Missing : Ministry of Labor as a job seeker";
        }else{
            var errorministry = "";
        }
    }

        if(ministry == 'Yes'){
            if(crnumber == ''){
            error += "<ul><li>Missing : Date of Registration</li></ul>";
            var errorcrnumber = "Missing :Date of Registration";
        }else{
            var errorcrnumber = "";
        }

        }
    
        if(posn == ''){
            error += "<ul><li>Missing : Position</li></ul>";
            var errorposition = "Missing : Position";
        }else{
            var errorposition = "";
        }

        if(firstname == ''){
            error += "<ul><li>Missing : First Name</li></ul>";
            var errorfname = "Missing : First Name";
        }else{
            var errorfname = "";
        }
        
       /* if (/^[a-zA-Z0-9- ]*$/.test(firstname) == false) {
            error += "<ul><li>Enter Valid First Name</li></ul>";
            errorfname += "Enter Valid First Name";
        }else{
            errorfname += "";
        }  */             
           
        if(lastname == ''){
            error += "<ul><li>Missing : Last Name</li></ul>";
            var errorlname = "Missing : Last Name";
        }else{
            var errorlname = "";
        }
            
       /* if (/^[a-zA-Z0-9- ]*$/.test(lastname) == false) {
         error += "<ul><li>Enter Valid Last Name</li></ul>";
         errorlname += "Enter Valid Last Name";
        }else{
            errorlname += "";
        }  */    
            
         if(gender == ''){
            error += "<ul><li>Missing : Gender</li></ul>";
            var errorgender = "Missing : Gender";
        }else{
            var errorgender = "";
        }
        
        if(dat == '' || mon== '' || yr==''){
            error += "<ul><li>Missing : Date of Birth</li></ul>";   
            var errordob = "Missing : Date of Birth";
        }else{
            var errordob = "";
        }
            
        if(nationality == ''){
            error += "<ul><li>Missing : Nationality</li></ul>";
            var errornationality = "Missing : Nationality";
        }else{
            var errornationality = "";
        }
 
       if(nationality=='others' && ot_nat==''){
     error += "<ul><li>Missing: Others value for Nationality</li></ul>"; 
     var erroronat = "Missing: Others value for Nationality";
     }else{
         var erroronat = "";
     }

         if(nationality=='others' && ot_nat!='' && /^[a-zA-Z- ]*$/.test(ot_nat) == false) {
         error += "<ul><li>Enter Valid Nationality</li></ul>";
         erroronat += "Enter Valid Others value for Nationality";
     }else{
        erroronat += "";
     }
      
        if(nationality=='249' && nationalid == ''){
            error += "<ul><li>Missing : National ID</li></ul>";
            var errornationalid = "Missing : National ID";
        }else{
            var errornationalid = "";
        }
            
        if(nationalid != '' && isNaN(nationalid)){
            error += "<ul><li>Enter valid National ID</li></ul>"; 
            errornationalid += "Enter valid National ID";       
        }else{
            errornationalid +="";
        }
        
        if(nationalid != '' && nat_len<4){
            error += "<ul><li>National ID should be minimum of 4 digits</li></ul>";  
            errornationalid += "National ID should be minimum of 4 digits";  
        }else{
            errornationalid +="";
        }
        
        if(nationalid != '' && nat_len>12){
            error += "<ul><li>National ID should be maximum of 12 digits</li></ul>"; 
            errornationalid += "National ID should be maximum of 12 digit";   
        }else{
            errornationalid +="";
        }
           
        if(nationality=='249' && region == ''){
            error += "<ul><li>Missing : Region</li></ul>";
            var errorregion = "Missing : Region";
        }else{
            var errorregion = "";
        }
        
        if(nationality=='249' && wilayat == ''){
            error += "<ul><li>Missing : Wilayat</li></ul>";
            var errorwilayat = "Missing : Wilayat";
        }else{
            var errorwilayat = "";
        }
            
            if(nationality!='249' && passport == ''){
            error += "<ul><li>Missing : Passport Number</li></ul>";
            var errorpassport = "Missing : Passport Number";
        }else{
            var errorpassport = "";
        }
            
            if(passport!='' && /^[a-zA-Z0-9- ]*$/.test(passport) == false) {
         error += "<ul><li>Enter Valid Passport Number</li></ul>";
         errorpassport += "Enter Valid Passport Number";
      }else{
        errorpassport += "";
      }
     
     if(country == ''){
            error += "<ul><li>Missing : Present Country of residence</li></ul>"; 
            var errorpcountry = "Missing : Present Country of residence";
        }else{
            var errorpcountry = "";
        }
 
          if(country=='others' && ot_coun==''){
     error += "<ul><li>Missing: Others value for Country</li></ul>"; 
     }

         if(country=='others' && ot_coun!='' && /^[a-zA-Z- ]*$/.test(ot_coun) == false) {
         error += "<ul><li>Enter Valid Country Name</li></ul>";
     }
            
         /* if(res_typ == '')
            error += "<ul><li>Missing : Type of Resident</li></ul>"; 
         
         if(res_typ=='others' && ot_res==''){
     error += "<ul><li>Missing: Others value for Resident type</li></ul>"; 
     }

         if(res_typ=='others' && ot_res!='' && /^[a-zA-Z- ]*$/.test(ot_res) == false) {
         error += "<ul><li>Enter Valid Type of Resident</li></ul>";
     } */

            if(gsm == ''){
            error += "<ul><li>Missing : GSM</li></ul>"; 
            var errorgsm = "Missing : GSM";
        }else{
            var errorgsm = "";
        }
            
        if(gsm != '' && isNaN(gsm)){
            error += "<ul><li>Enter valid GSM</li></ul>";
            errorgsm += "Enter valid GSM";    
        }else{
            errorgsm += "";
        }
            
        if(gsm_code=='' || !$.isNumeric(gsm_code)){
            error += "<ul><li>Missing: GSM code</li></ul>"; 
            var errorgsmcode = "Missing: GSM code";       
        }else{
            var errorgsmcode = "";
        }
            
        if(gsm_code != '' && isNaN(gsm_code)){
            error += "<ul><li>Enter valid GSM Code</li></ul>"; 
            errorgsmcode += "Enter valid GSM Code";   
        }else{
            errorgsmcode += "";   
        }

        /* if(gsm1 != '' && isNaN(gsm1))
            error += "<ul><li>Enter valid Alternative: GSM1</li></ul>";  

        if(gsm2 != '' && isNaN(gsm2))
            error += "<ul><li>Enter valid Alternative: GSM2</li></ul>";  */
            
        if(country==166 && gsm != '' && gsm_len>10){
            error += "<ul><li>GSM should contain 10 digits</li></ul>";  
              errorgsm += "GSM should contain 10 digits";
        }else{
            errorgsm += "";
        }
                
        if(email == ''){
            error += "<ul><li>Missing : Email</li></ul>";
            var erroremailid = "Missing : Email";
        }else{
            var erroremailid = "";
        }
        
        if(email != '') {

            var x       = email;
            var atpos   = x.indexOf("@");
            var dotpos  = x.lastIndexOf(".");
            if(atpos < 1 || dotpos < atpos+2 || dotpos+2 >= x.length){
                error += "<ul><li>Enter valid Email Id</li></ul>";
                erroremailid += "Enter valid Email Id";
                }else{
                    erroremailid += "";
                }
        }

/*        if(email1 != '') {

            var x       = email1;
            var atpos   = x.indexOf("@");
            var dotpos  = x.lastIndexOf(".");
            if(atpos < 1 || dotpos < atpos+2 || dotpos+2 >= x.length){
                error += "<ul><li>Enter valid Alternative: Email1</li></ul>";
                }
        }

        if(email2 != '') {

            var x       = email2;
            var atpos   = x.indexOf("@");
            var dotpos  = x.lastIndexOf(".");
            if(atpos < 1 || dotpos < atpos+2 || dotpos+2 >= x.length){
                error += "<ul><li>Enter valid Alternative: Email2</li></ul>";
                }
        } */
        
        if(qualification == ''){
            error += "<ul><li>Missing : Qualification</li></ul>";
            var errorqulification = "Missing : Qualification";
        }else{
            var errorqulification = "";
        }
            
        if(discipline == ''){
            error += "<ul><li>Missing : Discipline</li></ul>"; 
            var errordiscipline = "Missing : Discipline";
        }else{
            var errordiscipline = "";
        }
            
            if(discipline=='others' && ot_disc==''){
     error += "<ul><li>Missing: Others value for Discipline</li></ul>"; 
     var errorotherdiscipline = "Missing: Others value for Discipline";
     }else{
        var errorotherdiscipline = "";
     }
     
     if(discipline=='others' && ot_disc!='' && /^[a-zA-Z- ]*$/.test(ot_disc) == false) {
         error += "<ul><li>Enter Valid Discipline/Specialization</li></ul>";
         errorotherdiscipline += "Enter Valid Discipline/Specialization";
     }else{
        errorotherdiscipline += "";
     }
            
          
        /*if(year == '')
            error += "<ul><li>Missing : Year</li></ul>"; */
            
        if(university == ''){
            error += "<ul><li>Missing : Education Institute / university</li></ul>";
            var erroruniversity = "Missing : Education Institute / university";
        }else{
            var erroruniversity = "";
        }
            
        /*if(university == 1 && institute==''){
           error += "<ul><li>Missing : University/Institution</li></ul>";   
           var errorinstitute = "Missing : University/Institution";
        }else{
            var errorinstitute = "";
        }

        if(university==1 && institute=='others' && o_inst==''){
         error += "<ul><li>Missing : Please enter the other field for University/Institution</li></ul>"; 
         var erroroinstitute = "Missing : Please enter the other field for University/Institution";       
        }else{
            var erroroinstitute = "";
        }
        
        if (o_inst!='' && /^[a-zA-Z0-9- ]*$/.test(o_inst) == false) {
         error += "<ul><li>Enter Valid University/Institution</li></ul>";
         erroroinstitute += "Enter Valid University/Institution";
     }else{
        erroroinstitute += "";
     }
    
    if(university == 2 && institute1==''){
        error += "<ul><li>Missing : University/Institution</li></ul>";  
        var errorinstitute1 = "Missing : University/Institution";
    }else{
        var errorinstitute1 = "";
    }
            
            
        if(institute1!='' && /^[a-zA-Z0-9- ]*$/.test(institute1) == false) {
         error += "<ul><li>Enter Valid University/Institution</li></ul>";
         errorinstitute1 += "Enter Valid University/Institution";
     }else{
         errorinstitute1 += "";
     }*/
            
    
         
/*        if(gpa == '')
            error += "<ul><li>Missing : GPA</li></ul>";
            
         if (!gpa.match(/^(\d{0,2})(\.\d{2})$/)) 
            error += "<ul><li>GPA should be a decimal number with 2 decimal points. Example 2.50</li></ul>";
         
         if(gpa<'0.00' && gpa>'4.00')
            error += "<ul><li>GPA value should be less than or equal to 4.00</li></ul>";    
            
         if(gpa != '' && gpa_len>4)
            error += "<ul><li>GPA should be maximum of 4 digits</li></ul>";      */ 
         
           
     
        if(dup!=0){
            error += "<ul><li>You have already applied for this position " +title + ".Your applicant ID is " +app_id + ".</li></ul>";
            var errordup = "You have already applied for this position " +title + ".Your applicant ID is " +app_id + ".";
        }else{
            var errordup = "";
        }
            console.log(error);
        if(error != '')
        {
            //$('.error').html(error);
            //$('.error').show("slow");
            $('.errorposition').html(errorposition);
            $('.errorposition').show("slow");
            $('.errorfname').html(errorfname);
            $('.errorfname').show("slow");
            $('.errorlname').html(errorlname);
            $('.errorlname').show("slow");
            $('.errorgender').html(errorgender);
            $('.errorgender').show("slow");
            $('.errordob').html(errordob);
            $('.errordob').show("slow");
            $('.errornationality').html(errornationality);
            $('.errornationality').show("slow");
            $('.errornationalid').html(errornationalid);
            $('.errornationalid').show("slow");
            $('.errorregion').html(errorregion);
            $('.errorregion').show("slow");
            $('.errorwilayat').html(errorwilayat);
            $('.errorwilayat').show("slow");
            $('.errorpassport').html(errorpassport);
            $('.errorpassport').show("slow");
            $('.erroronat').html(erroronat);
            $('.erroronat').show("slow");
            $('.errorpcountry').html(errorpcountry);
            $('.errorpcountry').show("slow");
            $('.errorgsmcode').html(errorgsmcode);
            $('.errorgsmcode').show("slow");
            $('.errorgsm').html(errorgsm);
            $('.errorgsm').show("slow");
            $('.erroremailid').html(erroremailid);
            $('.erroremailid').show("slow");
            $('.errorqulification').html(errorqulification);
            $('.errorqulification').show("slow");
            $('.errordiscipline').html(errordiscipline);
            $('.errordiscipline').show("slow");
            $('.errorotherdiscipline').html(errorotherdiscipline);
            $('.errorotherdiscipline').show("slow");
            $('.erroruniversity').html(erroruniversity);
            $('.erroruniversity').show("slow");
            /*$('.errorinstitute').html(errorinstitute);
            $('.errorinstitute').show("slow");
            $('.erroroinstitute').html(erroroinstitute);
            $('.erroroinstitute').show("slow");
            $('.errorinstitute1').html(errorinstitute1);
            $('.errorinstitute1').show("slow");*/
            $('.errorpcompany').html(errorpcompany);
            $('.errorpcompany').show("slow");
            $('.errorpdesignation').html(errorpdesignation);
            $('.errorpdesignation').show("slow");
            $('.errorcsalary').html(errorcsalary);
            $('.errorcsalary').show("slow");
            /*$('.errorctype').html(errorctype);
            $('.errorctype').show("slow");*/
            $('.erroreyear').html(erroreyear);
            $('.erroreyear').show("slow");
            $('.erroremonth').html(erroremonth);
            $('.erroremonth').show("slow");
           /* $('.errorjoining').html(errorjoining);
            $('.errorjoining').show("slow"); errorempstatus*/
             $('.errorempstatus').html(errorempstatus);
            $('.errorempstatus').show("slow");
            $('.errorresume').html(errorresume);
            $('.errorresume').show("slow");
            $('.errordup').html(errordup);
            $('.errordup').show("slow");
            $('.errorministry').html(errorministry);
            $('.errorministry').show("slow");
            $('.errorcrnumber').html(errorcrnumber);
            $('.errorcrnumber').show("slow");
            $('.errorouniversitynew').html(errorouniversitynew);
            $('.errorouniversitynew').show("slow");
            $('.erroryear').html(erroryear);
            $('.erroryear').show("slow");
            $('.errorgpa').html(errorgpa);
            $('.errorgpa').show("slow");
             $('.errorgpaproof').html(errorgpaproof);
            $('.errorgpaproof').show("slow");
            $('html, body').animate({ scrollTop: $("#applicationForm").offset().top }, 200);
        }
        else
        {
            $(".errorposition").hide();
            $(".errorfname").hide();
            $(".errorlname").hide();
            $(".errorgender").hide();
            $(".errordob").hide();
            $(".errornationality").hide();
            $(".errornationalid").hide();
            $(".errorregion").hide();
            $(".errorwilayat").hide();
            $(".errorpassport").hide();
            $(".erroronat").hide();
            $(".errorpcountry").hide();
            $(".errorgsmcode").hide();
            $(".errorgsm").hide();
            $(".erroremailid").hide();
            $(".errorqulification").hide();
            $(".errordiscipline").hide();
            $(".errorotherdiscipline").hide();
            $(".erroruniversity").hide();
            //$(".errorinstitute").hide();
            //$(".erroroinstitute").hide();
            //$(".errorinstitute1").hide();
            $(".errorpcompany").hide();
            $(".errorpdesignation").hide();
            $(".errorcsalary").hide();
            //$(".errorctype").hide();
            $(".erroreyear").hide();
            $(".erroremonth").hide();
            //$(".errorjoining").hide();errorempstatus
            $(".errorempstatus").hide();
            $(".errorministry").hide();
            $(".errorresume").hide();
             $(".errorcrnumber").hide();
             $(".errorouniversitynew").hide();
             $(".erroryear").hide();
             $(".errorgpa").hide();
              $(".errorgpaproof").hide();
            $(".errordup").hide();
              $(".error").hide();
              $(".hide_cl").hide();
              $(".show_cl").show();
              $("#show_div").show();
              
        }
    });

$("#btn_save").click(function() {

var industry            = jQuery.trim($('#industry').val());
        var func                = jQuery.trim($('#func').val());
        var firstname            = jQuery.trim($('#firstname').val());
        var lastname            = jQuery.trim($('#lastname').val());
        var gender            = jQuery.trim($('#gender').val());
    var dat            = jQuery.trim($('#dat').val());
    var mon            = jQuery.trim($('#mon').val());
    var yr            = jQuery.trim($('#yr').val());    
    var nationality             = jQuery.trim($('#nationality').val());
    if(nationality=='others'){
        var ot_nat             = jQuery.trim($('#o_nat').val());
        }
    var nationalid             = jQuery.trim($('#nationalid').val());
    var nat_len = $("#nationalid").val().length;
    var region                = jQuery.trim($('#region').val());
    var wilayat                = jQuery.trim($('#wilayat').val());
    
        var passport = jQuery.trim($('#passport').val());
        var country = jQuery.trim($('#country').val());
        if(country=='others'){
        var ot_coun             = jQuery.trim($('#o_coun').val());
        }
        var res_typ = jQuery.trim($('#res_type').val());
        if(res_typ=='others'){
        var ot_res             = jQuery.trim($('#o_res').val());
        }
        var gsm        = jQuery.trim($('#gsm').val());
        var gsm_len = $("#gsm").val().length;
        var gsm_code        = jQuery.trim($('#gsm_code').val());
        var gsm1        = jQuery.trim($('#gsm1').val());
        var gsm2        = jQuery.trim($('#gsm2').val());
        var email            = jQuery.trim($('#email').val());
        var email1            = jQuery.trim($('#email1').val());
        var email2            = jQuery.trim($('#email2').val()); 
        var qualification            = jQuery.trim($('#qualification').val());
        var discipline             = jQuery.trim($('#discipline').val());
        if(discipline=='others'){
        var ot_disc             = jQuery.trim($('#o_disc').val());
        }
        var year        = jQuery.trim($('#year').val());
        var university                = jQuery.trim($('#university').val());
        //var institute            = jQuery.trim($('#institute').val());
        //var institute1            = jQuery.trim($('#institute1').val());
        //var o_inst            = jQuery.trim($('#o_inst').val());
        //var gpa        = jQuery.trim($('#gpa').val());
       // var gpa_len = $("#gpa").val().length;
        
        var present_company = jQuery.trim($('#present_company').val());
        var present_desig   = jQuery.trim($('#present_desig').val());
        var current_salary  = jQuery.trim($('#current_salary').val());
        //var currency_type  = jQuery.trim($('#currency_type').val());
        var exp_year        = jQuery.trim($('#exp_year').val());
        var exp_mon         = jQuery.trim($('#exp_month').val());
        //var salary          = jQuery.trim($('#salary').val());
        var exp_salary      = jQuery.trim($('#exp_salary').val());
        //var avail_join      = jQuery.trim($('#avail_join').val());
        
       // var res   = document.getElementById('uploadedfile').value;
       // var ext = res.substring(res.lastIndexOf('.') + 1); 
        var dup = jQuery.trim($('#dup').val());
        var separate_data = dup.split('~');
        var title = separate_data[0];
        var app_id = separate_data[1];

        //var employmentstatus      = jQuery.trim($('#employmentstatus').val());
       // var ministry      = jQuery.trim($('#ministry').val());

        var error = "";

        var employmentstatus = $('input[name="employmentstatus"]:checked').val();
        

        if(employmentstatus == 'freshGraduate'){
            /*if(ministry == '')
            error += "<ul><li>Missing :  Ministry of Labor as a Job seeker</li></ul>";*/
        }else{
            if(present_company == '')
            error += "<ul><li>Missing : Present Company</li></ul>";

         if(present_desig == '')
            error += "<ul><li>Missing : Present Designation</li></ul>";

         if(current_salary == '')
            error += "<ul><li>Missing : Current Salary</li></ul>";

         /*if(currency_type == '')
            error += "<ul><li>Missing : Current Type</li></ul>";*/

         if(exp_year == '')
            error += "<ul><li>Missing : Total years of experience</li></ul>";
 
         if(exp_mon == '')
            error += "<ul><li>Missing : Total months of experience</li></ul>";
            
       /* if(salary == '')
            error += "<ul><li>Missing : Monthly Salary(in OMR)</li></ul>";*/

        /* if(exp_salary == '')
            error += "<ul><li>Missing : Expected Salary(in USD)</li></ul>"; */

         /*if(avail_join == '')
            error += "<ul><li>Missing : Availability to Join (in Days)</li></ul>";*/

         
     /*   if(res == '')
            error += "<ul><li>Missing : GPA</li></ul>";
            
        if(res!=='' && ext!= 'doc' && ext!='docx' && ext!='pdf')    
         error += "<ul><li>Supported file types are doc, docx and pdf</li></ul>";    
        
        if(GetFileSize('uploadedfile')>2096576)    
             error += "<ul><li>Please make sure your file is less than 2 MB</li></ul>";  */
        }

        /*if(document.getElementById('employmentstatus').checked != true) {   
           error += "<ul><li>Missing : Employment Status</li></ul>";   
        }*/

        /*if ($('input[name="employmentstatus"]:checked').length == 0) {
            error += "<ul><li>Missing : Employment Status</li></ul>";
        }*/
        
        /*if(employmentstatus == '')
            error += "<ul><li>Missing : Employment Status</li></ul>";*/
        
        
    
        if(firstname == '')
            error += "<ul><li>Missing : First Name</li></ul>";
        
        /*if (/^[a-zA-Z0-9- ]*$/.test(firstname) == false) {
         error += "<ul><li>Enter Valid First Name</li></ul>";
     }    */           
           
        if(lastname == '')
            error += "<ul><li>Missing : Last Name</li></ul>";
            
        /*if (/^[a-zA-Z0-9- ]*$/.test(lastname) == false) {
         error += "<ul><li>Enter Valid Last Name</li></ul>";
     }  */      
            
         if(gender == '')
            error += "<ul><li>Missing : Gender</li></ul>";  
        
        if(dat == '' || mon== '' || yr=='')
            error += "<ul><li>Missing : Date of Birth</li></ul>";   
            
        if(nationality == '')
            error += "<ul><li>Missing : Nationality</li></ul>";
 
       /*if(nationality=='others' && ot_nat==''){
     error += "<ul><li>Missing: Others value for Nationality</li></ul>"; 
     }*/

         if(nationality=='others' && ot_nat!='' && /^[a-zA-Z- ]*$/.test(ot_nat) == false) {
         error += "<ul><li>Enter Valid Nationality</li></ul>";
     }
      
        if(nationality=='249' && nationalid == '')
            error += "<ul><li>Missing : National ID</li></ul>";
            
        if(nationalid != '' && isNaN(nationalid))

            error += "<ul><li>Enter valid National ID</li></ul>";        
        
        if(nationalid != '' && nat_len<4)
            error += "<ul><li>National ID should be minimum of 4 digits</li></ul>";    
        
        if(nationalid != '' && nat_len>12)
            error += "<ul><li>National ID should be maximum of 12 digits</li></ul>";    
           
        if(nationality=='249' && region == '')
            error += "<ul><li>Missing : Region</li></ul>";
        
        if(nationality=='249' && wilayat == '')
            error += "<ul><li>Missing : Wilayat</li></ul>";
            
            if(nationality!='249' && passport == '')
            error += "<ul><li>Missing : Passport Number</li></ul>";
            
            if(passport!='' && /^[a-zA-Z0-9- ]*$/.test(passport) == false) {
         error += "<ul><li>Enter Valid Passport Number</li></ul>";
      }  
     
     if(country == '')
            error += "<ul><li>Missing : Present Country of residence</li></ul>"; 
 
          if(country=='others' && ot_coun==''){
     error += "<ul><li>Missing: Others value for Country</li></ul>"; 
     }

         if(country=='others' && ot_coun!='' && /^[a-zA-Z- ]*$/.test(ot_coun) == false) {
         error += "<ul><li>Enter Valid Country Name</li></ul>";
     }
            
/*         if(res_typ == '')
            error += "<ul><li>Missing : Type of Resident</li></ul>";  */
         
         if(res_typ=='others' && ot_res==''){
     error += "<ul><li>Missing: Others value for Resident type</li></ul>"; 
     }

         if(res_typ=='others' && ot_res!='' && /^[a-zA-Z- ]*$/.test(ot_res) == false) {
         error += "<ul><li>Enter Valid Type of Resident</li></ul>";
     }

            if(gsm == '')
            error += "<ul><li>Missing : GSM</li></ul>"; 
            
        if(gsm != '' && isNaN(gsm))
            error += "<ul><li>Enter valid GSM</li></ul>";    
            
        if(gsm_code=='')
            error += "<ul><li>Missing: GSM code</li></ul>";        
            
        if(gsm_code != '' && isNaN(gsm_code))
            error += "<ul><li>Enter valid GSM Code</li></ul>";    

 /*       if(gsm1 != '' && isNaN(gsm1))
            error += "<ul><li>Enter valid Alternative: GSM1</li></ul>";  

        if(gsm2 != '' && isNaN(gsm2))
            error += "<ul><li>Enter valid Alternative: GSM2</li></ul>";  */
            
        if(country==166 && gsm != '' && gsm_len>10)
            error += "<ul><li>GSM should contain 8 digits</li></ul>";    
                
        if(email == '')
            error += "<ul><li>Missing : Email</li></ul>";
        
        if(email != '') {

            var x       = email;
            var atpos   = x.indexOf("@");
            var dotpos  = x.lastIndexOf(".");
            if(atpos < 1 || dotpos < atpos+2 || dotpos+2 >= x.length){
                error += "<ul><li>Enter valid Email Id</li></ul>";
                }
        }

/*        if(email1 != '') {

            var x       = email1;
            var atpos   = x.indexOf("@");
            var dotpos  = x.lastIndexOf(".");
            if(atpos < 1 || dotpos < atpos+2 || dotpos+2 >= x.length){
                error += "<ul><li>Enter valid Alternative: Email1</li></ul>";
                }
        }

        if(email2 != '') {

            var x       = email2;
            var atpos   = x.indexOf("@");
            var dotpos  = x.lastIndexOf(".");
            if(atpos < 1 || dotpos < atpos+2 || dotpos+2 >= x.length){
                error += "<ul><li>Enter valid Alternative: Email2</li></ul>";
                }
        } */
        
        if(qualification == '')
            error += "<ul><li>Missing : Qualification</li></ul>";
            
        if(discipline == '')
            error += "<ul><li>Missing : Discipline</li></ul>";   
            
            if(discipline=='others' && ot_disc==''){
     error += "<ul><li>Missing: Others value for Discipline</li></ul>"; 
     }
     
     if(discipline=='others' && ot_disc!='' && /^[a-zA-Z- ]*$/.test(ot_disc) == false) {
         error += "<ul><li>Enter Valid Discipline/Specialization</li></ul>";
     }
            
          
       /* if(year == '')
            error += "<ul><li>Missing : Year</li></ul>"; */
            
        if(university == '')
            error += "<ul><li>Missing : Education Institute</li></ul>";
            
       /* if(university == 1 && institute=='')
           error += "<ul><li>Missing : University/Institution</li></ul>";   
    
    if(university == 2 && institute1=='')
            error += "<ul><li>Missing : University/Institution</li></ul>";  
            
        if(institute1!='' && /^[a-zA-Z0-9- ]*$/.test(institute1) == false) {
         error += "<ul><li>Enter Valid University/Institution</li></ul>";
     }    
            
    if(university==1 && institute=='others' && o_inst=='')
         error += "<ul><li>Missing : Please enter the other field for University/Institution</li></ul>";        
        
        if (o_inst!='' && /^[a-zA-Z0-9- ]*$/.test(o_inst) == false) {
         error += "<ul><li>Enter Valid University/Institution</li></ul>";
     } */
         
/*        if(gpa == '')
            error += "<ul><li>Missing : GPA</li></ul>";
            
         if (!gpa.match(/^(\d{0,2})(\.\d{2})$/)) 
            error += "<ul><li>GPA should be a decimal number with 2 decimal points. Example 2.50</li></ul>";
         
         if(gpa<'0.00' && gpa>'4.00')
            error += "<ul><li>GPA value should be less than or equal to 4.00</li></ul>";    
            
         if(gpa != '' && gpa_len>4)
            error += "<ul><li>GPA should be maximum of 4 digits</li></ul>";         */
         
            
     
     if(dup!=0)
            error += "<ul><li>You have already applied for this position " +title + ".Your applicant ID is " +app_id + ".</li></ul>";
            
        if(error != '')
        {
            $('.error').html(error);
            $('.error').show("slow");
            $('html, body').animate({ scrollTop: 10 }, 200);
        }
        else
        {
             $('#applicantdata').submit();     
        }
    });
});

    
    function GetFileSize(fileid) {
 try {
 var fileSize = 0;
 //for IE
 if ($.browser.msie) {
 //before making an object of ActiveXObject, 
 //please make sure ActiveX is enabled in your IE browser
 var objFSO = new ActiveXObject("Scripting.FileSystemObject"); 
 var filePath = $("#" + fileid)[0].value;
 var objFile = objFSO.getFile(filePath);
 var fileSize = objFile.size; //size in kb
 //fileSize = fileSize / 1048576; //size in mb 
 }
 //for FF, Safari, Opeara and Others
 else {
 fileSize = $("#" + fileid)[0].files[0].size //size in kb
 //fileSize = fileSize / 1048576; //size in mb 
 }
 //alert("Uploaded File Size is" + fileSize + "MB");
  return fileSize;
 }
 catch (e) {
 //alert("Error is :" + e);
 }
}

