// JavaScript Document
function isEmail(strEmail){
	var patrn = /^[\w\-\.]+@[\w\-\.]+(\.\w+)+$/;
	return patrn.test(strEmail);
}
function isValidDigit(s) 
{ 
	var patrn=/^[0-9]{1,20}$/; 
	if (!patrn.exec(s)) return false;
	return true;
} 
function isValidInput(s)
{
	var patrn=/^([a-zA-Z0-9]|[. ,-]){1,}$/; 
	if (!patrn.exec(s)) return false;
	return true;
}


$(document).ready(function(){
	$("input[name='CardType']").change(function(){
		if ($("input[name='CardType']:checked").val()=="KMClubCard")
		{$("#Company,#AccountNumber").removeAttr("disabled");}
		else
		{$("#Company,#AccountNumber").attr("disabled","disabled");}
	});
	
	if ($("#Industry").length > 0)
	{
		if ($("#Industry").val()=="Other")
		{$("#hiddentr").show();$("#OtherIndustry").focus();}
		else
		{$("#hiddentr").hide();}
	}

	$("#Industry").change(function(){
		if ($("#Industry").val()=="Other")
		{$("#hiddentr").show();$("#OtherIndustry").focus();}
		else
		{$("#hiddentr").hide();}
	});
	
	$("#wrapper_signup_fm").submit(function(){
		if ($("input#FirstName").val()=="")
		{alert("Please enter a value for the \"First Name\" field.");$("input#FirstName").focus();return false;}
		if ($("input#FirstName").val().length<2)
		{alert("Please enter at least 2 characters in the \"First Name\" field.");$("input#FirstName").focus();return false;}
		if (!isValidInput($("input#FirstName").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"First Name\" field.");$("input#FirstName").focus();return false;}

		if ($("input#LastName").val()=="")
		{alert("Please enter a value for the \"Last Name\" field.");$("input#LastName").focus();return false;}
		if ($("input#LastName").val().length<2)
		{alert("Please enter at least 2 characters in the \"Last Name\" field.");$("input#LastName").focus();return false;}
		if (!isValidInput($("input#LastName").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"Last Name\" field.");$("input#LastName").focus();return false;}
		
		if ($("input#Address").val()=="")
		{alert("Please enter a value for the \"Address\" field.");$("input#Address").focus();return false;}
		if ($("input#Address").val().length<5)
		{alert("Please enter at least 5 characters in the \"Address\" field.");$("input#Address").focus();return false;}
		if (!(/^([a-zA-Z0-9]|[ .,-]|[#]){1,}$/.test($("input#Address").val())))
		{alert("Please enter only letter, digit, whitespace and \"-.,#\" characters in the \"Address\" field.");$("input#Address").focus();return false;}
		
		if ($("input#City").val()=="")
		{alert("Please enter a value for the \"City\" field.");$("input#City").focus();return false;}
		if ($("input#City").val().length<2)
		{alert("Please enter at least 2 characters in the \"City\" field.");$("input#City").focus();return false;}
		if (!(/^[a-z A-Z]{2,}$/.test($("input#City").val())))
		{alert("Please enter only letter in the \"City\" field.");$("input#City").focus();return false;}
		
		if ($("input#State").val()=="")
		{alert("Please enter a value for the \"State\" field.");$("input#State").focus();return false;}
		if ($("input#State").val().length<2)
		{alert("Please enter 2 characters in the \"State\" field.");$("input#State").focus();return false;}
		if (!(/^[a-z A-Z]{2,}$/.test($("input#State").val())))
		{alert("Please enter only letter in the \"State\" field.");$("input#State").focus();return false;}
		
		if ($("input#PostalCode").val()=="")
		{alert("Please enter a value for the \"Zip\" field.");$("input#PostalCode").focus();return false;}
		if ($("input#PostalCode").val().length<5)
		{alert("Please enter at least 5 characters in the \"Zip\" field.");$("input#PostalCode").focus();return false;}
		if ($("input#PostalCode").val().length>15)
		{alert("Please enter at most 15 characters in the \"Zip\" field.");$("input#PostalCode").focus();return false;}
		
		if ($("input#Phone").val()=="")
		{alert("Please enter a value for the \"Phone\" field.");$("input#Phone").focus();return false;}
		if ($("input#Phone").val().length<10)
		{alert("Please enter at least 10 characters in the \"Phone\" field.");$("input#Phone").focus();return false;}
		if ($("input#Phone").val().length>15)
		{alert("Please enter at most 15 characters in the \"Phone\" field.");$("input#Phone").focus();return false;}
		if (!(/[0-9( )-]{10,}/.test($("input#Phone").val())))
		{alert("Please enter only digit and \"-\" characters in the \"Phone\" field.");$("input#Phone").focus();return false;}
		
		if ($("input#Email").val()=="")
		{alert("Please enter a value for the \"Email\" field.");$("input#Email").focus();return false;}
		if (!isEmail($("input#Email").val()))
		{alert("Please enter a valid Email address");$("input#Email").focus();return false;}
		
		if ($("#Industry").length>0)
		{
			if ($("#Industry").val()=="")
			{alert("Please select an option for the \"I am a...\" field.");$("select#Industry").focus();return false;}
			else
			{
				if ($("#Industry").val()=="Other" && $("#OtherIndustry").val()=="")
				{alert("Please enter a value for the \"Other\" field.");$("input#OtherIndustry").focus();return false;}
			}
		}
		
		if ($("input[name='cardtype']:checked").val()=="KMClubCard")
		{}

	});
});
