function ajaxFunction(str)
{
   var xmlhttp;
   var pageURL;
   pageURL = str;
   if (window.XMLHttpRequest)
   {
      // code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
   }
   else if (window.ActiveXObject)
   {
     // code for IE6, IE5
     xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }
   else
   {
      alert("Your browser does not support XMLHTTP!");
   }
   
   xmlhttp.onreadystatechange=function() {
      if(xmlhttp.readyState==4)
      {
         document.getElementById('listing_content').innerHTML=xmlhttp.responseText;
         document.getElementById('listing_content_text').innerHTML="Listing View";
         document.getElementById('listing_content_text').click();
      }
   }
   
   xmlhttp.open("GET", pageURL, true);
   xmlhttp.send(null);
}

function showListings(str)
{
   var pageURL;
   
   if(document.getElementById('value5').value == 1 || document.getElementById('value5').value == 2)
   {
      pageURL = "/homes/homes_list_prg.php";
   }
   else if(document.getElementById('value5').value == "Coop" || document.getElementById('value5').value == "Condo")
   {
      pageURL = "/flats/flats_list_prg.php";
   }
   else if(document.getElementById('value5').value == "Rentals")
   {
      pageURL = "/rentals/rentals_list_prg.php";
   }
   else if(document.getElementById('value5').value == "")
   {
      pageURL = "/commercial/commercial_list_prg.php";
   }
   
   document.forms.frmSearch.action = pageURL;
   
   if(str == "showall")
   {
      document.forms.frmSearch.value6.value="0";
      document.forms.frmSearch.value7.value="0";
      document.forms.frmSearch.value11.value="0";
      document.forms.frmSearch.value10011.value="5000000";  
   
      if(document.getElementById('value5').value == 1)
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "Contains";
         document.forms.frmSearch.value5.value = "1";
      }
      else if (document.getElementById('value5').value == 2)
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "More than ...";
         document.forms.frmSearch.value5.value = "1";
      }
      else if (document.getElementById('value5').value == "Coop")
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "Contains";
         document.forms.frmSearch.value5.value = "Coop";
      }
      else if (document.getElementById('value5').value == "Condo")
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "Contains";
         document.forms.frmSearch.value5.value = "Condo";
      }
      else
      {
         document.forms.frmSearch.a.value = "showall";
         document.forms.frmSearch.value5.value = "";
      }
   }
   else
   {
      if(document.getElementById('value5').value == 1)
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "Contains";
         document.forms.frmSearch.value5.value = "1";
      }
      else if (document.getElementById('value5').value == 2)
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "More than ...";
         document.forms.frmSearch.value5.value = "1";
      }
      else if (document.getElementById('value5').value == "Coop")
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "Contains";
         document.forms.frmSearch.value5.value = "Coop";
      }
      else if (document.getElementById('value5').value == "Condo")
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "Contains";
         document.forms.frmSearch.value5.value = "Condo";
      }
      else
      {
         document.forms.frmSearch.a.value = "advsearch";
         document.getElementById('asearchopt5').value = "Contains";
         document.forms.frmSearch.value5.value = "";
         document.forms.frmSearch.value6.value="0";
         document.forms.frmSearch.value7.value="0";
      }
   }
   
   document.forms.frmSearch.submit();
}

function mybreSearchListings(frm)
{
	var pageURL;
   
	if(frm.propertytype.value == "single-family" || frm.propertytype.value == "multi-family")
	{
		pageURL = "/homes/homes_list_prg2.php";
	}
	else if(frm.propertytype.value == "cooperative" || frm.propertytype.value == "condominium")
	{
		pageURL = "/flats/flats_list_prg.php";
	}
	else if(frm.propertytype.value == "rentals")
	{
		pageURL = "/rentals/rentals_list_prg.php";
	}
	else if(frm.propertytype.value == "commercial")
	{
		pageURL = "/commercial/commercial_list_prg.php";
	}
   
	document.forms.frmSearch.action = pageURL;
   
	if(frm.propertytype.value == "single-family")
	{
		document.forms.frmSearch.a.value = "advsearch";
		
		document.getElementById('asearchopt4').value = "Contains";
		document.forms.frmSearch.value4.value = "";
		document.forms.frmSearch.value10004.value = "";
		
		document.getElementById('asearchopt5').value = "Contains";
		document.forms.frmSearch.value5.value = "1";
		document.forms.frmSearch.value10005.value = "";
		
		document.getElementById('asearchopt6').value = "Between";
		document.forms.frmSearch.value6.value = frm.bedmin.value;
		document.forms.frmSearch.value10006.value = frm.bedmax.value;
		
		document.getElementById('asearchopt7').value = "Between";
		document.forms.frmSearch.value7.value = frm.bathmin.value;
		document.forms.frmSearch.value10007.value = frm.bathmax.value;
        
        document.getElementById('asearchopt8').value = "Contains";
        document.forms.frmSearch.value8.value = "";
		document.forms.frmSearch.value10008.value = "";
		
		document.getElementById('asearchopt11').value = "Between";
		document.forms.frmSearch.value11.value = frm.pricemin.value;
		document.forms.frmSearch.value10011.value = frm.pricemax.value;
		
		document.forms.frmSearch.advkeyword.value = frm.keyword.value;
	}
	else if(frm.propertytype.value == "multi-family")
	{
		document.forms.frmSearch.a.value = "advsearch";
		
		document.getElementById('asearchopt4').value = "Contains";
		document.forms.frmSearch.value4.value = "";
		document.forms.frmSearch.value10004.value = "";
		
		document.getElementById('asearchopt5').value = "More than ...";
		document.forms.frmSearch.value5.value = "1";
		document.forms.frmSearch.value10005.value = "";
		
		document.getElementById('asearchopt6').value = "Between";
		document.forms.frmSearch.value6.value = frm.bedmin.value;
		document.forms.frmSearch.value10006.value = frm.bedmax.value;
		
		document.getElementById('asearchopt7').value = "Between";
		document.forms.frmSearch.value7.value = frm.bathmin.value;
		document.forms.frmSearch.value10007.value = frm.bathmax.value;
        
        document.getElementById('asearchopt8').value = "Contains";
        document.forms.frmSearch.value8.value = "";
		document.forms.frmSearch.value10008.value = "";
		
		document.getElementById('asearchopt11').value = "Between";
		document.forms.frmSearch.value11.value = frm.pricemin.value;
		document.forms.frmSearch.value10011.value = frm.pricemax.value;

		document.forms.frmSearch.advkeyword.value = frm.keyword.value;
	}
	else if(frm.propertytype.value == "cooperative")
    {
        document.forms.frmSearch.a.value = "advsearch";
		 
		document.getElementById('asearchopt4').value = "Contains";
		document.forms.frmSearch.value4.value = "";
		document.forms.frmSearch.value10004.value = "";
		
		document.getElementById('asearchopt5').value = "Contains";
		document.forms.frmSearch.value5.value = "Coop";
		document.forms.frmSearch.value10005.value = "";
		
		document.getElementById('asearchopt6').value = "Between";
		document.forms.frmSearch.value6.value = frm.bedmin.value;
		document.forms.frmSearch.value10006.value = frm.bedmax.value;
		
		document.getElementById('asearchopt7').value = "Between";
		document.forms.frmSearch.value7.value = frm.bathmin.value;
		document.forms.frmSearch.value10007.value = frm.bathmax.value;
        
        document.getElementById('asearchopt8').value = "Contains";
        document.forms.frmSearch.value8.value = "";
		document.forms.frmSearch.value10008.value = "";
		
		document.getElementById('asearchopt11').value = "Between";
		document.forms.frmSearch.value11.value = frm.pricemin.value;
		document.forms.frmSearch.value10011.value = frm.pricemax.value;
    }
	else if(frm.propertytype.value == "condominium")
	{
		document.forms.frmSearch.a.value = "advsearch";
		
		document.getElementById('asearchopt4').value = "Contains";
		document.forms.frmSearch.value4.value = "";
		document.forms.frmSearch.value10004.value = "";
		
		document.getElementById('asearchopt5').value = "Contains";
		document.forms.frmSearch.value5.value = "Condo";
		document.forms.frmSearch.value10005.value = "";
		
		document.getElementById('asearchopt6').value = "Between";
		document.forms.frmSearch.value6.value = frm.bedmin.value;
		document.forms.frmSearch.value10006.value = frm.bedmax.value;
		
		document.getElementById('asearchopt7').value = "Between";
		document.forms.frmSearch.value7.value = frm.bathmin.value;
		document.forms.frmSearch.value10007.value = frm.bathmax.value;
        
        document.getElementById('asearchopt8').value = "Contains";
        document.forms.frmSearch.value8.value = "";
		document.forms.frmSearch.value10008.value = "";
		
		document.getElementById('asearchopt11').value = "Between";
		document.forms.frmSearch.value11.value = frm.pricemin.value;
		document.forms.frmSearch.value10011.value = frm.pricemax.value;
	}
	else if(frm.propertytype.value == "rentals")
	{
        document.forms.frmSearch.a.value = "advsearch";
		
        document.getElementById('asearchopt4').value = "Between";
		document.forms.frmSearch.value4.value = frm.bedmin.value;
		document.forms.frmSearch.value10004.value = frm.bedmax.value;
		
		document.getElementById('asearchopt5').value = "Between";
        document.forms.frmSearch.value5.value = frm.bathmin.value;
		document.forms.frmSearch.value10005.value = frm.bathmax.value;
		
		document.getElementById('asearchopt6').value = "Contains";
        document.forms.frmSearch.value6.value = "";
		document.forms.frmSearch.value10006.value = "";
		
		document.getElementById('asearchopt7').value = "Contains";
        document.forms.frmSearch.value7.value = "";
		document.forms.frmSearch.value10007.value = "";
        
        document.getElementById('asearchopt8').value = "Between";
        document.forms.frmSearch.value8.value = frm.pricemin.value;
		document.forms.frmSearch.value10008.value = frm.pricemax.value;
		
		document.getElementById('asearchopt11').value = "Contains";
        document.forms.frmSearch.value11.value = "";
		document.forms.frmSearch.value10011.value = "";
	}
	else if(frm.propertytype.value == "commercial")
	{
        document.forms.frmSearch.a.value = "advsearch";
		
		document.getElementById('asearchopt4').value = "Contains";
        document.forms.frmSearch.value4.value = "";
		document.forms.frmSearch.value10004.value = "";
		
		document.getElementById('asearchopt5').value = "Contains";
        document.forms.frmSearch.value5.value = "";
		document.forms.frmSearch.value10005.value = "";
         
		document.getElementById('asearchopt6').value = "Contains";
        document.forms.frmSearch.value6.value = "";
		document.forms.frmSearch.value10006.value = "";
		
		document.getElementById('asearchopt7').value = "Contains";
        document.forms.frmSearch.value7.value = "";
		document.forms.frmSearch.value10007.value = "";
        
        document.getElementById('asearchopt8').value = "Contains";
        document.forms.frmSearch.value8.value = "";
		document.forms.frmSearch.value10008.value = "";
		
		document.getElementById('asearchopt11').value = "Contains";
        document.forms.frmSearch.value11.value = "";
		document.forms.frmSearch.value10011.value = "";
	}
   
	document.forms.frmSearch.submit();
}

var isTransformedForm = [];
var regFormOptionsPriceMinText = ['No Minimum','$50,000','$100,000','$150,000','$200,000','$300,000','$400,000','$500,000','$600,000','$700,000','$800,000','$900,000','$1,000,000'];
var regFormOptionsPriceMinValue = ['0','50000','100000','150000','200000','300000','400000','500000','600000','700000','800000','900000','$1000000'];
var regFormOptionsPriceMaxText = ['No Maximum','$50,000','$100,000','$150,000','$200,000','$300,000','$400,000','$500,000','$600,000','$700,000','$800,000','$900,000','$1,000,000'];
var regFormOptionsPriceMaxValue = ['500000000','50000','100000','150000','200000','300000','400000','500000','600000','700000','800000','900000','$1000000'];

var regFormOptionsBedMinText = ['No Minimum','1','2','3','4','5'];
var regFormOptionsBedMinValue = ['0','1','2','3','4','5'];
var regFormOptionsBedMaxText = ['No Maximum','1','2','3','4','5'];
var regFormOptionsBedMaxValue = ['500000000','1','2','3','4','5'];

var regFormOptionsBathMinText = ['No Minimum','1','2','3','4','5'];
var regFormOptionsBathMinValue = ['0','1','2','3','4','5'];
var regFormOptionsBathMaxText = ['No Maximum','1','2','3','4','5'];
var regFormOptionsBathMaxValue = ['500000000','1','2','3','4','5'];

//to transform search form with appropriate values
function tranformForm(frm)
{
	if(frm.propertytype.value == "rentals")
	{
		frm.pricemin.options.length = 0;
		frm.pricemin.options[0]=new Option("No Minimum", "0", true, false);
		frm.pricemin.options[1]=new Option("$500", "500", false, false);
		frm.pricemin.options[2]=new Option("$1,000", "1000", false, false);
		frm.pricemin.options[3]=new Option("$1,500", "1500", false, false);
		frm.pricemin.options[4]=new Option("$2,000", "2000", false, false);
		frm.pricemin.options[5]=new Option("$2,500", "2500", false, false);
		frm.pricemin.options[6]=new Option("$3,000", "3000", false, false);
		frm.pricemin.options[7]=new Option("$3,500", "3500", false, false);
		frm.pricemin.options[8]=new Option("$4,000", "4000", false, false);
		frm.pricemin.options[9]=new Option("$4,500", "4500", false, false);
		frm.pricemin.options[10]=new Option("$5,000", "5000", false, false);
		
		frm.pricemax.options.length = 0;
		frm.pricemax.options[0]=new Option("No Maximum", "500000000", true, false);
		frm.pricemax.options[1]=new Option("$500", "500", false, false);
		frm.pricemax.options[2]=new Option("$1,000", "1000", false, false);
		frm.pricemax.options[3]=new Option("$1,500", "1500", false, false);
		frm.pricemax.options[4]=new Option("$2,000", "2000", false, false);
		frm.pricemax.options[5]=new Option("$2,500", "2500", false, false);
		frm.pricemax.options[6]=new Option("$3,000", "3000", false, false);
		frm.pricemax.options[7]=new Option("$3,500", "3500", false, false);
		frm.pricemax.options[8]=new Option("$4,000", "4000", false, false);
		frm.pricemax.options[9]=new Option("$4,500", "4500", false, false);
		frm.pricemax.options[10]=new Option("$5,000", "5000", false, false);
		
		frm.bedmin.disabled = false;
		frm.bedmin.options.length = 0;	
		for(i=0; i < regFormOptionsBedMinText.length; i++)
			frm.bedmin.options[i] = new Option(regFormOptionsBedMinText[i], regFormOptionsBedMinValue[i]);
		
		frm.bedmax.disabled = false;
		frm.bedmax.options.length = 0;
		for(i=0; i < regFormOptionsBedMaxText.length; i++)
			frm.bedmax.options[i] = new Option(regFormOptionsBedMaxText[i], regFormOptionsBedMaxValue[i]);
			
		frm.bathmin.disabled = false;
		frm.bathmin.options.length = 0;		
		for(i=0; i < regFormOptionsBathMinText.length; i++)
			frm.bathmin.options[i] = new Option(regFormOptionsBathMinText[i], regFormOptionsBathMinValue[i]);
		
		frm.bathmax.disabled = false;
		frm.bathmax.options.length = 0;
		for(i=0; i < regFormOptionsBathMaxText.length; i++)
			frm.bathmax.options[i] = new Option(regFormOptionsBathMaxText[i], regFormOptionsBathMaxValue[i]);
	}
	else if(frm.propertytype.value == "commercial")
	{
		frm.pricemin.options.length = 0;
		frm.pricemax.options.length = 0;
		
		for(i=0; i < regFormOptionsPriceMinText.length; i++)
			frm.pricemin.options[i] = new Option(regFormOptionsPriceMinText[i], regFormOptionsPriceMinValue[i]);
			
		for(i=0; i < regFormOptionsPriceMaxText.length; i++)
			frm.pricemax.options[i] = new Option(regFormOptionsPriceMaxText[i], regFormOptionsPriceMaxValue[i]);
		
		frm.bedmin.options.length = 0;
		frm.bedmin.options[0]=new Option(" ", "0", true, false);
		
		frm.bedmax.options.length = 0;
		frm.bedmax.options[0]=new Option(" ", "0", true, false);
		
		frm.bathmin.options.length = 0;
		frm.bathmin.options[0]=new Option(" ", "0", true, false);
		
		frm.bathmax.options.length = 0;
		frm.bathmax.options[0]=new Option(" ", "0", true, false);
	}
	else
	{
		frm.pricemin.options.length = 0;		
		for(i=0; i < regFormOptionsPriceMinText.length; i++)
			frm.pricemin.options[i] = new Option(regFormOptionsPriceMinText[i], regFormOptionsPriceMinValue[i]);
		
		frm.pricemax.options.length = 0;
		for(i=0; i < regFormOptionsPriceMaxText.length; i++)
			frm.pricemax.options[i] = new Option(regFormOptionsPriceMaxText[i], regFormOptionsPriceMaxValue[i]);
		
		frm.bedmin.disabled = false;
		frm.bedmin.options.length = 0;	
		for(i=0; i < regFormOptionsBedMinText.length; i++)
			frm.bedmin.options[i] = new Option(regFormOptionsBedMinText[i], regFormOptionsBedMinValue[i]);
		
		frm.bedmax.disabled = false;
		frm.bedmax.options.length = 0;
		for(i=0; i < regFormOptionsBedMaxText.length; i++)
			frm.bedmax.options[i] = new Option(regFormOptionsBedMaxText[i], regFormOptionsBedMaxValue[i]);
			
		frm.bathmin.disabled = false;
		frm.bathmin.options.length = 0;		
		for(i=0; i < regFormOptionsBathMinText.length; i++)
			frm.bathmin.options[i] = new Option(regFormOptionsBathMinText[i], regFormOptionsBathMinValue[i]);
		
		frm.bathmax.disabled = false;
		frm.bathmax.options.length = 0;
		for(i=0; i < regFormOptionsBathMaxText.length; i++)
			frm.bathmax.options[i] = new Option(regFormOptionsBathMaxText[i], regFormOptionsBathMaxValue[i]);
	}
}

