<!--
/*-------------------------------------------------------------
  Copywright March 2010 - Bruno Torrinha (www.torrinha.com)
-------------------------------------------------------------*/



function open_window(url, nxX, nyY) {
	var x = 0;
	var y = 0;
	x = (screen.width / 2) - (nxX / 2);
	y = (screen.height /2) - (nyY / 2);
	window.open(url,"popWnd",'top='+y+',left='+x+',width='+ nxX +',height='+ nyY +',menubar=no,toolbar=no,resizable=1,status=no,scrollbars=no');
}



//***************************
//****  Form Handle  ********
//***************************
window.onload = attachFormHandlers;

function attachFormHandlers() {
	// Ensure we're working with a 'relatively' standards 
	// compliant browser
	if (document.getElementsByTagName) {
		var objForm = document.getElementsByTagName('form');
		for (var iCounter=0; iCounter<objForm.length; iCounter++)
		objForm[iCounter].onsubmit = function(){return checkForm(this);}
	}
}


function checkForm(objForm) {
var arClass, bValid;
var objField = objForm.getElementsByTagName('*');

for (var iFieldCounter=0; iFieldCounter<objField.length; iFieldCounter++) {
	// Allow for multiple values being assigned to the class attribute
	arClass = objField[iFieldCounter].className.split(' ');
	for (var iClassCounter=0; iClassCounter<arClass.length; iClassCounter++) {
		switch (arClass[iClassCounter]) {
		case 'string':
			bValid = isString(objField[iFieldCounter].value.replace(/^\s*|\s*$/g, ''));
			break;
		case 'number' :
			bValid = isNumber(objField[iFieldCounter].value);
			break;
		case 'email' :
			bValid = isEmail(objField[iFieldCounter].value);
			break;
		default:
			bValid = true;
		}
		if (bValid == false) {
			// If this field is invalid, leave the testing early,
			// and alert the visitor to this error
			alert('Please review the value you provided for ' + objField[iFieldCounter].name);
			objField[iFieldCounter].select();
			objField[iFieldCounter].focus();
			return false;
		}
    }
  }
  return true;
}

function isString(strValue) {
	return (typeof strValue == 'string' && strValue != '' && isNaN(strValue));
}

function isNumber(strValue) {
	return (!isNaN(strValue) && strValue != '');
}

function isEmail(strValue) {
	var objRE = /^[\w-\.\']{1,}\@([\da-zA-Z-]{1,}\.){1,}[\da-zA-Z-]{2,}$/;
	return (strValue != '' && objRE.test(strValue));
}
//-->
