function setActiveStyleSheet(title, reset) {
  var i, a, main;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title")) {
      a.disabled = true;
      if(a.getAttribute("title") == title) a.disabled = false;
    }
  }
  
	// NS6 won't properly apply the changes in abs positioned divs unless we do
	// this trickery:
	if (!document.all) { 
		e = document.getElementsByTagName('body')[0];
		e.parentNode.replaceChild(e,e);
	}
	
	if (reset == 1) {
		//setCookie('style', title, '/', '')
		createCookie("style", title, 365);
	}

}


function getActiveStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1 && a.getAttribute("title") && !a.disabled) return a.getAttribute("title");
  }
  return null;
}

function getPreferredStyleSheet() {
  var i, a;
  for(i=0; (a = document.getElementsByTagName("link")[i]); i++) {
    if(a.getAttribute("rel").indexOf("style") != -1
       && a.getAttribute("rel").indexOf("alt") == -1
       && a.getAttribute("title")
       ) return a.getAttribute("title");
  }
  
 if (!document.all) { 
  e = document.getElementsByTagName('body')[0];
  e.parentNode.replaceChild(e,e);
  }  
  
  
  return null;
}

function createCookie(name,value,days) {
  if (days) {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
  }
  else expires = "";
  document.cookie = name+"="+value+expires+"; path=/";
}

function readCookie(name) {
  var nameEQ = name + "=";
  var ca = document.cookie.split(';');
  for(var i=0;i < ca.length;i++) {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
  }
  return null;
}

onload = function() {
	thisTest();
}

function thisTest() {
  var styleW = readCookie('style');
	if (styleW != null) {
		setActiveStyleSheet(styleW, 0);
	} 
}

function setStyle() {
	var style = readCookie("wstyle");
	if (style != null) {
		setActiveStyleSheet(style, 0);
	}
}

//window.UnLoadOff=function(e) {
//  var title = getActiveStyleSheet();
//  createCookie("style", title, 365);
//}

function openWindow(contentURL, windowName, windowWidth, windowHeight) {
	widthHeight = 'height=' + windowHeight + ',width=' + windowWidth + ',scrollbars, resizable';
	newWindow = window.open(contentURL, windowName, widthHeight );
	newWindow.focus();
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

	//shows/hides an id
	function showhide(myId) {
		if (document.getElementById) {
			state = document.getElementById(myId).style.visibility
			if (state == 'visible') {
				hideId(myId)
				return false
			}
			else {
				showId(myId)
				return false
			}
		}
	}
	
	//shows/hides an id
	function showhideCom(myId, parentId) {
		if (document.getElementById) {
			state = document.getElementById(myId).style.visibility;
			comNS = document.getElementById('comNS');
			comAZ = document.getElementById('comAZ');
			
			if (myId == 'toc2a') {
				comNS.style.color = '#fff';
				comAZ.style.color = '#000';
				comNS.style.backgroundColor = 'yellow';
				comAZ.style.backgroundColor = 'transparent';
				hideId('toc2b');
				showId('toc2a')
			} else {
				comNS.style.color = '#000';
				comAZ.style.color = '#fff';
				comNS.style.backgroundColor = 'transparent';
				comAZ.style.backgroundColor = 'yellow';					
				hideId('toc2a');
				showId('toc2b');
			}
		}
		parent = document.getElementById(parentId);
		move = document.getElementById(myId);
		parentXY = getPageXY(parent);
		//alert("point x:" + parentXY.x + " point y: " + parentXY.y);
		//alert(move);
		
		setPageXY(move, parentXY.x, parentXY.y);
		
	}
	
	function showhideTools(myId, parentId) {
		
		showhide(myId);
	
		parent = document.getElementById(parentId);
		move = document.getElementById(myId);
		parentXY = getPageXY(parent);
		//alert("point x:" + parentXY.x + " point y: " + parentXY.y);
		//alert(move);
		
		setPageXY(move, parentXY.x + 20, parentXY.y + 20);
	}
	
	//hides an id
	function hideId(myId) {
		if (document.getElementById) {
			document.getElementById(myId).style.visibility = 'hidden'
		}
	}

	//shows an id
	function showId(myId) {
		if (document.getElementById) {
			document.getElementById(myId).style.visibility = 'visible'
		}
	}





var timer = "";
var openMenu = null;

/* d closes all menus and drops the selected one */
function d(id, containerId){
  if (document.getElementById){
    window.clearTimeout(timer);
    document.getElementById('toc').style.display = 'none';
    document.getElementById('toc2').style.display = 'none';
    document.getElementById('toc3').style.display = 'none';
    
    var dropDownItem = document.getElementById(id);

    var parentItem = document.getElementById(containerId);
    var location = getPageXY(parentItem);
    
    dropDownItem.style.left = location.x + 30 + 'px'; //30 is for the margin on the items
    dropDownItem.style.top = location.y + parentItem.offsetHeight + 'px';
    //alert(parentItem.offsetHeight);
    //setPageXY(dropDownItem, location.x, location.y);
    dropDownItem.style.display = 'block';
    
    //alert('x: ' + dropDownItem.style.top + ' y: ' + dropDownItem.style.left);
    //alert(location.x + 'y: ' + location.y);
    openMenu = id;
  }
}

/* h holds the menu open */
function h(id){
  openMenu = id;
}

/* t tries to close the menu */
function t(id){
  if (document.getElementById){
    openMenu = null;
    var funcToCall = "closeMenu('"+id+"')"
    timer = setTimeout(funcToCall, 600);
  }
}

/* closeMenu closes the menu if it's not held open */
function closeMenu(id){
  if (document.getElementById){
    if (openMenu == null)
     document.getElementById(id).style.display = 'none';
  }
}






////////////////////////////////


function init() 
{
  cssjsmenu('comNav');
  cssjsmenu('toolNav');
  if (document.getElementById)
  {
    var kill = document.getElementById('hoverJS'); 
    kill.disabled = true;
  }
  //ndeSetStyleSheetInternal();
}

// csjsmenu.js

function elementContains(elmOuter, elmInner)
{
  while (elmInner && elmInner != elmOuter)
  {
    elmInner = elmInner.parentNode;
  }
  if (elmInner == elmOuter)
  {
    return true;
  }
  return false;
}

function getPageXY(elm)
{
  var point = { x: 0, y: 0 };
  while (elm)
  {
    point.x += elm.offsetLeft;
    point.y += elm.offsetTop;
    elm = elm.offsetParent;
  }
  return point;
}

function setPageXY(elm, x, y)
{
  var parentXY = {x: 0, y: 0 };

  if (elm.offsetParent)
  {
    parentXY = getPageXY(elm.offsetParent);
  }

  elm.style.left = (x - parentXY.x) + 'px';
  elm.style.top  = (y - parentXY.y) + 'px';
}