(function($)
{
	$(function(){
		//$('.ProgramOverviewTabs ul.tabMenu li a').click()
		

		
		$("#ContactFormDropDown").change(function(){
			var targetId = "#" + $(this).attr('value');
			var targetObj = $(targetId);
			targetObj.show().addClass('current').siblings('.current').removeClass('current').hide();
			$('div.ContactUsForm').addClass('active');
		});
		
		/* stransky 27mar11 - setting white highlight on all text boxes when active */
		$('input.textbox, input.field, input.text, #ContactUsForm textarea').focus(function(){
			$(this).addClass('textbox_highlight');
		});
		$('input.textbox, input.field, input.text, #ContactUsForm textarea').blur(function(){
			$(this).removeClass('textbox_highlight');
		});
		

		$('.tabSet ul.tabMenu li').click(function()
		{
			//alert($(this).children('a:first').attr('id'));
			changeTab($(this));
		});
		
		
		
		$('.tabPageDropDown').change(function()
		{
			//var targetId = $(this).attr('value');
			//$('#'+targetId).fadeIn(500).addClass('current').siblings('.current').hide();
			//LayoutSizer($('#'+targetId));
			
			var targetId = "#" + $(this).attr('value');
			var targetObj = $(targetId);
			targetObj.show().addClass('current').siblings('.current').removeClass('current').hide();
			
			LayoutSizer(targetObj.children(".TBDescription:first"));
			//var targetSize = $('#'+targetId).children(".TBDescription").first().height();
			//alert(targetSize);
			//$('#Layout').css("height",(targetSize+780));
			
			$('.FormControl').removeAttr('disabled');
			$(".tabPageDropDown option[value='StartOption']").remove();
		});
		
		$('#Step2').hide().removeClass('current');
		$('#Step1').addClass('current');	
	});
		
		$('#Next').click(function(event) {
			event.preventDefault();
			var login_email = $("#signup_login_email").val();
			var login_email_confirm =$("#signup_login_email_confirm").val();
			
			//var email = $("#signup_email").val();
			//var email_confirm =$("#signup_email_confirm").val();
			var password =$("#signup_password").val();
			var password_confirm =$("#signup_password_confirm").val();
			var errors = new Array;
			
			
			if(!login_email) errors.push("Please enter a login email address");
			if(login_email.toLowerCase() != login_email_confirm.toLowerCase()) errors.push("Login Email and email confirmation must match");
			
			//if(!email) errors.push("Please enter an email address");
			//if(email.toLowerCase() != email_confirm.toLowerCase()) errors.push("Email and email confirmation must match");
			if(!password) errors.push("Please enter a password");
			if(password.length<6) errors.push("Password must be longer than 6 characters");
			if(password!= password_confirm) errors.push("Password and password confirmation must match");
			
			if(errors.length){
				showError(errors.join('<Br>'));
				
			} else {
				$('#Step1').hide().removeClass('current');
				$('#Step2').show().addClass('current');
				_gaq.push(['_trackPageview', '/funnel/registration/step_2']);
			}
			//return false;
		});
		
		$('#NextEdit').click(function(event) {
			
			
			var login_email = $("#signup_login_email").val();
			var login_email_confirm =$("#signup_login_email_confirm").val();
			
			
			var email = $("#signup_email").val();
			var email_confirm =$("#signup_email_confirm").val();
			var password =$("#signup_password").val();
			var password_confirm =$("#signup_password_confirm").val();
			var errors = new Array;
			
			if(!login_email) errors.push("Please enter a login email address");
			if(login_email.toLowerCase() != login_email_confirm.toLowerCase()) errors.push("Login Email and email confirmation must match");
			
			if(!email) errors.push("Please enter an email address");
			if(email.toLowerCase() != email_confirm.toLowerCase()) errors.push("Property Email and property email confirmation must match");
			//if(!password) errors.push("Please enter a password");
			//if(password.length<3) errors.push("Password must be longer than 3 characters");
			
			if(password && password_confirm){
				if(password!= password_confirm) errors.push("Password and password confirmation must match");
			}
			
			if(errors.length){
				showError(errors.join('<br>'));
				
			} else {
				$('#Step1').hide().removeClass('current');
				$('#Step2').show().addClass('current');
				window.scrollTo(0,0);
			}
			event.preventDefault();
		});
		
		$('#Previous').click(function() {
			$('#Step2').hide().removeClass('current');
			$('#Step1').show().addClass('current');
			return false;
		});
		
		
		
	
})(jQuery);

	


	function changeTab(element){
		var $thisLi = element;
		if($thisLi.attr('class').indexOf('selected')> -1) return false;
		
		$thisLi.addClass('selected')
			.siblings().removeClass('selected');
		
		$thisLi.parents('.tabSet').find('div.tabContent.current').hide();
		$thisLi.parents('.tabSet').find('div.tabContent.current').removeClass('current');
		$thisLi.parents('.tabSet')
			.find('#'+$thisLi.data('target'))
			.show(0, function(){
				$(this).addClass('current');
				var newHeight = 0;
				if((element.children('a:first').attr('id')) == "link_0"){
					newHeight = $("#page0 .divContent.current .TBDescription:first");			
					
				} else {
					newHeight = $("#page1 .divContent.current .TBDescription:first");
				}
				LayoutSizer(newHeight);
				//var targetID = $(".current .TBDescription:first").height();
				//alert(targetID);
				//LayoutSizer(targetID);
			});
	}

	/*function checkTerms(){
		var terms = $("#register_terms").attr('checked');
		if(!terms){
		    alert("Please accept the terms & conditions");
		}
		return terms;
	}*/
 
	function createErrorArrow(element,message){
		
	}
 
	function winlossFormSubmit(){
		var year = $("#winloss_year");
		
		year.removeClass('error_input');
		if(!year.val()){
			year.addClass('error_input');
			return false;
		}
		//alert(year.val());
		return true;
	}
 
	function memberSignupForm(){
		var terms = $("#register_terms").attr('checked');
		if(!terms){
		    showError("Please accept the terms & conditions");
		    return false;
		}		
		$.fn.signup(document.getElementById("signUpForm"));
		return false;
	}
	
	function profileEditForm(){
		$.fn.editprofile(document.getElementById("editProfileForm"));
		return false;
	}
 
	function loginFormSubmit(suffix){
		if (!suffix) var suffix = '';
		$(".mandatory").removeClass('error_input');
		var email = $("#login_userid"+suffix);
		var password = $("#login_password"+suffix);
		var errors = new Array;

		if(!email.val()){
			errors.push("Email cannot be blank");
			email.addClass('error_input');
		}
		
		if(!password.val()){
			errors.push("Password cannot be blank");
			password.addClass('error_input');
			
		}
		
		if(errors.length){
			$("#errormsg_body").html(errors.join('<br>'))
			$(".errormsg").show().center();
			return false;
		} else {
			$("#member_login"+suffix).hide();
			$("#login_loading"+suffix).show().html('<img src="/themes/mychoice/images/loading.gif"><Br>Please wait...');
		}
		
		$.fn.patron_login(email.val(),password.val(),suffix);
	    return false;
	}
	function showLoggingIn() {
		$('#BgContainer').append('<div id="login_overlay"><img src="/themes/mychoice/images/saving_animation.gif">&nbsp;&nbsp;Please wait while we log you in...</div>');
			//$('#login_overlay').delay(3000).hide();
			
	    }
	function showLoadingImage() {
		$('#BgContainer').append('<div id="login_overlay"></div>');
	}
	    
	function hideLoadingImage() {
		$('#login_overlay').remove();
	}

	
	function signUpFormSubmit(){
		
		//$("#verify_progress").html('Please wait while we validate your pin');
		
		$(".mandatory").removeClass('error_input');
		var card_number = $("#card_number2");
		var pin_number = $("#pin_number");
		var property_id = $("#card_number1");
		//var property_id = $("#select_property_create");
		
		var errors = new Array;
		
		if(!property_id.val()){
			//errors.push("Card number cannot be blank");
			errors.push("Card number part 1 cannot be blank");
			property_id.addClass('error_input');
		}
		
		if(!card_number.val()){
			errors.push("Card number part 2 cannot be blank");
			card_number.addClass('error_input');
		}
		
		if(!pin_number.val()){
			errors.push("Pin number cannot be blank");
			pin_number.addClass('error_input');
		}
	    
		/*if(!property_id.val()){
			errors.push("Property number cannot be blank");
			property_id.addClass('error_input');
		}*/
		
		if(errors.length){
			//$("#verify_progress").html(errors.join('<br>'));
			
			$("#errormsg_body").html(errors.join('<br>'));
			$(".errormsg").center().show();
			return false;
		} else {
			$("#button_create-account").hide();
			$("#verify_progress").html('<img src="/themes/mychoice/images/loading.gif"><Br>Please wait...');
		}
	   
		$.fn.validatePin(card_number,pin_number,property_id,document.getElementById("signUpForm"));
		//$("#verify_progress").html('');
		
		return false;
	}
	
	
	function toggle(id) {
		var state = document.getElementById(id).style.display;
			if (state == 'block') {
				document.getElementById(id).style.display = 'none';
			} else {
				document.getElementById(id).style.display = 'block';
			}
		}
	/*** function heightFix($){
			var parentCon = $("#Layout");
			    child = ($('.TBDescription').height())+780;
			if(parentCon.height() < child){
			   parentCon.height(child)
			}
			setTimeout(function(){
			    heightFix($);
			},100)
	}
	
	***/
	// Layout Sizer ***/
	function LayoutSizer(targetID){
		
		var targetSize = targetID.height();
		
		$('#Layout').css("height",(targetSize+840));
		
	}
	//function DivSizer
	function echo(msg)
	{
		try
		{
			console.log(msg);
		}
		catch(err)
		{
			alert(msg);
		}
	}
	
	


