

function updateCities (load) {

	//if (load == null || load == '') {
		//load = "";
	//}
	//alert(load);
    selectedCity = $('county').options[$('county').selectedIndex].value;
    selectedCity = (selectedCity == "") ? "all" : selectedCity;
    
   	new Ajax.Updater('city-list', '/mlssearch/search2.php?county=' + selectedCity, {
                      onComplete: function () {
                      	//load = (load != 'load') ? load : null;
                      	addcity(load);
                      },
	      			  evalScripts:true, asynchronous:true });
	//addcity(load);			  
}

function saveInterval(i){

	selectedCity = $('saveinterval'+ i).options[$('saveinterval'+ i).selectedIndex].value;
    selectedCity = (selectedCity == "") ? "Weekly" : selectedCity;
    //alert(selectedCity);
	 $('saved_indicator'+ i).innerHTML=' &nbsp;&nbsp;<img src="/img/gbl/indicator.white.gif" border="0" />&nbsp;&nbsp;  ';
	 var searchId = $('search_id').value;
	 new Ajax.Request('/mlssearch/pages/interval.php?city='+ selectedCity +'&id='+i, {
     onSuccess: function(transport) {
      	$('saved_indicator'+ i).innerHTML='';


      
  }
});
	
}

function freset(){
	var s=0;	
	$('minprice').selectedIndex = s;
	$('beds').selectedIndex = s;
	$('sqft').selectedIndex = s;
	$('maxprice').selectedIndex = s;
	$('baths').selectedIndex = s;
	$('sortbuy').selectedIndex = s;
	
	if ($('land') != null){
	$('land').checked = false;
	$('mobl').checked = false;
	$('multi').checked = false;
	$('sing').checked = true;
	$('cond').checked = true;
	}
	
	if ($('Qsubtype') != null ){
	$('Qsubtype').selectedIndex = s;
	}
	
	
	  new Ajax.Request('/rpc.php?action=clear', {
      onSuccess: addcity });
}
function saveSearch () {

	
	$('saved_indicator').innerHTML=' &nbsp;&nbsp;<img src="/img/gbl/indicator.white.gif" border="0" />&nbsp;&nbsp;';
	formblock= document.getElementById('searchForm');
	forminputs = formblock.getElementsByTagName('input');
	var city = '';
	var proptype = '';
	var subproptype = '';
	
	for (i = 0; i < forminputs.length; i++) {
		// regex here to check name attribute
		    var cityname = "search_city"
			var regex = new RegExp(cityname, "i");
			
			if (regex.test(forminputs[i].getAttribute('name'))) {
			    if (forminputs[i].checked){
				city = "&search_city[]="+ forminputs[i].getAttribute('value') + "" + city;
			    }
			}
			
			var subpropname = "sub";
			var regex = new RegExp(subpropname, "i");
			if (regex.test(forminputs[i].getAttribute('name'))) {
			    if (forminputs[i].checked){
				subproptype = "'"+ forminputs[i].getAttribute('value') + "'," + subproptype;
			    }
			}
			
			
			var propname = "proptype";
			var regex = new RegExp(propname, "i");
			if (regex.test(forminputs[i].getAttribute('name'))) {
			    if (forminputs[i].checked){
				proptype = "'"+ forminputs[i].getAttribute('value') + "'," + proptype;
			    }
			}
			
		
	}
	proptype = proptype.substring(0,(proptype.length)-1);
	subproptype = subproptype.substring(0,(subproptype.length)-1);
	
	var thecity = city;
	var theproptype = proptype;
    var thesubproptype = subproptype;
	
	var beds = $('beds');
	var sub = $('Qsubtype');
	var baths = $('baths');
	var minprice = $('minprice');
	var maxprice = $('maxprice');
	var sqft = $('sqft');
	var county = $('county');
	
	var thebeds = beds.options[beds.selectedIndex].value; 
	var thebaths = baths.options[baths.selectedIndex].value; 
	var theminprice = minprice.options[minprice.selectedIndex].value; 
	var themaxprice = maxprice.options[maxprice.selectedIndex].value; 
	if (county != null && county != ""){
	var thecounty = county.options[county.selectedIndex].value; 
	}
	var thesqft = sqft.options[sqft.selectedIndex].value;
	if ((subproptype == null || subproptype == "") && sub != null && sub != "")
	var thesubproptype = sub.options[sub.selectedIndex].value; 
	
	//if (themaxprice != "NoLimit"){

	var theurl = '&search_city='+thecity+'&county='+thecounty+'&sub='+thesubproptype+'&proptype='+theproptype+'&minimum_price='+theminprice+'&maximum_price='+themaxprice+'&minimum_bedrooms='+thebeds+'&minimum_bathrooms='+thebaths+'&minimum_sqft='+thesqft+'&save=Save+%26+Search';
	//}else{
	//var theurl = '&search_city='+thecity+'&county='+thecounty+'&sub='+thesubproptype+'&proptype='+theproptype+'&minimum_price='+theminprice+'&minimum_bedrooms='+thebeds+'&minimum_bathrooms='+thebaths+'&minimum_sqft='+thesqft+'&save=Save+%26+Search';		
    //alert(theurl);
	//}
  new Ajax.Request('/mlssearch/save_search.php?new_search=true&'+ theurl, {
  onSuccess: function(transport) {
      	$('saved_indicator').innerHTML='Save Search';
    	document.location = '/mlssearch/saved-searches.html';
      
  }
});
}


function togglemap(){
		
	if ($('map-search').style.display=="block"){ 
		$('map-search').style.display="none";
		$('hidden_list').style.display="block";
		$('hide_map').innerHTML='VIEW LIST | <a href="javascript: void(0)" class="current" onclick="togglemap();">SHOW MAP</a>';
	}else{
		
		$('map-search').style.display="block";
		$('hidden_list').style.display="none";
		$('hide_map').innerHTML='<a href="javascript: void(0)" onclick="togglemap();" class="current">VIEW LIST</a> | SHOW MAP';
	}
	
}

function mailto(){
var user = "inforequest";
var site = "marindreamhouse.com";
$('mailto').href = 'mailto:' + user + '@' + site;
}

function openNewWindow(URLtoOpen, windowName, windowFeatures) { newWindow=window.open(URLtoOpen, windowName, windowFeatures); } 