/*global alert, document, self, window*/ /* * $RCSfile: XmlHttp.js,v $ * * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2005 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /** logging enabled **/ var doLogging = false; if(typeof window.console != 'undefined'){ doLogging = true; } //end on load functions function fixNav() { if ($('navigationBar')) { var firstLink = $('navigationBar').getElement('ul[class=horizontal_lists]').getElement('li').getElement('a'); //alert(firstLink); firstLink.set('title','Information about studying at Coventry University'); //http://alumni.coventry.ac.uk/NetCommunity/Page.aspx?pid=191 var alumniLink = $('navigationBar').getElement('ul[class=horizontal_lists]').getElements('li')[5].getElement('a'); alumniLink.set('href','http://alumni.coventry.ac.uk/NetCommunity/Page.aspx?pid=191'); } if ($('qlUrl')) { //http://wwwp.coventry.ac.uk/university-sites-and-information/a/1989 $('qlUrl').getChildren('option').each(function(item){ if(item.get("value") == 'http://www.coventry.ac.uk/undergraduate-study/open-days') { item.set("value",'http://wwwm.coventry.ac.uk/opendays/Pages/opendays.aspx'); } }); } if ($('linkcloud')) { var OnlineStore = $('linkcloud').getElement('ul[class=horizontal_lists]').getElements('li')[1].getElement('a'); OnlineStore.set('title','Coventry University\'s online shop for unversity merchandise and event tickets'); } } function GetXmlHttp() { var xmlHttp = null; try { xmlHttp = new XMLHttpRequest(); } catch (e) { try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { xmlHttp = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { xmlHttp = false; } } } if (!xmlHttp && typeof XMLHttpRequest != 'undefined') { xmlHttp = new XMLHttpRequest(); } return xmlHttp; } function SendHttpPost(xmlHttp, url, args, callback) { xmlHttp.open("POST", url, /* async */ true); xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); xmlHttp.onreadystatechange = function() { callback(xmlHttp); } xmlHttp.send(args); } function SendHttpGet(xmlHttp, url, callback) { try { xmlHttp.open("GET", url, /* async */ true); } catch (e) { } xmlHttp.onreadystatechange = function() { callback(xmlHttp); } xmlHttp.send("FOO"); } /*** end xmlHTTP.js**/ /* * $RCSfile: AutoComplete.js,v $ * * Gallery - a web based photo album viewer and editor * Copyright (C) 2000-2005 Bharat Mediratta * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or (at * your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ /* * Inspired by code from: * - Guyon Roche (http://www.webreference.com/programming/javascript/gr/column5/) * - Zichun (http://codeproject.com/jscript/jsactb.asp) */ var autoCompleteContexts = new Array(); var immediateSubmit = true; var g_PopupIFrame; var navRules; function isIE() { return ( navigator.appName=="Microsoft Internet Explorer" ); } function hidePopupDiv(divPopup) { divPopup.style.visibility = "hidden"; if (isIE() && g_PopupIFrame != null) { document.body.removeChild(g_PopupIFrame); g_PopupIFrame = null; } } function showPopupDiv(divPopup) { if (!isIE()) { //Just display the div divPopup.style.visibility = "visible"; return; } //Increase default zIndex of div by 1, so that DIV appears before IFrame divPopup.style.zIndex = divPopup.style.zIndex+1; var iFrame = document.createElement("IFRAME"); iFrame.setAttribute("src", ""); //Match IFrame position with divPopup iFrame.style.position = "absolute"; iFrame.style.left = divPopup.offsetLeft + 'px'; iFrame.style.top = divPopup.offsetTop + 'px'; iFrame.style.width = divPopup.offsetWidth + 'px'; iFrame.style.height = divPopup.offsetHeight + 'px'; document.body.appendChild(iFrame); //Store iFrame in global variable, so it can get removed when divPopup is hidden if (g_PopupIFrame != null) { document.body.removeChild(g_PopupIFrame); } g_PopupIFrame = iFrame; divPopup.style.visibility = "visible"; } String.prototype.trim = function () { return this.replace(/^\s*/, "").replace(/\s*$/, ""); } function autoCompleteTrigger(id) { var responseCallback = function(response) { if (response.readyState != 4) { return; } if (response.responseText.trim().length > 0) { results = response.responseText.split("\n"); autoCompleteContexts[id]['results'] = new Array(); for (i = 0; i < results.length; i++) { autoCompleteContexts[id]['results'][i] = results[i]; } autoCompleteRender(id); } else { autoCompleteContexts[id]['results'] = new Array(); autoCompleteHide(id); } } if (document.getElementById(id).value.trim().length > 0) { var url = autoCompleteContexts[id]['url'].replace( /__VALUE__/, escape(document.getElementById(id).value)); // encodeURI(document.getElementById(id).value)); SendHttpGet(autoCompleteContexts[id]['connection'], url, responseCallback); //autoCompleteContexts[id]['results'] = new Array(); //for (i = 0; i < 10; i++) { // autoCompleteContexts[id]['results'][i] = "Accountancy BA Honours Degree "+i; //} autoCompleteRender(id); } else { autoCompleteContexts[id]['results'] = new Array(); autoCompleteHide(id); } } function autoCompleteGetLeft(element) { var offset = 0; while (element) { offset += element.offsetLeft; element = element.offsetParent; } return offset; } function autoCompleteGetTop(element) { var offset = 0; while (element) { offset += element.offsetTop; element = element.offsetParent; } return offset; } function autoCompleteIsVisible(id) { var autoCompleteId = id + '_autocomplete'; var ac = document.getElementById(autoCompleteId); if (!ac) { return false; } return ac.style.visibility == 'visible'; } function autoCompleteRender(id) { var autoCompleteId = id + '_autocomplete'; var source = document.getElementById(id); var ac = document.getElementById(autoCompleteId); if (!ac) { ac = document.createElement('div'); ac.className = 'autoCompleteBackground'; ac.style.position = 'absolute'; ac.style.zIndex = 2000; ac.id = autoCompleteId; document.body.appendChild(ac); } ac.style.top = eval(autoCompleteGetTop(source) + source.offsetHeight) + 'px'; ac.style.left = autoCompleteGetLeft(source) + 'px'; var matches = autoCompleteFindMatches(source.value, autoCompleteContexts[id]['results']); // Windows gives us backslashes in the path which break the regex, so escape them. escapedValue = source.value.replace(/\\([^u])/g, '\\\\$1'); var regexp = new RegExp("("+escapedValue+")", "i"); if (matches.length > 0) { for (i = 0; i < Math.min(matches.length, 15); i++) { var row; var newHTML = matches[i].replace(regexp, '$1'); if (i >= ac.childNodes.length) { row = document.createElement('div'); ac.appendChild(row); } else { row = ac.childNodes[i]; if (row.innerHTML == newHTML) { // Already up to date continue; } } row.className = 'autoCompleteNotSelected'; row.innerHTML = newHTML; row.ac_data = matches[i]; row.ac_index = i; row.onmousedown = function() { source.value = this.ac_data; if (immediateSubmit) { submitSearchCourses(source.value); } }; row.onmouseover = function() { autoCompleteSelect(id, this); }; row.onmouseout = function() { autoCompleteDeselect(id); }; } while (i < ac.childNodes.length) { ac.removeChild(ac.childNodes[i]); } showPopupDiv(ac); autoCompleteContexts[id]['current'] = -1; } else { hidePopupDiv(ac); } } function autoCompleteMove(id, delta) { var autoCompleteId = id + '_autocomplete'; var ac = document.getElementById(autoCompleteId); if (!ac || ac.childNodes.length == 0) { return; } var source = document.getElementById(id); var current = autoCompleteContexts[id]['current'] + delta; if (current < 0) { current += ac.childNodes.length; } current = current % ac.childNodes.length; autoCompleteSelect(id, ac.childNodes[current]); } function autoCompleteSelect(id, row) { autoCompleteDeselect(id); row.className = 'autoCompleteSelected'; autoCompleteContexts[id]['current'] = row.ac_index; } function autoCompleteDeselect(id) { var current = autoCompleteContexts[id]['current']; if (current != -1) { var autoCompleteId = id + '_autocomplete'; var ac = document.getElementById(autoCompleteId); ac.childNodes[current].className = 'autoCompleteNotSelected'; autoCompleteContexts[id]['current'] = -1; } } function autoCompleteChoose(id) { var current = autoCompleteContexts[id]['current']; if (current != -1) { var autoCompleteId = id + '_autocomplete'; var ac = document.getElementById(autoCompleteId); var source = document.getElementById(id); source.value = ac.childNodes[current].ac_data; autoCompleteHide(id); } } function autoCompleteFindMatches(needle, haystack) { // Windows gives us backslashes in the path which break the regex, so escape them. safeNeedle = needle.replace(/\\([^u])/g, '\\\\$1'); matches = new Array(); var regexp = new RegExp(safeNeedle, "i"); /* for (hay in haystack) { if (regexp.test(haystack[hay])) { matches.push(haystack[hay]); } } */ var i; for (i=0; i < haystack.length; i++) { // if (regexp.test(haystack[i])) { matches.push(haystack[i]); // } } return matches;//.sort(); } function autoCompleteHide(id) { if (autoCompleteContexts[id]['timerId']) { clearTimeout(autoCompleteContexts[id]['timerId']); } autoCompleteId = id + '_autocomplete'; var ac = document.getElementById(autoCompleteId); if (ac) { hidePopupDiv(ac); } } function autoCompleteAttach(id, url) { autoCompleteContexts[id] = new Array(); autoCompleteContexts[id]['connection'] = GetXmlHttp(); autoCompleteContexts[id]['results'] = new Array(); autoCompleteContexts[id]['url'] = url; var source = document.getElementById(id); source.setAttribute("autocomplete", "off"); if (document.all) { // IE doesn't let you set attributes by passing in a lambda function like // Mozilla does. Instead, we have to create a string and pass it to the // Function() constructor. We expand the 'id' and 'url' elements in the // string, but allow the event object to pass through from the calling // scope. Ugh. source.onblur = new Function('autoCompleteHide("' + id + '");'); source.onkeydown = new Function('return autoCompleteHandleEvent("' + id + '", event, "' + url + '"); '); } else { // Everything else source.onblur = function() { autoCompleteHide(id); } source.onkeydown = function(event) { return autoCompleteHandleEvent(id, event, url);} } } function autoCompleteHandleEvent(id, event, url) { switch(event.keyCode) { case 38: // up key autoCompleteMove(id, -1); break; case 40: // down key autoCompleteMove(id, 1); break; case 9: // tab if (autoCompleteIsVisible(id)) { autoCompleteChoose(id); return true; } break; case 13: // enter var source = document.getElementById(id); if (autoCompleteIsVisible(id)) { autoCompleteChoose(id); if (immediateSubmit) { submitSearchCourses(source.value); } return false; } else { submitSearchCourses(source.value); } break; case 27: // escape autoCompleteHide(id); break; default: if (autoCompleteContexts[id]['timerId']) { clearTimeout(autoCompleteContexts[id]['timerId']); } autoCompleteContexts[id]['timerId'] = setTimeout("autoCompleteTrigger(\"" + id + "\")", 250); autoCompleteRender(id); } return true; } /** end AutoComplete.js **/ function hola() { alert("hola"); } /* * if we have an external link open this in a new window */ function quicklinkAction(url){ if(url!='selected'){ if(url.indexOf("http",0) === 0 && url.indexOf('coventry.ac.uk') < 0){ var w=window.open(url); w.focus(); }else{ self.location=url; } } } function searchAttach(id) { var source = document.getElementById(id); if (document.all) { // IE doesn't let you set attributes by passing in a lambda function like // Mozilla does. Instead, we have to create a string and pass it to the // Function() constructor. We expand the 'id' and 'url' elements in the // string, but allow the event object to pass through from the calling // scope. Ugh. source.onkeydown = new Function('return searchHandleEvent("' + id + '", event); '); } else { // Everything else source.onkeydown = function(event) { return searchHandleEvent(id, event);} } } function searchHandleEvent(id, event) { if (event.keyCode == 13) { var source = document.getElementById(id); submitSearch(source.value); } return true; } function submitSearch(queryVal) { if (queryVal != "") { self.location.href="http://wwwm.coventry.ac.uk/search?q=" + queryVal + "&cx=012739113142552960993%3A2acz9qbzrpk&cof=FORID%3A11"; } } function submitSearchCourses(queryVal) { if (queryVal != "") { queryVal = '"' + queryVal + '"'; self.location.href="http://wwwm.coventry.ac.uk/search?q=" + queryVal + "&cx=012739113142552960993%3A1thhlrbwone&cof=FORID%3A11"; } } function setClassName(objId, className) { var doc = document.getElementById(objId).className = className; } function cu_removeNodes(nodeArray) { if (inputNodes != null && inputNodes.length > 0) { for ( var i = 0; i < inputNodes.length; i++) { var parent = inputNodes[i].parentNode; var x = parent.removeChild(inputNodes[i]); } } } function makeMenu3(){ var navId = "navColumn"; //alert("hello"); var navColumn = document.getElementById(navId); var navParentUL; var currentNode; //$('covTools').appendChild(); //alert(navColumn.innerHTML); //get the first ul node as the parent of our for (var i = 0;i < navColumn.childNodes.length;++i) { if (navColumn.childNodes[i].nodeName.toLowerCase() == "ul") { navParentUL = navColumn.childNodes[i]; } } //alert(navParentUL.nodeName); //loop through all the child nodes of the nav and find the li that contains the span tag this is the location of the current node var firstLI = ""; for (var i = 0; i < navParentUL.childNodes.length;++i) { if (navParentUL.childNodes[i].nodeName.toLowerCase() == "li") { if (firstLI == "") { firstLI = navParentUL.childNodes[i]; } var spans = navParentUL.childNodes[i].getElementsByTagName("SPAN"); //alert(spans.length); if (spans.length > 0) { currentNode = navParentUL.childNodes[i]; } else if(!currentNode) { try{ //currentNode = firstLI; var siteMapSpans; var siteMapPath = document.getElementById("ctl00_siteMapPath"); if (siteMapPath) { siteMapSpans = siteMapPath.getElementsByTagName("SPAN"); } var siteNameLink; if (siteMapSpans && siteMapSpans.length > 2) { siteNameLink = siteMapSpans[2].getElementsByTagName("A")[0].getAttribute("HREF"); } if (siteNameLink) { var childInnerHTML = navParentUL.childNodes[i].innerHTML.toLowerCase(); var url = /http:\/\/wwwm\.coventry\.ac\.uk/i; siteNameLink = siteNameLink.toLowerCase().replace(url,""); if (childInnerHTML.indexOf(siteNameLink) > -1) { currentNode = navParentUL.childNodes[i]; } } }catch (e){ //alert("error"); var ten = 10; } } } } if (!currentNode) { //there isn't a current node so we need to find the current site nav in a more obsucre way //this for deep linking and } var re = /