var chk_menu	=	0;
window.onload = function()
{
//collapseAll('menuItem');
//alert("boo");
   // setFromCookie();
 //setTimeout("setFromCookie()",200);
}

function headerMouseOver(td)
{
 td.style.backgroundColor="#666667";
 td.style.cursor='hand';
}
function headerMouseOut(td)
{
 td.style.backgroundColor='#999998';
}

function headerMousePress(id,td)
{
//alert("inside js "+id);
 ioSwitch(id);
}

function setFromCookie()
{
 if (document.getElementsByTagName)
{
  var nl = document.getElementsByTagName('div');
  var l = nl.length;
  for (var i = 0; i<l; i++){
   var node = nl.item(i);
   if (node.getAttribute('name') == 'menuItem')
{
    var id = node.id;
    var val = getCookie(id);
    if(val == "collapsed"){
     collapse(id,true);
    } else if (val == 'expanded'){
     expand(id,true);
    } else
{
     if(node.getAttribute('init') == 1){
      expand(id,true);
     } else
{
      collapse(id,true);
     }
    } 
   }
  }
 }
} 

function setToDefault()
{
 if (document.getElementsByTagName)
{
  var nl = document.getElementsByTagName('div');
  var l = nl.length;
  for (var i = 0; i<l; i++){
   var node = nl.item(i);
   if (node.getAttribute('name') == 'menuItem')
{
    if(node.getAttribute('init') == 1){
     expand(node.id);
    } else
{
     collapse(node.id);
    } 
   }
  }
 }
}

img_expanded  = 'arrow_closed.gif';
img_collapsed = 'arrow_open.gif';

function expand(ioNode,cook)
{
 //ioWedge = "i" + ioNode.substr(1);
 ioButton = "b" + ioNode.substr(1);
 
 if (document.getElementById && document.getElementById(ioNode) != null)
{
  //if(!cook)setCookie(ioNode, "leaf", getCTime(), '/', "www.cooperative-solutions.com", '');
  //document.getElementById(ioButton).style.borderBottom="0px solid #E4ECF3";
  //document.getElementById(ioWedge).src=img_collapsed;
  //document.getElementById(ioWedge).title='collapse';
  //document.getElementById(ioButton).style.borderLeft="1em solid #666666";
 // document.getElementById(ioButton).style.fontSize='12px';
  document.getElementById(ioNode).className='expand';
//  alert("hi")
  document.getElementById(ioNode).width='160px';
  
 }
}

function collapse(ioNode,cook)
{
 //ioWedge = "i" + ioNode.substr(1);
 //ioButton = "b" + ioNode.substr(1);
 
 if (document.getElementById && document.getElementById(ioNode) !=  null)
{
  //if(!cook)setCookie(ioNode, "collapsed", getCTime(), '/', "www.cooperative-solutions.com", '');
  //document.getElementById(ioButton).style.borderBottom="1px solid #E4ECF3";
  //document.getElementById(ioWedge).src=img_expanded;
  //document.getElementById(ioWedge).title='expand';
 // document.getElementById(ioButton).style.borderLeft="0em";
 // document.getElementById(ioButton).style.fontSize='11px';
  document.getElementById(ioNode).className='collapsed';
//  document.getElementById(ioNode).width='160px';
 }
}

function ioSwitch(ioNode)
{

 if (document.getElementById && document.getElementById(ioNode) !=  null)
{
  nodeState = document.getElementById(ioNode).className;
 }

    if (nodeState == 'collapsed')
{
  expand(ioNode);
  return 1;
 }

 else
{
  collapse(ioNode);
  return 0;
 }
}

function expandAll(divName) 
{
 if (document.getElementsByTagName)
{
  var nl = document.getElementsByTagName('div');
  var l = nl.length;
  for (var i=0; i<l;i++)
{
   var node = nl.item(i);
   if (node.getAttribute('name') == divName)
{
    expand(node.id); 
   }
  }
 }
}

function collapseAll(divName) 
{
 if (document.getElementsByTagName)
{
  var nl = document.getElementsByTagName('div');
  var l = nl.length;
  for (var i=0; i<l;i++)
{
   var node = nl.item(i);
   if (node.getAttribute('name') == divName)
{
    collapse(node.id); 
   }
  }
 }
}



// Cookie functions

function setCookie (name, value, expires, path, domain, secure) 
{
    var curCookie = name + "=" + escape(value) + ((expires) ? "; expires=" + expires.toGMTString() : "") + ((path) ? "; path=" + path : "") + ((domain) ? "; domain=" + domain : "") + ((secure) ? "; secure" : "");
    document.cookie = curCookie;
}

function getCookie (name) 
{
    var prefix = name + '=';
    var c = document.cookie;
    var nullstring = '';
    var cookieStartIndex = c.indexOf(prefix);
    if (cookieStartIndex == -1)
        return nullstring;
    var cookieEndIndex = c.indexOf(";", cookieStartIndex + prefix.length);
    if (cookieEndIndex == -1)
        cookieEndIndex = c.length;
 var value = unescape(c.substring(cookieStartIndex + prefix.length, cookieEndIndex));
    return value;
}


function fixDate (date)
{
    var base = new Date(0);
    var skew = base.getTime();
    if (skew > 0)
        date.setTime(date.getTime() - skew);
}


function getCTime()
{
    var now = new Date();
    fixDate(now);
    now.setTime(now.getTime() + 365 * 24 * 60 * 60 * 1000);
 return now;
}

function timeout(ids,va){
	setTimeout("hide_menu(\""+ids+"\")", '100');
}

function hide_menu(ids,va){
	
	if(chk_menu!=1){
		
		document.getElementById(ids).className='collapsed';
	}else{

	}

}

function chk_men(ids,va){
	if(va==1){
		chk_menu	=	1;
		document.getElementById(ids).className='expand';
		
	}else{
		//	alert("working");
		chk_menu	=	0;
		setTimeout("hide_menu(\""+ids+"\",\""+va+"\")", '1000');
	}
	
}
