if(typeof(Event) != "undefined")
	Event.unloadCache = function() {} 

function clearRadio() {
    // clear the city text box
    document.forms[0].city.value = '';
    var radios = document.forms[0].rCity;
    for (i = 0; i < radios.length; i++)
    radios[i].checked = false;
}



function OpenDates(file,input) {
    window.open(file, input, 'width=300,height=300,resizable=1');
}


function OpenCalendar(dayField, day, monthField, month, yearField, year)  {
    file = '/util/calendar.jsp?formName=frm_Search';
    if ( dayField != null )
      file += '&dayField=' + dayField + '&day=' + day;
    if ( monthField != null )
      file += '&monthField=' + monthField + '&month=' + month;
    if ( yearField != null )
      file += '&yearField=' + yearField + '&year=' + year;
    window.open( file, "dates", 'width=300,height=300,resizable=1');
}


function OpenLogWindow(file,input) {
    window.open(file, input, 'width=250,height=175,resizable=1,status=1');
}


function isBrowserSupp() {
    version =  parseFloat( navigator.appVersion );
	if ( ( version >= 2.0 ) && ( version < 2.1 ) && ( navigator.appName.indexOf( "Netscape" ) != -1 ) ) {
        return false;
    }
    else {
    	return true;
    }
	return true;
}


function isLeapYear(yrStr) {
	var leapYear=false;
	var year = parseInt(yrStr, 10);
	if (year%4 == 0) {
	    leapYear=true;
    	if (year%100 == 0) {
	        leapYear=false;
        	if (year%400 == 0) {
	            leapYear=true;
            }
        }
    }
	return leapYear;
}

function getDaysInMonth(mthIdx, YrStr) {
	var maxDays=31
	if (mthIdx==2) {
	    if (isLeapYear(YrStr)) {
	        maxDays=29;
        }
    	else {
	        maxDays=28;
        }
    }
	if (mthIdx==4 || mthIdx==6 || mthIdx==9 || mthIdx==11) {
	    maxDays=30;
    }
	return maxDays;
}


function adjustDate(mthIdx, Dt) {
	var value=0;
	var today = new Date()
	var theYear = parseInt(today.getYear(),10)
	if (mthIdx < today.getMonth()) {
    	theYear = (parseInt(today.getYear(), 10) + 1)
	}
	if(theYear<100){
    	theYear = "19" + theYear
	}
	else {
    	if((theYear-100) < 10) {
        	theYear = "0" + (theYear-100)
    	}
    	else{
        	theYear = (theYear-100)+""
    	}
    	theYear = "20" + theYear
	}
	var numDays=getDaysInMonth(mthIdx, theYear);
	if (mthIdx==1) {
	    if (Dt.options.selectedIndex < numDays) {
	        return 0;
        }
    	else {
        	Dt.options.selectedIndex=numDays - 1;
        	if (numDays==29) {
	            return 99;
            }
        	else {
            	return 1;
            }
        }
    }
	if (Dt.options.selectedIndex < numDays) {
    	value=0;
    }
	else {
    	if (Dt.options.selectedIndex > numDays) {
	        Dt.options.selectedIndex ;
       	 	value=3;
        }
    	else {
        	value=2;
        }
    }
	return value;
}

function amadChange(inM,inD,outM,outD) {
    if (!isBrowserSupp()) {
    	return;
    }
	var res = adjustDate(inM.options.selectedIndex, inD);
	if (res != 0) {
		outD.options.selectedIndex=0;
        if (outM.options.selectedIndex==12){
        	outM.options.selectedIndex=1
		}
        else {
			outM.options.selectedIndex=inM.options.selectedIndex;
        }
    } 
    else {
    	outM.options.selectedIndex = inM.options.selectedIndex;
    	outD.options.selectedIndex = inD.options.selectedIndex+2;
    }
	return ;
}

function dmddChange(outM,outD) {
    if (!isBrowserSupp()) {
	    return;
    }
	adjustDate(outM.options.selectedIndex,outD);
	return;
}

function hideProcess() {
    document.getElementById('process').style.visibility = "hidden";
	document.getElementById('overlay').style.visibility = "visible";
}

function setPriceRange(form, min, max) {
	if (min == null)
		$(form).priceRangeMin.value = "";
	else
		$(form).priceRangeMin.value = min;
		
	if (max == null)
		$(form).priceRangeMax.value = "";
	else
		$(form).priceRangeMax.value = max;
}

function setPriceRange(form) {
	if(form.priceRanges.options[1].selected) {
		form.priceRangeMin.value = null;
		form.priceRangeMax.value = 74;
	}
	else if(form.priceRanges.options[2].selected) {
		form.priceRangeMin.value = 75;
		form.priceRangeMax.value = 125;
	}
	else if(form.priceRanges.options[3].selected) {
		form.priceRangeMin.value = 125;
		form.priceRangeMax.value = 200;
	}
	else if(form.priceRanges.options[4].selected) {
		form.priceRangeMin.value = 200;
		form.priceRangeMax.value = null;
	}
	else {
		form.priceRangeMin.value = null;
		form.priceRangeMax.value = null;
	}
}

function showAmenities() {
	if (Element.visible($('priceRanges'))) {
		new Effect.SwitchOff($('priceRanges'));
		setTimeout("new Effect.Appear($('amenities'));", 1000);
	} else {
		new Effect.Appear($('amenities'));
	}
}

function clearAndHideAmenities() {
	var amenities = $('filterForm').amenity
	
	for (i = 0; i < amenities.length; i++) {
		amenities[i].checked = false;
	}
	
	new Effect.SwitchOff($('amenities'));
}

function clearAndHidePriceRanges() {
	// check the 'Any' radio button and update the form values
	$('filterForm').priceRange[0].checked = true;
	$('filterForm').priceRangeMin.value = '';
	$('filterForm').priceRangeMax.value = '';
	
	
	new Effect.SwitchOff($('priceRanges'));
}

function showPriceRanges() {
	// update the radio buttons with the appropriate value
	
	var min = (+$('filterForm').priceRangeMin.value)
	var max = (+$('filterForm').priceRangeMax.value)
	
	if (min == 0 && max == 0)
		$('filterForm').priceRange[0].checked = true;
	else if (min == 0)
		$('filterForm').priceRange[1].checked = true;
	else if (max == 0)
		$('filterForm').priceRange[4].checked = true;
	else {
		if ((+min) == 75)
			$('filterForm').priceRange[2].checked = true;
		else if ((+min) == 125)
			$('filterForm').priceRange[3].checked = true;
	}
	
	if (Element.visible($('amenities'))) {
		new Effect.SwitchOff($('amenities'));
		setTimeout("new Effect.Appear($('priceRanges'));", 1000);
	} else {
		new Effect.Appear($('priceRanges'));
	}
}

var currentDivLayer = 'photosDiv';
function showInfoDiv(divLayer) {
	gotoInfoDiv(divLayer);
	if(!Element.visible(divLayer)) {
		if(currentDivLayer != '')
			hideInfoDiv(currentDivLayer);
		if(divLayer != 'theMapDiv' || mapLoaded)
			new Effect.toggle(divLayer, 'slide', {queue: 'end'});
		else
			new Effect.toggle(divLayer, 'slide', {queue: 'end', afterFinish: loadGMap});
		currentDivLayer = divLayer;
	}
}

function hideInfoDiv(divLayer) {
	if (Element.visible(divLayer)) {
		new Effect.toggle(divLayer, 'slide', {queue: 'front'});
		currentDivLayer = '';
	}
}

function gotoInfoDiv(divLayer) {
	if(window.location.href.indexOf("#") > 0)
		window.location.href = window.location.href.substring(0, window.location.href.indexOf("#")) + "#" + divLayer.substring(0, divLayer.length - 3);
	else
		window.location.href += "#" + divLayer.substring(0, divLayer.length - 3);
}

var aCalendar, dCalendar; 
var holdAMonth, holdAYear, holdDMonth, holdDYear;
var currentDate = new Date();
var currentMonth = currentDate.getMonth() + 1;
var currentDay = currentDate.getDate();
var currentYear = currentDate.getFullYear();

function loadArrivalCalendar () {		
	var theYear = currentYear;
	//see if there is only one form
	if(typeof document.travelSearchForm != 'undefined') {
		if(typeof document.travelSearchForm[0].arrivalMonth == 'undefined') {
			if(document.travelSearchForm.arrivalMonth.selectedIndex != 0 && (document.travelSearchForm.arrivalMonth.selectedIndex < currentMonth  || (document.travelSearchForm.arrivalMonth.selectedIndex == currentMonth && document.travelSearchForm.arrivalDay.selectedIndex + 1 < currentDay)))
				theYear++;	
				
			holdAMonth = document.travelSearchForm.arrivalMonth.selectedIndex + 1;
			holdAYear = theYear;
		
			var tempMonth = document.travelSearchForm.arrivalMonth.selectedIndex > 0 ? document.travelSearchForm.arrivalMonth.selectedIndex - 1 : 0;
			var tempDay = document.travelSearchForm.arrivalDay.selectedIndex > 0 ? document.travelSearchForm.arrivalDay.selectedIndex - 1 : 0;
			
			aCalendar = new Epoch('arrivalCal', 
				'popup', 
				document.getElementById('arrivalCalendarValue'), 
				document.getElementById('arrivalCalendarImgHeader'), 
				false,
				tempMonth,
				tempDay,
				theYear,
				function() {
					var sd = document.getElementById('arrivalCalendarValue').value.split("\/");
					document.travelSearchForm.arrivalMonth.options.selectedIndex = sd[0];
					document.travelSearchForm.arrivalDay.options.selectedIndex = sd[1];
					//document.forms[0].arrivalYear.value = sd[2];			
					amadChangeAll(document.travelSearchForm, false);
				});
		}
		else {//find the first form that has selectable dates and not just hidden inputs
			for(var i = 0; i < document.travelSearchForm.length; i++) 
				if(typeof document.travelSearchForm[i].arrivalMonth.selectedIndex != 'undefined') {
					if(document.travelSearchForm[i].arrivalMonth.selectedIndex != 0 && (document.travelSearchForm[i].arrivalMonth.selectedIndex < currentMonth  || (document.travelSearchForm[i].arrivalMonth.selectedIndex == currentMonth && document.travelSearchForm[i].arrivalDay.selectedIndex + 1 < currentDay)))
						theYear++;	
						
					holdAMonth = document.travelSearchForm[i].arrivalMonth.selectedIndex + 1;
					holdAYear = theYear;
						
					var tempMonth = document.travelSearchForm[i].arrivalMonth.selectedIndex > 0 ? document.travelSearchForm[i].arrivalMonth.selectedIndex - 1 : 0;
					var tempDay = document.travelSearchForm[i].arrivalDay.selectedIndex > 0 ? document.travelSearchForm[i].arrivalDay.selectedIndex - 1 : 0;
					
					aCalendar = new Epoch('arrivalCal', 
						'popup', 
						document.getElementById('arrivalCalendarValue'), 
						document.getElementById('arrivalCalendarImgHeader'), 
						false,
						tempMonth,
						tempDay,
						theYear,
						function() {
							var sd = document.getElementById('arrivalCalendarValue').value.split("\/");
							document.travelSearchForm[i].arrivalMonth.options.selectedIndex = sd[0];
							document.travelSearchForm[i].arrivalDay.options.selectedIndex = sd[1];
							//document.forms[i].arrivalYear.value = sd[2];			
							amadChangeAll(document.travelSearchForm[i], false);
						});
					break;
				}
		}
	}
}
function loadDepartureCalendar () {			
	var theYear = currentYear;
	//see if there is only one form
	if(typeof document.travelSearchForm != 'undefined') {
		if(typeof document.travelSearchForm[0].departureMonth == 'undefined') {
			if(document.travelSearchForm.departureMonth.selectedIndex != 0 && (document.travelSearchForm.departureMonth.selectedIndex < currentMonth  || (document.travelSearchForm.departureMonth.selectedIndex == currentMonth && document.travelSearchForm.departureDay.selectedIndex + 1 < currentDay)))
				theYear++;	
				
			holdDMonth = document.travelSearchForm.departureMonth.selectedIndex + 1;
			holdDYear = theYear;
			
			var tempMonth = document.travelSearchForm.departureMonth.selectedIndex > 0 ? document.travelSearchForm.departureMonth.selectedIndex - 1 : 0;
			var tempDay = document.travelSearchForm.departureDay.selectedIndex > 0 ? document.travelSearchForm.departureDay.selectedIndex - 1 : 0;
			
			dCalendar = new Epoch('departureCal', 
				'popup', 
				document.getElementById('departureCalendarValue'), 
				document.getElementById('departureCalendarImgHeader'), 
				false,
				tempMonth,
				tempDay,
				theYear,
				function() {
					var sd = document.getElementById('departureCalendarValue').value.split("\/");
					document.travelSearchForm.departureMonth.options.selectedIndex = sd[0];
					document.travelSearchForm.departureDay.options.selectedIndex = sd[1];
					//document.forms[0].departureYear.value = sd[2];
					dmddChangeAll(document.travelSearchForm, false);
				});
		}
		else {//find the first form that has selectable dates and not just hidden inputs
			for(var i = 0; i < document.travelSearchForm.length; i++)
				if(typeof document.travelSearchForm[i].departureMonth.selectedIndex != 'undefined') {
					if(document.travelSearchForm[i].departureMonth.selectedIndex != 0 && (document.travelSearchForm[i].departureMonth.selectedIndex < currentMonth  || (document.travelSearchForm[i].departureMonth.selectedIndex == currentMonth && document.travelSearchForm[i].departureDay.selectedIndex + 1 < currentDay)))
						theYear++;	
						
					holdDMonth = document.travelSearchForm[i].departureMonth.selectedIndex + 1;
					holdDYear = theYear;
					
					var tempMonth = document.travelSearchForm[i].departureMonth.selectedIndex > 0 ? document.travelSearchForm[i].departureMonth.selectedIndex - 1 : 0;
					var tempDay = document.travelSearchForm[i].departureDay.selectedIndex > 0 ? document.travelSearchForm[i].departureDay.selectedIndex - 1 : 0;
					
					dCalendar = new Epoch('departureCal', 
						'popup', 
						document.getElementById('departureCalendarValue'), 
						document.getElementById('departureCalendarImgHeader'), 
						false,
						tempMonth,
						tempDay,
						theYear,
						function() {
							var sd = document.getElementById('departureCalendarValue').value.split("\/");
							document.travelSearchForm[i].departureMonth.options.selectedIndex = sd[0];
							document.travelSearchForm[i].departureDay.options.selectedIndex = sd[1];
							//document.forms[i].departureYear.value = sd[2];
							dmddChangeAll(document.travelSearchForm[i], false);
						});		
					break;
				}
		}
	}
}

function loadCalendars() {
	loadArrivalCalendar();
	loadDepartureCalendar();
}

function amadChangeAll(theForm, changeCalendars) {
    if (!isBrowserSupp())
       	return;
       	
	var newDepartureDay = adjustDates(theForm.arrivalMonth, theForm.arrivalDay);
        if (theForm.arrivalMonth.options.selectedIndex == 12 && theForm.arrivalDay.options.selectedIndex >= 30) {
        	theForm.departureMonth.options.selectedIndex = 1;
        	theForm.departureDay.options.selectedIndex = 1 + theForm.arrivalDay.options.selectedIndex - 30;			
        } else {
    		theForm.departureMonth.options.selectedIndex = theForm.arrivalMonth.options.selectedIndex;
	    	theForm.departureDay.options.selectedIndex = theForm.arrivalDay.options.selectedIndex + 2;
	}
    
    if(changeCalendars)    	
		changeArrivalCalendar(theForm);

	if(typeof dCalendar != 'undefined')
		changeDepartureCalendar(theForm);
	

	for(var i = 0; i < document.travelSearchForm.length; i++) 
		if(document.travelSearchForm[i] != theForm && typeof document.travelSearchForm[i].arrivalMonth != 'undefined' && typeof document.travelSearchForm[i].arrivalMonth.options != 'undefined') {
			document.travelSearchForm[i].arrivalMonth.options.selectedIndex = theForm.arrivalMonth.options.selectedIndex;
			document.travelSearchForm[i].arrivalDay.options.selectedIndex = theForm.arrivalDay.options.selectedIndex;
			//in case of nights drop down instead of the normal departure date
			if(typeof document.travelSearchForm[i].departureMonth != 'undefined' && typeof document.travelSearchForm[i].departureDay != 'undefined') {
				document.travelSearchForm[i].departureMonth.options.selectedIndex = theForm.departureMonth.options.selectedIndex;
				document.travelSearchForm[i].departureDay.options.selectedIndex = theForm.departureDay.options.selectedIndex;
			}
		}
}

function dmddChangeAll(theForm, changeCalendars) {
    if (!isBrowserSupp()) 
	    return;
    
	adjustDates(theForm.departureMonth, theForm.departureDay);
	if(changeCalendars)
		changeDepartureCalendar(theForm);

	for(var i = 0; i < document.travelSearchForm.length; i++) 
		if(document.travelSearchForm[i] != theForm && typeof document.travelSearchForm[i].departureMonth != 'undefined' && typeof document.travelSearchForm[i].departureMonth.options != 'undefined') {
			document.travelSearchForm[i].departureMonth.options.selectedIndex = theForm.departureMonth.options.selectedIndex;
			document.travelSearchForm[i].departureDay.options.selectedIndex = theForm.departureDay.options.selectedIndex;
		}
}

function changeArrivalCalendar(theForm) {
	var needsRedrawn = false;
	//determine if the new month & year are the same as the old ones
	if(theForm.arrivalMonth.options.selectedIndex < currentMonth  || 
		(theForm.arrivalMonth.options.selectedIndex == currentMonth && theForm.arrivalDay.options.selectedIndex < currentDay)) {
		if(holdAYear != currentYear + 1 || holdAMonth != theForm.arrivalMonth.options.selectedIndex)  {
			holdAYear = currentYear + 1;
			needsRedrawn = true;
		}
	}
	else if(holdAYear != currentYear || holdAMonth != theForm.arrivalMonth.options.selectedIndex) {
		holdAYear = currentYear;
		needsRedrawn = true;
	}
	
	holdAMonth = theForm.arrivalMonth.options.selectedIndex - 1;
	aCalendar.selectedDates = new Array(new Date(currentDate.setFullYear(holdAYear,holdAMonth,theForm.arrivalDay.options.selectedIndex)));
	
	//if month or year has changed calendar needs to be recreated for the new month/year
	if(needsRedrawn) { 
		aCalendar.monthSelect.value = aCalendar.displayMonth = holdAMonth;
		aCalendar.yearSelect.value = aCalendar.displayYear = holdAYear;

		//and refresh the calendar for the new month/year
		aCalendar.deleteCells();
		aCalendar.calCellContainer.appendChild(aCalendar.createCalCells());
	}
	else 
		aCalendar.reDraw();	
}

function changeDepartureCalendar(theForm) {
	var needsRedrawn = false;
	//determine if the new month & year are the same as the old ones
	if(theForm.departureMonth.options.selectedIndex < currentMonth  || 
		(theForm.departureMonth.options.selectedIndex == currentMonth && theForm.departureDay.options.selectedIndex < currentDay)) {
		if(holdDYear != currentYear + 1 || holdDMonth != theForm.departureMonth.options.selectedIndex)  {
			holdDYear = currentYear + 1;
			needsRedrawn = true;
		}
	}
	else if(holdDYear != currentYear || holdDMonth != theForm.departureMonth.options.selectedIndex) {
		holdDYear = currentYear;
		needsRedrawn = true;
	}
	
	holdDMonth = theForm.departureMonth.options.selectedIndex - 1;
	dCalendar.selectedDates = new Array(new Date(currentDate.setFullYear(holdDYear,holdDMonth,theForm.departureDay.options.selectedIndex)));
	
	//if month or year has changed calendar needs to be recreated for the new month/year
	if(needsRedrawn) { 
		dCalendar.monthSelect.value = dCalendar.displayMonth = holdDMonth;
		dCalendar.yearSelect.value = dCalendar.displayYear = holdDYear;

		//and refresh the calendar for the new month/year
		dCalendar.deleteCells();
		dCalendar.calCellContainer.appendChild(dCalendar.createCalCells());
	}
	else 
		dCalendar.reDraw();	
}

function adjustDates(monthField, dayField) {
	var numDays;
	if(monthField.options.selectedIndex < currentMonth  || (monthField.options.selectedIndex == currentMonth && dayField.options.selectedIndex < currentDay)) 
		numDays = getDaysInMonth(monthField.options.selectedIndex, currentYear+1);
	else
		numDays = getDaysInMonth(monthField.options.selectedIndex, currentYear);
    if (dayField.options.selectedIndex <= numDays) 
    	return 0;
    else if(dayField.options.selectedIndex > numDays) { 
		monthField.options.selectedIndex++; //dont have to worry about december since it has 31 days
		dayField.options.selectedIndex -= numDays;
		return 0;
	}
}

function changeParentUrl(url)
{
	document.location = url;
}

var ihsRepeat = null;
var ihsVar = 0;

function clear() {
	ihsStopProcessing();	
}
function ihsStopProcessing() {
	try {		
		if(ihsRepeat != null)
			clearInterval(ihsRepeat);
		$('process').hide();
		$('overlay').hide();
	} catch(e) {		
	}
}
function ihsRunProcessing() {
	if ( ihsVar > 0) {
		document.getElementById("bg"+ihsVar).style.background = '#CCCCCC' ;
	}
	ihsVar++;
	document.getElementById("bg"+ihsVar).style.background = '' ;
	if (ihsVar == 10) {
		ihsVar = 0;  
	}
}
function ihsStartProcessing() {
	try {		
		ihsStopProcessing();
		$('overlay').style.display = "block";
		$('process').show();
		ihsRepeat = setInterval("ihsRunProcessing()",1000);
	} catch(e) {
	}	
}
document.observe("dom:loaded", function() {	
	loadCalendars();
	ihsStopProcessing();
});
Event.observe(window, 'load', function() {	
	for(var i = 0; i < document.forms.length; i++)
		Event.observe(document.forms[i], 'submit', function() {
			if(this.id != 'bookfrm' && this.id != 'travelSearchForm') {
				ihsStartProcessing(); 
				window.scroll(0,0); 
			}
		});
});
Event.observe(window, 'unload', function() {	
	setTimeout("ihsStopProcessing();", 5000);
});
function checkDates(theForm) {
  	if(theForm.arrivalMonth.value == "") {
  	  	alert("Please select an arrival date");
  		theForm.arrivalMonth.focus();
  		return false;
  	} else if(theForm.arrivalDay.value == "") {
  	  	alert("Please select an arrival date");
  		theForm.arrivalDay.focus();
  		return false;
  	} else if(theForm.departureMonth != undefined && theForm.departureMonth.value == "") {
  	  	alert("Please select an departure date");
  		theForm.departureMonth.focus();
  		return false;
  	} else if(theForm.departureDay != undefined && theForm.departureDay.value == "") {
  	  	alert("Please select an departure date");
  		theForm.departureDay.focus();
  		return false;
  	}
  	ihsStartProcessing(); 
	window.scroll(0,0); 
  	return true;
}
