﻿
//Workaround for evil Microsoft bug in IE :)
if(typeof(window.external) != 'undefined'){

    //yes, this is evil browser sniffing, but only IE has this bug


    document.getElementsByName = function(name, tag){
        if(!tag){
            tag = '*';
        }
        var elems = document.getElementsByTagName(tag);
        var res = []
        for(var i=0;i<elems.length;i++){
            att = elems[i].getAttribute('name');
            if(att == name) {
                res.push(elems[i]);
            }
        }
        return res;
    }

}


function toggleMenu(listId,parentId,menuMode,menuID){
	
	if (menuMode==0)
	{
	    if (document.getElementById(listId).style.display == "block"){
		    document.getElementById(listId).style.display="none";		
		    document.getElementById(listId).style.visibility="hidden";
		    document.getElementById(parentId).className="arrow_inactive selected_arrow";
	    }
	    else{
		    document.getElementById(listId).style.display="block";
		    document.getElementById(listId).style.visibility="visible";	
		    document.getElementById(parentId).className="arrow_active selected_arrow";
	    }
	}
	else
	{
	    
	    if (document.getElementById(listId).style.display == "block"){
		    document.getElementById(listId).style.display="none";		
		    document.getElementById(listId).style.visibility="hidden";
		    document.getElementById(parentId).className="arrow_inactive selected_arrow";
	    }
	    else{
	        
	        var Cookies=getCookie("openMenu");
	        
	        var arrCookies=Cookies.split('-');
	        var i=0;
	        var Depthi=0;
	        var tmpMenuID=0;
	        ob_post.AddParam('id', menuID);
	        
	        var Depth=ob_post.post("_script/ajax/menu_left.aspx","Depthfinder")
	           
	        if (Depth==0)
	            {
	                var sArrMenu=document.getElementsByName("rootkit","ul");   
                    var i=0;
	                setCookie("openMenu","-",1);  
	                while (i < sArrMenu.length)
                    {     
                         
                        document.getElementById(sArrMenu[i].id).style.display="none";		
                        document.getElementById(sArrMenu[i].id).style.visibility="hidden";
                        document.getElementById(parentId).className="arrow_right_inactive";
                        
                        i++;   
                    }   
	            }
	           
	         document.getElementById(listId).style.display="block";
		    document.getElementById(listId).style.visibility="visible";	
		    document.getElementById(parentId).className="arrow_active selected_arrow";
	        } 
	        
	 
	    /*
	    var sArrMenu=document.getElementsByName("rootkit","ul");   
        var i=0;
        
        ob_post.AddParam('id', menuID);
        var realParentId=ob_post.post("_script/ajax/menu_left.aspx","Parentfinder")
        var lastID=getCookie("lastclicks");
        
        //alert('LastID:'+lastID);
        //alert('Parent:'+realParentId);
        
        //alert(menuID+'*'+lastID+'*'+realParentId);
        if (lastID.indexOf(realParentId)==-1 && getCookie("lastclick")!=menuID)
        {
            setCookie('openMenu','-',0);
            
            while (i < sArrMenu.length)
            {     
                 
                document.getElementById(sArrMenu[i].id).style.display="none";		
                document.getElementById(sArrMenu[i].id).style.visibility="hidden";
                document.getElementById(parentId).className="arrow_right_inactive";
                
                i++;   
            }
            setCookie('lastclicks','|',0);
        }
	    
	    setCookie("lastclick",menuID,1);
	    setCookie("lastclicks",getCookie("lastclicks")+menuID+'|',1);    
	*/
	}
}
function addCookie(id)
{
  var d=new Date();
  var sArrOpen ='';
  var sCook=getCookie('openMenu');
  if((sCook != '') && (sCook!=null))
        {
        sArrOpen = sCook;
       
        }
  
  if(sArrOpen.indexOf('-' + id + '-') == -1 )
      {sArrOpen = sArrOpen + '-' + id + '-';
     
      }
  else
   {
      sArrOpen = sArrOpen.replace('-' + id + '-', '-');
      
   }
   
   /*
   if (id==0)
    {
       if(sArrOpen.indexOf('-' + id + '-') == -1 )
          sArrOpen='--';
       else
          sArrOpen='-0-';
       
    }*/
  setCookie("openMenu", sArrOpen.replace('--','-'),1);
}
/**
 * Read the JavaScript cookies tutorial at:
 *   http://www.netspade.com/articles/javascript/cookies.xml
 */


//w3schools
function setCookie(c_name,value,expiredays)
{
var exdate=new Date()
exdate.setDate(exdate.getDate()+expiredays)
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate)
}

/**
 * Gets the value of the specified cookie.
 *
 * name  Name of the desired cookie.
 *
 * Returns a string containing value of specified cookie,
 *   or null if cookie does not exist.
 */


function getCookie(cookiename) {
 var cookiestring=""+document.cookie;
 var index1=cookiestring.indexOf(cookiename);
 if (index1==-1 || cookiename=="") return ""; 
 var index2=cookiestring.indexOf(';',index1);
 if (index2==-1) index2=cookiestring.length; 
 return unescape(cookiestring.substring(index1+cookiename.length+1,index2));
}

/**
 * Deletes the specified cookie.
 *
 * name      name of the cookie
 * [path]    path of the cookie (must be same as path used to create cookie)
 * [domain]  domain of the cookie (must be same as domain used to create cookie)
 */
/*function deleteCookie(name, path, domain)
{
    if (getCookie(name))
    {
        document.cookie = name + "=" + 
            ((path) ? "; path=" + path : "") +
            ((domain) ? "; domain=" + domain : "") +
            "; expires=Thu, 01-Jan-70 00:00:01 GMT";
    }
}*/
/*To ERASE COOKIES*/
function eraseCookie(name) {
	createCookie(name,"-",-1);
	
}
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 var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
/*End COOKIE ERASER*/
function changeTop(top)
{
    
//    var t=document.getElementById(header);
//    alert(top);
//    t.className=top;

}

