
// Adds event to window.onload without overwriting currently 
// assigned onload functions.

function addLoadEvent(func) {    
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } 
  else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}


// set target for external links (rel="external")

function external() { 
  if(!document.getElementsByTagName)return; 
  var anchors = document.getElementsByTagName("a"); 
  for(var i=0;i<anchors.length;i++) { 
    var anchor = anchors[i]; 
    if(anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")anchor.target = "_blank";
    else if(anchor.getAttribute("href") && anchor.getAttribute("type") == "external")anchor.target = "_blank";
  } 
} 

addLoadEvent(external);

// AJAX load url into div

function ajaxGetFile(divID, url) {
  ran = new Date();
  if(url.indexOf('?') == -1)var sep = "?";
  else var sep = "&amp;";
  url = url + sep + ran.getTime();
  var ajaxRequest;  // The variable that makes Ajax possible!
  try {
    // Opera 8.0+, Firefox, Safari
    ajaxRequest = new XMLHttpRequest();
  } catch (e) {
    // Internet Explorer Browsers
    try {
      ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
      try {
        ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
      } catch (e) {
        // Something went wrong
        return false;
      }
    }
  }
  // Create a function that will receive data sent from the server
  ajaxRequest.onreadystatechange = function() {
    if(ajaxRequest.readyState == 4) {
      if(ajaxRequest.status == 200) {
        var ajaxDisplay = document.getElementById(divID);
        document.getElementById(divID).innerHTML = ajaxRequest.responseText;
        // eval any Javascript
        var x = document.getElementById(divID).getElementsByTagName("script");
        for(var i=0;i<x.length;i++) {
          eval(x[i].text);
        }
      }
    }
  }
  ajaxRequest.open("GET", url, true);
  ajaxRequest.send(null);
}

// stylesheet load check

function check_css() {
  // we shouldn't have to do this, but...
  // check if both stylesheets have been loaded 
  var el = document.getElementById("wp-footer");
  if (el.currentStyle) { //IE
    var visibility = el.currentStyle["visibility"];
    var display = el.currentStyle["display"];
  }
  else if (document.defaultView && document.defaultView.getComputedStyle) { //Firefox
    var visibility = document.defaultView.getComputedStyle(el, "")["visibility"];
    var display = document.defaultView.getComputedStyle(el, "")["display"];
  }
  // if style not loaded, refresh page
  if(visibility != "hidden" || display != "none")document.location.reload(true);
}

addLoadEvent(check_css);

