// Collection of js functions responsible for form details validation

// Hide all error divs
function aHideErrDivs(fCheck){
	document.all["eRRError"].style.display = "none";
	document.all["eRREmail"].style.display = "none";
	for (var i = 0;i < fCheck.length;i++){
		eval('document.all["eRR' + fCheck[i] + '"]').style.display = "none";
		}
	}

// Validate Fields
function aFieldValidate(fCheck)	{
	var bReturn = true;
	for (var i = 0;i < fCheck.length;i++) {
		if (eval('document.frmEmail.f' + fCheck[i]).value == "") { 
			eval('document.all["eRR' + fCheck[i] + '"]').style.display=""; 
			bReturn = false;
			}
		}
	return bReturn;
	}

// Validate email
function aEmailValidate()
	{
	var bReturn = true;

	var re;
//	re = /^[a-z\d]{1,10}[\_|\.]?[a-z\d]{1,10}[\@][a-z\d]{1,10}/i;
	re = /^[\w\.]+@\w+(\.\w+)+$/i;
	if (!re.test(document.frmEmail.fEmail.value)) 
		bReturn = false;

	if (bReturn == false)
		document.all["eRREmail"].style.display = ""; 

	return bReturn;

}

function bCheck() {
	var fCheck = new Array();
	var bReturn = true;		
	// must fields
	fCheck[0] = "Name";
	fCheck[1] = "Phone";
	
	// Hide all error divs
	aHideErrDivs(fCheck);

	// Validate Fields
	if (aFieldValidate(fCheck) == false) {
		bReturn = false;
		}

	// Validate email
	if (aEmailValidate() == false) {
		bReturn = false;
		}

	if (bReturn == true) { 
		document.frmEmail.submit(); 
		}
	else { 
		document.all["eRRError"].style.display = ""; 
		document.location = "#form" 
		}
	}
