
var gpoint;
var gpoint1;
var myDate = new Date();    
gpoint=myDate.getFullYear()-18;
gpoint1=myDate.getFullYear()-100;

(function($){

	//password strength function
	$.fn.passwordStrength = function( options )
	{
		return this.each(function()
		{
			var that = this;that.opts = {};
			
			that.opts = $.extend({}, $.fn.passwordStrength.defaults, options);

			that.div = $(that.opts.targetDiv);
			that.defaultClass = that.div.attr('class');

			that.percents = (that.opts.classes.length) ? 100 / that.opts.classes.length : 100;

			v = $(this).keyup(function()
			{
				if( typeof el == "undefined" )
				this.el = $(this);
				var s = getPasswordStrength (this.value);
				var p = this.percents;
				var t = Math.floor( s / p );

				if( 100 <= s )
				t = this.opts.classes.length - 1;

				this.div.removeAttr('class').addClass( this.defaultClass ).addClass( this.opts.classes[ t ] );
			});
		});

		function getPasswordStrength(password)
		{
			var total_length=(password.length);
			
			//total
			if(total_length<=4) {E=0}
			
			else {
			
				var number=password.replace(/[0-9]/g,"");
				var N=(password.length-number.length);
				if (N>5) { N=5 }
				
				var lower_letter=password.replace(/[a-z]/g,"");
				var Li=(password.length-lower_letter.length);
				if (Li>5) { Li=5 }
				
				var letter=password.replace(/[A-Z]/g,"");
				var L=(password.length-letter.length);
				if (L>5) { L=5 }
				
				E=(N*6)+((Li*6)+10)+(L*5)
			}
			
			return E
		}
		
	};
	//end of predefien functions
	
	//start loading 
	$(document).ready(function() 
	{
		$("#joinbox").css("display", "block");
		
		$("#viewdetailVIP").click(function() {
			$("#features").slideDown("slow");
			$("#grayout").css("display", "block");
		});
		
		$("#viewdetailDELUXE").click(function() {
			$("#features").slideDown("slow");
			$("#grayout").css("display", "block");
		});
		
		$("#viewdetailECONOMY").click(function() {
			$("#features").slideDown("slow");
			$("#grayout").css("display", "block");
		});
		
		$("#closefeature").click(function() {
			$("#features").css("display", "none");
			$("#grayout").slideUp("slow");
		});
		
		// Expand Panel
		$("#open").click(function(){
			$("div#panel").slideDown("slow");
		
		});	
		
		// Collapse Panel
		$("#close").click(function(){
			$("div#panel").slideUp("slow");	
		});		
		
		$("#toggle a").click(function () {
			$("#toggle a").toggle();
		});
	
		//$('input[type=checkbox], input[type=radio]').prettyCheckboxes();
			
		$("#cstate").change(function()
		{
			var cstate=$("#cstate").val();
			if (cstate=="outofusa")
			{
				$("#other").css("display", "block");
				$("#otherinput").css("display", "block");
			}
			else
			{
				$("#other").css("display", "none");
				$("#otherinput").css("display", "none");
			}
			
		}).change();
		
		
		$(".faq h3").click(function(){
			$(this).next("p").slideToggle("slow")
			.siblings("p:visible").slideUp("slow");
			$(this).toggleClass("active");
			$(this).siblings("h3").removeClass("active");
		});
		
		$(".help h3").click(function(){
			$(this).next("#answer").slideToggle("slow")
			.siblings("#answer:visible").slideUp("slow");
			$(this).toggleClass("active");
			$(this).siblings("h3").removeClass("active");
		});
		
		$(".site_tour_faq h3").click(function(){
			$(this).next("p").slideToggle("slow")
			.siblings("p:visible").slideUp("slow");
			$(this).toggleClass("active");
			$(this).siblings("h3").removeClass("active");
		});
		
		$('#payment').submit(function(){
			$('BODY').block({
				centerX: true,
				centerY: false,
				overlayCSS:
					{
						backgroundColor: '#dfdfdf'
					},
				css:
					{
						backgroundColor: '#ffffff',
						border: '3px solid #000000',
						top: '70%'
					},
				message: '<div style="padding: 20px; width: 300px">PROCESSING PLEASE WAIT<BR>DO NOT REFRESH THIS PAGE</div>'
				
			});
		});
		
		
		$("#headline").charCounter(100, {
		container: "<div></div>",
		classname: "counter",
		format: "(Headline %1 characters left)",
		pulse: false,
		delay: 10
		});
		
		$("#essay").charCounter(1000, {
		container: "<div></div>",
		classname: "counter",
		format: "(Essay %1 characters left)",
		pulse: false,
		delay: 10
		});
		
		$("#describe_your_ideal_first_night_out").charCounter(1000, {
		container: "<div></div>",
		classname: "counter",
		format: "(Characters %1 characters left)",
		pulse: false,
		delay: 10
		});
		
		
		function blockX(option)
		{
			//grayout
			$('#'+option).block({ 
			centerX: false,
			centerY: false,
			overlayCSS:
			{
				backgroundColor: '#dfdfdf',
				cursor: 'default'
			},
			opacity: 0.5,
			css:
			{
				backgroundColor: '',
				border: '0px',
				top: '5%',
				left: '70%'
			},
			message: '<div id="'+option+'close"><img src="skins/img/edit.png" id="joinstepbedit"></div>',
			fadeIn: 1000
			});
			
			$("#"+option+"close").click(function()
			{
				$('#'+option).unblock();
			});
		}
		
		blockX("joinstepb");
		
		blockX("joinstepc");
		
		blockX("joinstepd");
		
		blockX("joinstepe");
		
		blockX("joinstepf");
		
		blockX("joinstepg");
		
		//captcha reload
		$("#reload").click(function () 
			{
				var timestamp = new Date().getTime();
				$("#captcha").attr("src", "captcha.svr?"+timestamp);
			}
		);
	
		//load passwrod strength function
		$('input[name="password"]').passwordStrength({targetDiv: '#iSM',classes : Array('weak','medium','strong')});
		//end
	
		//begin of city, state, country ajax
		$('#city').attr("disabled",true).append("<option value=''>Select Country First<option>");
		
		$('#state').attr("disabled",true).append("<option value=''>No Country Selected<option>");
		
		$('#p_state').attr("disabled",true).append("<option value=''>No Country Selected<option>");
		
		//
		
		$('#country').change(function() {
			
			$.post("join_step_a_ajax_deal_city_state.svr", {
				country: $(this).val()
			},
			
			function(data) {
				
				var result = $(data);
				
				$('#state').replaceWith(result).attr("disabled",false);
				
				$('#state').unbind().change(function() {
				
					$.post("join_step_a_ajax_deal_city_state.svr", {
						state: $(this).val()
					},
					
					function(data) {
						$('#city').replaceWith(data).attr("disabled",false);
					}); //grabe city
					
				}); //grabe state and city
				
			}); //end of posting data to check state city php
			
		});	
		
		//
		$('#p_country').change(function() {
			
			$.post("join_step_a_ajax_deal_city_state.svr", {
				pcountry: $(this).val()
			},
			
			function(data) {
				
				var result = $(data);
				
				$('#p_state').replaceWith(result).attr("disabled",false);
				
				$('#p_state').unbind().change(function() {
				
					$.post("join_step_a_ajax_deal_city_state.svr", {
						state: $(this).val()
					});
					
				});
				
			}); //end of posting data to check state city php
			
		});	
		
	//end of on change for state, country, city
		
	// validate signup form on keyup and submit
	var validator = $("#signupform").validate({
	
		rules:
		{
								type_of_christianity:
						{
							required: true
						},
												who_is_first_in_your_life:
						{
							required: true
						},
												i_attend_church:
						{
							required: true
						},
												i_pray:
						{
							required: true
						},
												level_of_faith:
						{
							required: true
						},
												read_the_bible:
						{
							required: true
						},
												relocate_for_the_right_person:
						{
							required: true
						},
												ethnicity:
						{
							required: true
						},
												height:
						{
							required: true
						},
												body:
						{
							required: true
						},
												eye:
						{
							required: true
						},
												hair:
						{
							required: true
						},
												education:
						{
							required: true
						},
												employment_status:
						{
							required: true
						},
												my_martial_status:
						{
							required: true
						},
												do_you_have_children:
						{
							required: true
						},
												children_live_with_you:
						{
							required: true
						},
												do_you_want_to_have_more_children:
						{
							required: true
						},
												smoking:
						{
							required: true
						},
												drinking:
						{
							required: true
						},
												humor:
						{
							required: true
						},
												when_last_relationship_ended_:
						{
							required: true
						},
												occupation:
						{
							required: true
						},
												favorite_activities:
						{
							required: true
						},
												favorite_reading:
						{
							required: true
						},
												favorite_music:
						{
							required: true
						},
												interest_in_politics:
						{
							required: true
						},
												favorite_food:
						{
							required: true
						},
												favorite_pets:
						{
							required: true
						},
												hobbies:
						{
							required: true
						},
												optional_search:
						{
							required: true
						},
									fname:
			{
				required: true
			},
			
			lname:
			{
				required: true
			},
			
			address:
			{
				required: true
			},
			
			czipcode:
			{
				required: true
			},
			
			cstate:
			{
				required: true
			},
			
			ccity:
			{
				required: true
			},
			
			ccountry:
			{
				required: true
			},
			
			cc:
			{
				required: true,
				creditcard: true
			},
			
			exp_month:
			{
				required: true
			},
			
			exp_year:
			{
				required: true
			},
			
			cvv2:
			{
				required: true,
				number: true
			},
			
			username:
			{
				required: true,
				minlength: 5,
				maxlength: 30,
				username: true,
				remote: "join_step_a_ajax_deal_username_form.svr"
			},
			
			password:
			{
				required: true,
				minlength: 6,
				maxlength: 25
			},
			
			repassword:
			{
				required: true,
				equalTo: "#password"
			},
			
			email:
			{
				required: true,
				email:true,
				remote: "join_step_a_ajax_deal_email_form.svr"
			},
			
			remail:
			{
				required: true,
				email:true,
				equalTo: "#email"
			},
			
			firstname:
			{
				required: true
			},
			
			lastname:
			{
				required: true
			},
			
			gender:
			{
				required: true
			},
				
			country:
			{
				required: true
			},
				
			state:
			{
				required: true
			},
				
			city:
			{
				required: true
			},
				
			birthmonth:
			{
				required: true
			},
			
			birthdate:
			{
				required: true,
				digits: true,
				min: 1,
				max: 31
			},
				
			birthyear:
			{
				required: true,
				digits: true,
				
			},
			
			howdidyouhear:
			{
				required: true
			},
			
			captcha:
			{
				required: true,
				remote: "captchacompare.svr"
			},
			
			"spoken_language[]":
			{
				required: true
			},
			
			"my_personality[]":
			{
				required: true
			},
			
			v1: 
			{
				required: true
			},
			
			v3: 
			{
				required: true
			},
			
			v2: 
			{
				required: true
			},
			
			agree :{
				required: true
			}
				
		},
			
		messages: 
		{
			username: 
			{
				required: ("Username is required"),
				minlength: ("Min length is 5 characters"),
				maxlength: ("Max length is 20 characters"),
				username: ("Only letters and numbers are allowed"),
				remote: ("Username is taken")
			},
					
			password: 
			{
				required: ("Password is required"),
				minlength: ("Password has to be more than 5 characters"),
				maxlength: ("Password cannot be more than 20 characters")
			},
			
			repassword: 
			{
				required: ("Retype your password"),
				equalTo: ("Retyped password doesn't match")
			},
			
			email:
			{
				required: ("Email is required"),
				email: ("Email address format is wrong"),
				remote: ("This email is already registered. Please log in.")
			},
			
			remail:
			{
				required: ("Retype your email"),
				email:("Retyped email address format is wrong"),
				equalTo: ("Retyped email address doesn't match")
			},
			
			firstname:
			{
				required: ("First name is required")
			},
			
			lastname:
			{
				required: ("Last name is required")
			},

			birthmonth: 
			{
				required: ("Birth month is required")
			},
					
			birthdate: 
			{
				required: ("Birth date is required"),
				digits: ("Birth Date is required"),
				min: ("Birthdate is incorrect"),
				max: ("Birthdate is incorrect")	
			},
					
			birthyear: 
			{
				required: ("Birth year is required"),
				digits: ("Birth Year is required"),
				min: ("You have to be younger than 100"),
				max: ("You have to be older than 18")	
			},
					
			gender:
			{
				required: ("Gender is required")
			},
			
			country: 
			{
				required: ("Country is required")
			},
			
			state:
			{
				required: ("State is required")
			},
			
			city:
			{
				required: ("City is required")
			},
			
			howdidyouhear:			
			{
				required: ("How did you hear about us is required")
			},
			
			captcha: 
			{
				required: ("Security Code required"),
				remote: ("Security code must be entered exactly as shown")
			},
			
			agree:
			{
				required: ("You must agree to become a member")
			}
			
		},
		
				
		errorElement: "div2",
		
				
		errorPlacement: 
			function(error, element) 
			{
				error.appendTo(element.parent())
			}
		});
		
	}); //end of jquery doc load
	
})(jQuery);


