$(function(){function getUrlParam(name,url){if(!url)url=window.location.href;name=name.replace(/[\[\]]/g,'\\$&');var regex=new RegExp('[?&]'+name+'(=([^&#]*)|&|#|$)'),results=regex.exec(url);if(!results)return null;if(!results[2])return'';return decodeURIComponent(results[2].replace(/\+/g,' '));} JSON.parseOrNull=function(str){try{return JSON.parse(str);}catch(e){return null;}} let searchModel={text:getUrlParam("text"),level:JSON.parseOrNull(getUrlParam("level"))||[],career:JSON.parseOrNull(getUrlParam("career"))||[],interest:JSON.parseOrNull(getUrlParam("interest"))||[],mode:JSON.parseOrNull(getUrlParam("mode"))||[],clearing:JSON.parseOrNull(getUrlParam("clearing"))||[],intake:JSON.parseOrNull(getUrlParam("intake"))||[]};let searchRoot=JSON.parseOrNull(getUrlParam("level"))||[];$("#activeFilters .active-filter").each(function(){let $filter=$(this);$('#courseFilters [data-filter-type], #newsFilters [data-filter-type]').filter(function(){return $(this).data("filter-type")===$filter.data("filter-type")&&$(this).data("filter-val")===$filter.data("filter-val");}).toggleClass("toggled");});$("#courseSearchForm form").submit(function(e){e.preventDefault();var text=$(this).find('input[type=search]').val();if(window.location.pathname.startsWith('/college-and-sixth-form')){if(window.location.pathname.startsWith('/college-and-sixth-form/college')){window.location.href="/college-and-sixth-form/college/courses/?text="+text;} else if(window.location.pathname.startsWith('/college-and-sixth-form/sixth-form-centre')){window.location.href="/college-and-sixth-form/sixth-form-centre/courses/?text="+text;} else{window.location.href="/college-and-sixth-form/courses/?text="+text;}} else{if(window.location.pathname.startsWith('/university/undergraduate')){window.location.href="/university/undergraduate/courses/?text="+text;} else if(window.location.pathname.startsWith('/university/postgraduate')){window.location.href="/university/postgraduate/courses/?text="+text;} else{window.location.href="/university/courses/?text="+text;}}});function refreshCourses(){$("#courseListing").prepend('
');document.activeElement.blur();$("html, body").animate({scrollTop:$("#courseListing").offset().top-220},150);$.ajax({url:"/umbraco/surface/SearchSurface/CourseSearch/",type:'POST',dataType:"html",data:{model:searchModel,searchRoot:searchRoot},success:function(result){$("#courseListing").html(result);$("#courseListing .course.card").on("click",function(e){$(this).find(".find-out-btn")[0].click();}) if($(window).outerWidth(true)>991){$('.course-info').each(function(){let hs=$(this)[0].scrollWidth>$(this)[0].clientWidth;if(hs){var cardScrollIndicator=$(this).siblings('.scroll-indicator')[0];$(cardScrollIndicator).css('display','block');}});$('.course-info').scroll(function(){let percentScroll=($(this).width()+$(this).scrollLeft())/$(this)[0].scrollWidth;var cardScrollIndicator=$(this).siblings('.scroll-indicator')[0];if(percentScroll>0.95){$(cardScrollIndicator).fadeOut();} else{if(parseInt($(cardScrollIndicator).css('opacity'))<1||$(cardScrollIndicator).css('display')=='none'){$(cardScrollIndicator).fadeIn();}}});$('.scroll-indicator').click(function(e){e.stopPropagation();var courseInfo=$(this).siblings('.course-info')[0];let rightHandScroll=$(courseInfo)[0].scrollWidth-$(courseInfo).width();$(courseInfo).animate({scrollLeft:rightHandScroll},800);});} displayResultCount($("#courseListing .course").length);},error:function(xhr,ajaxOptions,error){alert(error);}});} function refreshMatches(){if(!searchModel.level.length){$("#questionResults").hide();}else{$("#questionResults").show();const token=$("#RequestVerificationToken").val() $.ajax({url:"/umbraco/surface/SearchSurface/GetCourseSearchCount/",type:'POST',dataType:"json",headers:{RequestVerificationToken:token},data:{model:searchModel},success:function(result){if(result){$("#questionResults form input[name=interest]").val(JSON.stringify(searchModel.interest));$("#questionResults form input[name=career]").val(JSON.stringify(searchModel.career));$("#questionResults form input[name=level]").val(JSON.stringify(searchModel.level));$("#questionResults h3").text("You've got "+result+" potential matches");$("#questionResults form button").show();}else{$("#questionResults form button").hide();$("#questionResults h3").text("Sorry we couldn't find any matches, please try less options");}},error:function(xhr,ajaxOptions,error){alert(error);}});}} function addFilter(type,val,text){searchModel[type].push(val);let $span=$(document.createElement('span'));let txt=text||val;$span.addClass("active-filter").data("filter-type",type).data("filter-val",val).text(txt).append("