$(document).ready(
	function(){
		$("#idx-search-form").submit(
			function(){
				
			   $.ajax({
				   type: "POST",
				   async: false,
				   data: $(this).serialize(),
				   url: SOLUTION_URL + "save_search.php",
				   success : function(response){
						
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
					   window.alert('err: ' + textStatus + '-' + errorThrown);
					}
				});
								
				var location=$('#idx-search-location option:selected');
				var type=$('#idx-search-type option:selected');
				if (location.val() == 'any' && type.val() == 'any')
					this.action+='search';
				else if (location.val() != 'any' && type.val() != 'any')
					//this.action+=escape(location.text()) + '/' + escape(type.text()) + '/';
					this.action+=location.text() + '/' + type.text() + '/';
				else if (location.val() != 'any')
					//this.action+=escape(location.text()) + '/';
					this.action+=location.text() + '/';
				else
					//this.action+=escape(type.text()) + '/';
					this.action+=type.text() + '/';
					
				window.location=this.action;
				
				return false;
			}
		);
		
		$("#search-result-filters").submit(
			function(){
				
			   $.ajax({
				   type: "POST",
				   async: false,
				   data: $(this).serialize(),
				   url: SOLUTION_URL + "save_search.php",
				   success : function(response){
						
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
					   window.alert('err: ' + textStatus + '-' + errorThrown);
					}
				});
								
				window.location=this.action;
				
				return false;
			}
		);
		
		$("#property-search-form").submit(
			function(){
				
			   $.ajax({
				   type: "POST",
				   async: false,
				   data: $(this).serialize(),
				   url: SOLUTION_URL + "save_search.php",
				   success : function(response){
						
					},
					error : function(XMLHttpRequest, textStatus, errorThrown) {
					   window.alert('err: ' + textStatus + '-' + errorThrown);
					}
				});
								
				window.location=this.action;
				
				return false;
			}
		);
	}
);

function searchAjaxSubmit(frm)
{
   $.ajax({
	   type: "POST",
	   async: false,
	   data: $(frm).serialize(),
	   url: SOLUTION_URL + "save_search.php",
	   success : function(response){
			
		},
		error : function(XMLHttpRequest, textStatus, errorThrown) {
		   window.alert('err: ' + textStatus + '-' + errorThrown);
		}
	});
   
	window.location=frm.get(0).action;
	
	return false;
}
