	function displayResult(){
		obj = eval( '(' + ajax.response + ')' );
		alert( obj.message );
	}

	function hideFavorite(fid){
		obj = eval( '(' + ajax.response + ')' );
		alert( obj.message );
		if ( obj.result == 1){
			document.getElementById( "prop-" + fid ).style.display='none';
			document.history.reload();
		}
	}
	var ajax; 
	
	function addFavorite(pid){
		ajax =  new sack();
		ajax.setVar("action", "new"); 
		ajax.setVar("pid", pid);
		ajax.requestFile = "/web/traveler/favorites.cgi";
		ajax.method = "GET";
		ajax.onCompletion = function(){
			obj = eval( '(' + ajax.response + ')' );
			if ( obj.result == 0){
				var link = document.getElementById('linkFav-'+pid);
				link.fav = { fid: obj.fid ,"pid": pid};
				formatlink(link, true);
			} else if ( obj.result == -1){
				location.href = "http://rentalo.com/web/traveler/travelerlogin.cgi";
			} 
		};
		ajax.runAJAX();
	} 

	function delFavorite(fid){
		ajax =  new sack();
		ajax.setVar("action", "delete"); 
		ajax.setVar("fid", fid);
		ajax.requestFile = "/web/traveler/favorites.cgi";
		ajax.method = "GET";
		ajax.onCompletion = function(){
			obj = eval( '(' + ajax.response + ')' );
			if ( obj.result == 0){
				// alert( obj.message );
			}
		};
		ajax.runAJAX();
	} 
	
	function delFavoriteReload(fid){
		ajax =  new sack();
		ajax.setVar("action", "delete"); 
		ajax.setVar("fid", fid);
		ajax.requestFile = "/web/traveler/favorites.cgi";
		ajax.method = "GET";
		ajax.onCompletion = function(){
			obj = eval( '(' + ajax.response + ')' );
			if ( obj.result == 0){
				history.go(0);
			}
		};
		ajax.runAJAX();
	} 
		
	var req;
	function enableFavoritesLinks(){
		req =  new sack();
		req.setVar("action", "read"); 
		req.requestFile = "/web/traveler/favorites.cgi";
		req.method = "GET";
		req.onCompletion = function(){
			var favorites = eval( '(' + req.response + ')' );
			
			if ( favorites.result && favorites.result == -1){
				return ;
			}
			
			for( var j = 0; j < favorites.length; j++ ) {
				var fav = favorites[j];
				var link = document.getElementById('linkFav-' + fav.pid);
				if ( link ){ link.fav = fav; formatlink(link, true); }
			}
		};
		req.runAJAX();
	}
	
	// called for remove a favorite then has been added previously
	function removeFavoriteProperty(){
		delFavorite( this.fav.fid );
		formatlink(this, false);
		return false;
	}
	
	// called for add a favroite then has been removed previously
	function addFavoriteProperty(){
		addFavorite( this.fav.pid );
		return false;
	}
	
	function formatlink(link, isFavorite){
		if ( isFavorite ){
			// link.style.backgroundImage = "http://i.rentalo.com/g/traveler-panel/remove-btn.gif";
			link.innerHTML = "Remove Favorite";
			link.onclick = removeFavoriteProperty;
		} else {
			// link.style.backgroundImage = "http://i.rentalo.com/g/traveler-panel/remove-btn.gif";
			link.innerHTML = "Add to Favorites";
			link.onclick = addFavoriteProperty;
  		}
	}
	