// MacIE doesn't understand Array.push(), so we'll clue it in
if (typeof Array.prototype.push == "undefined")
{
  Array.prototype.push = function()
  {
    var i=0;
    b = this.length
    a = arguments;
    for(i;i<a.length;i++)this[b+i]=a[i];
    return this.length
  }
}
if (typeof Array.prototype.shift == "undefined")
{
  Array.prototype.shift = function()
  {
	var response = this[0];
	for (var i=0; i < this.length-1; i++)
    {
		this[i] = this[i + 1];
	}
	this.length--;
	return response;
  };
}

// popup window
function openWin( windowURL, windowName, windowFeatures ) {
    return window.open( windowURL, windowName, windowFeatures ) ;
}

// onload will process an array we can push any functions to that we want
var old = window.onload; // catch any existing onload calls 1st
window.onload = function () {
  if (old) { // execute existing onloads
    old();
  }
  for(var ii = 0; arguments.callee.actions.length > ii; ii++)
  {
    arguments.callee.actions[ii]();
  }
};
window.onload.actions = [];

// searchText
// prepoulate the search form with "Search this Site"
// and blank it when someone clicks
function searchText()
{
  var srchFld = document.getElementById('headerQuery');
  srchFld.setAttribute('value','Search this Site');
  srchFld.onfocus = function() {
    srchFld.setAttribute('value','');
  };
  // don't allow anyone to submit a query with the default text in it
  var goBtn = document.getElementById('searchGo');
  goBtn.onclick = function() {
    if (srchFld.value == 'Search this Site') {
       srchFld.focus();
       return false;
     } else {
       return true;
     }
  }
}
window.onload.actions.push(searchText);

function statusBar()
{
  window.status = 'Healthcare the way you prescribe it.';
}
window.onload.actions.push(statusBar);

function fixLinks()
{
  if (!document.getElementsByTagName) return null;
  var server = document.location.hostname;
  var anchors = document.getElementsByTagName("a");
  var i, href, title;
  for(i=0; i < anchors.length; i++){
    if(!anchors[i].href) continue;
    href = anchors[i].href;
    title = anchors[i].title;
    if(href.indexOf(server) == -1){ // Href is not a file on my server
      if(href.indexOf("javascript:") == -1){ // Href is not a javascript call
        if(!anchors[i].onclick){ // Href does not have an onclick event
          if(href.indexOf("mailto:") == -1){ // Href is not a mailto:
            if((href.indexOf("http://") != -1) || (href.indexOf("https://") != -1)){ // Href is not relative (for Safari)
              anchors[i].setAttribute("target","_blank");
              anchors[i].setAttribute("title",title + " [This Link Will Open in a New Window] ");
            }
          }
        }
      }
    }
  }
  return null;
}
window.onload.actions.push(fixLinks);


// New Emergency Department Photo Gallery
function showPic (whichpic) {
	if (document.getElementById) {
		document.getElementById('newEdDefaultImg').src = whichpic.href;
		if (whichpic.title) {
			document.getElementById('newEdImageDesc').childNodes[0].nodeValue = whichpic.title;
		} else {
			document.getElementById('newEdImageDesc').childNodes[0].nodeValue = whichpic.childNodes[0].nodeValue;
		}
		return false;
	} else {
		return true;
	}
}
