$(window).load(function(){
	//alert(top.location.href);
	if($("#step").val() >= 1){
		$.ajax({
			type: 'POST',
			url: 'form_save.php',
			data: 'get=true',
			success: function(text){
				if(text != ""){					
					text = text.split("&amp;");
					for(i in text){
						array = text[i].split("=");
						if(array[0] != "step"){						
							$('#' + array[0]).val(replaceAll(unescape(array[1]), "rlnrln", " "));						
						}else{
							$("#step").val(array[1]);
						}
					}
					$("input[name='type']:eq(" + (eval($("#type").val())-1) + ")").attr("checked", true);
					if($("#same_hidden").val() == 1) $("#same").attr("checked", true);
					if($("#same_hidden").val() == 1) $(".tr_billing").show();
					switch($("#step").val()){
						case '1': 
							if(eval($("#discount").val()) > 0){
								$("#promo_code").attr("readonly", true);
								$(".tr_submitcode").hide();
							}
							$("html, body").animate({scrollTop: $("#divform1").offset().top}, 1000);
							break;
						case '2': 
							if($("#fri").val() == 1){
								var down = "20.00";
								$(".terms").attr("href", "terms_and_conditions.php");
								$(".divprice").hide();
							}else if($("#fri").val() == 2){
								var down = "0.00";
								$(".terms").attr("href", "terms_and_conditions.php");
								$(".divprice").hide();
								$("#creditcardtype, .tr_card > input, .tr_card > select").attr("disabled", true);
							}else{
								var price = ($("input[name='type']:checked").val() == "1") ? "717.00" : "667.00";
								var down1 = ($("input[name='type']:checked").val() == "1") ? "149.00" : "99.00";
								var discount = "0.00";
								if(eval($("#discount").val()) > 0){
									discount = roundNumber(eval(down1) * (eval($("#discount").val()) / 100), 2);
									price = roundNumber(eval(price) - eval(discount), 2);
									$(".total_promocode").text(discount);
									$(".tr_promocode").show();
								}
								var state = ($('#state2').val() == "") ? $('#state').val() : $('#state2').val();
								var tax = (state == "FL") ? roundNumber(eval(price) * eval("0.06"), 2) : "0.00";
								var total = roundNumber(eval(price) + eval(tax), 2);											
								var down = roundNumber(eval(down1) - eval(discount) + eval(tax), 2);
								var totalSales = roundNumber(588 + eval(down), 2);
								$(".total_price").text(price);
								$(".total_tax").text(tax);
								$(".total_total").text(total);
								$(".total_down1").text(down1);
								$(".total_down").text(down);
								$(".total_totalSales").text(totalSales);
							}
							$("#amount").val(down);
							if($("#iaccept_hidden").val() == 1) $("#iaccept").attr("checked", true);
							$("#signature2").val($('#firstname').val() + " " + $('#lastname').val());
							$("#signature3").val($('#firstname').val() + " " + $('#lastname').val());
							$(".firstname").text($('#firstname').val());
							$(".lastname").text($('#lastname').val());
							$(".socialnumber").text($('#socialnumber1').val() + "-" + $('#socialnumber2').val() + "-" + $('#socialnumber3').val());
							$(".datebirth").text($('#datebirth1').val() + "-" + $('#datebirth2').val() + "-" + $('#datebirth3').val());
							$(".address").text($('#address').val() + " " + $('#city').val() + ", " + $('#state').val() + " " + $('#zip').val());
							if($("#firstname_card").val() == "") $("#firstname_card").val($('#firstname').val());
							if($("#lastname_card").val() == "") $("#lastname_card").val($('#lastname').val());
							if($("#creditcardtype").val() == "Check"){
								$(".tr_card").hide();
								$(".tr_check").show();
							}
							$("#divform1").hide();
							$("#divform2").fadeIn();
							$("html, body").animate({scrollTop: $("#divform2").offset().top}, 1000);
							break;
					}
				}			
			}
		});
	}
	
	$('#form_contactus').submit(function(){
		$('input').blur();
		if(!required('#contact_firstname','You must enter a First Name')) return false;
		if(!required('#contact_lastname','You must enter a Last Name')) return false;
		if(!required('#contact_email','You must enter a Email Address') || !validateEmail('#contact_email')) return false;
		if(!required("#contact_phone","You must enter a Phone")) return false;
		if(!required("#contact_time","You must enter a Best Time to Reach you")) return false;
		if(!required('#contact_comments','You must enter a Comments')) return false;
		$.ajax({
			type: 'POST',
			url: 'contactus_process.php',
			data: $('#form_contactus').serialize(),
			success: function(){
				document.form_contactus.reset();
				$focus = "#contact_firstname";
				alert("Your inquiry has been submitted.");
			}
		});
		return false;
	});
	
	$('#form_newsletter').submit(function(){
		$('input').blur();		
		if(!required('#newsletter_name','You must enter a Name')) return false;
		if(!required('#newsletter_email','You must enter a Email') || !validateEmail('#newsletter_email')) return false;
		$.ajax({			
			type: 'POST',
			url: 'newsletter_process.php',
			data: $('#form_newsletter').serialize(),
			success: function(){
				document.form_newsletter.reset();
				$("#newsletter2").slideToggle();
				alert("Your inquiry has been submitted.");
			}
		});
		return false;
	});
	
	$("#newsletter1").click(function(){
		$("#newsletter2").slideToggle();
	});

	$("#form_memberlogin").submit(function(){
		$('input').blur();
		if(!required('#email_memberlogin','You must enter a E-mail') || !validateEmail('#email_memberlogin')) return false;
		if(!required('#id_memberlogin','You must enter a Member ID')) return false;
		$.ajax({
			type: 'POST',
			url: 'access.php',
			data: $('#form_memberlogin').serialize(),
			success: function(msg){
				switch(msg){
					case '': document.location = "member.php"; break;
					case '1': $focus = "#email_memberlogin"; alert("The E-mail does not exist, please enter another"); break;
					case '2': $focus = "#id_memberlogin"; alert("The Member ID does not exist, please enter another"); break;
				}
			}
		});
		return false;
	});

	$("#form_merchantlogin").submit(function(){
		$('input').blur();
		if(!required('#email_memberlogin','You must enter a Email') || !validateEmail('#email_memberlogin')) return false;
		if(!required('#id_memberlogin','You must enter a Member ID')) return false;
		$.ajax({
			type: 'POST',
			url: 'access_download.php',
			data: $('#form_merchantlogin').serialize(),
			success: function(msg){
				switch(msg){
					case '': document.location = "download_list.php"; break;
					case '1': $focus = "#email_memberlogin"; alert("The Email does not exist, please enter another"); break;
					case '2': $focus = "#id_memberlogin"; alert("The Member ID does not exist, please enter another"); break;
					case '3': $focus = "#email_memberlogin"; alert("The Customer no have access, please try later"); break;
				}
			}
		});
		return false;
	});
	
	$("#imgform1_member").click(function(){
		$('input').blur();
		if(!required('#firstname_member','You must enter a First Name')) return false;
		if(!required('#lastname_member','You must enter a Last Name')) return false;
		if(!required('#address_member','You must enter a Address')) return false;
		if(!required('#city_member','You must enter a City')) return false;
		if(!required('#state_member','You must select a State')) return false;
		if(!required('#homephone_member','You must enter a Home Phone')) return false;
		if(!required('#cellphone_member','You must enter a Cell Phone')) return false;
		if(!required('#email_member','You must enter a Email Address') || !validateEmail('#email_member')) return false;
		$("#divform1_member").hide();
		$("#divform2_member").fadeIn();
	});
	
	$("#imgform2_member").click(function(){
		$("#divform2_member").hide();
		$("#divform3_member").fadeIn();
		$.ajax({
			type: 'POST',
			url: 'member_process.php',
			data: $('#form_member').serialize()
		});
		setTimeout(function(){
			$("#divform3_member").hide();
			$("#divform4_member").fadeIn();
		}, 4000);
	});
	
	$("#btn_memberlogin").click(function(){
		$("#btn_memberlogin").hide();
		$("#div_memberlogin").animate({width:'show'});
	});
	
	$("#btn_memberlogin2").click(function(){
		$("#div_memberlogin").animate({width:'hide'});
		setTimeout(function(){
			$("#btn_memberlogin").fadeIn();
		}, 500);
	});
	
	$("#form_affiliate").submit(function(){
		$('input').blur();
		if(!required('#firstname', 'You must enter a First Name')) return false;
		if(!required('#lastname', 'You must enter a Last Name')) return false;
		if(!required('#title', 'You must enter a Title')) return false;
		if(!required('#name', 'You must enter a Business Name')) return false;
		if(!required('#address', 'You must enter a Business Mailing Address')) return false;
		if(!required('#city', 'You must enter a City')) return false;
		if(!required('#state', 'You must select a State')) return false;
		if(!required('#zip', 'You must enter a Zip') || !maxlength('#zip', 5, 'Invalid Zip')) return false;
		if(!required('#homephone1', 'You must enter a Phone Number') || !maxlength('#homephone1', 3, 'Invalid Phone Number')) return false;
		if(!required('#homephone2', 'You must enter a Phone Number') || !maxlength('#homephone2', 3, 'Invalid Phone Number')) return false;
		if(!required('#homephone3', 'You must enter a Phone Number') || !maxlength('#homephone3', 4, 'Invalid Phone Number')) return false;
		if(!required('#cellphone1','You must enter a Cell Phone Number') || !maxlength('#cellphone1', 3, 'Invalid Cell Phone Number')) return false;
		if(!required('#cellphone2','You must enter a Cell Phone Number') || !maxlength('#cellphone2', 3, 'Invalid Cell Phone Number')) return false;
		if(!required('#cellphone3','You must enter a Cell Phone Number') || !maxlength('#cellphone3', 4, 'Invalid Cell Phone Number')) return false;
		//if(!required('#faxnumber','You must enter a Fax Number')) return false;
		if(!required('#email','You must enter a Email') || !validateEmail('#email')) return false;
		if(!required('#email2','You must enter a Confirm Email') || !validateEmail('#email2')) return false;
		if(!compare('#email', '#email2', 'Your e-mails do not match')) return false;
		//if(!required('#website','You must enter a Website') || !validateUrl('#website', 'Invalid Website')) return false;
		if(!required('#website','You must enter a Website')) return false;
		$.ajax({
			type: 'POST',
			url: 'affiliate_process.php',
			data: $('#form_affiliate').serialize(),
			success: function(){
				document.form_affiliate.reset();
				$focus = "#firstname";
				alert("Your inquiry has been submitted.");
			}
		});
		return false;
	});

	$("#imgform, #imgform_, #staryour, #enrollnowexternal").click(function(){
		document.location = "enrollnow.php";
	});
		
	$("#form_register input, #form_register select").blur(function(){		
		$.ajax({
			type: 'POST',
			url: 'form_save.php',
			data: $('#form_register').serialize()
		});
	});
		
	$("#same").click(function(){
		if($(this).is(':checked')){
			$("#same_hidden").val(1);
			if($.browser.msie){ $(".tr_billing").show(); }else{ $(".tr_billing").fadeIn(); }
		}else{
			$("#same_hidden").val(0);
			if($.browser.msie){ $(".tr_billing").hide(); }else{ $(".tr_billing").fadeOut(); }
		}
	});

	$("#datebirth1").keyup(function(){
		if($(this).val().length >= 2){
			$("#datebirth2").focus();
			return false;
		}
	});
	
	$("#datebirth2").keyup(function(){
		if($(this).val().length >= 2){
			$("#datebirth3").focus();
			return false;
		}
	});
	
	$("#socialnumber1").keyup(function(){
		if($(this).val().length >= 3){
			$("#socialnumber2").focus();
			return false;
		}
	});
	
	$("#socialnumber2").keyup(function(){
		if($(this).val().length >= 2){
			$("#socialnumber3").focus();
			return false;
		}
	});
	
	$("#homephone1").keyup(function(){
		if($(this).val().length >= 3){
			$("#homephone2").focus();
			return false;
		}
	});
	
	$("#homephone2").keyup(function(){
		if($(this).val().length >= 3){
			$("#homephone3").focus();
			return false;
		}
	});
	
	$("#cellphone1").keyup(function(){
		if($(this).val().length >= 3){
			$("#cellphone2").focus();
			return false;
		}
	});
	
	$("#cellphone2").keyup(function(){
		if($(this).val().length >= 3){
			$("#cellphone3").focus();
			return false;
		}
	});
	
	$("#imgform1").click(function(){
		if($("#step").val() < 1) return false;
		if(!required('#firstname', 'You must enter a First Name')) return false;
		if(!required('#lastname', 'You must enter a Last Name')) return false;
		if(!required('#address', 'You must enter a Address')) return false;
		if(!required('#city', 'You must enter a City')) return false;
		if(!required('#state', 'You must select a State')) return false;
		if(!required('#zip', 'You must enter a Zip Code') || !maxlength('#zip', 5, 'Invalid Zip Code')) return false;
		if($("#same").is(":checked")){
			if(!required('#address2', 'You must enter a Billing Address')) return false;
			if(!required('#city2', 'You must enter a City')) return false;	
			if(!required('#state2', 'You must enter a State')) return false;		
			if(!required('#zip2', 'You must enter a Zip Code') || !maxlength('#zip2', 5, 'Invalid Zip Code')) return false;
		}else{
			$('#address2, #city2, #state2, #zip2').val("");
		}
		if(!required('#datebirth1', 'You must enter a Date of Birth') || !maxlength('#datebirth1', 2, 'Invalid Date of Birth')) return false;
		if(!required('#datebirth2', 'You must enter a Date of Birth') || !maxlength('#datebirth2', 2, 'Invalid Date of Birth')) return false;
		if(!required('#datebirth3', 'You must enter a Date of Birth') || !maxlength('#datebirth3', 4, 'Invalid Date of Birth')) return false;
		if(!required('#driversnumber', 'You must enter a Drivers License Number')) return false;
		if(!required('#stateissued', 'You must enter a State Issued')) return false;
		if(!required('#socialnumber1', 'You must enter a Social Security Number') || !maxlength('#socialnumber1', 3, 'Invalid Social Security Number')) return false;
		if(!required('#socialnumber2', 'You must enter a Social Security Number') || !maxlength('#socialnumber2', 2, 'Invalid Social Security Number')) return false;
		if(!required('#socialnumber3', 'You must enter a Social Security Number') || !maxlength('#socialnumber3', 4, 'Invalid Social Security Number')) return false;
		if(!required('#homephone1', 'You must enter a Home Phone') || !maxlength('#homephone1', 3, 'Invalid Home Phone')) return false;
		if(!required('#homephone2', 'You must enter a Home Phone') || !maxlength('#homephone2', 3, 'Invalid Home Phone')) return false;
		if(!required('#homephone3', 'You must enter a Home Phone') || !maxlength('#homephone3', 4, 'Invalid Home Phone')) return false;
		if(!required('#cellphone1', 'You must enter a cell Phone') || !maxlength('#cellphone1', 3, 'Invalid Cell Phone')) return false;
		if(!required('#cellphone2', 'You must enter a cell Phone') || !maxlength('#cellphone2', 3, 'Invalid Cell Phone')) return false;
		if(!required('#cellphone3', 'You must enter a cell Phone') || !maxlength('#cellphone3', 4, 'Invalid Cell Phone')) return false;
		if(!required('#email','You must enter a Email Address') || !validateEmail('#email')) return false;
		if(!required('#email2','You must enter a Confirm Email Address') || !validateEmail('#email2')) return false;
		if(!compare('#email', '#email2', 'Your e-mails do not match')) return false;
		$.ajax({
			type: 'POST',
			url: 'form_ssn.php',
			data: "ssn=" + $('#socialnumber1').val() + "-" + $('#socialnumber2').val() + "-" + $('#socialnumber3').val() + "&first=" + $('#firstname').val() + "&last=" + $('#lastname').val(),
			success: function(msg){
				if(msg != ""){
					alert(msg);
					$('#socialnumber1').val("");
					$('#socialnumber2').val("");
					$('#socialnumber3').val("");
					$focus = "#socialnumber1";
					return false;
				}else{
					if($.trim($('#promo_code').val()) != ""){
						$.ajax({
							type: 'POST',
							url: 'form_promocode.php',
							data: 'promo_code=' + $.trim($('#promo_code').val()),
							success: function(msg){
								if(msg != "" && msg != "amount20" && msg != "focus"){
									alert(msg);
									$focus = "#promo_code";
								}else{
									if(msg == "amount20") $("#fri").val(1);
									else if(msg == "focus") $("#fri").val(2);
									else $("#discount").val(10);
									$("#promo_code").attr("readonly", true);
									$(".tr_submitcode").hide();
									$("#step").val(2);
									$.ajax({
										type: 'POST',
										url: 'form_save.php',
										data: $('#form_register').serialize(),
										success: function(){
											if($("#fri").val() == 1){
												var down = "20.00";
												$(".terms").attr("href", "terms_and_conditions.php");
												$(".divprice").hide();
											}else if($("#fri").val() == 2){
												var down = "0.00";
												$(".terms").attr("href", "terms_and_conditions.php");
												$(".divprice").hide();
												$("#creditcardtype, .tr_card > input, .tr_card > select").attr("disabled", true);
											}else{
												var price = ($("input[name='type']:checked").val() == "1") ? "717.00" : "667.00";
												var down1 = ($("input[name='type']:checked").val() == "1") ? "149.00" : "99.00";
												var discount = "0.00";
												if(eval($("#discount").val()) > 0){
													discount = roundNumber(eval(down1) * (eval($("#discount").val()) / 100), 2);
													price = roundNumber(eval(price) - eval(discount), 2);
													$(".total_promocode").text(discount);
													$(".tr_promocode").show();
												}
												var state = ($('#state2').val() == "") ? $('#state').val() : $('#state2').val();
												var tax = (state == "FL") ? roundNumber(eval(price) * eval("0.06"), 2) : "0.00";
												var total = roundNumber(eval(price) + eval(tax), 2);											
												var down = roundNumber(eval(down1) - eval(discount) + eval(tax), 2);
												var totalSales = roundNumber(588 + eval(down), 2);
												$(".total_price").text(price);
												$(".total_tax").text(tax);
												$(".total_total").text(total);
												$(".total_down1").text(down1);
												$(".total_down").text(down);
												$(".total_totalSales").text(totalSales);
											}
											$("#amount").val(down);
											$("#signature2").val($('#firstname').val() + " " + $('#lastname').val());
											$("#signature3").val($('#firstname').val() + " " + $('#lastname').val());
											$(".firstname").text($('#firstname').val());
											$(".lastname").text($('#lastname').val());
											$(".socialnumber").text($('#socialnumber1').val() + "-" + $('#socialnumber2').val() + "-" + $('#socialnumber3').val());
											$(".datebirth").text($('#datebirth1').val() + "-" + $('#datebirth2').val() + "-" + $('#datebirth3').val());
											$(".address").text($('#address').val() + " " + $('#city').val() + ", " + $('#state').val() + " " + $('#zip').val());
											if($("#firstname_card").val() == "") $("#firstname_card").val($('#firstname').val());
											if($("#lastname_card").val() == "") $("#lastname_card").val($('#lastname').val());
											if($("#creditcardtype").val() == "Check"){
												$(".tr_card").hide();
												$(".tr_check").show();
											}
											$("#divform1").hide();
											$("#divform2").fadeIn();
											$("html, body").animate({scrollTop: $("#divform2").offset().top}, 1000);
										}
									});
								}
							}
						});
					}else{
						$("#step").val(2);
						$.ajax({
							type: 'POST',
							url: 'form_save.php',
							data: $('#form_register').serialize(),
							success: function(){
								var price = ($("input[name='type']:checked").val() == "1") ? "717.00" : "667.00";
								var down1 = ($("input[name='type']:checked").val() == "1") ? "149.00" : "99.00";
								var discount = "0.00";
								if(eval($("#discount").val()) > 0){
									discount = roundNumber(eval(down1) * (eval($("#discount").val()) / 100), 2);
									price = roundNumber(eval(price) - eval(discount), 2);
									$(".total_promocode").text(discount);
									$(".tr_promocode").show();
								}
								var state = ($('#state2').val() == "") ? $('#state').val() : $('#state2').val();
								var tax = (state == "FL") ? roundNumber(eval(price) * eval("0.06"), 2) : "0.00";
								var total = roundNumber(eval(price) + eval(tax), 2);											
								var down = roundNumber(eval(down1) - eval(discount) + eval(tax), 2);
								var totalSales = roundNumber(588 + eval(down), 2);
								$(".total_price").text(price);
								$(".total_tax").text(tax);
								$(".total_total").text(total);
								$(".total_down1").text(down1);
								$(".total_down").text(down);
								$(".total_totalSales").text(totalSales);
								$("#amount").val(down);
								$("#signature2").val($('#firstname').val() + " " + $('#lastname').val());
								$("#signature3").val($('#firstname').val() + " " + $('#lastname').val());
								$(".firstname").text($('#firstname').val());
								$(".lastname").text($('#lastname').val());
								$(".socialnumber").text($('#socialnumber1').val() + "-" + $('#socialnumber2').val() + "-" + $('#socialnumber3').val());
								$(".datebirth").text($('#datebirth1').val() + "-" + $('#datebirth2').val() + "-" + $('#datebirth3').val());
								$(".address").text($('#address').val() + " " + $('#city').val() + ", " + $('#state').val() + " " + $('#zip').val());
								if($("#firstname_card").val() == "") $("#firstname_card").val($('#firstname').val());
								if($("#lastname_card").val() == "") $("#lastname_card").val($('#lastname').val());
								if($("#creditcardtype").val() == "Check"){
									$(".tr_card").hide();
									$(".tr_check").show();
								}
								$("#divform1").hide();
								$("#divform2").fadeIn();
								$("html, body").animate({scrollTop: $("#divform2").offset().top}, 1000);
							}
						});
					}
				}
			}
		});
	});

	$("#imgformedit1").click(function(){
		$("#step").val(1);
		$.ajax({
			type: 'POST',
			url: 'form_save.php',
			data: $('#form_register').serialize(),
			success: function(){
				$("#divform2").hide();				
				$("#divform1").fadeIn();
				$("html, body").animate({scrollTop: $("#divform1").offset().top}, 1000);
			}
		});
	});
		
	$("#iaccept").click(function(){
		if($(this).is(':checked')){
			$("#iaccept_hidden").val(1);
		}else{
			$("#iaccept_hidden").val(0);
		}
	});
	
	$("#divaggrement").click(function(){
		$(".divform_content").animate({scrollTop: $("#signature1").position().top - 775 + $(".divform_content").scrollTop()}, 1000);
	});
	
	$("#divcontract1").click(function(){		
		$(".divform_content").animate({scrollTop: $("#signature2").position().top - 775 + $(".divform_content").scrollTop()}, 1000);
	});
	
	$("#divcontract2").click(function(){
		$(".divform_content").animate({scrollTop: $("#signature3").position().top - 675 + $(".divform_content").scrollTop()}, 1000);
	});
	
	$("#creditcardtype").change(function(){
		if($(this).val() == "Check"){
			$(".tr_card").hide();
			$(".tr_check").fadeIn();
		}else{
			$(".tr_card").fadeIn();
			$(".tr_check").hide();
		}
	});

	$("#imgform2").click(function(){
		if($("#step").val() < 2) return false;
		
		if($("#fri").val() == 2){
			if(!required('#iaccept_hidden', 'Please accept the terms and conditions.', 0)) return false;
			$.ajax({
				type: 'POST',
				url: 'form_focus.php',
				data: $('#form_register').serialize(),
				success: function(msg){
					if(msg != "" && msg.substring(0, 5) != "idrln"){
						if(msg != "rlnrln") alert(msg);
						else{
							$("#step").val(1);
							$.ajax({
								type: 'POST',
								url: 'form_save.php',
								data: $('#form_register').serialize(),
								success: function(){				
									alert("This email is already registered");
									$("#divform2").hide();
									$("#divform1").fadeIn();
									$focus = "#email";
								}
							});
						}
					}else{
						$.ajax({
							type: 'POST',
							url: 'name.php',
							data: 'id=' + msg.substring(6),
							success: function(){
								document.location = "thanks.php";
							}
						});
					}
				}
			});
		}else{
			if($("#creditcardtype").val() != "Check"){
				if(!required('#acct','You must enter a Credit Card Number')) return false;
				
				if(!validateCreditCard($.trim($('#acct').val()))){
					alert('You must enter a valid Credit Card Number');
					$focus='#acct';
					return false;
				}
				
				// Credit card type detecting regexp
				var ccTypeRegExp = {
					'Visa': new RegExp('^4[0-9]{12}([0-9]{3})?$'),
					'MasterCard': new RegExp('^5[1-5][0-9]{14}$'),
					'Amex': new RegExp('^3[47][0-9]{13}$'),
					'Discover': new RegExp('^6011[0-9]{12}$')
				};
				
				var ccType = $.trim($('#creditcardtype').val());
				
				// Matched credit card type
				var ccMatchedType = '';
			
				switch($('#acct').val().substring(0,1)){
					case '3' : ccMatchedType="Amex";break;
					case '4' : ccMatchedType="Visa";break;
					case '5' : ccMatchedType="MasterCard";break;
					case '6' : ccMatchedType="Discover";break;
				}
				
				if(ccMatchedType != ccType) {
					alert('Credit Card Number doesn\'t match Credit Card type');						
					$focus='#acct';
					return false;
				}
				
				if(!required('#firstname_card','You must enter a First Name on Card')) return false;
				
				if(!required('#lastname_card','You must enter a Last Name on Card')) return false;
				
				var ccExpMonth   = $.trim($('#expDateMonth').val());
				var ccExpYear    = $.trim($('#expDateYear').val());
				var currentTime  = new Date();
				var currentMonth = currentTime.getMonth() + 1;
				var currentYear  = currentTime.getFullYear();
				if (ccExpMonth < currentMonth && ccExpYear == currentYear) {
					alert("Incorrect Credit Card Expiration Date");
					$focus='#expDateMonth';
					return false;
				}
				
				if(!required('#cvv2','You must enter a Credit Card Verification Number')) return false;
				
				switch (ccType) {
					case 'Visa' :
					case 'MasterCard' :
					case 'Discover' :
						re = new RegExp('^[0-9]{3}$');
						break;
					case 'Amex' :
						re = new RegExp('^[0-9]{4}$');
						break;
				}
				
				if (!$.trim($('#cvv2').val()).match(re)) {
					alert('You must enter a valid Credit Card Verification Number.');
					$focus='#cvv2';
					return false;
				}
			}else{
				//if(!required('#depamo','You must enter a Deposit Amount')) return false;
				if(!required('#namche','You must enter a Name as Shown on Check')) return false;
				if(!required('#rouaba','You must enter a Routing ABA Number')) return false;
				if(!required('#accnum','You must enter a Account Number')) return false;
			}
			if(!required('#iaccept_hidden', 'Please accept the terms and conditions.', 0)) return false;
			
			form = ($("#creditcardtype").val() != "Check") ? "credit" : "check";		
			$.ajax({
				type: 'POST',
				url: 'form_' + form + '.php',
				data: $('#form_register').serialize(),
				success: function(msg){
					if(msg != "" && msg.substring(0, 5) != "idrln"){
						if(msg != "rlnrln") alert(msg);
						else{
							$("#step").val(1);
							$.ajax({
								type: 'POST',
								url: 'form_save.php',
								data: $('#form_register').serialize(),
								success: function(){				
									alert("This email is already registered");
									$("#divform2").hide();
									$("#divform1").fadeIn();
									$focus = "#email";
								}
							});
						}
					}else{
						$.ajax({
							type: 'POST',
							url: 'name.php',
							data: 'id=' + msg.substring(6),
							success: function(){
								document.location = "thanks.php";
							}
						});
					}
				}
			});
		}
	});
	
	var browser = $.browser.msie ? "msie" : $.browser.chrome ? "chrome" : $.browser.safari ? "safari" : $.browser.mozilla ? "mozilla" : $.browser.opera ? "opera" : "";
	$.ajax({
		type: 'POST',
		url: 'form_ipControl.php',
		data: 'action=create&url=' + document.URL + '&browser=' + browser
	});
});

$(window).bind("beforeunload", function(e){
	if(document.URL.indexOf("enrollnow") >= 0 || document.URL.indexOf("posecredilife") >= 0){
		$.ajax({
			type: 'POST',
			url: 'form_temporary.php',
			data: $('#form_register').serialize()
		});
	}
	$.ajax({
		type: 'POST',
		url: 'form_ipControl.php',
		data: 'action=save'
	});
});

function flash_enrollment(flash_type){	
	$("#step").val(1);
	$("#type").val(flash_type);
	$.ajax({
		type: 'POST',
		url: 'form_save.php',
		data: $('#form_register').serialize(),
		success: function(){
			document.location = "enrollnow.php";
		}
	});
}

var $lightbox = false;
var $focus = "";

//function alert(msg){ Lightbox(msg); }

function Lightbox(msg){
	$lightbox = true;
	$("#fadebox").css({width: $(window).width() + 'px', height: $(window).height() + 'px'});
	$("#fadebox").css('opacity',.75).fadeIn();
	$("#overbox").fadeIn();
	$("#overboxBody").html(msg);
}

function hideLightbox(){
	$lightbox = false;
	$("#overbox").fadeOut();$("#fadebox").fadeOut();
	$($focus).focus();
}

document.onkeypress = function hiddenLightbox(e){
	var kC=(window.event)?event.keyCode:e.keyCode;
	if((kC==13 || kC==27) && $lightbox){ hideLightbox(); return false; }
}


/*-------------- functions --------------*/
function roundNumber(num, dec){
	if(dec == null) dec = 0;
	number = Math.round(eval(num) * Math.pow(10, eval(dec))) / Math.pow(10, eval(dec));
	number2 = number.toString().split(".");
	if(number2.length <= 1){
		if(dec > 0){
			number2+= ".";
			for(i = 0; i < dec; i++) number2+= 0;
		}else number2 = number;
	}else if(number2[1].length < dec){
		number = number.toString();
		for(i = 0; i < (dec - number2[1].length); i++) number+= 0;
		number2 = number.toString();
	}else number2 = number;
	return number2;
}

function replaceAll( text, busca, reemplaza ){
  while (text.toString().indexOf(busca) != -1)
      text = text.toString().replace(busca,reemplaza);
  return text;
}

var key;
// NOTE: Backspace = 8, Enter = 13, '0' = 48, '9' = 57 , '.' = 46, '-' = 45, ' ' = 32
function only_numbers(evt){
	(document.all)?key=evt.keyCode:key=evt.which;
	return (key <= 13 || key == 46 || key == 45 || key == 32 || evt.ctrlKey || (key >= 48 && key <= 57));
}

function number(elem){
	var expre = /^[0-9].+$/;
	if($.trim($(elem).val()).match(expre) || $.trim($(elem).val()) == ""){ return true; }
	else{ alert('You must enter only numbers.'); $focus=elem; if($.browser.msie && $.browser.version < 7){ $(elem).focus(); } return false; }
}

function validateUrl(elem, msg){
	var expre = /^(ht|f)tps?:\/\/\w+([\.\-\w]+)?\.([a-z]{2,3}|info|mobi|aero|asia|name)(:\d{2,5})?(\/)?((\/).+)?$/i;
	if($.trim($(elem).val()).match(expre) || $.trim($(elem).val()) == ""){ return true; }
	else{ alert(msg); $focus=elem; if($.browser.msie && $.browser.version < 7){ $(elem).focus(); } return false; }
}

function validateMatch(elem, expre, msg){
	if($.trim($(elem).val()).match(expre) || $.trim($(elem).val()) == ""){ return true; }
	else{ alert(msg); $focus=elem; if($.browser.msie && $.browser.version < 7){ $(elem).focus(); } return false; }
}

function required(elem, msg, conten){
	if(conten == null) conten = "";
	if($.trim($(elem).val()) == conten){alert(msg); $focus=elem; if($.browser.msie && $.browser.version < 7){ $(elem).focus(); } return false; }
	return true;
}

function maxlength(elem, value, msg){
	if(msg == null) msg = "You must enter " + value + " characters";
	if($.trim($(elem).val()).length < value){ alert(msg); $focus = elem; if($.browser.msie && $.browser.version < 7) $(elem).focus(); return false; }
	return true;
}

function validateEmail(elem){
	if($.trim($(elem).val()) != "" && !emailCheck($.trim($(elem).val()))){ $focus=elem; if($.browser.msie && $.browser.version < 7){$(elem).focus();}return false;}
	return true;
}

function compare(elem1,elem2,msg){
	if($.trim($(elem1).val()) != $.trim($(elem2).val())){ alert(msg); $focus=elem2; if($.browser.msie && $.browser.version < 7){ $(elem).focus(); }return false; }
	return true;
}

function emailCheck(emailStr) {
<!-- Changes:  Sandeep V. Tamhankar (stamhankar@hotmail.com) -->

/* 1.1.2: Fixed a bug where trailing . in e-mail address was passing
            (the bug is actually in the weak regexp engine of the browser; I
            simplified the regexps to make it work).
   1.1.1: Removed restriction that countries must be preceded by a domain,
            so abc@host.uk is now legal.  However, there's still the 
            restriction that an address must end in a two or three letter
            word.
     1.1: Rewrote most of the function to conform more closely to RFC 822.
     1.0: Original  */

<!-- This script and many more are available free online at -->
<!-- The JavaScript Source!! http://javascript.internet.com -->

<!-- Begin
/* The following pattern is used to check if the entered e-mail address
   fits the user@domain format.  It also is used to separate the username
   from the domain. */
var emailPat=/^(.+)@(.+)$/
/* The following string represents the pattern for matching all special
   characters.  We don't want to allow special characters in the address. 
   These characters include ( ) < > @ , ; : \ " . [ ]    */
var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]"
/* The following string represents the range of characters allowed in a 
   username or domainname.  It really states which chars aren't allowed. */
var validChars="\[^\\s" + specialChars + "\]"
/* The following pattern applies if the "user" is a quoted string (in
   which case, there are no rules about which characters are allowed
   and which aren't; anything goes).  E.g. "jiminy cricket"@disney.com
   is a legal e-mail address. */
var quotedUser="(\"[^\"]*\")"
/* The following pattern applies for domains that are IP addresses,
   rather than symbolic names.  E.g. joe@[123.124.233.4] is a legal
   e-mail address. NOTE: The square brackets are required. */
var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/
/* The following string represents an atom (basically a series of
   non-special characters.) */
var atom=validChars + '+'
/* The following string represents one word in the typical username.
   For example, in john.doe@somewhere.com, john and doe are words.
   Basically, a word is either an atom or quoted string. */
var word="(" + atom + "|" + quotedUser + ")"
// The following pattern describes the structure of the user
var userPat=new RegExp("^" + word + "(\\." + word + ")*$")
/* The following pattern describes the structure of a normal symbolic
   domain, as opposed to ipDomainPat, shown above. */
var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$")


/* Finally, let's start trying to figure out if the supplied address is
   valid. */

/* Begin with the coarse pattern to simply break up user@domain into
   different pieces that are easy to analyze. */
var matchArray=emailStr.match(emailPat)
if (matchArray==null) {
  /* Too many/few @'s or something; basically, this address doesn't
     even fit the general mould of a valid e-mail address. */
	alert("The email address appears invalid. <br />(check [@] y [.])");
	return false
}
var user=matchArray[1]

var domain=matchArray[2]

// See if "user" is valid 
if (user.match(userPat)==null) {
    // user is not valid
	alert("The email address appears invalid. <br />(check data before de [@])");
    return false
}

/* if the e-mail address is at an IP address (as opposed to a symbolic
   host name) make sure the IP address is valid. */
var IPArray=domain.match(ipDomainPat)
if (IPArray!=null) {
    // this is an IP address
	  for (var i=1;i<=4;i++) {
	    if (IPArray[i]>255) {
			alert("The email address appears invalid. <br />(Incorrect destination IP)");
		return false
	    }
    }
    return true
}

// Domain is symbolic name
var domainArray=domain.match(domainPat)
if (domainArray==null) {
	alert("The email address appears invalid. <br />(After checking data of [@])");
    return false
}

/* domain name seems valid, but now make sure that it ends in a
   three-letter word (like com, edu, gov) or a two-letter word,
   representing country (uk, nl), and that there's a hostname preceding 
   the domain or country. */

/* Now we need to break up the domain to get a count of how many atoms
   it consists of. */
var atomPat=new RegExp(atom,"g")
var domArr=domain.match(atomPat)
var len=domArr.length
if (domArr[domArr.length-1].length<2 || 
    domArr[domArr.length-1].length>3) {
   // the address must end in a two letter or three letter word.
   alert("The email address appears invalid. <br />(After checking data of [.])");
   return false
}

// Make sure there's a host name preceding the domain.
if (len<2) {
   var errStr="The email address appears invalid. <br />(After checking data of [.])"
   alert(errStr);
   return false
}

// If we've gotten this far, everything's valid!
return true;
}
//  End -->

function validateCreditCard(s) {
    // remove non-numerics
    var v = "0123456789";
    var w = "";
    for (i=0; i < s.length; i++) {
        x = s.charAt(i);
        if (v.indexOf(x,0) != -1)
        w += x;
    }
    // validate number
    j = w.length / 2;
    if (j < 6.5 || j > 8 || j == 7) return false;
    k = Math.floor(j);
    m = Math.ceil(j) - k;
    c = 0;
    for (i=0; i<k; i++) {
        a = w.charAt(i*2+m) * 2;
        c += a > 9 ? Math.floor(a/10 + a%10) : a;
    }
    for (i=0; i<k+m; i++) c += w.charAt(i*2+1-m) * 1;
    return (c%10 == 0);
}