/*
Please use this JavaScript code for meetings with registration fees.
*/
function checkElem(elem, msg)	{
	if ((elem.value == "") || (elem.value.length == 0))	{
		alert("Please fill in the '" + msg + "' field."); elem.focus(); return false;
	}
	if (!checkBadSmb(elem, msg))	{ return false;	}
return true;
}

function IsNumeric(sText) {
	var ValidChars = "0123456789";
	var IsNumber=true;
	var Char;

	for (i = 0; i < sText.length && IsNumber == true; i++)
		{
		Char = sText.charAt(i);
		if (ValidChars.indexOf(Char) == -1)
		{
		IsNumber = false;
		}
	}
return IsNumber;
}

function checkNumeric(elem, msg)	{
	if (!IsNumeric(elem.value))
		{
		alert("Please fill in the '" + msg + "' field with no spaces, dashes, etc.")
		elem.focus();
	return false;
	}
return true;
}

function checkBadSmb(elem, msg)	{
	var regexp = /(\s{2,})|(\|)|(\?)|(\:)|(\*)|(\_)|(\@)|(\!)|(\^)|(\<)|(\>)|(\+)|(\%)|(\;)/g
		if (regexp.test(elem.value))	{ alert("Bad symbols or too many whitespaces are in the " + msg + " field!"); 				elem.focus(); return false; }
		if (elem.value.indexOf('"') != -1)	{
		for (var i=0; i < elem.value.length; i++)	{ elem.value = elem.value.replace('"',"'"); }
	}
return true;
}

function copyFlash(aaa)	{
	with (aaa)	{
		if (flag.checked)	{
			accountholdername.value = firstname.value+" "+lastname.value;
			statementaddress.value = streetaddress.value;
			statementcity.value = city.value;
			statementstate.selectedIndex = document.forms[0].state.selectedIndex;
			statementcountry.selectedIndex = document.forms[0].country.selectedIndex;
			statementzip.value = zip.value;
		}
		else{
			accountholdername.value = "";
			statementaddress.value = "";
			statementcity.value = "";
			statementstate.selectedIndex = 0;
			statementcountry.selectedIndex = 0;
			statementzip.value = "";
		}
	}
}

function checkEmail(elem) {
	var regex = /^([\w\-\.]+)@((\[([0-9]{1,3}\.){3}[0-9]{1,3}\])|(([\w\-]+\.)+)([a-zA-Z]{2,4}))$/
	if (elem.value.length < 6)	{ alert("Please enter your E-mail Address.");elem.focus(); return false; }
	if (!regex.test(elem.value))	{ alert("You have entered a bad format of E-mail Address. Please re-enter it.");		elem.focus(); return false; }
return true;
}

function checkSelect(elem, msg)	{
	if (elem.selectedIndex == 0) { alert(msg);  elem.focus(); return false; }
return true;
}



function checkOther(elem1, elem2, msg)	{
	if ( (elem1.selectedIndex == 6) && (elem2.value == "") ) { alert(msg);  elem2.focus(); return false; }
return true;
}

function checkRadio(elem, num, msg)	{
	var er = 1;
	for (var i = 0; i < num; i++)	{ if (elem[i].checked) { er = 0; } }
	if (er == 1)  {alert(msg); elem[0].focus(); return false; }
return true;
}

function checkRadText(elem1,elem2,msg)	{	
	if (elem1.checked) { 	
		if (elem2.value == "") 	{ alert(msg); elem2.focus(); return false; }
	}	
	return true;
}

function checkState(elem1, elem2)	{
	if ((elem1.selectedIndex == 1) && (elem2.selectedIndex == 0 || elem2.selectedIndex > 52)) {
		alert("If you selected USA, please select the \"State\".");
		elem2.focus();	return false;	}
	if ((elem1.selectedIndex == 41) && (elem2.selectedIndex < 53)) {
		alert("If you selected CANADA, please select the \"Province\".");
		elem2.focus();	return false;	}
return true;
}

function checkForm(aaa)	{
//Form Validation
	if (!checkElem(aaa.firstname,"First Name"))	{return false}
	if (!checkElem(aaa.lastname,"Last Name"))	{return false}
	if (!checkElem(aaa.degree,"Degree"))	{return false}
	if (!checkElem(aaa.streetaddress,"Street Address"))	{return false}
	if (!checkElem(aaa.city,"City"))	{return false}
	/*if (!checkSelect(aaa.state,"Please select your state."))	{return false}*/
	if (!checkState(aaa.country, aaa.state)) { return false; }
	if (!checkElem(aaa.zip,"Postal Code"))	{return false}
	if (!checkSelect(aaa.country,"Please select your country"))	{return false}
	if (!checkElem(aaa.phone,"Phone"))	{return false}
	if (!checkNumeric(aaa.phone,"Phone"))	{return false}
	if (!checkEmail(aaa.email)) {return false}
	if (!checkRadio(aaa.practice,2, "Please select your primary practice operation")) { return false; }	
	if (!checkRadio(aaa.mktgSource,10, " How did you hear about the meeting?")) { return false; }	
	if (!checkRadio(aaa.regtype,9, "Please select your Registration Type."))	{return false}	
	if (!checkElem(aaa.accountholdername, "Name of the Accountholder"))	{return false}
	if (!checkElem(aaa.statementaddress, "Statement Mailing Address"))	{return false}
	if (!checkElem(aaa.statementcity, "City"))	{return false}
	if (!checkState(aaa.statementcountry, aaa.statementstate))	{ return false; }
	if (!checkElem(aaa.statementzip," Postal code"))	{return false}
return true;
}

