/* General Open Window Function... 
Arguments: url, name, width (int), height (int), scrollbars (boolean 0 or 1)--
width, height, and scrollbars values are optional.*/
function openWin(url, name, w, h, s) {
	if (w) { w = "width=" + w; } else { w = "width=300" }
	if (h) { h = "height=" + h; } else { h = "height=400"}
	if (s) { s = "scrollbars=" + s } else { s = "scrollbars=0" }
	messagewindow = window.open(url, name, ""+w+","+h+","+s+",menubar=no,top=50,left=50,resizable=yes");
	messagewindow.focus();
}
	
/* Preload any images (navigation, mouseovers, layers, etc.) */
var imgAr = new Array(
	"images/button_genReport_On.gif",
	"images/button_exportData_On.gif",
	"images/button_printPage_On.gif",
	"images/arrow_On.gif"
);

if (document.images) {
	var imgs = new Array();
	for (var i=0; i<imgAr.length; i++) {
  	imgs[i] = new Image(); 
		imgs[i].src = imgAr[i];
  }
}

/* a general swap image function.
Takes 2 arguments: image, state
imageName= to be efficient, this is part of the actual graphic's filename, 
           minus the "_Off" or "_On", AND part of the image's "name=" parameter
state    = either 0 (On) or 1 (Off, default state) */
function chgImg(imageName,state) {
	state = (state==1)?"_On":"_Off";
	if(document.images) {
		if (state=="_On") {
			document.images[imageName].src = "images/"+imageName+"_On.gif";
		}
		else {
			document.images[imageName].src = "images/"+imageName+"_Off.gif";
		}
	}
}

/* Print Page handler. No arguments. */
function printPage() {
	var destLoc
	var pageURL    = window.location.href;
	var pageQStr   = window.location.search;
	var strPrintIt = "PrintIt=1";
	
	/* remove any anchors from the URL -- this confuses the ASP that handles
	hiding page elements. */
	if (pageURL.indexOf("#")) {
		pageURLArray = (pageURL.split("#"));
		pageURL = pageURLArray[0];
	}
	
	/* Create the printable URL and send to browser */
	if ((pageQStr.length!="") || (pageQStr.length!=0)) {
		destLoc = pageURL + "&" + strPrintIt;
	} else {
		destLoc = pageURL + "?" + strPrintIt;
	}
	window.location.href = destLoc;
}

/* The actual Print page function, which opens the Print dialog box where possible. */
function prePrint()
{
	if (window.print) {
		window.print();
	}
}