
/*-----------------------------------------------------------------------------------------
-	12/07/2005  Brad Sulewski       Updating to work with city subfolders
-   12/19/2005  Brad Sulewski       WFM 2826 Updated CheckDate() to populate new hidden fields fromdatehidden and todatehidden for making the calendar popup default to current selected dates
-   12/22/2005  Brad Sulewski       Removed updating of hidden fields fromdatehidden and todatehidden and am calling Format10DigitDate directly in the call to the calendar popup in find_hotel_include.asp
-   12/29/2005  Brad Sulewski       Fixed CheckDate() -- when start date is < today, display the alert and update FromDate to tomorrow date to break the loop
-   01/18/2006  Brad Sulewski       Added function setCityAddress() to update the hidden City filed from the Search By Address Fields
-                                   Added function clearLatLong() to clear the lat and lon hidden fields when searching by address
-                                   Modified UpdateLatLong() to clear the Search By Address fields so that they do not interfear with the search if a location is selected after entering in an address
-   01/19/2006  Brad Sulewski       Modified setCityAddress() to clear the Town and State fields when entering an address to search by
-                                   And modified setCity() to clear the search by address fields when a new city/state is entered
-   01/26/2005  Brad Sulewski       Replaced with file from roomrate
-   01/31/2006  Brad Sulewski       Added clearAddress and clearChain functions
------------------------------------------------------------------------------------------*/


function showAmenitiesNext(next) {
	document.all.amenitiesDiv[0].style.display = "none";
	document.all.amenitiesDiv[1].style.display = "none";
	document.all.amenitiesDiv[2].style.display = "none";
	document.all.amenitiesDiv[3].style.display = "none";
	document.all.amenitiesDiv[4].style.display = "none";

	document.all.amenitiesDiv[next].style.display = "inline";
}

var vCurrentField;
var vFuncName;
vFuncName = "";
function openDualCalendarWindow(vField1, vField2)
{

var varTop = 0;
var varLeft = 0;
var varheight=280;
var varwidth= 310;

	varTop = ((screen.availHeight - varheight)/ 2) - 50;
	varLeft = ((screen.availWidth - varwidth) / 2) - 5;
	
	var varWindow = window.open ("/Include/DualCalendarPopup.asp?sdate="+vField1.value + "&edate="+vField2.value + "&sfield="+ vField1.form.name + "." + vField1.name + "&efield="+vField2.form.name  + "." + vField2.name, "CalendarPopup", "height=" + varheight + ",width=" + varwidth + ",top=" + varTop + ", left=" + varLeft + ", scrollbars=no,menubar=no,toolbar=no,resizable=no" , true);
	vCurrentField = vField1;
	varWindow.focus();
}

function openCalendarWindow(vField, vFunc)
{
var varTop = 0;
var varLeft = 0;
var varheight=220;
var varwidth=210;
	
	varTop = ((screen.availHeight - varheight)/ 2) - 50;
	varLeft = ((screen.availWidth - varwidth) / 2) - 5;
	var varWindow = window.open ("/CalendarPopup.asp?date="+vField.value, "CalendarPopup", "height=" + varheight + ",width=" + varwidth + ",top=" + varTop + ", left=" + varLeft + ", scrollbars=no,menubar=no,toolbar=no,resizable=no" , true);
	vCurrentField = vField;
	vFuncName = vFunc;
	varWindow.focus();
}

function openCalendarWindow2(vField, vFunc)
{
var varTop = 0;
var varLeft = 0;
var varheight=220;
var varwidth=210;
	
	varTop = ((screen.availHeight - varheight)/ 2) - 50;
	varLeft = ((screen.availWidth - varwidth) / 2) - 5;
	var varWindow = window.open ("/CalendarPopup.asp?date="+vField.value, "CalendarPopup", "height=" + varheight + ",width=" + varwidth + ",top=" + varTop + ", left=" + varLeft + ", scrollbars=no,menubar=no,toolbar=no,resizable=no" , true);
	vCurrentField = vField;
	vFuncName = vFunc;
	varWindow.focus();
}

function returnValue(vValue)
{
	vCurrentField.value = vValue;
	if (vFuncName != "") {
		eval(vFuncName);
		
	}
}


function setToDate() {
	var FromDate = new Date(document.CreateBooking.FromDate.value);
	var ToDate = new Date(document.CreateBooking.ToDate.value);

	if (ToDate.valueOf() > FromDate.valueOf()) {
		return;
	}
	if (!(isNaN(FromDate))) {
		ToDate.setYear(FromDate.getFullYear());
		ToDate.setMonth(FromDate.getMonth());
		ToDate.setDate(FromDate.getDate() + 1);

		document.CreateBooking.ToDate.value = (ToDate.getMonth()+1) + "/" + ToDate.getDate() + "/" + ToDate.getFullYear();
	}	
	return;
}

function calculateTotalTravellers() {
	document.CreateBooking.Travellers.value = Number(document.CreateBooking.NoAdults.value)
		+ Number(document.CreateBooking.NoChildren.value)
		+ Number(document.CreateBooking.NoSeniors.value);
		
}




/* VALIDATION FUNCTIONS */
function setCity() {
		// 01/18/2006 -- need to clear the search by address fields incase this is selected after entering in an address
		//document.CreateBooking.AddrStreet.value="";
		//document.CreateBooking.AddrCity.value="";
		//document.CreateBooking.AddrState.selectedIndex=0;
		//document.CreateBooking.AddrZip.value="";
		document.CreateBooking.Lat.value="";
		document.CreateBooking.Lon.value="";
		
		// now update the hidden city field with the new search by address values
		document.CreateBooking.City.value = document.CreateBooking.Town.value + "," + document.CreateBooking.State.value + "," + document.CreateBooking.Country.value;
		
		
}

function setCityAddress() {
	//also want to clear the main city and state fields
	document.CreateBooking.Town.value="";
	document.CreateBooking.State.selectedIndex=0;
	
	// now update the hidden city field with the new search by address values
	document.CreateBooking.City.value = document.CreateBooking.AddrCity.value + "," + document.CreateBooking.AddrState.value + "," + document.CreateBooking.Country.value;
		
}

function NewJackCity(city, state, country) {
	document.CreateBooking.Town.value = city;
	setCity();
}

function CheckDate() {
	if (document.CreateBooking.FromDate.value!='') {
		var Today = new Date();
		FormatYear(document.CreateBooking.FromDate);
		var d1 = new Date(document.CreateBooking.FromDate.value);
		var dt = new Date(Today);
		// set today back to 00:00 so the compare is just comparing DATE not TIME
		dt.setHours(0,0,0,0);
		if (isNaN(d1)) {
			dt.setDate(dt.getDate()+1);
			document.CreateBooking.FromDate.value = FormatDate(dt);
		}
		if (dt.valueOf() > d1.valueOf()) {
			alert('You can only search for future dates');
			document.CreateBooking.FromDate.value = FormatDate(dt.setDate(dt.getDate()+1));
			f = true;
		} else {
			if (document.CreateBooking.ToDate.value!='') {
				
				var d2 = new Date(document.CreateBooking.ToDate.value);
				
				FormatYear(document.CreateBooking.ToDate);
				var d2 = new Date(document.CreateBooking.ToDate.value);
				
				
				if (isNaN(d2)) {
					d2 = d1;
					d2.setDate(d2.getDate()+1);
					document.CreateBooking.ToDate.value = FormatDate(d2);
				}
				if (d2.valueOf() <= d1.valueOf()) {
					
					d2 = d1;
					d2.setDate(d2.getDate()+1);
					document.CreateBooking.ToDate.value = FormatDate(d2);
				}
				
			}
		}
	}
}

function updateToDate() {
	if (document.CreateBooking.nightcount.value != "") {
		var nightNum = Number(document.CreateBooking.nightcount.value);
		if (isNaN(nightNum)) {
			document.CreateBooking.nightcount.value = "";
		} else {
			var fd = new Date(document.CreateBooking.FromDate.value);
			document.CreateBooking.ToDate.value = FormatDate(DateAdd(fd, Math.abs(document.CreateBooking.nightcount.value)));
		}
	} else {
		var fd = new Date(document.CreateBooking.FromDate.value);
		document.CreateBooking.ToDate.value = FormatDate(DateAdd(fd, 1));
	
	}
}

function updateNights() {

	if (document.CreateBooking.ToDate.value != "") {
		var fd = new Date(document.CreateBooking.FromDate.value);
		var td = new Date(document.CreateBooking.ToDate.value);
		if (!isNaN(fd) && !isNaN(td)) {
			if (td.valueOf() > fd.valueOf()) {
				document.CreateBooking.nightcount.value = (DateDiff(fd, td, 'd',0));
			}
		}
	}
}
	
function CheckValues() {
	var f = false ;
	var d1 = new Date(document.CreateBooking.FromDate.value);
	var dt = new Date();
	// set today back to 00:00 so the compare is just comparing DATE not TIME
	dt.setHours(0,0,0,0);
	if (dt.valueOf() > d1.valueOf()) {
		alert('You can only search for future dates');
		f = true;
	} else {
		var d2 = new Date(document.CreateBooking.ToDate.value);

		if (d2.valueOf() <= d1.valueOf()) {
			alert('You cannot have a check-out date before check-in date');
			f = true;
		} 
		if (isNaN(d2)) {
			alert('You need to specify a check-out date');
			f = true;
		}
	}
		if (document.CreateBooking.City.value == ", , US") {
			if (document.CreateBooking.Lat.value == "") {
				alert('You need to select a location');
				f = true;
			}
	}
	if (!f) {
		document.CreateBooking.submit();
	}
	
}

function clearCityForm(clear) {
	if (clear.defaultValue==clear.value) clear.value = ""
}

function UpdateLatLong() {
	//alert(document.all.PointOfInterest.value);
	tmpIdx = document.CreateBooking.PointOfInterest.value;
	if (tmpIdx == "") {
		document.CreateBooking.lat.value="";
		document.CreateBooking.lon.value="";
	} else {
		
		//document.CreateBooking.Lat.value=csPointsArray[tmpIdx*2];
		//document.CreateBooking.Lon.value=csPointsArray[tmpIdx*2+1];
		
		// 11/29/2005 since adding in the point name and state, we need to multiply by 4 now
		document.CreateBooking.Lat.value=csPointsArray[tmpIdx*4];
		document.CreateBooking.Lon.value=csPointsArray[tmpIdx*4+1];
		POItempName = csPointsArray[tmpIdx*4+2];
		POItempState = csPointsArray[tmpIdx*4+3];
		
		POItempArray = POItempName.split(", ");
		if (POItempArray.length == 1){
			document.CreateBooking.City.value = POItempArray[0] + "," + POItempState;
			//alert(document.CreateBooking.City.value);
		} else if (POItempArray.length == 2) {
			document.CreateBooking.City.value = POItempArray[0] + "," + POItempState;
			//alert(document.CreateBooking.City.value);
		} else if (POItempArray.length == 3) {
			document.CreateBooking.City.value = POItempArray[0] + " " + POItempArray[1] + "," + POItempState;
			//alert(document.CreateBooking.City.value);
		} else {
			document.CreateBooking.City.value = POItempArray[1] + "," + POTtempState;
			//alert(document.CreateBooking.City.value);
		}
		
		// 01/18/2006 -- need to clear the search by address fields incase this is selected after entering in an address
		/*document.CreateBooking.AddrStreet.value="";
		document.CreateBooking.AddrCity.value="";
		document.CreateBooking.AddrState.selectedIndex=0;
		document.CreateBooking.AddrZip.value=""; */
		clearAddress();
		
		// 01/31/2006 -- need to clear the search by chain
		/*document.CreateBooking.hotel.value="";
		document.CreateBooking.chain.selectedIndex=0; */
		clearChain();
		
	}
}

function clearLatLong(){
	document.CreateBooking.Lat.value="";
	document.CreateBooking.Lon.value="";
}

function clearAddress(){
	document.CreateBooking.AddrStreet.value="";
	document.CreateBooking.AddrCity.value="";
	document.CreateBooking.AddrState.selectedIndex=0;
	document.CreateBooking.AddrZip.value="";
}

function clearChain(){
	document.CreateBooking.hotel.value="";
	document.CreateBooking.chain.selectedIndex=0;
}

function UpdateSupplierList(whIdx) {
	var suppList = String(document.CreateBooking.SupplierId.value);
	var selSupp = eval("document.frmHotelList.supplier" + whIdx + ".value");
	var suppPos = suppList.search(selSupp);
	if (suppPos == -1) {
		if (suppList.length > 0) {
			suppList += ", ";
		}
		suppList += selSupp;
	} else {
		if (suppPos > 0) {
			var newString = suppList.slice(0, suppPos-2);
		} else {
			var newString = suppList.slice(0, suppPos);
		}	
		suppList = suppList.slice(suppPos);
		var endSupp = suppList.search(",");
		
		if (endSupp > -1) {
			newString += suppList.slice(endSupp);	
		}
		suppList = newString;
	}
	document.CreateBooking.SupplierId.value = suppList;


}
