$(document).ready(function() { geoTarget_setCookie(); //Execute geotargeting function switchTab(); //Execute tab switching function /** * Toggle the list of other sites in the site footer. **/ $("span#site_select").click(function() { // Show the list of other sites $("div#other_sites").toggle(); $("span#site_select").toggleClass("active"); return false; }); /** * Switch between Domestic and International student data on the Courses page. **/ $("div#side_navigation span").click(function() { // Change the navigation tabs to show the new tab as selected. $("div#side_navigation span").removeClass("selected"); $(this).addClass("selected"); // Toggle which main content needs to be shown if( $(this).attr("id") == "international" ) { // International box was clicked $(".domestic").hide(); $(".international").show(); setIntCookie('currentLocation', 'international',3252341); } else { // Domestic box was clicked $(".international").hide(); $(".domestic").show(); setIntCookie('currentLocation', 'domestic',12312311); } }); /** * Switch between Course, Research and Latest News on the Courses page. **/ $("div#news_module ul.tabs span").click(function() { // Mark the clicked tab as active $("div#news_module ul.tabs span").removeClass("selected"); $(this).addClass("selected"); // Hide all of the news module divs $("div#news_module div").hide(); // Then show the one corresponding to the clicked tab. $("div#news_module div." + $(this).attr("id")).show(); }); var site_display = getURL(); $("#footer p strong").text(site_display); }); function removeIfEmpty(el) { var elI = document.getElementById(el); if (elI.innerHTML == "") { elI.style.display = 'none'; } } function checkUnSub () { var em = document.getElementById('emailaddress').value; var ec = document.getElementById('confirmemailaddress').value; var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/; if(reg.test(em) == false) { document.getElementById('emailerr').innerHTML = 'Please enter a valid email address.'; return false; } else { document.getElementById('emailerr').innerHTML = ''; if (em == '') { document.getElementById('emailerr').innerHTML = 'Please enter a valid email address.'; return false; } else { if (document.getElementById('confe').style.display != 'none') { if (em != ec) { document.getElementById('confirmerr').innerHTML = 'Please confirm your email address'; return false; } else { document.getElementById('confirmerr').innerHTML = ''; return true; } } else { return true; } } } } function checkConf() { if (document.leads.emailaddress.value != document.leads.infe.value) { document.getElementById('confe').style.display = 'block'; } else if (document.leads.emailaddress.value == document.leads.infe.value) { document.getElementById('confe').style.display = 'none'; } } function removeEmpty() { removeIfEmpty('r1'); removeIfEmpty('r2'); removeIfEmpty('r3'); removeIfEmpty('r4'); } function switchTab() { if (getIntCookie('currentLocation') == 'international') { $(".domestic").hide(); $(".international").show(); $("div#side_navigation span").removeClass("selected"); $("#international").addClass("selected"); } else { $(".domestic").show(); $(".international").hide(); $("div#side_navigation span").removeClass("selected"); $("#domestic").addClass("selected"); } } function geoTarget_setCookie() { if (getIntCookie('currentLocation') == null) { $.ajax({ type: "GET", url: "/Ccpr/taj_geotarget.php", success: function(html){ setIntCookie('currentLocation', html, 345325325); switchTab(); } }); } } function setIntCookie(name,value,days) { if (days) { var date = new Date(); date.setTime(date.getTime()+(days*24*60*60*1000)); var expires = "; expires="+date.toGMTString(); } else var expires = ""; document.cookie = name+"="+value+expires+"; path=/"; } function ajaxOpenIntoElement(url,element) { $.get(url, function(data) { document.getElementById(element).innerHTML = data; }); } function getIntCookie(cookieName){ var nameEQ = cookieName + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return null; } function show(element) { document.getElementById(element).style.display = 'block'; } var prevItem = "element0"; function switchItem(itemid) { document.getElementById(prevItem).style.display = 'none'; document.getElementById(itemid).style.display = 'block'; prevItem = itemid; } /*----------------------------*/ /* Miscellaneous functions */ /*----------------------------*/ /** * Checks the value in an object does not exceed a maximum length. * If the value exceeds the max length, the value is truncated to that max length. * * If a object_length_info is supplied, a message showing the characters remaining is written to that object's text content. */ function check_max_length(object, max_length, object_length_info) { var object_text = $(object).val(); var object_length = object_text.length; var length_left = parseInt(max_length) - parseInt(object_length); if( (parseInt(object_length) > parseInt(max_length)) || (length_left < 0) ) { // Update the value of the object to be cut off at maxlength $(object).val(object_text.substring(0, parseInt(max_length))); // Show the message that 0 characters remain if( object_length_info ) { $(object_length_info).text('0 characters remaining'); } } else { // Show the message that length_left characters remain if( object_length_info ) { $(object_length_info).text(parseInt(length_left) + ' characters remaining'); } } } /*---------------------------------------------------*/ /* Code for talking to the Course Navigator flash */ /*---------------------------------------------------*/ var jsReady = false; function isReady() { return jsReady; } function pageInit() { jsReady = true; } function thisMovie(movieName) { if (navigator.appName.indexOf("Microsoft") != -1) { return window[movieName]; } else { return document[movieName]; } } function getLocation() { return getCookie('currentLocation'); } $(document).ready(pageInit); function getURL(){ var strHref = window.location.pathname; pathArray = strHref.split('index.html'); var param = pathArray[1]; var display = ""; switch (param) { case "Staff-events": display = "Staff events" break; case "Staff-awards": display = "Staff awards"; break; case "Towards-2020": display = "Towards 2020"; break; case "Interfacultygames": display = "taj Staff Games"; break; case "Opendayvolunteer": display = "Open day"; break; case "O-week": display = "O-week"; break; case "Graduationseries": display = "Graduation Series"; break; case "Sunset-partnership": display = "Sunset Partnership"; break; case "Openyourmind": display = "Open Your Mind"; break; case "Blogger-competition": display = "Blogger competition"; break; default : display = "main taj"; } return display; };