/* 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) {
	screenDim = screenXY();
	name = (name) ? name : 'pop' ;
	w = (w) ? w : 300 ;
	h = (h) ? h : 400 ;
	s = (s) ? s : 1 ;
	leftPos = ((screenDim[0] - w) / 2);
	topPos = ((screenDim[1] - h) / 2);
	popwin = window.open(url, name, "width="+w+", height="+h+",scrollbars="+s+",menubar=no,top="+topPos+",left="+leftPos+",resizable=yes");
	popwin.focus();
}

/* Detect Monitor Screen Dimensions */
function screenXY() {
	scr = new Array();
	scr[0] = screen.width;
	scr[1] = screen.height;
	return scr;
}

/* Target Opener:
Send location url to window.opener and closes the pop up. */
function targetOpener(url) {
	if (!window.opener) { 
		location.replace(url);
	} else {
		window.opener.location.replace(url);
		window.opener.focus();
		window.close(self);
	}
}

/* Swap Image.
image   = to be efficient, this is part of the actual graphic's filename, 
          minus the "_A" or "_B", AND part of the image's "name=" parameter
state   = either 0 (Off, default state) or 1 (On)
*/
function chgImg(image,state) {
	var imgName = image;
	var status  = state;
	var suffix 	= document.images[imgName].src.substr(document.images[imgName].src.length-3);
	if(document.images) {
		if (status == 1) {
			document.images[imgName].src = "/images/"+imgName+"_hi."+suffix;
		}
		else {
			document.images[imgName].src = "/images/"+imgName+"_off."+suffix;
		}
	}
}

/* Swap specific to Expo map */
function chgMapImg(image,state) {
	var imgName = image;
	var status  = state;
	if(document.images) {
		if (status == 1) {
			document.images[imgName].src = "/UPLOADS/sfs_expographics/"+imgName+"_on.gif";
		}
		else {
			document.images[imgName].src = "/UPLOADS/sfs_expographics/"+imgName+"_off.gif";
		}
	}
}

/* Swap Table Cell background color. 
IE5+ and NS6+ only. Ignored in older browsers. */
function chgBG(cellID,bgColor) {
	var cell     = cellID;
	var newColor = bgColor;
	if ((document.getElementById) || (document.getElementById && !document.all)) {
		document.getElementById(cell).style.background = newColor;
	}
}

/* Swap a font's color inside an Object */
function chgFontColor(cellID,fontColor) {
	cell     = cellID;
	newColor = fontColor;
	if ((document.getElementById) || (document.getElementById && !document.all)) {
		document.getElementById(cell).style.color = newColor;
	}
}

/*
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;
	window.open(destLoc, "print", "width=800,height=600,scrollbars=yes, menubar=yes,top=50,left=50,resizable=yes");
}

/*
E-mail to Colleague handler. Single argument: the 'pageTitle' variable in
URL encoded form.
*/
function emailColleague(Title) {
	var pageURL   = window.location.href;
	var pageTitle = Title;
	window.open("/colleague.asp?refURL="+pageURL+"&refPageTitle="+pageTitle, "Email_Colleague", "width=410,height=460,scrollbars=yes, menubar=no,top=50,left=50,resizable=yes");
}

