// JavaScript Document
$(document).ready(function(){

	//PayBy
	$("#drpPayBy").change(function(){
	    var intPayBy = 	$("#drpPayBy").val();
		
		if(intPayBy == "1") //Credit Card
		{
			$('.CreditCard').show();
		}
		else if (intPayBy == "2") //PayPal
		{
			$('.CreditCard').hide();
		}		
	});
	
	//Create account
	$("#btn_CreateAccount").click(function(){
	    location.href="/newuser.asp?redeemid=" + $("input#redeemid").val();											
	});
	
	// user login from (#userlogin_fm) -- validate login -- login.asp
	jQuery("#btn_login").click(function(){
		
		if (jQuery("input#UserName").val()=="")
		{jQuery("#loginerror").html("Your email or password was entered incorrectly.");jQuery("input#UserName").focus();return false;}
		if (!isEmail(jQuery("input#UserName").val()))
		{jQuery("#loginerror").html("Your email or password was entered incorrectly.");jQuery("input#UserName").focus();return false;}
		
		if (jQuery("input#LoginPassword").val()=="")
		{jQuery("#loginerror").html("Your email or password was entered incorrectly.");jQuery("input#LoginPassword").focus();return false;}
		if (jQuery("input#LoginPassword").val().length<5)
		{jQuery("#loginerror").html("Your email or password was entered incorrectly.");jQuery("input#LoginPassword").focus();return false;}
		if (!isValidInput(jQuery("input#LoginPassword").val()))
		{jQuery("#loginerror").html("Your email or password was entered incorrectly.");jQuery("input#LoginPassword").focus();return false;}
		if($("input#redeemid").val() == 1)
		{
		$.get('/login.asp?rand='+Math.random(),{ UserName:$.trim($("#UserName").val()), Password:$.trim($("#LoginPassword").val())},function(data){
			if (data == "0")
			{jQuery("#loginerror").html("Your email or password was entered incorrectly.");}
			else if( data == "1")
			{location.href="Redeem-Sucess.asp";}
			else if ( data == "2")
			{
			   	location.href="Redeem-fail.asp";
			}
		});
		}
		else
		{
		   	$.get('/login.asp?rand='+Math.random(),{ UserName:$.trim($("#UserName").val()), Password:$.trim($("#LoginPassword").val())},function(data){
			if (data == "0")
			{jQuery("#loginerror").html("Your email or password was entered incorrectly.");}
			else if( data == "1")
			{location.href="/";}
			else if ( data == "2")
			{
			   	location.href="/";
			}
		});
		}
		
	});	
	
	//forgotpassword
	$("#forgotlink").click(function(){
	    $("#signincondv").hide();
		$("#forgotpasswordcondv").show();
	});
	
	$("#btn_forgot").click(function(){
		
	    if ($("input#ForgotEmail").val() == "" )
		{
		   	$("#emailloginerror").html("Your email was entered incorrectly.");
			$("input#ForgotEmail").focus();
			return false;
		}
		if (!isEmail(jQuery("input#ForgotEmail").val()))
		{
		   	$("#emailloginerror").html("Your email was entered incorrectly.");
			$("input#ForgotEmail").focus();
			return false;
		}
		//alert("123");
		$.get('/forgotpassword.asp?rand='+Math.random(),{Email:$.trim($("#ForgotEmail").val())},function(data){

			if (data == "0")
			{
				$("#emailloginerror").html("The email provided doesn't have an account associated with it."); 
				return false;
			}
			else
			{
				
				$("#ssmessage").html("Please check your emails. We have just sent you your new password.<br>We will redirect you to the Sign-In window in 10 seconds.");
				$("#forgotTable").hide();
				setTimeout(function(){
					
				    $("#forgotpasswordcondv").hide();
                    $("#signincondv").show();
					$("#ssmessage").html("Please provide us with the email address you created your account with.<br />Once you click OK, we will send you an email with your password and you can<br /> try to log in again.");
				    $("#forgotTable").show();
					
				},10000);
				return false;
			}
		});
	});
	
	// user login from (#userlogin_fm) -- validate login -- login.asp
	jQuery("input#btn_MyAccount").click(function(){
		if (jQuery("input#UserName").val()=="")
		{alert("Please enter your email address.");jQuery("input#UserName").focus();return false;}
		if (!isEmail(jQuery("input#UserName").val()))
		{alert("Please enter a valid email address.");jQuery("input#UserName").focus();return false;}
		
		if (jQuery("input#LoginPassword").val()=="")
		{alert("Please enter your password.");jQuery("input#LoginPassword").focus();return false;}
		if (jQuery("input#LoginPassword").val().length<5)
		{alert("Password requires a minimum 5 characters");jQuery("input#LoginPassword").focus();return false;}
		if (!isValidInput(jQuery("input#LoginPassword").val()))
		{alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"Password\" field.");jQuery("input#LoginPassword").focus();return false;}
		
		$.get('/login.asp?rand='+Math.random(),{Action:"AjaxRequest", UserName:$.trim($("#UserName").val()), Password:$.trim($("#LoginPassword").val())},function(data){
			if (data == "0")
			{alert("Password not valid, please try again.");}
			else
			{location.href="/status.asp";}
		});
		
	});
	
	// newuser from (#newuser_fm) newuser area	--	validate reg
	// edituser from (#edituser_fm) edituser area	--	validate edit
	jQuery("#newuser_fm #btn_reg, #edituser_fm #btn_edit").click(function(){
	
		//email and password
		if (jQuery("input#Email").val()=="")
		{alert("Please enter a value for the \"Email\" field.");jQuery("input#Email").focus();return false;}
		if (!isEmail(jQuery("input#Email").val()))
		{alert("Please enter a valid email address");jQuery("input#Email").focus();return false;}
		if ((jQuery("input#Email").val() != jQuery("input#Email2").val()) || jQuery("input#Email").val() == "" || !isEmail(jQuery("input#Email2").val()))
		{
		   	{alert("Please enter a correct retype email address");jQuery("input#Email2").focus();return false;}
		}
	
		if (jQuery("input#Password").val()=="")
		{alert("Please enter a value for the \"Password\" field.");jQuery("input#Password").focus();return false;}
		if (jQuery("input#Password").val().length<5)
		{alert("Please enter at least 5 characters in the \"Password\" field.");jQuery("input#Password").focus();return false;}
		if (jQuery("input#Password").val().length>50)
		{alert("Please enter at most 50 characters in the \"Password\" field.");jQuery("input#Password").focus();return false;}
		if (!isValidInput(jQuery("input#Password").val()))
		{alert("Please enter only letter, digit, whitespace and \"-.\" characters in the \"Password\" field.");jQuery("input#Password").focus();return false;}
		if (jQuery("input#Password2").val()!=jQuery("input#Password").val())
		{alert("Please re-enter your password so that it matches.");jQuery("input#Password2").focus();return false;}
		
		
		//billing information
		if (jQuery("input#FirstName").val()=="")
		{alert("Please enter a value for the \"First Name\" field.");jQuery("input#FirstName").focus();return false;}
		if (jQuery("input#FirstName").val().length<2)
		{alert("Please enter at least 2 characters in the \"First Name\" field.");jQuery("input#FirstName").focus();return false;}
		if (jQuery("input#FirstName").val().length>50)
		{alert("Please enter at most 50 characters in the \"First Name\" field.");jQuery("input#FirstName").focus();return false;}
		if (!isValidInput(jQuery("input#FirstName").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"First Name\" field.");jQuery("input#FirstName").focus();return false;}
		
		if (jQuery("input#LastName").val()=="")
		{alert("Please enter a value for the \"Last Name\" field.");jQuery("input#LastName").focus();return false;}
		if (jQuery("input#LastName").val().length<2)
		{alert("Please enter at least 2 characters in the \"Last Name\" field.");jQuery("input#LastName").focus();return false;}
		if (jQuery("input#LastName").val().length>50)
		{alert("Please enter at most 50 characters in the \"Last Name\" field.");jQuery("input#LastName").focus();return false;}
		if (!isValidInput(jQuery("input#LastName").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"Last Name\" field.");jQuery("input#LastName").focus();return false;}
	


	   if($(this).val()=="USA" || $(this).val()=="Canada")
	   {

		if (jQuery("select#Country").val()=="USA")
		{
			if (!(/^([0-9]|[ -]){2,}$/.test(jQuery("input#PostalCode").val())))
			{alert("Please enter only digit, whitespace and \"-\" characters in the \"Zip Code\" field.");jQuery("input#PostalCode").focus();return false;}
		}
		else
		{
			if (!(/^([a-z0-9A-Z]|[ -]){2,}$/.test(jQuery("input#PostalCode").val())))
			{alert("Please enter only letter, digit, whitespace and \"-\" characters in the \"Zip Code\" field.");jQuery("input#PostalCode").focus();return false;}
		}
		
		if (jQuery("input#Address1").val()=="")
		{alert("Please enter a value for the \"Address\" field.");jQuery("input#Address1").focus();return false;}
		if (jQuery("input#Address1").val().length<5)
		{alert("Please enter at least 5 characters in the \"Address\" field.");jQuery("input#Address1").focus();return false;}
		if (jQuery("input#Address1").val().length>50)
		{alert("Please enter at most 50 characters in the \"Address\" field.");jQuery("input#Address1").focus();return false;}
		//if (!isValidInput(jQuery("input#Address1").val()))
		if (!(/^([a-zA-Z0-9]|[ .,-]|[#]){1,}$/.test(jQuery("input#Address1").val())))
		{alert("Please enter only letter, digit, whitespace and \"-.,#\" characters in the \"Address\" field.");jQuery("input#Address1").focus();return false;}
		
		if (jQuery("input#City").val()=="")
		{alert("Please enter a value for the \"City\" field.");jQuery("input#City").focus();return false;}
		if (jQuery("input#City").val().length<2)
		{alert("Please enter at least 2 characters in the \"City\" field.");jQuery("input#City").focus();return false;}
		if (jQuery("input#City").val().length>25)
		{alert("Please enter at most 25 characters in the \"City\" field.");jQuery("input#City").focus();return false;}
		if (!(/^[a-z A-Z]{2,}$/.test(jQuery("input#City").val())))
		{alert("Please enter only letter in the \"City\" field.");jQuery("input#City").focus();return false;}
		
		
		if (jQuery("select#State").val()=="")
		{alert("Please select an option for the \"State\" field.");jQuery("select#State").focus();return false;}
		
		if (jQuery("input#PostalCode").val()=="")
		{alert("Please enter a value for the \"Zip Code\" field.");jQuery("input#PostalCode").focus();return false;}
		if (jQuery("input#PostalCode").val().length<5)
		{alert("Please enter at least 5 characters in the \"Zip Code\" field.");jQuery("input#PostalCode").focus();return false;}
		if (jQuery("input#PostalCode").val().length>15)
		{alert("Please enter at most 15 characters in the \"Zip Code\" field.");jQuery("input#PostalCode").focus();return false;}

		
		if (jQuery("input#Phone").val()=="")
		{alert("Please enter a value for the \"Phone\" field.");jQuery("input#Phone").focus();return false;}
		if (jQuery("input#Phone").val().length<10)
		{alert("Please enter at least 10 characters in the \"Phone\" field.");jQuery("input#Phone").focus();return false;}
		if (jQuery("input#Phone").val().length>15)
		{alert("Please enter at most 15 characters in the \"Phone\" field.");jQuery("input#Phone").focus();return false;}
		if (!(/[0-9( )-]{10,}/.test(jQuery("input#Phone").val())))
		{alert("Please enter only digit and \"-\" characters in the \"Phone\" field.");jQuery("input#Phone").focus();return false;}
		
		if(jQuery("#GPSModel").length > 0)
		{
			if(jQuery("#GPSModel").val() == "")
			{alert("Please select the GPS model you own below."); jQuery("#GPSModel").focus(); return false;}
		}
		
	    }
		
		if(jQuery("#newuser_fm").length>0)
		{jQuery("#newuser_fm").submit();}
		else
		{jQuery("#edituser_fm").submit();}
	});
	
	// edituser form (#edituser_fm) -- state selected option fix
	jQuery("#edituser_fm Select#State").val(jQuery("#edituser_fm Select#State").attr("title"));
	jQuery("#edituser_fm Select#ShipState").val(jQuery("#edituser_fm Select#ShipState").attr("title"));
	
	
	// state or country change events for newuser page -- newuser.asp
	if (jQuery("Select#Country").length > 0 && jQuery("Select#State").length > 0)
	{
		jQuery("Select#Country").change(function(){
			if(jQuery(this).val()=="USA")
			{jQuery("Select#State").val('AL');}
			else
			{jQuery("Select#State").val('AB');}
		});
		
		jQuery("Select#State").change(function(){
			if(jQuery(this).children("option:selected").is(".canda"))
			{jQuery("Select#Country").val('Canada');}
			else
			{jQuery("Select#Country").val('USA');}
		});
	}

						   
	if ($("#BillingState").attr("title") != '') $("#BillingState").val($("#BillingState").attr("title"));
	if ($("#BillingCountry").attr("title") != '') $("#BillingCountry").val($("#BillingCountry").attr("title"));
	if ($("#CCType").attr("title") != '') $("#CCType").val($("#CCType").attr("title"));
	if ($("#strCCExpiresMonth").attr("title") != '') $("#strCCExpiresMonth").val($("#strCCExpiresMonth").attr("title"));
	if ($("#strCCExpiresYear").attr("title") != '') $("#strCCExpiresYear").val($("#strCCExpiresYear").attr("title"));
	
	$("Select#BillingState").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#BillingCountry").change(function(){
		var obj=$(this).attr("id").replace("Country","")+"State";
		
		if($(this).val()=="USA" || $(this).val()=="Canada")
		{
			if($(this).val()=="USA")
			{$("#"+obj).val("AL");}
			else
			{$("#"+obj).val("AB");}
			$('.domestic').show();
			$('#drpPayBy').attr('disabled','');
		}else{
			$('#drpPayBy').attr('disabled','disabled');
			$('#drpPayBy').val('2');
			$('#drpPayBy').trigger('change');
			$('.domestic').hide();
		}
	});
	
	$("#placeorder_fm input:text").keydown(function(event){
		if(event.keyCode == 13)
		{
			//$("#placeorder_fm").trigger("submit");
			$("#placeorder_button").trigger("click");
		}
	});
	
	$("#placeorder").click(function(){
		//$("#placeorder_fm").trigger("submit");
		$("#placeorder_button").trigger("click");
		return false;
	});
	
	$("#placeorder_button").click(function(){
		// check whether the user exists or not
		if (parseInt($('#CurUserID').val()) == 0 && $.trim($('#Email').val()) != "")
		{
			$.post("/login.asp",{Action:"CheckUser",UserName:$.trim($("#Email").val())},function(result){
				if (result == "1")
				{$('#placeorder_fm_infodv').show();}
				else
				{$('#placeorder_fm_infodv').hide(); $("#placeorder_fm").trigger("submit");}
			});
		}
		else
		{$("#placeorder_fm").trigger("submit");}
		
		// Verify Promo Code
		//if ($.trim($("#PromoCode").val())=="")
		//{
		//	$("#placeorder_fm").trigger("submit");
		//}
		//else
		//{
		//	$.post("/checkout.asp",{Action:"VerifyPromoCode",PromoCode:$.trim($("#PromoCode").val())},function(result){
		//		if(result!=1)
		//		{
		//			$("#Errormsg_PromoCode").show();
		//			$("#PromoCode").focus();
		//			return false;
		//		}
		//		else
		//		{
		//			$("#placeorder_fm").trigger("submit");
		//		}
		//	});
		//}
	});
	
	$("#PromoCode").change(function(){
		$("#Errormsg_PromoCode, #Errormsg_PromoCode2").hide();
	});
	
	$("#PromoCode").blur(function(){
		$("#Errormsg_PromoCode, #Errormsg_PromoCode2").hide();
	});
	
	// --------------------------------
	$("#applycode").click(function(){
		if ($.trim($("#PromoCode").val())=='')
		{$('#Errormsg_PromoCode').hide();$('#Errormsg_PromoCode2').show();return false;}
		$('#promocode_fm').submit();
	});
	
	
	$("#placeorder_fm").submit(function(){
		if ($("#RecipientName").length > 0)
		{
			if ($("#RecipientName").val()=="")
			{alert("Please enter a value for the \"Name of Recipient\" field.");$("input#RecipientName").focus();return false;}
			
			if ($("input#RecipientEmail").val()=="")
			{alert("Please enter a value for the \"Recipient's Email\" field.");$("input#RecipientEmail").focus();return false;}
			if (!isEmail($("input#RecipientEmail").val()))
			{alert("Please enter a valid email address");$("input#RecipientEmail").focus();return false;}
			
			if ($("#GiftNote").val()=="")
			{alert("Please enter a value for the \"Personal Gift Note\" field.");$("#GiftNote").focus();return false;}
			
			if ($.trim($("input[name='designtype']:checked").val()) == "")
			{alert("Please choose a design for your message."); 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 ($("input#Email2").val()!=$("input#Email").val())
		{alert("Please re-enter your email address so that it matches.");$("input#Email2").focus();return false;}
		
		if ($("input#Password").val()=="")
		{alert("Please enter a value for 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#BillingFirstName").val()=="")
		{alert("Please enter a value for the \"First Name\" field.");$("input#BillingFirstName").focus();return false;}
		if ($("input#BillingFirstName").val().length<2)
		{alert("Please enter at least 2 characters in the \"First Name\" field.");$("input#BillingFirstName").focus();return false;}
		if ($("input#BillingFirstName").val().length>50)
		{alert("Please enter at most 50 characters in the \"First Name\" field.");$("input#BillingFirstName").focus();return false;}
		if (!isValidInput($("input#BillingFirstName").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"First Name\" field.");$("input#BillingFirstName").focus();return false;}
		
		if ($("input#BillingLastName").val()=="")
		{alert("Please enter a value for the \"Last Name\" field.");$("input#BillingLastName").focus();return false;}
		if ($("input#BillingLastName").val().length<2)
		{alert("Please enter at least 2 characters in the \"Last Name\" field.");$("input#BillingLastName").focus();return false;}
		if ($("input#BillingLastName").val().length>50)
		{alert("Please enter at most 50 characters in the \"Last Name\" field.");$("input#BillingLastName").focus();return false;}
		if (!isValidInput($("input#BillingLastName").val()))
		{alert("Please enter only letter, whitespace and \"-.\" characters in the \"Last Name\" field.");$("input#BillingLastName").focus();return false;}

		

	   if($(this).val()=="USA" || $(this).val()=="Canada")
	   {

		if ($("select#BillingCountry").val()=="USA")
		{
			if (!(/^([0-9]|[ -]){2,}$/.test($("input#BillingPostalCode").val())))
			{alert("Please enter only digit, whitespace and \"-\" characters in the \"Zip Code\" field.");$("input#BillingPostalCode").focus();return false;}
		}
		else
		{
			if (!(/^([a-z0-9A-Z]|[ -]){2,}$/.test($("input#BillingPostalCode").val())))
			{alert("Please enter only letter, digit, whitespace and \"-\" characters in the \"Zip Code\" field.");$("input#BillingPostalCode").focus();return false;}
		}
		
		if ($("input#BillingAddress1").val()=="")
		{alert("Please enter a value for the \"Address\" field.");$("input#BillingAddress1").focus();return false;}
		if ($("input#BillingAddress1").val().length<5)
		{alert("Please enter at least 5 characters in the \"Address\" field.");$("input#BillingAddress1").focus();return false;}
		if ($("input#BillingAddress1").val().length>50)
		{alert("Please enter at most 50 characters in the \"Address\" field.");$("input#BillingAddress1").focus();return false;}
		if (!(/^([a-zA-Z0-9]|[ .,-]|[#]){1,}$/.test($("input#BillingAddress1").val())))
		{alert("Please enter only letter, digit, whitespace and \"-.,#\" characters in the \"Address\" field.");$("input#BillingAddress1").focus();return false;}
		
		if ($("input#BillingCity").val()=="")
		{alert("Please enter a value for the \"City\" field.");$("input#BillingCity").focus();return false;}
		if ($("input#BillingCity").val().length<2)
		{alert("Please enter at least 2 characters in the \"City\" field.");$("input#BillingCity").focus();return false;}
		if ($("input#BillingCity").val().length>25)
		{alert("Please enter at most 25 characters in the \"City\" field.");$("input#BillingCity").focus();return false;}
		if (!(/^[a-z A-Z]{2,}$/.test($("input#BillingCity").val())))
		{alert("Please enter only letter in the \"City\" field.");$("input#BillingCity").focus();return false;}
		
		if ($("select#BillingState").val()=="")
		{alert("Please select an option for the \"State\" field.");$("select#BillingState").focus();return false;}
		
		if ($("input#BillingPostalCode").val()=="")
		{alert("Please enter a value for the \"Zip Code\" field.");$("input#BillingPostalCode").focus();return false;}
		if ($("input#BillingPostalCode").val().length<5)
		{alert("Please enter at least 5 characters in the \"Zip Code\" field.");$("input#BillingPostalCode").focus();return false;}
		if ($("input#BillingPostalCode").val().length>15)
		{alert("Please enter at most 15 characters in the \"Zip Code\" field.");$("input#BillingPostalCode").focus();return false;}

		
		if ($("input#BillingPhone").val()=="")
		{alert("Please enter a value for the \"Phone\" field.");$("input#BillingPhone").focus();return false;}
		if ($("input#BillingPhone").val().length<10)
		{alert("Please enter at least 10 characters in the \"Phone\" field.");$("input#BillingPhone").focus();return false;}
		if ($("input#BillingPhone").val().length>15)
		{alert("Please enter at most 15 characters in the \"Phone\" field.");$("input#BillingPhone").focus();return false;}
		if (!(/[0-9( )-]{10,}/.test($("input#BillingPhone").val())))
		{alert("Please enter only digit and \"-\" characters in the \"Phone\" field.");$("input#BillingPhone").focus();return false;}
		
		if ($("input#BillingPhone").val().replace(/[^0-9]/g,'').length != 10)
		{alert("Please enter a valid 10 digit phone number.");$("input#BillingPhone").focus();return false;}
		$("input#BillingPhone").val($("input#BillingPhone").val().replace(/[^\d]/g,''));
		
	   }
	   
		if($('#drpPayBy').val() == "3" || $('#drpPayBy').val() == "4" || $('#drpPayBy').val() == "5")
		{
		   if($('input#pin').val() == "")
		   {
			  {alert("Please enter a value for the \"Pin/Code\" field.");$("input#pin").focus();return false;}   
		   }
		}
		
		if(($('#drpPayBy').val() == "1" || $('#drpPayBy').val() == "4") && $("#HiddenCardInfo").length == 0)
		{
			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 (parseInt($("#strCCExpiresYear").val()) < parseInt($("#strCCExpiresYear").attr("title")))
			{
				alert("Please select a valid Expiration Date.");
				$("#strCCExpiresMonth").focus();
				return false;
			}
			else
			{
				if ((parseInt($("#strCCExpiresYear").val()) <= parseInt($("#strCCExpiresYear").attr("title"))) && (parseInt($("#strCCExpiresMonth").val())-parseInt($("#strCCExpiresMonth").attr("title")) <= 0))
				{
					alert("Please select a valid Expiration Date.");
					$("#strCCExpiresMonth").focus();
					return false;
				}
			}
			
			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;}
		}
	});
});
