// JavaScript Document
// Development-Test functions
function showcookie()
{
	tmp1 = GetCookie('aaasne');
	tmp2 = GetCookie('zipcode');
	tmp3 = GetCookie('snelogin');
	tmp4 = "Customer Data: "+tmp1+"\nZipcode Data: "+tmp2+"\nLogin Data: "+tmp3; 
	alert(tmp4);
	//document.forms[1].ck.value = tmp4;
}
// Common functions
function MM_jumpMenu(targ,selObj,restore)
{ //Scott Adams version
	turl = selObj.options[selObj.selectedIndex].value;
	if(turl.toLowerCase().indexOf('http') > -1)
	{
		remote = window.open(turl, '_new');
		remote.focus();
	}
	else
	{
		eval(targ+".location='"+turl+"'");
	}
	if (restore) selObj.selectedIndex=0;
}
<!--
function MM_jumpMenu_old(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}
//-->
function MM_popupMsg(msg) { //v1.0
  alert(msg);
}
// Used for the travel search areas.
function MM_goToURL() { //v3.0
  var i, args=MM_goToURL.arguments; document.MM_returnValue = false;
  for (i=0; i<(args.length-1); i+=2) eval(args[i]+".location='"+args[i+1]+"'");
}
// Used for the travel search areas.
function hider_hotels(){
	var checkinDate=document.getElementById("checkinDay").value;
	var mySplitResult1 = checkinDate.split("/");

	for(i = 0; i < mySplitResult1.length; i++)
	var checkinMonth=mySplitResult1[0];
	var checkinDay=mySplitResult1[1];
	var checkinYear=mySplitResult1[2];
	if (checkinMonth==1) {
		checkinMonth="JAN";
	}
	if (checkinMonth==2) {
		checkinMonth="FEB";
	}
	if (checkinMonth==3) {
		checkinMonth="MAR";
	}
	if (checkinMonth==4) {
		checkinMonth="APR";
	}
	if (checkinMonth==5) {
		checkinMonth="MAY";
	}
	if (checkinMonth==6) {
		checkinMonth="JUNE";
	}
	if (checkinMonth==7) {
		checkinMonth="JUL";
	}
	if (checkinMonth==8) {
		checkinMonth="AUG";
	}
	if (checkinMonth==9) {
		checkinMonth="SEP";
	}
	if (checkinMonth==10) {
		checkinMonth="OCT";
	}
	if (checkinMonth==11) {
		checkinMonth="NOV";
	}
	if (checkinMonth==12) {
		checkinMonth="DEC";
	} 


	document.getElementById("checkinDay").value=checkinDay;
	document.getElementById("checkinMonth").value=checkinMonth;
	document.getElementById("checkinYear").value=checkinYear;

	var checkoutDate=document.getElementById("checkoutDay").value;
	var mySplitResult2 = checkoutDate.split("/");

	for(i = 0; i < mySplitResult2.length; i++)
	var checkoutMonth=mySplitResult2[0];
	var checkoutDay=mySplitResult2[1];
	var checkoutYear=mySplitResult2[2];

	if (checkoutMonth==1) {
		checkoutMonth="JAN";
	}
	if (checkoutMonth==2) {
		checkoutMonth="FEB";
	}
	if (checkoutMonth==3) {
		checkoutMonth="MAR";
	}
	if (checkoutMonth==4) {
		checkoutMonth="APR";
	}
	if (checkoutMonth==5) {
		checkoutMonth="MAY";
	}
	if (checkoutMonth==6) {
		checkoutMonth="JUNE";
	}
	if (checkoutMonth==7) {
		checkoutMonth="JUL";
	}
	if (checkoutMonth==8) {
		checkoutMonth="AUG";
	}
	if (checkoutMonth==9) {
		checkoutMonth="SEP";
	}
	if (checkoutMonth==10) {
		checkoutMonth="OCT";
	}
	if (checkoutMonth==11) {
		checkoutMonth="NOV";
	}
	if (checkoutMonth==12) {
		checkoutMonth="DEC";
	} 
					
	document.getElementById("checkoutDay").value=checkoutDay;
	document.getElementById("checkoutMonth").value=checkoutMonth;
	document.getElementById("checkoutYear").value=checkoutYear;
}
function hider_cars(){
					var pickupDate=document.getElementById("pickupDay").value;
					var mySplitResult1 = pickupDate.split("/");

					for(i = 0; i < mySplitResult1.length; i++)
					var pickupMonth=mySplitResult1[0];
					var pickupDay=mySplitResult1[1];
					var pickupYear=mySplitResult1[2];

						if (pickupMonth==1) {
							pickupMonth="JAN";
							}
						if (pickupMonth==2) {
							pickupMonth="FEB";
							}
						if (pickupMonth==3) {
							pickupMonth="MAR";
						}
						if (pickupMonth==4) {
							pickupMonth="APR";
						}
						if (pickupMonth==5) {
							pickupMonth="MAY";
						}
						if (pickupMonth==6) {
							pickupMonth="JUNE";
						}
						if (pickupMonth==7) {
							pickupMonth="JUL";
						}
						if (pickupMonth==8) {
							pickupMonth="AUG";
						}
						if (pickupMonth==9) {
							pickupMonth="SEP";
						}
						if (pickupMonth==10) {
							pickupMonth="OCT";
						}
						if (pickupMonth==11) {
							pickupMonth="NOV";
						}
						if (pickupMonth==12) {
							pickupMonth="DEC";
						} 


						document.getElementById("pickupDay").value=pickupDay;
						document.getElementById("pickupMonth").value=pickupMonth;
						document.getElementById("pickupYear").value=pickupYear;

						var dropoffDate=document.getElementById("dropoffDay").value;
						var mySplitResult2 = dropoffDate.split("/");

						for(i = 0; i < mySplitResult2.length; i++)
						var dropoffMonth=mySplitResult2[0];
						var dropoffDay=mySplitResult2[1];
						var dropoffYear=mySplitResult2[2];

						if (dropoffMonth==1) {
							dropoffMonth="JAN";
							}
						if (dropoffMonth==2) {
							dropoffMonth="FEB";
							}
						if (dropoffMonth==3) {
							dropoffMonth="MAR";
						}
						if (dropoffMonth==4) {
							dropoffMonth="APR";
						}
						if (dropoffMonth==5) {
							dropoffMonth="MAY";
						}
						if (dropoffMonth==6) {
							dropoffMonth="JUNE";
						}
						if (dropoffMonth==7) {
							dropoffMonth="JUL";
						}
						if (dropoffMonth==8) {
							dropoffMonth="AUG";
						}
						if (dropoffMonth==9) {
							dropoffMonth="SEP";
						}
						if (dropoffMonth==10) {
							dropoffMonth="OCT";
						}
						if (dropoffMonth==11) {
							dropoffMonth="NOV";
						}
						if (dropoffMonth==12) {
							dropoffMonth="DEC";
						} 
						
						document.getElementById("dropoffDay").value=dropoffDay;
						document.getElementById("dropoffMonth").value=dropoffMonth;
						document.getElementById("dropoffYear").value=dropoffYear;

						}
function hider_air(){
					var depDate=document.getElementById("depDay").value;
					var mySplitResult1 = depDate.split("/");

					for(i = 0; i < mySplitResult1.length; i++)
					var depMonth=mySplitResult1[0];
					var depDay=mySplitResult1[1];
					var depYear=mySplitResult1[2];

						if (depMonth==1) {
							depMonth="JAN";
							}
						if (depMonth==2) {
							depMonth="FEB";
							}
						if (depMonth==3) {
							depMonth="MAR";
						}
						if (depMonth==4) {
							depMonth="APR";
						}
						if (depMonth==5) {
							depMonth="MAY";
						}
						if (depMonth==6) {
							depMonth="JUNE";
						}
						if (depMonth==7) {
							depMonth="JUL";
						}
						if (depMonth==8) {
							depMonth="AUG";
						}
						if (depMonth==9) {
							depMonth="SEP";
						}
						if (depMonth==10) {
							depMonth="OCT";
						}
						if (depMonth==11) {
							depMonth="NOV";
						}
						if (depMonth==12) {
							depMonth="DEC";
						} 


						document.getElementById("depDay").value=depDay;
						document.getElementById("depMonth").value=depMonth;
						document.getElementById("depYear").value=depYear;

						var retDate=document.getElementById("retDay").value;
						var mySplitResult2 = retDate.split("/");

						for(i = 0; i < mySplitResult2.length; i++)
						var retMonth=mySplitResult2[0];
						var retDay=mySplitResult2[1];
						var retYear=mySplitResult2[2];

						if (retMonth==1) {
							retMonth="JAN";
							}
						if (retMonth==2) {
							retMonth="FEB";
							}
						if (retMonth==3) {
							retMonth="MAR";
						}
						if (retMonth==4) {
							retMonth="APR";
						}
						if (retMonth==5) {
							retMonth="MAY";
						}
						if (retMonth==6) {
							retMonth="JUNE";
						}
						if (retMonth==7) {
							retMonth="JUL";
						}
						if (retMonth==8) {
							retMonth="AUG";
						}
						if (retMonth==9) {
							retMonth="SEP";
						}
						if (retMonth==10) {
							retMonth="OCT";
						}
						if (retMonth==11) {
							retMonth="NOV";
						}
						if (retMonth==12) {
							retMonth="DEC";
						} 
						
						document.getElementById("retDay").value=retDay;
						document.getElementById("retMonth").value=retMonth;
						document.getElementById("retYear").value=retYear;

						}
function mailpage()
{
	mail_str = "mailto:?subject=Thought you’d be interested in this from AAA";
	mail_str += "&body=I thought you might be interested in the " + document.title;
	mail_str += ".%0DYou can view it at, " + location.href; 
	location.href = mail_str;
}
function findstring(fullstr, delimiter, whichone)
{
	whichone = whichone - 1;
	temparray = fullstr.split(delimiter);
	for(i = 0;i<temparray.length;i++)
	{
		if(i==whichone)
		{
			 return temparray[i];
		}
	}
}
function arrayUnique(temparr)
{
	var tmp= new Array(0);
	for(var n=0; n<temparr.length; n++)
	{
		if(!contains(tmp, temparr[n]))
		{
			tmp.length+=1;
			tmp[tmp.length-1]=temparr[n];
		}
	}
	return tmp;
}
function contains(temparray, value)
{
	var isdupe = 0;
	for(var j=0; j<temparray.length; j++)
	{
		if (temparray[j]==value)
		{
			isdupe = 1;
		}
	}
	if(isdupe == 0)
	{
		return false;
	}
	else
	{
		return true;
	}
}
function trim(inputString)
{ 
	finalText = "";
     lastChar = " ";
     for(x = 0; x < inputString.length; x++)
     {
      	curChar = inputString.charAt(x);
          if ((curChar != " ") || (lastChar != " "))
          {
      		finalText += curChar;
          }
          lastChar = curChar;
	}
     if (finalText.charAt(finalText.length - 1) == " ")
    {
		finalText = finalText.substring(0, finalText.length - 1);
	}
     return finalText;
}
function explode(inputstring, separators, includeEmpties)
{
	inputstring = new String(inputstring);
	separators = new String(separators);
	if(separators == "undefined")
	{ 
		separators = " :;";
	}
	fixedExplode = new Array(1);
	currentElement = "";
	count = 0;
	for(x=0; x < inputstring.length; x++)
	{
		ch = inputstring.charAt(x);
		if(separators.indexOf(ch) != -1)
		{
			if ( ( (includeEmpties <= 0) || (includeEmpties == false)) && (currentElement == ""))
			{
			 }
			else
			{
				fixedExplode[count] = currentElement;
				count++;
				currentElement = "";
			}
		}
		else
		{
			currentElement += ch;
		}
	}
	if (( ! (includeEmpties <= 0) && (includeEmpties != false)) || (currentElement != ""))
	{
		fixedExplode[count] = currentElement;
	}
	return fixedExplode;
}
function replaceSubString(strSource, strFind, strReplace, caseInsensitive)
{
	if(caseInsensitive)
	{
		re = "/" + strFind + "/g";
	}
	else
	{
		re = "/" + strFind + "/gi";
	}
	return strSource.replace(eval(re), strReplace);
}
function isDate (day,month,year)
{
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false;
}
function y2k(number) { 
number = number - 0; 
return (number < 1000) ? number + 1900 : number; 
} 

// Common Validation functions
function validatePhone(obj)
{
	if(obj.value =="")
	{
		return false;	
	}
	return true;
}
function validateEmail(obj)
{
	if(obj.value.indexOf('@') == -1 || obj.value.indexOf('.') == -1)
	{
		return false;	
	}
	return true;
}
function validateNotBlank(obj)
{
	if(obj.value =="")
	{
		return false;	
	}
	return true;
}
function validateIsSelected(obj)
{
	option = -1;  // Peform any select option validation
	for (i=0; i<obj.length;i++)  {
		if (obj[i].checked)  {
			option = i;
		}
	}
	if (option == -1)  
	{	
		return false;
	}
	else
	{
		return true;
	}
}
function validateSelectedIndex(obj)
{
	if (obj.selectedIndex == "0"){	
		return false;
	}
	return true;
}
function validateMemberNumber(obj, howmany)
{
	// make sure the value is the correct length
	if(obj.value.length < howmany) {
	return false;
	}
	// make sure the number is all digits.
	for(var i = 0; i < obj.value.length; i++ ) {	
   		var c = obj.value.charAt(i);
   		if( c < '0' || c > '9' ) {
		return false;
   		}	
	}
	return true;
}

// National Cookie script
function verifyUserIsInOurTerritory(clubNumber) {
        // verify client is in our territory via ZCG, must escape the rurl for proper processing by browsers
        window.location = "http://www.aaa.com/?rclub=" + clubNumber + "&rurl=" + escape(window.location);
}

// checks to see if the client is a spider, major engines listed
function spiderClient() {
        var spiderFound = false;
        var useragent = window.navigator.userAgent;
        useragent = useragent.toUpperCase();
        if(useragent.substring(0, 6) == "GOOGLE" || useragent.substring(0, 7) == "BACKRUB") {
                // should match all Google Spiders
                spiderFound = true;
        } else if(useragent.substring(0, 5) == "YAHOO") {
                // should match all Yahoo spiders
                spiderFound = true;
        } else if(useragent.substring(0, 6) == "MSNBOT") {
                // should match all MSN spiders
                spiderFound = true;
        } else if(useragent.substring(0, 5) == "LYCOS") {
                // should match Lycos
                spiderFound = true;
        } else if(useragent.substring(0, 8) == "MERCATOR") {
                // should match AltaVista
                spiderFound = true;
        }
        return spiderFound;
}

// gets the zipcode cookie data from the club's cookie
function getCookie(CookieName) {
        var search = CookieName + "=";
        if(document.cookie.length > 0) {
                offset = document.cookie.indexOf(search);
                if(offset != -1) {
                        offset += search.length;
                        end = document.cookie.indexOf(";", offset);
                        if(end == -1) {
                                end = document.cookie.length;
                        }
                        return document.cookie.substring(offset, end);
                }
        }
}

// This method should be used by clubs hosting pages on aaa.com
// that are referenced under the domains ww1.aaa.com, ww2.aaa.com and www.aaa.com
// since these pages will have access to the zipcode cookie written under aaa.com.

function validateUserInClub(clubNumber) {
        var ourUser = false;
        var foundAssociation = "";
        var foundClub = "";
        var startIndex = 0;
        var pipe = "";
        //var cookieData = getCookie("zipcode");
		var cookieData = unescape(getCookie("zipcode"));
        var foundZipCode = "";

        if(cookieData > "") {
                // get the zipcode
                pipe = cookieData.indexOf("|");
                if(pipe > 4) {
                        foundZipCode = cookieData.substring(startIndex, pipe);
                        // find association
                        startIndex = pipe + 1;
                        pipe = cookieData.indexOf("|", startIndex);
                        if(pipe > 8) {
                                foundAssociation = cookieData.substring(startIndex, pipe);
                                // get the club
                                startIndex = pipe + 1;
                                if(cookieData.length > startIndex) {
                                        foundClub = cookieData.substring(startIndex);
                                }
                        }
                }
        }
        if(foundZipCode > "" && foundAssociation > "" && foundClub > "") {
                // we have valid data
                if(foundClub == clubNumber) {
                        // this is our user, keep them here.
                        ourUser = true;
                } else {
                        // not our user, calling method will get them to the
                        // ZipCode Gateway and then routed to their club.
                        ourUser = false;
                }
        } else {
                // returning false, in this case meaning we could not validate
                // the user, the calling method will call the ZipCode Gateway
                // which will take care of validating the user
                ourUser = false;
        }
        return ourUser;
}


// Cookie functions
function getCookieVal(offset)
{
   var endstr = document.cookie.indexOf(";",offset);
   if (endstr == -1) endstr=document.cookie.length;
   return unescape(document.cookie.substring(offset,endstr));
}
function FixCookieDate(date)
{
   var base = new Date(0);
   var skew = base.getTime();
   if (skew > 0)
   date.setTime(date.getTime()-skew);
}
function GetCookie(name)
{
   var arg = name + "=";
   var alen = arg.length;
   var clen = document.cookie.length;
   var i = 0;
   while (i < clen)
   {
     var j = i + alen;
     if (document.cookie.substring(i, j) == arg) return getCookieVal (j);
     i = document.cookie.indexOf(" ", i) + 1;
     if (i == 0) break;
   }
   return null;
}
function SetCookie(name,value,expires,path,domain,secure)
{
  	 document.cookie=name+"="+escape(value)+
	((expires)?";expires="+expires.toGMTString():"")+
	((path)?";path="+path:"")+
	((domain)?";domain="+domain:"")+
	((secure)?";secure":"");
}
function DeleteCookie(name,path,domain)
{
   if(GetCookie(name))
   {
     document.cookie=name+"="+
     ((path)?";path="+path:"")+
     ((domain)?";domain="+domain:"")+
     "; expires=Thu,01-Jan-70 00:00:01 GMT";
   }
}
function ReplaceCookie(name,values,expires)
{
  var tmpcookiedata = GetCookie(name);
  if (tmpcookiedata != null) {
  var srv = document.forms[0].server_name.value;
  if(expires != '') {
  var tmpdate = Make_Exp_Date(expires,0,0);
  var expdate = new Date(tmpdate); }
  else {
  var expdate = ''; }
  SetCookie(name,values,expdate,"/",srv); }
}
function ReplaceCookieValue(name,whichone,value,expires)
{
  var tmpstr = '';
  var cookie = GetCookie(name);	
  if(cookie != null) {
  var cookiedata = cookie.split('|');
  for(v = 0; v < cookiedata.length; v++) {
  var varray = cookiedata[v].split('^');
  if(varray[0].toLowerCase() == whichone.toLowerCase()) {
  if(tmpstr == '') {
  tmpstr = varray[0] + '^' + value; }
  else {
  tmpstr = tmpstr + '|' + varray[0] + '^' + value;	} }
  else {
  if(tmpstr == '') {
  tmpstr = varray[0] + '^' + varray[1]; }
  else {
  tmpstr = tmpstr + '|' + varray[0] + '^' + varray[1];	} } }
  ReplaceCookie(name,tmpstr,expires); }	
}
function GetCookieValue(name,whichone)
{
  var cookie = GetCookie(name);	
  if(cookie != null) {
  var cookiedata = cookie.split('|');
  if(cookiedata.length > 1) {
  for(v = 0; v < cookiedata.length; v++) {
  var varray = cookiedata[v].split('^');
  if(varray[0].toLowerCase() == whichone.toLowerCase()) {return varray[1]; } } } }
  else	{return null;}	
}
function UpdateCookie(name,values,expires)
{
  var tmpcookiedata = GetCookie(name);
  if (tmpcookiedata != null) {
  var srv = document.forms[0].server_name.value;
  newvalues =  tmpcookiedata + '|' + values;
  if(expires != '') {
  var tmpdate = Make_Exp_Date(expires,0,0);
  var expdate = new Date(tmpdate); }
  else {
  var expdate = ''; }
  SetCookie(name,newvalues,expdate,"/",srv); }
}
function Make_Exp_Date(days, hours, minutes)
{
  var expDate = new Date( );
  if (typeof days == "number" && typeof hours == "number" && typeof hours == "number") {
  expDate.setDate(expDate.getDate( ) + parseInt(days));
  expDate.setHours(expDate.getHours( ) + parseInt(hours));
  expDate.setMinutes(expDate.getMinutes( ) + parseInt(minutes));
  return expDate.toGMTString( ); }
}
function writeZipCodeCookie(zip) 
{
	var today = new Date();
	var expdate = new Date();
	expdate.setFullYear(today.getFullYear() + 1 );  // 1 Year
	var mn = zip + '|AAA|240';
	SetCookie('zipcode',mn,expdate,'/');
}
//Ajax
function ajaxlogoutFunction()
{
var xmlHttp;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
try
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e)
{
alert("Your browser does not support AJAX!");
return false;
}
}
}
xmlHttp.onreadystatechange=function()
{
if(xmlHttp.readyState==4)
{
document.myForm.time.value=xmlHttp.responseText;
}
}
xmlHttp.open("GET","https://www.aaasnemembercenter.com/Logout/logout.aspx",true);
xmlHttp.send(null);
window.location="../../includes/login/240loginprocess.php";
}
