// Website main JavaScript functions

function checkBrowser() {
    var strChUserAgent = navigator.userAgent;
    var intSplitStart = strChUserAgent.indexOf("(",0);
    var intSplitEnd = strChUserAgent.indexOf(")",0);
    var strChStart = strChUserAgent.substring(0,intSplitStart);
    var strChMid = strChUserAgent.substring(intSplitStart, intSplitEnd);
    var strChEnd = strChUserAgent.substring(strChEnd);
	
	if(strChMid.indexOf("MSIE 8") != -1)
    	browser = "IE";
    else if(strChMid.indexOf("MSIE 7") != -1)
    	browser = "IE";
	else if(strChMid.indexOf("MSIE 6") != -1)
    	browser = "IE";
    else if(strChEnd.indexOf("Firefox/2") != -1)
    	browser = "FIREFOX";
    else if(strChEnd.indexOf("Firefox") != -1)
    	browser = "FIREFOX";
    else if(strChEnd.indexOf("Netscape/7") != -1)
    	browser = "NETSCAPE";
    else if(strChEnd.indexOf("Netscape") != -1)
    	browser = "NETSCAPE";
    else if(strChStart.indexOf("Opera/9") != -1)
    	browser = "OPERA";
    else if(strChStart.indexOf("Opera") != -1)
    	browser = "OPERA";
	else if(strChUserAgent.indexOf("Safari") != -1)
		browser = "SAFARI";
    else
		browser = "OTHER";
	
	return browser;
}

function sleep(time) {
	d=new Date();
	diff=0;
	while(diff < time)
	{
		n=new Date();
		diff=n-d;
	} 
}

function getPageSize(){
	
	var xScroll, yScroll;
	
	if (window.innerHeight && window.scrollMaxY) {	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}
	
	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	
	
	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else { 
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){	
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	return yScroll;
}

function getCenterScroll(){

	var yScroll;

	/*if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}*/
	
	yScroll = document.getElementById('center').scrollTop;

	return yScroll;
}

function moveMenu() {
	pos = getCenterScroll() + "px";
	document.getElementById('menu').style.top = pos;
}

function setPageTitle(pageTitle) {
	document.title = pageTitle;	
}

function menuOver(id)
{
	resetSubmenus();
	document.getElementById(id).className = "menucellover";
	submenuid = "sub" + id;
	if(document.getElementById(submenuid) != null) 
	{
		document.getElementById(submenuid).className = "submenuvisible";
	}
}

function menuOut(id)
{
	document.getElementById(id).className = "menucell";
}

function submenuOver(id)
{
	document.getElementById(id).className = "submenuvisible";
	menu = id.substr(3, id.length-3);
	document.getElementById(menu).className = "menucellover";	
}

function submenuOut(id)
{
	document.getElementById(id).className = "submenuhidden";
	menu = id.substr(3, id.length-3);
	document.getElementById(menu).className  = "menucell";
}

function resetSubmenus()
{
	tablesArray = document.getElementsByTagName("td");
	
	for(t = 0; t < tablesArray.length; t++) 
	{
		if(tablesArray[t].id.indexOf("submenu") != -1)
		{
			tablesArray[t].className = "submenuhidden";
		}
	}
}

function setPageTitle(pageTitle)
{
	document.title = pageTitle;	
}

function blockKeyCode(e) 
{
	 var keycode = (window.event) ? event.keyCode : e.keyCode;
	 
	 if (document.all) {
		if (keycode == 116) {
		   event.keyCode = 0;
		   event.returnValue = false;
		   return false;
		}
	 }
	 else {
		if (keycode == 116) {
		   return false;
		}
	 }
}

function mouseMovePopBox (evt) {
	var x = 0;
	var y = 0;
	var plusX = 0;
	var plusY = 0;
	if (document.layers) {
		x = evt.x;
		y = evt.y;
		plusX = window.pageXOffset;
		plusY = window.pageYOffset;
	} else	if (document.all) {
		x = event.clientX;
		y = event.clientY;
		plusX = document.body.scrollLeft;
		plusY = document.body.scrollTop;
	} else if (document.getElementById) {
		x = evt.clientX;
		y = evt.clientY;
		plusX = window.pageXOffset;
		plusY = window.pageYOffset;
	}
	document.getElementById("popBox").style.left = (x+plusX+15)+"px";
	document.getElementById("popBox").style.top = (y+plusY+5)+"px";
} 

	
function showPopBox(id, text) {
 var elt = document.getElementById(id);
 elt.innerHTML = '<p width="50px">' + text + '</p>';
 elt.style.display = "block";
}

function hidePopBox(id) {
 var elt = document.getElementById(id);
 elt.style.display = "none";
}

function trim(str)
{
	return str.replace(/^\s\s*/, '').replace(/\s\s*$/, '');	
}

