var wH = window.innerHeight;
var wW = window.innerWidth;

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 getAjax(URL, post) { // Ajax call to get basic Text.  Will not do XML.  XML requires synchronous call.
  var sendType = (post) ? "post" : "get";
  var response;

  if (post) waiting(true);
  var xhr = new createXMLHttpRequest();

  xhr.open(sendType, URL, false);
  if (post) xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
  xhr.send(post);
  response = xhr.responseText;
  xhr.close;

  if (response.match(/^\s*$/)) response = null;
  waiting(false);
  return response;
}
function waiting(on) {
  if (document.body) {
    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 = "/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";

    if (document.all) { // something to deal with the FIXED position not working for IE
      document.body.parentNode.style.overflow = (on) ? "hidden" : "auto";
    }
  }
  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);
}
var _ = $;

function pageLoad() {
  var placeHolder = _("foot").nextSibling;
  _("foot").parentNode.removeChild(_("foot"));
  var tmp = document.createElement("div");
  tmp.innerHTML = getAjax("/includes/footer/default.shtml");
  for (x=tmp.childNodes.length; x>=0; x--) {
    placeHolder.parentNode.insertBefore(tmp.childNodes[x], placeHolder);
  }
  
/*  var links = document.getElementById("foot-links").childNodes;
  for (x=0; x<links.length; x++) {
    if (links[x]) { if (links[x].tagName) { if (links[x].tagName.match(/^a$/i)) {
      if (links[x].innerHTML=="Comment on this Page") {
        links[x].href = "/arts/artsdigital/?email=web&subject=Comment%20on%20"+window.location.href.replace(/\?/, "%3F").replace(/&/, "%26").replace(/=/, "%3D");
      }
    } } }
  }
*/

// All the new branding shenanigans
// Replacing the logo
  if (_('logo')) {
    var par = _("logo").parentNode;
    par.removeChild(_("logo"));
    par.id = "logo";
    par.innerHTML = "The University of Sydney";
    par.href = "http://www.sydney.edu.au";
    var h = document.createElement("h1");
    par.parentNode.insertBefore(h, par);
    h.appendChild(par);
  }

// breadcrumbs fixing
  var divs = document.getElementsByTagName("div");
  for (x=0; x<divs.length; x++) {
    try {
      if (divs[x].className=="breadcrumb") _("mid").parentNode.insertBefore(divs[x], _("mid"));
    } catch(e) {}
  }
}
function openWorkspace() {
  var WStyle = $('WORKSPACE').style;
  WStyle.width = wW+"px";
  WStyle.height = wH+"px";
  WStyle.zIndex = 2000;
  WStyle.visibility = "visible";
  return; 
} 
function closeWorkspace() {
  var WStyle = $('WORKSPACE').style;
  WStyle.visibility = "hidden";
  WStyle.zIndex = -1;
  return;
} 


/*function pagetools(ID) {
  var p = "";
  if (location.href.match(/\?/)) var printHref = location.href+"&printable";
  else var printHref = location.href+"?printable";

//  p = "
//<img src=\"/images/nav/cws/lftbrkt.gif\" alt=\"spcr\" />
//<a href=\"#\" onClick=\"var printVersion=window.open('"+printHref+"','PrinterFriendly','toolbar=no,width=620,height=500,resizable=yes,menubar=yes,status=no,scrollbars=yes,left=100,top=100');printVersion.focus();return false;\" title=\"Printer Friendly Format\">
//<img src=\"/images/nav/cws/pix.gif\" height=\"20\" width=\"20\" alt=\"Print Friendly Version\" /><span>Printer format</span></a>
//<img src=\"/images/nav/cws/bar.gif\" alt=\"spcr\" />
//<a href=\"#\" onClick=\"var emailForm=window.open('/departs/english/mail.shtml','EmailForm','toolbar=no,menubar=no,width=500,height=500,resizable=no,status=no,scrollbars=yes,left=100,top=100');emailForm.focus();return false;\" title=\"Email a friend\">
//<img src=\"/images/nav/cws/pix.gif\" height=\"20\" width=\"20\" alt=\"Email a Friend\" /><span>Email to a friend</span></a>
//<img src=\"/images/nav/cws/bar.gif\" alt=\"spcr\" />
//<a href=\"#\" onclick=\"SetCookie('textsize','120',null,'/');location.reload(true);\" title=\"Large text size\"><img src=\"/images/nav/cws/pix.gif\" alt=\"Large text\" name=\"largeA\" width=\"20\" height=\"20\" onmouseover=\"swapImage('textsize','','/images/nav/cws/largertext.gif',1)\" onmouseout=\"swapImgRestore()\" /></a>
//<img src=\"/images/nav/cws/bar.gif\" alt=\"spcr\" />
//<a href=\"#\" onclick=\"SetCookie('textsize','100',null,'/');location.reload(true);\" title=\"Default text size\"><img src=\"/images/nav/cws/pix.gif\" alt=\"Default text\" name=\"smalla\" width=\"20\" height=\"20\" onmouseover=\"swapImage('textsize','','/images/nav/cws/defaulttext.gif',1)\" onmouseout=\"swapImgRestore()\"/></a>
//<img src=\"/images/nav/cws/rghtbrkt.gif\" alt=\"spcr\" />\r";
  if ($(ID)) $(ID).innerHTML = p;
  return;
}
*/

