// Used for Fireclick Tracking from Flash SWF
function call_fc_flash(arg1, arg2) {
    if (typeof(fc_flash) == "function") {
        fc_flash(arg1, arg2);
    }
}

function hideInterstitial() {
    document.write('</div>');
    if (document.getElementById) {
    	document.getElementById('interstitial-box').style.display = 'none';
    	document.getElementById('loading-container').style.display = 'block';

        if (document.body) {
            document.body.style.backgroundImage = "url(/images/promotions/bg_tile.gif)";
        }
        if (document.documentElement) {
            document.documentElement.style.backgroundImage = "url(/images/promotions/bg_tile.gif)";
        }
    }
}

function hideInterstitial2() {
    if (document.getElementById) {
    	document.getElementById('interstitial-box').style.display = 'none';
    	document.getElementById('loading-container').style.display = 'block';

        if (document.body) {
            document.body.style.backgroundImage = "url(/images/promotions/bg_tile.gif)";
        }
        if (document.documentElement) {
            document.documentElement.style.backgroundImage = "url(/images/promotions/bg_tile.gif)";
        }
    }
}

function showInterstitialFlash() {
    document.write('<object type="application/x-shockwave-flash" data="/images/chrysalis/interstitial/searching.swf" width="250" height="160">\n');
    document.write('  <param name="movie" value="/images/chrysalis/interstitial/searching.swf" />\n');
    document.write('  <img src="/images/chrysalis/interstitial/searching.png" width="250" height="160" alt="Loading" />\n');
    document.write('</object>\n');
}

function hideWaitScreen() {
	var oWait = null, elemWait = null;
	if (document.getElementById) { // IE 5+/NS6
		elemWait = document.getElementById('waitScreen');
		if (elemWait != null) {
			oWait = elemWait.style;
		}
	} else if (document.layers) {
		oWait = document.layers['waitScreen'];
	} else if (document.all) {
		elemWait = document.all['waitScreen'];
		if (elemWait != null) {
			oWait = elemWait.style;
		}
	}
	if (oWait != null) {
		oWait.visibility = 'hidden';
	}
}


function popupBook(url) {
	var w=window.open(url, "myWindow", 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=0,resizable=0,width=503,height=250');
	w.focus();
}


function popUp(url) {
	sealWin=window.open(url,"win",'toolbar=0,location=0,directories=0,status=1,menubar=1,scrollbars=1,resizable=1,width=500,height=450');
	self.name = "mainWin";
}

function openNewWindow(fileName,windowName,theWidth,theHeight) {
	if (windowName == "newWindow") {
		 windowName = new String(Math.round(Math.random() * 100000));
	}
	window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight)
}

function openMapWindow(mapUrl,windowName,width,height) {
	window.open(mapUrl,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+width+",height="+height)
}
function openMapWithPropInfo(mapUrl,propInfo,propInfoString,windowName,width,height) {
	var newUrl;
	if (isNN3 || isNN4 || isNN6) {
		newUrl = mapUrl + propInfo + propInfoString;
	} else {
		newUrl = mapUrl + propInfo + escape(propInfoString);
	}	
	window.open(newUrl,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+width+",height="+height)	
}

function openNewWindowEscape(fileName,windowName,theWidth,theHeight,to) {
	if (windowName == "newWindow") {
		 windowName = new String(Math.round(Math.random() * 100000));
	}
	var encoded = escape(to);
	encoded = fileName + encoded;
	window.open(encoded,windowName,"toolbar=1,location=1,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight)
}

function openNewWindowReturnFalse(fileName,windowName,theWidth,theHeight) {
	if (windowName == "newWindow") {
		 windowName = new String(Math.round(Math.random() * 100000));
	}
	var w = window.open(fileName,windowName,"toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight);
	return false;
}

function openPopup(url, to, windowName, theWidth, theHeight) {
	var newURL;
	if (isNN3 || isNN4) {
		newURL = url + to;
	} else {
		newURL = url + escape(to);
	}
	window.open(newURL,windowName,"toolbar=1,location=1,directories=0,status=0,menubar=1,scrollbars=1,resizable=1,width="+theWidth+",height="+theHeight)
}

function openPopup3(url, name1, param1, name2, param2, name3, param3, windowName, theWidth, theHeight) {
	var wSettings = 'toolbar=1,location=1,directories=0,status=0,menubar=1,scrollbars=1,resizable=1';
	openPopupWin(url, name1, param1, name2, param2, name3, param3, windowName, wSettings, theWidth, theHeight);
}

function openMapNetscape(url, name1, param1, name2, param2, name3, param3, windowName, theWidth, theHeight) {
	var wSettings = 'toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=1,resizable=1';
	openPopupWin(url, name1, param1, name2, param2, name3, param3, windowName, wSettings, theWidth, theHeight);
}

function openPopupWin(url, name1, param1, name2, param2, name3, param3, windowName, windowSettings, theWidth, theHeight) {
	var newURL;
	windowSettings += ',width='+theWidth+',height='+theHeight;
	if (isNN3 || isNN4) {
		newURL = url + name1 + param1 + name2 + param2 + name3 + param3;
	} else {
		newURL = url + name1 + escape(param1) + name2 + escape(param2) + name3 + escape(param3);
	}
	window.open(newURL,windowName,windowSettings);
}

function open_calendar(strType) {
	document.myform.inout.value = strType;
	new_window=window.open("calendar.htm","","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width=300,height=200");
}

function popup(url, name, width, height) {
	settings="toolbar=yes,location=yes,directories=yes,"+"status=no,menubar=no,scrollbars=yes,"+"resizable=yes,width="+width+",height="+height;
	MyNewWindow=window.open("http://"+url,name,settings);
}

function getMousePos(e) {
    xPos = 0;
    yPos = 0;
    if (!e) var e = window.event;
    if (e.pageX || e.pageY)
    {
        xPos = e.screenX;
        yPos = e.screenY;
    }
    else if (e.clientX || e.clientY)
    {
        xPos = e.screenX;
        yPos = e.screenY;
    }
}

function openPopWindow(pageLocation,winName, pgW, pgH) {
	winStats='toolbar=no,location=no,directories=no,menubar=no,';
	winStats+='scrollbars=no,width=' + pgW + ',height=' + pgH ;

	if (navigator.appName.indexOf("Microsoft")>=0) {
		winStats+=',left=' + (xPos) + ',top=' + (-200 + yPos);
	} else {
		winStats+=',screenX='+ (xPos) + ',screenY=' + (yPos - 300);
	}

	floater=window.open(pageLocation,winName,winStats);
	if (floater!=null) { if (floater.focus) { floater.focus() } };
}

function openCalWindow(thisPage, strType, CalLocation) {
	document.myform.inout.value = strType;

	// Switch to JSP, this is a catch-all for old code.  Should be removed eventually
	if (thisPage=='popcal.html') { thisPage = 'popcal.jsp'; }

	if ( strType == 'out') {
		thisPage = thisPage + '?' + new String(document.myform.COMonth.value -1) + ',' + document.myform.COYear.value
	} else {
		thisPage = thisPage + '?' + new String(document.myform.CIMonth[document.myform.CIMonth.selectedIndex].value -1) + ',' + document.myform.CIYear.value
	}

	winStats='toolbar=no,location=no,directories=no,menubar=no,'

	//IE/NS
	if (navigator.appName.indexOf("Microsoft")>=0) {winStats+='scrollbars=no,width=160,height=180'}
	else {winStats+='scrollbars=no,width=160,height=170'}

	//IE leftnav area
	if (navigator.appName.indexOf("Microsoft")>=0) {
			if(CalLocation == 'leftNavArea')
				{winStats+=',left=' + (xPos) + ',top=' + (yPos)
				 }//IE content area
			else if (CalLocation == 'contentArea')
				{winStats+=',left=' + (-200 + xPos) + ',top=' + (-160 + yPos)
				}
			else if (CalLocation == 'calendarArea')
				{winStats+=',left=' + (-150 + xPos) + ',top=' + (yPos + 20)
				}	
    } else {
		//Netscape leftnav area
		if(CalLocation == 'leftNavArea')
				{winStats+=',screenX='+ (xPos) + ',screenY=' + (yPos)
				 }//Netscape content area
			else if (CalLocation == 'contentArea')
				{winStats+=',screenX='+ (-150 + xPos) + ',screenY=' + (-230 + yPos)
				}
			else if (CalLocation == 'calendarArea')
				{winStats+=',screenX='+ (-150 + xPos) + ',screenY=' + (yPos + 20)
				}	
    }
	floater=window.open(thisPage,"myform",winStats)
	if (floater!=null) { if (floater.focus) { floater.focus() } };
}

function openCalWindowDo(thisPage, strType, CalLocation, year, month, day) {
    if (document.forms[0].name == "myform") {
        document.forms[0].inout.value = strType;
    } else {
        document.forms[1].inout.value = strType;
    }
    
    // Switch to JSP, this is a catch-all for old code.  Should be removed eventually
    if (thisPage=='popcal.html') { 
        thisPage = 'popcal.jsp'
    }
    if (thisPage=='popcal.jsp') {
        thisPage = '/popCalendar.do'
    }

    var formDay;
    var formMonth;
    var formYear;
    
    if (document.forms[0].name == "myform") {
    
        if ( strType == 'out') {
            formDay = document.forms[0].CODay[document.forms[0].CODay.selectedIndex];
            formMonth = document.forms[0].COMonth[document.forms[0].COMonth.selectedIndex];
            formYear = document.forms[0].COYear.value;
        } else {
            formDay = document.forms[0].CIDay[document.forms[0].CIDay.selectedIndex];
            formMonth = document.forms[0].CIMonth[document.forms[0].CIMonth.selectedIndex];
            formYear = document.forms[0].CIYear.value;
        }
    } else {
        if ( strType == 'out') {
            formDay = document.forms[1].CODay[document.forms[1].CODay.selectedIndex];
            formMonth = document.forms[1].COMonth[document.forms[1].COMonth.selectedIndex];
            formYear = document.forms[1].COYear.value;
        } else {
            formDay = document.forms[1].CIDay[document.forms[1].CIDay.selectedIndex];
            formMonth = document.forms[1].CIMonth[document.forms[1].CIMonth.selectedIndex];
            formYear = document.forms[1].CIYear.value;
        }
    }
    
    var currDay = formDay.value;
    var currMonth = formMonth.value;
    if (currMonth > 1 && currDay == -1) {
    	currDay = 0;
    }else if (currMonth < 1 || currDay < 1) {
        currDay = day;
        currMonth = month;
        formYear = year;
    }
    else {
        var monthText = formMonth.text;
        if (monthText.length > 5 && monthText.charAt(monthText.length - 5) == ' ') {
            formYear = monthText.substr(monthText.length - 4);
        }
    }
    thisPage = thisPage 
        + '?' + currMonth // cal month
        + ',' + formYear  // cal year
        + ',' + formYear  // form year (or today)
        + ',' + currMonth // form month (or today)
        + ',' + currDay   // form day (or today)

    winStats='toolbar=no,location=no,directories=no,menubar=no,'

    //IE/NS
    if (navigator.appName.indexOf("Microsoft")>=0) {winStats+='scrollbars=no,width=160,height=180'}
    else {winStats+='scrollbars=no,width=160,height=170'}

    //IE leftnav area
    if (navigator.appName.indexOf("Microsoft")>=0) {
            if(CalLocation == 'leftNavArea')
                {winStats+=',left=' + (xPos) + ',top=' + (yPos)
                 }//IE content area
            else if (CalLocation == 'contentArea')
                {winStats+=',left=' + (-200 + xPos) + ',top=' + (-160 + yPos)
                }
            else if (CalLocation == 'calendarArea')
                {winStats+=',left=' + (-150 + xPos) + ',top=' + (yPos + 20)
                }   
    } else {
        //Netscape leftnav area
        if(CalLocation == 'leftNavArea')
                {winStats+=',screenX='+ (xPos) + ',screenY=' + (yPos)
                 }//Netscape content area
            else if (CalLocation == 'contentArea')
                {winStats+=',screenX='+ (-150 + xPos) + ',screenY=' + (-230 + yPos)
                }
            else if (CalLocation == 'calendarArea')
                {winStats+=',screenX='+ (-150 + xPos) + ',screenY=' + (yPos + 20)
                }   
    }
    floater=window.open(thisPage,"myform",winStats)
    if (floater!=null) { if (floater.focus) { floater.focus() } };
}

function openWindow(thisPage, strType) {
	document.myform.inout.value = strType;
	thisPage = thisPage + '?' + new String(document.myform.CIMonth[document.myform.CIMonth.selectedIndex].value -1) + ',' + document.myform.CIYear.value

	if ( strType == 'out') {
		thisPage = thisPage + '?' + new String(document.myform.COMonth.value -1) + ',' + document.myform.COYear.value
	}
	winStats='toolbar=no,location=no,directories=no,menubar=no,'
	winStats+='scrollbars=no,width=160,height=140'
	if (navigator.appName.indexOf("Microsoft")>=0) {
     	  winStats+=',left=' + (xPos) + ',top=' + (yPos)
	} else {
	winStats+=',screenX='+ (xPos) + ',screenY=' + (yPos)
	}
	floater=window.open(thisPage,"myform",winStats)
	if (floater!=null) { if (floater.focus) { floater.focus() } };

}
function initializeDates()
{
	var thisdate = new Date();
	var thismonth = thisdate.getMonth();
	var thisday = thisdate.getDate();
	var thisyear = thisdate.getFullYear();

	document.myform.CIMonth.value = thismonth+1;
	document.myform.CIYear.value = thisyear;
	document.myform.CIDay.value = thisday+7;

	document.myform.COMonth.value = thismonth+1
	document.myform.COYear.value = thisyear;
	document.myform.CODay.value = thisday+7+1;
}

function doSelectOptions(theValue,theField) {

	var objForm = document.myform;
	for (i=0; i< objForm[theField].options.length; i++)
		if (objForm[theField].options[i].value == theValue) {
			objForm[theField].options[i].selected = true;
		}
}

function updateBothDates(theForm)
{
	var worker	= new Date();
	calcBothDates(theForm, (worker.getYear()%1900+1900), worker.getMonth()+1, worker.getDate());
}
function calcBothDates(theForm, ty, tm, td)
{
	calcBothDates2(theForm, ty, tm, td, 2);
}

function calcBothDates2(theForm, ty, tm, td, daysInAdvance)
{
	var today	= new Date((ty%1900+1900), tm-1, td, 0,0,0);
	var inDate	= new Date((ty%1900+1900), parseInt(document.myform.CIMonth[document.myform.CIMonth.selectedIndex].value)-1, document.myform.CIDay[document.myform.CIDay.selectedIndex].value, 0,0,0);
	
	//When calculating inDate value for next year months, the value 'ty' is not representing the 
	//forth coming year but the current year.
	//Since in our site we will show only current month and the months after.. 	
	if(inDate.getMonth() < today.getMonth()){
		ty = ty+1;
		inDate = new Date((ty%1900+1900), parseInt(document.myform.CIMonth[document.myform.CIMonth.selectedIndex].value)-1, document.myform.CIDay[document.myform.CIDay.selectedIndex].value, 0,0,0);
	}
	
	var outDate	= new Date((ty%1900+1900), parseInt(document.myform.CIMonth[document.myform.CIMonth.selectedIndex].value)-1, parseInt(document.myform.CIDay[document.myform.CIDay.selectedIndex].value)+daysInAdvance, 0,0,0);

	if (inDate.getTime()  < today.getTime()) { // Crossed the newyear boundary
		inDate.setYear((today.getYear()%1900+1900)+1);
		outDate.setYear((today.getYear()%1900+1900)+1);
	}

	theForm.CIYear.value	= (inDate.getYear()%1900) + 1900;
	doSelectOptions(inDate.getMonth()+1, 'CIMonth');
	doSelectOptions(inDate.getDate(), 'CIDay');

	theForm.COYear.value	= (outDate.getYear()%1900) + 1900;
	doSelectOptions(outDate.getMonth()+1, 'COMonth');
	doSelectOptions(outDate.getDate(), 'CODay');
}

function updateCIDate(theForm)
{
	var worker	= new Date();
	calcCIDate(theForm, (worker.getYear()%1900+1900), worker.getMonth()+1, worker.getDate());
}
function calcCIDate(theForm, ty, tm, td)
{
	var today	= new Date((ty%1900+1900), tm-1, td, 0,0,0);
	var inDate	= new Date((ty%1900+1900), parseInt(document.myform.CIMonth[document.myform.CIMonth.selectedIndex].value)-1, document.myform.CIDay[document.myform.CIDay.selectedIndex].value, 0,0,0);

	if (inDate.getTime()  < today.getTime()) { // Crossed the newyear boundary
		inDate. setYear((today.getYear()%1900+1900)+1);
	}

	theForm.CIYear.value	= (inDate.getYear()%1900) + 1900;
	doSelectOptions(inDate.getMonth()+1, 'CIMonth');
	doSelectOptions(inDate.getDate(), 'CIDay');
}

function updateCODate(theForm)
{
	var worker	= new Date();
	calcCODate(theForm, (worker.getYear()%1900+1900), worker.getMonth()+1, worker.getDate());
}
function calcCODate(theForm, ty, tm, td)
{
	var today	= new Date((ty%1900+1900), tm-1, td, 0,0,0);
	var outDate	= new Date((ty%1900+1900), parseInt(document.myform.COMonth[document.myform.COMonth.selectedIndex].value)-1, parseInt(document.myform.CODay[document.myform.CODay.selectedIndex].value), 0,0,0);

	if( (parseInt(theForm.CIYear.value)%1900) >(today.getYear()%1900) || (outDate.getTime() < today.getTime()) ){
		outDate	= new Date((ty%1900+1900)+1, parseInt(document.myform.COMonth[document.myform.COMonth.selectedIndex].value)-1, parseInt(document.myform.CODay[document.myform.CODay.selectedIndex].value), 0,0,0);
	}

	theForm.COYear.value	= (outDate.getYear()%1900) + 1900;
	doSelectOptions(outDate.getMonth()+1, 'COMonth');
	doSelectOptions(outDate.getDate(), 'CODay');
}

function searchDebug() { alert('CIYear='+myform.CIYear.value+', COYear='+myform.COYear.value); }
function changeRezDebug() { alert('CIYear='+myform.CIYear.value+', COYear='+myform.COYear.value); }
function debugRefineLeftnav() { alert('CIYear='+myform.CIYear.value+', COYear='+myform.COYear.value); }

function focusOnSecTwo(destNum) {
    if (isIE) {
	if (document.forms.myform.usertypedcity.value != "") {
	    document.forms.myform.destination[0].checked = true;
	} else {
	    if (destNum > 1) {
		destNumAry = new Array(
		    2, 5, 8, 11, 14, 
		    3, 6, 9, 12, 15, 
		    4, 7, 10, 13, 16);
		eval('document.forms.myform.destination[' + destNumAry[destNum] + '].checked = true;');
	    }
	}
	window.setTimeout('document.forms.myform.CIMonth.focus()', 200);
    } else {
	document.forms.myform.CIMonth.focus();
    }
}
function selectUserTyped() {
    if (isIE) {
	if (document.forms.myform.usertypedcity.value != "") {
	    document.forms.myform.destination[0].checked = true;
	}
    }
}

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 getCookie(name) {
  var dc = document.cookie;
  var prefix = name + "=";
  var begin = dc.indexOf("; " + prefix);
  if (begin == -1) {
    begin = dc.indexOf(prefix);
    if (begin != 0) return null;
  } else {
    begin += 2;
  }
  var end = document.cookie.indexOf(";", begin);
  if (end == -1) {
    end = dc.length;
  }
  return unescape(dc.substring(begin + prefix.length, end));
}

function getRequestedPage(currentPage, direction){
	alert(direction);
	var requestedPage = document.getElementById("requestedPage");
	if(direction == "next")
		requestedPage.value = currentPage + 1;
	if(direction == "previous")
		requestedPage.value = currentPage - 1;
		
	alert("after being set :: "+requestedPage.value);	
}

function setCurrentTab(tab, anchor) {
	var target = anchor.href;
    if (target.indexOf('?') > 0) {
        target += '&tab=' + tab;
    } else {
        target += '?tab=' + tab;
    }
    if (isSafari) {
    	anchor.href = target;
    } else {
    	window.location = target;
    }
}
function setCurrency(currency) {
        
    var target = window.location.href;
    var curIndex = target.indexOf('currency');
	var anchorIndex = target.indexOf('#');
	
	var trailer = '';

    if ( curIndex > 0) 
    {
        if (curIndex + 12 < target.length) {
                trailer = target.substring(curIndex+12);
        }
        target = target.substr(0, curIndex-1);
    } else if ( anchorIndex > 0 ) {
    	trailer = target.substr(anchorIndex);
    	target = target.substr(0, anchorIndex);
    }
    if (target.indexOf('?') > 0) {
        target += '&currency=' + currency;
    } else {
        target += '?currency=' + currency;
    }
    target += trailer;
    window.location = target;
}

function setCountry(country) {

	if (country == null || country.length < 0) {
		return false;
	}        
    var target = window.location.protocol + '//' + window.location.hostname;
    if (window.location.port != null) {
    	target += ':' + window.location.port;
    }
    target += '/?requestedCountry=' + country; 
    window.location = target;
    return true;
}


function showCurrentTab (currentTab) {
	if (currentTab) {
		var elem = document.getElementById(currentTab + "Link");
		elem.onmouseover=function(evt){};
		elem.onmouseout=function(evt){};

		var img = document.images[currentTab];
		img.src = "/images/header/tab-" + currentTab + "_on.gif";
	}
}
