var wW = 0; var wH = 0;
var mX = 0; var mY = 0;

window.onresize = winDimensions;
if (!document.all) document.onmousemove = mousePosition;

function winDimensions() {
  if (typeof(window.innerHeight)=="number") {
    wH = window.innerHeight;
    wW = window.innerWidth;
  } else if (document.body && typeof(document.body.offsetHeight)=="number") {
    wH = document.body.offsetHeight;
    wW = document.body.offsetWidth;
  } 
  return;
}

function getURLVar(urlVarName) {
  var urlHalves = String(document.location).split('?');
  var urlVarValue = '';
  if(urlHalves[1]) {
    var urlVars = urlHalves[1].split('&');
    for(i=0; i<=(urlVars.length); i++) {
      if(urlVars[i]) {
//load the name/value pair into an array
        var urlVarPair = urlVars[i].split('=');
        if (urlVarPair[0] && urlVarPair[0] == urlVarName) {
//I found a variable that matches, load it's value into the return variable
          urlVarValue = urlVarPair[1];
        }
      }
    }
    urlVarValue = urlVarValue.replace(/#.*$/, "");
  }
  return urlVarValue;   
}

function pageLoading(onoff) {
  if (onoff) {
    var cover = document.createElement("div");
    cover.style.background = "#FFF"; cover.style.position = "fixed"; cover.style.left = "0px"; cover.style.top = "0px"; cover.style.width = "100%"; cover.style.height = "100%"; cover.style.opacity = ".8"
    cover.style.filter = "alpha(opacity=80)"; cover.style.zOpacity= "0.8"; cover.style.KhtmlOpacity="0.8";
    cover.style.zIndex = "2005";
    cover.style.textAlign = "center"
    cover.setAttribute("id", "__loading");
    var image = document.createElement("img");
    image.src = "/arts/artsdigital/images/icons/ajax-loader.gif";
    image.style.position = "absolute"; image.style.top = (wH / 2)+"px";
    document.body.appendChild(cover);
    cover.appendChild(image);
    setTimeout("pageLoading(false)", 500);
  } else {
    if (_('__loading')) _('__loading').parentNode.removeChild(_('__loading'));
  }
  return;
}

function cleanEmail(text, id, mail) {
  var final = "";
  var let = 0;
  text = text.split("");

  while (let < text.length) {
    if ((let % 3) != 1) final+= text[let];
    let++;
  }
  (mail) ? _(id).href = "mailto:"+final : _(id).innerHTML = final;
  return "";
}

function ServerTime() {
  return getAjax("/arts/artsdigital/PHP/js_returns.php?TIME="+dummyVal());
}

function getAjax(URL, post) {
  var sendType = (post) ? "post" : "get";
  var response;
  var xhr = new createXMLHttpRequest();

  if (post) waiting(true);

  xhr.open(sendType, URL, false);
  if (post) {
    xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xhr.send(post);
  } else xhr.send(null);
  response = xhr.responseText;
  xhr.close;

  if (response.match(/^\s*$/)) response = "";
  waiting(false);
  return response;
}
function waiting(on) {
  if (!document.body) return
  if (!_("_WAITING_")) { 
    var wait = document.createElement("div");
    wait.style.position = "fixed"; wait.style.width="100%"; wait.style.height="100%"; wait.style.left = "0px"; wait.style.top = "0px"; wait.style.opacity = ".8"; wait.style.background = "#FFF"; wait.style.zIndex = "2500";
    wait.setAttribute("id", "_WAITING_"); wait.id = "_WAITING_";
    document.body.appendChild(wait);
  
    var img = document.createElement("img");
    img.src = "/arts/artsdigital/images/icons/ajax-loader.gif";
    img.style.left = "50%"; img.style.top = "50%"; img.style.position = "absolute";
    wait.appendChild(img);
  } 
  if (on) _("_WAITING_").style.visibility = "visible";
  else _("_WAITING_").style.visibility = "hidden";
  return;
}
function dummyVal() {
  var now = new Date;
  return now.getTime();
}

function showTime(obj) {
  if (ServerTime().length && obj) {
    obj.innerHTML = "The time in Sydney is "+ServerTime();
    t = setTimeout(function() { showTime(obj); }, 30000);
  }
  return;
}

function createXMLHttpRequest() {
  try { return new ActiveXObject("Msxml2.XMLHTTP") } catch (e) {}
  try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) {}
  try { return new XMLHttpRequest(); } catch (e) {}
  alert ("XMLHttpRequest not Supported!");
  return null;
}     

function _(id) { return obj = document.getElementById(id); }

function pageLoad() {
  if (_('ServerTime')) showTime(_("ServerTime"));
  winDimensions();

// Something to insert input fields into ones not there previously
  var tags2check = Array("input", "textarea", "select");
  var tmp;
  for (x in tags2check) {
    tmp = document.getElementsByTagName(tags2check[x]);
    for (y in tmp) {
      if (!tmp[y].className || !tmp[y].style) tmp[y].className = "field";
    }
  }

// Clearing out the space created by the false sidebar
  if (_("sidebar")) {
    if (_("sidebar").innerHTML.match(/^\s*$/)) {
      _("sidebar").parentNode.removeChild(_("sidebar"));
      _("content").className+= " nofeature";
    }
  }

  additionalScripts(); // To call any other scripts that need calling nested i nthe content - for IE
  return;
}

if (!window.onload) window.onload = pageLoad;
else {
  window.onload = function() {
    pageLoad();
  }
}

function additionalScripts() { return; }

function openWorkspace() {
  if (!_("WORKSPACE")) {
    var ws = document.createElement("div");
    ws.setAttribute("id", "WORKSPACE");
    ws.setAttribute("style", "position: fixed; left: 0px; top: 0px; background-color: #000; filter: alpha(opacity=70); z-opacity: 0.7; -khtml-opacity: 0.7; opacity: 0.7; width: 100%; height: 100%;");
    document.body.appendChild(ws);
  } else var ws = _('WORKSPACE');
  ws.style.zIndex = 2000;
  ws.style.visibility = "visible";

  if (document.all) {
    ws.style.left = "0px";
    ws.style.top =  "0px";
    ws.style.height = "100%";
    ws.style.width = "100%";
    ws.style.backgroundColor = "#000";
    ws.style.filter = "alpha(opacity=70)";
    document.body.scrollTop = "0px";
  }

  return; 
} 
function closeWorkspace() {
  var WStyle = _('WORKSPACE').style;
  WStyle.visibility = "hidden";
  WStyle.zIndex = -1;
  return;
} 
function centreObjectV(obj, height) {
  if (!height) {
    if (obj.style.height) height = obj.style.height;
    else height = 500;
  }
  var Ypos = Math.ceil((wH - height)/2 - 30);
  if (Ypos < 0) Ypos = 0;
  if (document.all) obj.style.posTop = Ypos;
  else obj.style.top = Ypos+"px";
  return;
}
function centreObjectH(obj, width) {
  if (!width) {
    if (obj.style.width) width = obj.style.width;
    else width = 500;
  }
  var Xpos = Math.ceil((wW - width)/2 - 30);
  if (Xpos < 0) Xpos = 0;
  obj.style.position = "fixed";
  if (document.all) obj.style.posLeft = Xpos;
  else obj.style.left = Xpos+"px";
  return;
}

function showGalleryImg(imgID, imgWidth, imgHeight) {
  if (!imgWidth) imgWidth = 300;
  if (!imgHeight) imgHeight = 300;
  openWorkspace();
  if (!_('showImage')) {
    var space = document.createElement("div")
    space.setAttribute("id", "showImage");
    space.setAttribute("style", "position: fixed; background-color: #FFF; padding: 10px; z-index: 2001; border: 4px double #CCC;");
    if (document.all) {
      space.style.position="fixed"; space.style.background="#FFF"; space.style.padding="10px"; space.style.zIndex="2001"; space.style.borderColor="#CCC"; space.style.borderStyle="double"; space.style.borderWidth="4px";
    }
    document.body.appendChild(space);
  }
  _('showImage').innerHTML = "<img src='/arts/artsdigital/?PICCIE="+imgID+"' />\r" + getAjax("/arts/artsdigital/PHP/js_returns.php?imgCaption="+imgID);
  
  _('WORKSPACE').setAttribute("onClick", "closePopupPage(_('showImage'))");
  centreObjectH(_('showImage'), imgWidth);
  centreObjectV(_('showImage'), imgHeight);

  return;
}

function setTarget(frameID) {
  var anchor = window.frames[frameID].document.body.getElementsByTagName("a");
  for (a in anchor) {
    if (a.match(/\d+/)) anchor[a].setAttribute("target", "_parent");
  }
  return;
}

function browsePage(URL, width, height) {
  loadStyleSheet("/arts/artsdigital/styles/additional.css");
  if (!width) width = Math.ceil(0.8 * wW);
  if (!height) height = Math.ceil(0.8 * wH);

  if (!_("popContainer")) {
// Making sure the iframe opens links in th parent window
    var iframe = document.createElement("iframe");
    var server = RegExp(document.location.hostname);

    if (URL.match(server) || !URL.match(/^http:/i)) iframe.setAttribute("onLoad", "setTarget('innerPage')"); 
    else { document.location = URL; return; }

    var show = document.createElement("div");
    show.setAttribute("id", "popContainer");
    show.style.textAlign="center"; show.style.width="80%"; show.style.position="fixed"; show.style.minWidth="850px"; show.style.height="80%"; show.style.zIndex="2001";
    var popTopLeft = document.createElement("div");
    popTopLeft.innerHTML = "<img src=\"/arts/artsdigital/images/pop-ups/7px-spacer.gif\" />";
    popTopLeft.style.backgroundImage="url(/arts/artsdigital/images/pop-ups/iframe_pop-tl.gif)"; popTopLeft.style.backgroundRepeat="no-repeat"; popTopLeft.style.backgroundPosition="top left"; popTopLeft.style.cssFloat="left"; popTopLeft.style.width="5%"; popTopLeft.style.height="7px"; popTopLeft.style.position="relative"; popTopLeft.style.styleFloat="left";
   show.appendChild(popTopLeft);

    var popTopMid = document.createElement("div");
    popTopMid.innerHTML = "<img src=\"/arts/artsdigital/images/pop-ups/7px-spacer.gif\" />";
    popTopMid.style.background="#2b2b2b"; popTopMid.style.cssFloat="left"; popTopMid.style.width="90%"; popTopMid.style.height="7px"; popTopMid.style.position="relative"; popTopMid.style.styleFloat="left";
    show.appendChild(popTopMid);

    var popTopRight = document.createElement("div");
    popTopRight.innerHTML = "<img src=\"/arts/artsdigital/images/pop-ups/7px-spacer.gif\" />";
    popTopRight.style.backgroundImage="url(/arts/artsdigital/images/pop-ups/iframe_pop-tr.gif)"; popTopRight.style.backgroundPosition="right top"; popTopRight.style.backgroundRepeat="no-repeat";  popTopRight.style.cssFloat="left"; popTopRight.style.width="5%"; popTopRight.style.height="7px"; popTopRight.style.position="relative"; popTopRight.style.styleFloat="left";
    show.appendChild(popTopRight);

    var popMain = document.createElement("div");
    popMain.style.height="100%"; popMain.style.background="#2b2b2b"; popMain.style.cssFloat="left"; popMain.style.width="100%"; popMain.style.posiiton="relative"; popMain.style.styleFloat="left";
    show.appendChild(popMain);

    var innerContainer = document.createElement("div");
    innerContainer.style.padding="10px 10px 0 10px"; innerContainer.style.overflow="hidden"; innerContainer.style.textAlign="center"; innerContainer.style.height="100%"; innerContainer.style.background="#2b2b2b";
    popMain.appendChild(innerContainer);

    iframe.setAttribute("src", URL);
    iframe.setAttribute("name", "innerPage");
    iframe.setAttribute("id", "browsePage");
    iframe.style.overflow="auto"; iframe.style.width="98%"; iframe.style.minWidth="810px"; iframe.style.height="97%"; iframe.style.left="0px"; iframe.style.top="0px"; iframe.style.position="relative"; iframe.style.border = "0px";
    innerContainer.appendChild(iframe);

    var closeBrowse = document.createElement("div");
    closeBrowse.style.cssFloat="left"; closeBrowse.style.width="49.99%"; closeBrowse.style.padding="10px 0 0 0"; closeBrowse.style.background="#2b2b2b"; closeBrowse.style.position="relative"; closeBrowse.style.textAlign="left"; closeBrowse.style.styleFloat="left"; closeBrowse.style.padding="0"; closeBrowse.style.margin="0";
    show.appendChild(closeBrowse);
    var closeL = document.createElement("a");
    closeL.style.color="#FFF"; closeL.style.fontWeight="bold"; closeL.style.cursor="pointer"; closeL.style.background="url(/arts/artsdigital/images/pop-ups/close.jpg)"; closeL.style.backgroundPosiiton="top left"; closeL.style.backgroundRepeat="no-repeat"; closeL.style.textDecoration="none"; closeL.style.display="block"; closeL.style.padding="5px 6px 7px 26px"; closeL.style.margin="5px 0 0 10px";
    closeL.innerHTML = "Return to Website";
    closeL.href = "javascript:closePopupPage(_('popContainer'));";
    closeBrowse.appendChild(closeL);

    var openNew = document.createElement("div");
    openNew.style.cssFloat="right"; openNew.style.width="50%"; openNew.style.padding="10px 0 0 0"; openNew.style.background="#2b2b2b"; openNew.style.position="relative"; openNew.style.textAlign="right"; openNew.style.margin="0px"; openNew.style.styleFloat="right"; openNew.style.padding="0"; openNew.style.margin="0";
    show.appendChild(openNew);
    var openL = document.createElement("a");
    openL.style.color="#FFF"; openL.style.fontWeight="bold"; openL.style.cursor="pointer"; openL.style.background="url(/arts/artsdigital/images/pop-ups/new.jpg)"; openL.style.backgroundRepeat="no-repeat";  openL.style.backgroundPosition="right top"; openL.style.textDecoration="none"; openL.style.display="block"; openL.style.padding="5px 26px 7px 6px"; openL.style.margin="5px 10px 0 0";
    openL.innerHTML = "Open in New Window";
    openL.href = "javascript:windowOpen('"+URL+"');";
    openNew.appendChild(openL);

    var popBtmLeft = document.createElement("div");
    popBtmLeft.style.backgroundImage="url(/arts/artsdigital/images/pop-ups/iframe_pop-bl.gif)"; popBtmLeft.style.backgroundRepeat="no-repeat"; popBtmLeft.style.backgroundPosition="left bottom"; popBtmLeft.style.cssFloat="left"; popBtmLeft.style.width="5%"; popBtmLeft.style.height="7px";popBtmLeft.style.position="relative"; popBtmLeft.style.styleFloat="left";
    popBtmLeft.innerHTML = "<img src=\"/arts/artsdigital/images/pop-ups/7px-spacer.gif\" />";
    show.appendChild(popBtmLeft);

    var popBtmMid = document.createElement("div");
    popBtmMid.style.background="#2b2b2b"; popBtmMid.style.cssFloat="left"; popBtmMid.style.width="90%"; popBtmMid.style.height="7px"; popBtmMid.style.position="relative"; popBtmMid.style.styleFloat="left";
    popBtmMid.innerHTML = "<img src=\"/arts/artsdigital/images/pop-ups/7px-spacer.gif\" />";
    show.appendChild(popBtmMid);

    var popBtmRight = document.createElement("div");
    popBtmRight.style.backgroundImage="url(/arts/artsdigital/images/pop-ups/iframe_pop-br.gif)"; popBtmRight.style.backgroundRepeat="no-repeat"; popBtmRight.style.backgroundPosition="right bottom"; popBtmRight.style.cssFloat="right"; popBtmRight.style.width="5%"; popBtmRight.style.height="7px";popBtmRight.style.position="relative"; popBtmRight.style.styleFloat="right";
    popBtmRight.innerHTML = "<img src=\"/arts/artsdigital/images/pop-ups/7px-spacer.gif\" />";
    show.appendChild(popBtmRight);

    document.body.appendChild(show);
  }

  openWorkspace();
  centreObjectH(show, width);
  centreObjectV(show, height);

  _("WORKSPACE").setAttribute("onClick", "closePopupPage(_('popContainer'))");
  return;
}
function closePopupPage(obj) {
  closeWorkspace();
  obj.parentNode.removeChild(obj);
  return;
}
function windowOpen(URL) {
  window.open(URL); return;
}

function loadStyleSheet(css) {
  var go;
  var links = document.getElementsByTagName("link");
  for (i in links) { if (links[i].href) {
    if (links[i].href.match(RegExp(css, "i"))) $go = true;
  } }
  if (!go) {
    var CSS = document.createElement("link");
    CSS.setAttribute("href", css);
    CSS.setAttribute("rel", "stylesheet");
    CSS.setAttribute("type", "text/css");
    document.getElementsByTagName("head")[0].appendChild(CSS);
  }
  return;
}

function timetableGen(target, TTtype, noCSS, IEesc) {
  if (document.all && !IEesc) {
    window.onload = function() { timetableGen(target, TTtype, noCSS, true); }
    return;
  }
  if (getURLVar('dept')) var dept = getURLVar('dept');
  else var dept = document.location.href.replace(/^http.*\/(departs|centres)\/(\w+)\/.*$/, "$2");
  if (getURLVar("timetable")) TTtype = getURLVar("timetable");
  if (!TTtype) TTtype = "ug";

  if (!_(target)) {
    var plugin = document.createElement("div");
    if (_('contentcol')) _('content').appendChild(plugin);
    else if (_('w4')) _('w4').appendChild(plugin);
  } else var plugin = _(target);

  var content = getAjax("/arts/artsdigital/PHP/js_returns.php?timetable="+TTtype+"&semes="+getURLVar('semes')+"&view="+getURLVar('view')+"&tute="+getURLVar('tute')+"&dept="+dept );
  plugin.innerHTML = content;

// Adding a Heading
  var heading = document.getElementsByTagName("h1"); 
  for (i in heading) {
    if (heading[i].innerHTML) {
      if (heading[i].innerHTML.match(/timetable/i)) { if (_('timetable').getAttribute("sessionName")) {
        heading[i].innerHTML+= ", "+_('timetable').getAttribute("sessionName");
      } }
    }
  }
// Putting in stylesheet
  if (noCSS) {
    var head = document.getElementsByTagName("head");
    var css1 = document.createElement("link");
    css1.setAttribute("rel", "stylesheet");
    css1.setAttribute("type", "text/css");
    css1.setAttribute("href", "/arts/artsdigital/styles/timetable.css");
    head[0].appendChild(css1);
    var css2 = document.createElement("link");
    css2.setAttribute("rel", "stylesheet");
    css2.setAttribute("type", "text/css");
    css2.setAttribute("href", "/arts/artsdigital/styles/additional.css");
    head[0].appendChild(css2);
  }
  return;
}
function timetableDisplay(target, IEesc) {
  if (document.all && !IEesc) {
    setTimeout("timetableDisplay('"+target+"', true)", 1000);
    return;
  }
  var TTtype;
  var res = "";

  if (_('timetable')) {
    var vars = _('timetable').getAttribute("getvars").split(/\&/);

    for (v in vars) {
      var tmp = vars[v].split(/=/);
      switch (tmp[0]) {
        case "semes" : var semes = tmp[1]; break
        case "view" : var view = tmp[1]; break
        case "tute" : var tute = tmp[1]; break
        case "timetable" : var TTtype = tmp[1]; break
      }
    }
  } else {
    if (getURLVar("timetable")) TTtype = getURLVar("timetable");
    var semes = getURLVar('semes');
    var view = getURLVar('view');
    var tute = getURLVar("tute");
  }

  if (!TTtype) TTtype = "all";

  if (_(target)) var feature = _(target);
  else {
    if (_('sidebar')) {
      var feature = document.createElement("dl");
      feature.setAttribute("class", "feature");
      _('sidebar').appendChild(feature);
    } else if (_('feature')) {
      var feature = document.createElement("div");
      var children = _('feature').childNodes;
      var done = false;
      for (x in children) { if (children[x].tagName) {
        children[x].appendChild(feature); done = true;
      } }
      if (!done) {
        feature.setAttribute("class", "featureitem");
        _('feature').appendChild(feature);
      }
    }
  }
  if (feature) {
    if (getURLVar('dept')) var deptvar = "&dept="+getURLVar("dept"); else var deptvar = "";
    feature.innerHTML = getAjax( "/arts/artsdigital/PHP/js_returns.php?timetableRHS="+TTtype+"&semes="+semes+"&view="+view+"&tute="+tute+deptvar );
  }
  return;
}

function showNews(target, dept, newsPage) {
  if (!dept && getURLVar("dept")) dept = getURLVar("dept");  
  if (!dept || dept==document.location.href) dept = "FACULTY";

  if (!target) {
    var show = document.createElement("div");
    if (_('w4')) _('w4').appendChild(show);
  } else var show = _(target);

  var result = getAjax("/arts/artsdigital/PHP/splash_news.php?dept="+dept+(newsPage ? "&newsPage="+newsPage : ""));
  show.innerHTML = result;
  return;
}

// Script to reveal hidden info on a click
function getMore(hidden, msg) {
  if (_(hidden)) {
    if (!msg) msg = "<i>more...</i>";
    _(hidden).style.visibility = "hidden";
    _(hidden).style.position = "absolute";

    var xx  = 0;
    while (_('clickMe_'+xx)) xx++;
    var cmd = "moreGotten('"+hidden+"', '"+xx+"');"

    var clickMe = document.createElement("a");
    clickMe.setAttribute("onclick", cmd);

    clickMe.setAttribute("id", "clickMe_"+xx);
    clickMe.setAttribute("href", "javascript:"+cmd);
    clickMe.innerHTML = msg;
    clickMe.style.fontSize = "1.2em"; clickMe.style.color = "#000";
    _(hidden).parentNode.insertBefore(clickMe, _(hidden));
  }
  return;
}
function moreGotten(objName, clickMeNum) {
  _(objName).style.visibility = 'visible'; 
  _(objName).style.position = 'relative'; 
  if (clickMeNum) {
    _('clickMe_'+clickMeNum).parentNode.removeChild(_('clickMe_'+clickMeNum));
  }
  return;
}

function sanitise(string) {
  if (string.match(/[#\&\?=]/)) {
    string = string.replace(/\?/g, "|_QUESTIONMARK_|");
    string = string.replace(/\&/g, "|_AMPERSAND_|");
    string = string.replace(/#/g, "|_HASH_|");
    string = string.replace(/=/g, "|_EQUAL_|");
  }
  return string;
}

// Form Processing
function processForm(formObj, processFile, req_fields, rewriteObj) {
  var ERROR = "";
  var result = ""; 
 
  if (typeof(formObj)=="text") formObj = _(formObj);
  if (formObj.elements) { 
    for (bit in formObj.elements) {
      if (formObj.elements[bit]) { if (formObj.elements[bit].tagName) { if (formObj.elements[bit].tagName.match(/^(textarea|input|select)$/i)) { if (formObj.elements[bit].name) {
// Determining if a required field is empty
        if (formObj.elements[bit].getAttribute("origValue")) { 
          if (formObj.elements[bit].value==formObj.elements[bit].getAttribute("origValue")) formObj.elements[bit].value = null;
        }
        if (!formObj.elements[bit].value) {
          if (req_fields) {
            for (req in req_fields) {
              if (req_fields[req]==formObj.elements[bit].name) {                ERROR+= formObj.elements[bit].name+" is missing!\n";
                formObj.elements[bit].style.border = "2px solid #D55";
              }
            }
          } else { // Putting something in the input/textarea etc to control what's manadatory but no need for req_fields
            if (formObj.elements[bit].getAttribute("mandatory")) ERROR+= formObj.elements[bit].name+" is missing!\n";
          }
        } else {
          if (formObj.elements[bit].type=="checkbox") {
            if (formObj.elements[bit].checked) result+= formObj.elements[bit].name+"=1&";
          } else if (formObj.elements[bit].name.match(/email/i)) {
            if (formObj.elements[bit].value.match(/^(\w\W*)+@(\w+\W*)+\.(\w+\W*)+$/)) result+= formObj.elements[bit].name+"="+sanitise(formObj.elements[bit].value)+"&";
            else ERROR+= "Please supply a legitimate Email!\n";
          } else {
            if (formObj.elements[bit].value!="NULL") result+= formObj.elements[bit].name+"="+sanitise(formObj.elements[bit].value)+"&";
          }
        }
      } } } }
    }

    if (ERROR) { alert(ERROR+"\nPlease correctly complete these fields before continuing."); return;
    } else {
      var returnMsg = getAjax(processFile, result);
      if (rewriteObj) rewriteObj.innerHTML = returnMsg;
      else if (returnMsg.match(/^error/i)) alert(returnMsg);
      else if (formObj.parentNode) {
        var blah = document.createElement("div");
        blah.innerHTML = returnMsg;
        formObj.parentNode.insertBefore(blah, formObj);
        formObj.parentNode.removeChild(formObj);
      } else alert(returnMsg);
    }
  } else alert("Form "+formObj.id+" has no inputs!!");
  return;
}

function chooseOne(targetURL, val, pageID) {
  if (!targetURL) return;
  if (!_(pageID)) return;
  if (val==false) val = "";
  var response = getAjax(targetURL+val+"&dummy="+dummyVal());
  if (!response) response = "";
  _(pageID).innerHTML = response;

  return;
}
//Functions to determin mouse position
function mousePosition(evt) {
  mX = mouseX(evt);
  mY = mouseY(evt);
  return;
}
function mouseX(evt) {
  if (evt.pageX) return evt.pageX;
  else if (evt.clientX)
    return evt.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
  else return null;
}
function mouseY(evt) {
  if (evt.pageY) return evt.pageY;
  else if (evt.clientY)
    return evt.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
  else return null;
}

// Functions that create a box on mouseover
function msgBoxOn(msg) {
  if (_('msgBox')) msgBoxOff();
  if (msg) {
    var msgBox = document.createElement("div");
    msgBox.setAttribute("id", "msgBox");
    msgBox.style.position = "fixed";
    msgBox.style.top = mX+"px";
    msgBox.style.left = mY+"px";
    msgBox.innerHTML = msg;
    document.body.appendChild(msgBox);
  }
  return;
}
function msgBoxOff() {
  if (_('msgBox')) _('msgBox').parentNode.removeChild(_('msgBox'));
  return;
}

// Functions that raise and lower elements
function setLevel(object, level) {
  if (!object) return;
  if (!level) level = -1;
  object.style.zIndex = level;
  return;
}

// Cookie Functions 
function readCookie(cookie) {
  var value = "";
  if (document.cookie) {
    var fit;
    var cookies = document.cookie.split("; ");
    for (x in cookies) {
      fit = RegExp("^"+cookie+"=");
      if (cookies[x].match(fit)) value = cookies[x].replace(fit, "");
    }
  }
  return value;
}
// Function for clearing Inputs and text areas based on what their initial value is (for descriptive purposes
function maybeClear(obj, clearText) {
  if (obj.value==clearText) obj.value = '';
  return;
}
// Function for tracking search terms on the Faculty sites
function trackSearchTerms() {
  if (_("search")) {
    for (x in _("search").elements) {
      if (_("search").elements[x]) { if (_("search").elements[x].name) { if (_("search").elements[x].name=="query") {
        if (_("search").elements[x].value) { if (!_("search").elements[x].value.match(/search/i)) {
          var feed = sanitise(_("search").elements[x].value.replace(/(^|\s+)(\W+)($|\s+)/g, " "));
        } }
      } } }
    }
    var resp = getAjax("/artsdiigtal/PHP/search_terms.php?searchTerms="+feed+"&pageURL="+sanitise(window.location.href));
    if (resp) { console.log(resp); return; }
    else _("search").submit();
  }
}
function onReturn(e, fxn) {
  var keyPress;
  e = (e) ? e : window.event;
  if (e.which) keyPress = e.which;
  else keyPress = e.keyCode;

  if (keyPress==13) eval(fxn);
  return;
}

function returnChildrenAsText(obj) { // Function that returns the inner bits of an Object (expected to be used for DOM processing) as Text
  var text = "";
  var current;
  if (obj.childNodes) {
    for (var x=0; x<obj.childNodes.length; x++) {
      if (!obj.childNodes[x].nodeName.match(/^#/)) {
        text+= "<"+obj.childNodes[x].nodeName;
        if (obj.childNodes[x].attributes) {
          for (y=0; y<obj.childNodes[x].attributes.length; y++) text+= " "+obj.childNodes[x].attributes[y].name+"=\""+obj.childNodes[x].attributes[y].value+"\"";
        }
        text+= ">";
      } 
      if (obj.childNodes[x].childNodes.length>1) text+= returnChildrenAsText(obj.childNodes[x]);
      else text+= obj.childNodes[x].nodeValue;

      if (!obj.childNodes[x].nodeName.match(/^#/)) text+= "</"+obj.childNodes[x].nodeName+">";
    }
  }
  return text;
}

