// JavaScript Document with common site scripts for 222//
// Created 11/3/2008 by WMS as part of Travel 2 migration//


//DROPDOWN MENU FUNCTIONS 
//Other global variables
var numMenus = 7;
var lastTwoLinks = new Array();

lastTwoLinks[0]="dropmenu6";
lastTwoLinks[1]="dropmenu7";

//login / logout scripts
// Club Dependent Constant Definitions
var DEFAULT_CLUB_HOME_URL = "http://www.aaa.com//scripts/WebObjects.dll/AAAOnline?association=aaa&club=222";
var LOGIN_URL = "/scripts/WebObjects.dll/AAAOnline?association=aaa&club=222&page=ExternalSignin&returnpoint=";
var LOGOUT_URL = "/scripts/WebObjects.dll/AAAOnline?association=aaa&club=222&page=signout";
var RETURN_POINT_URL = "http%3A%2F%2F" + document.domain + "%2Fscripts%2FWebObjects.dll%2FAAAOnline%3Fassociation%3Daaa%26club%3D222%26page%3DClubConfig68";

function SetAAACookie(cookieName,cookieValue,nDays,path) 
{
	path = path ? path : "/"
	var today = new Date();
	var expire = new Date();
	nDays = nDays ? nDays : 1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)
					 + ";expires="+expire.toGMTString()+";path="+path;
}
function ReadAAACookie(cookieName) 
{
 	var theCookie=""+document.cookie;
	 var ind=theCookie.indexOf(cookieName);
 	if (ind==-1 || cookieName=="") return ""; 
	 var ind1=theCookie.indexOf(';',ind);
	 if (ind1==-1) ind1=theCookie.length; 
	 return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}

//GO TO PAGE WHEN DROPDOWN IS CLICKED
function goEx(URL,width,height)
{
	goTo(URL, "_new", height, width);	
	return false;
}
function goTo(URL,target,height,width)
{
 var winProps
 if (target != "_self")
 {
  winProps="toolbar=no,menubar=no,location=no,scrollbars=yes,resizable=yes,height=" +
     ((height==null || height=='') ? 650 : height) + ",width=" + ((width==null || width=='') ? 785 : width);
  NewWin0=this.open(URL,"Win",winProps);
 }
 else
 {
  document.location.href=URL;
 }
}

var zindex=100
var ns4=document.layers
var ns6=document.getElementById&&!document.all
var ie4=document.all
var opr=navigator.userAgent.indexOf("Opera")
var detect = navigator.userAgent.toLowerCase(); 


function checkBrowserType(string)
{
	place = detect.indexOf(string) + 1;
	thestring = string;
	return place;
}

//Places an iframe underneath the dynamic menus so they appear on top of dropdown form elements in IE
function addRemoveddCover(menu)
{
	if (!document.all) return; 
	
	   var ddcover = document.getElementById('ddCover');
	   if(menu)
	   { 
			var ddMenu = (typeof menu == "object") ? menu : document.getElementById(menu); 
			ddcover.style.width = ddMenu.offsetWidth;
			ddcover.style.height = ddMenu.offsetHeight;
			ddcover.style.top = ddMenu.style.top;
			ddcover.style.left = ddMenu.style.left;
			ddcover.style.zIndex = ddMenu.style.zIndex - 1;
			ddcover.style.display = "block";
	   }
	   else
	   {
			ddcover.style.display = "none";
		}
}

function doTheDrop(menu,element)
{
     //CLEAR HIDE MENU TIMER IF EXISTS & DROP MENU
     if (window.aaaHideMenuTimer) 
     	clearTimeout(aaaHideMenuTimer);
        
	dropit(menu,element); 
	addRemoveddCover(menu);
}

//CLOSE ALL OPEN MENUS, POSITION & DROP CORRECT CURRENT MENU
function dropit(whichone,element){
aaa_closeMenus();

curmenuID=ns6? document.getElementById(whichone).id : eval(whichone).id

themenu=ns6? document.getElementById(whichone): eval(whichone)
themenuStyle=(ns6||ie4)? themenu.style : themenu

themenuoffsetX=(ie4&&opr==-1)? document.body.scrollLeft : 0
themenuoffsetY=(ie4&&opr==-1)? document.body.scrollTop : 0

var x, y
x = getPageOffsetLeft(element);
y = getPageOffsetTop(element)+element.offsetHeight;

 // For IE, adjust position.


  if (ie4) {
    x += themenu.offsetParent.clientLeft;
    y += themenu.offsetParent.clientTop;
	y-=3;
	x-=3;
  }
  //LAST TWO MENU ITEMS (AS DEFINED IN VARIABLE AT TOP OF PAGE)
  //ARE DROPPED 60 PX TO THE LEFT TO AVOID GOING OFF THE PAGE
  if (curmenuID==lastTwoLinks[0] || curmenuID==lastTwoLinks[1]){
	x-=60;
  }
  //Set the position and drop the menu
  themenuStyle.left = x + "px";
  themenuStyle.top  = y + "px";
  themenuStyle.visibility = "visible";
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;//alert("el.offsetLeft="+el.offsetLeft);
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);
  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the y coordinate of an element relative to the page.

  y = el.offsetTop;//alert("el.offsetTop="+el.offsetTop);
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);
  return y;
}

//SET STYLES AND RESTORE STYLES SHOW AND HIDE MENU IN IE
//SET AND CLEAR TIMEOUT (USED FOR HIDING MENU) IN NN
function setStyles(el)
{
	 if(document.all) el.style.visibility='visible';
	 addRemoveddCover(el);
	 if(document.getElementById && !document.all)clearTimeout(aaaHideMenuTimer);
}
function restoreStyles(el)
{
	 addRemoveddCover();
	 if(document.all) el.style.visibility='hidden';
	 if(document.getElementById && !document.all)aaa_startTimeout();
}

//CAPTURE MOUSE CLICKS TO HIDE MENU WHEN PAGE IS CLICKED
if (document.all)
  document.onmousedown = pageMousedown;
else 
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event){
//GET THE ELEMENT THAT WAS CLICKED
var el;
if (document.all){
    el = window.event.srcElement;
}
else{
    el = (event.target.tagName ? event.target : event.target.parentNode);
}
//IF THE ELEMENT THAT WAS CLICKED DOES NOT HAVE THE CSS CLASSNAME FOR THE DROPDOWN MENU
//LINK AND TD, CLOSE THE DROPDOWNS
if (el.className != "dropdownlink" && el.className != "dropdownhover" && el.className != "dropdown")
	aaa_closeMenus();
}
//CLOSE DROPDOWN MENU FUNCTION
function aaa_doMenuClose()
{
	if(document.all) aaa_closeMenus();
	if(document.getElementById && !document.all) aaa_startTimeout();
}
function aaa_closeMenus()
{
	addRemoveddCover();
	for (var i=1;i<=numMenus;i++)
	{
		var menuName="dropmenu"+i.toString();
		if (document.getElementById)document.getElementById(menuName).style.visibility="hidden"
		if (document.all)document.all(menuName).style.visibility="hidden";
	}
}
//FOR NN6+ HIDE THE MENU AFTER 1 SECOND
function aaa_startTimeout(){	
	aaaStart = new Date();	
	aaaDHFlag = true;	
	aaaHideMenuTimer = setTimeout("aaa_DoHide()", 1000);
}
function aaa_DoHide(){	
	if (!aaaDHFlag) return;	
	var elapsed = new Date() - aaaStart;	
	if (elapsed < 1000) {		
		aaaHideMenuTimer = setTimeout("aaa_DoHide()", 1100-elapsed);		
		return;	}	
	aaaDHFlag = false;	
	aaa_closeMenus();	
}

//TRAVEL 2 SCRIPTS//
//travel 2 override functions for positioning lrp div
function showLrp() 
{
	var bodyContainer = window.document.body;
	showAjaxSpinner(bodyContainer, 'lrpOverlay', 'lrp');
	
	var pos = window.pageYOffset ? parseInt(window.pageYOffset) : 
		document.documentElement.scrollTop ? parseInt(document.documentElement.scrollTop):
			parseInt(document.body.scrollTop);
			
	pos = pos.toString() != "NaN" ? pos : 0;
	document.getElementById("lrp").style.top = pos + 150 + "px";
	document.getElementById("lrp").style.left = "290px";
	show('lrp');
}	
