// Create a cookie with the specified name and value.
// The cookie expires at the end of the 20th century.
function SetCookie(sName, sValue)
{
  var now = new Date();
  cookie_exp = new Date(now.getFullYear() + 1, now.getMonth(), now.getDay());
  document.cookie = sName + "=" + escape(sValue) + "; expires=" + cookie_exp.toGMTString() + "; path=/"; 
}

// Retrieve the value of the cookie with the specified name.
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

function byid(id){return document.getElementById(id);}

function opnewWin (s, w, h, is_centered)
{	
	if (is_centered == 1)
	{
		var coord = new Array();
		coord = get_center_window_coord(h, w);
		left_pos = coord["x"];
		top_pos = coord["y"];
		winank = window.open(s, "picture", "height=" + h + ",width=" + w + ",,,,,,top=" + top_pos + ",left=" + left_pos);
	}
	else
	{
		winank = window.open (s, "picture", "width= " + w + ", height= " + h);
	}	
}


function get_center_window_coord(h_desc, w_desc)
{
	var coord = new Array("x", "y");
	var swidth=0;
	var sheight=0;
	var left_pos, top_pos;
	h_desc = h_desc || 500;
	w_desc = w_desc || 600;
	if (self.screen) { // for NN4 and IE4
	  swidth = screen.width;
	  sheight = screen.height	  
	} else if (self.java) { // for NN3 with enabled Java
	  var jkit = java.awt.Toolkit.getDefaultToolkit();
	  var scrsize = jkit.getScreenSize();
	  swidth = scrsize.width;
	  sheight = scrsize.height;
	}
	coord["x"] = (swidth/2) - (w_desc/2);
	coord["y"] = (sheight/2) - (h_desc/2);
	return coord;
}
function hig(id_menu){
	obj_menu = document.getElementById('m_'+id_menu);
	if(obj_menu !=null){
		obj_menu.className = 'active';
	}
	/* if last */
	obj_menu = document.getElementById('nav');
	if(obj_menu !=null){
		if(obj_menu.hasChildNodes()){
			//alert(obj_menu.childNodes.length);
			i = obj_menu.childNodes.length - 1;
			while(obj_menu.childNodes[i].nodeName !="LI" || i<=0 )	i--;
			last = -1;
			for(j =0; j< obj_menu.childNodes.length; j++){
				if(obj_menu.childNodes[j].nodeName =="LI" ){
					if(obj_menu.childNodes[j].id ==  'm_'+id_menu){
						break;
					}
					last = j;
				}
			}
			if(last != -1){
				obj_menu.childNodes[last].className = 'na_ser';
			}
			//obj_menu.childNodes[i].className = 'last';
			if(obj_menu.childNodes[i].id == 'm_'+id_menu){
				obj_menu.childNodes[i].className = 'active act_last';
				//obj_menu.childNodes[i].className += ' act_last';
			} else {
				obj_menu.childNodes[i].className = 'last';
			}
		}
			
	}
}

function get_last(){
	nav_obj = document.getElementById('nav');
	if(nav_obj.hasChildNodes){
		nav_obj.childNodes.length
	}
}

function hig2(id_menu){
	obj_menu = document.getElementById('l_'+id_menu);
	if(obj_menu !=null){
		obj_menu.className = 'active';
		ul_f(obj_menu);
	}
}

function ul_f(obj){
	if(obj.parentNode != null){ 
		if(obj.parentNode.tagName == 'UL'){
			if(obj.parentNode.id == 'left_menu'){
				return false;
			}
			obj.parentNode.className = 'ul_o';
		}
		ul_f(obj.parentNode);
	} else {
		return false;
	}
}

function open_menu(id){
	if(byid('l_' + id) !=null){
		if(byid('l_' + id).hasChildNodes){
			if(byid('l_' + id).getElementsByTagName('UL').length != 0){
				if(byid('l_' + id).getElementsByTagName('UL')[0].className == 'ul_o'){
					byid('l_' + id).getElementsByTagName('UL')[0].className = '';
				} else {
					byid('l_' + id).getElementsByTagName('UL')[0].className = 'ul_o';
				}
			} else {
				if(byid('l_' + id).getElementsByTagName('A').length != 0){
					//alert(byid('l_' + id).getElementsByTagName('A')[0]);
					location.href = byid('l_' + id).getElementsByTagName('A')[0];
				}
			};
		}
	}
}