var menuids=new Array("verticalmenu"); //Enter id(s) of UL menus, separated by commas
var submenuoffset=-2 ;//Offset of submenus from main menu. Default is -2 pixels.

function getFile(url) {
  if (window.XMLHttpRequest) {
      AJAX=new XMLHttpRequest();
  } else {
           AJAX=new ActiveXObject("Microsoft.XMLHTTP");
  }  
  if (AJAX) {
       AJAX.open("GET", url, false);
       AJAX.send(null);
       return AJAX.responseText;
  } else {
          return false;
  }
}
function doLoadDiv(){
	//alert(getFile('/Menu/VertMenu.html'));
	document.getElementById("VertMenu").innerHTML = getFile('/Menu/VertMenu.html');
	createcssmenu();
	JSFX_FloatTopDiv();
}

function doScripts(scriptx){
// contentElem is the HTML element you've loaded via ajax
//      scriptx = contentElem.getElementsByTagName("script");

      // Load scripts into new array because 
      // scriptx seems to change as scripts execute, at least in some browsers
      scripts = new Array();
      for (var idx=0; idx<scriptx.length; idx++) {
        scripts[idx] = scriptx[idx].text;
      }

      // execute each script in turn
      for(idx=0; idx<scripts.length; ++idx) {
         if (scripts[idx].length!=0) {
            try {
              // create a function for the script & execute it
              f = new Function(scripts[idx]);
              f();
            } catch(se) {
                 alert(me.tagId+": Script error (" + se.message + "):\n"+scripts[idx]);
            } // end try-catch
         } // end if
      } // end for
}


function createcssmenu(){
	for (var i=0; i<menuids.length; i++){
	  var ultags=document.getElementById(menuids[i]).getElementsByTagName("ul")
	    for (var t=0; t<ultags.length; t++){
	    var spanref=document.createElement("span")
			spanref.className="arrowdiv"
			spanref.innerHTML="&nbsp;&nbsp;"
			ultags[t].parentNode.getElementsByTagName("a")[0].appendChild(spanref)
		    ultags[t].parentNode.onmouseover=function(){
		    this.getElementsByTagName("ul")[0].style.left=this.parentNode.offsetWidth+submenuoffset+"px"
		    this.getElementsByTagName("ul")[0].style.display="block"
		    }
		    ultags[t].parentNode.onmouseout=function(){
		    this.getElementsByTagName("ul")[0].style.display="none"
		    }
    	}
  	}
}

//Enter "frombottom" or "fromtop"
var verticalpos="fromtop"
 // getAnchorPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the page.
function getAnchorPosition(anchorname) {
	// This function will return an Object with x and y properties
	var useWindow=false;
	var coordinates=new Object();
	var x=0,y=0;
	// Browser capability sniffing
	var use_gebi=false, use_css=false, use_layers=false;
	if (document.getElementById) { use_gebi=true; }
	else if (document.all) { use_css=true; }
	else if (document.layers) { use_layers=true; }
	// Logic to find position
 	if (use_gebi && document.all) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_gebi) {
		var o=document.getElementById(anchorname);
		x=AnchorPosition_getPageOffsetLeft(o);
		y=AnchorPosition_getPageOffsetTop(o);
		}
 	else if (use_css) {
		x=AnchorPosition_getPageOffsetLeft(document.all[anchorname]);
		y=AnchorPosition_getPageOffsetTop(document.all[anchorname]);
		}
	else if (use_layers) {
		var found=0;
		for (var i=0; i<document.anchors.length; i++) {
			if (document.anchors[i].name==anchorname) { found=1; break; }
			}
		if (found==0) {
			coordinates.x=0; coordinates.y=0; return coordinates;
			}
		x=document.anchors[i].x;
		y=document.anchors[i].y;
		}
	else {
		coordinates.x=0; coordinates.y=0; return coordinates;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// getAnchorWindowPosition(anchorname)
//   This function returns an object having .x and .y properties which are the coordinates
//   of the named anchor, relative to the window
function getAnchorWindowPosition(anchorname) {
	var coordinates=getAnchorPosition(anchorname);
	var x=0;
	var y=0;
	if (document.getElementById) {
		if (isNaN(window.screenX)) {
			x=coordinates.x-document.body.scrollLeft+window.screenLeft;
			y=coordinates.y-document.body.scrollTop+window.screenTop;
			}
		else {
			x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
			y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
			}
		}
	else if (document.all) {
		x=coordinates.x-document.body.scrollLeft+window.screenLeft;
		y=coordinates.y-document.body.scrollTop+window.screenTop;
		}
	else if (document.layers) {
		x=coordinates.x+window.screenX+(window.outerWidth-window.innerWidth)-window.pageXOffset;
		y=coordinates.y+window.screenY+(window.outerHeight-24-window.innerHeight)-window.pageYOffset;
		}
	coordinates.x=x;
	coordinates.y=y;
	return coordinates;
	}

// Functions for IE to get position of an object
function AnchorPosition_getPageOffsetLeft (el) {
	var ol=el.offsetLeft;
	while ((el=el.offsetParent) != null) { ol += el.offsetLeft; }
	return ol;
	}
function AnchorPosition_getWindowOffsetLeft (el) {
	return AnchorPosition_getPageOffsetLeft(el)-document.body.scrollLeft;
	}	
function AnchorPosition_getPageOffsetTop (el) {
	var ot=el.offsetTop;
	while((el=el.offsetParent) != null) { ot += el.offsetTop; }
	return ot;
	}
function AnchorPosition_getWindowOffsetTop (el) {
	return AnchorPosition_getPageOffsetTop(el)-document.body.scrollTop;
	}


function JSFX_FloatTopDiv()
{
	var coordinates = getAnchorPosition('VertAnchor')
	var startX = coordinates.x;
	var startY = coordinates.y;
	//alert(startX +':'+startY);
	//if(startY < 10)startY = 10;
	var ns = (navigator.appName.indexOf("Netscape") != -1);
	var d = document;
	function ml(id)
	{
		coordinates = getAnchorPosition('VertAnchor')
		startX = coordinates.x;
		startY = coordinates.y;
		//if(startY < 100)startY=100;
		var el=d.getElementById?d.getElementById(id):d.all?d.all[id]:d.layers[id];
		if(d.layers)el.style=el;
		el.sP=function(x,y){this.style.left=x;this.style.top=y;};
		el.x = startX;
		if (verticalpos=="fromtop")
		el.y = startY;
		else{
		el.y = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		el.y -= startY;
		}
		return el;
	}
	window.stayTopLeft=function()
	{
		
		coordinates = getAnchorPosition('VertAnchor')
		var posX = coordinates.x;
		var posY = coordinates.y;

		if (verticalpos=="fromtop"){
		var pY = ns ? pageYOffset : document.body.scrollTop;
//		ftlObj.y += (posY + startY - ftlObj.y)/8;
//		ftlObj.x += (posX + startX - ftlObj.x)/8;
		var pYY = 0;
		if(pY > (posY-20)) pYY = pY - (posY-20);
		ftlObj.y += (pYY + posY - ftlObj.y)/8;
		ftlObj.x += (posX - ftlObj.x)/8;
		//ftlObj.y = startY;
		}
		else{
		var pY = ns ? pageYOffset + innerHeight : document.body.scrollTop + document.body.clientHeight;
		//ftlObj.y += (pY - startY - ftlObj.y)/8;
		ftlObj.y += (pY - startY - ftlObj.y);
		}
		ftlObj.sP(ftlObj.x, ftlObj.y);
		setTimeout("stayTopLeft()", 10);
	}
	ftlObj = ml("divStayTopLeft");
	stayTopLeft();
}  //end of JSFX_FloatTopDiv()

function UpdateAllChildren(nodes, checked)
{
   var i;
   for (i=0; i<nodes.get_count(); i++)
   {
       if (checked)
       {
           nodes.getNode(i).check();
       }
       else
       {
           nodes.getNode(i).set_checked(false);
       }
       
       if (nodes.getNode(i).get_nodes().get_count()> 0)
       {
           UpdateAllChildren(nodes.getNode(i).get_nodes(), checked);
       }
   }
}
function clientNodeChecked(sender, eventArgs)
{
   var childNodes = eventArgs.get_node().get_nodes();
   var isChecked = eventArgs.get_node().get_checked();
   UpdateAllChildren(childNodes, isChecked);
}

//JSFX_FloatTopDiv();

//if (window.addEventListener)
//window.addEventListener("load", createcssmenu, false)
//else if (window.attachEvent)
//window.attachEvent("onload", createcssmenu)