//Menu Controls
function GetChild(item, nodeName)
{
	var child = item.childNodes[0];
	while(child.nodeName != nodeName)
	{
		child = child.nextSibling;
	}

	return child;
}

function ShowMenu(item)
{
	var child = GetChild(item, 'UL');
	child.style.display = 'block';

	//Style information
	item.style.background = 'url(images/highlight_nav.gif)';
	item.style.borderLeft = '1px solid #000';
	item.style.borderRight = '1px solid #000';
	item.style.paddingRight = '9px'
	item.style.paddingLeft = '9px'
}

function HideMenu(item)
{
	var child = GetChild(item, 'UL');
	child.style.display = 'none';
	
	//Style Information
	item.style.background = 'none';
	item.style.borderLeft = '0px';
	item.style.borderRight = '0px';
	item.style.paddingRight = '10px'
	item.style.paddingLeft = '10px'
}

// Start of the AJAX session updater
var xmlhttp;
var timerObj;

function FillHttpObject()
{ 
	try
	{
		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch(e)
	{
		try
		{
			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(e)
		{
			xmlhttp = false;
		}
	}

	if(!xmlhttp && typeof XMLHttpRequest != 'undefined')
	{
		try
		{
			xmlhttp = new XMLHttpRequest();
		}
		catch(e)
		{
			xmlhttp = false;
		}
	}
};

function LoadXMLDoc(url)
{
	FillHttpObject();
	
	if(xmlhttp)	
	{
		xmlhttp.onreadystatechange = BuildXMLResults;
		xmlhttp.open("GET", url, true);
		xmlhttp.send(null);
	}
}

function BuildXMLResults()
{
	if(xmlhttp.readyState == 4)
	{
		if(xmlhttp.status == 200)
		{
			if(xmlhttp.responseText.indexOf("Session Updated") == 0)
				SetTimer();
			else
				alert("Your session has expired.");
		}
	}
}

function ConfirmUpdate()
{
	if(confirm("Your session is about to expire. Press 'OK' to renew your session."))
		LoadXMLDoc('sessionUpdater.aspx');
}     

function SetTimer()
{
	timerObj = setTimeout("ConfirmUpdate()", 58 * 60 * 1000);
}

SetTimer();
// End of the AJAX session updater


//Playing with a highlighting system for help
var CurBorder;
var CurBackground;
var CurBackgroundImage;
var CurForeColor;
function HighLightBox(TextBoxID)
{
    var TextBox = document.getElementById(TextBoxID);
    CurBorder = TextBox.style.borderColor; 
    CurBackground = TextBox.style.backgroundColor;
    CurBackgroundImage = TextBox.style.backgroundImage;
    CurForeColor = TextBox.style.color;
    TextBox.style.borderColor = '#152D45';
    TextBox.style.backgroundColor = '#009AFF';
    TextBox.style.color = '#FFFFFF';
    TextBox.style.backgroundImage = 'none';
    return false;
}

function UnHighLightBox(TextBoxID)
{
    var TextBox = document.getElementById(TextBoxID);
    TextBox.style.borderColor = CurBorder;
    TextBox.style.backgroundColor = CurBackground;
    TextBox.style.backgroundImage = CurBackgroundImage;
    TextBox.style.color = CurForeColor;
    return false;
}

window.onload = function()
{
	var oLoadingDIV = document.getElementById('divLoading');
	if(oLoadingDIV != null)
	{
		oLoadingDIV.style.visibility = "hidden";
		oLoadingDIV.style.display = "none";
	}
		
	var oLoadingIFrame = document.getElementById('col_main');
	if(oLoadingIFrame != null)
	{
		oLoadingIFrame.style.visibility = "visible";
		oLoadingIFrame.style.display = "block";
	}

    if(window.ScrollMeAgain)
    {
	    ScrollMeAgain();
	}
	
	if(window.FocusOnItem)
	{
	    FocusOnItem();
	}
}

function LoadingAgain()
{
	var oLoadingDIV = document.getElementById('divLoading');
	if(oLoadingDIV != null)
	{
		oLoadingDIV.style.visibility = "visible";
		oLoadingDIV.style.display = "block";
	}
		
	var oLoadingIFrame = document.getElementById('col_main');
	if(oLoadingIFrame != null)
	{
		oLoadingIFrame.style.visibility = "hidden";
		oLoadingIFrame.style.display = "none";
	}
	
	return true;
}

function trim (str) {
    str = this != window? this : str;
    return str.replace(/^\s+/, '').replace(/\s+$/, '');
}

//Used to open a new window for data exports
var win= null;
function NewWindow(mypage, myname, w, h, scroll)
{
	var winl = (screen.width-w) / 2;
	var wint = (screen.height - h) / 2;
	var settings = 'height = ' + h + ',';
	settings += 'width = ' + w + ',';
	settings += 'top = ' + wint + ',';
	settings += 'left = ' + winl + ',';
	settings += 'scrollbars = ' + scroll + ',';
	settings += 'resizable=yes';
	win = window.open(mypage, myname, settings);
	if(parseInt(navigator.appVersion) >= 4)
		win.window.focus();
} 

//Used in Footer...
function openFeedbackWindow() 
{
	NewWindow('Feedback.aspx', '', 326, 230, 'no');
	return false;
}

function ShowChatPopup(url)
{
	if(url.indexOf('?env=') == -1)
		return;

	var w = 645;
	var h = 485;
	var winl = (screen.width - w) / 2;
	var wint = (screen.height - h) / 2;
	var settings = 'top = '
		+ wint
		+ ', left = '
		+ winl
		+ ', width = '
		+ w
		+ ', height = '
		+ h
		+ ', scrollbars = no, statusbar = no, resizable = no';
	win = window.open(url, '', settings);
	if(parseInt(navigator.appVersion) >= 4)
		win.window.focus();
}