//////////////////////////////////////////////////////////////////////////////////////////
// OBJECT window
//	.getQueryStringMap()	-	Returns a array map of query string name value pairs
//	.getHeight()			-	Return window size
//	.getWidth()
//	.openCentered(url, w, h)			- Opens url in a centered window (w x h) with all features off
//	.openCenteredScrollable(url, w, h)	- Same as above but scrolling is enabled
//	.refresh(hardReload=true)			- Reloads the page with or without cache...
//	.setError(msg)						- if msg is not given then errors are ignored, else msg is disp in an alert
/////////////////////////////////////////////////////////////////////////////////////////////////
window.getQueryStringMap = function () {
	var query = this.location.search.substring(1);
	var vars = query.split("&");
	var queryMap = new Array();

	for (var i=0; i<vars.length; i++) {
		var pair = vars[i].split("=");
		queryMap[pair[0]] = pair[1];
	} 
	return queryMap;
}

window.openCentered = function (url, w, h) {
	var left = Math.floor((screen.width - w) / 2);
	var top  = Math.floor((screen.height - h) / 2);	
	return this.open(url, '', "width="+w+",height="+h+",top="+top+",left="+left);	
}
window.openCenteredScrollable = function (url, w, h) {
	var left = Math.floor((screen.width - w) / 2);
	var top  = Math.floor((screen.height - h) / 2);
	return this.open(url, '', "width="+w+",height="+h+",top="+top+",left="+left+",scrollbars=yes"+",resizable=1, status=1");	
}

/********************************************************************
* Display image popup.  Window opens with 5% of screen indent left/top
********************************************************************/
window.openImage = function (imgUrl, w, h, desc) {
	var htmlFrame  = '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">';
	 htmlFrame += '<html><head><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">';
	 htmlFrame += '<title>'+desc+'</title></head>';
	 htmlFrame += '<body style="margin: 0px" marginheight="0" marginwidth="0" topmargin="0" bottommargin="0" leftmargin="0" rightmargin="0">';
	 htmlFrame += '<img border="0" style="margin: 0px"; src="'+imgUrl+'" height="'+h+'" width="'+w+'" alt="'+desc+'">';
	 htmlFrame += '</body></html>';

	var left = Math.floor(screen.width *.05);	//indent window 5% of screen
	var top  = Math.floor(screen.height *.05);	
	newWin = this.open('','' , "width="+(w)+",height="+(h)+",top="+top+",left="+left);	
	newWin.document.write(htmlFrame);
	newWin.document.close();
}
window.getHeight = function () {
	var myWidth = 0, myHeight = 0;
	if( typeof( this.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = this.innerWidth;
	myHeight = this.innerHeight;
	} else if( document.documentElement &&
	  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	return myHeight;
}
window.getWidth = function () {
	var myWidth = 0, myHeight = 0;
	if( typeof( this.innerWidth ) == 'number' ) {
	//Non-IE
	myWidth = this.innerWidth;
	myHeight = this.innerHeight;
	} else if( document.documentElement &&
	  ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
	//IE 6+ in 'standards compliant mode'
	myWidth = document.documentElement.clientWidth;
	myHeight = document.documentElement.clientHeight;
	} else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
	//IE 4 compatible
	myWidth = document.body.clientWidth;
	myHeight = document.body.clientHeight;
	}
	
	return myWidth;
}

/////
// Refreshes page
// I: hardReload (bool)	- Defaults to true for Firefox
// O: None
window.refresh = function (hardReload) {
	hardReload = ((typeof(hardReload) == 'undefined') ?	true : hardReload);	//default to true

	// Reload depending on options
	if (hardReload)
		this.location.reload(true);					// performs a non-cached reload
	else {
		var tmp = this.location.href + this.location.search; 
		this.location.href = tmp;
	}
}
/********************************************************************
* Set error handling to ignore error or display alert
* i: msg - If not given then then errors are ignored.  If specified
*		   then an alert is given with this message
* o: Alert or nothing
********************************************************************/
window.setError = function (msg) {
	if (msg)
		window.onerror = function () {
			alert(msg);
			return true;
		}
	else
		window.onerror = function () {	return true;	}
}

