function fixLinks()
{
  if (!document.getElementsByTagName) return null;
  var server = document.location.hostname;
  var anchors = document.getElementsByTagName("a");
  for(var i=0; i < anchors.length; i++)
  {
    var a = anchors[i];
    var href = a.href;
    var id = a.id;
    var title = a.title;
    if ((href.indexOf("#") != -1) && (href.indexOf("header") == -1)) { // jump ref
      var index = href.indexOf("#") + 1;
      href = "javascript:show('" + href.substring(index) + "');";
      a.setAttribute("href",href);
    }
  } 
}

function hideDivs(exempt)
{
  //if cookie set, switch to that div (change exempt to that id)
  var exemptCookie;
  exemptCookie = getCookie('switchTabName');
  //if (exemptCookie != null) {
  //   exempt = exemptCookie;
  //}

  if (!document.getElementsByTagName) return null;
  if (!exempt) exempt = "";
  var divs = document.getElementsByTagName("blockquote");  //this can be set to 'div' or whatever element you want to be set invisible
  for(var i=0; i < divs.length; i++)
  {
    var div = divs[i];
    var id = div.id;
    if ((id != "header") && (id != "footer") && (id != exempt))
    {
      div.style.display = "none";
    }
  }
}

function show(what)
{
  setCookie('switchTabName', what);
  if (!document.getElementById) return null;
  showWhat = document.getElementById(what);
  showWhat.style.display = "block";      // !important
  hideDivs(what);
}

// window.onload = function()
//{
//  fixLinks();
//  hideDivs("hosted");  //these functions are to embedded in the body tag 'onload'.  The name of the initial 'on' state element ID is to be set here.
//}



// Cookie handling
function setCookie ( sName, sValue, nDays ) {
	var expires = "";
	if ( nDays ) {
		var d = new Date();
		d.setTime( d.getTime() + nDays * 24 * 60 * 60 * 1000 );
		expires = "; expires=" + d.toGMTString();
	}

	document.cookie = sName + "=" + sValue + expires + "; path=/";
};

function getCookie (sName) {
	var re = new RegExp( "(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)" );
	var res = re.exec( document.cookie );
	return res != null ? res[3] : null;
};

function removeCookie ( name ) {
	setCookie( name, "", -1 );
};

