// JavaScript Document
var cmMonthArray = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
$(document).ready(function(){
//Start JQuery Code

	//Initialization
    var beenHit = false;
    var beenHit2 = false;

	//Primary Nav hover
	$("#primarynav li a img").hover(	
		function() {			
			off_img = $(this).attr("src");			
			over_img = off_img.replace("off/","on/");																			
			$(this).attr("src", over_img);		
		},		
		function() {		
			$(this).attr("src", off_img);
		}
	);	
	
	//Button Hovers
	$("a.getquote img, .submit, .quantitybutton").hover(	
		function() {			
			off_img = $(this).attr("src");			
			over_img = off_img.replace("off/","on/");																			
			$(this).attr("src", over_img);		
		},		
		function() {		
			$(this).attr("src", off_img);
		}
	);
	
	$("#printlink").click(	
		function() {			
		 window.print();
		}
	);	
	$("#printlink2").click(	
		function() {			
		 window.print();
		}
	);

	//Five Questions
	$("#hpbottom div.col_a li a img").hover(	
		function() {			
			off_img = $(this).attr("src");			
			over_img = off_img.replace("off/","on/");																			
			$(this).attr("src", over_img);	
			beenHit = false;
		},		
		function() {	
            if (beenHit == false){	
				$(this).attr("src", off_img);
			};
		}
	);


	function sweeper() {
		$("#question1").css("display","none");
		$("#question2").css("display","none");	
		$("#question3").css("display","none");	
		$("#question4").css("display","none");	
		$("#question5").css("display","none");	
		$("#qbutton1").attr("src", $("#qbutton1").attr("src").replace("selected/","off/"));	
		$("#qbutton2").attr("src", $("#qbutton2").attr("src").replace("selected/","off/"));	
		$("#qbutton3").attr("src", $("#qbutton3").attr("src").replace("selected/","off/"));	
		$("#qbutton4").attr("src", $("#qbutton4").attr("src").replace("selected/","off/"));	
		$("#qbutton5").attr("src", $("#qbutton5").attr("src").replace("selected/","off/"));	
	}

	$("#hpbottom div.col_a li a").click(function(){
		var anchor = $(this).attr("href").replace("#","");
		if (anchor != "faq.html") sweeper(); //Changed 2/27/08
		switch(anchor) {
			case "question1": $("#question1").css("display","block"); break;
			case "question2": $("#question2").css("display","block"); break;
			case "question3": $("#question3").css("display","block"); break;
			case "question4": $("#question4").css("display","block"); break;
			case "question5": $("#question5").css("display","block"); break;
			default: $(this).attr("href"); break;
		}
		$(this).children().attr("src", $(this).children().attr("src").replace("on/","selected/"));
		beenHit = true;
		return false;
	});	

	//Outside Links
	$("a.target").click(function(){
		window.open($(this).attr("href"));
		return false;
	});	
	
	$("a.aatarget").click(function(){
		window.open($(this).attr("href"),'','width=500,height=490,resizable=yes');
		return false;
	});	
	
	//Homepage Benefits Feature

	//Initialize
	$("#benefitsfeature").load("benefitsfeature/benefit_1.html");

	//Rollovers/Selected States
	$("#benefitsnav a img").hover(	
		function() {			
			off_img = $(this).attr("src");			
			over_img = off_img.replace("off/","on/");																			
			$(this).attr("src", over_img);	
			beenHit2 = false;
		},		
		function() {	
            if (beenHit2 == false){	
				$(this).attr("src", off_img);
			};
		}
	);

	//Click/AJAX Function
	$("#benefitsnav a").click(function(){

		$("#benefit1").children().attr("src", $("#benefit1").children().attr("src").replace("on/","off/"));
		$("#benefit2").children().attr("src", $("#benefit2").children().attr("src").replace("on/","off/"));
		$("#benefit3").children().attr("src", $("#benefit3").children().attr("src").replace("on/","off/"));

		$(this).children().attr("src", $(this).children().attr("src").replace("off/","on/"));
		$("#benefitsfeature").load($(this).attr("href"));
		beenHit2 = true;
		return false;
	});		

	//Close/Open Window
	$("div.productnotify a.closewindow").click(function(){
		$("div.productnotify").css("display","none");
		removeOverlay();
		return false;
	});

	$("div.packagenotify a.closewindow").click(function(){
		$("div.packagenotify").css("display","none");
		return false;
	});

	$("a.viewcoverage").click(function(){
		$("div.packagenotify").css("display","block");
		return false;
	});

	$(".purchasebox a.closewindow").click(function(){
		$(this).parent().parent().css("display","none");
		return false;
	});


	//Dropdown Menu
	var t;

	$("a#annualproduct img").mouseover(function(){
		$("div#annual").css("display","block");						
	});	
	$("div#annual").mouseout(function(){
		t = setTimeout("$('div#annual').css('display','none')", 200);
	});	
	$("div#annual").mouseover(function(){
		clearTimeout(t);
	});	

	
	//Zebra Tables (Grid) - Changed 7/21/08
	if ($("body").attr("class") == "grid") {
		$("table tr:even").addClass("even");
		$("table td:last-child").css("border-right", "none");
		$("table th:last-child").css("border-right", "none");
		$("table tr#theader th:last-child").css("border-right", "1px solid #B1BBB2");
		$("table tr#selection th:last-child").css("border-right", "1px solid #B1BBB2");
		$("table tr#triplength td:last-child").css("border-right", "1px solid #B1BBB2");
	}
	
	//Grid Functionality	

	//Benefits - Removed 7/16/08

	/*if ($("body").attr("class") == "grid") {
		//Initialization
		var defaultvalue = "benefit_3";
		var defaultarray = "benefit_1|benefit_2|benefit_3|benefit_4|";
		var list = new Array();
		var initial = Get_Cookie('grid');
		if ((initial == null) || (initial == '')) {
			list[0] = defaultvalue;
			Set_Cookie('grid', defaultvalue + "|", '', '', '', '' );
		} else {
			list = initial.split('|');
			list.pop();
		};
		
		for(i=0;i<list.length;i++) {
			if ($.browser.msie) $("#gridbox tr." + list[i]).css("display","inline");		
			else $("#gridbox tr." + list[i]).css("display","table-row");
			$("#gridbox th#" + list[i] + " a").css("background","transparent url(images/lists/benefits_select_arrow.gif) no-repeat 0px 3px");
			$("#gridbox th#" + list[i] + " a").css("padding-left","20px");
		}
	
		//Click Functionality
		$("#gridbox tr.benefits th.rowheader a").click(
			function() {			
				var name = $(this).parent().attr("id");
				var state = $("#gridbox tr." + name).css("display");
				var ctest = Get_Cookie('grid');
				if (state == "none") {	
					$(this).css("background","transparent url(images/lists/benefits_select_arrow.gif) no-repeat 0px 3px")
					$(this).css("padding-left","20px")
					if ($.browser.msie) $("#gridbox tr." + name).css("display","inline");		
					else $("#gridbox tr." + name).css("display","table-row");
					if (ctest == null) ctest = '';
					else ctest = ctest + name + "|";
				} else {	
					$(this).css("background","transparent url(images/lists/benefits_arrow.gif) no-repeat 0px -1px")
					$(this).css("padding-left","14px")		
					$("#gridbox tr." + name).css("display","none");	
					var ctest = Get_Cookie('grid');
					if (ctest != null) {
						param = name + "|";
						var ctest = ctest.replace(param,"");
					}
				};
				Set_Cookie('grid', ctest, '', '', '', '' );
				return false;
			}
		);
	
		//Expand/Collapse Grids
		$("a#openall").click(function() {	
			$("#gridbox tr.benefits th.rowheader a").css("background","transparent url(images/lists/benefits_select_arrow.gif) no-repeat 0px 3px")
			$("#gridbox tr.benefits th.rowheader a").css("padding-left","20px")
			if ($.browser.msie) $("#gridbox tr.details").css("display","inline");		
			else $("#gridbox tr.details").css("display","table-row");	
			Set_Cookie('grid', defaultarray, '', '', '', '' );	
		});
	
		$("a#closeall").click(function() {	
			$("#gridbox tr.benefits th.rowheader a").css("background","transparent url(images/lists/benefits_arrow.gif) no-repeat 0px -1px")
			$("#gridbox tr.benefits th.rowheader a").css("padding-left","14px")	
			$("#gridbox tr.details").css("display","none");
			Set_Cookie('grid', '', '', '', '', '' );
		});

	};	*/
	
	//Description Rollovers - Added 7/16/08
	$("th.rowheader a").hover(	
		function() {			
			$(this).siblings('.productnotify').css('display','block');
		},		
		function() {	
			$(this).siblings('.productnotify').css('display','none');
		}
	);	

	//Medical Evac Select/Form Window - Changed 7/16/08
	function me_cleaner() {
		$(".me1").css("display","none");
		$(".me2").css("display","none");
		$(".me3").css("display","none");
	};

	$('form.mevaclength select').attr("value", "3");

	$('form.mevaclength select').change(function(){			
										
		me_cleaner();
		var test = $(this).attr("value");
		switch(test) {
			case "3": 
				if ($.browser.msie) $(".me1").css("display","inline"); 
				else $(".me1").css("display","table-cell"); 
				$('.me1 form.mevaclength select').attr("value", "3");				
			break;
			case "6": 
				if ($.browser.msie) $(".me2").css("display","inline"); 
				else $(".me2").css("display","table-cell");
				$('.me2 form.mevaclength select').attr("value", "6");				
			break;
			case "12": 
				if ($.browser.msie) $(".me3").css("display","inline"); 
				else $(".me3").css("display","table-cell");
				$('.me3 form.mevaclength select').attr("value", "12");				
			break;
		};

      });
	
	//Family Select/Form Window - Changed 7/21/08
	function family_cleaner() {
		$(".family1").css("display","none");
		$(".family2").css("display","none");
		$(".family3").css("display","none");
		$(".family4").css("display","none");
		$(".family5").css("display","none");		
	};

    
	//$('.family2 form.familylength select').attr("value", "0");
	
	/* Sets the family column to default to the 1500 values */
	$(".family1").css("display","none");
	$(".family2").css("display","inline");
	$(".family3").css("display","none");
	$(".family4").css("display","none");
	$(".family5").css("display","none");
	if ($.browser.msie) $(".family2").css("display","inline"); 
	else $(".family2").css("display","table-cell");	
                     

	$('form.familylength select').change(function(){													
		family_cleaner();
		var test2 = $(this).attr("value");
		
		switch(test2) {
			case "0": 
				if ($.browser.msie) $(".family1").css("display","inline"); 
				else $(".family1").css("display","table-cell"); 
				$('.family1 form.familylength select').attr("value", "0");					
			break;
			case "1500": 
				if ($.browser.msie) $(".family2").css("display","inline"); 
				else $(".family2").css("display","table-cell");
				$('.family2 form.familylength select').attr("value", "1500");				
				
			break;
			case "5000": 
				if ($.browser.msie) $(".family3").css("display","inline"); 
				else $(".family3").css("display","table-cell");
				$('.family3 form.familylength select').attr("value", "5000");				
			break;
			case "10000": 
				if ($.browser.msie) $(".family4").css("display","inline"); 
				else $(".family4").css("display","table-cell");
				$('.family4 form.familylength select').attr("value", "10000");				
			break;
			case "15000": 
				if ($.browser.msie) $(".family5").css("display","inline"); 
				else $(".family5").css("display","table-cell");
				$('.family5 form.familylength select').attr("value", "15000");				
			break;			
		};

      });	

	//Th Rollovers - Removed 7/16/08
	/*$("tr#selection th, tr#triplength td").css("cursor","pointer");

	$("tr#triplength td").hover(	
		function() {			
			$(this).css("background-color","#F8E6A0");
			var color = $(this).children("a.selectpackage").attr("id");
			$("tr#selection th strong." + color).parent().css("background-color","#F8E6A0");
			$("tr#selection th strong." + color).parent().css("background-image","none");
		},		
		function() {	
			$(this).css("background-color","#FAFAF9");
			var color = $(this).children("a.selectpackage").attr("id");
			$("tr#selection th strong." + color).parent().css("background-color","#FAFAF9");
			$("tr#selection th strong." + color).parent().css("background-image","url(images/backgrounds/thpcheader_background.jpg)");
		}
	);

	$("tr#selection th").hover(	
		function() {			
			$(this).css("background-color","#F8E6A0");
			$(this).css("background-image","none");
			var color = $(this).children("strong").attr("class");
			$("tr#triplength td a#" + color).parent().css("background-color","#F8E6A0");
		},		
		function() {	
			$(this).css("background-color","#FAFAF9");
			$(this).css("background-image","url(images/backgrounds/thpcheader_background.jpg)");
			var color = $(this).children("strong").attr("class");
			$("tr#triplength td a#" + color).parent().css("background-color","#FAFAF9");
		}
	);*/

	//Form popup - Changed 7/16/08
	$("tr#triplength td a.selectpackage").click(function(){
		var formname = $(this).attr("id");
		$("tr#theader form#" + formname + "form").css("display","block");
		return false;		
	});

	$("tr#triplength td form").click(function(){
		return false;
	});
	
	$("tr#triplength2 td a.selectpackage").click(function(){
		var formname = $(this).attr("id");
		$("tr#theader2 form#" + formname + "form").css("display","block");
		return false;		
	});

	$("tr#triplength2 td form").click(function(){
		return false;
	});	

	//Removed 7/16/08
/*	$("tr#selection th").click(function(){
		var formname = $(this).children("strong").attr("class");
		$("tr#theader form#" + formname + "form").css("display","block");
	});
*/
	//Coverage Description Window - Changed 2/26/08
	$("tr#theader a.help").hover(
		function(){
			var notifybox = $(this).attr("id");
			$("tr#theader div." + notifybox).css("display","block");
			return false;
		},		
		function() {
			var notifybox = $(this).attr("id");
			$("tr#theader div." + notifybox).css("display","none");
		}
	);

	//Form submit - Sidebar/Content Pages - Changed 2/28/08  
	$('#mevaclength2 select').attr("value", "3");

	$('#mevaclength2 select').change(function(){	
						
		var test = $(this).attr("value");
		
		switch(test) {
			case "3": 				
				$("#sidebar div.me1").html($("#meval1").html());				
				$('#sidebar #productID').val('001001163');
			break;
			case "6": 			   		
				$("#sidebar div.me1").html($("#meval2").html());
				$('#sidebar #productID').val('001001209');
				
			break;
			case "12": 
				$("#sidebar div.me1").html($("#meval3").html());	
				$('#sidebar #productID').val('001001236');
			break;
		}; 
		
      });
	
	//Family Extension - Changed 7/21/08
	$('#familylength2 select').change(function(){						
		var test2 = $(this).attr("value");		
		switch(test2) {
			case "0": 				
				$("#sidebar div.family1").html($("#familyval1").html());				
				$('#sidebar #productID').val('001001950');
				$('#familyproductform #productID').val('001001950');
			break;
			case "1500": 			   				
				$("#sidebar div.family1").html($("#familyval2").html());
				$('#sidebar #productID').val('001001951');
				$('#familyproductform #productID').val('001001951');
			break;
			case "5000": 
				$("#sidebar div.family1").html($("#familyval3").html());	
				$('#sidebar #productID').val('001001952');
				$('#familyproductform #productID').val('001001952');
			break;
			case "10000": 
				$("#sidebar div.family1").html($("#familyval4").html());	
				$('#sidebar #productID').val('001001953');
				$('#familyproductform #productID').val('001001953');
			break;
			case "15000": 
				$("#sidebar div.family1").html($("#familyval5").html());	
				$('#sidebar #productID').val('001001954');
				$('#familyproductform #productID').val('001001954');
			break;			
		}; 

      });	

	// Left Side Nave - Submit Functionality
	$("ul.productcompare li a.selectpackage").click(function(){			
		$(this).siblings("form.productform").submit();
		return false;
	});
		
	//Text Field Forms (Purchase Path)
	$("#quotebox input:text").focus(function(){		
		if($(this).val() == "Enter Text" || $(this).val() == "MM/DD/YYYY" || $(this).val() == "xxx-xxx-xxxx" || $(this).val() == "xxxxx") {
		 $(this).attr("value","");
		}
		else {
		 $(this).select();
		}
		$(this).css("color","black");
	});		
	
	$("#quotebox input:text").css("color","black");
	$("#quotebox input[value='Enter Text']").css("color","#999999");
	$("#quotebox input[value='MM/DD/YYYY']").css("color","#999999");
	$("#quotebox input[value='MM/YYYY']").css("color","#999999");	
	$("#quotebox input[value='xxx-xxx-xxxx']").css("color","#999999");
	$("#quotebox input[value='xxxxx']").css("color","#999999");

	//Calendar
	if ($('form').attr('id') == "purchaseForm") $('#coverage_date').attachDatepicker({showOn: 'both', buttonImage: 'images/icons/calendar.gif', buttonImageOnly: true, buttonText: 'Select Date'}); 
	
	if(document.getElementById('purchaseForm')) {
	 $('#purchaseForm').submit(function(){
										
	  if(validatePurchaseForm()) {	
	    $("#quotebox input[value='Enter Text']").val(''); 
		document.getElementById('purchaseForm').submit();		
	  }	  	  
	  return false;
	 });
	 
	  $('#delivery_policy_1').click(function(){
	    $('#same_address_container').hide();	
		$('#shippingInformationContainer').hide();	
		$('#same_address').attr('checked','checked');		
      });
	  
	  $('#delivery_policy_2').click(function(){
	    $('#same_address_container').show();								
      });	  
	  
	  
	   $('#same_address').click(function(){			 
		if(!$('input[name="same_address"][checked]').val()) {		 
		  $('#shippingInformationContainer').show();
		}
		else {
		  $('#shippingInformationContainer').hide();	
		}
	   								
      });
	  
	  $('#quantity').change(function(){
		reCalculatePrice();
		var displayTotal = parseInt($(this).val());
		for(var x = 1; x < 11; x++) {
		 if(x <= displayTotal) {
			$('#travlerContainer'+x).show();
		 }
		 else {
			$('#travlerContainer'+x).hide();  
		 }
		}		
								 
      });									 
	   
	 
	}
	
	$("#startNewQuoteLnk").click(function(){
	   if(confirm("Are you sure you would like to start a new quote?  All data previously entered will be lost.")) {									  
        Delete_Cookie('CUSTOMERID');	  
        window.location='get-a-quote.html';  			
	   }
	});	
	
	$("#reviewForm").submit(function(){
	  purchaseProduct();
	});	
	
	//Added 2/26/08 - MedEvac Form/Product Page  
	$("#mevaclength3 select[name='me_duration']").attr("value", "3");

	function me_cleaner2() {
		$("#mevaclength3 .me1").css("display","none");
		$("#mevaclength3 .me2").css("display","none");
		$("#mevaclength3 .me3").css("display","none");
	};


	$("#mevaclength3 select[name='me_duration']").change(function(){																		
		me_cleaner2();
		var test = $(this).attr("value");
		var cost = "";
		var value = "";
		switch(test) {
			case "3": 
						$("#mevaclength3 .me1").css("display","block"); 
						cost = $("#mevaclength3 .me1 span").html();
						value = $("#mevaclength3 .me1 span").text();      
						$('#mevaclength3 #productID').val('001001163');              
			break;
			case "6": 
						$("#mevaclength3 .me2").css("display","block"); 
						cost = $("#mevaclength3 .me2 span").html();
						value = $("#mevaclength3 .me2 span").text();
						$('#mevaclength3 #productID').val('001001209');
			break;
			case "12": 
						$("#mevaclength3 .me3").css("display","block"); 
						cost = $("#mevaclength3 .me3 span").html();
						value = $("#mevaclength3 .me3 span").text();
						$('#mevaclength3 #productID').val('001001236');
			break;
		};
	
		$("#mevaclength3 input[name='cost']").attr("value",value.replace("$",""));              
      });
	
	//Changed 7/21/08 - Family Form/Product Page  
	$("#familylength3 select[name='family_duration']").attr("value", "0");

	function family_cleaner2() {
		$("#familylength3 .family1").css("display","none");
		$("#familylength3 .family2").css("display","none");
		$("#familylength3 .family3").css("display","none");
		$("#familylength3 .family4").css("display","none");
		$("#familylength3 .family5").css("display","none");		
	};


	$("#familylength3 select[name='family_duration']").change(function(){								
		family_cleaner2();
		var test2 = $(this).attr("value");
		var cost2 = "";
		var value2 = "";
		switch(test2) {
			case "0": 
						$("#familylength3 .family1").css("display","block"); 
						cost2 = $("#familylength3 .family1 span").html();
						value2 = $("#familylength3 .family1 span").text();      
						$('#familylength3 #productID').val('001001950');              
			break;
			case "1500": 
						$("#familylength3 .family2").css("display","block"); 
						cost2 = $("#familylength3 .family2 span").html();
						value2 = $("#familylength3 .family2 span").text();
						$('#familylength3 #productID').val('001001951');
			break;
			case "5000": 			           
						$("#familylength3 .family2").css("display","block"); 
						cost2 = $("#familylength3 .family3 span").html();
						value2 = $("#familylength3 .family3 span").text();
						$('#familylength3 #productID').val('001001952');
			break;
			case "10000": 
						$("#familylength3 .family4").css("display","block"); 
						cost2 = $("#familylength3 .family4 span").html();
						value2 = $("#familylength3 .family4 span").text();
						$('#familylength3 #productID').val('001001953');
			break;
			case "15000": 
						$("#familylength3 .family5").css("display","block"); 
						cost2 = $("#familylength3 .family5 span").html();
						value2 = $("#familylength3 .family5 span").text();
						$('#familylength3 #productID').val('001001954');
			break;			
		};
	
		$("#familylength3 input[name='cost']").attr("value",value2.replace("$",""));              
      });	
			
	  $("#billingState").change(	
		function() {	
		 clearErrors();
		 $.get('/actions/_checkStateExclusion.cfm?UID='+getUID()+'&productID='+$('#productID').val()+'&state='+$('#billingState').val(), 
         function(result) { 		 
		   if(result.indexOf("|result|checkforstateexclusion|yes|") != -1) {
			addError('billingState',"We're sorry, but we cannot offer the product you selected. Unable to buy due to state of residence.  The state of <strong>"+$('#billingState').val()+"</strong> does not allow the sale of annual insurance. Please visit <a href='http://www.accessamerica.com'>AccessAmerica.com</a> to get a quote on per-trip insruance that's right for you.");   
			displayErrorsMsgs();
		   }		
         }); 
		}		
 	  );

	
	
	
	/* 
	$("div.items ul li a").hover(	
		function() {			   
			$(this).siblings('.productnotify').css('top','0px');
			$(this).siblings('.productnotify').css('margin-left','-460px');		
			$(this).siblings('.productnotify').css('display','block');
		},		
		function() {	
			$(this).siblings('.productnotify').css('display','none');
		}
	);	
	*/
	

//End JQuery Code
});

function reCalculatePrice() {
	
	$.get('/actions/_getProductPricing.cfm?UID='+getUID()+'&productID='+$('#productID').val()+'&quantity='+$('#quantity').val(), 
         function(result) {
				   $('#productPriceTxt1').html($.trim(result));
				   $('#productPriceTxt2').html($.trim(result));
		
         }); 
}