// email,digit,other fields validate
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() {
    $('#ziniocode').submit(function() {
        if ($('#Coupon').val() != 'zinio-dlx') { alert('Please check your coupon code.'); $('#Coupon').focus(); return false; }
    });
    // shipping validate
    $("#shipping_usa_fm").submit(function() {
        if ($.trim($("input:checked[name='ShipMethod']").val()) == "")
        { alert("Please select a shipping method."); return false; }
    });

    // credit card info validate
    $("#confirmorder_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 ($("input#FirstName").val().length > 50)
        { alert("Please enter at most 50 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 ($("input#LastName").val().length > 50)
        { alert("Please enter at most 50 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 ($("select#CCType").val() == "1")// Visa	13 or 16 digit
        {
            if (!($("input#CCNumber").val().length == 13 || $("input#CCNumber").val().length == 16) || !isValidDigit($("input#CCNumber").val()))
            { alert("Please enter 13 or 16 digit in the \"Credit Card Number\" field."); $("input#CCNumber").focus(); return false; }
        }
        else if ($("select#CCType").val() == "2")// MasterCard	16 digit
        {
            if ($("input#CCNumber").val().length != 16 || !isValidDigit($("input#CCNumber").val()))
            { alert("Please enter 16 digit in the \"Credit Card Number\" field."); $("input#CCNumber").focus(); return false; }
        }
        else if ($("select#CCType").val() == "3")// AMEX	15 digit
        {
            if ($("input#CCNumber").val().length != 15 || !isValidDigit($("input#CCNumber").val()))
            { alert("Please enter 15 digit in the \"Credit Card Number\" field."); $("input#CCNumber").focus(); return false; }
        }
        else
        { }

        if ($("input#CSC").val().length < 3 || !isValidDigit($("input#CSC").val()))
        { alert("Please enter at least 3 digit in the \"Security Code\" field."); $("input#CSC").focus(); return false; }

    });

});


// user validate
$(document).ready(function(){

	// user login from (#userlogin_fm) -- validate login -- login.asp
	$("#userlogin_fm #btn_login").click(function(){
		if ($("input#UserName").val()=="")
		{alert("Please enter your email address.");$("input#UserName").focus();return false;}
		if (!isEmail($("input#UserName").val()))
		{alert("Please enter a valid email address.");$("input#UserName").focus();return false;}
		
		if ($("input#Password").val()=="")
		{alert("Please enter your password.");$("input#Password").focus();return false;}
		if ($("input#Password").val().length<5)
		{alert("Password requires a minimum 5 characters");$("input#Password").focus();return false;}
		if (!isValidInput($("input#Password").val()))
		{alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"Password\" field.");$("input#Password").focus();return false;}
		$("#userlogin_fm").submit();
	});
	

	// input keydown check
	if($("#newuser_fm").length>0)
	{
		$("#newuser_fm :input[id!='LoginEmail'][id!='LoginPassword']").keydown(function(event){
			if(event.keyCode == 13)
			{$("#newuser_fm #btn_reg").trigger("click");}
		});
		
		$("#LoginEmail,#LoginPassword").keydown(function(event){
			if(event.keyCode == 13)
			{$("#newuser_fm #btn_login").trigger("click");}
		});
	}
	
	if($("#edituser_fm").length>0)
	{
		$("#edituser_fm :input").keydown(function(event){
			if(event.keyCode == 13)
			{$("#newuser_fm #btn_edit").trigger("click");}
		});
	}
	
	// newuser form (#newuser_fm) login area	--	validate login
	$("#newuser_fm #btn_login").click(function(){
		if ($("input#LoginEmail").val()=="")
		{alert("Please enter your email address.");$("input#LoginEmail").focus();return false;}
		if (!isEmail($("input#LoginEmail").val()))
		{alert("Please enter a valid email address.");$("input#LoginEmail").focus();return false;}
		
		if ($("input#LoginPassword").val()=="")
		{alert("Please enter your password.");$("input#LoginPassword").focus();return false;}
		if ($("input#LoginPassword").val().length<5)
		{alert("Password requires a minimum 5 characters");$("input#LoginPassword").focus();return false;}
		if (!isValidInput($("input#LoginPassword").val()))
		{alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"Password\" field.");$("input#LoginPassword").focus();return false;}
	
		window.location.href="/login.asp?UserName="+$("input#LoginEmail").val()+"&Password="+$("input#LoginPassword").val();
	});
	
	
	// newuser from (#newuser_fm) newuser area	--	validate reg
	// edituser from (#edituser_fm) edituser area	--	validate edit
	$("#newuser_fm #btn_reg, #newuser_fm #btn_reg2, #edituser_fm #btn_edit").click(function(){
		//email and password
		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 ($("input#Password").val()=="")
		{alert("Please enter a value for the \"Password\" field.");$("input#Password").focus();return false;}
		if ($("input#Password").val().length<5)
		{alert("Please enter at least 5 characters in the \"Password\" field.");$("input#Password").focus();return false;}
		if ($("input#Password").val().length>50)
		{alert("Please enter at most 50 characters in the \"Password\" field.");$("input#Password").focus();return false;}
		if (!isValidInput($("input#Password").val()))
		{alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"Password\" field.");$("input#Password").focus();return false;}
		if ($("input#Password2").val()!=$("input#Password").val())
		{alert("Please re-enter your password so that it matches.");$("input#Password2").focus();return false;}
		
		
		//billing information
		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 ($("input#FirstName").val().length>50)
		{alert("Please enter at most 50 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 ($("input#LastName").val().length>50)
		{alert("Please enter at most 50 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#Address1").val()=="")
		{alert("Please enter a value for the \"Address\" field.");$("input#Address1").focus();return false;}
		if ($("input#Address1").val().length<5)
		{alert("Please enter at least 5 characters in the \"Address\" field.");$("input#Address1").focus();return false;}
		if ($("input#Address1").val().length>50)
		{alert("Please enter at most 50 characters in the \"Address\" field.");$("input#Address1").focus();return false;}
		//if (!isValidInput($("input#Address1").val()))
		if (!(/^([a-zA-Z0-9]|[ .,-]|[#]){1,}$/.test($("input#Address1").val())))
		{alert("Please enter only letter, digit, whitespace and \"-.,#\" characters in the \"Address\" field.");$("input#Address1").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 ($("input#City").val().length>25)
		{alert("Please enter at most 25 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;}
		
		//--	when state field is input box
		//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 at least 2 characters in the \"State\" field.");$("input#State").focus();return false;}
		//if ($("input#State").val().length>25)
		//{alert("Please enter at most 25 characters in the \"State\" field.");$("input#State").focus();return false;}
		//if (!(/^[a-zA-Z]{2,}$/.test($("input#State").val())))
		//{alert("Please enter only letter in the \"State\" field.");$("input#State").focus();return false;}
		
		if ($("select#State").val()=="")
		{alert("Please select an option for the \"State\" field.");$("select#State").focus();return false;}
		
		if ($("input#PostalCode").val()=="")
		{alert("Please enter a value for the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		if ($("input#PostalCode").val().length<5)
		{alert("Please enter at least 5 characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		if ($("input#PostalCode").val().length>15)
		{alert("Please enter at most 15 characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}

		if ($("select#Country").val()=="USA")
		{
			if (!(/^([0-9]|[ -]){2,}$/.test($("input#PostalCode").val())))
			{alert("Please enter only digit, whitespace and \"-\" characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		}
		else
		{
			if (!(/^([a-z0-9A-Z]|[ -]){2,}$/.test($("input#PostalCode").val())))
			{alert("Please enter only letter, digit, whitespace and \"-\" characters in the \"Zip Code\" 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#Phone").val().replace(/[^0-9]/g,'').length != 10)
		{alert("Please enter a valid 10 digit phone number.");$("input#Phone").focus();return false;}
		$("input#Phone").val($("input#Phone").val().replace(/[^\d]/g,''));
		
		
		//shipping information
		if ($("input#ShipFirstName").val()=="")
		{alert("Please enter a value for the \"Shipping First Name\" field.");$("input#ShipFirstName").focus();return false;}
		if ($("input#ShipFirstName").val().length<2)
		{alert("Please enter at least 2 characters in the \"Shipping First Name\" field.");$("input#ShipFirstName").focus();return false;}
		if ($("input#ShipFirstName").val().length>50)
		{alert("Please enter at most 50 characters in the \"Shipping First Name\" field.");$("input#ShipFirstName").focus();return false;}
		if (!isValidInput($("input#ShipFirstName").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"Shipping First Name\" field.");$("input#ShipFirstName").focus();return false;}
		
		if ($("input#ShipLastName").val()=="")
		{alert("Please enter a value for the \"Shipping Last Name\" field.");$("input#ShipLastName").focus();return false;}
		if ($("input#ShipLastName").val().length<2)
		{alert("Please enter at least 2 characters in the \"Shipping Last Name\" field.");$("input#ShipLastName").focus();return false;}
		if ($("input#ShipLastName").val().length>50)
		{alert("Please enter at most 50 characters in the \"Shipping Last Name\" field.");$("input#ShipLastName").focus();return false;}
		if (!isValidInput($("input#ShipLastName").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"Shipping Last Name\" field.");$("input#ShipLastName").focus();return false;}

		if ($("input#ShipAddress1").val()=="")
		{alert("Please enter a value for the \"Shipping Address\" field.");$("input#ShipAddress1").focus();return false;}
		if ($("input#ShipAddress1").val().length<5)
		{alert("Please enter at least 5 characters in the \"Shipping Address\" field.");$("input#ShipAddress1").focus();return false;}
		if ($("input#ShipAddress1").val().length>50)
		{alert("Please enter at most 50 characters in the \"Shipping Address\" field.");$("input#ShipAddress1").focus();return false;}
		//if (!isValidInput($("input#ShipAddress1").val()))
		if (!(/^([a-zA-Z0-9]|[ .,-]|[#]){1,}$/.test($("input#Address1").val())))
		{alert("Please enter only letter, digit, whitespace and \"-.,#\" characters in the \"Shipping Address\" field.");$("input#ShipAddress1").focus();return false;}

		if ($("input#ShipCity").val()=="")
		{alert("Please enter a value for the \"Shipping City\" field.");$("input#ShipCity").focus();return false;}
		if ($("input#ShipCity").val().length<2)
		{alert("Please enter at least 2 characters in the \"Shipping City\" field.");$("input#ShipCity").focus();return false;}
		if ($("input#ShipCity").val().length>25)
		{alert("Please enter at most 25 characters in the \"Shipping City\" field.");$("input#ShipCity").focus();return false;}
		if (!(/^[a-z A-Z]{2,}$/.test($("input#ShipCity").val())))
		{alert("Please enter only letter in the \"Shipping City\" field.");$("input#ShipCity").focus();return false;}

		//--	when shipstate field is input box
		//if ($("input#ShipState").val()=="")
		//{alert("Please enter a value for the \"Shipping State\" field.");$("input#ShipState").focus();return false;}
		//if ($("input#ShipState").val().length<2)
		//{alert("Please enter at least 2 characters in the \"Shipping State\" field.");$("input#ShipState").focus();return false;}
		//if ($("input#ShipState").val().length>25)
		//{alert("Please enter at most 25 characters in the \"Shipping State\" field.");$("input#ShipState").focus();return false;}
		//if (!(/^[a-zA-Z]{2,}$/.test($("input#ShipState").val())))
		//{alert("Please enter only letter in the \"Shipping State\" field.");$("input#ShipState").focus();return false;}
		
		if ($("select#ShipState").val()=="")
		{alert("Please select an option for the \"Shipping State\" field.");$("select#ShipState").focus();return false;}
		
		if ($("input#ShipPostalCode").val()=="")
		{alert("Please enter a value for the \"Shipping Zip Code\" field.");$("input#ShipPostalCode").focus();return false;}
		if ($("input#ShipPostalCode").val().length<5)
		{alert("Please enter at least 5 characters in the \"Shipping Zip Code\" field.");$("input#ShipPostalCode").focus();return false;}
		if ($("input#ShipPostalCode").val().length>15)
		{alert("Please enter at most 15 characters in the \"Shipping Zip Code\" field.");$("input#ShipPostalCode").focus();return false;}
		
		if ($("select#ShipCountry").val()=="USA")
		{
			if (!(/^([0-9]|[ -]){2,}$/.test($("input#ShipPostalCode").val())))
			{alert("Please enter only digit, whitespace and \"-\" characters in the \"Shipping Zip Code\" field.");$("input#ShipPostalCode").focus();return false;}
		}
		else
		{
			if (!(/^([a-z0-9A-Z]|[ -]){2,}$/.test($("input#ShipPostalCode").val())))
			{alert("Please enter only letter, digit, whitespace and \"-\" characters in the \"Shipping Zip Code\" field.");$("input#ShipPostalCode").focus();return false;}
		}

		if ($("input#ShipPhone").val()=="")
		{alert("Please enter a value for the \"Shipping Phone\" field.");$("input#ShipPhone").focus();return false;}
		if ($("input#ShipPhone").val().length<10)
		{alert("Please enter at least 10 characters in the \"Shipping Phone\" field.");$("input#ShipPhone").focus();return false;}
		if ($("input#ShipPhone").val().length>15)
		{alert("Please enter at most 15 characters in the \"Shipping Phone\" field.");$("input#ShipPhone").focus();return false;}
		if (!(/[0-9( )-]{10,}/.test($("input#ShipPhone").val())))
		{alert("Please enter only digit and \"-\" characters in the \"Shipping Phone\" field.");$("input#ShipPhone").focus();return false;}
		if ($("input#ShipPhone").val().replace(/[^0-9]/g,'').length != 10)
		{alert("Please enter a valid 10 digit phone number.");$("input#ShipPhone").focus();return false;}
		$("input#ShipPhone").val($("input#ShipPhone").val().replace(/[^\d]/g,''));
		
		
		if($("#newuser_fm").length>0)
		{$("#newuser_fm").submit();}
		else
		{$("#edituser_fm").submit();}
	});
	
	// edituser form (#edituser_fm) -- state selected option fix
	$("#edituser_fm Select#State").val($("#edituser_fm Select#State").attr("title"));
	$("#edituser_fm Select#ShipState").val($("#edituser_fm Select#ShipState").attr("title"));
	
	if($("#newuser").length > 0 || $("#edituser").length > 0)
	{
		// state or country change events
		$("Select#State,Select#ShipState").change(function(){
			var obj=$(this).attr("id").replace("State","")+"Country";
			if($(this).children("option:selected").is(".canda"))
			{$("#"+obj).val("Canada");}
			else
			{$("#"+obj).val("USA");}
		});
		
		$("Select#Country,Select#ShipCountry").change(function(){
			var obj=$(this).attr("id").replace("Country","")+"State";
			if($(this).val()=="USA")
			{$("#"+obj).val("AL");}
			else
			{$("#"+obj).val("AB");}
		});
	
		// shipping same as billing
		$("input#FillFields").click(function(){
			if ($("input#FillFields:checked").val()=="on")
			{
				$("input#ShipFirstName").val($("input#FirstName").val());
				$("input#ShipLastName").val($("input#LastName").val());
				$("input#ShipAddress1").val($("input#Address1").val());
				$("input#ShipAddress2").val($("input#Address2").val());
				$("input#ShipCity").val($("input#City").val());
				$("input#ShipPostalCode").val($("input#PostalCode").val());
				$("select#ShipState").val($("select#State").val());
				$("select#ShipCountry").val($("select#Country").val());
				$("input#ShipPhone").val($("input#Phone").val());
			}
		});
	}


	$("#service_fm").submit(function() {

	if ($("input#Email").val() != $("input#Email2").val())
	{ alert("Please make sure the email fields are identical."); $("input#Email").focus(); return false; }
	
		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 ($("input#FirstName").val().length>50)
		{alert("Please enter at most 50 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 ($("input#LastName").val().length>50)
		{alert("Please enter at most 50 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#Email").val()=="")
		{alert("Please enter a value for the \"Email Address\" field.");$("input#Email").focus();return false;}
		if (!isEmail($("input#Email").val()))
		{alert("Please enter a valid email address");$("input#Email").focus();return false;}

		if ($("input#Country").val()=="")
		{alert("Please enter a value for the \"Country\" field.");$("input#Country").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#Product").val()=="")
		{alert("Please enter a value for the \"Product\" field.");$("input#Product").focus();return false;}

		if ($("input#Serial").val()=="")
		{alert("Please enter a value for the \"Serial Number\" field.");$("input#Serial").focus();return false;}

		if ($("input#Subject").val()=="")
		{alert("Please enter a value for the \"Reason for Contact\" field.");$("input#Subject").focus();return false;}
		
		if ($("textarea#Comments").val()=="")
		{alert("Please enter a value for the \"Comments\" field.");$("textarea#Comments").focus();return false;}
		if ($("textarea#Comments").val().length<10)
		{alert("Please enter at least 10 characters in the \"Comments\" field.");$("textarea#Comments").focus();return false;}
		if ($("textarea#Comments").val().length>255)
		{alert("Please enter at most 255 characters in the \"Comments\" field.");$("textarea#Comments").focus();return false;}
	});

	// product registration page -- signup
	$("#registration_fm select#Country").change(function(){
		$("#registration_fm select#State").val("");
		if ($("select#Country").val()=="United States")
		{$("#usstatesrow").show(); $("#provinceitem").hide();}
		else
		{$("#usstatesrow").hide(); $("#provinceitem").show();}
	});
	
	$("#registration_fm").submit(function(){
		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 ($("input#Password").val()=="")
		{alert("Please enter a value for the \"Password\" field.");$("input#Password").focus();return false;}
		if ($("input#Password").val().length<5)
		{alert("Please enter at least 5 characters in the \"Password\" field.");$("input#Password").focus();return false;}
		if ($("input#Password").val().length>50)
		{alert("Please enter at most 50 characters in the \"Password\" field.");$("input#Password").focus();return false;}
		if (!isValidInput($("input#Password").val()))
		{alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"Password\" field.");$("input#Password").focus();return false;}

		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 ($("input#FirstName").val().length>50)
		{alert("Please enter at most 50 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 ($("input#LastName").val().length>50)
		{alert("Please enter at most 50 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#Address1").val()=="")
		//{alert("Please enter a value for the \"Address\" field.");$("input#Address1").focus();return false;}
		//if ($("input#Address1").val().length<5)
		//{alert("Please enter at least 5 characters in the \"Address\" field.");$("input#Address1").focus();return false;}
		//if ($("input#Address1").val().length>50)
		//{alert("Please enter at most 50 characters in the \"Address\" field.");$("input#Address1").focus();return false;}
		//if (!(/^([a-zA-Z0-9]|[ .,-]){1,}$/.test($("input#Address1").val())))
		//{alert("Please enter only letter, digit, whitespace and \"-.,\" characters in the \"Address\" field.");$("input#Address1").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 ($("input#City").val().length>25)
		//{alert("Please enter at most 25 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#PostalCode").val()=="")
		{alert("Please enter a value for the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		if ($("input#PostalCode").val().length<5)
		{alert("Please enter at least 5 characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		if ($("input#PostalCode").val().length>15)
		{alert("Please enter at most 15 characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}

		if ($("select#Country").val()=="United States")
		{
			if (!(/^([0-9]|[ -]){2,}$/.test($("input#PostalCode").val())))
			{alert("Please enter only digit, whitespace and \"-\" characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		}
		else
		{
			if (!(/^([a-z0-9A-Z]|[ -]){2,}$/.test($("input#PostalCode").val())))
			{alert("Please enter only letter, digit, whitespace and \"-\" characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		}
		
		if ($("select#Country").val()=="United States")
		{
			if ($("select#State").val()=="")
			{alert("Please select an option for the \"State\" field.");$("select#State").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 at least 2 characters in the \"State\" field.");$("input#State").focus();return false;}
			//if ($("input#State").val().length>25)
			//{alert("Please enter at most 25 characters in the \"State\" field.");$("input#State").focus();return false;}
			//if (!(/^[a-zA-Z]{2,}$/.test($("input#State").val())))
			//{alert("Please enter only letter in the \"State\" field.");$("input#State").focus();return false;}
		}
		else
		{
			if ($("input#Province").val()=="")
			{alert("Please enter a value for the \"State/Province\" field.");$("input#Province").focus();return false;}
			if ($("input#Province").val().length<2)
			{alert("Please enter at least 2 characters in the \"State/Province\" field.");$("input#Province").focus();return false;}
			if ($("input#Province").val().length>25)
			{alert("Please enter at most 25 characters in the \"State/Province\" field.");$("input#Province").focus();return false;}
			if (!(/^[a-zA-Z]{2,}$/.test($("input#Province").val())))
			{alert("Please enter only letter in the \"State/Province\" field.");$("input#Province").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 ($("#BirthDay").val()=="")
		{alert("Please select an item for the \"Year of Birth\" field.");$("#BirthDay").focus();return false;}
		
	});
	
});


$(document).ready(function(){
    $("#dataplan_fm1").submit(function() {
        

        if ($.trim($("#Dmail").val()) == '')
        { alert("Please enter a value for the \"Photo Mail Frame Email Address\" field."); $("#Dmail").focus(); return false; }
        
        if ($.trim($("#Dmail2").val()) != $.trim($("#Dmail").val()))
        { alert("Please re-enter your \"Photo Mail Frame Email Address\" so that it matches."); $("input#Dmail2").focus(); return false; }
    });
	$("#topup_fm1").submit(function(){
		if($.trim($("#Model").val())=='')
		{alert("Please select a Model.");$("#Model").focus();return false;}
		
		if($.trim($("#Dmail").val())=='')
		{alert("Please enter a value for the \"Photo Mail Frame Email Address\" field.");$("#Dmail").focus();return false;}
		if(!isEmail($.trim($("#Dmail").val())))
		{alert("Please enter a valid email address");$("#Dmail").focus();return false;}
		
		if($.trim($("#Dmail2").val())!=$.trim($("#Dmail").val()))
		{alert("Please re-enter your \"Photo Mail Frame Email Address\" so that it matches.");$("input#Dmail2").focus();return false;}
	});

	$("#topup_fm2").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 ($("input#FirstName").val().length>50)
		{alert("Please enter at most 50 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 ($("input#LastName").val().length>50)
		{alert("Please enter at most 50 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#Address1").val()=="")
		{alert("Please enter a value for the \"Address\" field.");$("input#Address1").focus();return false;}
		if ($("input#Address1").val().length<5)
		{alert("Please enter at least 5 characters in the \"Address\" field.");$("input#Address1").focus();return false;}
		if ($("input#Address1").val().length>50)
		{alert("Please enter at most 50 characters in the \"Address\" field.");$("input#Address1").focus();return false;}
		if (!(/^([a-zA-Z0-9]|[ .,-]|[#]){1,}$/.test($("input#Address1").val())))
		{alert("Please enter only letter, digit, whitespace and \"-.,#\" characters in the \"Address\" field.");$("input#Address1").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 ($("input#City").val().length>25)
		{alert("Please enter at most 25 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 at least 2 characters in the \"State\" field.");$("input#State").focus();return false;}
		if ($("input#State").val().length>25)
		{alert("Please enter at most 25 characters in the \"State\" field.");$("input#State").focus();return false;}
		if (!(/^[a-zA-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 Code\" field.");$("input#PostalCode").focus();return false;}
		if ($("input#PostalCode").val().length<5)
		{alert("Please enter at least 5 characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		if ($("input#PostalCode").val().length>15)
		{alert("Please enter at most 15 characters in the \"Zip Code\" field.");$("input#PostalCode").focus();return false;}
		
		
		
		
		if ($("select#CCType").val()=="1")// Visa	13 or 16 digit
		{
			if (!($("input#CCNumber").val().length==13 || $("input#CCNumber").val().length==16) || !isValidDigit($("input#CCNumber").val()))
			{alert("Please enter 13 or 16 digit in the \"Credit Card Number\" field.");$("input#CCNumber").focus();return false;}
		}
		else if ($("select#CCType").val()=="2")// MasterCard	16 digit
		{
			if ($("input#CCNumber").val().length!=16 || !isValidDigit($("input#CCNumber").val()))
			{alert("Please enter 16 digit in the \"Credit Card Number\" field.");$("input#CCNumber").focus();return false;}
		}
		else if ($("select#CCType").val()=="3")// AMEX	15 digit
		{
			if ($("input#CCNumber").val().length!=15 || !isValidDigit($("input#CCNumber").val()))
			{alert("Please enter 15 digit in the \"Credit Card Number\" field.");$("input#CCNumber").focus();return false;}
		}
		else
		{}
		
		if ($("input#CSC").val().length<3 || !isValidDigit($("input#CSC").val()))
		{alert("Please enter at least 3 digit in the \"Security Code\" field.");$("input#CSC").focus();return false;}

	});
});
