// Contact Us dropdown

jQuery(document).ready(function($) 
{
	$("a#enquiry_anchor, a.enquiry_anchor")
	.click(function () 
	{	
		$('html').animate({scrollTop:0}, 'slow'); 
		$("div#enquiry_slide_down").slideToggle();
		clear_messages();
		return false;
	})
});

///////////////
/* 
function add_subscriber_ajax(email)
{
	var $ = jQuery;

	$.fn.clearForm = function() {
	  return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
		  return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
		  this.value = '';
		else if (type == 'checkbox' || type == 'radio')
		  this.checked = false;
		else if (tag == 'select')
		  this.selectedIndex = -1;
	  });
	};

	$.post(
		"/booking/async_call.php",
		{action: "add_subscriber", email: email},
		function(data, textStatus)
		{
			clear_messages();
			$("message",data).each(function(id) {
				   message = $("message",data).get(id);
				   add_message($("title",message).text(), $("description",message).text());
				 }); 

			if ($("title", $("message", data).eq(0)).text() == "Subscribed")
			{
				$("form").filter("#subscriber_form").clearForm();
			}
		},
		"xml"
	);

	return false;
}
 */

function submit_enquiry_form()
{
	var $ = jQuery;
	
	if($(this).parents("#enquiry_slide_down").length > 0) 
	{
		return send_enquiry_ajax(
			$("#first_name").val(),
			$("#last_name").val(),
			$("#email").val(),
			$("#phone").val(),
			$("#message").val()
		);
	}
}

function send_enquiry_ajax(first_name, last_name, email, phone, message)
{
	var $ = jQuery;
	
	$.fn.clearForm = function() {
	  return this.each(function() {
		var type = this.type, tag = this.tagName.toLowerCase();
		if (tag == 'form')
		  return $(':input',this).clearForm();
		if (type == 'text' || type == 'password' || tag == 'textarea')
		  this.value = '';
		else if (type == 'checkbox' || type == 'radio')
		  this.checked = false;
		else if (tag == 'select')
		  this.selectedIndex = -1;
	  });
	};

	$.post(
		"/booking/async_call.php",
		{action: "send_enquiry", first_name: first_name, last_name: last_name, email: email, phone: phone, message: message},
		function(data, textStatus)
		{
			clear_messages();
			$("message",data).each(function(id) {
				   message = $("message",data).get(id);
				   add_message($("title",message).text(), $("description",message).text());
				 }); 

			if ($("title", $("message", data).eq(0)).text() == "Enquiry Sent")
			{
				try
				{
					_s_action('03');
					pageTracker._trackPageview('/CONTACT_FORM/SENT');
				}
				catch (err)
				{
					//Do nothing
				}
				$("form").filter("#enquiry_html_form").clearForm();
				$("a#enquiry_anchor").click();
			}
		}, 
		"xml"
	);

	return false;
}

// Messages Javascript //

function add_message(title, message)
{
	var $ = jQuery;
	
	$('#enquiry_message_container').show();
	$('#enquiry_messages').append("<h6>" + title + "</h6>" + message);
}

function clear_messages()
{
	var $ = jQuery;
	
	$('#enquiry_message_container').hide();
	$('#enquiry_messages').html("");
}

