$(document).ready(function(){

//Calling the functionality of fancy box plugin.

$(".thumb_container a[rel=group1]").fancybox({
                        'transitionIn'		: 'none',
                        'transitionOut'		: 'none',
                        'titlePosition' 	: 'over',
                        'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
                                return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
                        }
                });
$("#sendloader").hide();
    //Onload displaying the current vacancies.
    $.ajax({
        type:"POST",
        url:"description.php",
        success:function(response){
            $("#pn_list").html(response);
           $("#pn_list li:odd").addClass("odd");
        }
    });
    //loading the prefered location.
    $.ajax({
        type:"POST",
        url:"preferedlocation.php",
        success:function(response){
           $("#pn_location").html(response);
           $("#pn_location").next().hide();
        }
    });
     //loading the prefered department.
    $.ajax({
        type:"POST",
        url:"prefereddepartment.php",
        success:function(response){
           $("#pn_department").html(response);
           $("#pn_department").next().hide();
        }
    });
    //highlighting the Careers link if there is any opening.
       $.ajax({
        type:"POST",
        url:"pn_checkvacancy.php",
        success:function(response){
            if(response!=0){
                $(".nav_links li:nth-child(6)").addClass("new");
             }
        }
    });
    //onclick on the apply button in current vacancies page.
    $(".apply_link").live('click',function(e){
        var data=$(e.currentTarget).attr("title");
        location.href="pn_appy.php?data="+data;
    });
    //keypress for validation.
    $(".required").keypress(function(e){
        if(e.keyCode==13){
            validation();
        }
    });
    //browser back link.
    $("#pn_back").click(function(){
        parent.history.back();
        return false;
    });
    //Redirecting to register page.
    $("#pn_novacancy").live('click',function(){
               $('.inner_content .l .one').hide();
               $('.inner_content .l .two').show();
               $('.inner_content .l .three').hide();
    });

});
 function validation(){
             var candidatename=$("#cand_name").val();
             var resume=$("#resume_title").val();
             var prefereddepartment=$("#pref_dept").val();
             var mobileno=$("#mobile").val();
             var emailid=$("#cand_email").val();
             var workexp=$("#work_exp").val();
             var location=$("#pref_loc").val();
             var file=$("#pn_file").val();
             var recaptchachallengefield=$("#recaptcha_challenge_field").val();
             var recaptcharesponsefield=$("#recaptcha_response_field").val();
             var noticeperiod=$("#notice_period").val();
             var alphaexp1=/[a-zA-Z]/;
             var atpos=emailid.indexOf("@");
             var dotpos=emailid.lastIndexOf(".");
             var alphaexp2=/[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]/;
             var value=$("#pn_value").val();
             var ext = $('#pn_file').val().split('.').pop().toLowerCase();


             if(candidatename!=""){
                      if(candidatename.match(alphaexp1)){
                                    if(mobileno!=""){
                                                        if(mobileno.length=="10"){
                                                            if(mobileno.match(alphaexp2)){
                                                                if(prefereddepartment!=""){
                                                                      if(workexp!=""){
                                                                                          if(emailid!=""){
                                                                                                 if(atpos<1 || dotpos<atpos+2 || dotpos+2>=emailid.length){
                                                                                                        alert("Email Id is not correct");
                                                                                                        return false;
                                                                                                    }else{
                                                                                                          if(location !=""){
                                                                                                              var extension = file.substr( (file.lastIndexOf('.') +1) );
                                                                                                                   if(file!="" && (extension=="doc" || extension=="docx" || extension=="pdf" || extension=="txt")){
                                                                                                                               if(resume!=""){
                                                                                                                                        if(noticeperiod!=""){
                                                                                                                                               $.ajax({
                                                                                                                                                       type:"POST",
                                                                                                                                                       url:"validationofcaptcha.php",
                                                                                                                                                       data:"recaptcha_challenge_field=" + recaptchachallengefield + "&recaptcha_response_field=" + recaptcharesponsefield,
                                                                                                                                                       success:function(response){
                                                                                                                                                           if(response=="success"){
                                                                                                                                                               $("#sendloader").show();
                                                                                                                                                               $(".contactform_button").attr("disabled","disabled");
                                                                                                                                                               
                                                                                                                                                               document.registered.submit();
                                                                                                                                                           }else{
                                                                                                                                                               alert("Enter the letters shown in the captcha below correctly.");
                                                                                                                                                           }
                                                                                                                                                       }
                                                                                                                                            });
                                                                                                                                        }else{
                                                                                                                                            alert("Enter the Notice Period");
                                                                                                                                            return false;
                                                                                                                                        }
                                                                                                                                }else{
                                                                                                                                   alert("Enter the Resume Title");
                                                                                                                                    return false;
                                                                                                                               }
                                                                                                                        }else{
                                                                                                                       alert("Upload a valid resume. \nAllowed file formats: .doc, .docx, .txt & .pdf.");
                                                                                                                       return false;
                                                                                                                   }

                                                                                                                }else{
                                                                                                                    alert("Enter the Location");
                                                                                                                    return false;
                                                                                                                }
                                                                                                  }
                                                                                          }else{
                                                                                              alert("Enter the Email Id");
                                                                                              return false;
                                                                                          }
                                                                                }else{
                                                                                    alert("Enter the Work Experience");
                                                                                    return false;
                                                                                }
                                                                      
                                                                }else{
                                                                    alert("Enter the Prefered Department");
                                                                    return false;
                                                                }
                                                            }else{
                                                                alert("Mobile Number Should consist only Numbers");
                                                                return false;
                                                            }
                                                        }else{
                                                            alert("Mobile Number should be 10 digit");
                                                            return false;
                                                        }
                                             }else{
                                                 alert("Enter the Mobile Number");
                                                 return false;
                                             }

                                                
                                         

                          }else{
                              alert("Candidates Name Should Consist Only Letters");
                              return false;
                          }
                     }else{
                         alert("Enter the Candidates Name");
                         return false;
                     }

 }

