var pageType;
function newSearchURL(sURL){  
  if(document.getElementById('newSearch') == null){
	  window.location.href = sURL;
  }else{
	  window.location.href = "#newSearch";
	  document.searchHotelsForm.cityName.focus();
  }
}
function changeCityURL(sURL){  
	window.location.href = sURL;
}
function submitOnEnter(e) {	
	if (e.keyCode == 13 ) {
		setTimeout('validateSearchForm();',300);
	}
}
function onEnterKey(e, copyFields){
	if (e.keyCode == 13 ) {
		setTimeout('validateSearch();',300);
	}        
}
function suppressEnterKey(e) {
	if (e.keyCode == 13 ) {
		return false;
	} else
		return true;
}
function hotelNameOnlyEnter(e) {
	if (e==null) {
		document.searchHotelsForm[0].searchHotelName.value = document.getElementById('htlSortName').value;
		validateSearchForm("&tabOverride=name");
	} else if (e.keyCode == 13) {
		document.searchHotelsForm[0].searchHotelName.value = document.getElementById('htlSortName').value;
		validateSearchForm("&tabOverride=name");
	}     
}
function validateSearch(){
	var searchType="CITY";
    for (var iT=0; iT<document.searchHotelsForm[1].searchType2.length; iT++)
		if (document.searchHotelsForm[1].searchType2[iT].checked) {
			document.searchHotelsForm[0].searchType[iT].checked = true;
			searchType = document.searchHotelsForm[1].searchType2[iT].value;	
		}
	document.searchHotelsForm[0].checkInDate.value = document.searchHotelsForm[1].tmpCheckInDate.value;
	document.searchHotelsForm[0].checkOutDate.value = document.searchHotelsForm[1].tmpCheckOutDate.value;
	document.searchHotelsForm[0].cityName.value = document.searchHotelsForm[1].destName.value;
	document.searchHotelsForm[0].cityID.value = document.searchHotelsForm[1].destID.value;
	document.searchHotelsForm[0].cityID_Name.value = document.searchHotelsForm[1].destID_Name.value;
	document.searchHotelsForm[0].poiName.value = document.searchHotelsForm[1].poiName2.value;
	document.searchHotelsForm[0].poiID.value = document.searchHotelsForm[1].poiID2.value;
	document.searchHotelsForm[0].poiID_Name.value = document.searchHotelsForm[1].poiID_Name2.value;
	document.searchHotelsForm[0].addrLine.value = document.searchHotelsForm[1].addrLine2.value;
	document.searchHotelsForm[0].addrCity.value = document.searchHotelsForm[1].addrCity2.value;
	document.searchHotelsForm[0].addrState.value = document.searchHotelsForm[1].addrState2.value;
	document.searchHotelsForm[0].addrZIP.value = document.searchHotelsForm[1].addrZIP2.value;
	document.searchHotelsForm[0].numberOfRooms.value = document.searchHotelsForm[1].numberOfRooms.value;
	document.searchHotelsForm[0].searchHotelName.value = document.searchHotelsForm[1].searchHotelName.value;
	document.searchHotelsForm[0].starRating.value = document.searchHotelsForm[1].starRating.value;
	document.searchHotelsForm[0].hotelBrand.value = document.searchHotelsForm[1].hotelBrand.value;        
	changeSearchType(searchType, "TR");
	validateSearchForm();
}
function toggleModifySearch() {
	if (document.getElementById('expand').style.display == "block")
		closeModifySearch();
	else
		modifySearch(false);
}
function modifySearch(bJump){
	synchSearchType();
	document.getElementById('expand').style.display = "block";
	try {
		if (document.searchHotelsForm[0].searchType[1].checked) {
			document.getElementById('poiName').focus();
		} else if (document.searchHotelsForm[0].searchType[2].checked) {
			document.getElementById('addrLine').focus();
		} else {
		  	document.getElementById('cityName').focus();
		}
	} catch (e) {}
	if (bJump) window.location.href = '#maincontent';
}
function closeModifySearch() {
	document.getElementById('expand').style.display = "none";
}
function changeSearchType(newType, ext) {
	

	if(pageType != null && pageType=='DETAIL' && document.getElementById("NewHotelSearch")
			&& document.getElementById("new_hotel_search_body")){
		document.getElementById("NewHotelSearch").style.height='270px';
		document.getElementById("new_hotel_search_body").style.height='250px';
	}

	if(document.getElementById("newSearchValidationErrors")){
		document.getElementById("newSearchValidationErrors").style.display = "none";
	}
	
	document.getElementById('addrSearch'+ext).style.display="none";

	if (ext=="TR") {
		document.getElementById('addrSearch2'+ext).style.display="none";
		document.getElementById('addrSearch3'+ext).style.display="none";
		document.getElementById('addrSearch4'+ext).style.display="none";
	}
	document.getElementById('citySearch'+ext).style.display="none";
	document.getElementById('poiSearch'+ext).style.display="none";
	
	if (newType == "POI") {
		document.getElementById('poiSearch'+ext).style.display="";
	} else if (newType=="ADDR") {
		if(pageType != null && pageType=='DETAIL' && document.getElementById("NewHotelSearch")
				&& document.getElementById("new_hotel_search_body")){
			
			document.getElementById("NewHotelSearch").style.height='410px';
			document.getElementById("new_hotel_search_body").style.height='390px';
		}
		document.getElementById('addrSearch'+ext).style.display="";
		if (ext=="TR") {
			document.getElementById('addrSearch2'+ext).style.display="";
			document.getElementById('addrSearch3'+ext).style.display="";
			document.getElementById('addrSearch4'+ext).style.display="";
		}
	} else {
		document.getElementById('citySearch'+ext).style.display="";
	}		
}
function synchSearchType() {
	if (document.searchHotelsForm[0].searchType[1].checked) {
		changeSearchType("POI", "TR");
		if (document.searchHotelsForm.length > 1) {
			document.searchHotelsForm[1].searchType2[1].checked=true;
			document.searchHotelsForm[1].poiName2.value = document.searchHotelsForm[0].poiName.value;
			document.searchHotelsForm[1].poiID2.value = document.searchHotelsForm[0].poiID.value;
			changeSearchType("POI", "Div");
		}
	} else if (document.searchHotelsForm[0].searchType[2].checked) {
		changeSearchType("ADDR", "TR");
		if (document.searchHotelsForm.length > 1) {
			document.searchHotelsForm[1].searchType2[2].checked=true;
			document.searchHotelsForm[1].addrLine2.value = document.searchHotelsForm[0].addrLine.value;
			document.searchHotelsForm[1].addrCity2.value = document.searchHotelsForm[0].addrCity.value;
			document.searchHotelsForm[1].addrState2.value = document.searchHotelsForm[0].addrState.value;
			document.searchHotelsForm[1].addrZIP2.value = document.searchHotelsForm[0].addrZIP.value;
			changeSearchType("ADDR", "Div");
		}
	} else {
		changeSearchType("CITY", "TR");
		if (document.searchHotelsForm.length > 1) {
			document.searchHotelsForm[1].searchType2[0].checked=true;
			document.searchHotelsForm[1].destName.value = document.searchHotelsForm[0].cityName.value;
			document.searchHotelsForm[1].destID.value = document.searchHotelsForm[0].cityID.value;
			changeSearchType("CITY", "Div");
		}
	}
}