// Jquery LiveSouthShows 
function SetCookie(cookieName,cookieValue,nDays) {
	 var today = new Date();
	 var expire = new Date();
	 if (nDays==null || nDays==0) nDays=1;
	 expire.setTime(today.getTime() + 3600000*24*nDays);
	 document.cookie = cookieName+"="+escape(cookieValue)
					 + ";expires="+expire.toGMTString();
	}
	function delCookie(cookieName) {
	document.cookie = name +
	'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	} 
	function Get_Cookie( name ) {
	var start = document.cookie.indexOf( name + "=" );
	var len = start + name.length + 1;
	if ( ( !start ) &&
	( name != document.cookie.substring( 0, name.length ) ) )
	{
	return null;
	}
	if ( start == -1 ) return null;
	var end = document.cookie.indexOf( ";", len );
	if ( end == -1 ) end = document.cookie.length;
	return unescape( document.cookie.substring( len, end ) );
	}	
	function processMessage(){
	
		//$(".jsButton").empty();
		//$(".jsButton").append('<div class="redLink blueLink" id="formBlueButton">Processing Your Information..</div>');
		//$(".jsButton").fadeIn("fast");
		
		var pHeight = $(".marketContent").height();
		var pWidth = $(".marketContent").width();
		
		pHeight = (pHeight / 2) - 200;
		pWidth = (pWidth / 2) - 130;
		
		$(".marketContent").css("opacity", 0.5);
		$(".marketContentCover").fadeTo("slow", 0.2); 
		
		$(".ProcessMessage").css("margin-top", pHeight);
		$(".ProcessMessage").css("margin-left", pWidth);
		
	}
	function fxStp(step){	
	
	switch (step){
		case 'one':		
		//Set Active Step
		$("#formStepOne").addClass("activeBox");
		$("#formStepOne").removeClass("formStep");
		$("#formStepOne").css("margin-top", "-20px");
		$("#formStepOne").css("margin-bottom", "20px");
		//Remove Pre-Active Class
		//Step Two
		$("#formStepTwo").addClass("formStep");
		$("#formStepTwo").addClass("formStep");
		$("#formStepTwo").removeClass("activeBox");
		//Step Three
		$("#formStepThree").addClass("formStep");
		$("#formStepThree").addClass("formStep");
		$("#formStepThree").removeClass("activeBox");
		//Set Proper Opacity
		$("#formStepTwo").css("opacity", 1);
		$("#formStepThree").css("opacity", 1);
		break;
		case 'two':
		//Set Active Step
		$("#formStepTwo").addClass("activeBox");
		$("#formStepTwo").removeClass("formStep");
		$("#formStepTwo").css("margin-top", "-20px");
		$("#formStepTwo").css("margin-bottom", "20px");
		//Remove Pre-Active Class
		//Step One
		$("#formStepOne").addClass("formStep");
		$("#formStepOne").addClass("formStep");
		$("#formStepOne").removeClass("activeBox");
		//Step Three
		$("#formStepThree").addClass("formStep");
		$("#formStepThree").addClass("formStep");
		$("#formStepThree").removeClass("activeBox");
		//Set Proper Opacity
		$("#formStepOne").css("opacity", 0.5);
		$("#formStepThree").css("opacity", 1);		
		break;
		case 'three':
		//Set Active Step
		$("#formStepThree").addClass("activeBox");
		$("#formStepThree").removeClass("formStep");
		$("#formStepThree").css("margin-top", "-20px");
		$("#formStepThree").css("margin-bottom", "20px");
		//Remove Pre-Active Class
				//Step One
		$("#formStepOne").addClass("formStep");
		$("#formStepOne").addClass("formStep");
		$("#formStepOne").removeClass("activeBox");
				//Step Two
		$("#formStepTwo").addClass("formStep");
		$("#formStepTwo").addClass("formStep");
		$("#formStepTwo").removeClass("activeBox");
		//Set Proper Opacity
		$("#formStepOne").css("opacity", 0.5);
		$("#formStepTwo").css("opacity", 0.5);	
		break;			
		};
		return true;	
	};	
	
	function checkForm(){
	
		$("input").each(function(){						 
			
		
			if($(this).hasClass("required")){	
			
				var Value = $(this).attr("value");
				
				if(Value==""){				
					
					$(this).css("background", '#FFD9D9');
					$(this).closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
					$(this).removeClass("intVal");
					$(this).addClass("intInval");
					
					var invalid='true';
				
				}else{
					
					$(this).css("background", "#FFFFFF");
					$(this).css("background-image", "url(/img/bg_input.png)");
					$(this).closest(".blltList").css("background-image", "url(/img/blltListGreen.png)");
					$(this).removeClass("intInval");
					$(this).addClass("intVal");
					
				}
				
			}
			
		});
		
		$("select").each(function(){
								  
			var Value = $(this).attr("value");
			
			if(Value==""){				
				
				$(this).css("background", '#FFD9D9');
				$(this).closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
				$(this).removeClass("intVal");
				$(this).addClass("intInval");
				
				var invalid='true';
			
			}else{
					
					$(this).css("background", "#FFFFFF");
					$(this).css("background-image", "url(/img/bg_input.png)");
					$(this).closest(".blltList").css("background-image", "url(/img/blltListGreen.png)");
					$(this).removeClass("intInval");
					$(this).addClass("intVal");
					
			}
			
		
		});
	
	}
	var currentAnchor = null;
	//Function which chek if there are anchor changes, if there are, sends the ajax petition
	function checkAnchor(){
	//Check if it has changes
	if(currentAnchor != document.location.hash){
		currentAnchor = document.location.hash;
		//if there is not anchor, the loads the default section
			if(!currentAnchor){
				//window.location.hash = 'one';
			}else
			{
				//Creates the  string callback. This converts the url URL/#main&id=2 in URL/?section=main&id=2
				var splits = currentAnchor.substring(1).split('&');
				//Get the section
				var section = splits[0];
				delete splits[0];
				//Create the params string
				var params = splits.join('&');
				var query = section + params;
			}
			var visIDr = Get_Cookie('visID');
			var sID = $("#sID").attr("value");
			//Send the petition
			if(visIDr){
				
				if(visIDr!=null || visIDr!='null'){
					/*
					alert(query);
					*/
					if(query!=null || query!='null'){
						
						if(query!='one'){
							
							var theData = $("#stepOne").serialize();
					
							$.post("inc/steps/stpChckr.php",'sID='+sID+'&visID='+visIDr+'&stp='+query+'&'+theData, function(data){
											$(".ProcessMessage").fadeIn("slow");
											$(".marketContentCover").fadeIn("slow"); 							
											$(".marketContent").empty();
											$(".marketContent").html(data);
											$(".ProcessMessage").fadeOut("slow");
											$(".marketContentCover").fadeOut("slow");
											fxStp(query);
											
											if(query=='two'){
												
												$("#formGreenButton").fadeOut("fast");
												$("formRedButton").fadeIn("fast");
												
											}else if(query=='three'){
												
												$(".jsButton").fadeOut("fast");
											}
											
							}); 
						}
					}
				}

			}else{
				//window.location.hash = 'one';	
			}
		}
	
	}


$(document).ready(function() {
	
		   
   $(".jsButton").fadeIn("fast");
   
   $(".ActivejsButton").click(function() {

		var theData = $("#stepOne").serialize();	

		checkForm();
		
		var num = 0;

		$(".required").each(function(){
			
			if($(this).hasClass("intInval")){
			
				num = num + 1;
				
			}
		});
		
		if($(this).hasClass("two")){
			var step = 'two';	
		}else{
			var step = 'three';
		}
		var h = window.location.hash;
		
		var v = Get_Cookie('visID'); 
		
		if(num==0){
			
			var hMrkInf = $("#marketingData").val();
			var hPrchsInf = $("#purchaseData").val();
			
			var bpinterest = $("#bpinterestin").val();
			var flinterest = $("#flinterestin").val();
			
			var marketingData = $("#marketingData").val();
			
			var promoData = $("#promoData").val();  //take out if problems
			
			$("#hPrchsInf").attr("value", hPrchsInf);
			$("#hMrkInf").attr("value", hMrkInf);
			
			$("#bpinterest").attr("value", bpinterest);
			$("#flinterest").attr("value", flinterest);
			
			$("#marketingData").attr("value", marketingData);
			$("#promoData").attr("value", promoData);
			
			processMessage();

			$(".ProcessMessage").fadeIn("fast");

			$.ajax({
				   type: "POST",
				   url: "/inc/addressUSPSChck.php",
				   data: theData + "&h=" + h, 
				   success: function(data){					   
					   var obj = jQuery.parseJSON(data);
					   if(obj.valid==='true'){
						
							//Address IS valid, store user info and move to step two
							
							$.ajax({
							   type: "POST",
							   url: "/inc/steps/steponeProcess.php",
							   data: theData + "&v=" + v + "&h=" + h + "&bpinterstin=" + bpinterest + "&flinterestin=" + flinterest + "&marketingcode=" + marketingData + "&promocode=" + promoData,
							   success: function(data){								   
								   		var visID = jQuery.parseJSON(data);	
										delCookie('visID');
						   				SetCookie('visID',visID.visID,5);
										window.location.href = "#" + step;
										$("hVisID").attr("value", visID.visID);
										var sID = $("#sID").val();										

										$.ajax({
										   type: "POST",
										   url: "/inc/steps/stpChckr.php",
										   data: theData + "&sID=" + sID + "&visID=" + visID.visID + "&stp=" + step, 
										   success: function(tdata){	
													$(".marketContent").empty();
													$(".marketContent").append(tdata);
													$(".marketContent").css("opacity", 1);;
													$(".marketContent").fadeIn("fast");
													$(".ProcessMessage").fadeOut("fast");
													$(".marketContentCover").fadeOut("slow"); 
													$("#formGreenButton").fadeOut("fast");
													fxStp(step);
													
													if(step=='three'){
													
														$("#formRedButton").fadeOut("fast");
													
													}
										   }
										});
							   }							   
							});
					   }else{
						
							if(obj.warning){
								
								
								$(".warningMessage").append("<br /><br /><strong>" + obj.warning + "</strong>");
							
							}

							$(".ProcessMessage").fadeOut("slow");
							$(".marketContentCover").fadeOut("slow"); 
							window.location.href = "#one";
							$(".marketContent").css("opacity", 1);
							$("#errorMessage").slideDown("fast");
							$("#address").css("background", '#FFD9D9');
							$("#address").closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
							$("#address").removeClass("intVal");
							$("#address").addClass("intInval");
							$("#city").css("background", '#FFD9D9');
							$("#city").closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
							$("#city").removeClass("intVal");
							$("#city").addClass("intInval");
							$("#state").css("background", '#FFD9D9');
							$("#state").closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
							$("#state").removeClass("intVal");
							$("#state").addClass("intInval");
							$("#zip").css("background", '#FFD9D9');
							$("#zip").closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
							$("#zip").removeClass("intVal");
							$("#zip").addClass("intInval");
						   
					   }
				   }
			});
			
			
		}else{
		
			if(num==1){
			alert("Please Fill out the Required Fields. There is "+num+" error!");	
			}else{
			alert("Please Fill out the Required Fields. There are "+num+" errors!");			
			}
			num=0;
		}
		
				
	});
									 
	
  
  	$(".lrgInpt").bind("keyup", function() {
		
			var D = $(this).attr("value");
			var name = $(this).attr("name");
			
		if($(this).hasClass("required")){			
		
			if(name=='email'){
				   var reg = /^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$/;
				   if(reg.test(D) == false) {
						$(this).closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
						$(this).removeClass("intVal");
						$(this).addClass("intInval");
					}else{
						$(this).css("background", "#FFFFFF");
						$(this).css("background-image", "url(/img/bg_input.png)");
						$(this).closest(".blltList").css("background-image", "url(/img/blltListGreen.png)");
						$(this).removeClass("intInval");
						$(this).addClass("intVal");
					}
			}else if(D!=""){
				$(this).css("background", "#FFFFFF");
				$(this).css("background-image", "url(/img/bg_input.png)");
				$(this).closest(".blltList").css("background-image", "url(/img/blltListGreen.png)");
				$(this).removeClass("intInval");
				$(this).addClass("intVal");
				//$(this).closest(".blltList").css("background", "#000000");
			}else{
				$(this).closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
				$(this).removeClass("intVal");
				$(this).addClass("intInval");
			}
		} 
		
	})
	$(".dropDown").change(function() {
										   
			var Q = $(this).attr("value");

			if(Q!=""){
				$(this).css("background", "#FFFFFF");
				$(this).css("background-image", "url(/img/bg_input.png)");
				$(this).closest(".blltList").css("background-image", "url(/img/blltListGreen.png)");
				$(this).removeClass("intInval");
				$(this).addClass("intVal");
				//$(this).closest(".blltList").css("background", "#000000");
			}else{
				$(this).closest(".blltList").css("background-image", "url(/img/blltListRed.png)");
				$(this).removeClass("intVal");
				$(this).addClass("intInval");
			}
								
	});	

		
		$(".seminarInfoLink").live("click", function(){		
		
				var showDetails = $(this).attr("title");
				$("#"+showDetails).toggle();
		
		});
		$(".seminarInfoLink").click(function(){		
		
				var smDetails = $(this).attr("title");
				$("#seminarDetails_"+smDetails).toggle();
		
		});
		
	
	$("#showLocator .submit").click(function(){
		var data = $("#locateZip").val();
		var h = $("#showLocatorWrp").height();

		
		if(data!='' && data!=null && data!='undefined' && data!=' '){
			$("#showLocatorWrp").css("height", h);								   
			$("#showLocator").fadeOut("fast");
			$("#showLocator").empty();
			$("#showLocator").append('<img src="../img/loading.gif" />');
			$("#showLocator").fadeIn("fast");
				$.ajax({
					   type: "POST",
					   url: "/inc/showLocate.php",
					   data: 'lz='+data, 
					   success: function(data){
							$("#showLocator").fadeOut("fast");
							$("#showLocator").empty();
							//$("#showLocator").append(data);
							//$("#showLocator").fadeIn("fast");
							alert(data);
					   }
				});
		}else{
			alert("Please Enter A Zip Code");
		}
	});	
	$("#showLocator input").bind("focus", function(){
		$(this).next(".submit").each(function(){
			$(this).fadeIn("fast");
		});
	});
	
	setInterval("checkAnchor()", 300);
	
	var cVisID = Get_Cookie('visID');
	
	if(!cVisID){
	
		var cVisID = $("#hVisID").attr("value");
		
		if(cVisID){
			
			if(cVisID!=null || cVisID!='null'){
		
				delCookie('visID');
				SetCookie('visID',cVisID,5);
			
			}
			
		}
				
	}
	
	$(".numInPartyC").live("click", function(){
	
		$(this).addClass("numInPartyChover");

		var clicked = $(this).attr("id");
		
		var num = $(this).attr("title");
		switch(num) {
			case 1:
				$("#TwoParty").removeClass("numInPartyChover");
				$("#ThreeParty").removeClass("numInPartyChover");
				$("#FourParty").removeClass("numInPartyChover");
				break;
			case 2:
				$("#OneParty").removeClass("numInPartyChover");
				$("#ThreeParty").removeClass("numInPartyChover");
				$("#FourParty").removeClass("numInPartyChover");
				break;
			case 3:
				$("#OneParty").removeClass("numInPartyChover");
				$("#TwoParty").removeClass("numInPartyChover");
				$("#FourParty").removeClass("numInPartyChover");
				break;
			case 4:
				$("#OneParty").removeClass("numInPartyChover");
				$("#TwoParty").removeClass("numInPartyChover");
				$("#ThreeParty").removeClass("numInPartyChover");
		}
		
		var num = $(this).attr("title");
		
		$("#numInParty").attr("value", num);

	
	});

});



