// creates a trim prototype on the String object
// returns string with leading and trailing spaces removed
// call as string.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();	
}

// form submission to new popup window
function popupSignup(strWin,strWidth,strHeight) {
	if (popWin != null){if(!popWin.closed) popWin.close();}
	popWin = window.open('',strWin,'width='+strWidth+',height='+strHeight+',toolbar=0,location=0,resizable=1,status=1,scrollbars=1');
	if (popWin.opener == null) popWin.opener = window;
	popWin.focus();
}

// contact form
function validateForm(f) {

	if ( f.fullname.value.trim() == '' ) {
		alert("Please provide your Name.");
		f.fullname.focus();
		return false;
	}
	if ( isEmail(f.email.value) == false ) {
		alert("Please provide a valid Email Address.");
		f.email.focus();
		return false;
	}
return true;
}

// internal functions
function isEmail(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;
}

