var idTimeout = 0;

function showsubmenu(holderName)
{	
	var toppos  = "0px";
	var leftpos = "0px";
	var widthX  = "200px";
	var heightX = "50px";
	//alert(document.getElementById("submenu").style.height);
	if(idTimeout) clearTimeout(idTimeout);
	idTimeout = 0;
	document.getElementById("submenu").innerHTML = document.getElementById(holderName).innerHTML;
	switch(holderName)
	{
		case("eventmenu"):	
			leftpos = "45px";	
			//toppos = "-130px";
			toppos = "-138px";
			//widthX = "70px";
			widthX = "60px";
			//heightX = "45px";
			heightX = "20px";
			break;
		case("aboutmenu"):
			leftpos = "45px";	
			//toppos = "-175px";
			toppos = "-180px";
			widthX = "100px";
			heightX = "65px";
			break;
		case("aimsmenu"):
			leftpos = "45px";	
			//toppos = "-220px";
			toppos = "-230px";
			widthX = "105px";
			//heightX = "45px";
			heightX = "20px";
			break;
	}
	//document.getElementById("submenu").style.left = leftpos;
	document.getElementById("submenu").style.top = toppos;
	document.getElementById("submenu").style.left = leftpos;	
	document.getElementById("submenu").style.width = widthX;
	document.getElementById("submenu").style.height = heightX;
	document.getElementById("submenu").style.visibility = "visible";
	
	
}

function delayhidemenu()
{
	idTimeout = setTimeout("hidemenu()", 500);
}

function hidemenu()
{
	document.getElementById("submenu").innerHTML = "";
	document.getElementById("submenu").style.visibility = "hidden";
	idTimeout = 0;
}

function cancelhidemenu()
{
	if(idTimeout) clearTimeout(idTimeout);
	idTimeout = 0;
}
	

function pageInit()
{
	url = document.location.href;
	//if(url.indexOf("?") == -1) doanimate("home_process", 5, -20);
}

function doanimate(el, mvt, stopMvt)
{
	var x = document.getElementById(el).style.left;
	var pos = x.substr(0, x.indexOf("p"));
	
	
	if ((mvt > 0 && pos < stopMvt) || (mvt < 0 && pos > stopMvt))
	{
		document.getElementById(el).style.visibility = "visible";
		document.getElementById(el).style.left = (pos - (- mvt));
		setTimeout("doanimate('" + el + "', " + mvt + ", " + stopMvt + ")", 50);
	}
	else
	{
		switch(el)
		{
		case("home_process"):
			document.getElementById("home_plus").style.visibility = "visible";
			setTimeout("doanimate('home_systems', -5, 20)");
			break;
		
		case("home_systems"):
			document.getElementById("home_equals").style.visibility = "visible";
			setTimeout("doanimate('home_results', -5, 0)");
			break;
		}
	}
}

function Delete_Record(delUrl)
{		
	if (confirm("Are you sure you want to delete this record?"))  
    		document.location = delUrl;
}

function onMouseChangeColor(event, highlightcolor, ajaxaction, ajaxdiv, timeout)
{		
	// source is element which was selected b4
	source=document.getElementById('row'+readCookie('id2')); 		
	// change the colour back b4 change actual object
	if(source)	
		source.style.backgroundColor='#FFFFFF';	
	// change colour of the selected row
	changeto(event, highlightcolor);	
	// write the ID to cookie
	createCookie('id2', readCookie('id1'));			
	// call ajax and replace detail div		
	ajax('ajax.php?'+ajaxaction+'='+readCookie('id1'), ajaxdiv, '', timeout);
}

function changeColorOver(row_id)
{	
	// if row not equals to selected ID then
	if ( row_id!=readCookie('id2') )
	{
		source=document.getElementById('row'+row_id);
		
		if(source)	
			source.style.backgroundColor='#E0FFFF';	
	}
}

function changeColorOut(row_id)
{	
	// if row not equals to selected ID then
	if ( row_id!=readCookie('id1') )
	{
		source=document.getElementById('row'+row_id);
		
		if(source)	
			source.style.backgroundColor='#FFFFFF';	
	}
}

/***********************************************
* Highlight Table Cells Script- © Dynamic Drive DHTML code library (www.dynamicdrive.com)
* Visit http://www.dynamicDrive.com for hundreds of DHTML scripts
* This notice must stay intact for legal use
***********************************************/

//Specify highlight behavior. "TD" to highlight table cells, "TR" to highlight the entire row:
var highlightbehavior="TR"

var ns6=document.getElementById&&!document.all
var ie=document.all

function changeto(e,highlightcolor)
{
	source=ie? event.srcElement : e.target	
	if (source.tagName=="TABLE")
		return
	while(source.tagName!=highlightbehavior && source.tagName!="HTML")
		source=ns6? source.parentNode : source.parentElement
	if (source.style.backgroundColor!=highlightcolor&&source.id!="ignore")
		source.style.backgroundColor=highlightcolor
}

function contains_ns6(master, slave)
{ //check if slave is contained by master
		while (slave.parentNode)
		if ((slave = slave.parentNode) == master)
			return true;
		return false;
}

function changeback(e,originalcolor)
{
	if (ie&&(event.fromElement.contains(event.toElement)||source.contains(event.toElement)||source.id=="ignore")||source.tagName=="TABLE")
		return
	else if (ns6&&(contains_ns6(source, e.relatedTarget)||source.id=="ignore"))
		return
	if (ie&&event.toElement!=source||ns6&&e.relatedTarget!=source)
		source.style.backgroundColor=originalcolor
}

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=/";
}

function readCookie(name)
{
	var ca = document.cookie.split(';');
	var nameEQ = name + "=";
	for(var i=0; i < ca.length; i++)
	{
		var c = ca[i];
    		while (c.charAt(0)==' ') c = c.substring(1, c.length); //delete spaces
    		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
	}
  	return null;
}

function eraseCookie(name)
{
	createCookie(name, "", -1);
}

function leftTrim(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}

function rightTrim(sString)
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function trimAll(sString)
{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
	sString = sString.substring(0,sString.length-1);
	}
	return sString;
}

function win_popup(mylink, windowname, winwidth, winheight)
{
if (! window.focus)return true;
var href;
if (typeof(mylink) == 'string')
   href=mylink;
else
   href=mylink.href;
window.open(href, windowname, winwidth, winheight, 'scrollbars=yes');
window.focus();
return false;
}