///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Page on load event mechanism to provide access for all components         //
//                                                                           //
//                                START                                      //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

// Create array, qsParm, that contains url query sting vars for javaScript functions. 
function makeQueryString() {
	var qsParm = new Array();
	var query = window.location.search.substring(1);
	var parms = query.split('&');	
	for (var i=0; i<parms.length; i++) {		
	   var pos = parms[i].indexOf('=');
	   if (pos > 0) {
		  var key = parms[i].substring(0,pos);
		  var val = parms[i].substring(pos+1);
		  qsParm[key] = val;
		}
	}
	return qsParm;		
}

var queryStingArray = makeQueryString();


// query string class
function QueryString() {
		
	this.qsParm = new Array();
		
	var query = window.location.search.substring(1);
	
	var parms = query.split('&');
	
	for (var i=0; i<parms.length; i++) {
	   var vars = parms[i].split('=');
	   
	   this.qsParm[i] = vars;	   		   
	   
	   this[vars[0]] = vars[1];	
	}
	
	return true;	
	
}
var queryStringObject = new QueryString();


// Global list of onLoadEvent methods (functions) to be called by 
// the document window/body onload event.  Any page that wishes to 
// have their custom onload event call should register itself by
// calling registerOnLoadEvent and passing in the function reference.
var onLoadEventFunctions = new Array();

function getFunctionName( functionReference ) {	
	var code			= functionReference.toString();
	
	var functionName	= null;
	var startPos		= -1;
	var endPos			= -1;

	// Go to the index after the word "function".
	var startPos = code.indexOf("function");
	if (startPos == -1) {
		return null;
	}
	startPos = startPos + 8;


	// Find the index where the "(" is located
	endPos = code.indexOf( "(", startPos );
	if (endPos == -1) {
		return null;
	}
	
	functionName = code.substring( startPos, endPos );
	if (functionName != null) {
		var re = new RegExp( "\\s*", "g" );
		functionName = functionName.replace( re, "" );
	}
	
	return functionName;
}


// Registers a custom onload event method to be invoked by the root
// onLoadEvent method inovked by window/body onload event.
function registerOnLoadEvent(functionReference) {
	var functionName = getFunctionName( functionReference );

	if (functionName == null) {
		alert( "registerOnLoadEvent: Failed to extract the function name.  The following method will NOT get registered for onload event.\n\n" + functionReference.toString() );
		return;
	} else {
		// call() is supported only by IE 5.5 or 5.0 SP2 (maybe SP1) and above.  Netscape seems to handle it ok.
		// Therefore we cannot use the function reference.   Instead, we will parse
		// out the method reference's code (using .toString()) and extract the method
		// name.  We'll store that instead in the format "functionName()".
		// The code that onLoadEvent() will do in effect will be eval( "function()" );
		// which will end up making the method call.  Same thing as function.call().
		onLoadEventFunctions[ onLoadEventFunctions.length ] = functionName + "()";
	
		//onLoadEventFunctions[ onLoadEventFunctions.length ] = functionReference;
	}
}



// Global onload event handler which gets called by window/body onload event.
// The method loops over the global list of registered onload event method
// handler and executes them one by one.
function onLoadEvent() {
	for (var i = 0; i < onLoadEventFunctions.length; i++) {

		// alert( "Invoking onLoad Event Function: " + onLoadEventFunctions[i] );

		// call/execute the registered handler method.
		eval( onLoadEventFunctions[i] );
		
		// call() is supported only by IE 5.5 or 5.0 SP2 (maybe SP1) and above.
		// To fix this we will use eval.
		//onLoadEventFunctions[i].call();
	}
}

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Page on load event mechanism to provide access for all components         //
//                                                                           //
//                                END                                        //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

function ii_checkBrowser() { //v1.0

  NSvers = 7.2; // Minimum Netscape ver.
  NSpass = 0;   // 0 = stay on current page is pass
  NSnoPass = 1;	// 1 = nogo URL
  
  IEvers = 5.0; // Minimum IE ver.
  IEpass = 0; 	// 0 = stay on current page is pass
  IEnoPass = 1; // 1 = nogo URL
  
  OPvers = 9.01; // Minimum Opera ver.
  OPpass = 0;	 // 0 = stay on current page is pass
  OPnoPass = 1;  // 1 = nogo URL
  
  OBpass = 0;
  URL = '/web/cs?a=60&p=notsupported&h=n&f=n&dontcheckbrowser=y';
  altURL = '';
 
  var newURL='', userAgent=navigator.userAgent, version=0;
  
  //alert("ver: " + parseFloat(userAgent.substring(userAgent.indexOf('Opera')+4,userAgent.length)));
 
  if (userAgent.indexOf('Netscape') != -1) {
  	version = parseFloat(userAgent.substring(userAgent.indexOf('Netscape')+9,userAgent.length));
    if (version >= NSvers) {
		if (NSpass>0) newURL=(NSpass==1)?URL:altURL;
	} else {
		if (NSnoPass>0) newURL=(NSnoPass==1)?URL:altURL;
	}
  } else if (userAgent.indexOf('MSIE') != -1) {
  	version = parseFloat(userAgent.substring(userAgent.indexOf('MSIE')+4,userAgent.length));
    if (version >= IEvers) {
		if (IEpass>0) 
			newURL=(IEpass==1)?URL:altURL;
	} else {
		if (IEnoPass>0) newURL=(IEnoPass==1)?URL:altURL;
	}
  } else if (userAgent.indexOf('Firefox') != -1) { // if FireFox pass on thru  		
	newURL=null;
  } else if (userAgent.indexOf('Safari') != -1) { // if Safari pass on thru  		
	newURL=null;
  } else if (userAgent.indexOf('Opera') != -1) { // if Opera 
	version = parseFloat(userAgent.substring(userAgent.indexOf('Opera')+6,userAgent.length));	
    if (version >= OPvers) {
		if (OPpass>0) 
			newURL=(OPpass==1)?URL:altURL;
	} else {
		if (OPnoPass>0) newURL=(OPnoPass==1)?URL:altURL;
	}
	
  } else if (userAgent.length < 40) { 
	 newURL = URL;
  } else if (OBpass>0) newURL=(OBpass==1)?URL:altURL;
  	if (newURL) { window.location=unescape(newURL); document.MM_returnValue=false; }
}

if(queryStingArray['dontcheckbrowser'] != 'y') { // register ii_checkBrowser only if not checking allready!	
	registerOnLoadEvent(ii_checkBrowser);
}



///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Common methods needed throughtout the application w/ specific application //
//                                                                           //
//                                START                                      //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

//
// Some global variable needed for code branching
isNav	= false;
isNav4	= false;
isIE	= false;
isIE4	= false;
isDHTML = true;
// Causing error when doing window.open() - SmartCalendarTag
// isDHTML	= (document.layers != null || document.all != null || document.getElementById != null);

if (navigator.appName == "Netscape") {
	isNav = true;
	if (parseInt(navigator.appVersion) >= 4) {
		isNav4 = true;
	}
} else {
	isIE = true;
	if (parseInt(navigator.appVersion) >= 4) {
		isIE4 = true;
	}
}


//
// Get a document object by name reference
// Generated by Macromedia Dreamweaver... cleaned up by Eric.
function getObject(n, d) {
	var i = 0;
	var p = 0;				// position
	var o = null;			// object ref.
	
	if (!d) {
		d = document;
	}


	// See if the object name is referring to an object within another frame window.
	// Object name would be   <object name>?<frame name>
	// Variable name will be replaced with the substring for <object name>
    p = n.indexOf("?");
	if (p > 0 && parent.frames.length) {
    	d = parent.frames[n.substring(p + 1)].document; 
    	n = n.substring(0, p);
    }


	// Check to see the object (which may have been extracted from a frame document)
	// is found at the root of the DOM
	o = d[n];
  	if (!o && d.all) {
  		o = d.all[n];
  	}
  		
  		
  	// Nothing yet... then check to see if it's a form element
  	for (i = 0; !o && i < d.forms.length; i++) {
  		o = d.forms[i][n];
  	}
  		
  		
  	// Alright, now check to see if it's a layer
  	for (i = 0; !o == null && d.layers && i < d.layers.length; i++) {
  		o = getObject(n, d.layers[i].document);
  	}
  		
  	
  	// Last ditch... try by ID
	if (!o && document.getElementById)  {
		o = document.getElementById(n); 
	}
		
	// Returns null by default if it wasn't found
	return o;
}


// Get the style property... this is different for IE & Netscape
function getStyleObject(object) {
	var o = object;
	
	if (o != null) {
		if (o.style) {
			return  o.style; 
		} else {
			return o;
		}
	} else {
		return null;
	}
}


// Display a given layer
function showLayer(layerName) {
	var layerObj = getObject(layerName);

	if (layerObj != null) {
		var style = getStyleObject(layerObj);
		
		if (style != null) { 
    		style.visibility = "visible";
    	} else {
    		alert("Could not locate style reference for object named: " + layerName);
    	}
	} else {
		alert("Could not obtain a reference for an object named: " + layerName);
	}
}


// Hide a given layer
function hideLayer(layerName) {
	var layerObj = getObject(layerName);

	if (layerObj != null) {
		var style = getStyleObject(layerObj);
		
		if (style != null) { 
    		style.visibility = "hidden";
    	} else {
    		alert("Could not locate style reference for object named: " + layerName);
    	}
	} else {
		alert("Could not obtain a reference for an object named: " + layerName);
	}
}


  	function getDocumentWidth() {
		if( typeof( window.innerWidth ) == "number" ) {
			// Non-IE
			return window.innerWidth;
		} else {
			if( document.documentElement &&document.documentElement.clientWidth ) {

				//IE 6+ in 'standards compliant mode'
				return document.documentElement.clientWidth;
			} else {
				if( document.body && document.body.clientWidth ) {
					//IE 4 compatible
					return document.body.clientWidth;
				}
			}
		}
	}


  	function getDocumentHeight() {
		if( typeof( window.innerHeight ) == "number" ) {
			// Non-IE
			return window.innerHeight;
		} else {
			if( document.documentElement && document.documentElement.clientHeight ) {

				//IE 6+ in 'standards compliant mode'
				return document.documentElement.clientHeight;
			} else {
				if( document.body && document.body.clientHeight ) {
					//IE 4 compatible
					return document.body.clientHeight;
				}
			}
		}
	}  	
  	
	function centerLayer(pLayerID, pLayerWidth, pLayerHeight) {
		var winWidth  = getDocumentWidth();
		var winHeight = getDocumentHeight();
		
		//alert( "Document Width: " + winWidth + "\nDocument Height: " + winHeight );
		
		var newLeft  = (winWidth - pLayerWidth) / 2;
		var newTop   = (winHeight - pLayerHeight) / 2;
		
		//alert( "Layer Left: " + newLeft + "\nLayer Top: " + newTop );

		var docLayer = getObject( pLayerID );
		
		if (docLayer != null) {
			docLayerStyle = getStyleObject( docLayer );

			if (docLayerStyle != null) {
   				docLayerStyle.top = newTop;
				docLayerStyle.left = newLeft;
			} else {
				alert( "Could not locate the layer object's style property for " + pLayerID );
			}
		} else { 
			alert( "Could not locate the layer object for " + pLayerID );
		}
	}


// Fix to the Netscape resize problem.  When the window resizes it is reloaded
// so that it properly formats itself with the new window dimensions.
function NetscapeResizeFix_reloadPage(init) {
	if (init == true) with (navigator) {
		if ( (appName == "Netscape") && (parseInt(appVersion)==4) ) {
			document.MM_pgW = innerWidth;
			document.MM_pgH = innerHeight;
			onresize = NetscapeResizeFix_reloadPage;
		}
	} else if (innerWidth != document.MM_pgW || innerHeight != document.MM_pgH) {
		location.reload();
	}
}
// Initialize the Netscape resize fix
NetscapeResizeFix_reloadPage(true);



// Method that does nothing.  Replaces the <a href="#"> code, which
// use to reload the page and put it in history.  Since it was in
// history, it would cause problems when clicking back.
function doNothing() {
}


function openPopupWindow(url, windowName, settings) {
	return window.open(url, windowName, settings);
}


// Opens a popup window that is centered on the screen.
function openCenteredPopupWindow(url, windowName, settings, windowWidth, windowHeight) {
	var windowX = (screen.width - windowWidth) / 2;
	var windowY = (screen.height - windowHeight) / 2;
	
	settings = settings + ",width=" + windowWidth + ",height=" + windowHeight + ",top=" + windowY + ",left=" + windowX;
	return window.open(url, windowName, settings);
}

//functions needed to check if a date is within certain range
function getYear(d) { 
  return (d < 1000) ? d + 1900 : d;
  }

function isDate (year, month, day) {
  // month argument must be in the range 0 - 11
  var tempDate = new Date(year,month,day);
  if ( (getYear(tempDate.getYear()) == year) &&
     (month == tempDate.getMonth()) &&
     (day == tempDate.getDate()) )
      return true;
  else
     return false;
  }

function isDateInRange(year, month, day, beginDate, endDate)
{
	
	if(!isDate(year, month, day))
	{
		
		return false;
	}
	
	
	var date = new Date(year, month, day);
	
	if((date.getTime()<beginDate.getTime()) || date.getTime()>endDate.getTime())
	{
		
		return false;
	}
	
	return true;
	
}


var veriSignSealWindow = null;
function openVeriSignSealWindow(digestNumber) {
	veriSignURL = "https://digitalid.verisign.com/as2/" + digestNumber;
	
	veriSignSealWindow = openCenteredPopupWindow(
		veriSignURL, 
		"VeriSignSealWindow", 
		"toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1",
		720, 
		450);

	self.name = "mainWin";
}
                  

function Trim(str)
{
	return str.replace(/^\s*|\s*$/g,"");
}

// Member Number Pad Digits (make sure it is numeric before padding zeros)
function PadDigits(value) 
    { 
    	var re = new RegExp(/^\d+$/);
   		if (re.test(value))
   		{
        	   	value = value.toString();         
        		var pd = ''; 
        		if (7 > value.length) 
        		{ 
            		for (i=0; i < (7-value.length); i++) 
            		{ 
                		pd += '0'; 
            		} 
        		} 
        		return pd + value.toString();             	
    	}
    	return value;
    }

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Common methods needed throughtout the application w/ specific application //
//                                                                           //
//                                END                                        //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////





///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Methods need by the web designer team - Macromedia Dreamweaver Tool       //
//                                                                           //
//                                START                                      //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

 
function MM_findObj(n, d) {
	return getObject(n, d);
}


//Dispaly Popup window using theURL as the contents.
//Ex: MM_openBrWindow('/home/example_text.htm','html','scrollbars=yes,width=320,height=400')
function MM_openBrWindow(url, windowName, features) {
	openPopupWindow(url, windowName, features);
}


function MM_jumpMenu(target, selObj, restore) {
	eval(target + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
	if (restore) {
		selObj.selectedIndex = 0;
	}
}


function MM_jumpMenuGo(selectName, target, restore) {
	var selObj = getObject(selectName);

	if (selObj) {
		MM_jumpMenu(target, selObj, restore);
	}
}


function MM_preloadImages() {
	var d = document;
  
	if (d.images) {
		if (!d.MM_p) {
			d.MM_p=new Array();
		}
  	
		var j = d.MM_p.length;
		var a = MM_preloadImages.arguments;
    
		for (var i = 0; i < a.length; i++) {
			if (a[i].indexOf("#") != 0) {
				d.MM_p[j] = new Image;
				d.MM_p[j++].src = a[i];
			}
		}
	}
}


function MM_swapImgRestore() {
	var x;
	var a = document.MM_sr;
  
	for (var i = 0; a != null && i <a.length && (x = a[i]) && x.oSrc; i++) {
		x.src = x.oSrc;
	}
}
 
  
function MM_swapImage() {
	var j = 0;
	var x;
	var a = MM_swapImage.arguments;
	document.MM_sr = new Array;
	
	for (var i = 0; i < (a.length - 2); i += 3) {
		if ((x = MM_findObj(a[i])) != null) {
			document.MM_sr[j++] = x;
			
			if (!x.oSrc) {
				x.oSrc = x.src; 
			}
				
			x.src = a[i + 2];
		}
	}
}

function MM_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])?args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) { img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr) for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function II_setImage(imgTag, img) {
	if(imgFind = MM_findObj(imgTag)) {
		imgFind.src = img;
	}
}

function ii_swapStyles(id, style1, style2) {		
	if((obj=document.getElementById(id))!=null) {		
		if(obj.className == style1) {
			obj.className = style2;
		} else {
			obj.className = style1;
		}
	}
}

function ii_swapText(id, text) {
	if((obj=document.getElementById(id))!=null) {		
			obj.innerHTML = text;

	}
}

function ii_setTab(tabName) {
	if((obj=document.getElementById("header"))!=null) {		
		obj.className = tabName;
	}	
}

function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
}                                                 

                                                                               
function MM_changeProp(objName,x,theProp,theValue) { //v6.0
  var obj = MM_findObj(objName);
  if (obj && (theProp.indexOf("style.")==-1 || obj.style)){
    if (theValue == true || theValue == false)
      eval("obj."+theProp+"="+theValue);
    else eval("obj."+theProp+"='"+theValue+"'");
  }
} 
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// Methods need by the web designer team - Macromedia Dreamweaver Tool       //
//                                                                           //
//                                END                                        //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// MISC Methods 														     //
//                                                                           //
//                                START                                      //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////

// Method: writeFastFactsPage()
// Argument(s): *NONE*
// Desc: Writes link for Fast Facts pop-up on Destination pages
// Returns: NULL
// Example: <script type="text/javascript">writeFastFactsPage()</script>
//
function writeFastFactsPage() {
	var pageName = queryStingArray['s'];
	var pageNameLength = pageName.length;
	var newPageName = pageName.substr(14, pageName.substr(14).length - 6) + "fast-facts.jsp";
	document.write("<iframe name='iframe_fast_facts' marginwidth='0' frameborder='no' scrolling='no' width='530' height='800' src='/web/_destinations/" + newPageName + "'></iframe>");
} 

// Method: getElementsByAttribute(attribute, attributeValue)
function getElementsByAttribute(attribute, attributeValue)
{
  var elementArray = new Array();
  var matchedArray = new Array();

  if (document.all)
  {
    elementArray = document.all;
  }
  else
  {
    elementArray = document.getElementsByTagName("*");
  }

  for (var i = 0; i < elementArray.length; i++)
  {
    if (attribute == "class")
    {
      var pattern = new RegExp("(^| )" + attributeValue + "( |$)");

      if (pattern.test(elementArray[i].className))
      {
        matchedArray[matchedArray.length] = elementArray[i];
      }
    }
    else if (attribute == "for")
    {
      if (elementArray[i].getAttribute("htmlFor") || elementArray[i].getAttribute("for"))
      {
        if (elementArray[i].htmlFor == attributeValue)
        {
          matchedArray[matchedArray.length] = elementArray[i];
        }
      }
    }
    else if (elementArray[i].getAttribute(attribute) == attributeValue)
    {
      matchedArray[matchedArray.length] = elementArray[i];
    }
  }

  return matchedArray;
}

function attachEventListener(target, eventType, functionRef, capture) {
  if (typeof target.addEventListener != "undefined")
  {
    target.addEventListener(eventType, functionRef, capture);
  }
  else if (typeof target.attachEvent != "undefined")
  {
    target.attachEvent("on" + eventType, functionRef);
  }
  else
  {
    eventType = "on" + eventType;

    if (typeof target[eventType] == "function")
    {
      var oldListener = target[eventType];

      target[eventType] = function()
      {
        oldListener();

        return functionRef();
      }
    }
    else
    {
      target[eventType] = functionRef;
    }
  }

  return true;
}

function showPreventRenewalMessage(message1, message2, message3){
   	 alert(message1 + "\n" + message2 + "\n" + message3);
}

function showBestPriceGuarantee(theAction){
	document.forms[0].action=theAction;
	document.forms[0].submit();
}
///////////////////////////////////////////////////////////////////////////////
//                                                                           //
// MISC Methods 														     //
//                                                                           //
//                                END                                        //
//                                                                           //
///////////////////////////////////////////////////////////////////////////////