$(document).ready(function(){$(".show_hide fieldset :input:not(.industrySectorIds)").blur(function(){$(this).parents("fieldset").find(":input:not(.industrySectorIds)").each(function(){if($(this).attr("id")=="locationJobTown"){searchForLocation("#upload","locationJobTown",false);return false}else{if($(this).attr("id")=="fullJobDescription"){if($("#summaryJobDescription").val()==""){$("#summaryJobDescription").val($("#fullJobDescription").val().substring(0,239))}if($("#fullJobDescription").val()==""){$("#upload").validate().element($("#fullJobDescription"))}}}})});$(".industrySectorIds").click(function(){var b=0;var a="";$("input[name='industrySectorIds']:checked").each(function(){b++});if(b>0){$(".industryErrorMessage").hide()}else{$(".industryErrorMessage").show()}if(b>5){$("#industryErrorMessage").css("color","red");$("#industryErrorMessage").html("You can choose a maximum of 5 sectors (Please deselect some of the sectors)");this.checked=false}else{$("#industryErrorMessage").css("color","#333");$("#industryErrorMessage").html("You can choose a maximum of 5 sectors ("+(5-b)+" left)");selectedIndustrySectorNumber=5-b;if(this.checked){a='<a href="javascript:void(0)" id="'+$(this).val()+'" onclick="clickSector(this)" title="remove '+$(this).attr("title")+' industry sector">'+$(this).attr("title")+"</a>";$(".selected_sectors").html($(".selected_sectors").html()+a)}else{$("#"+$(this).val()).remove()}}})});function clickSector(b){$("#industrySector"+$(b).attr("id")).attr("checked",false);var a=0;$("input[name='industrySectorIds']:checked").each(function(){a++});$("#industryErrorMessage").html("You can choose a maximum of 5 sectors ("+(5-a)+" left)");$(b).remove()}function validateIndustySectors(){var a=0;$("input[name='industrySectorIds']:checked").each(function(){a++});if(a>5){$("#industryErrorMessage").css("color","red");$("#industryErrorMessage").html("You can choose a maximum of 5 sectors (Please deselect some of the sectors)")}else{$("#industryErrorMessage").css("color","#333333");$("#industryErrorMessage").html("You can choose a maximum of 5 sectors ("+(5-a)+" left)")}if(a==0||a>5){$("#industryHeader").removeClass("valid")}else{$("#industryHeader").addClass("valid")}}function deselectAllCheckboxes(a){$("#"+a).find("input[type=checkbox]").each(function(){if(this.checked){$("#"+$(this).val()).remove()}this.checked=false});$("#industryErrorMessage").css("color","#333333");$("#industryErrorMessage").html("You can choose a maximum of 5 sectors (5 left)")}function fillAdFields(){var c=[];$("input:checkbox[name=industrySectorIds]:checked").each(function(d){c[d]=$(this).attr("title")});var b=c[0];for(var a=1;a<c.length;a++){b+=", "+c[a]}$(".preview_jobtitle").html($("#jobTitle").val()+(($("#jobTitle").val()!=""&&$("#locationJobTown").val()!="")?", ":"")+$("#locationJobTown").val());($("#salaryText").val()!=""||$("#benefits").val()!="")?($(".preview_salary").html("Salary - ")):($(".preview_salary").html(""));$(".preview_salarytext").html($("#salaryText").val()+(($("#salaryText").val()!=""&&$("#benefits").val()!="")?", ":"")+$("#benefits").val());$(".preview_workhours").html($("#workingHoursId option:selected").text());$(".preview_type").html($("#jobTypeId option:selected").text());$(".preview_sectors").html(b);$(".preview_description").html(("\n"+$("#fullJobDescription").val()).replaceAll("\n","<br />"))}function fillPhoneNumber(){if($("#contactTelephone").val()==""){$("#contactTelephone").val($("#tel").val())}}function searchForLocation(d,a,c){var b=true;if($("#"+a).val().length>2){if($("#areaId").length>0&&$("#areaId").val()!=""&&$("#locationCheck").val()==$("#locationJobTown").val()){b=false}if(b){if($(".locationName_error").is(":visible")){$("#"+a).removeClass("error_msg");$(".locationName_error").hide()}$(".chooseLocationBox").html("");$.ajax({type:"POST",url:sChooseLocationURL,data:"locationName="+$("#"+a).val(),success:function(e){if(e!="fail"){if(e=="location_not_supported"){$("#"+a).addClass("error_msg");$(".locationName_error").html("This location is not supported for this site.");$(".locationName_error").show()}else{$(".chooseLocationBox").html(e);$("#locationCheck").val($("#"+a).val());if($(".location_radio").length>0){$(".chooseLocationBox").show()}else{if(c&&$(d).valid()){$(d).submit()}}}}else{if(c){$("#"+a).addClass("error_msg");$(".locationName_error").show()}else{$("#"+a).addClass("error_msg");$(".locationName_error").html("This is not a valid location.");$(".locationName_error").show()}}}})}else{if(c&&$(d).valid()){$(d).submit()}}}else{if(c){$(d).submit()}}$("#"+a).focus(function(){if($(".locationName_error").is(":visible")){$("#"+a).removeClass("error_msg");$(".locationName_error").hide()}if($(".location_radio:checked").length>0&&$("#areaId").val()!=""&&$("#"+a).val().length<3){$(".chooseLocationBox").html("");$("#"+a).removeClass("error_msg");$(".locationName_error").hide()}})}$(document).ready(function(){if($(".amend_adform").length>0){$(".amend_adform").validate({errorClass:"error_msg",errorElement:"span",rules:{tel:{phoneUK:true},address:{required:true},postcode:{required:true,postcodeUK:true},jobTitle:{required:true},durationDays:{required:true,differentThan:"0"},jobTypeId:{required:true},workingHoursId:{required:true},fullJobDescription:{required:true},industrySectorIds:"required",minSalary:{digits:true,required:true},maxSalary:{digits:true,greaterThan:"#minSalary"},locationJobTown:{required:function(a){if($("input[name=radioAreaId]").length>0){$("input[name=radioAreaId]").rules("add",{required:true,messages:{required:"Please choose one or amend your search"}})}},enoughLocationCharacters:true},contactEmail:{required:true,email:true},contactTelephone:{phoneUK:true},applicationURL:{url:true},directURL:{url:true},summaryJobDescription:{required:function(a){if($(a).attr("type")=="hidden"){return false}return true},maxlength:240},startDate:{required:true,date:true},terms:"required"},messages:{industrySectorIds:"You have to choose at least 1 sector",terms:"You have to accept the terms and conditions to continue"}})}});
