function SetCookie(cookieName,cookieValue,nDays) {
 var today = new Date();
 var expire = new Date();
 if (nDays==null || nDays==0) nDays=1;
 expire.setTime(today.getTime() + 3600000*24*nDays);
 document.cookie = cookieName+"="+escape(cookieValue)+";expires="+expire.toGMTString();
}


function ReadCookie(cookieName) {
 var theCookie=""+document.cookie;
 var ind=theCookie.indexOf(cookieName);
 if (ind==-1 || cookieName=="") return ""; 
 var ind1=theCookie.indexOf(';',ind);
 if (ind1==-1) ind1=theCookie.length; 
 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

opened_menuT = 'temp';
opened_menuL = 'temp';
hidetimerT = false;
MenuHover = false;
L1Timer = "";

function setTimer(){
	if(hidetimerT){
		clearTimeout(L1Timer);
	}
	L1Timer = setTimeout("doHideMenuT();", 2000);
	hidetimerT = true;
}

function unsetTimer(){
	if(hidetimerT){
		clearTimeout(L1Timer);
		hidetimerT = false;
	}
}

/* Function is called when a L2 or L3 item is hovered */
function onM() {
	MenuHover = true;
}

/* Function is called onmouseout of L1 menu, L2 menu, L2 item or L3 item */
function offM() {
	MenuHover = false;
	setTimer();
}

function hideLIfOpen(){
	var menudiv_open = window.document.getElementById(opened_menuL);
	if(menudiv_open) {
		menudiv_open.style.display = 'none';
		menudiv_open.style.left = '0px';
		opened_menuL = 'temp';
	}
}

function hideTIfOpen(){
	var menudiv_open = window.document.getElementById(opened_menuT);
	if(menudiv_open) {
		menudiv_open.style.display = 'none';
		menudiv_open.style.left = '0px';
		opened_menuT = 'temp';
	}
}

/* Function is called when a L1 or L2 menu is hovered */
function spawnMenu(menu, parnt, TorL) {
	var menudiv = window.document.getElementById(menu);
	var reference = parnt;
	var offSetL = 0;
	var offSetT = 0;
	
	MenuHover = true;
		
	if(opened_menuT == menu || opened_menuL == menu)
		return;
	
	hideLIfOpen();
	if(TorL == 'T') {
		hideTIfOpen();
	}

	while(reference)
	{
		if(TorL == 'L'){
			offSetL += reference.offsetLeft;
			offSetT += reference.offsetTop;
			break;
		}
		else{
			offSetL += reference.offsetLeft;
			offSetT += reference.offsetTop;
			reference = reference.offsetParent;
		}
	}

	if(TorL == 'T')
		offSetT += 24;
	else {
		offSetL += 149;
	}

	menudiv.style.left = offSetL+"px";
	menudiv.style.top = offSetT+"px";
	menudiv.style.display = 'block';
	menudiv.style.height = 'auto';
	
	if(TorL == 'L')
		opened_menuL = menu;
	else
		opened_menuT = menu;
}

/* Function is called when a L1 item is hovered */
function hideAll() {
	unsetTimer();
	MenuHover = false;
	hideLIfOpen();
	hideTIfOpen();
}

function doHideMenuT(){
	hidetimerT = false;
	if(MenuHover) // Hover is active, don't close stuff
		hidetimerT = false;
	else
		hideAll();
}

function Go(dest){
	document.location.href=dest;
}

function GoPg(destid, mid){
	if(destid != -1)
		document.location.href='p.php?id='+destid+'&mid='+mid;
}

function RefreshMe(res){
	//location.reload(true);
	//document.location.href = document.location.href;
	document.getElementById('projects_menu_container').innerHTML = res;
}

function GotoAJAX(dest){
	AJAXRequest(dest, RefreshMe);
}

function AJAXRequest(dest, completefunc){
<!-- // Required to be compliant with XHTML-->
	var xmlHttp=null; // Defines that xmlHttp is a new variable.
	var res;
		// Try to get the right object for different browser
	try {
		// Firefox, Opera 8.0+, Safari, IE7+
		xmlHttp = new XMLHttpRequest(); // xmlHttp is now a XMLHttpRequest.
	}
	catch (e) {
		// Internet Explorer
		try {
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch (e) {
			xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	xmlHttp.onreadystatechange = function() {
		if (xmlHttp.readyState == 4)
			try { 	// In some instances, status cannot be retrieved and will produce an error (e.g. Port is not responsive)
				if (xmlHttp.status == 200) {
					// Set the main HTML of the body to the info provided by the  Ajax Request
					res = xmlHttp.responseText;
					completefunc(res);
				}
			}
			catch (e) {
				res = -1;//"Error on Ajax return call : " + e.description;
				completefunc(res);
			}

	}
	
	xmlHttp.open("get",dest); // .open(RequestType, Source);
	xmlHttp.send(null); // Since there is no supplied form, null takes its place 
					 // as a new form.
	return res;
}