function resetSelects(Init){
	try{
		var data = "cmd=resetSelects"
		if (Init != null){
			data = data + "&Init=" + Init;
		}
		data = data + "&selPropertyType=" + document.getElementById("selPropertyType").options[document.getElementById("selPropertyType").selectedIndex].value;
		data = data + "&selBedrooms=" + document.getElementById("selBedrooms").options[document.getElementById("selBedrooms").selectedIndex].value;
		data = data + "&selLocation=" + document.getElementById("selLocation").options[document.getElementById("selLocation").selectedIndex].value;
		data = data + "&selProximity=" + document.getElementById("selProximity").options[document.getElementById("selProximity").selectedIndex].value;
		var strPromotionCode = document.getElementById("txtPromotionCode").value;
		if (strPromotionCode == "Promotion Code" || strPromotionCode == ""){
			data = data + "&PromotionCode=";
		}else{
			data = data + "&PromotionCode=" + document.getElementById("txtPromotionCode").value;
		}
		
		if ( _checkDate(document.getElementById("requested_date").value) && _checkDate(document.getElementById("requested_date2").value))
		{
			data = data + "&Check_In=" + document.getElementById("requested_date").value;
			data = data + "&Check_Out=" + document.getElementById("requested_date2").value;
		}else{
			data = data + "&Check_In=&Check_Out=";
		}
		//window.alert(data);
		replaceHtml ( 'spnSearchProgressImg', "<img src='/vacation-rentals/images/progressImg.gif' style='width:20px;height:20px;'>");
		sendRequest( _afterResetSelects, data, "POST", "/vacation-rentals/includes/call-i-right.asp", true );
		setCursorWait();
	}catch(e){
		replaceHtml ( 'spnSearchProgressImg', "");
		setCursorDefault();
	}
}

function _afterResetSelects( oj ) {	
	try{
		var xmlDoc  = oj.responseXML;	
		var result = xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue;
		if (result =="ok"){
			replaceHtml ("spnSelPropertyType", xmlDoc.getElementsByTagName("selPropertyTypeHTML")[0].firstChild.nodeValue );
			replaceHtml ("spnSelBedrooms", xmlDoc.getElementsByTagName("selBedroomsHTML")[0].firstChild.nodeValue );
			replaceHtml ("spnSelLocation", xmlDoc.getElementsByTagName("selLocationHTML")[0].firstChild.nodeValue );
			replaceHtml ("spnProximity", xmlDoc.getElementsByTagName("selProximityHTML")[0].firstChild.nodeValue );
			//updateSearchForm();
		}
	}catch(e){
		//window.alert ( e ) ; 
	}finally{		
		setCursorDefault();
		replaceHtml ( 'spnSearchProgressImg', "");
	}
}

function setCursorDefault(){
	try{
		document.body.style.cursor = 'default' ;

		var brwsr=navigator.appName;
		if (brwsr=="Microsoft Internet Explorer"){
			document.getElementById("imgBtnSearch").style.cursor = 'hand' ;
		}else{
			document.getElementById("imgBtnSearch").style.cursor = 'pointer' ;
		}

		document.getElementById("selPropertyType").style.cursor = 'default' ;
		document.getElementById("selBedrooms").style.cursor = 'default' ;
		document.getElementById("selLocation").style.cursor = 'default' ;
		document.getElementById("selProximity").style.cursor = 'default' ;

		document.getElementById("requested_date").style.cursor = 'text' ;
		document.getElementById("requested_date2").style.cursor = 'text' ;
		document.getElementById("txtPromotionCode").style.cursor = 'text' ;

	}catch(e){
	}
}

function setCursorWait(){
	try{
		document.body.style.cursor = 'wait' ;
		document.getElementById("imgBtnSearch").style.cursor = 'wait' ;

		document.getElementById("selPropertyType").style.cursor = 'wait' ;
		document.getElementById("selBedrooms").style.cursor = 'wait' ;
		document.getElementById("selLocation").style.cursor = 'wait' ;
		document.getElementById("selProximity").style.cursor = 'wait' ;
		
		document.getElementById("requested_date").style.cursor = 'wait' ;
		document.getElementById("requested_date2").style.cursor = 'wait' ;

		document.getElementById("txtPromotionCode").style.cursor = 'wait' ;

	}catch(e){
	}
}

function toggleElement( sel1, sel2, element1){
	try{
		var arrival=document.getElementById(sel1);
		var departure=document.getElementById(sel2);

		if (arrival.value != 'Arrival Date' && arrival.value != ''){
			departure.value=arrival.value;
		}

		try{
			if ( document.getElementById(element1) != null)
			{			
				var element1 = document.getElementById(element1);
				if ((arrival.value != 'Arrival Date' && arrival.value != '') && (departure.value != 'Departure Date' && departure.value != '')){
					element1.style.visibility= 'visible';
				}else{
					element1.value = ''; 
					element1.style.visibility= 'hidden';
				}
			}
		}catch(e){
		}
	}catch(e){
	}
	return;
}

function updateSearchForm(){	
	
	var propertyType=document.getElementById("selPropertyType").options[document.getElementById("selPropertyType").selectedIndex].value;

	if (propertyType=="Villa"){
		document.forms['search'].rentalRange.options.length = 0;
		document.forms['search'].rentalRange.options[0]=new Option('Any Budget/Rate','');
		document.forms['search'].rentalRange.options[1]=new Option('Up to $1,200','0-1200');
		document.forms['search'].rentalRange.options[2]=new Option('$1,201-$2,500','1201-2500');
		document.forms['search'].rentalRange.options[3]=new Option('$2,501 and up','2501-10000');		
	}else{ // "Home"
		document.forms['search'].rentalRange.options.length = 0;
		document.forms['search'].rentalRange.options[0]=new Option('Any Budget/Rate','');
		document.forms['search'].rentalRange.options[1]=new Option('Up to $1,500','0-1500');
		document.forms['search'].rentalRange.options[2]=new Option('$1,501-$4,000','1501-4000');
		document.forms['search'].rentalRange.options[3]=new Option('$4,001-$8,000','4001-8000');
		document.forms['search'].rentalRange.options[4]=new Option('$8,0001 and up','8001-20000');		
	}
}

function select_radio( strA )
{
	try{
		document.getElementById("txtRating").value = strA;
	}catch(e){
	}
	select_order();	
}

function check_petfriendly()
{
	try{
		var chkVal = document.getElementById("chkPetFriendly").checked;
		if (chkVal){
			document.getElementById("txtPetFriendly").value = '1';
		}else{
			document.getElementById("txtPetFriendly").value = '0';
		}
	}catch(e){
		window.alert ( "check_petfriendly : " + e);
	}
	select_order();	
}

function select_order()
{
	try{
		document.getElementById("txtOrderBy").value = document.getElementById("selOrder").options[document.getElementById("selOrder").selectedIndex].value;
	}catch(e){
	}	
	document.search.submit();	
}

function select_home()
{
	var id= document.getElementById("selHome").options[document.getElementById("selHome").selectedIndex].value;
	_call_property(id);
}

function select_villa()
{
	var id= document.getElementById("selVilla").options[document.getElementById("selVilla").selectedIndex].value;
	_call_property(id);
}

function _call_property(id)
{
	document.location='/vacation-rentals/property.asp?rental=' + id;
}

function callProperties() {
	
	replaceHtml ( 'divResults', '' );
	var sLists = document.getElementById("hdnResultList").value;
	var aArg = sLists.split(",");	
	for ( var i=0; i < aArg.length; i++){
		getPropertyDetail (aArg[i]);
	}
}

function getPropertyDetail( vPropertyId ){

	var data = "cmd=PropertyDetail";
	data = data + "&PropertyId=" + vPropertyId;
	sendRequest( _afterPropertyDetail, data, "POST", "/vacation-rentals/includes/call-i-advanced-search.asp", true );
}

function _afterPropertyDetail( oj ) {

	try{
		var xmlDoc  = oj.responseXML;	
		var result = xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue;		
		
		if ( result == "ok" ){
			var PropertyId = xmlDoc.getElementsByTagName("PropertyId")[0].firstChild.nodeValue;			
			var PropertyName = xmlDoc.getElementsByTagName("PropertyName")[0].firstChild.nodeValue;
			var Location = xmlDoc.getElementsByTagName("Location")[0].firstChild.nodeValue;
			var ViewCount = xmlDoc.getElementsByTagName("ViewCount")[0].firstChild.nodeValue;
			var Bedrooms = xmlDoc.getElementsByTagName("Bedrooms")[0].firstChild.nodeValue;
			var Bathrooms = xmlDoc.getElementsByTagName("Bathrooms")[0].firstChild.nodeValue;
			var Bedding = xmlDoc.getElementsByTagName("Bedding")[0].firstChild.nodeValue;
			var WeeklyRate = xmlDoc.getElementsByTagName("WeeklyRate")[0].firstChild.nodeValue;
			var PropertyPicture = xmlDoc.getElementsByTagName("PropertyPicture")[0].firstChild.nodeValue;
			var PropertyDescription = xmlDoc.getElementsByTagName("PropertyDescription")[0].firstChild.nodeValue;
			
			if ( PropertyDescription.length > 220 )
			{
				PropertyDescription = PropertyDescription.substr(0,220) + "..."
			}
			
		}else{
			//window.alert (result);
		}
	
		addPropertyDetail ( 
				PropertyId, PropertyName, Location,
				ViewCount, Bedrooms, Bathrooms, 
				Bedding, WeeklyRate, PropertyPicture, 
				PropertyDescription) ;
	
	}catch(e){
		
	}finally{
		
	}
}

function addPropertyDetail( 
			vPropertyId, PropertyName, Location, ViewCount, Bedrooms, 
			Bathrooms, Bedding, WeeklyRate, PropertyPicture, PropertyDescription){

	try{
		var newDivNode = document.createElement('DIV');
		newDivNode.id = "div" + vPropertyId;
		document.getElementById('divResults').appendChild(newDivNode);
		
		var tmpHTML = '';
		tmpHTML = tmpHTML + '';

		tmpHTML = tmpHTML + '<table width="100%" border="0" cellspacing="1" cellpadding="3">';
		tmpHTML = tmpHTML + '	<tr>';
		tmpHTML = tmpHTML + '		<td colspan="3" class="ListingH">' + PropertyName + '</td>';
		//tmpHTML = tmpHTML + '		<td class="ListingH" align="center">rental rates: ' + WeeklyRate + '</td>';
		tmpHTML = tmpHTML + '	</tr>';
		tmpHTML = tmpHTML + '	<tr>';
		tmpHTML = tmpHTML + '		<td class="midT" width="200">';
		tmpHTML = tmpHTML + '			<img src="/vacation-rentals/images/uploads/' + PropertyPicture + '" width="200" height="135">';
		tmpHTML = tmpHTML + '			</td>';
		tmpHTML = tmpHTML + '		<td class="Tdes lightlistingT" valign="top">';
		tmpHTML = tmpHTML + '			<!-- doors you will find an inviting open floor plan and expansive views of the Atlantic Ocean. The living room is spacious and welcoming, featuring a fully-loaded jukebox, big screen fl... -->';
		tmpHTML = tmpHTML + '			' + PropertyDescription + '';
		tmpHTML = tmpHTML + '		</td>';
		tmpHTML = tmpHTML + '		<td class="midT" width="240" valign="top">';
		tmpHTML = tmpHTML + '			<table width="100%" border="0" cellspacing="0" cellpadding="4" class="ListingR">';
		tmpHTML = tmpHTML + '				<tr>';
		tmpHTML = tmpHTML + '					<td>';
		tmpHTML = tmpHTML + '						<img src="images/list.gif" width="5" height="5" />';
		tmpHTML = tmpHTML + '						<strong>Bedrooms:</strong>';
		tmpHTML = tmpHTML + '						' + Bedrooms + '';
		tmpHTML = tmpHTML + '					</td>';
		tmpHTML = tmpHTML + '				</tr>';
		tmpHTML = tmpHTML + '				<tr>';
		tmpHTML = tmpHTML + '					<td>';
		tmpHTML = tmpHTML + '						<img src="images/list.gif" width="5" height="5" />';
		tmpHTML = tmpHTML + '						<strong>Baths:</strong>';
		tmpHTML = tmpHTML + '						' + Bathrooms + '';
		tmpHTML = tmpHTML + '					</td>';
		tmpHTML = tmpHTML + '				</tr>';
		tmpHTML = tmpHTML + '				<tr>';
		tmpHTML = tmpHTML + '					<td>';
		tmpHTML = tmpHTML + '						<img src="images/list.gif" width="5" height="5" />';
		tmpHTML = tmpHTML + '						<strong>Area:</strong>';
		tmpHTML = tmpHTML + '						' + Location + '';
		tmpHTML = tmpHTML + '					</td>';
		tmpHTML = tmpHTML + '				</tr>';
		tmpHTML = tmpHTML + '				<tr>';
		tmpHTML = tmpHTML + '					<td>';
		tmpHTML = tmpHTML + '						<img src="images/list.gif" width="5" height="5" />';
		tmpHTML = tmpHTML + '						<strong>Location to Beach : </strong>';
		tmpHTML = tmpHTML + '						' + ViewCount + '';
		tmpHTML = tmpHTML + '					</td>';
		tmpHTML = tmpHTML + '				</tr>';
		tmpHTML = tmpHTML + '				<tr>';
		tmpHTML = tmpHTML + '					<td>';
		tmpHTML = tmpHTML + '						<img src="images/list.gif" width="5" height="5" />';
		tmpHTML = tmpHTML + '						<strong>Bed Sizes:</strong>';
		tmpHTML = tmpHTML + '						' + Bedding + '';
		tmpHTML = tmpHTML + '					</td>';
		tmpHTML = tmpHTML + '				</tr>';
		tmpHTML = tmpHTML + '				<tr>';
		tmpHTML = tmpHTML + '					<td align="center">';
		tmpHTML = tmpHTML + '						<a href="/vacation-rentals/property.asp?rental=' + vPropertyId + '">';
		tmpHTML = tmpHTML + '							<img src="/vacation-rentals/images/more-info.gif" border="0" /></a></td>';
		tmpHTML = tmpHTML + '				</tr>';
		tmpHTML = tmpHTML + '			</table>';
		tmpHTML = tmpHTML + '		</td>';
		tmpHTML = tmpHTML + '	</tr>';
		tmpHTML = tmpHTML + '</table>';
		tmpHTML = tmpHTML + '<br />';


		replaceHtml ( 'div' + vPropertyId, tmpHTML ) ;
	}catch(e){
		//window.alert (e);
	}
}
