navTimer = null;
currentNav = 0;
o_navigator = navigator.userAgent
var isIE5 = (o_navigator.indexOf("MSIE 5") > -1) ? 1 : 0;
var isMac = (o_navigator.indexOf("Mac") > -1) ? 1 : 0;
var isIE50 = (o_navigator.indexOf("MSIE 5.0") > -1) ? 1 : 0;
var isIE52 = (o_navigator.indexOf("MSIE 5.2") > -1) ? 1 : 0;
var isNN6 = (o_navigator.indexOf("Netscape6") > -1) ? 1 : 0;
var isDOM = (document.getElementById) ? 1 : 0;

function mainNavOver(o_div){
	if (isDOM && !isNN6 && !isIE52 && !isIE50){
		if (currentNav)
			currentNav.className = "";
		clearTimeout(navTimer);
		o_div.className = "navOver";
	}
}
function mainNavOut(o_div){
	if (isDOM && !isNN6 && !isIE52 && !isIE50) {
		currentNav = o_div;
		navTimer = setTimeout('currentNav.className=""', 1);
	}
}
function launchWindow(url,w,h,scrollbars){
	winName = "_new"
	if (!h)
		popHeight = screen.availHeight - 100;
	else 
		popHeight = h;
	winParams = (scrollbars) ? 'scrollbars=yes,' : 'scrollbars=no,';
	winParams += 'toolbar=no,location=no,directories=no,status=no,menubar=no,resizable=yes,width=' + w + ',height=' + popHeight;
	newwin = window.open(url, winName, winParams);
	newwin.focus();
}

function rotateBanners( bannersArray, height, width, border ) {
	var choice = Math.floor( Math.random() * bannersArray.length );
	if ( bannersArray[choice].src ) {
		var bannerHTML = '<img src="' + bannersArray[choice].src +
			'" height="' + height +
			'" width="' + width +
			'" border="' + border +
			'" alt="' + bannersArray[choice].alt + '">';
		if ( bannersArray[choice].href ) {
			bannerHTML = '<a href="' + bannersArray[choice].href +
				'">' + bannerHTML + '</a>';
		}
		return bannerHTML;
	} else {
		return "The banner image was not defined."
	}
}

function qsToArray() 
{
	var ret = new Object();
	var kvpairs = new Array();
	var qs = location.search.replace("?", "");
	kvpairs = qs.split("&");

	for (var i = 0; i < kvpairs.length; i++) {
		var tmp = new Array();
		tmp = kvpairs[i].split("=");
		ret[tmp[0]] = tmp[1]; 
	}
	return ret;
}

function ckToArray()
{
	var ret = new Object();
	var ck  = new Array();
	ck = document.cookie.split(";");

	for (var i = 0; i < ck.length; i++) {
		var tmp = new Array();
		tmp = ck[i].split('=');
		ret[tmp[0]] =tmp[1]; 
	}
	return ret;
}

function getValueByKey(array, key)
{
	var ret = "";
	for (k in array) {
		if (k.match(key) != null) {
			ret = array[k];
			break;
		}
	}
	return ret;
}

function getSrvc()
{
	var ret = "";
	ret = getValueByKey(ckToArray(), 'tvly_service');
	if (ret == "")
		ret = getValueByKey(qsToArray(), 'Service');
	if (ret == "")
		ret = "TRAVELOCITY";
	return ret;
}

function sendSrvc() 
{
   	var srvc = getSrvc();

   	for ( var i = 0; i < document.links.length; i++ ) {   
		var l = document.links[i];
       	if (l.href.indexOf("REPLACE_SERVICE") < 0)
			continue;
	
       	document.links[i].href = l.href.replace(/REPLACE_SERVICE/, srvc);
   	}
}




function getCookieVal ( offset ) 
{
	var endstr = document.cookie.indexOf( ";", offset );
	if ( endstr == -1 ) 
		endstr = document.cookie.length;
	return unescape( document.cookie.substring( offset, endstr ) );
}
function get_cookie( c ) 
{
	var arg  = c + "=";
	var alen = arg.length;
	var clen = document.cookie.length;
	var i = 0;
	while ( i < clen ) {
		var j = i + alen;
		var c = document.cookie.substring( i, j );
		if ( document.cookie.substring( i, j ) == arg ) {
			return getCookieVal( j );
		}
		i = document.cookie.indexOf( " ", i ) + 1;
		if ( i == 0 ) {
			break;
		}
	}
	return null;
}

function popUp() {
	if ( get_cookie( "ck_popup" ) == null ) {
		var popwin = "user_registration.html";
		var windowprops = "location=no,directories=no,scrollbars=no,menubars=no,statusbar=no,toolbars=no,resizable=no,width=340,height=420,left=360,top=110" ;
		mywindow = open(popwin,'emailreg',windowprops);
		if (mywindow) {
			mywindow.location.href = popwin;
			window.name = "index";
			if (mywindow.opener == null) 
				mywindow.opener = self;
		}
	}
}

function popUnder() {

	var affiliate = get_cookie( "ck_affiliate_key" )

	if ( affiliate != null ) {
		if (affiliate == 9985 || affiliate == 9986 || affiliate == 9982 || affiliate == 9983) return;
	}
	// Current date to use for comparison
	var d = new Date();

	popWidth = 500;
	popHeight = 250;

	if ( document.all ) {
		popLeft = 5000;
		popTop = 5000;
	} else {
		popLeft = (screen.width - popWidth)/2;
		popTop = ((screen.height - popHeight)/2) - 20;
	}

	// Travelocity popunder settings
	var popwin = "/tvly_tt.html?in_promoclick=tvly_pop_launched";
	var windowprops = "location=no,directories=no,scrollbars=no,menubars=no,statusbar=no,toolbars=no,resizable=no,width=" + popWidth  + ",height=" + popHeight  + ",left=" + popLeft  + ",top=" +  popTop;

	// If cookie doesn't exist, launch popunder
	// Then set it to launch again the next day
	if ( get_cookie( "ck_s59popunder" ) == null ) {

		mywindow = open(popwin,'tvly_tt',windowprops);
		setExpiry(d);
		
	} else {

		expiry = get_cookie( "ck_s59popunder" );

		// Test whether the user has disabled the popunder
		if ( expiry != '0' ) {

			// Test whether the current time exceeds the time for relaunch
			if ( d.getTime() > expiry ) {

				// If so, launch popunder and reset expiry time
				mywindow = open(popwin,'tvly_tt',windowprops);
				setExpiry(d);
			}
		}
	}
	self.focus();
}

// Sets the time in which popunder suppression expires.
// Unless user clicks the "Don't show again" link, 
// popunder automatically relaunches after the next day

function setExpiry(d) {

	var expiry = new Date();
	expiry.setDate(d.getDate()+1); // Launch popunder the next day
	expiry.setHours(0);
	expiry.setMinutes(0);
	expiry.setMilliseconds(0);

	// set cookie with expiry time and one year lifespan
	nextYear = new Date();
	nextYear.setFullYear( nextYear.getFullYear() + 1); // cookie expires a year from now
	document.cookie = "ck_s59popunder=" + expiry.getTime() + "; expires=" + nextYear.toGMTString();
	return true;
}

function getObjStyle(name) {
	if (document.getElementById) {
		return document.getElementById(name).style;
	 } else if (document.all) {
	   	return document.all[name].style;
	 } else if (document.layers) {
	   	return document.layers[name];
	 } else 
	 	return false;
}

function getObjDoc(name) {
	if (document.getElementById) {
		return document;
	} else if (document.all) {
	  	return document.all[name].document;
	} else if (document.layers) {
	  	return document.layers[name].document;
	} else 
		return false;
}

function getSelectedIndex(select, val) {
	for (var i = 0; i < select.length; i++) {
		if (select.options[i].value == val) 
			return i;
	}
	return 0;
}

function getCheckedIndex(checkbox, val) {
	if (!hasValue(checkbox))
		return 0;
        if (hasValue(val)) {
			for (var i = 0; i < checkbox.length; i++) {
				if (checkbox[i].value == val) 
					return i;
			}
        }
        return 0;
}

function flipLayers(layerOne,layerTwo) {
	self.scrollTo(0,0);
	var mainLayerType = getObjStyle(layerOne);
	mainLayerType.display = 'none';
	var timeLayerType = getObjStyle(layerTwo);
	timeLayerType.display = 'block';
}

function flipInlines(layerOne,layerTwo) {
	self.scrollTo(0,0);
	var mainLayerType = getObjStyle(layerOne);
	mainLayerType.display = 'none';
	var timeLayerType = getObjStyle(layerTwo);
	timeLayerType.display = 'inline';
}


var agt = navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer') == -1)
                && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera') == -1)
                && (agt.indexOf('webtv')==-1) && (agt.indexOf('hotjava') == -1));
var is_nav4up = (is_nav && (is_major >= 4));
var is_nav4   = (is_nav && (is_major == 4));
var is_nav6up = (is_nav && (is_major >= 5));
var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
var is_ie3    = (is_ie && (is_major < 4));
var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4") != -1) );
var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
var is_mac    = (agt.indexOf("mac")!=-1);

var oldBrowser = 0;
if (!(is_nav6up || is_ie5up)) { oldBrowser = 1; }


