function resetAdvanced(Init){
	try{
		var data = "cmd=resetAdvanced"
		if (Init != null){
			data = data + "&Init=" + Init;
		}
		data = data + "&AdvPropertyType=" + document.getElementById("AdvPropertyType").options[document.getElementById("AdvPropertyType").selectedIndex].value;
		data = data + "&AdvBedrooms=" + document.getElementById("AdvBedrooms").options[document.getElementById("AdvBedrooms").selectedIndex].value;
		data = data + "&AdvLocation=" + document.getElementById("AdvLocation").options[document.getElementById("AdvLocation").selectedIndex].value;
		data = data + "&AdvProximity=" + document.getElementById("AdvProximity").options[document.getElementById("AdvProximity").selectedIndex].value;
		data = data + "&AdvPromotionCode=" + document.getElementById("AdvPromotionCode").value;

		if ( _checkDate(document.getElementById("AdvRequested_date").value) && _checkDate(document.getElementById("AdvRequested_date2").value))
		{
			data = data + "&AdvCheck_In=" + document.getElementById("AdvRequested_date").value;
			data = data + "&AdvCheck_Out=" + document.getElementById("AdvRequested_date2").value;
		}else{
			data = data + "&AdvCheck_In=&AdvCheck_Out=";
		}
		
		var checks = document.getElementsByTagName("input");
		var chk, chkId, chkTable, chkField
		if ( checks ){
			for  ( var i = 0; i < checks.length; i++){
				chk = checks[i];
				if (chk.type == "checkbox") {
					chkId = (chk.id).split("__");
					if (chkId && chkId.length == 2 && chk.checked ) {
						chkField = chkId[1];
						data = data + "&AdvAmenity=" + chkField;
					}
				}
			}
		}
		//window.alert( data ) ;
		replaceHtml ( 'divPromotion', '' );
		setNone ( 'divPromotion' );
		setNone ( 'divRating' );
		setNone ( 'divCommant' );
		replaceHtml ( 'divResults', '' );
		replaceHtml ( 'spnAdvSearch', "<img src='/vacation-rentals/images/progressImg.gif' style='width:20px;height:20px;'>");
		replaceHtml ( 'spnResult', "searching ...");
		sendRequest( _afterResetAdvanced, data, "POST", "/vacation-rentals/includes/call-i-advanced-search.asp", true );
		
		setCursorWait();
		
	}catch(e){
		//window.alert ( "resetAdvanced" + '\n\r' + e ) ;
		replaceHtml ( 'spnAdvSearch', "&nbsp;&nbsp;&nbsp;");
		setCursorDefault();
	}
}

function _afterResetAdvanced( oj ) {	
	try{
		var xmlDoc  = oj.responseXML;	
		var result = xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue;
		if (result =="ok"){
			replaceHtml ("spnAdvPropertyType", xmlDoc.getElementsByTagName("AdvPropertyTypeHTML")[0].firstChild.nodeValue );
			replaceHtml ("spnAdvBedrooms", xmlDoc.getElementsByTagName("AdvBedroomsHTML")[0].firstChild.nodeValue );
			replaceHtml ("spnAdvLocation", xmlDoc.getElementsByTagName("AdvLocationHTML")[0].firstChild.nodeValue );
			replaceHtml ("spnAdvProximity", xmlDoc.getElementsByTagName("AdvProximityHTML")[0].firstChild.nodeValue );
			replaceHtml ("spnResult", "show " + xmlDoc.getElementsByTagName("ResultCount")[0].firstChild.nodeValue + " results");
			
			document.getElementById("hdnResultList").value = xmlDoc.getElementsByTagName("PropertyList")[0].firstChild.nodeValue;
			document.getElementById("hdnResultListPH").value = xmlDoc.getElementsByTagName("PropertyListPH")[0].firstChild.nodeValue;
			document.getElementById("hdnResultListPL").value = xmlDoc.getElementsByTagName("PropertyListPL")[0].firstChild.nodeValue;

		}
	}catch(e){
		//window.alert ( "_afterResetAdvanced" + '\n\r' + e ) ;
	}finally{		
		replaceHtml ( 'spnAdvSearch', "&nbsp;&nbsp;&nbsp;");
		setCursorDefault();
	}
}

function setCursorDefault(){
	try{
		document.body.style.cursor = 'default' ;

		var brwsr=navigator.appName;
		if (brwsr=="Microsoft Internet Explorer"){
			document.getElementById("tblAdvSearch").style.cursor = 'hand' ;
			document.getElementById("spnResult").style.cursor = 'hand' ;
		}else{
			document.getElementById("tblAdvSearch").style.cursor = 'pointer' ;
			document.getElementById("spnResult").style.cursor = 'pointer' ;
		}

		document.getElementById("AdvRequested_date").style.cursor = 'text' ;
		document.getElementById("AdvRequested_date2").style.cursor = 'text' ;

		document.getElementById("AdvPropertyType").style.cursor = 'default' ;
		document.getElementById("AdvBedrooms").style.cursor = 'default' ;
		document.getElementById("AdvLocation").style.cursor = 'default' ;
		document.getElementById("AdvProximity").style.cursor = 'default' ;

		document.getElementById("AdvPromotionCode").style.cursor = 'text' ;

	}catch(e){
		//window.alert ( "setCursorDefault" + '\n\r' + e ) ;
	}
}

function setCursorWait(){
	try{
		document.body.style.cursor = 'wait' ;
		document.getElementById("tblAdvSearch").style.cursor = 'wait' ;
		document.getElementById("spnResult").style.cursor = 'wait' ;

		document.getElementById("AdvRequested_date").style.cursor = 'wait' ;
		document.getElementById("AdvRequested_date2").style.cursor = 'wait' ;

		document.getElementById("AdvPropertyType").style.cursor = 'wait' ;
		document.getElementById("AdvBedrooms").style.cursor = 'wait' ;
		document.getElementById("AdvLocation").style.cursor = 'wait' ;
		document.getElementById("AdvProximity").style.cursor = 'wait' ;

		document.getElementById("AdvPromotionCode").style.cursor = 'wait' ;

	}catch(e){
		//window.alert ( "setCursorWait" + '\n\r' + 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){
			//window.alert ( "toggleElement_inner" + '\n\r' + e ) ;
		}
	}catch(e){
		//window.alert ( "toggleElement_outter" + '\n\r' + e ) ;
	}
	return;
}

function callList() {
	
	try{
		// Promotion
		replaceHtml ( 'divPromotion', '' );
		setNone ( 'divPromotion' );
		var AdvPromotionCode = document.getElementById("AdvPromotionCode").value;
		if (AdvPromotionCode != ""){
			var data = "cmd=Promotion";
			data = data + "&PCode=" + AdvPromotionCode;
			sendRequest( _afterPromotion, data, "POST", "/vacation-rentals/includes/call-i-advanced-search.asp", true );
		}

		// Properties
		document.getElementById("rdoRating").checked = true;
		document.getElementById("rdoRatingPR").checked = false;
		document.getElementById("rdoRatingDR").checked = false;
		document.getElementById("rdoRatingRR").checked = false;

		document.getElementById("selOrder").selectedIndex = 0;
		
		// Properties
		replaceHtml ( 'divResults', '' );

		// Rating
		if (document.getElementById("hdnResultList").value != "" ){
			setBlock ( 'divRating' );
		}else{
			setNone ( 'divRating' );
		}


		// Order By Price
		if (document.getElementById("hdnResultListPH").value != "" ){
			setBlock ( 'divCommant' );
		}else{
			setNone ( 'divCommant' );
		}

		var sLists = document.getElementById("hdnResultList").value;
		var aArg = sLists.split(",");	
		for ( var i=0; i < aArg.length; i++){
			getPropertyDetail (aArg[i]);		
		}
		document.location = "#top2";
	}catch(e){
		//window.alert ( "callList" + '\n\r' + e ) ;
	}
}

function _afterPromotion( oj ) {

	try{
		var xmlDoc  = oj.responseXML;	
		var result = xmlDoc.getElementsByTagName("result")[0].firstChild.nodeValue;		
		
		if ( result == "ok" ){
			var PromotionCode = xmlDoc.getElementsByTagName("PromotionCode")[0].firstChild.nodeValue;			
			var PromotionName = xmlDoc.getElementsByTagName("PromotionName")[0].firstChild.nodeValue;			
			var PromotionDesc = xmlDoc.getElementsByTagName("PromotionDesc")[0].firstChild.nodeValue;			
			var PromotionStartDate = xmlDoc.getElementsByTagName("PromotionStartDate")[0].firstChild.nodeValue;			
			var PromotionEndDate = xmlDoc.getElementsByTagName("PromotionEndDate")[0].firstChild.nodeValue;			
			var PromotionCheck_In = xmlDoc.getElementsByTagName("PromotionCheck_In")[0].firstChild.nodeValue;			
			var PromotionCheck_Out = xmlDoc.getElementsByTagName("PromotionCheck_Out")[0].firstChild.nodeValue;			
			var PromotionCheck_Out_Desc = xmlDoc.getElementsByTagName("PromotionCheck_Out_Desc")[0].firstChild.nodeValue;			
			var tmpHTML = '';
			
			/*
			tmpHTML = tmpHTML + '<h2>Promotion Code: ' + PromotionCode +  '</h2>';
			tmpHTML = tmpHTML + '<h3>' + PromotionName +  '</h3>';
			tmpHTML = tmpHTML + '<li>Valid from ' + PromotionStartDate + ' to ' + PromotionEndDate + '</li>';
			tmpHTML = tmpHTML + '<li>For Bookings between: ' + PromotionCheck_In + ' - ' + PromotionCheck_Out + '</li>';
			tmpHTML = tmpHTML + '<li>' + PromotionDesc + '</li>';
			tmpHTML = tmpHTML + '<br>&nbsp;';
			*/

			tmpHTML = tmpHTML + '<table width="100%" border="0" align="center" cellpadding="6" cellspacing="0" bgcolor="#e5e5e5">';
			tmpHTML = tmpHTML + '	<tr>';
			tmpHTML = tmpHTML + '		<td align="left">';
			tmpHTML = tmpHTML + '		<h2>Promotion Code: ' + PromotionCode +  '</h2>';
			tmpHTML = tmpHTML + '		<h3>' + PromotionName +  '</h3>';
			//tmpHTML = tmpHTML + '		<li>Valid from ' + PromotionStartDate + ' to ' + PromotionEndDate + '</li>';
			tmpHTML = tmpHTML + '		<ul type="disc">';
			tmpHTML = tmpHTML + '		<li>Valid for travel through: ' + PromotionCheck_Out_Desc + '</li>';
			tmpHTML = tmpHTML + '		<li>' + PromotionDesc;
			tmpHTML = tmpHTML + '  </ul>';
			tmpHTML = tmpHTML + '		</td>';
			tmpHTML = tmpHTML + '	</tr>';
			tmpHTML = tmpHTML + '</table>';
			tmpHTML = tmpHTML + '<br />';

			replaceHtml ( 'divPromotion', tmpHTML ) ;
			setBlock ( 'divPromotion' );
		}else{
		}	
	
	}catch(e){
		//window.alert ( "_afterPromotion" + '\n\r' + e ) ;
	}
}

function getPropertyDetail( vPropertyId ){

	try{
		var data = "cmd=PropertyDetail";
		data = data + "&PropertyId=" + vPropertyId;
		//window.alert ( data ) ;
		sendRequest( _afterPropertyDetail, data, "POST", "/vacation-rentals/includes/call-i-advanced-search.asp", true );
	}catch(e){
		//window.alert ( "getPropertyDetail" + '\n\r' + e ) ;
	}
}

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 PromotionRate = xmlDoc.getElementsByTagName("PromotionRate")[0].firstChild.nodeValue;
			var PropertyPicture = xmlDoc.getElementsByTagName("PropertyPicture")[0].firstChild.nodeValue;
			var infoURL = xmlDoc.getElementsByTagName("infoURL")[0].firstChild.nodeValue;
			var PropertyDescription = xmlDoc.getElementsByTagName("PropertyDescription")[0].firstChild.nodeValue;
			var Rating = xmlDoc.getElementsByTagName("Rating")[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, infoURL, PropertyDescription, Rating) ;
	
	}catch(e){
		//window.alert ( "_afterPropertyDetail" + '\n\r' + e ) ;
	}
}

function addPropertyDetail( 
			vPropertyId, PropertyName, Location, 
			ViewCount, Bedrooms, Bathrooms, Bedding, 
			WeeklyRate, 
			PropertyPicture, infoURL, 
			PropertyDescription, Rating){

	try{
		var newDivNode = document.createElement('DIV');
		newDivNode.id = "div" + vPropertyId;
		newDivNode.className = Rating;
		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="2" class="ListingH">' + PropertyName + '</td>';
		tmpHTML = tmpHTML + '		<td class="ListingH" align="center">' + WeeklyRate + '</td>';
		tmpHTML = tmpHTML + '	</tr>';
		tmpHTML = tmpHTML + '	<tr>';
		tmpHTML = tmpHTML + '		<td class="midT" width="200">';
		tmpHTML = tmpHTML + '			<img src="' + 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="' + infoURL + '">';
		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 ( "addPropertyDetail" + '\n\r' + e ) ;
	}
}

function callListOrder( argi ) {
	
	try{
		
		if (argi == 0){	
			replaceHtml ( 'divResults', '' );
		}
	
		document.getElementById("rdoRating").checked = true;
		document.getElementById("rdoRatingPR").checked = false;
		document.getElementById("rdoRatingDR").checked = false;
		document.getElementById("rdoRatingRR").checked = false;

		var objTextObj = document.getElementById("selOrder").options[document.getElementById("selOrder").selectedIndex].value;
		var sListsObj = "hdnResultList" + objTextObj;
		var sLists = document.getElementById(sListsObj).value;
		var aArg = sLists.split(",");	
		for ( var i=0; i < aArg.length; i++){
			if (argi == i ){
				getPropertyDetailOrder (aArg[i], i+1);			
			}
		}
	}catch(e){
		//window.alert ( "callListOrder" + '\n\r' + e ) ;
	}
}

function getPropertyDetailOrder( vPropertyId, OrderIndex ){

	try{
		var data = "cmd=PropertyDetail";
		data = data + "&PropertyId=" + vPropertyId;
		data = data + "&OrderIndex=" + OrderIndex;
		//window.alert ( data ) ;
		sendRequest( _afterPropertyDetailOrder, data, "POST", "/vacation-rentals/includes/call-i-advanced-search.asp", true );
	}catch(e){
		//window.alert ( "getPropertyDetailOrder" + '\n\r' + e ) ;
	}
}

function _afterPropertyDetailOrder( 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 infoURL = xmlDoc.getElementsByTagName("infoURL")[0].firstChild.nodeValue;
			var PropertyDescription = xmlDoc.getElementsByTagName("PropertyDescription")[0].firstChild.nodeValue;
			var Rating = xmlDoc.getElementsByTagName("Rating")[0].firstChild.nodeValue;
			var OrderIndex = xmlDoc.getElementsByTagName("OrderIndex")[0].firstChild.nodeValue;
			
		}else{
			//window.alert (result);
		}
	
		addPropertyDetail ( 
				PropertyId, PropertyName, Location,
				ViewCount, Bedrooms, Bathrooms, Bedding, 
				WeeklyRate, 
				PropertyPicture, infoURL, PropertyDescription, Rating) ;
	
	}catch(e){
		//window.alert ( "_afterPropertyDetailOrder" + '\n\r' + e ) ;
	}finally{
		callListOrder( OrderIndex );
	}
}

function showRating( Rating ){
	
	try{
		var objDiv;
		var aArg = document.getElementById("hdnResultList").value.split(",");	
		for ( var i=0; i < aArg.length; i++){
			
			objDiv = document.getElementById("div" + aArg[i]);
			if (objDiv.className == Rating ){
				objDiv.style.display= 'block';
			}else{
				objDiv.style.display= 'none';
			}
		}
	}catch(e){
		//window.alert ( "showRating" + '\n\r' + e ) ;
	}
}

function showRatingAll( ){
	
	try{
		var objDiv;
		var aArg = document.getElementById("hdnResultList").value.split(",");	
		for ( var i=0; i < aArg.length; i++){
			
			objDiv = document.getElementById("div" + aArg[i]);
			objDiv.style.display= 'block';
		}
	}catch(e){
		//window.alert ( "showRatingAll" + '\n\r' + e ) ;
	}
}