var nodeOver = false;
var nodeOptions = null;
var intervalID = 0;

// loads the selected option
function loadOption(evt, formList)
{
     evt = (evt) ? evt : ((window.event) ? window.event : "");
	 
	 endBubble(evt);

	var chosen = formList.selectedIndex;
	
	var pathUrl = new String(location.protocol +"//"+ location.host+ formList.options[chosen].value);
	pathUrl = pathUrl.toLowerCase();
	
    if (chosen > 0)
    { 
	  location.href = pathUrl;
	  
	}
/*
	if (!evt) var evt = window.event;
	evt.cancelBubble = true;
	if (evt.stopPropagation) evt.stopPropagation();
	return false;
	*/
}
// end hiding

function endBubble(evt)
{
    if(evt.cancelBubble == false){ 
        evt.cancelBubble = true; 
        evt.returnValue = false;
        
     }
	 if (evt.stopPropagation) {
	    evt.stopPropagation(); 
	    evt.preventDefault();
    	
	 }
}

 function startList(){
	if (document.all&&document.getElementById) {
		navRoot = document.getElementById("nav");
		for (i=0; i<navRoot.childNodes.length; i++) {
			node = navRoot.childNodes[i];
			if (node.nodeName=="LI") 
			{
				if(node.id=="products")
				{
					node.onmouseover=function() 
					{
						this.className+=" productOver";
					}
					node.onmouseout=function() 
					{
						this.className=this.className.replace(" productOver", "");
					}
				}
				else
				{
					node.onmouseover=function() 
					{
						this.className+=" over";
					}
					node.onmouseout=function() 
					{
						this.className=this.className.replace(" over", "");
					}
				}				
			}
		}
	}
}

function button_over(btn)
{
	var __nodeOptions = null;
	__nodeOptions = btn.parentNode;
	if( !(__nodeOptions.className=='container' || __nodeOptions.className=='container_over') )
	{
		__nodeOptions=__nodeOptions.parentNode;
	}
	if( __nodeOptions!=nodeOptions && nodeOptions!=null)
	{
		nodeOptions.className='container';
	}
	__nodeOptions.className='container_over';
	nodeOptions=__nodeOptions;
	nodeOver = true;
	
	
}
function button_out()
{
	nodeOver = false;
}
function valid_visibility()
{
	if( !nodeOver && nodeOptions!=null )
	{
		nodeOptions.className='container';
		/*
		alert("before if test "+intervalID+" "+typeof(intervalID));
		if(intervalID != 0)
		{
			alert("cleared the interval\n"+intervalID);
			clearInterval(intervalID);
			alert("cleared the interval\n"+intervalID);
		}
		*/
	}
}
intervalID = setInterval("valid_visibility()",100);

var currPage = location.pathname;

var ieModel = false;
if (window.addEventListener){
    window.addEventListener('load', openLeftMenu, false );
    //window.addEventListener('load', searchKB, false);
	
}
else {
   	window.attachEvent('onload', openLeftMenu);
   	//window.attachEvent('onload', searchKB);
   	if(currPage=="/AboutLANDesk/Customer.aspx")
   	{
   	   window.attachEvent('onload', addMouseMenu);
   	}
   	if(currPage=="/default.aspx"||currPage=="/")
   	{
   	   window.attachEvent('onload', displayDDHome);
   	}
	ieModel = true;
}

/**
 * This function allows the programmer to retrieve objects biased on the class name you 
 * want to retrieve. Similar to the GetElementByID and GetElementByTagName.
 * @member UtilNS
 * @param {object} oElm The object you want to search, could be a whole document or something more specific.
 * @param {string} strTagName The string containing the name of the tag name i.e. "a", "div", "span" what ever the class name is attached to.
 * If no tag is given it will search all elements.
 * @param {string} strClassName The string containing the class name you're searching for
 * @returns An array filled with the class names found in the search
 * @type Array
 * {@link  http://www.robertnyman.com/2005/11/07/the-ultimate-getelementsbyclassname/#more-256 getElementsByClassName} Utility Function
 */


function getElementsByClassName(oElm, strTagName, strClassName){
	var arrElements = (strTagName == "*" && document.all)? document.all : oElm.getElementsByTagName(strTagName);
	var arrReturnElements = new Array();
	strClassName = strClassName.replace(/\-/g, "\\-");
	var oRegExp = new RegExp("(^|\\s)" + strClassName + "(\\s|$)");
	var oElement;
	for(var i=0; i<arrElements.length; i++){
		oElement = arrElements[i];		
		if(oRegExp.test(oElement.className)){
			arrReturnElements.push(oElement);
		}	
	}
	return arrReturnElements;
}

function openLeftMenu()
{
	
		var lhn = getElementsByClassName(document, "td", "MenuLeft");
		var allianceStr = "alliances and partnerships";

		if(lhn && (lhn.length == 1))
		{
			var temp = lhn[0];
			var ulName = temp.getElementsByTagName("ul");
			
			if(ulName[0].className == "ulRight")
			{
				var temp2 = ulName[0];
				var aTags = temp2.getElementsByTagName("a");
				var path = new String(location);
				path = path.toLowerCase();

				if(path.indexOf("#") == (path.length -1))
					path = path.substr(0, path.length-1);
				//alert(path + " " + path.indexOf("partner") + " " + path.indexOf("corporate"));
				
				path2 = new String(location.search);
				path2 = path2.substr(1, path2.length);
				if(path2.indexOf("#") == (path2.length -1))
						path2 = path2.substr(0, path2.length-1);	
				
				var i=0;
				var foundNum = -1;
				
				for(i=0; i < aTags.length; i++)
				{
					var linkPath = new String(aTags[i].href);
					linkPath = linkPath.toLowerCase();
					//console.debug("%d %s %s %b", i, aTags[i].innerHTML, allianceStr, ((aTags[i].innerHTML.toLowerCase() == allianceStr) && path.indexOf("corporate/partners") > 0));
					
					if(path == linkPath)
					{
						foundNum = i;
						
						break;
					}
					else if((aTags[i].innerHTML.toLowerCase() == allianceStr) && path.indexOf("corporate/partners") > 0)// partners check
					{
						foundNum = i;
						//alert(i+" "+linkPath);
						break;	
					}
					else
					{	// check search params
						
						linkPath = linkPath.substr(linkPath.indexOf("?")+1, linkPath.length);
						var foundIndex = linkPath.lastIndexOf("id=");
						linkPath = linkPath.substr(foundIndex, linkPath.length);
						if(foundIndex > 0 && (path2 == linkPath))
						{
							foundNum = i;
							
							break;
						}
						
					}
				}
				
				
				
				if(foundNum != -1)
				{
					var leaf = aTags[foundNum];
				
					
					while(leaf.parentNode.className != "ulRight")
					{
						leaf = leaf.parentNode;
						
					}
					
					leaf.className = "ulDown";	  
				}
				
		}
	}
}

/*------------ Knowledge BASE--------------------------------------------*/
/* <form name="searchform" action="http://kb.landesk.com/display/4/search.asp" method="post"> */
/* <form id="aspnetForm" action="Default.aspx" method="post" name="aspnetForm">*/
function searchKB () {
    
    var url = location.pathname;
    
    if(url.toLowerCase() == "/supportdownload/default.aspx")
    {
        //var tdCell = document.getElementById("kbTd");
        // id="searchtype" style="MARGIN-TOP: 1px" onchange="setSearchBy();" 
        var searchtype = document.getElementById("searchtype");
        searchtype.onchange = function (){setSearchBy(); };
        
        // id="kbid" style="MARGIN-TOP: 0px" onchange="document.aspnetForm.search.value=0;document.aspnetForm.kbchange.value=1;document.aspnetForm.submit();"
        var kbid = document.getElementById("kbid");
        kbid.onchange = function(){
            document.aspnetForm.search.value=0;
            document.aspnetForm.kbchange.value=1;
            document.aspnetForm.submit();
        };
        
        
        // id="cat1id" style="MARGIN-TOP: 0px" onchange="document.aspnetForm.search.value = 0;document.aspnetForm.submit();"
        var cat1id = document.getElementById("cat1id");
        cat1id.onchange = function() {
            document.aspnetForm.search.value = 0;
            document.aspnetForm.submit();
        };
        var form = document.getElementById("aspnetForm");
	    form.action="http://kb.landesk.com/display/4/search.asp"; 
    }
}


function setSearchBy () {
sVal = document.aspnetForm.searchtype.value;
if (sVal == "nlq") {
    document.aspnetForm.searchby.value = "freetext";
	}
else if (sVal == "exact") {
	document.aspnetForm.searchby.value = "exactKeyword";
	}
else
	document.aspnetForm.searchby.value = "keywords";
	
	
}

/*------------ Google Search--------------------------------------------*/
/* <form name="searchform" action="http://search.landesk.com/search" method="post"> */
function SetSearchForm () {
        var form = document.getElementById("aspnetForm");
	    form.action="http://search.landesk.com/search";
	    form.method="get";
}

function setfocusSearch(va, evt)
{   
    evt = (evt && evt.keyCode) ? evt : ((window.event) ? window.event : "");
    var searchInput = (evt.target) ? evt.target : evt.srcElement;   
	if (evt && (evt.keyCode == 13) && (va.length > 0) && (searchInput.value == va)) 
    {
        var form = document.getElementById("aspnetForm");
	    form.action="http://search.landesk.com/search";
	    form.method="get";
        form.submit()
    } 
}

function setTimeId(value)
{
var field = document.getElementById("DataId");
field.value = value;
}
/*------------------LANDESK CODE-------------------------*/
//    Opens a new window with specified properties
function openWin(url,name,w,h,scroll,resize,status,title,tool,menubar)
{
      var sFeatures;
      if (typeof(h) == "undefined") h = 300;
      if (typeof(w) == "undefined") w = 400;
      
      var screenW = screen.width;
      var screenH = screen.height;
      var posX = (screenW/2)-(w/2);
      var posY = (screenH/2)-(h/2);
      
      sFeatures = "screenY="+posY+",screenX="+posX+",top="+posY+",left="+posX+",height="+h+",width="+w;
      
      if (typeof(scroll) != "undefined"){ sFeatures += ",scrollbars=" + scroll; }
      if (typeof(resize) != "undefined"){ sFeatures += ",resizable=" + resize; }
      if (typeof(status) != "undefined"){ sFeatures += ",status=" + status; }
      if (typeof(title) != "undefined"){ sFeatures += ",titlebar=" + title; }
      if (typeof(tool) != "undefined"){ sFeatures += ",toolbar=" + tool; }
      if (typeof(menubar) != "undefined"){ sFeatures += ",menubar=" + menubar; }
      
      //alert(sFeatures);
      var win = window.open(url,name,sFeatures);
      win.focus();
}
/*-----------------------END LANDESK CODE -------------------------------*/

/*----------------------- Start Fix dropdown -----------------------------------*/
function addMouseMenu()
{
 
 if(document.getElementById("ie6only"))
 {
   var temp = new Array(4);
   var temp2 = new Array(4);
   
   if(typeof(swapImgArr[0]) == 'string')
   {
       for(i=0; i < swapImgArr.length; i++)
       {
         temp[i] = document.getElementById(swapImgArr[i]);
         temp2[i] = document.getElementById(ddArr[i]);
       }
       swapImgArr = temp;
       ddArr = temp2;
       var products = document.getElementById("products");
       var support = document.getElementById("support");
       products.attachEvent('onmouseover', swapBoxes);
       products.attachEvent('onmouseout', swapBoxes);
       support.attachEvent('onmouseover', swapBoxes);
       support.attachEvent('onmouseout', swapBoxes);
      
  }
 }
}
var proSelect = null;
var swapImgArr = new Array("ddlIndustryImg","ddlProductImg","ddlNodesImg","ddlGeographyImg");
var ddArr = new Array("ctl00_ContentPlaceHolder1_ddlIndustry", "ctl00_ContentPlaceHolder1_ddlProduct", "ctl00_ContentPlaceHolder1_ddlNodes", "ctl00_ContentPlaceHolder1_ddlGeography");
var setHide = false;
function swapBoxes()
{
 
 if(setHide) // hide the fake boxes restore the originals
 { 
    try {
        for(var i=0; i < swapImgArr.length; i++)
        {
           swapImgArr[i].className = "hid";
           ddArr[i].className = "SelectStyle";         
        }  
    }
    catch(e)
    {
        
    }
    setHide = false;
 }
 else // show the fake boxes get the selected from the list items
 {
    try {
        for(var i=0; i < swapImgArr.length; i++)
        {
            swapImgArr[i].className = "";
            ddArr[i].className= "SelectStyle hid";
        }
    }
    catch(e)
    {
    
    }
    setHide = true;
 }
}
function displayDDHome() 
{
   
   var ddList = document.getElementById("prodselect2");
   if(ddList)
   {
    var prodselect2 = new YAHOO.Hack.FixIESelectWidth( 'prodselect2'  );
   }
}

/*-----------------------   End Fix dropdown -----------------------------------*/
