
// Send an ajax call to m=accommodations&op=addfavourite
// // and show a message telling the user it has been added,
// and that they can view their favorites from the menu
// at the top
function add_favourite(prop_id, title, loggedin) {	
	if (loggedin == 1) {
		// Callback does nothing; expects no server response
		ajax.makeRequest('get', baseurl + "index.php?m=accommodations&op=addfavourite&id=" + prop_id + "&ajax=1", function() { });

		alert(title + " has been added to your favourites. You may view them at any time using the menu at the top of the page.");
	} else {
		alert("Sorry, but you must be logged in to add properties to your favourites.");
	}
}

function remove_favourite(prop_id, title, remove_from_list) {
	// Callback does nothing; expects no server response
	ajax.makeRequest('get', baseurl + "index.php?m=accommodations&op=removefavourite&id=" + prop_id + "&ajax=1", function() { });
	
//	if (typeof(remove_from_list) !== 'undefined') {
//		$(remove_from_list).style.visibility = "none";		
//	}
//
	alert(title + " has been removed from your favourites.");
	
}

faq = {
	add_event : function() {
		if ($('faq_container')) {
			dom.addEvent($('faq_container'), 'click', faq.toggle_answer);
		}
	},
	
	toggle_answer : function(e) {
		var target = dom.getTarget(e);
		try {
			if (target.className == 'faq_question') {
				var answer = target.nextSibling.nextSibling;
				if (answer.className == 'faq_hidden_answer') {
					answer.className = 'faq_visible_answer';
				} else {
					answer.className = 'faq_hidden_answer';
				}
			}
		} catch (err) {
			alert("Failed to make the answer visible. Error: " . err);
		}
	}
}

tooltips = {
	init : function() {
		// Add a click event to the center panel, which
		// checks if what was clicked was a div with the class 
		// "tooltip," and if it was copy the innerHTML contents
		// of that div to a form field. But which form field?
		dom.addEvent($('centerpanel'), 'click', tooltips.processTooltip);
	},
		
	processTooltip : function(event) {
		var target = dom.getTarget(event);

		if (sa2.checkClassName(target, 'tooltip')) {
			//dom.dumpProps(target);
			var text = target.innerHTML;
			
			var id = target.className;
			id = target.className.substring(8, 18);

			var idfield = $(id);

			var searchfield = id + '_search';
			var textfield = $(searchfield);
			textfield.value = text;
		}		
	}		
}

sa2.onLoad(faq.add_event);
sa2.onLoad(tooltips.init);
