// JavaScript Document
 
function checkSel0() {
 		
  if ($("name").value.length < 1) {
		alert('Please enter your client name.');
		$("name").focus();
		return false;
  }
		
  if ($("email").value == "") {
    alert( "Please enter your client email address." );
    $("email").focus();
    return false ;
  }
  else if (($("email").value.indexOf(".") < 2) || (!$("email").value.indexOf("@")) || $("email").value.indexOf(";")!=-1) {
    alert('Please enter a valid email address.');
    $("email").focus();
    return false;
  }
		
 
   return true;

}
 
 
function checkSel(needName) {
 	
   if($("name").value == "") {
	  alert( "Please enter your name.");
	  $("name").focus();
	  return false;
  }
   else if ($("email").value == "") {
    alert( "Please enter your email address." );
    $("email").focus();
    return false ;
  }
  else if (($("email").value.indexOf(".") < 2) || (!$("email").value.indexOf("@")) || $("email").value.indexOf(";")!=-1) {
    alert('Please enter a valid email address.');
    $("email").focus();
    return false;
  }

  if ($("password").value.length < 5) {
	  alert('Please create a password of at least 5 characters.');
	  $("password").focus();
	  return false;
  }
  else if ($("password").value != $("pass2").value) {
	alert('Password entries do not match.');
	$("password").focus();
	return false;
  }
  if(needName) {
	  if ($("searchName").value.length < 1) {
		alert('Please enter a name for this search.');
		$("searchName").focus();
		return false;
	  }
  }
  bigName = $("name").value;
  bigEmail = $("email").value;
  bigPhone = $("phone").value;
   return true;

}


function checkSel2(needName) {
 		
  if ($("email").value == "") {
    alert( "Please enter your email address." );
    $("email").focus();
    return false ;
  }
  else if (($("email").value.indexOf(".") < 2) || (!$("email").value.indexOf("@")) || $("email").value.indexOf(";")!=-1) {
    alert('Please enter a valid email address.');
    $("email").focus();
    return false;
  }
		
 
  if ($("password").value.length < 5) {
	  alert('Please enter your password.');
	  $("password").focus();
	  return false;
  }
   
  if(needName) { 
	  if ($("searchName").value.length < 1) {
		alert('Please enter a name for this search.');
		$("searchName").focus();
		return false;
	  }
  }

   bigEmail = $("email").value;
 
   return true;

}


function checkSel3() {
 
  if ($("searchName").value.length < 1) {
    alert('Please enter a name for this search.');
	$("searchName").focus();
	return false;
  }
   return true;

}

function checkSel4() {
    if(document.sel4.name.value == "") {
	  alert( "Please enter your name.");
	  document.sel4.name.focus();
	  return false;
  }
  else if (document.sel4.email.value == "") {
    alert( "Please enter your email address." );
    document.sel4.email.focus();
    return false ;
  }
  else if ((document.sel4.email.value.indexOf(".") < 2) || (!document.sel4.email.value.indexOf("@")) || $("email").value.indexOf(";")!=-1) {
    alert('Please enter a valid email address.');
    document.sel4.email.focus();
    return false;
  }
  else if (document.sel4.adate.value == "") {
	  alert( "Please enter a date for showing.");
	  document.sel4.adate.focus();
	  return false;
  }
     bigName = document.sel4.name.value;
  bigEmail = document.sel4.email.value;
  bigPhone =document.sel4.phone.value;
    return true;

}

function saveFav(mlsnum) {
   	var str='<span style="text-decoration:underline;font-size:12px;font-weight:bold;color:#a00;margin-bottom:10px;cursor:pointer;"><a onclick=showLog(1,'+mlsnum+');>Already have a login?-Sign in</a></span>';
	  str +='<p style="margin:8px;color:#1f1f21;"><b>Create a FREE, no obligation account</b> to save searches, track homes and received daily email of new listings and price changes.        </p>';
	  
 
	  str += '<form name="sel1" onsubmit="return false;" >';
	  str += '<table style="margin:5px">  ';
      str += '<tr><td class="fieldlabel">Name*:</td><td class="td-left1"><input type="text" id="name" name="name" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Phone:</td><td class="td-left1"><input type="text" id="phone" name="phone" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Email*:</td><td class="td-left1"><input type="text" id="email" name="email" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Password*:</td><td class="td-left1"><input type="password" id="password" name="password" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Confirm Password:</td><td class="td-left1"><input type="password" id="pass2" name="pass2" value="" size="20"></td></tr>';
       str += '<tr><td class="fieldlabel">Comments or Questions</td><td><textarea name="comments" id="comments" style="width:95%;height:30px;"></textarea></td></tr> '; 
		str += '<tr><td>&nbsp;</td></tr>';
          str += '<tr><td colspan="2" align="center"><img src=images/signmeup.gif style="cursor:pointer;" onclick=if(checkSel(0))doChange("saveFav",1,' + mlsnum + ');></td></tr>';  
            
		str += '</table>';
		str += '</form>';
 		str += '<div id=spin2><img src=images/spinner.gif></div>';
  		$("landing").innerHTML = str;
		$("name").focus();
}

	
	
function saveSearch(aSearch) {
//first get sql and adv
  	if(bigUser) 
		showName(aSearch);
	else	
 		showForm(aSearch);
	
}

function showName(aSearch) {
   	var str;
	if(aSearch) {
			str='<p style="margin:8px;margin-top:12px;font-size:12px;font-weight:bold;color:#aa0000"><b>Please enter a name for your search.</b>        </p>';
	} else {
		  	str='<span style="text-decoration:underline;font-size:12px;font-weight:bold;color:#a00;margin-bottom:10px;cursor:pointer;"><a onclick=clientForm();>These listings are for a new client</a></span>';
			str+='<p style="margin:8px;margin-top:12px;font-size:12px;font-weight:bold;color:#aa0000"><b>Please enter a name for your listings.</b>        </p>';
	}
	  str += '<form onsubmit="return false;" >';
	  str += '<table style="margin:5px">  ';
 	  if(aSearch) {
       		str += '<tr><td class="fieldlabel">Search Name*:</td><td class="td-left1"><input type="text" id="searchName" name="searchName" value="' + bigSearch + '" ></td></tr>';
	  } else {
			str += '<tr><td class="fieldlabel">Listings Name*:</td><td class="td-left1"><input type="text" id="searchName" name="searchName" value="" ></td></tr>';
	  }
       str += '<tr><td class="fieldlabel" colspan="2">Email me results of this search:&nbsp;&nbsp;<input type="checkbox" id="sendResults" name="sendResults" value="sendResults" checked="checked"></td></tr>';
       str += '<tr><td class="fieldlabel" colspan="2">Email daily matching new listings & price changes:&nbsp;&nbsp;<input type="checkbox" id="sendEmails" name="sendEmails" value="sendEmails" checked="checked"></td></tr>';
 	   
 		str += '<tr><td>&nbsp;</td></tr>';
		if(aSearch) {
          str += '<tr><td colspan="2" align="center"><img src=images/savesearch.gif onclick=if(checkSel3())doChange("saveSearch",0); style="cursor:pointer;"></td></tr>'; 
		} else {
          str += '<tr><td colspan="2" align="center"><img src=images/emaillistings.gif onclick=if(checkSel3())doChange("saveSearch",0); style="cursor:pointer;"></td></tr>';  
		}
		str += '</table>';
		str += '</form>';
 		str += '<div id=spin2><img src=images/spinner.gif></div>';
 		
		
  		$("landing").innerHTML = str;
		$("searchName").focus();
}

function showForm(aSearch) {
	//doChange("email",1);
   	var str='<span style="text-decoration:underline;font-size:12px;font-weight:bold;color:#a00;margin-bottom:10px;cursor:pointer;"><a onclick=showLog(2,0);>Already have a login?-Sign in</a></span>';
	  str +='<p style="margin:8px;color:#1f1f21;"><b>Create a FREE, no obligation account</b> to save searches, track homes and received daily email of new listings and price changes.        </p>';

	  str += '<form onsubmit="return false;" >';
	  str += '<table style="margin:5px">  ';
      str += '<tr><td class="fieldlabel">Name*:</td><td class="td-left1"><input type="text" id="name" name="name" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Phone:</td><td class="td-left1"><input type="text" id="phone" name="phone" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Email*:</td><td class="td-left1"><input type="text" id="email" name="email" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Password*:</td><td class="td-left1"><input type="password" id="password" name="password" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Confirm Password:</td><td class="td-left1"><input type="password" id="pass2" name="pass2" value="" size="20"></td></tr>';
	  if(aSearch) {
		    str += '<tr><td class="fieldlabel">Search Name*:</td><td class="td-left1"><input type="text" id="searchName" name="searchName" value="" ></td></tr>';
	  } else {
      		str += '<tr><td class="fieldlabel">Listings Name*:</td><td class="td-left1"><input type="text" id="searchName" name="searchName" value="" ></td></tr>';
	  }
		str += '<tr><td class="fieldlabel" colspan="2">Email me results of this search:&nbsp;&nbsp;<input type="checkbox" id="sendResults" name="sendResults" value="sendResults" checked="checked"></td></tr>';
       str += '<tr><td class="fieldlabel" colspan="2">Email daily matching new listings & price changes:&nbsp;&nbsp;<input type="checkbox" id="sendEmails" name="sendEmails" value="sendEmails" checked="checked"></td></tr>';
 	  
      str += '<tr><td class="fieldlabel">Comments or Questions</td><td><textarea name="comments" id="comments" style="width:95%;height:40px;"></textarea></td></tr> '; 
		str += '<tr><td>&nbsp;</td></tr>';
		/*
        str += '<tr><td colspan=2><font size="-2">* Denotes required field</font></td></tr>';
		str += '<tr><td>&nbsp;</td></tr>';
		*/
         str += '<tr><td colspan="2" align="center"><img src=images/signmeup.gif style="cursor:pointer;" onclick=if(checkSel(1))doChange("saveSearch",1);></td></tr>';  
 //		str += '<tr><td>&nbsp;</td></tr>';
           
		str += '</table>';
		str += '</form>';
 		str += '<div id=spin2><img src=images/spinner.gif></div>';
		
   		$("landing").innerHTML = str;
		$("name").focus();
}

function showLog(fav,mlsnum) {
	var str;
 	if(fav==1) {
			str	= '<p style="margin:8px;margin-top:12px;font-weight:bold;font-size:12px;color:#aa0000">Please log in to save favorites.</p>';
	} else if (fav==2){		
			str	= '<p style="margin:8px;margin-top:12px;font-weight:bold;font-size:12px;color:#aa0000">Please log in to save searches.</p>';
	} else if (fav==3){
			str	= '<p style="margin:8px;margin-top:12px;font-weight:bold;font-size:12px;color:#aa0000">Please log in to automate emails.</p>';
	} else {
			str	= '<p style="margin:8px;margin-top:12px;font-weight:bold;font-size:12px;color:#aa0000">Dream Realty Sign In</p>';
	}
	str += '<form onsubmit="return false;">';		
	str += '<table style="margin:5px">  ';
    str += '<tr><td class="fieldlabel">Email:</td><td class="td-left1"><input type="text" id="email" name="email" value="" size="20"></td></tr>';
    str += '<tr><td class="fieldlabel">Password:</td><td class="td-left1"><input type="password" id="password" name="password" value="" size="20"></td></tr>';
	if(fav > 1) {  
      	str += '<tr><td class="fieldlabel">Search Name:</td><td class="td-left1"><input type="text" id="searchName" name="searchName" value="" ></td></tr>';
       	str += '<tr><td class="fieldlabel" colspan="2">Email me results of this search:&nbsp;&nbsp;<input type="checkbox" id="sendResults" name="sendResults" value="sendResults" checked="checked"></td></tr>';
       	str += '<tr><td class="fieldlabel" colspan="2">Email daily matching new listings & price changes:&nbsp;&nbsp;<input type="checkbox" id="sendEmails" name="sendEmails" value="sendEmails" checked="checked"></td></tr>';
	}
 	str += '<tr><td>&nbsp;</td></tr>';
	if(fav==1) {
	    str += '<tr><td colspan="2" align="center"><img src=images/signmein.gif style="cursor:pointer;" onclick=if(checkSel2(0))doChange("saveFav",2,'+mlsnum+');></td></tr>';  
 	} else if(fav > 1){
    	str += '<tr><td colspan="2" align="center"><img src=images/signmein.gif style="cursor:pointer;" onclick=if(checkSel2(1))doChange("saveSearch",2);></td></tr>';  
	} else {
		str += '<tr><td colspan="2" align="center"><img src=images/signmein.gif style="cursor:pointer;" onclick=if(checkSel2(0))doChange("saveFav",0,'+mlsnum+');></td></tr>';  
	}
	str += '</form>';
 	str += '<tr><td>&nbsp;</td></tr>';
	
	str += '<tr><td colspan="2" class="fieldlabel"><a href=mailto:cwd@dreamrealty.com?subject=forgot-password>Forgot password?</a></td></tr>'
	str += '</table>';
 	str += '<div id=spin2><img src=images/spinner.gif></div>';
	
  	$("landing").innerHTML = str;
 	$("email").focus();
 	

}

function clientForm() {
	//doChange("email",1);
 	var str ='<p style="margin:8px;color:#1f1f21;"><b>Create an account for your client.</p>';

	  str += '<form onsubmit="return false;" >';
	  str += '<table style="margin:5px">  ';
      str += '<tr><td class="fieldlabel">Client Name*:</td><td class="td-left1"><input type="text" id="name" name="name" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Phone:</td><td class="td-left1"><input type="text" id="phone" name="phone" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Email*:</td><td class="td-left1"><input type="text" id="email" name="email" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Password*:</td><td class="td-left1"><input type="password" id="password" name="password" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Confirm Password:</td><td class="td-left1"><input type="password" id="pass2" name="pass2" value="" size="20"></td></tr>';
 	  str += '<tr><td class="fieldlabel">Search Name*:</td><td class="td-left1"><input type="text" id="searchName" name="searchName" value="" ></td></tr>';
	  str += '<tr><td class="fieldlabel" colspan="2">Email me results of this search:&nbsp;&nbsp;<input type="checkbox" id="sendResults" name="sendResults" value="sendResults" checked="checked"></td></tr>';
       str += '<tr><td class="fieldlabel" colspan="2">Email daily matching new listings & price changes:&nbsp;&nbsp;<input type="checkbox" id="sendEmails" name="sendEmails" value="sendEmails" checked="checked"></td></tr>';
 	  
      str += '<tr><td class="fieldlabel">Intro comments:</td><td><textarea name="comments" id="comments" style="width:95%;height:40px;"></textarea></td></tr> '; 
		str += '<tr><td>&nbsp;</td></tr>';
		/*
        str += '<tr><td colspan=2><font size="-2">* Denotes required field</font></td></tr>';
		str += '<tr><td>&nbsp;</td></tr>';
		*/
         str += '<tr><td colspan="2" align="center"><img src=images/signclientup.gif style="cursor:pointer;" onclick=if(checkSel(1))doChange("saveSearch",1);></td></tr>';  
 		str += '<tr><td>&nbsp;</td></tr>';
         str += '<tr><td colspan="2" align="center"><img src=images/listingsonly.gif style="cursor:pointer;" onclick=if(checkSel0())doChange("saveSearch",3);></td></tr>';  
		
           
		str += '</table>';
		str += '</form>';
 		str += '<div id=spin2><img src=images/spinner.gif></div>';
		
   		$("landing").innerHTML = str;
		$("name").focus();
}

function goSeeIt(mlsnum) {
	
 	
  	var str='<p style="margin:8px; margin-top:12px; color:#aa0000;font-size:12px">Please fill out the enclosed form.  You will be contacted quickly to set up the tour.  Usually within 2 hours.        </p>';

 		str += '<form name="sel4"> ';
 		str += '        	<table> ';
		str += '      		<tr><td class="fieldlabel" width="40%">Name:</td><td class="td-left1"><input type="text" id="name" name="name" value=' + bigName +'></td></tr> ';
		str += '<tr><td class="fieldlabel" width="40%">Phone:</td><td class="td-left1"><input type="text" id="phone" name="phone" value=' +bigPhone +'></td></tr> ';
		str += '      		<tr><td class="fieldlabel" width="40%">Email:</td><td class="td-left1"><input type="text" id="email" name="email" value=' + bigEmail + '></td></tr> ';
		str += '	  		<tr><td class="fieldlabel" colspan="2">Contact Me Via:&nbsp;&nbsp;<input type="radio" name="via" value="Email"  />Email <input type="radio" name="via" value="Phone" />Phone</td></tr> ';
 		str += '            <tr><td class="fieldlabel">Date:</td><td><input name="adate" id="adate" style="width:80px;" ></td></tr> ';
		str += '<tr><td colspan=2 align=center><select name="moving" id="moving" style="margin-left:10px;"> ';
		str += '<option value="0" >Morning</option> 			 ';
		str += '<option value="1" >Afternoon</option> 			 ';
		str += '<option value="2" >Evening</option> 			 ';
		str += '</select>         ';
		str += '			</td></tr> ';
		str += '            <tr><td colspan=2 class="fieldlabel">Time frame for buying:</td></tr> ';
		str += '            <tr><td colspan=2><input type="radio" name="timeframe" id="timeframe" value="3months" />Within 3 months</td></tr>';
		str += '            <tr><td colspan=2><input type="radio" name="timeframe" id="timeframe" value="1year" />Within 1 year </td></tr>';
		str += '            <tr><td colspan=2><input type="radio" name="timeframe" id="timeframe" value="not-sure" />Not sure / Just looking</td></tr> ';
       str += '<tr><td class="fieldlabel">Comments or Questions</td><td><textarea name="comments" id="comments" style="width:95%;height:40px;"></textarea></td></tr> '; 
		str += '            <input type="hidden" id="mlsnum" name="mlsnum" value=' + mlsnum + ' /> ';
 		str += '<tr><td>&nbsp;</td></tr>';		
        str += '<tr><td colspan="2" align="center"><img src=images/scheduleme.gif style="cursor:pointer;" onclick=if(checkSel4())doChange("schedule",0,' + mlsnum + ');></td></tr>';  		
		str += '</form> ';
 		str += '<div id=spin2><img src=images/spinner.gif></div>';
  		
		$("landing").innerHTML = str;
		$("name").focus();
}


function moreCriteria() {
		$("criteria").innerHTML = "<img src=images/spinner.gif></img>";
 		$("criteria").style.display = "block";
		$("criteria").style.height = "300px";
  	  str = '<table style="margin:5px">';
str += '                 <tr><td class="fieldlabel">Within:</td><td>';
str += '                <select name="within1" id="within1" >';
str += '                    	<option value="100" selected >Any distance</option>';
str += '                        <option value="1" >1 mile</option>                        ';
 str += '                         <option value="2" >2 miles</option>                        ';
str += '                        <option value="5">5 miles</option>';
str += '                        <option value="10" >10 miles</option>';
str += '                        <option value="25" >25 miles</option>';
str += '                        <option value="50" >50 miles</option>';
str += '                </select></td></tr>';	  
	  str += '<tr><td class="fieldlabel">Min price:</td><td>';
      str += '<select  name="minprice1" id="minprice1" class="forminput">';
      str += '<option value="0">No minimum</option> ';
      str += '<option value="100000">$100,000</option>';
      str += '<option value="125000">$125,000</option>';
      str += '<option value="150000">$150,000</option>';
      str += '<option value="175000">$175,000</option>';
      str += '<option value="200000">$200,000</option>';
      str += '<option value="225000">$225,000</option>';
      str += '<option value="250000">$250,000</option>';
      str += '<option value="275000">$275,000</option>';
      str += '<option value="300000">$300,000</option>';
      str += '<option value="325000">$325,000</option>';
      str += '<option value="350000">$350,000</option>';
      str += '<option value="400000">$400,000</option>';
      str += '<option value="450000">$450,000</option>';
      str += '<option value="500000">$500,000</option>';
      str += '<option value="550000">$550,000</option>';
      str += '<option value="600000">$600,000</option>';
      str += '<option value="650000">$650,000</option>';
      str += '<option value="700000">$700,000</option>';
      str += '<option value="750000">$750,000</option>';
      str += '<option value="800000">$800,000</option>';
      str += '<option value="850000">$850,000</option>';
      str += '<option value="900000">$900,000</option>';
      str += '<option value="950000">$950,000</option>';
      str += '<option value="1000000">$1,000,000</option>';
      str += '<option value="1500000">$1,500,000</option>';
      str += '<option value="2000000">$2,000,000</option>';
      str += '<option value="3000000">$3,000,000</option>';
      str += '<option value="3500000">$3,500,000</option>';
      str += '<option value="4000000">$4,000,000</option>';
      str += '</select></td></tr>';
	  str += '<tr><td class="fieldlabel">Max price:</td><td>';
      str += '<select  name="maxprice1" id="maxprice1" class="forminput">';
      str += '<option value="0">No maximum</option> ';
      str += '<option value="100000">$100,000</option>';
      str += '<option value="125000">$125,000</option>';
      str += '<option value="150000">$150,000</option>';
      str += '<option value="175000">$175,000</option>';
      str += '<option value="200000">$200,000</option>';
      str += '<option value="225000">$225,000</option>';
      str += '<option value="250000">$250,000</option>';
      str += '<option value="275000">$275,000</option>';
      str += '<option value="300000">$300,000</option>';
      str += '<option value="325000">$325,000</option>';
      str += '<option value="350000">$350,000</option>';
      str += '<option value="400000">$400,000</option>';
      str += '<option value="450000">$450,000</option>';
      str += '<option value="500000">$500,000</option>';
      str += '<option value="550000">$550,000</option>';
      str += '<option value="600000">$600,000</option>';
      str += '<option value="650000">$650,000</option>';
      str += '<option value="700000">$700,000</option>';
      str += '<option value="750000">$750,000</option>';
      str += '<option value="800000">$800,000</option>';
      str += '<option value="850000">$850,000</option>';
      str += '<option value="900000">$900,000</option>';
      str += '<option value="950000">$950,000</option>';
      str += '<option value="1000000">$1,000,000</option>';
      str += '<option value="1500000">$1,500,000</option>';
      str += '<option value="2000000">$2,000,000</option>';
      str += '<option value="3000000">$3,000,000</option>';
      str += '<option value="3500000">$3,500,000</option>';
      str += '<option value="4000000">$4,000,000</option>';
      str += '</select></td></tr>';
str += '	<tr>';
str += '		<td class="fieldlabel">Bedrooms:</td>';
str += '		<td>';
str += '			<select name="beds1" id="beds1" class="forminput">';
str += '			<option value="">Any number</option>';
str += '			<option value="1">At least 1</option>';
str += '			<option value="2">At least 2</option>';
str += '			<option value="3">At least 3</option>';
str += '			<option value="4">At least 4</option>';
str += '			<option value="5">At least 5</option>';
str += '			</select>';
str += '		</td>';
str += '	</tr>';
str += '	<tr>';
str += '		<td class="fieldlabel">Bathrooms:</td>';
str += '		<td>';
str += '			<select name="baths1" id="baths1" class="forminput">';
str += '			<option value="">Any number</option>';
str += '			<option value="1">At least 1</option>';
str += '			<option value="2">At least 2</option>';
str += '			<option value="3">At least 3</option>';
str += '			<option value="4">At least 4</option>';
str += '			<option value="5">At least 5</option>';
str += '			</select>';
str += '		</td>';
str += '	</tr>';
str += '    <tr>';
str += '    	<td class="fieldlabel">Square Footage:</td>';
str += '        <td>';
str += '					<select name="square1" id="square1">';
str += '                                    <option value="0" 0>Any</option>';
str += '                                    <option value="1000">1000+</option>';
str += '                                    <option value="2000">2000+</option>';
str += '                                    <option value="3000">3000+</option>';
str += '                                    <option value="4000">4000+</option>';
str += '                                    <option value="5000">5000+</option>';
str += '     				</select>';
str += '    	</td>';
str += '     </tr>   ';
str += '     <tr>';
str += '     	<td class="fieldlabel">Lot Size:</td>';
str += '        <td>';
str += '               	<select name="lotsize1" id="lotsize1">';
str += '                   					<option value="0" >Any Size</option>  ';
str += '                    				<option value="98" >1/4+ Acres</option>                                   ';
str += '                    				<option value="99"  >1/2+ Acres</option>    ';
str += '                    				<option value="1" >1+ Acres</option>    ';
str += '                    				<option value="2" >2+ Acres</option>    ';
str += '                    				<option value="3" >5+ Acres</option>    ';
str += '                    				<option value="4" >10+ Acres</option>    ';
str += '                    				<option value="5" >20+ Acres</option> ';
str += '                     </select>                  ';
str += '      	</td>';
str += '     </tr>   ';
str += '     <tr>';
str += '     	<td class="fieldlabel">Year Built:</td>';
str += '        <td>';
str += '					<select name="year1" id="year1">';
str += '                                    <option value="0" >Any</option>';
str += '                                    <option value="1960" >1960+</option>                                    ';
str += '                                    <option value="1970" >1970+</option>';
str += '                                    <option value="1980" >1980+</option>';
str += '                                    <option value="1990" >1990+</option>';
str += '                                    <option value="2000" >2000+</option>';
str += '                                    <option value="2005" >2005+</option>';
str += '        			</select>';
str += '     	</td>';
str += '     </tr>   ';
str += '	<tr>';
str += '    	<td class="fieldlabel">Waterfront:</td>';
str += '        <td>';
str += '        	<select name="waterfront1" id="waterfront1" class="forminput" >';
str += '			<option value="0">Not Needed</option>';
str += '			<option value="1">Gulf</option>';
str += '			<option value="2">Intracoastal</option>';
str += '            <option value="3">Gulf or Intercoastal</option>';
str += '            <option value="4">Any Waterfront</option>';
str += '			</select>';
str += '        </td>';
str += '     </tr>   ';
str += '     <tr>';
str += '     	<td class="fieldlabel">Pool:</td>';
str += '        <td>';
str += '        	<select name="pool1" id="pool1">';
str += '                                    <option value="0" >Not Needed</option>';
str += '                                    <option value="1" >Yes</option>';
str += '                                    <option value="2" >No</option>';
str += '     		</select>';
str += '    	</td>';
str += '     </tr>   ';
str += '     <tr>';
str += '     	<td class="fieldlabel">Foreclosure:</td>';
str += '        <td>';
str += '			<select name="foreclosure1" id="foreclosure1">            ';
str += '            <option value="0" >Not Needed</option>';
str += '            <option value="1">Bank Owned / REO</option>            ';
str += '            <option value="2">Short Sale </option>';
str += '            <option value="3">Any Distressed</option>            ';
str += '            </select>';
str += '        </td>';
str += '     </tr>';
     	str += '<tr><td class="fieldlabel">Comments or Questions</td><td><textarea name="comments" id="comments" style="width:95%;height:30px;"></textarea></td></tr> '; 
		str += '<tr><td>&nbsp;</td></tr>';
	  
	  str += '</table>';				
 	$("criteria").innerHTML = str;
	str = '<a onclick="lessCriteria()" style="cursor:pointer;color:#a00;text-decoration:underline;">Less search criteria...</a>';
	$("yaba").innerHTML= str;
 	$("lander").style.height = "900px";
	$("landing").style.height = "900px";
   
}


function lessCriteria() {
	$("criteria").style.display = "none";
	str = '<a onclick="moreCriteria()" style="cursor:pointer;color:#a00;text-decoration:underline;">More search criteria...</a>';
	$("yaba").innerHTML= str;
 	$("lander").style.height = "600px";
	$("landing").style.height = "600px";
	$("lander").scrollTop = 0;
	$("landing").scrollTop = 0;
 	
}

function signMeUp(temper) {
//	doChange("email",3);
 	spin2On();
	if(temper) {
		frontSign = true; 
		codeAddress(0); 		
	} else frontSign = false;
  	
    	bigSql='';  //drSign will treat this as just a signup without saved search or favorite
   	var str='<span style="text-decoration:underline;font-size:12px;font-weight:bold;color:#a00;margin-bottom:10px;cursor:pointer;"><a onclick=showLog(0,0);>Already have a login?-Sign in</a></span>';
	  str +='<p style="margin:8px;color:#1f1f21;"><b>Create a FREE, no obligation account.</b> </p>';
  	  str += "<ul>";
 	  str += "<li>Gain access to all listings straight from the MLS. <br /><a onclick='window.open(\"http://www.clearwaterdreaming.com/mls_detail.php?lid=7425739&active=0\",\"Window1\",\"menubar=no,width=1000,height=600,toolbar=no,scrollbars=yes\");' style='text-decoration:underline;cursor:pointer;color:#a00;font-weight:500;'>(view example)</a></li>";
 	  str += "<li>Receive daily email notifications. <br /> <a onclick='window.open(\"sample.php\",\"Window2\",\"menubar=no,width=630,height=500,toolbar=no,scrollbars=yes\");' style='text-decoration:underline;cursor:pointer;color:#a00;font-weight:500;'>(view example)</a></li>"; 
  	  str += "<li>Save your favorites homes.</li>";
 	  str += "<li>Find your dream home with no pressure and <font color='#aa0000'><b>NO SPAM.</b></font></li>"; 
	  str += "</ul> ";
	  str += '<form name="sel1" onsubmit="return false;" >';
	  str += '<table style="margin:5px">  ';
      str += '<tr><td class="fieldlabel">Name*:</td><td class="td-left1"><input type="text" id="name" name="name" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Phone:</td><td class="td-left1"><input type="text" id="phone" name="phone" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Email*:</td><td class="td-left1"><input type="text" id="email" name="email" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Password*:</td><td class="td-left1"><input type="password" id="password" name="password" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Confirm Password:</td><td class="td-left1"><input type="password" id="pass2" name="pass2" value="" size="20"></td></tr>';
      str += '<tr><td class="fieldlabel">Interest City:</td><td class="td-left1"><input type="text" id="searchName" name="searchName" value="' + myCity + '" ></td></tr>';
	  str += '<tr><td class="fieldlabel">Property Type:</td><td><select name="type1" id="type1"><option value="0">Any Type</option>';
	  str += '<option value="SINGL" >Single Family</option>';
      str += '<option value="CONDO">Condo</option>';
      str += '<option value="TOWNH">Townhome</option>';
      str += '<option value="VILLA">Villa</option>';
      str += '</select></td></tr>';
       str += '<tr><td class="fieldlabel" colspan="2">Email daily matching listings:&nbsp;&nbsp;<input type="checkbox" id="sendEmails" name="sendEmails" value="sendEmails" checked="checked"></td></tr></table>';
	  


	    str += '<table width=95%>';
        str += '<tr><td align="center"><img src=images/signmeup.gif style="cursor:pointer"; onclick=if(checkSel(0))doChange("saveFav",5);></td></tr>';  
 //		str += '<tr><td>&nbsp;</td></tr>';
           
	  str += '<tr><td class="fieldlabel" colspan=2 align="center"><span id="yaba"><a onclick="moreCriteria()" style="cursor:pointer;color:#a00;text-decoration:underline;">More search criteria...</a></span></td></tr>';	  
		str += '</table>';

		str += '</form>';
 	  str += '<div id="criteria"></div>';
 		
 		str += '<div id=spin2><img src=images/spinner.gif></div>';
 		if(isIE) fudge = 55; else fudge = 25;
   		$("landing").innerHTML = str;
		signLand = $("landing").offsetHeight + fudge;
   		$("lander").style.height = "600px";
 		$("landing").style.height = "600px";
  		spin2Off();
 // 		$("name").focus();
 }

		
 
 

function spinOn() {
	document.getElementById("spinner").style.display = "block";
	document.getElementById("leftside").style.opacity = .5;
	document.getElementById("search_suggestions_menu").style.display = "none";
	
}

function spinOff() {
	document.getElementById("spinner").style.display = "none";
	document.getElementById("leftside").style.opacity = 1;
	
}

function spin3On() {
  	$("landing").innerHTML = "<img src=images/spinner.gif></img>";
 	document.getElementById("landing").style.opacity = .5;
 }

function spin3Off() {
	document.getElementById("landing").style.opacity = 1;
}
	
function spin2On() {
	document.getElementById("spin2").style.display = "block";
	document.getElementById("landing").style.opacity = .5;
}

function spin2Off() {
	document.getElementById("spin2").style.display = "none";
	document.getElementById("landing").style.opacity = 1;
	
}
 
	function showImg(img) {
		document.getElementById("main_pic").innerHTML = "<img src=" + img + "></img>";
		
	} 


function addCommas(nStr,doll)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	if(doll)
		 	return "$" + x1 + x2;
	else
 		return x1 + x2;
}
 
 
  
//map.fitBounds(markerBounds);


function byFloat(i,dir) {
return function(a,b){a = parseFloat(a[i]);b = parseFloat(b[i]);return a == b ? 0 : (a < b ? -1*dir : dir)}
}
function byNum(i,dir) {
return function(a,b){a = parseInt(a[i]);b = parseInt(b[i]);return a == b ? 0 : (a < b ? -1*dir : dir)}
}
function by(i,dir) {
return function(a,b){a = a[i];b = b[i];return a.toLowerCase() == b.toLowerCase() ? 0 : (a.toLowerCase() < b.toLowerCase() ? -1*dir : dir)}
}
 
function sortSidebar(criterion, up_down, by_function, block){
  var div;
  if (block && block.nodeType == 1) div = block;
  else
    div = document.getElementById(block)         //  find the sidebar div
    || document.getElementById("sidebar")
   var first = div.firstChild;
   var buttonArray = Array();
 //  alert("first = " + first.sortCriteria);
     while (first.nextSibling){                     //  make an array of buttons
    first = first.nextSibling;
	
      buttonArray.push(first);
 	  
  }
  
  var crit = criterion || 0;                     // parameters
  var ud = up_down || 1;
  var sortInt = by_function
    || function(a,b){a = parseInt(a.sortCriteria[crit]);b = parseInt(b.sortCriteria[crit]);return a > b ? 1 : -1 };
  var sortFunction = by_function  || function(a,b){return a.sortCriteria[crit] > b.sortCriteria[crit] ? 1 : -1 };
  var sortDec = by_function
    || function(a,b){a = parseFloat(a.sortCriteria[crit]);b = parseFloat(b.sortCriteria[crit]);return a > b ? 1 : -1 };
  
 
  if(!crit) {
	  	if(addressAsc) {
			addressAsc=false;
			ud = -1;
		} else {
			addressAsc=true;
			ud = 1;
  		}	  
  		buttonArray.sort(sortFunction);                // sort
  } else if(crit==1) {
	  	if(priceAsc) {
			priceAsc=false;
			ud = -1;
		} else {
			priceAsc=true;
			ud = 1;
  		}
  		buttonArray.sort(sortInt);                // sort
   } else if(crit==2) {
	  	if(bedAsc) {
			bedAsc=false;
			ud = -1;
		} else {
			bedAsc=true;
			ud = 1;
  		}
  		buttonArray.sort(sortInt);                // sort
    } else if(crit==3) {
	  	if(bathAsc) {
			bathAsc=false;
			ud = -1;
		} else {
			bathAsc=true;
			ud = 1;
  		}
  		buttonArray.sort(sortInt);                // sort
     } else if(crit==4) {
	  	if(yearAsc) {
			yearAsc=false;
			ud = -1;
		} else {
			yearAsc=true;
			ud = 1;
  		}
  		buttonArray.sort(sortInt);                // sort
     } else if(crit==5) {
	  	if(sqAsc) {
			sqAsc=false;
			ud = -1;
		} else {
			sqAsc=true;
			ud = 1;
  		}
  		buttonArray.sort(sortInt);                // sort
     } else if(crit==6) {
	  	if(sqftAsc) {
			sqftAsc=false;
			ud = -1;
		} else {
			sqftAsc=true;
			ud = 1;
  		}
  		buttonArray.sort(sortInt);                // sort
     } else if(crit==7) {
	  	if(daysAsc) {
			daysAsc=false;
			ud = -1;
		} else {
			daysAsc=true;
			ud = 1;
  		}
  		buttonArray.sort(sortInt);                // sort
     } else if(crit==8) {
	  	if(distAsc) {
			distAsc=false;
			ud = -1;
		} else {
			distAsc=true;
			ud = 1;
  		}
  		buttonArray.sort(sortDec);                // sort
   	}
  
  
 // buttonArray.sort();
  if (ud && ud < 0) buttonArray.reverse();
 
 
  for(var ii=0; ii<buttonArray.length; ii++){    // rearrange buttons
    div.appendChild(buttonArray[ii]);
  }
}

function showLand() {
	if(bigUser.length<2  && firstSearch) {
//		str = "<EMBED SRC='help.wav' autostart=true hidden=true>";
//		str = "<img src=images/beby3.png style='margin-top:10px;margin-left:10px; width:240px;'>";
//		str = "<img src=images/beby-help.png style='margin-top:10px;margin-left:10px; >&nbsp;<h1>Help</h1>";
		str = "<h1>beBY&trade; Help</h1>";
		str += "<p>You can enter an address, point of interest, city, or zipcode to be by.  <b>beBY&trade;</b> will create a circle and display all properties that meet your criteria. </p>  <p>The <b>WITHIN</b> selection will determine how big the circle is.  (see examples below)</>";
 		$("landing").innerHTML = str;
 	}
}
 
function showDR() {
	$("dropDown").style.display = "block";
	str = "<a onclick=if(bigUser){doChange('userSearches',bigUser)}else{signMeUp(false)}>Searches</a><br><a onclick=if(bigUser){doChange('favorites',bigUser)}else{signMeUp(false)}>Favorites</a><br><a onclick=if(bigUser){doChange('profile',bigUser)}else{signMeUp(false)}>Profile</a>";
   	$("dropDown").innerHTML = str;
	$("dropDown").focus();
}

function hideDR() {
	$("dropDown").style.display = "none";
}



function getWithin(str,poster) {
	len = poster.length;
	a = poster.indexOf(str);
	if(a==-1) return 0;
 	a = a + str.length + 3;
 	sub1 = poster.substring(a);
   	start = sub1.indexOf('"');
 	sub2 = sub1.substring(start+1);
	end = sub2.indexOf('"');
	r = sub2.substr(0,end);
 	if(str=="beby")
		return sub2.substr(0,end).replace(/%20/g," ");		
 	else if(r.indexOf(';') >= 0)
		return 0;
	else
		return sub2.substr(0,end);
							   
}
	
function getW(str,poster) {
	len = poster.length;
	a = poster.indexOf(str);
	if(a==-1) return "";
 	a = a + str.length + 3;
 	sub1 = poster.substring(a);
   	start = sub1.indexOf('"');
 	sub2 = sub1.substring(start+1);
	end = sub2.indexOf('"');
	r = sub2.substr(0,end);
 	if(str=="beby")
		return sub2.substr(0,end).replace(/%20/g," ");		
 	else if(r.indexOf(';') >= 0)
		return 0;
	else
		return sub2.substr(0,end);
							   
}

function disectPoster(poster, sName) {
	bigSearch = sName.replace("%20"," ");
	$("beby").value = getWithin("zipcode",poster);
	if($("beby").value.length < 2)
    		$("beby").value = getWithin("beby",poster);
	$("within").value = getWithin("within",poster);
	$("type").value  = getWithin("type",poster);
	$("beds").value = getWithin("beds",poster);
	$("baths").value = getWithin("baths",poster);
	$("minprice").value = getWithin("minprice",poster);	
	$("maxprice").value = getWithin("maxprice",poster);
	$("square").value = getWithin("square",poster);
	$("year").value = getWithin("year",poster);
	$("days").value = getWithin("days",poster);
	$("foreclosure").value = getWithin("foreclosure",poster);
	$("waterfront").value = getWithin("waterfront",poster);
	$("lotsize").value = getWithin("lotsize",poster);
	$("pool").value = getWithin("pool",poster);
	
	doChange("grid");
 }
 
function checkDeletion(id,fav) {
  if(confirm("Confirm deletion.")) {
	  if(fav)
			doChange('deleteFavs',id)  
	  else		  
			doChange('deleteSearches',id)  
 } else return false;
}

function fbs_click() 
{
        u=location.href;
        t=document.title;
        window.open('http://www.facebook.com/sharer.php?u='+encodeURIComponent(u)+'&t='+encodeURIComponent(t),' sharer', 'toolbar=0, status=0, width=626, height=436');
        return false;
}
 
function disableForm() {
	$("beby").disabled = true;
	$("minprice").disabled = true;
	$("maxprice").disabled = true;
	$("within").disabled = true;
	$("beds").disabled = true;
	$("baths").disabled = true;
	$("type").disabled = true;
	$("foreclosure").disabled = true;
	$("pool").disabled = true;
	$("year").disabled = true;
	$("square").disabled = true;
	$("lotsize").disabled = true;
	$("days").disabled = true;
	$("waterfront").disabled = true;
	formDisabled = true;
}


function enableForm() {
	$("beby").disabled = false;
	$("minprice").disabled = false;
	$("maxprice").disabled = false;
	$("within").disabled = false;
	$("beds").disabled = false;
	$("baths").disabled = false;
	$("type").disabled = false;
	$("foreclosure").disabled = false;
	$("pool").disabled = false;
	$("year").disabled = false;
	$("square").disabled = false;
	$("lotsize").disabled = false;
	$("days").disabled = false;
	$("waterfront").disabled = false;
	formDisabled = false;
}



function showLoader() {
	$("results").style.display = "none";
	$("loader").style.display = "block";
//	str = "<h1>Work with DREAM REALTY and save THOUSANDS!</h1>";
	str = "<h1>Your DREAMS MADE REAL with DREAM REALTY</h1>";
	str += "<h2>How we are unlike other real estate brokerages:</h2>";
	str += "<ul>";
	str += "<li>We provide the most innovative real estate search with complete MLS data. <a href='http://www.dreamrealty.com/dr_detail.php?lid=" + featured + "' target='_blank'>view sample</a></li>";
	str += "<li>We provide the most thorough <font color=#aa0000>FREE</font> email alerts of new listings and price changes. <a href='http://www.dreamrealty.com/sample.php' target='_blank'>view sample</a></li>";
	
	str += "<li>We <a onclick=showHelp(0); style='color:#a00;font-weight:bold;text-decoration:underline;cursor:pointer;'>GUARANTEE</a> you will be satisfied with our service.</li>";
	str += "<li>Work with the top agents in the area with no pressure and no obligation.</li>";	
	str += "</ul>";
 	str += '<a onclick=closeLoader();signMeUp(false); style="margin-left:35px;margin-bottom:10px;cursor:pointer;text-decoration:underline;color:#aa0000;font-weight:bold;">FREE SIGN UP</a>&nbsp;&nbsp;<a onclick=closeLoader(); style="margin-left:35px;margin-bottom:10px;cursor:pointer;text-decoration:underline;color:#aa0000;font-weight:bold;">I&#39ll PASS (for now)</a>';
	
	$("loader").innerHTML = str;
//  	doChange("landing",'',featured);
	loaderShown = true;
	gridCount=0;
//	firstTime = false;
}

function closeLoader() {
	$("loader").style.display = "none";
	$("results").style.display = "block";
	$("results").innerHTML = show;	
	
}


function showPop(choice) {
 	str = 	'<a href="javascript:hideDiv()"><img src="images/close2.png" class="cntrl" title="Close" /></a> ';
	if(choice==1) {
 		str += "<h4>Search Help</h4>";
  		str += "<p>Enter a city, neighborhood, an address, an MLS number or even a point of interest - like Tampa Airport. <br /><br />";
		str += "You will be sent to the results page.&nbsp;&nbsp;On that page you will find many options to refine your search. <br /><br />";
		str += "Our beBY&trade; search engine is extremely flexible. <br /><br /> ";
		str += "If you want an MLS number, enter with an @ - eg. @7123343.&nbsp;&nbsp;&nbsp;If you only want the entered city or zipcode, select EXACT LOCATION in the 'Within' dropdown box on the results page..<br /><br />";
		str += "Otherwise, indicate how close you want to be by your indicated loaction.";
  		str += "</p>";
	} else if(choice==2) {
		str += "<p>Check out our new patent pending real estate search engine.<br /><br />";
		str += "If you can name it, you can be near it, whether it's your work, your family, the beach, the airport, etc. <br /><br />";
 
		str += "Simply enter where you want to be by in the location box. </p>";
	}
	str += "<a onclick=hideDiv(); style='float:left;text-align:center;font-size:12px;font-weight:bold;text-decoration:underline;margin-left:50px;margin-top:10px;color:#e463a2;cursor:pointer;'><br />CLOSE WINDOW</a>";
  	$("hideshow").innerHTML = str;
 	showDiv();
 
}

function showTemperHelp(help) {
	$("temperHelp").style.display = "block";
	if(help) {
 		str = "<h4>Search Help</h4>";
  		str += "<p>Enter a city, neighborhood, an address, an MLS number or even a point of interest - like Tampa Airport. <br /><br />";
		str += "You will be sent to the results page.&nbsp;&nbsp;On that page you will find many options to refine your search. <br /><br />";
		str += "Our beBY&trade; search engine is extremely flexible. <br /><br /> ";
		str += "If you want an MLS number, enter with an @ - eg. @7123343.&nbsp;&nbsp;&nbsp;If you only want the entered city or zipcode, select EXACT LOCATION in the 'Within' dropdown box on the results page..<br /><br />";
		str += "Otherwise, indicate how close you want to be by your indicated loaction.";
  		str += "</p>";
	} else {
		str = "<h4>Dream Realty Guarantee<h4>";
 		str += "<p>As your real estate home buying or selling agent, we guarantee that you will be satisfied with out service. If, upon closing with us, you do not feel that we have met your service expectations, tell us about it in writing and we will give you <b>$250</b>. </p>  ";
	}
	str += "<a onclick=closeHelp(true); style='font-size:14px;font-weight:bold;text-decoration:underline;margin-left:50px;margin-top:10px;color:#a00;cursor:pointer;'>CLOSE WINDOW</a>";
	$("temperHelp").scrollTop = 0; 	
	$("temperHelp").innerHTML = str;
		
}

function showHelp(help) {
	$("help").style.display = "block";
	if(help) {
		str = "<h2>BEBY&trade; HELP</h2>";
 		str += "<p>Simply enter where you want to be by in the location box.&nbsp;&nbsp;Then, how close you want to be.";
		str += "&nbsp;&nbsp;Enter a city, neighborhood, an address or even a point of interest - like Tampa Airport. <br /><br />";
		str += "If you only want the entered city or zipcode, select EXACT LOCATION in the 'Within' dropdown box.<br /><br />";
		str += "You can resize the search area by dragging the purple pins.<br /><img src=images/purple-arrow.png><br />";
		str += "You can move the entire search area by dragging the blue circle.<br /><img src=images/blue_dot_circle.png>";
 		str += "</p>";
	} else {
		str = "<h1>Dream Realty Guarantee<h1>";
		
		str += "<p>As your real estate home buying or selling agent, we guarantee that you will be satisfied with out service. If, upon closing with us, you do not feel that we have met your service expectations, tell us about it in writing and we will give you <b>$250</b>. </p>  ";
/*		
		str = "<h1>Dream Realty Savings Guarantee</h1>";
		str += "<p>For the last 4 years, we have gone out of way to provide our clients the most competitive mortgage rates around.  We receive no kick-back whatsover for these low rates.  We are so confident you will not find a better ";
		str += "rate, we will pay you $1000 at closing if you do.  Assuming our rate is at least 1/8 of a point less than the market, on a typical $200,000 loan, you would save approximately $6000.00+ over the life of the loan.</p>";
		str += "<p>Our guarantee is only offered to clients working with a Dream Realty agent.  To be eligible, the competing loan product and terms must be identical and the rate must be locked on the same day the customer receives a quote from Sawbuck’s mortgage partner. The customer must supply a Good Faith Estimate (GFE) from the competing lender plus the HUD-1 settlement statement and final mortgage note to receive the $1000. Please note that this guarantee is from Sawbuck Realty and not from its mortgage and settlement partners; also, this guarantee is only available where allowed by law.</p>";
*/		
	}
	str += "<a onclick=closeHelp(false); style='font-size:14px;font-weight:bold;text-decoration:underline;margin-left:50px;color:#a00;cursor:pointer;'>CLOSE WINDOW</a>";
	$("help").scrollTop = 0; 	
	$("help").innerHTML = str;
}


function closeHelp(temper) {
	if(temper)
		$("temperHelp").style.display = "none";
	else	
		$("help").style.display = "none";
		
}


function listOnly() {
//	doChange("email",2);
	
	showMap = false;
	$("map").style.display = "none";
	$("results").style.display = "none";
	$("statushead").style.display = "none";
	$("sidebar").style.height = "100%";
    $("gridhead").style.display = "none";
	$("listResults").style.display = "block";
	$("gridlist").style.display = "block";
	$("sidebar").style.backgroundColor = "#fff";
	
//	doChange("grid");

	
}


function mapOnly() {
	showMap = true;
	$("map").style.display = "block";
 	if(!firstTime)
		$("results").style.display = "block";
	$("statushead").style.display = "block";
//	$("sidebar").style.height = saveSide + "px";
    $("gridhead").style.display = "block";
	$("listResults").style.display = "none";
	$("gridlist").style.display = "none";
	$("sidebar").style.backgroundColor = "#39434c";
     	
//	doChange("grid");
	
}
 
function closeDesc() {
//	alert("saveland = " + saveLand);

	$("lander").style.height = saveLand + "px";
	$("landing").style.height = saveLand + "px";
	
	$("descript").style.display = "none";
	$("lander").scrollTop = 0;
//	alert("land= " + saveLand + "-" + $("lander").offsetHeight);	
}


function onImgErrorSmall(source)
{
source.src = "images/noimage.gif";
// disable onerror to prevent endless loop
source.onerror = "";
return true;
}

function noImage() {
 	myImage = "images/noimage.gif";
}

function toggle(imgName, state){  
      flip(imgName, 'images/' + toggleState + state + '.gif')
}

function selectItems(choice){
  var div;
	div = document.getElementById("sidebar");	
   var first = div.firstChild;
   var buttonArray = Array();
 //  alert("first = " + first.sortCriteria);
     while (first.nextSibling){                     //  make an array of buttons
    first = first.nextSibling;
	if(choice) { 
		first.style.backgroundImage ="url(images/home-green.png)";
		first.selected = true;
	} else	{
		first.style.backgroundImage ="url(images/home.png)";
		first.selected = false;
	}
	
      buttonArray.push(first);
 	  
  }
    
  for(var ii=0; ii<buttonArray.length; ii++){    // rearrange buttons
    div.appendChild(buttonArray[ii]);
  }
}



function getItems() {
  var div;
	div = document.getElementById("sidebar");	
	selectedArray = new Array();
   	var first = div.firstChild;
 //  alert("first = " + first.sortCriteria);
     while (first.nextSibling){                     //  make an array of buttons
    	first = first.nextSibling;
		if(first.selected)
			selectedArray.push(first.mlsnum);
	 }
	 if(selectedArray.length==0 || selectedArray.length==totalRecs)  // all or none were selected so just print all 
	 	selectedArray = null;
}


function getListings() {
  var div;
	div = document.getElementById("sidebar");	
	selectedArray = new Array();
   	var first = div.firstChild;
 //  alert("first = " + first.sortCriteria);
     while (first.nextSibling){                     //  make an array of buttons
    	first = first.nextSibling;
//		if(first.selected)
			selectedArray.push(first.mlsnum);
	 }
	 if(!selectedArray.length)  // all or none were selected so just print all 
	 	selectedArray = null;
}

function MatchSelected(matches) {

	if(firstTime)
		$("beby1").value = matches.options[matches.selectedIndex].value;
	else	
		$("beby").value = matches.options[matches.selectedIndex].value;
		
	if(firstTime)
	  	$("search_suggestions").style.display = "none";
	else	
	  	$("search_suggestions_menu").style.display = "none";
		
	matchCity = matches.options[matches.selectedIndex].defaultValue;
	matchSub = matches.options[matches.selectedIndex].caption;
	
}

function addOption(text,value,city,subdivision)
{
var optn = document.createElement("OPTION");
optn.text = text;
optn.value = value;
//use defaultValue and caption for city and subdivision
optn.defaultValue = city;
optn.caption = subdivision;
//$("matches").options.add(optn);
if(firstTime)
	document.homeForm.matches.options.add(optn);
else
	document.myForm.matches.options.add(optn);

} 


 
 

 function codeAddress(within) {
	 var geocoder = new google.maps.Geocoder();
	 var fudge;
     var address;
	 
	 if(firstTime)
	 	address = $("beby1").value;
	 else
	 	address = $("beby").value;
	  if(within==0)
 	  		within = $("within").value;
	  else 	{
	  		$("within").selectedIndex = within;
 	  }
    geocoder.geocode( { 'address': address}, function(results, status) {
      if (status == google.maps.GeocoderStatus.OK) {
		  /*
        map.setCenter(results[0].geometry.location);
        var marker = new google.maps.Marker({
            map: map, 
            position: results[0].geometry.location
        });
		*/
  		bigLat = results[0].geometry.location.lat();
		bigLon = results[0].geometry.location.lng();
 		if(results[0].geometry.bounds != null) {
 			
 			topRightLat = results[0].geometry.bounds.getNorthEast().lat() + ((within) * ONELAT);
			topRightLng = results[0].geometry.bounds.getNorthEast().lng() + ((within) * ONELON);
			botLeftLat = results[0].geometry.bounds.getSouthWest().lat() - ((within) * ONELAT);
			botLeftLng = results[0].geometry.bounds.getSouthWest().lng() - ((within) * ONELON);
		} else {
			if(within==0) within = .5;
			topRightLat = bigLat + (within * ONELAT); 		
			topRightLng = bigLon + (within * ONELON);
			botLeftLat = bigLat - (within * ONELAT);
			botLeftLng = bigLon - (within * ONELON);
		}
		doChange('grid');
      } else {
        alert("Geocode was not successful for the following reason: " + status);
      }
    });
  }

    function redraw() {
        var latLngBounds = new google.maps.LatLngBounds(
          swMarker.getPosition(),
          neMarker.getPosition()
        );
        rectangle.setBounds(latLngBounds);
		topRightLat = latLngBounds.getNorthEast().lat();
		topRightLng = latLngBounds.getNorthEast().lng();
		botLeftLat = latLngBounds.getSouthWest().lat();
		botLeftLng = latLngBounds.getSouthWest().lng();
	   map.fitBounds(latLngBounds);
	   
	}


function closeResults() {
	$("results").style.display = "none";
}

function loadingNew() {
	document.getElementById("landing").innerHTML = "<img src=images/ajax.gif>";
}


function testImage(URL) {
     var tester=new Image();
	
 //   tester.onLoad=isGood;
 //   tester.onError=isBad;
  	tester.src = URL;
	tester.onerror = noImage();
   	
}


 
	   
	function updater() {
		isReDrawn = true;
 		redraw();
		
		doChange('grid');
		
		
		
	}
	
function changeActive() {
	
	str = '<select name="days" id="days" >';
	if (showActive) {
    	str += '<option value="0">Days on Market</option>';
		showActive = false;
	} else {
    	str += '<option value="0">Sold Date</option>';
		showActive = true;
	}
	str += '<option value="1">Today</option>';                                   
    str += '<option value="10">10 or less</option>';
    str +- '<option value="20">20 or less</option>';
    str += '<option value="30">30 or less</option>';
    str += '<option value="60">60 or less</option>';
    str += '<option value="90">90 or less</option>'
 	str += '</select>';
	$("market").innerHTML =  str;	
}


 


	
function checkBeby(evt) {	
 	var keycode=(evt.which)? evt.which:event.keyCode;

// 	doAuto = false;
	if(keycode >= 48 && keycode <= 57) {
		doAuto=false;
 		return false;
	}
 	if ((keycode >= 65 && keycode <= 90) || (keycode >= 97 && keycode <= 122)) doAuto = true;
	
	if(keycode==13) {
		if(firstTime) {
			if(document.getElementById('beby1').value.length<2) {
				alert('Please enter a location.');document.getElementById('beby1').focus();
			} else  doChange('grid'); 
		} else {
			if(document.getElementById('beby').value.length<2) {
				alert('Please enter a location.');document.getElementById('beby').focus();
			} else  doChange('grid'); 
		}
	} else if(keycode==40) {
 			if(firstTime)	{
				document.homeForm.matches.focus();
				document.homeForm.matches.options[0].selected = true;
			} else {
				document.myForm.matches.focus();
				document.myForm.matches.options[0].selected = true;
			}
  		
 	} else if(doAuto) {
		doChange('auto');return false;
	} else 
		return false;	
}

function updateScreen() {
	/*
	pageHeight = document.getElementsByTagName("body")[0].clientHeight;
  	var ls = (pageHeight - 140);
 	$("leftside").style.height = ls + "px";
	$("map").style.height = (ls * .70) + "px";
	$("sidebar").style.height = (ls * .30) - 45 + "px";
	*/
	
	$("head").style.display = "block";
	$("myCenter").style.display = "block";
	$("map").style.display = "block";
	$("map").style.height = (pageHeight - 290) + "px";
	$("gridhead").style.display = "block";
	$("gridlist").style.display = "block";
	$("statushead").style.display = "block";
	$("sidebar").style.display = "block";
	$("sidebar").style.height = "100px";
	
	$("landing").style.display = "block";
	$("lander").style.display = "block";	
	if(frontSign) {
		$("landing").style.height = "600px";	
		$("lander").style.height = "600px";
	} else {
		$("landing").style.height = "100%";	
		$("lander").style.height = "100%";
	}
	$("temper").style.display = "none";
	$("search_suggestions_menu").style.left = $("beby").offsetLeft + "px";
	
 // 	alert("1");
	if(firstTime) {
		mapCenter = new google.maps.LatLng(27.9656,-82.799764);		
		mapOpts = {
		  mapTypeId: google.maps.MapTypeId.ROADMAP,
		  scaleControl: true,
		  scrollwheel: true,
		  zoom:13,
		  backgroundColor:"#39434c",
		  center:mapCenter,
		  navigationControlOptions: {
				style: google.maps.NavigationControlStyle.ZOOM_PAN,
				position: google.maps.ControlPosition.TOP_LEFT
			}
		}	
 		map = new google.maps.Map(document.getElementById("map"), mapOpts);
	}
  }
	

function InfoBox(opts) {
  google.maps.OverlayView.call(this);
  this.latlng_ = opts.latlng;
  this.map_ = opts.map;
  this.offsetVertical_ = 0;  //was -195
 
  this.offsetHorizontal_ = 0;
  this.height_ = 20;
//  this.width_ = 266;
  this.address = opts.address;
  this.width = opts.addLength * 8;
   var me = this;
  this.boundsChangedListener_ =
    google.maps.event.addListener(this.map_, "bounds_changed", function() {
      return me.panMap.apply(me);
    });
  // Once the properties of this OverlayView are initialized, set its map so
  // that we can display it.  This will trigger calls to panes_changed and
  // draw.
  this.setMap(this.map_);
}

/* InfoBox extends GOverlay class from the Google Maps API
 */
InfoBox.prototype = new google.maps.OverlayView();

/* Creates the DIV representing this InfoBox
 */
InfoBox.prototype.remove = function() {
  if (this.div_) {
    this.div_.parentNode.removeChild(this.div_);
    this.div_ = null;
  }
};

/* Redraw the Bar based on the current projection and zoom level
 */
InfoBox.prototype.draw = function() {
  // Creates the element if it doesn't exist already.
  this.createElement();
  if (!this.div_) return;

  // Calculate the DIV coordinates of two opposite corners of our bounds to
  // get the size and position of our Bar
  var pixPosition = this.getProjection().fromLatLngToDivPixel(this.latlng_);
  if (!pixPosition) return;

  // Now position our DIV based on the DIV coordinates of our bounds
  /*
  this.div_.style.width = this.width_ + "px";
  this.div_.style.width = "300px";
  */
  this.div_.style.left = (pixPosition.x) + "px";
  this.div_.style.height = this.height_ + "px";
  this.div_.style.top = (pixPosition.y) + "px";
  this.div_.style.border = "2px solid black";
  this.div_.style.fontSize = "12px";
    this.div_.style.background = "#fff";
  this.div_.style.display = 'block';
 };

/* Creates the DIV representing this InfoBox in the floatPane.  If the panes
 * object, retrieved by calling getPanes, is null, remove the element from the
 * DOM.  If the div exists, but its parent is not the floatPane, move the div
 * to the new pane.
 * Called from within draw.  Alternatively, this can be called specifically on
 * a panes_changed event.
 */
InfoBox.prototype.createElement = function() {
  var panes = this.getPanes();
  var div = this.div_;
  if (!div) {
    // This does not handle changing panes.  You can set the map to be null and
    // then reset the map to move the div.
    div = this.div_ = document.createElement("div");
    div.style.border = "0px none";
    div.style.position = "absolute";
 	div.style.width = this.width + "px";
	div.style.height = "20px";
    var contentDiv = document.createElement("div");
    contentDiv.style.padding = "3px"
    contentDiv.innerHTML = this.address;

    var topDiv = document.createElement("div");
    topDiv.style.textAlign = "right";
	/*
    var closeImg = document.createElement("img");
    closeImg.style.width = "32px";
    closeImg.style.height = "32px";
    closeImg.style.cursor = "pointer";
    closeImg.src = "http://gmaps-samples.googlecode.com/svn/trunk/images/closebigger.gif";
    topDiv.appendChild(closeImg);
*/
    function removeInfoBox(ib) {
      return function() {
        ib.setMap(null);
      };
    }

    google.maps.event.addDomListener(document, 'click', removeInfoBox(this));

    div.appendChild(topDiv);
    div.appendChild(contentDiv);
    div.style.display = 'none';
    panes.floatPane.appendChild(div);
    this.panMap();
  } else if (div.parentNode != panes.floatPane) {
    // The panes have changed.  Move the div.
    div.parentNode.removeChild(div);
    panes.floatPane.appendChild(div);
  } else {
    // The panes have not changed, so no need to create or move the div.
  }
}

/* Pan the map to fit the InfoBox.
 */
InfoBox.prototype.panMap = function() {
  // if we go beyond map, pan map
  var map = this.map_;
  var bounds = map.getBounds();
  if (!bounds) return;

  // The position of the infowindow
  var position = this.latlng_;

  // The dimension of the infowindow
  var iwWidth = this.width_;
  var iwHeight = this.height_;

  // The offset position of the infowindow
  var iwOffsetX = this.offsetHorizontal_;
  var iwOffsetY = this.offsetVertical_;

  // Padding on the infowindow
  var padX = 40;
  var padY = 40;

  // The degrees per pixel
  var mapDiv = map.getDiv();
  var mapWidth = mapDiv.offsetWidth;
  var mapHeight = mapDiv.offsetHeight;
  var boundsSpan = bounds.toSpan();
  var longSpan = boundsSpan.lng();
  var latSpan = boundsSpan.lat();
  var degPixelX = longSpan / mapWidth;
  var degPixelY = latSpan / mapHeight;

  // The bounds of the map
  var mapWestLng = bounds.getSouthWest().lng();
  var mapEastLng = bounds.getNorthEast().lng();
  var mapNorthLat = bounds.getNorthEast().lat();
  var mapSouthLat = bounds.getSouthWest().lat();

  // The bounds of the infowindow
  var iwWestLng = position.lng() + (iwOffsetX - padX) * degPixelX;
  var iwEastLng = position.lng() + (iwOffsetX + iwWidth + padX) * degPixelX;
  var iwNorthLat = position.lat() - (iwOffsetY - padY) * degPixelY;
  var iwSouthLat = position.lat() - (iwOffsetY + iwHeight + padY) * degPixelY;

  // calculate center shift
  var shiftLng =
      (iwWestLng < mapWestLng ? mapWestLng - iwWestLng : 0) +
      (iwEastLng > mapEastLng ? mapEastLng - iwEastLng : 0);
  var shiftLat =
      (iwNorthLat > mapNorthLat ? mapNorthLat - iwNorthLat : 0) +
      (iwSouthLat < mapSouthLat ? mapSouthLat - iwSouthLat : 0);

  // The center of the map
  var center = map.getCenter();

  // The new map center
  var centerX = center.lng() - shiftLng;
  var centerY = center.lat() - shiftLat;

  // center the map to the new shifted center
  map.setCenter(new google.maps.LatLng(centerY, centerX));

  // Remove the listener after panning is complete.
  google.maps.event.removeListener(this.boundsChangedListener_);
  this.boundsChangedListener_ = null;
};
 
 
/**
 * makeMarker() ver 0.2
 * creates Marker and InfoWindow on a Map() named 'map'
 * creates sidebar row in a DIV 'sidebar'
 * saves marker to markerArray and markerBounds
 * @param options object for Marker, InfoWindow and SidebarItem
 * @author Esa 2009
 */
var infoWindow = new google.maps.InfoWindow();
var markerBounds = new google.maps.LatLngBounds();
var markerArray = [];
  
function makeMarker(options){
   var pushPin = new google.maps.Marker({map:map});
  pushPin.setOptions(options);
  if(showMap) {
	  google.maps.event.addListener(pushPin, "click", function(){
	 //   infoWindow.setOptions(options);
	  //  infoWindow.open(map, pushPin);
		   var infoBox = new InfoBox({latlng: pushPin.getPosition(), map: map, address: options.content, addLength: options.addLength});
		
		doChange('landing',-1, options.mlsnum);	
		if(this.sidebarButton)this.sidebarButton.button.focus();
	  });
	   google.maps.event.addListener(pushPin, "mouseover", function(){
				pushPin.setIcon("images/home-green.png");				
		 });
	
	   google.maps.event.addListener(pushPin, "mouseout", function(){
				pushPin.setIcon("images/home.png");				
		 });
  }
  var idleIcon = pushPin.getIcon();
  if(options.sidebarItem){
     pushPin.sidebarButton = new SidebarItem(pushPin, options);
    pushPin.sidebarButton.addIn("sidebar");
  }
  markerBounds.extend(options.position);
  markerArray.push(pushPin);
  return pushPin;
}

function clearMarkers(doAll) {
  	for (var i=0; i<markerArray.length;i++) {
// 		markerArray[i].setMap(null);
 		markerArray[i].sidebarButton.remove();
		markerArray[i].setMap(null);
  	}
//	map.setMap(null);
	if(doAll)
		markerArray.length = 0;
//  remove map handles
	if(neMarker != null) {
		neMarker.setMap(null);
		swMarker.setMap(null);
		rectangle.setMap(null);
		centerMarker.setMap(null);
	}
}
 

  
 
/**
 * Creates a sidebar item 
 * @constructor
 * @author Esa 2009
 * @param marker
 * @param options object Supported properties: sidebarItem, sidebarItemClassName, sidebarItemWidth,
 */

function SidebarItem(marker, opts){
  var tag = opts.sidebarItemType || "button";
  var row = document.createElement(tag);
 // opts.sidebarItem = "<span style='width:200px;float:left;'>shit</span><span style='width:140px;float:left;'>fuck</span>";
  row.innerHTML = opts.sidebarItem;
  row.className = opts.sidebarItemClassName || "sidebar_item";  
  row.style.display = "block";
  row.style.width = opts.sidebarItemWidth || "100%";
  row.style.backgroundRepeat = "no-repeat";
  if(!showMap) {
 	 	row.style.backgroundPosition = "left";
  		row.style.backgroundImage ="url(images/home.png)";
  		row.selected = false;
  }
  row.onclick = function(){
    google.maps.event.trigger(marker, 'click');
 //	doChange('landing',-1,7436767);	
 	if(!showMap) {
		if(row.selected) {
			row.style.backgroundImage ="url(images/home.png)";
			row.selected = false;		
		} else	{
			row.style.backgroundImage ="url(images/home-green.png)";
			row.selected = true;
		}
	}
	/*
	row.style.backgroundRepeat = "no-repeat";
	row.style.backgroundPosition = "left";
	*/
 	doChange('landing',-1, opts.mlsnum);
   }
  row.onmouseover = function(){
    google.maps.event.trigger(marker, 'mouseover');
  }
  row.onmouseout = function(){
    google.maps.event.trigger(marker, 'mouseout');
  }
  this.button = row;
  this.button.sortCriteria = opts.sortCriteria || [row.innerHTML];   //////// added for sorting  
  this.button.mlsnum = opts.mlsnum;
  }
// adds a sidebar item to a <div>
SidebarItem.prototype.addIn = function(block){
  if(block && block.nodeType == 1)this.div = block;
  else
    this.div = document.getElementById(block)
    || document.getElementById("sidebar")
    || document.getElementsByTagName("body")[0];
   this.div.appendChild(this.button);
}


//var mapCenter = new google.maps.LatLng(27.97,-82.53);	//tampa
var mapCenter;	//downtown cw
var mapOpts;
var map;
//  We set zoom and center later by fitBounds()
var name;
var myDir=document.getElementById("myDir").value;
//var latlng;
//latlon="27.9656,-82.799764";
//var ONELAT = 0.01505;
var ONELAT = 0.01;
//var ONELON = 0.0132;
var ONELON = 0.01;
var bigSql;
var bigPoster;
var bigUser = document.getElementById("user_id").value;
var bigEmail =document.getElementById("drEmail").value;
var bigName = document.getElementById("drName").value;

var tempBeby = document.getElementById("tempBeby").value;
var myCity = document.getElementById("myCity").value;
var featured = document.getElementById("featured").value;
var agent = document.getElementById("agent").value;
var within;
var title;
var neMarker;
var swMarker;
var rectangle;
var centerMarker;

//var within = document.getElementById("within").value;
var beby = '';
var lastBeby = '';
var bigPhone = '';
var bigSearch = '';
var totalRecs;
var xmlHttp;
var choice;
var adv;
var jack;
var results;
var myImage;
var show;
var isActive = 1;
var selectedArray = Array();
var showMap = true;
var saveSide;
var addressAsc = false;
var priceAsc = true;
var bedAsc = false;
var bathAsc = false;
var yearAsc = false;
var sqAsc = false;
var sqftAsc = false;
var daysAsc = false;
var distAsc = false;
//var cran = crandom();
var xmlReady = false;
//var cran=crandom();^M


if(bigUser > 0) showUser();
 
 
function doChange(src,val,mlsnum,lat,lon)
{ 
 choice = src;
 str = val;
 xmlHttp=GetXmlHttpObject();
//alert("container = " + $("container").offsetHeight);
if (xmlHttp==null)
 {
 alert ("Browser does not support HTTP Request");
 return;
 }
/*
	if(src=="agent") {
		url = "agent.php?id=2";
    	xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	

	 if(gridCount >= 1000 && (bigUser.length < 2 || bigUser=="0000") && src=="grid") {  //1000 makes this not going to happen
 		disableForm();
  		signMeUp();
		bigUser = "0000";   //temp so this code doesn't run after user signs up	
		alert("To continue searching, please create a no-obligation, free account >>" );
		
		return;		
*/	  
	  if(src=="exiting") {
		url="agentHits.php?beby=" + $("beby").value;
    	xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
			
	  }else if(src=="grid") {  
//		$("temper").style.display = "none";  
		if(firstTime) {
			beby = $("beby1").value;
			lastBeby = $("beby1").value;
			updateScreen(true);
			$("beby").value = lastBeby;
			$("within").value = 0;
		} else beby = $("beby").value;
		if($("beby1").value != lastBeby) {
//basically start over			
			isReDrawn = false;
			lastBeby = $("beby1").value;
		}
// 		  codeAddress();
		  
  	    spinOn();
 		if($("show").value==1) {showMap=true; mapOnly(); } else {showMap=false; listOnly();}
		if($("active").value==1) isActive=1; else isActive=0;
 		
		if($("beby1").value != tempBeby && $("beby1").value != lastBeby && useCookies) doCookie("drSearch",$("beby1").value);
  		
// 		$("beby").value.replace(/%20/g," ");
// 		if(val) $("within").value = val;
//   		if(lat > 15) {
//	alert("lat = " + topRightLat);
//	isReDrawn = true;
      			var url= "data.php?beby="+beby + "&within="+$("within").value + "&minprice="+document.getElementById("minprice").value+"&maxprice="+document.getElementById("maxprice").value+"&beds="+document.getElementById("beds").value+"&baths="+document.getElementById("baths").value+"&type="+document.getElementById("type").value + "&square="+document.getElementById("square").value + "&year="+document.getElementById("year").value + "&lotsize="+document.getElementById("lotsize").value + "&foreclosure="+document.getElementById("foreclosure").value + "&waterfront="+document.getElementById("waterfront").value + "&pool="+document.getElementById("pool").value + "&days=0" + "&active=" + isActive + "&lat="+bigLat+"&lon="+bigLon + "&useCookies=" + useCookies + "&firstTime=" + firstTime + "&choice=3&trlat=" + topRightLat + "&trlng=" + topRightLng + "&bllat=" + botLeftLat + "&bllng=" + botLeftLng + "&isReDrawn=" + isReDrawn + "&matchCity=" + matchCity + "&matchSub=" + matchSub;
//alert("url= " + url);
			/*
		} else {
			var url= "data.php?beby="+document.getElementById("beby").value+"&within="+$("within").value+"&minprice="+document.getElementById("minprice").value+"&maxprice="+document.getElementById("maxprice").value+"&beds="+document.getElementById("beds").value+"&baths="+document.getElementById("baths").value+"&type="+document.getElementById("type").value + "&square="+document.getElementById("square").value + "&year="+document.getElementById("year").value + "&lotsize="+document.getElementById("lotsize").value + "&foreclosure="+document.getElementById("foreclosure").value + "&waterfront="+document.getElementById("waterfront").value + "&pool="+document.getElementById("pool").value + "&days=" + document.getElementById("days").value + "&active=" + isActive + "&useCookies=" + useCookies+ "&firstTime=" + firstTime + "&choice=3&ran="+Math.random();
		}
		*/
     	xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
		lastBeby = $("beby").value;
//		if(loaderShown) gridCount++;
		gridCount++;
		if(gridCount==10) gridCount=0;
 		if(useCookies) parseCookies();
   } else if(src=='auto') {
	    if(firstTime)
	    	var url=  "getAuto.php?txt=" + $("beby1").value;
		else	
	    	var url= "getAuto.php?txt=" + $("beby").value;
			
   		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);	
		
   } else if (src=='landing') {
//	   $("landing").style.overflowY = "auto";
	    spin2On();	
		$("landing").style.height = saveLand;
		$("landing").style.overflowY = "hidden";
		$("lander").style.height = saveLand;
		$("lander").style.overflowY = "hidden";

		var url= "showDR1.php?mlsnum="+mlsnum+"&active="+isActive;	   
   		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);		
   } else if(src=="popup") {
	   $("popup").style.display = "block";
		var url= "showPopup.php?mls="+mlsnum+"&pic_count="+val;	   
   		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);			   
   } else if(src=="latlon") {
		var url=myDir + "getLatLon.php?q="+document.getElementById("beby").value;	   //cd
 		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
   } else if(src=="saveSearch") {  //cd
	   	spin2On();
 	   	if(!showMap) getItems();
 		if(val==1) {
 			var url= "data.php?beby="+document.getElementById("beby").value+"&within="+document.getElementById("within").value+"&minprice="+document.getElementById("minprice").value+"&maxprice="+document.getElementById("maxprice").value+"&beds="+document.getElementById("beds").value+"&baths="+document.getElementById("baths").value+"&type="+document.getElementById("type").value + "&square="+document.getElementById("square").value + "&year="+document.getElementById("year").value + "&lotsize="+document.getElementById("lotsize").value + "&foreclosure="+document.getElementById("foreclosure").value + "&waterfront="+document.getElementById("waterfront").value + "&pool="+document.getElementById("pool").value + "&days=" + document.getElementById("days").value + "&choice=1&email=" + $("email").value + "&name=" + $("name").value + "&password=" + $("password").value + "&phone=" + $("phone").value + "&sname=" + $("searchName").value + "&comments=" + $("comments").value + "&sendResults=" + $("sendResults").checked + "&sendEmails=" + $("sendEmails").checked + "&selectedArray="+selectedArray + "&useCookies=" + useCookies+"&ran="+Math.random();
 		} else if (val==2) {
			var url= "data.php?beby="+document.getElementById("beby").value+"&within="+document.getElementById("within").value+"&minprice="+document.getElementById("minprice").value+"&maxprice="+document.getElementById("maxprice").value+"&beds="+document.getElementById("beds").value+"&baths="+document.getElementById("baths").value+"&type="+document.getElementById("type").value + "&square="+document.getElementById("square").value + "&year="+document.getElementById("year").value + "&lotsize="+document.getElementById("lotsize").value + "&foreclosure="+document.getElementById("foreclosure").value + "&waterfront="+document.getElementById("waterfront").value + "&pool="+document.getElementById("pool").value + "&days=" + document.getElementById("days").value + "&choice=2&email=" + $("email").value +  "&password=" + $("password").value + "&sname=" + $("searchName").value  + "&sendResults=" + $("sendResults").checked + "&sendEmails=" + $("sendEmails").checked + "&selectedArray="+selectedArray + "&useCookies=" + useCookies+"&ran="+Math.random();
		} else if (val==3) {
 			if(!selectedArray.length) getListings();
//if user is logged in and wants to save search - need to use drName;
		    if($("name")==null) {
 				var url = myDir + "listingsOnly.php?name=" + $("drName").value + "&email=" + $("drEmail").value + "&comments=" + $("comments").value + "&selectedArray=" + selectedArray + "&ran=" + Math.random();
			} else {
				var url = myDir + "listingsOnly.php?name=" + $("name").value + "&email=" + $("email").value + "&comments=" + $("comments").value + "&selectedArray=" + selectedArray + "&ran=" + Math.random();
			}
		} else { 		
 			var url= "data.php?beby="+document.getElementById("beby").value+"&within="+document.getElementById("within").value+"&minprice="+document.getElementById("minprice").value+"&maxprice="+document.getElementById("maxprice").value+"&beds="+document.getElementById("beds").value+"&baths="+document.getElementById("baths").value+"&type="+document.getElementById("type").value + "&square="+document.getElementById("square").value + "&year="+document.getElementById("year").value + "&lotsize="+document.getElementById("lotsize").value + "&foreclosure="+document.getElementById("foreclosure").value + "&waterfront="+document.getElementById("waterfront").value + "&pool="+document.getElementById("pool").value + "&days=" + document.getElementById("days").value + "&choice=0&sname=" + $("searchName").value  + "&sendResults=" + $("sendResults").checked + "&sendEmails=" + $("sendEmails").checked + "&selectedArray="+selectedArray + "&useCookies=" + useCookies+"&ran="+Math.random();
 			
		}
   		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
   } else if(src=="saveFav") { //cd
	   	spin2On();
	    if(val==1) {
	 		var url=myDir + "drSign2.php?signup=1&email=" + $("email").value + "&name=" + $("name").value + "&password=" + $("password").value + "&phone=" + $("phone").value + "&comments=" + $("comments").value + "&mlsnum=" + mlsnum + "&useCookies=" + useCookies+ "&agent=" + agent + "&ran="+Math.random();
		} else if (val==2) {
	 		var url=myDir + "drSign2.php?signup=2&email=" + $("email").value + "&password=" + $("password").value + "&mlsnum=" + mlsnum + "&useCookies=" + useCookies+ "&ran="+Math.random();
		} else if (val==3) {
	 		var url=myDir + "drSign2.php?signup=3&mlsnum=" + mlsnum + "&user_id=" + bigUser + "&ran="+Math.random();
		} else if (val==4) {
	 		var url=myDir + "drSign2.php?signup=1&email=" + $("email").value + "&name=" + $("name").value + "&password=" + $("password").value + "&phone=" + $("phone").value + "&comments=" + $("comments").value + "&useCookies=" + useCookies+ "&agent=" + agent +"&ran="+Math.random();
		} else if (val==5) {
//if user does hit - more search criteria - comments and several other fields will be null
			if($("comments")==null) {
 	 			var url=myDir + "drSign2.php?signup=1&email=" + $("email").value + "&name=" + $("name").value + "&password=" + $("password").value + "&phone=" + $("phone").value + "&useCookies=" + useCookies+ "&sendEmails=" + $("sendEmails").checked + "&beby=" + $("searchName").value +  "&type=" + $("type1").value + "&agent=" + agent +"&ran="+Math.random();
			} else {
 	 			var url=myDir + "drSign2.php?signup=1&email=" + $("email").value + "&name=" + $("name").value + "&password=" + $("password").value + "&phone=" + $("phone").value + "&comments=" + $("comments").value + "&useCookies=" + useCookies+ "&sendEmails=" + $("sendEmails").checked + "&beby=" + $("searchName").value + "&within=" + $("within1").value + "&type=" + $("type1").value + "&minprice=" + $("minprice1").value + "&maxprice=" + $("maxprice1").value + "&beds=" + $("beds1").value + "&baths=" + $("baths1").value + "&square=" + $("square1").value + "&lotsize=" + $("lotsize1").value + "&year=" + $("year1").value + "&waterfront=" + $("waterfront1").value + "&pool=" + $("pool1").value + "&foreclosure=" + $("foreclosure1").value + "&agent=" + agent +"&ran="+Math.random();
			}
		} else {  //just a login
	 		var url=myDir + "drSign2.php?signup=2&email=" + $("email").value + "&password=" + $("password").value + "&ran="+Math.random();
 		}
    	xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
		enableForm();
		$("landing").style.overflowY = "hidden";
		$("landing").scrollTop = 0;
   } else if(src=="schedule") { //cd
   		spin2On();
 	   	url = myDir + "goseeit.php?mlsnum=" + mlsnum + "&name=" + document.sel4.name.value + "&email=" + document.sel4.email.value + "&phone=" + document.sel4.phone.value + "&adate=" + document.sel4.adate.value + "&moving=" + document.sel4.moving.value + "&timeframe=" + document.sel4.timeframe.value + "&comments=" + document.sel4.comments.value + "&agent=" + agent +"&ran="+Math.random();
  		xmlHttp.onreadystatechange=stateChanged;
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
   } else if(src=="showDesc") { //cd
   	  //spin2On();
		
 
	  var url="showDesc.php?mls="+mlsnum + "&active" + isActive;
	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null); 	   
   } else if(src=="userSearches") { //cd
   	  spin2On();
	  var url=myDir + "userSearches.php?user_id="+val;
	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null); 
   } else if(src=="deleteSearches") {  //cd
   	  spin2On();
	  var url=myDir + "deleteSearches.php?id="+val;
  	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);	  
   } else if(src=="favorites") {  //not cd because of file_exists works with idx directory not http
   	  spin2On();
   
	  var url="favorites.php?user_id="+val;
  	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);	  
   } else if(src=="deleteFavs") {  //cd
   	  spin2On();
   
	  var url=myDir + "deleteFavs.php?id="+val;
  	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);	  
   } else if(src=="profile") {  //cd
   	  spin2On();
   
	  var url=myDir + "profile.php?user_id="+val;
   	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);		  	  
   } else if(src=="updateProfile") {  //cd
   	  spin2On();
   
	  var url=myDir + "update.php?user_id="+val+"&name="+$("name").value+"&phone="+$("phone").value+"&pass="+$("password").value+"&interestcity="+$("interestcity").value;
   	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);		  	  
   } else if(src=="email") {  //cd
	  var url=myDir + "email.php?id=" + val + "&beby=" + $("beby").value;
      xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);		  	  
	  
   } else if((val==-1) || (val <-4)) {  //cd
	  var url=myDir + "getNew.php?code="+val;
	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null); 		 
   } else if ((val == -2) || (val == -3) || (val == -4)) {  //cd
 	  loadingNew();
	  var url=myDir + "miniDetail.php?mlsnum="+mlsnum+"&load="+val;
	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
  } else {  //cd
 //str and adv are determined in getParam on choice = mydiv
 	  var url=myDir + "statey.php?data="+src+"&val="+str+"&adv="+adv;
	  if(val==1000) choice="bcities";
	  xmlHttp.onreadystatechange=stateChanged;
	  xmlHttp.open("GET",url,true);
	  xmlHttp.send(null);
  }
}

 	
function stateChanged() {
	if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
		if((choice=="saveSearch")||(choice=="saveFav") || (choice=="deleteSearches") || (choice=="deleteFavs") || (choice=="updateProfile")) {
			joe=xmlHttp.responseText;
   			var arr = joe.split("\n");
  //little problem with the response.  seems to be a 3 char arr[0] - but they are invisible and I don't know where they are coming from			
			var k=0;
			for(var i=0;i<arr.length;i++) {
				if(arr[i].length > 5 && !k) {
					alert(arr[i]);
					k++;
				} else if(arr[i].length > 1 && k) {
					if(k==1) {
						bigUser = arr[i];
						k++;
					} else
						bigName = arr[i];		
 				}
 			}
			if(k) {
					$("loader").style.display = "none";
					if(useCookies) {
						doCookie("drUser",bigUser);
						doCookie("drName",bigName);						
						parseCookies();
					}
					showUser();
			}
			if(choice=="deleteFavs") doChange('favorites',bigUser);
			else if(choice=="deleteSearches") doChange('userSearches',bigUser);
//			spin2Off();
   		} else if(choice=="schedule") {
  			alert(xmlHttp.responseText);	
			spin2Off();
		} else if(choice=="auto") {
				joe=xmlHttp.responseText;
   				var arr= joe.split("\n");
   				if(arr.length > 1) {
					if(firstTime) 
						$("search_suggestions").style.display = "block";
					else	
						$("search_suggestions_menu").style.display = "block";
 					if(firstTime)	
						document.homeForm.matches.options.length=0;
					else	
						document.myForm.matches.options.length=0;
						
 					for(i=0;i<arr.length;i++) {
						a = arr[i].split(",");
 						addOption(a[0],a[1],a[2],a[3]);
					}
 				} else if (firstTime) $("search_suggestions").style.display = "none";	
				  else $("search_suggestions_menu").style.display = "none";	
		} else if((choice=="userSearches") || (choice=="favorites") || (choice=="profile") || (choice=="agent")) {
 			$("lander").innerHTML=xmlHttp.responseText;
//			spin2Off();
		} else if(choice=="popup") {
 			$("popup").innerHTML=xmlHttp.responseText;
		} else if(choice=="showDesc") {
			$("descript").style.display = "block";
			ls = $("container").offsetHeight - $("lander").offsetHeight;
   			$("descript").innerHTML=xmlHttp.responseText;
			if(isIE) fudge = 55; else fudge = 40;
			ds = $("descript").offsetHeight + fudge;
			if(ds > ls) {
				$("lander").style.height = saveLand + (ds - ls) + "px";
				$("landing").style.height = saveLand + (ds -ls) + "px";
			}
		} else if(choice=="grid") {
//			spinOff();
 			joe=xmlHttp.responseText;	
 			clearMarkers(true);
			
 //			alert("count= " + markerArray.length);
			if(markerArray.length) {
//				map.setMap(null);
				if(showMap) {
 //					map = new google.maps.Map(document.getElementById("map"), mapOpts);
				}
   			}
  			var arr = joe.split("\n");
   			
// 			if(arr.length<3) return;
			var john;
//first record of the array is the lat and lon	
 			b=arr[0].split(",");
			
			/*
 			bigLat = b[0];
 			bigLon = b[1];
			*/
 			totalRecs = b[2];
			spinOff();			
/*			
//			if((arr.length<3)||(!totalRecs)){
			if((totalRecs==0)||(arr.length<3)) {
 				document.getElementById("statushead").innerHTML = "0 matching listings.  Try adding the city or zipcode to the search.";
				alert("No listings matches your criteria.  Try adding the city or zipcode to the search.");	
				$("beby").focus();
				return;
			} else {
//				upGrid();
*/
				show = "<span class=sstatus>&nbsp;&nbsp;";
				if(totalRecs==0) {
 					show += "0 matching listings.  Try dragging the handles to enlarge the search area."
					document.getElementById("statushead").innerHTML = show;
					
 					if(!firstTime)clearMarkers(false);
					
				} else {
					if (totalRecs == 1) show += totalRecs + " matching listing";
					else if (totalRecs > 100) show += totalRecs + " matchings listings. &nbsp; Showing 100";
					else show += totalRecs + " matching listings.";
	//				show += "</span>";
	
	// 				show += " <a onClick='saveSearch()' style='text-decoration:underline;cursor:pointer;margin-left:10px;'>Save Search</a></span>";
					show += " <a onClick='saveSearch(1)'><img src=images/save.png style='margin-left:15px;cursor:pointer;'></a>";
	
					show += " <a onClick='saveSearch(1)' style='text-decoration:underline;cursor:pointer;color:#a00; font-size:12px;font-weight:bold;'>Save search</a></span>";
	
					show += " <a onClick='saveSearch(0)'><img src=images/email.png style='margin-left:15px;cursor:pointer;'></a>";
	
					show += " <a onClick='saveSearch(0)' style='text-decoration:underline;cursor:pointer;color:#a00;font-size:12px;font-weight:bold;'>Email me new matching listings & price changes</a></span>";
					
					document.getElementById("statushead").innerHTML = show;
 					if(totalRecs > 1)
						show = "<span>&nbsp;" + totalRecs + " results <a onClick='saveSearch(0)'><img src=images/email.png style='margin-left:15px;cursor:pointer;'></a>";
					else 	
						show = "<span>&nbsp;" + totalRecs + " result <a onClick='saveSearch(0)'><img src=images/email.png style='margin-left:15px;cursor:pointer;'></a>";
	
					show += " <a onClick='saveSearch(0)' style='text-decoration:underline;cursor:pointer;color:#a00;font-size:12px;font-weight:bold;'>Email me</a>&nbsp;&nbsp;selected results<input type='checkbox' id='sendResults' name='sendResults' value='sendResults' checked='checked'>&nbsp;new listings&nbsp;<input type='checkbox' id='sendEmails' name='sendEmails' value='sendEmails' checked='checked'>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a onClick='closeResults()'><img src=images/close.gif style='cursor:pointer;position:absolute;top:2px;right:5px;margin-left:10px;' alt='Close results'></a></span>";
 				}
				if(showMap) {
					
//					if(!firstTime) {
						$("results").style.display="block";
						$("results").innerHTML = show;	
//					}
				} else {
					$("listResults").style.display="block";
					$("results").style.display = "none";
					temp = "&nbsp;&nbsp;Click rows for details.&nbsp;&nbsp;<a onClick=selectItems(1)><img src=images/home-green.png style='cursor:pointer;height:12px;width:12px;border:0px;'>&nbsp;<span style='height:15px;width:15px;border:0px;color:#a00;text-decoration:underline;'>Select all</span></a>&nbsp;&nbsp;&nbsp;";
					temp += "<a onClick=selectItems(0)><img src=images/home.png style='cursor:pointer;height:12px;width:12px;border:0px; '>&nbsp;<span style='height:15px;width:15px;border:0px;color:#a00;text-decoration:underline;'>Un-select all</span></a>&nbsp;&nbsp;";
					$("listResults").innerHTML = temp + " " + show;				
				}
//			}
			if(!isIE) {
//				if(totalRecs<6)
				if($("sidebar").scrollHeight > $("sidebar").clientHeight)
					document.getElementById("address3").style.width = "41%";
 				else 					
					document.getElementById("address3").style.width = "39%";					
			}
  			jack = new Array();
			
  			for(i=1;i<arr.length;i++) {
				a = arr[i].split(",");
				john = a;
				jack.push(a);
 				if(a[9] > 25) {  //in florida
//           		var latlng = new google.maps.LatLng(a[9], a[10]);
					address = "<a href=http://www.clearwaterdreaming.com/mls_detail.php?id=" + a[11] + "&active=" + isActive +  " target='_blank'>" + a[0] + "</a>";
					name="row " + i;
 					if(showMap) {
						/*
 					if(bigLat.length < 2) {
//need for mls only entries			
						bigLat = a[9];
						bigLon = a[10];
 					}		
						*/
						if(i%2)
							joe = "<span class='address1'>" + a[0] + "</span><span class='price1'>" + addCommas(a[1],true) + "&nbsp;</span><span class='bed1'>" + a[2] + "&nbsp;</span><span class='bed1'>" + a[3] + "&nbsp;</span><span class='bed1'>" + a[4] + "&nbsp;</span><span class='bed1'>" + addCommas(a[5],false) + "&nbsp;</span><span class='per1'>" + addCommas(a[6],true) + "&nbsp;&nbsp;</span><span class='bed1'>" + a[7] + "&nbsp;&nbsp;</span><span class='dist1'>" + a[8] + "&nbsp;</span>";
						else	
							joe = "<span class='address2'>" + a[0] + "</span><span class='price2'>" + addCommas(a[1],true) + "&nbsp;</span><span class='bed2'>" + a[2] + "&nbsp;</span><span class='bed2'>" + a[3] + "&nbsp;</span><span class='bed2'>" + a[4] + "&nbsp;</span><span class='bed2'>" + addCommas(a[5],false) + "&nbsp;</span><span class='per2'>" + addCommas(a[6],true) + "&nbsp;&nbsp;</span><span class='bed2'>" + a[7] + "&nbsp;&nbsp;</span><span class='dist2'>" + a[8] + "&nbsp;</span>";
 					} else {  // not showmap
						//cd
						myImage = myDir + "idx/" + a[11] + "_1.jpg";
   						if(i%2)
							joe = "<span class='gridImage'><img src= " + myImage + " onerror=onImgErrorSmall(this) height=60 hspace=5 border=1 ></span><span class='address0'> " + a[0] + "</span><span class='price0'>" + addCommas(a[1],true) + "&nbsp;</span><span class='bed0'>" + a[2] + "&nbsp;</span><span class='bed0'>" + a[3] + "&nbsp;</span><span class='bed0'>" + a[4] + "&nbsp;</span><span class='bed0'>" + addCommas(a[5],false) + "&nbsp;</span><span class='per0'>" + addCommas(a[6],true) + "&nbsp;&nbsp;</span><span class='bed0'>" + a[7] + "&nbsp;&nbsp;</span><span class='dist0'>" + a[8] + "&nbsp;</span>";
						else	
							joe = "<span class='gridImage'><img src= " + myImage + "  onerror=onImgErrorSmall(this) height=60 hspace=5></span><span class='address0a'> " + a[0] + "</span><span class='price0a'>" + addCommas(a[1],true) + "&nbsp;</span><span class='bed0a'>" + a[2] + "&nbsp;</span><span class='bed0a'>" + a[3] + "&nbsp;</span><span class='bed0a'>" + a[4] + "&nbsp;</span><span class='bed0a'>" + addCommas(a[5],false) + "&nbsp;</span><span class='per0a'>" + addCommas(a[6],true) + "&nbsp;&nbsp;</span><span class='bed0a'>" + a[7] + "&nbsp;&nbsp;</span><span class='dist0a'>" + a[8] + "&nbsp;</span>";							
 					}
  					makeMarker({
						  icon: "images/home.png",		   
						  position: new google.maps.LatLng(a[9],a[10]),
						  title: addCommas(a[1],true),
						  sidebarItem: joe,
						  sortCriteria: a,
						  mlsnum: a[11],
						  addLength: a[12],
						  content: address
 					});   				
					
				}  // a>25
			}
			
			if(showMap) {

 				map.setCenter(new google.maps.LatLng(bigLat,bigLon));
				if(!isReDrawn)
					map.fitBounds(map.getBounds());
				within = document.getElementById("within").value;
				switch(within) {
					case "1":
						zoom = 14;
						radius = 1.609;
						break;
					case "2":
						zoom = 13;
						radius = 1.609 * 2;
						break;
					case "5":
						zoom = 12;
						radius = 1.609 * 5;
						break;
					case "10":
						zoom = 11;
						radius = 16.09;
						break;
					case "25":
						zoom = 10;
						radius = 1.609 * 25;
						break;
					default:
						zoom = 13;
						radius = 50 * 1.609;
						break;
				}
				zoom--;
//				map.setZoom(zoom);
				var title = $("beby").value.toUpperCase() + " - You can drag marker - then release or click to update search.";
				
				centerMarker = new google.maps.Marker({
				  map: map,
				  icon: "images/blue_dot_circle.png",
				  position: new google.maps.LatLng(bigLat,bigLon),
				  draggable: true,
				  title: title
				});
				google.maps.event.addListener(centerMarker, "mouseup", function() {
						c=centerMarker.getPosition();
						isReDrawn = true;
						var saveLat = bigLat;
						var saveLng = bigLon;
						bigLat=c.lat();
						bigLon=c.lng();
						var latDiff = bigLat - saveLat;
						var lngDiff = bigLon - saveLng;
						
						topRightLat = topRightLat + latDiff;
 						topRightLng = topRightLng + lngDiff;
						botLeftLat = botLeftLat + latDiff;
						botLeftLng = botLeftLng + lngDiff;
						
//alert("toprl = " + topRightLat + "-" + topRightLng + "-" + botLeftLat + "-" + botLeftLng);						
						doChange('grid');
//						doChange("grid",'','',c.lat(),c.lng());
						
				});
				/*
				if(!isReDrawn) {
	 				topRightLat = parseFloat(bigLat) + (within * ONELAT);
 	 				topRightLng = parseFloat(bigLon) + (within * ONELON);				
				}
				*/
 				title = 'DRAG ME ANY DIRECTION';
				neMarker = new google.maps.Marker({
				  map: map,
				  icon: "images/purple-arrow.png",
 //         		  position: new google.maps.LatLng(topLeftLat, topLeftLon),
				  position: new google.maps.LatLng(topRightLat,topRightLng),
				  
				  
				  draggable: true,
				  title: title
				});
				/*
				if(!isReDrawn) {
	 				botLeftLat = parseFloat(bigLat) - (within * ONELAT);
	 				botLeftLng = parseFloat(bigLon) - (within * ONELON);	
				}
				*/
				title = 'DRAG ME ANY DIRECTION';
				
				swMarker = new google.maps.Marker({
				  map: map,
				  icon: "images/purple-arrow.png",
 //         		  position: new google.maps.LatLng(topLeftLat, topLeftLon),
				  position: new google.maps.LatLng(botLeftLat,botLeftLng),
				  
				  
				  draggable: true,
				  title: title
				});
       			google.maps.event.addListener(neMarker, 'mouseup', updater);
        		google.maps.event.addListener(swMarker, 'mouseup', updater);
       			rectangle = new google.maps.Rectangle({
          			map: map,
					strokeColor: "#aa0000",
				  	fillOpacity: 0.1,		
					strokeOpacity: 0.8,
					strokeWeight: 2
					
        		});
 //        		if(isReDrawn==false) {alert("redraw");redraw()}
				redraw();
          				
				/*
				 var flightPlanCoordinates = [
					new google.maps.LatLng(topLeftLat, topLeftLon),
					new google.maps.LatLng(topRightLat,topRightLon),
					new google.maps.LatLng(botRightLat, botRightLon),
					
					new google.maps.LatLng(botLeftLat, botLeftLon),
 					
					
				  ];
				  var flightPath = new google.maps.Rectangle({
					path: flightPlanCoordinates,
					strokeColor: "#aa0000",
					strokeOpacity: 0.8,
					strokeWeight: 2
				  });
				
				  flightPath.setMap(map);				
				  */
				
	/*			
				var rad = 1000 * radius;
				// Add a Circle overlay to the map.
				
				var circle = new google.maps.Circle({
				  map: map,
				  fillOpacity: 0.1,	
				  strokeColor: "#a00",
				  strokeWeight: 2,
				  radius: rad // 3000 km
				});
				// Since Circle and Marker both extend MVCObject, you can bind them
				// together using MVCObject's bindTo() method.  Here, we're binding
				// the Circle's center to the Marker's position.
				// http://code.google.com/apis/maps/documentation/v3/reference.html#MVCObject
				circle.bindTo('center', marker, 'position');
*/				
			}  //if showmap
			document.getElementById("sidebar").scrollTop = 0; 
			
 			if($("sidebar").scrollHeight > $("sidebar").clientHeight) {
				var l = $("gridhead").clientWidth;
 				$("statushead").style.width = (l-17) + "px";
			} else $("statushead").style.width = "100%";
	   	  	if(!gridCount && (bigUser.length < 2 || bigUser=="0000")) {
		  		showLoader();
			}
//			if(firstTime) $("land").style.display = "block";
   			firstTime = false;
		} else if (choice != "email") {  //landing
			spin2Off();
  			document.getElementById(choice).innerHTML=xmlHttp.responseText;
  		} 
 	}

}

function GetXmlHttpObject()
{
var xmlHttp=null;
try
 {
 // Firefox, Opera 8.0+, Safari
 xmlHttp=new XMLHttpRequest();
 }
catch (e)
 {
 //Internet Explorer
 try
  {
  xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
  }
 catch (e)
  {
  xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
 }
return xmlHttp;
}


// deletes a sidebar item
SidebarItem.prototype.remove = function(){
  if(!this.div) return false;
   this.div.removeChild(this.button);
  return true;
}


function showUser() {
 	str = "<h4>" +  bigName + "</h4>";
	str += "<div id=spin2></div>";
	$("landing").innerHTML = str;
 
}


function pause(milliseconds) {
	var dt = new Date();
	while ((new Date()) - dt <= milliseconds) { /* Do nothing */ }
}


function hideDiv() { 
if (document.getElementById) { // DOM3 = IE5, NS6 
document.getElementById('hideshow').style.visibility = 'hidden'; 
} 
else { 
if (document.layers) { // Netscape 4 
document.hideshow.visibility = 'hidden'; 
} 
else { // IE 4 
document.all.hideshow.style.visibility = 'hidden'; 
} 
} 
}
 
function showDiv() { 
 if (document.getElementById) { // DOM3 = IE5, NS6 
  
 	document.getElementById('hideshow').style.visibility = 'visible'; 
 	
} 
else { 
if (document.layers) { // Netscape 4 
document.hideshow.visibility = 'visible'; 
} 
else { // IE 4 
document.all.hideshow.style.visibility = 'visible'; 
} 
} 
 } 

