var IdCity = -1;

function checkForm() {
	if (document.search.keyword.value=="") return false;
	return true;
}	
function doClear(theText) { if (theText.value == theText.defaultValue) { theText.value = "" } }	
function doDefault(theText) { if (theText.value == "") { theText.value = theText.defaultValue } }
	
$(document).ready(function() {
	$('.idx_control_type').change(function() {
		type = $("option:selected", this).val();
		if(type =="-1") return false;
		form = $('#form').val();
		min_price = $('#mprice').val();
		url_max_price = URL_SITE+'select/max-price/'+type+'/'+form+'/'+min_price ;
		url_min_price = URL_SITE+'select/min-price/'+type+'/'+form+'/'+min_price ;
		jQuery('#min-price').load(url_min_price);
		jQuery('#max-price').load(url_max_price);
	});
	
	$('.idx_type').change(function() {
		type = $(this+":checked").val();
		if(type =="-1") return false;
		form = $('#form').val();
		url_max_price = URL_SITE+'select/max-price/'+type+'/'+form;
		url_min_price = URL_SITE+'select/min-price/'+type+'/'+form;
		jQuery('#min-price').load(url_min_price);
		jQuery('#max-price').load(url_max_price);
	});
	
	$('.list-tabs').live('click', function() {
		 var code = $(this).attr('rel');
		 $.ajax({
	          type: 'GET',
	          url: URL_SITE+'tab-page/'+code,
	          success: function(data) {
			    $('.content-tab').html(data);
	          }
	      });
	});
	
	$('.img_banner').live('click', function() {
		var img = $(this).attr('rel');
		var id = $(this).attr('id');
		$('#project_dev_'+id).attr('src', img);
	});
	
	
	
	
	$('.vcity').live('change', function() {
		IdCity = $("option:selected", this).val();
		if(IdCity != -1) {
			vcnt = '<input id="submit-form" type="image" src="'+URL_SITE+'public/image/idx_btn_mini_search.png" border="0" />';
			$('#btn_submit').html(vcnt);
		} else
			$('#btn_submit').html('<img src="'+URL_SITE+'public/image/idx_btn_mini_search_off.png" border="0" />');
	});
	
	 $('#idx_advanced_search_city').change(function () {
         var str = "";
         $("#idx_advanced_search_city option:selected").each(function () {
        	 x = $(this).val();
        	 if( x != '-1') { str += $(this).val() + "|"; }
             });
         $("#idx_advanced_search_cities").val(str);
    }).trigger('change');
	
	$('.ofname').live('click', function() {
		 var code = $(this).attr('rel');
		 $.ajax({
	          type: 'GET',
	          url: URL_SITE+'contact/filter/'+code,
	          dataType: 'html',
	          success: function(html) {
	        	  $('.map-contact').html(html);
	          }
	      });
	});
	
	$('.item_video').live('click', function() {
		 var code = $(this).attr('rel');
		 content = '<iframe class="youtube-player" type="text/html" width="640" height="399" src="http://www.youtube.com/embed/'+code+'" frameborder="0" style="border:0px;"></iframe>';
		 $('.cnt_video').html(content);
	});
	
	
 });

 function pagination(url){
	jQuery('.content-right').load(url);
 }
 
 function submit_select(value, type) {
	if(value == 0) return false;
	switch(type) {
		case 1: url = URL_SITE+'properties/foreclosure/'+value; break;
		case 2: url = URL_SITE+'properties/condos/'+value; break; 
	}
	window.location.href = url;
 }
 
$('.add-favorites').live('click', function(){
	var mslid = $(this).attr('rel');
	$.ajax({
		url: URL_SITE+'properties/add-favorites/'+mslid,
		type: 'GET', 
		dataType: 'text',
		success: function(data) {
			if(data == 'login')
				document.location = URL_SITE+'login';
			else
			alert(data);
	    }
	});
});

$('.remove-favorites').live('click', function(){
	var mslid = $(this).attr('rel');
	$.ajax({
		url: URL_SITE+'properties/remove-favorites/'+mslid,
		type: 'GET', 
		dataType: 'text',
		success: function(data) {
			alert(data);
	    }
	});
});

function property_order(order) {
	$.ajax({
    	url: URL_SITE+'list-properties/order/'+order,
    	type: 'GET', 
    	success: function(data){
    			$('#idx_result_property').html(data);    		
    	}
    });
}
