var ctjoin = "http://www.aaa.com/aaa/240/sne/membership/joinaaa_ct.html";
var ctgift = "http://www.aaa.com/aaa/240/sne/membership/giftmembership_ct.html";
var ctbenefits = "http://www.aaact.com/sne/CTMCAAA20.Nsf/vwWeb/Benefits?open";
var ctautoguide = "http://www.aaact.com/Resources.Nsf/vwWeb/ERSGuideLines/$File/ERSGuideLines.pdf";
var cthr = "http://www.aaa.com/aaa/240/sne/jobs/index.html";
var rihr = "http://www.aaa.com/aaa/240/sne/jobs/index.html";
var riautoguide = "http://www.aaa.com/aaa/240/sne/membership/benefits/benefits.html";
var ribenefits = "http://www.aaa.com/aaa/240/sne/membership/benefits/benefits.html";
var rijoin = "http://www.aaa.com/aaa/240/sne/membership/joinaaa.html";
var rihr2 = "http://www.aaa.com/aaa/240/sne_ct/jobs/index.html";
var riautoguide2 = "http://www.aaa.com/aaa/240/sne_ct/membership/benefits/benefits.html";
var ribenefits2 = "http://www.aaa.com/aaa/240/sne_ct/membership/benefits/benefits.html";
var rijoin2 = "http://www.aaa.com/aaa/240/sne/membership/joinaaa.html";
var selectstate = "http://stager.aaasneconnect.com/site/membership/select_state.php";
var holdstatevalue = "";
var istest = 0; // Set to 1 to display the value of the holdstatevalue variable, set to 0 (zero) to turn off this function.
var mytest = 0; // Set to 1 to use the test values, set to 0 (zero) to use the production values.
function getCookieVal(offset)
{
// Returns only the data for a cookie.
   var endstr = document.cookie.indexOf(";",offset);
   if (endstr == -1) endstr=document.cookie.length;
   return unescape(document.cookie.substring(offset,endstr));
}
function GetCookie(name)
{
// Returns all data for a specific cookie whose name is passed as an argument.
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;  // document.cookie contains all cookies set by a specific domain.
   var i = 0;
   while (i < clen)
   {
     var j = i + alen;
     // Walks all cookies to match on the name passed as an argument to this function.
     if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
     i = document.cookie.indexOf(" ", i) + 1;
     if (i == 0) break;
   }
   return null;
}
function dogetZD()
{
   var startIndex = 0;
   var ct="CT";
   var ma="MARI";
   var none="other";
   var hold;
   // Get the values of a specific cookie. Just chnage the name passed to the function to get any cookie value.
   var cookieData = GetCookie("zipcode");
   // Make sure the specific cookie was found.
   if(cookieData != null)  // Yes it was found.
   {
	// Set what the delimiter is of the cookie data.
	pipe = cookieData.indexOf("|");
	// Display all of the cookie data.
	zipcodedata = cookieData;
	// Parse out just the data you want, using the delimiter.
	foundZipCode = cookieData.substring(startIndex, pipe);
	// Get just the specific number of characters from the parsed data.
	firsttwo = foundZipCode.substring(0,2)
	if ((firsttwo=="02")||(firsttwo=="01"))
	{
		document.forms["former1"].region.value = ma;
	}
	if (firsttwo=="06")
	{
		document.forms["former1"].region.value = ct;
	} 
	else
	{
	}
	if (istest == 1)
	{
		hold=document.forms["former1"].region.value;
		document.forms["testplace"].tester.value=hold;
	}
	holdstatevalue = document.forms["former1"].region.value;
   }
   else
   {
	document.forms["former1"].region.value = none;
	if (istest == 1)
	{
		hold=document.forms["former1"].region.value;
		document.forms["testplace"].tester.value=hold;
	}
	holdstatevalue = document.forms["former1"].region.value;
   }
}

// join script
function join()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = rijoin2;
	}
	else
	{
	  location = rijoin;
	}
   }
   else if (hold=="CT")
   {
	location = ctjoin;
   } 
   else if (hold=="other")
   {
	location = selectstate + "?page=join";
   } 
}
	
// renew script
function renew()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = rirenew2;
	}
	else
	{
	  location = rirenew;
	}
   }
   else if (hold=="CT")
   {
	location = ctrenew;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=renew";
   } 
}
	
// gift script
function gift()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = rigift2;
	}
	else
	{
	  location = rigift;
	}
   }
   else if (hold=="CT")
   {
	location = ctgift;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=gift";
   } 
}

// update script
function update()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = riupdate2;
	}
	else
	{
	  location = riupdate;
	}
   }
   else if (hold=="CT")
   {
	location = ctupdate;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=maintain";
   } 
}

// add script
function add()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = riadd2;
	}
	else
	{
	  location = riadd;
	}
   }
   else if (hold=="CT")
   {
	location = ctupdate;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=add";
   } 
}

// benefits script
function benefits()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = ribenefits2;
	}
	else
	{
	  location = ribenefits;
	}
   }
   else if (hold=="CT")
   {
	location = ctbenefits;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=benefits";
   } 
}

// auto guide script
function autoguide()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = riautoguide2;
	}
	else
	{
	  location = riautoguide;
	}
   }
   else if (hold=="CT")
   {
	location = ctautoguide;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=autoguide";
   } 
}

// credit cards script
function creditcards()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = ricreditcards2;
	}
	else
	{
	  location = ricreditcards;
	}
   }
   else if (hold=="CT")
   {
	location = ctcreditcards;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=creditcards";
   } 
}

// hr script
function hr()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = rihr2;
	}
	else
	{
	  location = rihr;
	}
   }
   else if (hold=="CT")
   {
	location = cthr;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=hr";
   } 
}

// disney script
function disney()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  location = ridisney2;
	}
	else
	{
	  location = ridisney;
	}
   }
   else if (hold=="CT")
   {
	location = ctdisney;
   }
   else if (hold=="other")
   {
	location = selectstate + "?page=disney";
   } 
}

// membership handbook script
function mhandbook()
{
   if (istest == 1)
   {
	hold=document.forms["former1"].region.value;
	document.forms["testplace"].tester.value=hold;
   }
   else
   {
	hold = holdstatevalue;
   }
   if (hold=="MARI")
   {
	if (mytest == 1)
	{
	  //location = rimhandbook2;
	  myurl = rimhandbook2;
	}
	else
	{
	  //location = rimhandbook;
	  myurl = rimhandbook;
	}
   }
   else if (hold=="CT")
   {
	//location = ctmhandbook;
	myurl = ctmhandbook;
   }
   else if (hold=="other")
   {
	//location = selectstate + "?page=mhandbook";
	myurl = selectstate + "?page=mhandbook";
   }
   open(myurl,"_blank");
}