var skip_search_value = false;
function validsearch()
{
	if (skip_search_value) return true;
	
	if ($('#query')[0].value == '' || $('#query')[0].value ==  'Enter a city name, property address, or zip code.')  {
		$('#queryrequire').fadeIn();
		return false;
	}
	return true;
}

function suggest(inputString){
	if(inputString.length == 0) {
		$('#suggestions').fadeOut();
	} else {
	$('#country').addClass('load');
		$.post("index.php?action=suggestion", {queryString: ""+inputString+""}, function(data){
			if(data.length >0) {
				$('#suggestions').fadeIn();
				$('#suggestionsList').html(data);
				$('#country').removeClass('load');
			}
		});
	}
}

function fill(thisValue) {
	//$('#query').val(thisValue);
	//setTimeout("$('#suggestions').fadeOut();", 600);
}

var old_query_value = '';

$(function(){
	if ($('#query')[0])
	{
		old_query_value = $('#query')[0].value;
		if (old_query_value == 'Enter a city name, property address, or zip code.')
		{
			$('#query').addClass('empty_text');
		}
	}
	
	$('#query').focus(function(){
		if (this.value == 'Enter a city name, property address, or zip code.')
		{
			this.value = '';
			//color:#2E850D;
			//$(this).css('color','#2E850D');
			$(this).removeClass('empty_text');
		}
		
	});
	
	$('#query').blur(function(){
		if (this.value == '')
		{
			this.value = 'Enter a city name, property address, or zip code.';
			//$(this).css('color','grey');
			$(this).addClass('empty_text');
		}
		
	});
	
	$('#query').keyup(function(){
		new_query_value = this.value;
		if (old_query_value != new_query_value)
		{
			old_query_value = new_query_value;
			
			
			
			if (old_query_value.length > 0)
			{
				$('#queryrequire').fadeOut();
				$('#suggestion').fadeIn();
				$('#suggestion').html("<img src='/images/loader.gif' />");
				$.post('/index.php?c=search&action=suggestion',{query: old_query_value},function (html){
					if (html.length > 0)
					{
						$('#suggestion').html(html);
						$('#suggestion li').hover(function(){$(this).addClass('hover');},function(){$(this).removeClass('hover')});
						$('#suggestion li').click(function(){
							$('#query')[0].value = $(this).text();
							$('#suggestion').fadeOut();
						});
					} else {
						$('#suggestion').fadeOut();
					}
				});
			} else {
				$('#suggestion').fadeOut();
			}
			
		} else
		{
			$('#suggestion').fadeOut();
		}
	});
	
	
	
	
	
	$('#nav .account .menu').hover(function(){
		$('#nav .account .favorite_list').slideDown(200);
		show_favorite_menu = true;
	},function(){
		show_favorite_menu = false;
		setTimeout(" hideFavoriteMenu();",1000);		
	});
	
	$('#nav .account .favorite_list').hover(function(){
		show_favorite_menu  = true;
	},function(){
		show_favorite_menu = false;
		setTimeout(" hideFavoriteMenu();",1000);	
	});
	
	
	
});
var show_favorite_menu = false;
function hideFavoriteMenu()
{
	if (!show_favorite_menu)
	{
		$('#nav .account .favorite_list').slideUp(200);
	}
}

function propertyFavoriteClick()
{
	if ($('.property.favorite.btn').hasClass('save'))
	{
		old_url = $('.property.favorite.btn')[0].href; 
		url =  old_url + '/ajax/1';
		$.get(url,{},function(data){alert(data);
			if (data != 'Please login to use this feature.')
			{
			$('.property.favorite.btn').removeClass('save');
			$('.property.favorite.btn').addClass('remove');
			$('.property.favorite.btn').html('REMOVE');
			$('.property.favorite.btn')[0].href = old_url.replace('/save/','/remove/');
			}
		});
	} else
	{
		old_url = $('.property.favorite.btn')[0].href; 
		url =  old_url + '/ajax/1';
		$.get(url,{},function(data){
			alert(data);
			$('.property.favorite.btn').removeClass('remove');
			$('.property.favorite.btn').addClass('save');
			$('.property.favorite.btn').html('SAVE');
			$('.property.favorite.btn')[0].href = old_url.replace('/remove/','/save/'); 
		});
	}
	return false;
}

function searchadvance()
{

	$('#s_form')[0].action = '/search/advance';
	skip_search_value = true;
	$('#s_form_submit')[0].click();
	return false;
}
