// 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",0);></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";
	
 	  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 = signLand + $("criteria").offsetHeight + "px";
	$("landing").style.height = signLand + $("criteria").offsetHeight + "px";
  
}


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 = signLand + "px";
	$("landing").style.height = signLand + "px";
	$("lander").scrollTop = 0;
 	
}

function signMeUp() {
//	doChange("email",3);
 	spin2On();
   	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.dreamrealty.com/Belleair_real_estate_bt7425739.htm\",\"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 align="center"><span id="yaba"><a onclick="moreCriteria()" style="cursor:pointer;color:#a00;text-decoration:underline;">More search criteria...</a></span></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 += '<div id="criteria"></div>';


	    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 += '</table>';

		str += '</form>';
 		
 		str += '<div id=spin2><img src=images/spinner.gif></div>';
 		if(isIE) fudge = 55; else fudge = 25;
  		$("landing").innerHTML = str;
		signLand = $("landing").offsetHeight + fudge;
 		$("landing").style.height = signLand + "px";
		$("lander").style.height = signLand + "px";
		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()}>Searches</a><br><a onclick=if(bigUser){doChange('favorites',bigUser)}else{signMeUp()}>Favorites</a><br><a onclick=if(bigUser){doChange('profile',bigUser)}else{signMeUp()}>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(); 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 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 move the search area by dragging the blue circle.<br /> <img src=images/blue_dot_circle.png>";
 		str += "</p>";
	} else {
		str = "<h1>Dream Realty Emails Alerts<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(); 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() {
	$("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);	
}

