﻿$(document).ready(function() {
	  $(function() {
		$("#tabs").tabs();
	});
	$(".thetabs").click(function(){
		var thetab = $(this).attr("id");
		self.document.location.hash=thetab+"id";  //the id is the key so it doesn't match any bookmarks currently on the page.
		return false;
		
	});
	
	 	if (self.document.location.hash.substring(1)!=''){
	 		var thetab=self.document.location.hash.substring(1);
	 		switch(thetab){
	 			case "abouttabid":
	 				$("#tabs").tabs('option', 'selected', 0);
	 				break;
	 			case "signuptabid":
	 				$("#tabs").tabs('option', 'selected', 1);
	 				break;
	 			case "jointabid":
	 				$("#tabs").tabs('option', 'selected', 2);
	 				break;
	 			case "grouptabid":
	 				$("#tabs").tabs('option', 'selected', 3);
	 				break;

		 		}
		
 		}
	
	$("#signupnow").click(function() {
		$("#tabs").tabs('option', 'selected', 1); //this makes the 2nd tab selected
	});
	$("#enrollingroup").click(function() {
		$("#tabs").tabs('option', 'selected', 2); //this makes the 3nd tab selected
	});
	$("#enrollingroup2").click(function() {
		$("#tabs").tabs('option', 'selected', 2); //this makes the 3nd tab selected
	});

	$("#signupsubmit").click(function(){
		var firstinitial = $("#firstname").val();
		firstinitial=firstinitial.substring(0,1);
		var lastinitial=$("#lastname").val();
		lastinitial=firstinitial+lastinitial.substring(0,1);
		lastinitial=lastinitial.toUpperCase();
		$("#spamhide").val(lastinitial);
		var thespam=$("#spam").val();
		thespam=thespam.toUpperCase()
		$("#spam").val(thespam);
		
		});
		
	$("#formsignup").validate({
	    rules: { 
	      firstname: "required",
	      lastname: "required",    // simple rule, converted to {required: true} 
	      organization: "required",
	      phone: "required",
	      email:{
	      	required: true,
	      	email: true
				},
			spam: "required",
			spamhide: {
				required: true,
				equalTo: "#spam"
				}
		 },
	      messages: {
		      	spam: "your initials"
	      },
	      submitHandler: function() {
			//run form and send email to mike@inidaho.com
			var formdata=$("#formsignup").serialize();
				$.ajax({
				type: "POST",
				url: "traveltogether_a.asp",
				data: formdata,
				timeout: 2000,
				error: function () {
						alert('Sorry, we experienced an error.\nPlease call us at 1-800-844-3246');
				},
				success: function (data) {
					$("#formbox").hide();
					$("#thankyousignup").show("slow");
					}
				});
			
			}//submitHandler end
	  }); 
	   $("#joinsubmit").click(function(){
		var firstinitial = $("#jfirstname").val();
		firstinitial=firstinitial.substring(0,1);
		var lastinitial=$("#jlastname").val();
		lastinitial=firstinitial+lastinitial.substring(0,1);
		lastinitial=lastinitial.toUpperCase();
		$("#jspamhide").val(lastinitial);
		var thespam=$("#jspam").val();
		thespam=thespam.toUpperCase()
		$("#jspam").val(thespam);
		
		});
		
	$("#formjoin").validate({
	    rules: { 
	      _firstname: "required",
	      _lastname: "required",    // simple rule, converted to {required: true} 
	      _organization: "required",
	      _phone: "required",
	      _email:{
	      	required: true,
	      	email: true
				},
		  _spam: "required",
		  _spamhide: {
				required: true,
				equalTo: "#jspam"
				}
		 },
	      messages: {
		      	_spam: "your initials"
	      },
	      submitHandler: function() {
			//run form and send email to mike@inidaho.com
			var formdata=$("#formjoin").serialize();
				$.ajax({
				type: "POST",
				url: "traveltogether_a.asp",
				data: formdata,
				timeout: 2000,
				error: function () {
						alert('Sorry, we experienced an error.\nPlease call us at 1-800-844-3246');
				},
				success: function (data) {
					$("#joinformbox").hide();
					$("#thankyoujoin").show("slow");
					}
				});
			
			}//submitHandler end
	  }); 

});

