/******************************
/*functions used by the svsohcahtoa.com website for 
/*fancy things.  grab it, use it if you want.  it
/*is most likely crap.
*******************************/
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));

if (top.addEventListener) { 
  top.addEventListener("load",_gaLoad,false); 

} else if (top.attachEvent) { 
  top.attachEvent("onload",_gaLoad); 
} 

function _gaLoad() {
  var pageTracker = _gat._getTracker("UA-5392682-1");
  pageTracker._initData();
  pageTracker._trackPageview();
}

function tidyText( text) {
  if( text) {
    text = text.replace( /\t/g, "");
    text = text.replace( /\n/g, " ");
    }
  return text;
}

function markMenu() {
  var url = String( document.URL);
  var thisFile = url.slice( url.lastIndexOf("/") + 1);
  var nav = document.getElementById("sitenav");
  var menuItems = nav.getElementsByTagName("li");
  for( var i = 0; i < menuItems.length; i++) {
    if( menuItems[i].className == "submenu") { }
    else {
      var href = menuItems[i].firstChild.getAttribute( "href");
      href = href.slice( href.lastIndexOf("/") + 1);
      if( thisFile == href) {
        menuItems[i].className =  "selectedlink";
        if( menuItems[i].parentNode.className == "level1") { }
        else {
          menuItems[i].parentNode.parentNode.className =  "selectedsubmenu";
        }
      }
    }    
  }
}

var g_NUM_HEADERS = 132;

function randomHeader( path){
  var LOW_LIMIT = 0;
  var trimmedNum = g_NUM_HEADERS - LOW_LIMIT;
  //hopefully create a random integer between 0 and NUM_HEADERS
  var randHeader = ( Math.round( Math.random() * trimmedNum) + LOW_LIMIT).toString();
  if(randHeader < 10) {
    randHeader = "00" + randHeader;
  }else if(randHeader < 100) {
    randHeader = "0" + randHeader;
  }
  var header = document.getElementById("header");
  header.style.backgroundImage = 'url('+path+'header/header_'+randHeader+'.gif)';

}

function dumpHeaders( path, width, heigth) {
  var headerTag = document.getElementById("all_headers");
  for( var i=g_NUM_HEADERS; i >= 0; i--) {
    var headerNum = i; 
    if( i < 10) {
      headerNum = "00" + headerNum; 
    }else if( i < 100) {
      headerNum = "0" + headerNum;
    }
    var img = document.createElement( "img");
    img.setAttribute( "src", path+'header/header_'+headerNum+'.gif');
    img.setAttribute( "Alt", "Header # - " + headerNum);  
    img.setAttribute( "heigth", heigth);
    img.setAttribute( "width", width);
    headerTag.appendChild( img);
  }
}

function openPicture( path) {
  openNoMenuNoScrollWindow( path, "singlePicture", 660, 510);
}

function getArgs() {
  var args = new Object();
  var query = location.search.substring(1);
  var pairs = query.split(",");
  for( var i = 0; i < pairs.length; i++) {
    var pos = pairs[i].indexOf('=');
    if( pos == -1) continue;
    var argName = pairs[i].substring( 0, pos);
    var value = pairs[i].substring( pos+1);
    args[argName] = unescape( value);
  }
  return args;
}

var xmlhttp;  //try and make this a global variable

function loadXML( fileName, handler, argumentone, argumenttwo) {

  var whichMethod = 1;  // 0 - use the XMLDOM method.  doesn't work in safari, but runs locally
  
  if( whichMethod == 0) {
     if( document.implementation && document.implementation.createDocument) {
      var xmlDoc = document.implementation.createDocument("", "", null);
      xmlDoc.onload = function() { handler( xmlDoc, argumentone, argumenttwo) }
      xmlDoc.load( fileName);
    }
    else if( window.ActiveXObject) {
      var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
      xmlDoc.onreadystatechange = function() {
	  if( xmlDoc.readyState == 4) handler( xmlDoc, argumentone, argumenttwo);}
      xmlDoc.load( fileName);
    }  
    else {
      document.write("<p>Broken</p>");
    }
  }
  else {
    //use the XMLHTTP request method.  This doesn't work when running locally.
    if (window.XMLHttpRequest)
    {
      xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange=function () {
        if (xmlhttp.readyState == 4) {
            if ( xmlhttp.status==200) {
              var xmlDoc = xmlhttp.responseXML;
              handler( xmlDoc, argumentone, argumenttwo);
            }
            else {
              alert("Problem retrieving XML data");
            }
         }
      }
      xmlhttp.open("GET",fileName,true);
      xmlhttp.send(null);
    }
    // code for IE
    else if (window.ActiveXObject)
    {
      xmlhttp = new ActiveXObject("Microsoft.XMLHTTP")
      if (xmlhttp){
        xmlhttp.onreadystatechange=function () {
          if (xmlhttp.readyState == 4) {
            if ( xmlhttp.status==200) {
              var xmlDoc = xmlhttp.responseXML;
              handler( xmlDoc, argumentone, argumenttwo);
            }
            else {
              alert("Problem retrieving XML data");
            }
          }
        } 
        xmlhttp.open("GET",fileName,true);
        xmlhttp.send();
      }
    }
  }
}

function switchPage( page) {
  location = page;
} 

function openNoScrollWindow(url,title,width,height) {
	// read resolution and set variables
	var      x = screen.width;
	var      y = screen.height;
	var    top = parseInt((y-height)/2);
	var   left = parseInt((x-width)/2);
	// open new window and use the variables to position it
	window.open(url,title,'width='+width+',height='+height+',left='+left+',top='+top+',scrollbars=no,resize=yes,resizable=yes,menubar=no,toolbar=no,directories=no');
}

function openWindow(url,title,width,height) {
	// read resolution and set variables
	var      x = screen.width;
	var      y = screen.height;
	var    top = parseInt((y-height)/2);
	var   left = parseInt((x-width)/2);
	// open new window and use the variables to position it
	w = window.open(url,title,'width='+width+',height='+height+',left='+left+',top='+top+',scrollbars=yes,resize=no,resizable=no,menubar=yes,toolbar=no,directories=no');
    w.focus();
}

function openNoMenuNoScrollWindow(url,title,width,height) {
	// read resolution and set variables
	var      x = screen.width;
	var      y = screen.height;
	var    top = parseInt((y-height)/2);
	var   left = parseInt((x-width)/2);
	// open new window and use the variables to position it
	var w = window.open(url,title,'width='+width+',height='+height+',left='+left+',top='+top+',scrollbars=no,resize=no,resizable=no,menubar=no,toolbar=no,directories=no');
    w.focus();
}

function openNoMenuWindow(url,title,width,height) {
	// read resolution and set variables
	var      x = screen.width;
	var      y = screen.height;
	var    top = parseInt((y-height)/2);
	var   left = parseInt((x-width)/2);
	// open new window and use the variables to position it
	var w = window.open(url,title,'width='+width+',height='+height+',left='+left+',top='+top+',scrollbars=no,resize=yes,resizable=yes,menubar=no,toolbar=no,directories=no');
	w.focus();
}

function debugnote( debugString) {
  document.write('<p>'+debugString+'<\p>');
}