// Common.js includes reusable functions for any website.
var theWindow="";	//Used in the various popXXX functions

function popWindow(page, widthPx, heightPx, topPx, leftPx, showScrollbars) {
// Allow the URL to be passed either as "page" or "page.ext".	
// This allows the URL to include a QueryString.
	var ASP_EXT = ".asp";
	var i = page.indexOf(ASP_EXT);
	var url, sName; 
	if (i > -1) {
		url = page;
		sName = page.substr(0, i - 1);
	}
	else {
		url = page + ASP_EXT;
		sName = page;
	}

// Close existing instance of the window.
	if (theWindow && !theWindow.closed) {
		theWindow.close();
	}
	var options = "width=" + widthPx + ",height=" + heightPx + ",top=" + topPx + ",left=" + leftPx + ",scrollbars=" + showScrollbars + ",resizable=no,toolbar=no,location=no,menubar=no,status=no";	
	theWindow = window.open (url, sName, options);
	theWindow.focus();
}

function popShot(sURL, widthPx, heightPx) {
	var topPx = "10";
	var leftPx = "10"; 
	var showScrollbars = "yes";
	var options;
	
	widthPx = 700;
	heightPx = 500;

	options = "width=" + widthPx + ",height=" + heightPx + ",top=" + topPx + ",left=" + leftPx + ",scrollbars=" + showScrollbars + ",resizable=yes,toolbar=no,location=no,menubar=no,status=no";

	if (theWindow  && !theWindow.closed) {
		theWindow.close();
	}
	theWindow = window.open (sURL, "shot",options);
	theWindow.focus();
}

function popBio(sAuth) {
	var url = '/bio.asp?auth=' + sAuth;
	
	var widthPx = "400";
	var heightPx = "250";
	var topPx = "10";
	var leftPx = "10"; 
	var showScrollbars = "yes";
	var options = "width=" + widthPx + ",height=" + heightPx + ",top=" + topPx + ",left=" + leftPx + ",scrollbars=" + showScrollbars + ",resizable=no,toolbar=no,location=no,menubar=no,status=no";

// Close existing instance of the window.
	if (theWindow && !theWindow.closed) {
		theWindow.close();
	}
	theWindow = window.open (url, "bio",options);
	theWindow.focus();
}

function popSignup(iErrorCode) {
	var url = '/signuppopup.asp?Error=' + iErrorCode;
	var widthPx = "400";
	var heightPx = "300";
	var topPx = "50";
	var leftPx = "50"; 
	var showScrollbars = "yes";
	var options = "width=" + widthPx + ",height=" + heightPx + ",top=" + topPx + ",left=" + leftPx + ",scrollbars=" + showScrollbars + ",resizable=no,toolbar=no,location=no,menubar=no,status=no";

// Close existing instance of the window.
	if (theWindow && !theWindow.closed) {
		theWindow.close();
	}
	theWindow = window.open (url, "signup",options);
	theWindow.focus();
}
		
function navWindow(sURL) {
// Navigate to the passed URL.  Netscape doesn't like open() or navigate() methods.
	window.location.href = sURL;
}
function GetTH(eSrc) {
// Return the TH element.
	if (typeof(eSrc) == "undefined") eSrc = window.event.srcElement;

	while (eSrc.tagName != "TH")
		eSrc = eSrc.parentElement;

	return eSrc;
}
function GetTD(eSrc) {
// Return the TD element.
	if (typeof(eSrc) == "undefined") eSrc = window.event.srcElement;

	while (eSrc.tagName != "TD")
		eSrc = eSrc.parentElement;

	return eSrc;
}
function GetTR(eSrc) {
// Return the TR element.
	if (typeof(eSrc) == "undefined") eSrc = window.event.srcElement;

	while (eSrc.tagName != "TR")
		eSrc = eSrc.parentElement;

	return eSrc;
}
function GetTABLE(eSrc) {
// Return the TABLE element.
	if (typeof(eSrc) == "undefined") eSrc = window.event.srcElement;

	while (eSrc.tagName != "TABLE")
		eSrc = eSrc.parentElement;

	return eSrc;
}
function IsBrowserIE() {
// Return true/false if Browser is IE or not.
	//alert(window.navigator.appName);
	if (window.navigator.appName.indexOf("Microsoft") > -1) 
		return(true);
	else
		return(false);	
}

function Trim(str) {
	var retVal = "";
	var start = 0;

	while ((start < str.length) && (str.charAt(start) == ' ')) {
	  ++start;
	}
	var end = str.length;
	if (start==end) {
		retVal = "";}
	else {
		while ((end > 0) && (str.charAt(end - 1) == ' ')) {
		  --end;
		}
		retVal = str.substring(start, end);
	}
	return retVal;
}
function CancelEvent() {
// Cancel an event we don't want to bubble up.
//	window.event.returnValue = false;
	window.event.cancelBubble = true;
}
function HasIllegalChar(sValue) {
// Determine if the passed string has illegal characters.
	var i = sValue.search(/[<>'"]/gi);
	
	return(i > -1 ? true : false);
}
