/* 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, top, left) {
	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" }
	if (top) { top = "top=" + top; } else { top = "top=50"}
	if (left) { left = "left=" + left; } else { left = "left=50"}
	messagewindow = window.open(url, name, ""+w+","+h+","+s+",menubar=no,"+top+","+left+",resizable=yes");
	messagewindow.focus();
}

/**** findPosX()
Find the X position of any element with an ID.
*/
function findPosX(obj) {
	var curleft = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	} else if (obj.x) {
		curleft += obj.x;
	}
	return curleft;
}

/**** findPosY()
Find the Y position of any element with an ID.
*/
function findPosY(obj) {
	var curtop = 0;
	if (obj.offsetParent) {
		while (obj.offsetParent) {
			curtop += obj.offsetTop;
			obj = obj.offsetParent;
		}
	} else if (obj.y) {
		curtop += obj.y;
	}
	return curtop;
}

/* Targe 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;
	if(document.images) {
		if (status == 1) {
			document.images[imgName].src = "images/"+imgName+"_on.gif";
		}
		else {
			document.images[imgName].src = "images/"+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;
}

/*
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("/sendtoafriend.php?refURL="+pageURL+"&refPageTitle="+pageTitle, "Friend", "width=450,height=500,scrollbars=yes, menubar=no,top=50,left=50,resizable=yes");
}
