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() {
// Footer replace
  var arr = getAjax("/arts/includes/footer/default.shtml").split(/[\r\n]+/);
  _("foot").innerHTML = "";
  _("foot").className = "clearfix";
  var legal = document.createElement("div"); legal.id = "legal"; _("foot").appendChild(legal); var legalOn = false; var legalHTML = "";
  var sitemap = document.createElement("div"); sitemap.id = "sitemap"; _("foot").appendChild(sitemap); var sitemapOn = false; var sitemapHTML = "";
  for (x=0; x<arr.length; x++) {
    if (arr[x+1]) {
      if (arr[x+1].match(/id="sitemap"/)) legalOn = false;
    }
    if (sitemapOn && arr[x].match(/<\/div>/)) sitemapOn = false;
    
    if (legalOn) legalHTML+= arr[x];
    if (sitemapOn) sitemapHTML+= arr[x];

    if (arr[x].match(/id="legal"/)) legalOn = true;
    if (arr[x].match(/id="sitemap"/)) sitemapOn = true;
  }
  legal.innerHTML = legalHTML;
  sitemap.innerHTML = sitemapHTML;

// 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;
} 


