var cstWOFFSET = 30;
var cstHOFFSET = 30;
//----------------------------------------- Checks if browser is IE
function IsIE() {
	return (navigator.appName.indexOf("Microsoft") != -1) 
}
//----------------------------------------- Checks if browser is Netscape
function IsNetscape() {
	return (navigator.appName.indexOf("Netscape") != -1) 
}
//----------------------------------------- get the window width
function getWindowWidth(pWin) {
	if (IsIE()) {
		return pWin.document.body.clientWidth;
	} else if (IsNetscape()) {
		return pWin.outerWidth;
	}
}
//----------------------------------------- get the window height
function getWindowHeight(pWin) {
	if (IsIE()) {
		return pWin.document.body.clientHeight;
	} else if (IsNetscape()) {
		return pWin.outerHeight;
	}
}

//----------------------------------------- Open a new window and focus it
function OpenWindowOnFocus(strURL, strWinTarget, strWinFeatures) {

	var pWindow = window.top.open(strURL, strWinTarget, strWinFeatures);
	if (pWindow)
		pWindow.focus();
}
//----------------------------------------- Refresh the current window
function RefreshWindow() {
	window.top.history.go(0);
}
//----------------------------------------- Return default features if input feature is ""
function getPoppedUpWindowFeatures(strWindowFeature, pWindowBasedOn) {
	var strFeature; 
	
	if (strWindowFeature == "") {
		strFeature = DefaultWindowFeature(pWindowBasedOn);
	} else {
		strFeature = strWindowFeature;
	}
	return strFeature;
}	

//----------------------------------------- Return default window features
function DefaultWindowFeature(pWindow) {
	var	lWidth = getWindowWidth(pWindow);
	var lHeight = getWindowHeight(pWindow);
	var strFeature;
	var lLeft;
	var lTop;

	if (IsIE()) {
		// IE case
		lTop = pWindow.screenTop + cstHOFFSET;
		lLeft = pWindow.screenLeft + cstWOFFSET;
		strFeature = "left=" + lLeft + ",top=" + lTop + ",width=" + lWidth + 
					 ",height=" + lHeight + ",resizable,scrollbars,status=yes";
	} else 	{
		// Netscape case	
		lTop = pWindow.screenY + cstHOFFSET;
		lLeft = pWindow.screenX + cstWOFFSET;
		strFeature = "screenX=" + lLeft + ",screenY=" + lTop + ",outerWidth=" + lWidth + 
					 ",outerHeight=" + lHeight + ",resizable,scrollbars,status=yes";
	}
	return strFeature;
}

// This function checks for the existence of a function in the specified window. 
// It returns the window or frame where the function is defined. 
// If no requested function is found, it will return null.
function IsFuncWin(strFunc, pTargetWin) {
	if (pTargetWin) {
		// try the window itself first
		if (eval("pTargetWin." + strFunc) != null) 
		{
			return pTargetWin;
		}
		// if not found, look into the children frames
		for (i=0; i < pTargetWin.top.frames.length; i++) {
			if (eval("pTargetWin.top.frames[i]." + strFunc) != null) {
				return pTargetWin.top.frames[i];
			}
		}
	}
	return null;
}

/*
-------------------------------------------------------------------------------------------------
	event handler setup
-------------------------------------------------------------------------------------------------
*/
function addOnloadEvent(newFunction)
{
	if (typeof window.addEventListener != "undefined" ) {
		window.addEventListener( "load", newFunction, false );
	} else if (typeof window.attachEvent != "undefined") {
		window.attachEvent( "onload", newFunction );
	} else {
		if ( window.onload != null ) {
			var prevOnload = window.onload;
			window.onload = function ( e ) 
			{
					prevOnload( e );
					window[newFunction]();
			};
		} else {
			window.onload = newFunction;
		}
	}
}