// JavaScript Document

//--START--Checks to see if there is a cookie associated with the page
$(document).ready(function(){
	   				
		//--START--These are gettin pulled in onReady however they could be pulled through direct JavaScript when the JavaScript load in order on the page
				zip=getCookie('zip');
				age0=getCookie('age0');
				tobacco0=getCookie('tobacco0');
				plan=getCookie('plan');	
				gender0=getCookie('gender0');
		//--End--These are gettin pulled in onReady however they could be pulled through direct JavaScript when the JavaScript load in order on the page
						   
		 $('#age0').change(function(){
				
				var age0;
				age0 = $('#age0').val();
				setCookie('age0',age0,365);
			});	
		 
		 $('#gender0').change(function(){
				
				var gender0;
				gender0 = $('#gender0').val();
				setCookie('gender0',gender0,365);
			});	
		 
		 $('#tobacco0').change(function(){
				
				var tobacco0;
				tobacco0 = $('#tobacco0').attr("checked");
				setCookie('tobacco0',tobacco0,365);
				
			});
						
});


function getCookie(c_name)
	{
		if (document.cookie.length>0)
		  {
		  c_start=document.cookie.indexOf(c_name + "=");
			  if (c_start!=-1)
				{
					c_start=c_start + c_name.length+1;
					c_end=document.cookie.indexOf(";",c_start);
					if (c_end==-1) c_end=document.cookie.length;
					return unescape(document.cookie.substring(c_start,c_end));
				}
		  }
		return "";
	}
//--End--Checks to see if there is a cookie associated with the page

//--Start--Checks to see if zip code cookie exists


function checkCookie(){
	
	//attempt to retrieve zip cookie
	zip=getCookie('zip');
	
	if (zip!=null && zip!="")
	  {
		//if its there run confimation and then calculate results
	  confirmation();
	  calcResults();
	  }
	else
	  {
		  //if zip cookie is not there redirect to zip.html so they can enter it
		  window.location = "zip.html"
		  //set a value to the zip code cookie to prevent the zip code redirect from looping on the zip page.  This is a bug that needs to be addressed after testing.
		  setCookie('zip',00000,365);
//   This can be turned on to override the anti deep linking feature of this script.  
//	   zip=prompt('Please enter your zip:',"");
	//	    if (zip!=null && zip!="")
	//		{
	//		setCookie('zip',zip,365);
	//		}
	  }
}
//--End--Checks to see if zip code cookie exists

function setCookie(c_name,value,expiredays)
{
	var exdate=new Date();
	exdate.setDate(exdate.getDate()+expiredays);
	document.cookie=c_name+ "=" +escape(value)+
	((expiredays==null) ? "" : ";path=/;expires="+exdate.toGMTString());
}
