//______________________________________________________________________

// The following code is used for the drop-down menus
// on the home and overview pages


var ParentItems = new Array();
var ChildItems = new Array();

var DelightClasses = new Array();

var MouseOverItemID = '';
var TimerItemID = '';
var RootMenuItemID='top';

// Test the User's browser...
var DomYes=document.getElementById?1:0;

function HL(MenuItemID, ParentItemID)	{
OnMenuItem(MenuItemID, ParentItemID, 160, 0, 'pop-on');
}

function DL(MenuItemID)	{
	OffMenuItem(MenuItemID, 'pop-off');
}


function OnMenuItem(MenuItemID, ParentItemID, OffsetX, OffsetY, HighlightClass){
	document.getElementById('I' + MenuItemID).className=HighlightClass;
	PositionRelative('M' + MenuItemID, 'M' + ParentItemID, 'I' + MenuItemID, OffsetX, OffsetY)
	ShowElement('M' + MenuItemID);
	MouseOverItemID = MenuItemID;
	ParentItems[MenuItemID]=ParentItemID;
	ChildItems[ParentItemID]=MenuItemID;
}

function OffMenuItem(MenuItemID, DelightClass) {
	MouseOverItemID='';
	DelightClasses[MenuItemID]=DelightClass;
	setTimeout('ClearMenu("' + MenuItemID + '")',50);
}

function ClearMenu(MenuItemID) {
	if ((!MouseOnMenuOrChild(MenuItemID) && MenuItemID!=RootMenuItemID)) {
		document.getElementById('I' + MenuItemID).className=DelightClasses[MenuItemID];
		HideElement('M' + MenuItemID);
		if (ParentItems[MenuItemID]) {
			ClearMenu(ParentItems[MenuItemID]);
		}
	}
}

function PositionRelative(ElementID, RelativeElementID1, RelativeElementID2, OffsetX, OffsetY) {
	if (document.getElementById(ElementID) && document.getElementById(RelativeElementID1)&& document.getElementById(RelativeElementID2)) {
		document.getElementById(ElementID).style.left = document.getElementById(RelativeElementID1).offsetLeft + document.getElementById(RelativeElementID2).offsetLeft + OffsetX;
		document.getElementById(ElementID).style.top = document.getElementById(RelativeElementID1).offsetTop + document.getElementById(RelativeElementID2).offsetTop + OffsetY;
	}
}

function ShowElement(ElementID) {
	if (document.getElementById(ElementID)) {
		document.getElementById(ElementID).style.visibility = 'visible';
	}
}

function HideElement(ElementID) {
	if (document.getElementById(ElementID)) {
		document.getElementById(ElementID).style.visibility = 'hidden';
	}
}

function MouseOnMenuOrChild(MenuItemID) {
	var ReturnValue = false;
	if (MouseOverItemID==MenuItemID) {
		ReturnValue = true;
	} else {
		if (ChildItems[MenuItemID]) {
			ReturnValue = MouseOnMenuOrChild(ChildItems[MenuItemID]);
		}
	}
	return ReturnValue;
}



// End drop-down menu code

//______________________________________________________________________
//______________________________________________________________________


// The following code is used to setting and getting cookies 
// (used for rotating images, sorting tables, etc.)

function getcookieval(offset)
{
	var endstr = document.cookie.indexOf(";",offset);
	if (endstr == -1)
		endstr = document.cookie.length;
	return unescape(document.cookie.substring(offset,endstr));
}

function getcookie(name)
{
	var arg = name + "=";
	var alen=arg.length;
	var clen=document.cookie.length;
	var i=0;
	while (i < clen)
		{
		var j=i + alen;
		if (document.cookie.substring(i,j)==arg)
			return getcookieval(j);
		i=document.cookie.indexOf(" ",i)+1;
		if (i==0) break;
		}
	return null;
}

function setcookie(name,value)
{
	var argv = setcookie.arguments;
	var argc = setcookie.arguments.length;
	var expires = (argc > 2) ? argv[2] : null;
	var path = (argc > 3) ? argv[3] : null;
	var domain=(argc > 4) ? argv[4] : null;
	var secure=(argc > 5) ? argv[5] : false;
	document.cookie=name+"="+escape(value)+((expires==null)?"":(";expires="+expires.togmtstring()))+((path==null) ? "":(";path="+path))+((domain==null)?"":(";domain="+domain))+((secure==true)?";secure" : "");
}


// End set cookie code

//______________________________________________________________________
//______________________________________________________________________

// The following code is for rotating images

rnd.today=new Date();
rnd.seed=rnd.today.getTime();

function rnd() {
        rnd.seed = (rnd.seed*9301+49297) % 233280;
        return rnd.seed/(233280.0);
};

function rand(number) {
        return Math.ceil(rnd()*number);
};

arrayImgs = new Array();
arrayUrls = new Array();
arrayAlts = new Array();
arrayTargets = new Array();

function addImg(ImageSrc,ImgUrl,ImgAlt,ImgTarget) {
arrayImgs[arrayImgs.length] = ImageSrc;
arrayUrls[arrayUrls.length] = ImgUrl;
arrayAlts[arrayAlts.length] = ImgAlt;
arrayTargets[arrayTargets.length] = ImgTarget;
}

function rotateImg(ID,width,height){
// All images need to be the same
//height and width.

	var tcookie = getcookie(ID);
	if (tcookie == null) {
		//----set cookie
		tcookie = rand(arrayImgs.length)
		setcookie(ID,tcookie,null,'/');
	}
	
	if (tcookie >= arrayImgs.length){
		setcookie(ID,1,null,'/');
	} else {
		setcookie(ID,parseInt(tcookie) + 1,null,'/');
	}
	if (arrayUrls[tcookie-1] != '') {
		document.write("<table width=" + width + " height=" + height + " cellpadding=0 cellspacing=0 border=0><tr><td background='" + arrayImgs[tcookie-1] + "'><a href=" + arrayUrls[tcookie-1] + " alt=" + arrayAlts[tcookie-1] + " target=" + arrayTargets[tcookie-1] + "><img src=/webinterface/images/spacer.gif border=0 height=" + height + " width=" + width + "></a></td></tr></table>");
	} else {
		document.write("<table width=" + width + " height=" + height + " cellpadding=0 cellspacing=0 border=0><tr><td background='" + arrayImgs[tcookie-1] + "'><img src=/webinterface/images/spacer.gif border=0 height=" + height + " width=" + width + "></td></tr></table>");
	}
	
}

// End rotate image code

//______________________________________________________________________
//______________________________________________________________________

// The following code is for sorting tables


function sorttable(columnname, direction) {
	setcookie('sort-column',columnname);
	setcookie('sort-direction',direction);
	document.location.href = document.location.href;
}

// End sorting table code

//______________________________________________________________________
//______________________________________________________________________

// The following code is for pop-up windows

function projectpop(URL) {
	window.open(URL,'ProjectPopUp','addressbar=yes,toolbar=yes,scrollbars=yes,width=750,height=450,resizable=yes');
}

function applicationpop(URL) {
	window.open(URL,'LoginPopUp','toolbar=yes,scrollbars=yes,width=650,height=400,resizable=yes');
}

function imagepop(URL, width, height) {
	var maxwindowheight = 570;
	var maxwindowwidth = 770;
	var windowwidth = width;
	var windowheight = height;
	var scrollbars = 'no';
	var scrollbarwidth = 16;
	if (height > maxwindowheight) {
		windowheight = maxwindowheight;
		windowwidth += scrollbarwidth;
		maxwindowwidth += scrollbarwidth;
		scrollbars = 'yes';		
	}
	if (width > maxwindowwidth) {
		windowwidth = maxwindowwidth;
		windowheight += scrollbarwidth;
		scrollbars = 'yes';		
	}
	window.open('/webinterface/popimage/index.htm?src=' + URL + '&width=' + width + '&height=' + height, '', 'addressbar=no,toolbar=no,scrollbars=' + scrollbars + ',width=' + windowwidth + ',height=' + windowheight);
}

function pagepop(URL, width, height) {
	var scrollbars = 'no';
	window.open(URL, '', 'addressbar=no,toolbar=no,scrollbars=' + scrollbars + ',width=' + width + ',height=' + height);
}


// End pop-up window code

//______________________________________________________________________
//______________________________________________________________________

// The following code is for printing

function printpage() {
	window.print();
}

// End printing code

//______________________________________________________________________
//______________________________________________________________________

// The following code is for disabling right clicks
function disablerightclick() {
	var message="";
	function clickIE() {if (document.all) {(message);return false;}}
	function clickNS(e) {if 
	(document.layers||(document.getElementById&&!document.all)) {
	if (e.which==2||e.which==3) {(message);return false;}}}
	if (document.layers) 
	{document.captureEvents(Event.MOUSEDOWN);document.onmousedown=clickNS;}
	else{document.onmouseup=clickNS;document.oncontextmenu=clickIE;}
	document.oncontextmenu=new Function("return false")
}

// End disable right click code
function todaysdate() {
       var today = new Date();
       var year = today.getYear();
       if(year<1000) year+=1900;
      document.write((today.getMonth()+1) + '/' + today.getDate() + '/' + (year+'').substring(2,4));
}


function ShowLayerAll(LayerID) {
document.getElementById(LayerID).style.display='block';
}

function HideLayerAll(LayerID) {
document.getElementById(LayerID).style.display='none';
}

function ShowLayerAll(LayerID) {
document.getElementById(LayerID).style.display='block';
}

function SwitchLayerAll(LayerID) {
	if (document.getElementById(LayerID).style.display!='none') {
		document.getElementById(LayerID).style.display='none';
	} else {
		document.getElementById(LayerID).style.display='block';
}
}

function SwitchImage(ImageID, Image1, Image2) {
	var prot_domain = document.getElementById(ImageID).src.split('://')[1].split('/')[0];
	if (document.getElementById(ImageID).src.split(prot_domain)[1].toLowerCase()==Image1.toLowerCase()) {
		document.getElementById(ImageID).src=Image2;
	} else {document.getElementById(ImageID).src=Image1;}
}

function GetQueryParam(ParamName){
  var regexS = '[\\?&]'+ParamName+'=([^&#]*)';
  var regex = new RegExp( regexS );
  var tmpURL = window.location.href;
  var results = regex.exec( tmpURL );
  if( results == null )
    return '';
  else
    return results[1];
	
}
