
  var TAB_PARENT_SELECTED_STYLE_CLASS = "topNavRollover";
  var TAB_PARENT_UNSELECTED_STYLE_CLASS = "topNavRollout";
  var TAB_UNSELECTED_STYLE_CLASS = "LeftNavItems";
  var TAB_SELECTED_STYLE_CLASS = "LeftNavItemsHighLight";
   
 /**
  *
  *
  */
  function selectTab( tab )
  {
    var parentObject = ( tab.parentElement )? tab.parentElement: tab.parentNode;
    changeObjectClass( tab, TAB_SELECTED_STYLE_CLASS );
    changeObjectClass( parentObject, TAB_PARENT_SELECTED_STYLE_CLASS );
  }
 
  /**
  *
  *
  */
  function selectTopNavTab( tab )
  {
    var parentObject = ( tab.parentElement )? tab.parentElement: tab.parentNode;
    changeObjectClass( tab, TAB_PARENT_SELECTED_STYLE_CLASS );
    changeObjectClass( parentObject, TAB_PARENT_SELECTED_STYLE_CLASS );
  }
 
 
 
 
 /**
  *
  *
  */
  function unselectTab( tab )
  {
    var parentObject = ( tab.parentElement )? tab.parentElement: tab.parentNode;
    changeObjectClass( tab, TAB_UNSELECTED_STYLE_CLASS );
    changeObjectClass( parentObject, TAB_PARENT_UNSELECTED_STYLE_CLASS );
  }

  /**
  *
  *
  */
  function unselectTopNavTab( tab )
  {
    var parentObject = ( tab.parentElement )? tab.parentElement: tab.parentNode;
    changeObjectClass( tab, TAB_PARENT_UNSELECTED_STYLE_CLASS );
    changeObjectClass( parentObject, TAB_PARENT_UNSELECTED_STYLE_CLASS );
  }



 /**
  *
  *
  */
  function changeObjectClass( object, styleClass )
  {
    object.className = styleClass;
  }
  
  
  /**
   *
   *
   */
   function setWindowStatus( status )
   {
     window.status = status;
     return true;
   }
   
   
   /**
    *
    *
    */
    function clearWindowStatus()
    {
      return setWindowStatus( "" );
    }
    
    
    
	function comboBoxNav(brandSelect)
	{
		var theIndex=brandSelect.selectedIndex;
		if (brandSelect.options[brandSelect.selectedIndex].value != "null") 
		{
			top.location=(brandSelect.options[theIndex].value);
		}
	}

    
    function sendto(country, brand, uri, popupCode)
    {
    	var brandName = new String(brand);
    	var protocol = window.location.protocol;
    	var forwardUrl = new String("");
    	
    	
    	if(brand == null || brand == "" || brand == "no_brand")
    	{
    		brandName = window.location.host;
    	}
    	else
    	{
    		brandName = brandName.toLowerCase();
    		
    		if(country == null || country == "")
    		{
    			country == "us";
    		}
    		
    		country = country.toLowerCase();
    		
    		switch(country)
    		{
    			case "br":
			    	brandName = brandName + ".br";
    				break;
    			case "fr":
			    	brandName = brandName + ".fr";
    				break;
    			case "au":
			    	brandName = brandName + ".com.au";
    				break;
    			case "kr":
			    	brandName = brandName + ".co.kr";
    				break;
    			case "cn":
			    	brandName = brandName + ".com.cn";
    				break;
    			case "nz":
			    	brandName = brandName + ".co.nz";
    				break;
    			case "de":
    				brandName = brandName + ".de";
    				break;
    			case "jp":
    				brandName = brandName + ".co.jp";
    				break;
    			case "uk":
    				brandName = brandName + ".co.uk";
    				break;
    			case "mx":
    				brandName = brandName + ".com.mx";
    				break;
    			case "ar":
    				brandName = brandName + ".com.ar";
    				break;
    			case "cl":
    				brandName = brandName + ".cl";
    				break;
    			case "cr":
    				brandName = brandName + ".co.cr";
    				break;
    			case "do":
    				brandName = brandName + ".com.do";
    				break;
    			case "pe":
    				brandName = brandName + ".com.pe";
    				break;
    			case "ve":
    				brandName = brandName + ".co.ve";
    				break;
    			case "la1":
    			case "la2":
    			case "gt":
    			case "ec":
    			case "ni":
    			case "uy":
    				brandName = "latinamerica.marriott.com";
    				break;
    			default:
    				brandName = brandName + ".com";
    				break;
    		}
    	}
     
     	forwardUrl = protocol + "//" + brandName;
     	
     	
     	if(uri != null)
     	{
     		forwardUrl = forwardUrl + uri;
     	}
     	
     	// rewrite url
     	var querystring = new String();
     	querystring = window.location.search;
     	queryArray = querystring.split("&");
     	for (var i=0; i < queryArray.length; i++) 
     	{
     		var valuePair = queryArray[i];
     		valuePair = valuePair.replace("/?", "");
     		var nameValArray = queryArray[i].split("=");
     		if(nameValArray[0] == "JSESSIONID")
     		{
     			if(forwardUrl.indexOf("?") == -1)
     			{
     				forwardUrl = forwardUrl + "?" + nameValArray[0] + "=" + nameValArray[1];
     			}
     			else
     			{
     				forwardUrl = forwardUrl + "&" + nameValArray[0] + "=" + nameValArray[1];
     			}
     		}
     	}
     	
     	
     	
		//determine window type
		switch(popupCode)
		{
			case "2":
				window.open(uri, "_blank");
				break;
			case "3":
				window.open(forwardUrl, "_blank");
				break;
			case "4":
				window.open(forwardUrl, "_blank", "width=235,height=206,scrollbars=no,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			case "5":
				window.open(forwardUrl, "_blank", "width=383,height=585,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			case "6":
				window.open(forwardUrl, "_blank", "width=350,height=475,scrollbars=no,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			case "7":
				window.open(forwardUrl, "_blank", "width=352,height=306,scrollbars=no,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			case "8":
				window.open(forwardUrl, "_blank", "width=575,height=385,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			case "9":
				window.open(forwardUrl, "_blank", "width=570,height=560,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			case "10":
				window.opener.location(forwardUrl);
				window.close();
				break;
			case "11":
				window.open(forwardUrl, "_blank", "");
				window.close();
				break;				
			case "12":
				window.open(forwardUrl, "imagePopUp", "width=590,height=413,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			case "13":
				window.open(forwardUrl, "_blank", "width=630,height=500,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			case "14":
				window.open(uri, "imagePopUp", "width=572,height=410,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes");			
				break;				
			case "15":
				window.open(forwardUrl, "_blank", "width=575,height=385,scrollbars=yes,menubar=yes,toolbar=yes,status=yes,resizable=yes");
				break;
			case "16":
				window.open(forwardUrl, "_blank", "width=610,height=535,scrollbars=yes,menubar=no,toolbar=no,status=no,resizable=yes");
				break;
			default:
				window.location.href = forwardUrl;
				break;
		
		}  	
    }
    
    function getServerName()
    {
    	var url = (new String(document.URL)).toLowerCase();
    	
    	var colonSlashSlashLocation = url.indexOf("://");
    	
    	if (colonSlashSlashLocation < 0)
    		return new String("marriott.com");//hard-coded worst case
    	
    	var slashLocation = url.indexOf("/",colonSlashSlashLocation+3);
    	
    	if (slashLocation < 0)
    		return new String("marriott.com");//hard-coded worst case
    		
    	return url.substring(colonSlashSlashLocation+3,slashLocation);
    }
    
 	function buildLoginUrl(url, altAction)
 	{
		var returnUrl = null;

		if(altAction != null && altAction != "")
		{
			if (altAction.indexOf("?") == -1)
			{
				returnUrl = new String(escape(altAction + ".mi"));
			}
			else
			{
				returnUrl = new String(escape(altAction));
			}
		}
		else
		{
			returnUrl = new String(escape(document.URL));
		}
		
		var loginUrl = new String(url + "?returnTo=" + returnUrl);

		//fix up the loginUrl so it is prefixed with https://<servername>...

		var serverName = new String(getServerName());

		var urlForServerNameCheck = (new String(url)).toLowerCase();
		if ((urlForServerNameCheck.indexOf("http://"+serverName) == 0) ||
		    (urlForServerNameCheck.indexOf("https://"+serverName) == 0))
			//shouldn't be in this case given the way we use buildLoginUrl()
			//today throughout the code, but if the server name is already
			//part of url, don't try to add https://servername...
			window.location.href = loginUrl;
		else
		{
			//This is for the general case of how buildLoginUrl is actually
			//used today; if /ProtectedServlet is passed in as url, we need
			//to prefix the https://<servername> part to that so that we're
			//going to an https-protected page so security popups don't
			//happen (otherwise when the container redirects the user to
			//http://<server>/ProtectedServlet.mi the user gets a security
			//alert. See IPMI00012733.
			serverName = "https://" + serverName;
			if (loginUrl.charAt(0) != '/')
				serverName = serverName + "/";
			window.location.href = serverName + loginUrl;
		}	
	}
    
    function addParameterToQuerystring(url, paramName, paramValue, returnOrForward)
    {
    	var host = window.location.host;
 		
	  	if(url.indexOf("?") == -1)
		{
			url = url + "?" + paramName + "=" + paramValue;
		}
		else
		{
			if(url.charAt(url.length - 1) == '?')
			{
				url = url + paramName + "=" + paramValue;
			}
			else
			{
				url = url + "&" + paramName + "=" + paramValue;
			}
		}
			
		if(url.indexOf("http://") != -1 || url.indexOf("https://") != -1)
		{
			url = url;
		}
		else	
		{
			//re: IPMI00009895
			//need to keep this list in sync with web.xml's list of protected resources
			//added cancel eCert pages
			if ((url.indexOf("/myaccount/missstay.mi") >= 0) ||
			    (url.indexOf("/myaccount/coversheetmissingstay.mi") >= 0) ||
			    (url.indexOf("/myaccount/chpass.mi") >= 0) ||
			    (url.indexOf("/myaccount/chuser.mi") >= 0) ||
			    (url.indexOf("/myaccount/modacct.mi") >= 0) ||
			    (url.indexOf("/myaccount/acctsum.mi") >= 0) ||
			    (url.indexOf("/myaccount/unusedcerts.mi") >= 0) ||
			    (url.indexOf("/myaccount/ordermat.mi") >= 0) ||
			    (url.indexOf("/promotionRegistration.mi") >= 0) ||
				(url.indexOf("/myAccount/default.mi") >= 0) ||
				(url.indexOf("/myAccount/activity.mi") >= 0) ||
				(url.indexOf("/myAccount/missingStayRequest.mi") >= 0) ||
				(url.indexOf("/myAccount/orderReplacementCard.mi") >= 0) ||
				(url.indexOf("/myAccount/deactivateAccount.mi") >= 0) ||
			    (url.indexOf("/reservation/confirmCancelRedemptionRes.mi") >= 0) ||
			    (url.indexOf("/reservation/cancelRedemptionRes.mi") >= 0) ||
				(url.indexOf("/travelagents") >= 0))
			{
				url = "https://" + host + url;
			}
			else
			{
				url = "http://" + host + url;
			}
		}
	
		if(returnOrForward == null || returnOrForward == "" || returnOrForward == "forward")
		{
			window.location.href = url;
		}
		else
		{
			return url;
		}
    }

    
    function changeSignOut(signOutURL)
    {
	signInURL = "/ProtectedServlet";
	var returnTo = "?returnTo=" + escape(document.URL);
	signInURL = signInURL + returnTo;
	
	changeSignOutURL = signOutURL + signInURL;
	
	window.location.href = changeSignOutURL;
    }
    
	/**
	 * Retrieve the value of the cookie with the specified name.
	 */
	function getCookie(sName)
	{
		// cookies are separated by semicolons
		var aCookie = document.cookie.split("; ");
		for (var i=0; i < aCookie.length; i++)
		{
			// a name/value pair (a crumb) is separated by an equal sign
			var aCrumb = aCookie[i].split("=");
			if (sName == aCrumb[0]) 
				return unescape(aCrumb[1]);
		}

		// a cookie with the requested name does not exist
		return "";
	}
