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);
	});
	
	$('#select_building').change(function() {
		type = $("option:selected", this).val();
		if(type =="-1") return false;
		var url_site = URL_SITE+'properties/buildings/'+type;
		window.location.href = url_site; 
	});
	
	$('#select_neighborhood').change(function() {
		type = $("option:selected", this).val();
		if(type =="-1") return false;
		var url_site = URL_SITE+'neighborhood/'+type;
		window.location.href = url_site; 
	});
	
	$('.idx_type').change(function() {
		type = $(this+":checked").val();
		if(type =="-1") return false;
		form = $('#mform').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);
	          }
	      });
	});
	
 });

 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);    		
    	}
    });
}

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

function MM_swapImgRestore() {
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() {
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) {
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() {
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

