var searchFields={keywords:"",location:"",sector:"",proximity:"",titleonly:"",partTimeOnly:"",fullTimeOnly:""};
var advSearchFields={keywords:"",keywordPhraseInc:"",keywordCouldInc:"",keywordNotInc:"",subjectID:"",location:"",partTimeOnly:"",fullTimeOnly:"",excludeHomeStudy:"",minPrice:"",maxPrice:"",types:"",awardingBody:"",startdate:"",endDate:""};
function UpdateSearchParams(){searchFields.keywords=$("#Keywords").val();searchFields.location=$("#Location").val();
searchFields.sector=$("#SubjectID").children("option:selected").text();searchFields.proximity=$("#Proximity").children("option:selected").text();
searchFields.titleonly=($("#chkTitleOnly").is(":checked"))?"Yes":"No";searchFields.partTimeOnly=($("#Schedule").val()==="PartTime")?"Yes":"No";
searchFields.fullTimeOnly=($("#Schedule").val()==="FullTime")?"Yes":"No";}function UpdateAdvSearchParams(){advSearchFields.keywords=$("#Keywords").val();
advSearchFields.keywordPhraseInc=$("#KeywordPhraseInc").val();advSearchFields.keywordCouldInc=$("#KeywordCouldInc").val();
advSearchFields.keywordNotInc=$("#KeywordNotInc").val();if($("input[name=SubjectID]:checked").length>0){advSearchFields.subjectID="selected";
}if($("input[name=Types]:checked").length>0){advSearchFields.types="selected";}advSearchFields.excludeHomeStudy=($("#ExcludeHomeStudy").is(":checked"))?"Yes":"No";
advSearchFields.partTimeOnly=($("#Schedule").val()==="PartTime")?"Yes":"No";advSearchFields.fullTimeOnly=($("#Schedule").val()==="FullTime")?"Yes":"No";
advSearchFields.awardingBody=$("#AwardingBody").val();advSearchFields.endDate=($("#EndDate").val()=="dd/mm/yyyy")?"":$("#EndDate").val();
advSearchFields.startdate=($("#StartDate").val()=="dd/mm/yyyy")?"":$("#StartDate").val();
advSearchFields.maxPrice=($("#MaxPrice").val()=="To")?"":$("#MaxPrice").val();advSearchFields.minPrice=($("#MinPrice").val()=="From")?"":$("#MinPrice").val();
advSearchFields.location=$("#Location").val();}$(document).ready(function(){$("#Location").autocomplete("/learningcentre/location/filterlocation",{dataType:"json",parse:function(C){var B=new Array();
for(var A=0;A<C.length;A++){B[A]={data:C[A],value:C[A].Name,result:C[A].Name};}return B;
},formatItem:function(A){return A.Name;},width:199,minChars:2,selectFirst:false,max:10,delay:100,scroll:false,cacheLength:2});
});function CheckAdvancedForm(){var B=document.forms[0];var C="";var A="";var E=0;
var D=0;$.each(B["SubjectID"],function(F,G){if(G.checked){C+=G.parentNode.innerText;
C+=",";E++;}D++;});if(E==D){C="";}$.each(B["Types"],function(F,G){if(G.checked){A+=G.id;
A+=",";}});UpdateAdvSearchParams();if(advSearchFields.keywords==""&&advSearchFields.keywordPhraseInc==""&&advSearchFields.keywordCouldInc==""&&advSearchFields.keywordNotInc==""&&advSearchFields.subjectID==""&&advSearchFields.location==""&&advSearchFields.awardingBody==""&&advSearchFields.endDate==""&&advSearchFields.excludeHomeStudy=="No"&&advSearchFields.fullTimeOnly=="No"&&advSearchFields.maxPrice==""&&advSearchFields.minPrice==""&&advSearchFields.partTimeOnly=="No"&&advSearchFields.startdate==""&&advSearchFields.types==""){$("#errorBoxKeywords").html("<ul><li>Please ensure you have entered some search criteria.</li></ul>");
$("#errorBoxKeywords").fadeIn(500);return false;}LogAdvSearchParams(C,A);return ValLocation(advSearchFields.location);
}function CheckForm(){UpdateSearchParams();if(searchFields.keywords==""&&searchFields.location==""&&searchFields.sector=="All Subjects"&&searchFields.partTimeOnly=="No"&&searchFields.fullTimeOnly=="No"){$("#errorBoxKeywords").fadeIn(500);
return false;}LogSearchParams();return ValLocation(searchFields.location);}function ValLocation(B){var A=true;
var C=/^\w{1,2}\d+/.test(B);if(B!=""){$.ajax({type:"POST",url:"/learningcentre/location/searchlocation",data:{q:B},async:false,dataType:"json",success:function(E,D){A=E.AbsoluteMatch;
if(!A){if(E.Results.length>0){$("#errorMessageLocation").html("<b>"+B+" not recognised, did you mean?...</b><br />");
$.each(E.Results,function(F,G){$("<a href='javascript: void(0)'>"+G.UniqueName+"</a><br />").click(function(){$("#Location").val(G.UniqueName);
$("#errorBoxLocation").hide();}).appendTo("#errorMessageLocation");if(F==10){return false;
}});}else{$("#errorMessageLocation").html("<b>You entered "+B+" No location suggestions found</b><br />");
}$("#errorBoxLocation").fadeIn(500);}}});}return A;}function LogSearchParams(){UpdateSearchParams();
dcsMultiTrack("DCS.dcsuri","/LearningCentre/search.html","DCSext.LogType","CourseSearch","DCSext.Keywords",searchFields.keywords,"DCSext.LocationName",searchFields.location,"DCSext.Sector",searchFields.sector,"DCSext.Proximity",searchFields.proximity,"DCSext.SearchTitleOnly",searchFields.titleonly);
}function LogAdvSearchParams(A,B){dcsMultiTrack("DCS.dcsuri","/LearningCentre/search.html","DCSext.LogType","AdvancedSearch","DCSext.Keywords",advSearchFields.keywords,"DCSext.LocationName",advSearchFields.location,"DCSext.Sectors",A,"DCSext.Proximity",advSearchFields.proximity,"DCSext.SearchTitleOnly",advSearchFields.titleonly,"DCSext.KeywordPhraseInc",advSearchFields.KeywordPhraseInc,"DCSext.KeywordCouldInc",advSearchFields.KeywordCouldInc,"DCSext.KeywordNotInc",advSearchFields.KeywordNotInc,"DCSext.ExcludeHomeStudy",advSearchFields.excludeHomeStudy,"DCSext.PartTimeOnly",advSearchFields.partTimeOnly,"DCSext.FullTimeOnly",advSearchFields.fullTimeOnly,"DCSext.AwardingBody",advSearchFields.awardingBody,"DCSext.EndDate",advSearchFields.endDate,"DCSext.MaxPrice",advSearchFields.maxPrice,"DCSext.MinPrice",advSearchFields.minPrice,"DCSext.CourseTypes",B);
}
