// creates a trim prototype on the String object
// returns string with leading and trailing spaces removed
// call as strString.trim();
String.prototype.trim = function() {
return this.replace(/^\s*/,"").replace(/\s*$/,"")
}

// global variable for popup windows
var popWin;

// popup windows
function popupWin(strURL,strName,strType,strWidth,strHeight) {
	var strOptions = "";
	if ( strType == "console" ) strOptions = "toolbar=no,scrollbars=no,status=no,width="+strWidth+",height="+strHeight;
	if ( strType == "fixed" ) strOptions = "status,width="+strWidth+",height="+strHeight;
	if ( strType == "resizable" ) strOptions = "status,scrollbars,resizable,width="+strWidth+",height="+strHeight;
	popWin = window.open(strURL,strName,strOptions);
	if ( window.focus ) popWin.focus();	
}

// newsletter form submission to new window
function doNewsletterSignup(strWin,strWidth,strHeight) {
	if ( popWin != null ) {
		if ( !popWin.closed ) popWin.close();
	}
	popWin = window.open("",strWin,"width="+strWidth+",height="+strHeight+",resizable=yes,status=yes,scrollbars=yes");
	if ( popWin.opener == null ) popWin.opener = window;
	popWin.focus();
}


// validate a form with name and email boxes
function ValidateNameEmail(theform) {
	if ( isLegal(theform.name.value.trim(),true) == false ) {
		alert("Please use only letters and numbers for your Name.");
		theform.name.focus();
		return false;
	}
	if ( isValidEmail(theform.email.value.trim()) == false ) {
		alert("Please provide a valid Email address.");
		theform.email.focus();
		return false;
	}
return true;
}

// print the page
function printPage() {
	if ( window.print ) window.print();
	else alert("To print this page please click on the File menu and select Print.");
}

// internal functions called by exposed functions
function isValidEmail(strEmail) {

	if ( strEmail == null || strEmail == "" ) return false;
	if ( strEmail.search(/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/) != -1 )
		return true;
	else
		return false;
}
function isLegal(strText, blRequired) {

	if ( blRequired == true ) {
		if ( strText == null || strText == "" ) return false;
	}
	var invalids = "\!\[\]\{\}\+#$\%\^\*()~,\'<>/?;:\|"
	for(i=0; i<invalids.length; i++) {
		if(strText.indexOf(invalids.charAt(i)) >= 0 ) {
			return false;
		}
	}
return true;
}

