
function kp_numbers() {
    if ((event.keyCode != 46) && (event.keyCode < 48 || event.keyCode > 57))
        event.returnValue = false;
    if (event.keyCode == 46) {
        if (event.srcElement.value.indexOf(".") > -1)
            event.returnValue = false;
    }
    if (event.keyCode == 47 || event.keyCode == 92) {
            event.returnValue = true;
    }
    if (event.keyCode == 13) {
            event.returnValue = true;
    }

}

function validateMemberForm()
{
	if(document.all("Read_Guidelines").checked==false)
	{
		showMsgSetFocus("Read_Guidelines", "Please review the Ajax Scuba Club Member Guildelines and check the box when you are done.");
		return(false);
	}
	
	if(testField("FirstName", "Invalid First Name")==false)
		return(false);

	if(testField("LastName", "Invalid Last Name")==false)
		return(false);
	
	if(testField("HomeStreet", "Invalid Address")==false)
		return(false);
	
	if(testField("HomeCity", "Invalid City")==false)
		return(false);
	
	if(testField("HomePostalCode", "Invalid Postal Code")==false)
		return(false);
	
	if(document.all("HomeCountry").value=="Canada")
		if(testPostalCode("HomePostalCode")==false)
		{
			showMsgSetFocus("HomePostalCode", "Invalid Postal Code");
			return(false);
		}
		
	if(testField("HomeProvinceState", "Invalid Province or State")==false)
		return(false);
	
	if(testField("HomeCountry", "Invalid Country")==false)
		return(false);
	
	/*
	if(testField("Security_Question", "Invalid Security Question, cannot be blank")==false)
		return(false);
	
	if(testField("Security_Answer", "Invalid Security Answer, cannot be blank")==false)
		return(false);
	*/
	
	if(testField("EMGContact", "Invalid Emergency Contact")==false)
		return(false);
	
	if(testPhoneField("EMGPhone1")==false)
		return(false);
	
	if(document.all("EMGContact2").value!="")
		if(testPhoneField("EMGPhone3")==false)
			return(false);
	
	//if(testField("EMGContact2", "Invalid Emergency Contact.\n\nWe require at least two emergency contact names.")==false)
	//	return(false);
	
	return(true);
}

function testPhoneField(ID)
{
/*
alert(document.all("Phone_Area_" + ID).value.length);
*/
	if(testField("Phone_Area_" + ID, "Invalid Area Code", 3)==false)
		return(false);
	
	if(testField("Phone_Route_" + ID, "Invalid telephone number", 3)==false)
		return(false);
	
	if(testField("Phone_Identifier_" + ID, "Invalid telephone number", 4)==false)
		return(false);

	return(true);
}

function testField(ID, Msg, Length)
{   if (testField.arguments.length == 2) Length = 0;
	if(ID!="") 
	{
	var str;
		if(document.all(ID).tagName=="TEXTAREA")
			str = document.all(ID).innerText;
		else
			str = document.all(ID).value;

		if(str.length==0)
		{
			showMsgSetFocus(ID, Msg);
			return(false);
		}
	
		if(Length > 0)
			if(str.length != Length)
			{
				showMsgSetFocus(ID, Msg);
				return(false);
			}
	}
	return(true);
}

function showMsgSetFocus(ID, Msg)
{
	alert(Msg);
	document.all(ID).focus();
	document.all(ID).select();
	return(true);
}

function testPostalCode(ID)
{
var i;
	if(ID!="") 
	{
		var str = document.all(ID).value;
		str = str.replace(" ", "");
		if(str.length<6)
			return(false);

		for(i=0;i<str.length;i++)
		{
			switch(i)
			{
			case 1:
			case 3:
			case 5:
				if(isDigit(str.substr(i, 1)) == false)
					return(false);
				break;
			case 2:
			case 4:
			case 6:
				if(isLetter(str.substr(i, 1)) == false)
					return(false);
				break;
			default:
				break;
			}
		}
	}
	return(true);
}

function validateEventsForm()
{
	if(testField("NAME", "Invalid Event Title")==false)
		return(false);
	
	if(testField("CONTACT_NAME", "Invalid Contact Name")==false)
		return(false);
	
	if(testPhoneField("CONTACT_PHONE")==false)
		return(false);

	if(checkEmail(document.all("CONTACT_EMAIL"), true)==false)
		return(false);
}

function validateNewPasswordForm()
{
	if(testField("OldPassword", "Invalid Old Password")==false)
		return(false);
	
	if(testField("NewPassword", "Invalid New Password")==false)
		return(false);
}

function validateLogonForm()
{
	if(testField("MemberID", "Invalid Member ID")==false)
		return(false);
}

function validateDive_LogsForm()
{
	if(testField("LOCATION", "Invalid Location")==false)
		return(false);
}

function validateInfoRequestForm()
{

	if(testField("CONTACT_NAME", "Invalid Contact Name")==false)
		return(false);

	if(checkEmail(document.all("CONTACT_EMAIL"), true)==false)
		return(false);
	
	if(testPhoneField("CONTACT_PHONE")==false)
		return(false);
		
	if(testField("DESCRIPTION", "Invalid Description")==false)
		return(false);
	
}
