// JavaScript Document

var buttonId;

jQuery(document).ready(function(){  
	 
	//jQuery('input').css('border', '1px solid red');
	                                                                                                                                         
	initCommentForm();
																																											
	function initCommentForm() {
		
		jQuery('.enquiry_button').unbind('click');
		
		jQuery('.enquiry_button').bind('click', function() {
			
			buttonId = (jQuery(this).attr('class')).split(" ")[0];
			//console.log(buttonId);
			
			jQuery.ajax({
				 type: "POST",
				 url: "/properties/add_property_to_enquiry_list_process.php",
				 data: jQuery(".form-" + buttonId).serialize(),
				 success: saveUserResponse
			});
			// do any other stuff here like animating button with loading button. to show its doing something. 
			

			return false;
			
		});
		// what happens on success of submitting form
		function saveUserResponse(){			
			// do stuff here to show that button is selected. 			
			//	jQuery("#" + buttonId).css('display','none');
			//	jQuery("#" + deleteButtonId).css('display','block');


			var addButton = jQuery('.' + buttonId);

			if (!addButton.hasClass('is_delete'))
			{
				addButton.attr('value', '');
				
				addButton.addClass('is_delete');
				addButton.removeClass('is_add');
								
				jQuery(jQuery('.form-' + buttonId + ' .action_type')).attr('value', 'delete_property_from_enquiry_list');
				
			} else
			{
				addButton.attr('value', '');
				
				addButton.addClass('is_add');
				addButton.removeClass('is_delete');
				
				jQuery(jQuery('.form-' + buttonId + ' .action_type')).attr('value', 'add_property_to_enquiry_list');
			}
			
			jQuery.ajax({
				url: "/properties/includes/favourites_panel.php",
				cache: false,
				success: function(html){
				 jQuery("#current_favourites").empty();
				 jQuery("#current_favourites").append(html);
				}
			});
			
			//jQuery('.add_property_to_list .enquiry_button').css('background','pink');
		}
	};                                                                                             
});

