
function getComparisonHTML(showForm){var r="";var idList="";var favoriteCount=0;var bathHTML;var averagePrice=0,medianPrice=0;var streetAddress;var town;var price;var priceTrend;var soldDate;var bedroomCount;var bathroomCount;var houseAge;var houseSize;var lotSize;var lotFrontage;var lotDepth;var daysOnMarket;var brokerage;var realtor;var realtorPhone;var realtorEmail;var realtorURL;var description;var features;var basement;var pictureCount;var picArray;var propertyCategory;var propertyStyle;var mlsNumber;var coords;var i,j,c2;var count;var list;var czInfo,c,z;var iSorted;var iPrev;var featureArray;var rows;var d=new Date();r+="<html>";r+="<head>";r+="<title>Compare Favourites</title>";if(showForm){r+="<script>";r+="var kMapName = \""+kMapName+"\";";r+="var kUserData = \""+kUserData+"\";";r+="var kMapServerURL = \""+kMapServerURL+"\";";r+="</script>";r+="<script src='map/libraries/XMLHttpRequest.js'></script>";r+="<script src='"+kMapName+"/data/map-constants.js'></script>";r+="<script src='"+kUserData+"/"+kMapName+"-userdata.js'></script>";r+="<script src='map/code/map-common.js'></script>";r+="<script src='map/code/map-send-sheet.js'></script>";}
r+="</head>";r+="<body>";if(showForm){r+="<div style='font-family: Arial, sans-serif; font-size: 12pt;'>";r+="<div id='buttons' style='text-align: center;'>";r+="<form style='margin: 0px;'>";r+="<input type=button value='Print Comparison' onclick='document.getElementById(\"buttons\").style.display=\"none\"; window.print(); document.getElementById(\"buttons\").style.display=\"\";'> ";r+="<input type=button value='Email Comparison' onclick='document.getElementById(\"buttons\").style.display=\"none\"; document.getElementById(\"emailEntry\").style.display=\"\"; document.emailForm.recipient.focus();'>";r+="</form>";r+="</div>";r+="<div id='emailEntry' style='text-align: center; display: none;'>";r+="<div style='font-weight: bold;'>Send Comparison by Email</div>";r+="<p>";r+="<form id='emailForm'>";r+="<input type='hidden' name='required' value='recipient,email'>";r+="<input type='hidden' name='content' value=\"Comparison of Favourite Properties -- view in HTML mode.\">";r+="<input type='hidden' name='contentHTML' value=\""+getComparisonHTML(false)+"\">";r+="Recipient email address<br><input name='recipient' style='width: 200px;'><br>";r+="<span style='font-size: 10pt;'>(Separate multiple email addresses with a comma)</span><p>";r+="Your email address<br><input name='email' style='width: 200px;'><br>";r+="<span style='font-size: 10pt;'><input type=checkbox name='copySender' checked>Send a copy to your email address</span><p>";r+="Subject<br><input type='text' name='subject' style='width: 500px;' value=\""+kComparisonSubject+"\"><p>";r+="Email message<br><textarea name='note' rows=6 style='width: 500px;'>";r+=kComparisonMsg;r+="</textarea><p>";r+="<table align=center style='font-size: 10pt;'><tr><td>";r+="<img id='captcha' src='"+kCaptchaFolder+"securimage_show.php' border=2>";r+="<td align=center>";r+="Type security word<br>";r+="<i>Not case sensitive</i><br>";r+="<a href='javascript:void(0)' onclick='document.getElementById(\"captcha\").src = \""+kCaptchaFolder+"securimage_show.php?\" + Math.random(); return false;'>Show a New Word</a><br>";r+="<input type='text' name='captcha_code' size='10' maxlength='6'><br>(required)";r+="</table>";r+="<div id='emailStatus' style='color: red; font-weight: bold;'></div>";r+="<input type='button' value='Cancel' onclick='cancelEmailForm();'> ";r+="<input type='submit' value='Send Email' onclick='submitEmailForm(); return false;'>";r+="</form>";r+="</div>";r+="</div>";}
r+="<hr ";r+=">";r+="<table width='100%' align=center style='font-family: Arial, sans-serif; font-size: 10pt;'>";r+="<tr><td align=center width=150>";if(kShowSheetBranding&&(kAgentPhotoURL!="")){r+="<img src='"+kAgentPhotoURL+"'>";}else{r+="<img src='"+kAgentBrokerageLogoBigURL+"'>";}
r+="<td align=center style='background-color: #FFEBCD; border: 1px solid black'>Presented by:<br><span style='font-weight: bold; font-size: 14pt;'>";if(kShowSheetBranding){r+=kAgentBizName;r+="</span><br>"+kAgentBrokerageName;r+="<br>Phone: "+kAgentPhone;r+="<br>Email: "+kAgentEmail;if(kAgentWebSite!=""){r+="<br>Web site: "+kAgentWebSite;}}else{r+=kAgentBrokerageName;r+="</span><br>";r+="<br>Phone: "+kAgentBrokeragePhone;if(kAgentBrokerageEmail!=""){r+="<br>Email: "+kAgentBrokerageEmail;}
if(kAgentBrokerageWebSite!=""){r+="<br>Web site: "+kAgentBrokerageWebSite;}}
r+="<br>"+kMonthNames[d.getMonth()]+" "+d.getDate()+", "+d.getFullYear();r+="<td align=center width=150><img src='"+kAgentBrokerageLogoBigURL+"'>";if(!showForm){for(i=1;i<=gPropertyCount;i++){if(propertyDB[i].isMarked){idList+=propertyDB[i].theMLSnumber+",";favoriteCount++;}}
idList=idList.substring(0,idList.length-1);czInfo=getCenterOfProperties(idList);c=czInfo.c;c=c.lat().toFixed(4)+","+c.lng().toFixed(4);z=czInfo.z;r+="<tr align=center><td colspan=3>";r+="<a href='"+gBaseURL+"?favorites="+idList+"&favonly=on"+kMapAnchorName+"'>";r+="Click here";r+="</a>";r+=" to view all "+favoriteCount+" properties on an interactive real estate map.";}
r+="</table>";r+="<hr>";rows=new StringBuffer();c=0;for(i=1;i<=gPropertyCount;i++){if(gSortOrder==0){iSorted=i;}else{iSorted=gPropertyCount+1-i;}
if(propertyDB[iSorted].isMarked){streetAddress=propertyDB[iSorted].theStreetAddress;town=propertyDB[iSorted].theTown;price=propertyDB[iSorted].thePrice;priceTrend=propertyDB[iSorted].thePriceTrend;soldDate=propertyDB[iSorted].theSoldDate;bedroomCount=propertyDB[iSorted].theBedroomCount;bathroomCount=propertyDB[iSorted].theBathroomCount;houseAge=propertyDB[iSorted].theHouseAge;houseSize=propertyDB[iSorted].theHouseSize;lotSize=propertyDB[iSorted].theLotSize;lotFrontage=propertyDB[iSorted].theLotFrontage;lotDepth=propertyDB[iSorted].theLotDepth;daysOnMarket=propertyDB[iSorted].DOM;brokerage=propertyDB[iSorted].theBrokerage;realtor=propertyDB[iSorted].theRealtor;realtorPhone=propertyDB[iSorted].theRealtorPhone;realtorEmail=propertyDB[iSorted].theRealtorEmail;realtorURL=propertyDB[iSorted].theRealtorURL;description=propertyDB[iSorted].theDescription;features=propertyDB[iSorted].theFeatures;basement=propertyDB[iSorted].theBasement;pictureCount=propertyDB[iSorted].thePictureCount;propertyCategory=propertyDB[iSorted].thePropertyCategory;if(propertyCategory=="Lot"){propertyCategory="Vacant Lot";}
propertyStyle=propertyDB[iSorted].thePropertyStyle;mlsNumber=propertyDB[iSorted].theMLSnumber;coords=propertyDB[iSorted].theMarker.getPosition();averagePrice+=price;picArray=propertyDB[iSorted].thePictureList.split(" ");if((c%4)==0){if(c>0){rows.append("</table>");if((c%8)==0){if(showForm){rows.append("<hr style='page-break-before: always; margin: 0px;'>");}else{rows.append("<hr style='margin: 0px;'>");}}else{rows.append("<hr style='margin: 0px;'>");}}
rows.append("<table width='100%' style='font-family: Arial, sans-serif; font-size: 8pt;'>");rows.append("<tr align=center>");}
c++;rows.append("<td valign=top>");if(soldDate!=""){rows.append("<span style='color: red; font-weight: bold;'>");rows.append("Sold ");rows.append("</span>");}
rows.append("<span style='color: green; font-size: 12pt; font-weight: bold;'>"+formatPrice(price)+priceTrend+"</span><br>");if(pictureCount>0){rows.append("<img src='"+picArray[0]+"' height=78><br>");}else{rows.append("<img src='"+kSpacerURL+"' height=78><br>");}
rows.append("<b>"+streetAddress+"</b><br>");rows.append(town+"<br>");rows.append(mlsNumber);rows.append("<table width=170 style='font-family: Arial, sans-serif; font-size: 8pt;'>");rows.append("<tr align=center><td colspan=2>"+propertyCategory);rows.append("<tr align=center><td colspan=2>");if(propertyStyle!="NA"&&propertyStyle!==""){rows.append(propertyStyle);}else{rows.append("<br>");}
rows.append("<tr><td>Bedrooms:<td>");if(bedroomCount>0){rows.append(bedroomCount);}
rows.append("<tr><td>Bathrooms:<td>");if(bathroomCount>0){bathHTML=""+Math.floor(bathroomCount);if(bathroomCount!=Math.floor(bathroomCount)){bathHTML=bathHTML+"&frac12;";}
rows.append(bathHTML);}
rows.append("<tr><td>Size of Home:<td>");if(houseSize>0){rows.append(formatNumber(houseSize)+" sq.ft.");}
if(basement!==""){}
rows.append("<tr><td>Lot Size:<td>");if(lotSize!==""&&lotSize!="0"&&lotSize!="NA"){if(lotSize.indexOf(" (")==-1){rows.append(lotSize);}else{rows.append(lotSize.substring(0,lotSize.indexOf(" (")));}}
rows.append("<tr><td>Lot Frontage:<td>");if(lotFrontage!==""&&lotFrontage!="0"&&lotFrontage.toLowerCase()!="not available"){rows.append(lotFrontage);}
rows.append("<tr><td>Lot Depth:<td>");if(lotDepth!==""&&lotDepth!="0"&&lotDepth.toLowerCase()!="not available"){rows.append(lotDepth);}
rows.append("<tr><td>Age of Home:<td>");if(houseAge!==""){if(houseAge=="0"){houseAge="New";}
rows.append(houseAge);houseAge=parseInt(houseAge,10);if(houseAge>0){rows.append(" year");if(houseAge!=1){rows.append("s");}}}
rows.append("<tr align=center><td colspan=2>"+brokerage.replace(/\'/g,"&#146;"));if(!kShowSheetBranding){if(brokerage.toLowerCase()==kAgentBrokerageName.toLowerCase()){rows.append("<br>"+realtor.replace(/\'/g,"&#146;")+"<br>"+realtorPhone);}else{rows.append("<br>-<br>-");}}
rows.append("</table>");rows.append("<table style='font-family: Arial, sans-serif; font-size: 8pt;'>");rows.append("<tr><td>");rows.append("<ul>");if(features!==""&&features.toLowerCase()!="not available"){featureArray=features.split(", ");for(j=0;j<featureArray.length;j++){rows.append("<li>"+featureArray[j]);}}
rows.append("</ul>");rows.append("</table>");}}
r+=rows.toString();r+="</table>";c2=0;for(i=1;i<=gPropertyCount;i++){if(propertyDB[i].isMarked){c2++;if(c2==(parseInt(c/2,10)+1)){if((c%2)==0&&(c>1)){medianPrice=(propertyDB[i].thePrice+propertyDB[iPrev].thePrice)/2;}else{medianPrice=propertyDB[i].thePrice;}
break;}
iPrev=i;}}
r+="<hr>";r+="<table width='100%' style='font-family: Arial, sans-serif; font-size: 12pt; font-weight: bold;'>";r+="<tr>";r+="<td align=left>Average Price: "+formatPrice(averagePrice/c);r+="<td align=center>"+c;if(c>1){r+=" properties";}else{r+=" property";}
r+="<td align=right>Median Price: "+formatPrice(medianPrice);r+="</table>";r+="<hr>";r+="<div style='font-size: 8pt; font-style: italic; text-align: center;'>";r+="This communication is not intended to cause or induce breach of an existing agency agreement.";r+="<p>";r+="</div>";if(showForm){r+="<hr style='page-break-before: always; margin: 0px;'>";}else{r+="<hr style='margin: 0px;'>";}
r+="<br><center>";r+="<img src='"+kStaticMapGoogleURL+"?size=900x600&maptype=roadmap";count=0;list="";for(i=1;i<=gPropertyCount;i++){if(gSortOrder==0){iSorted=i;}else{iSorted=gPropertyCount+1-i;}
if(propertyDB[iSorted].isMarked){count++;if(count<10){r+="&markers=color:red|label:"+count+"|";r+=propertyDB[iSorted].theMarker.getPosition().lat();r+=",";r+=propertyDB[iSorted].theMarker.getPosition().lng();list+="<li>";list+=propertyDB[iSorted].theStreetAddress;list+=" -- ";list+=formatPrice(propertyDB[iSorted].thePrice);}}}
r+="&sensor=false' border=2>";r+="</center>";r+="<ol>"+list+"</ol>";if(count>9){r+="Note: Only the first 9 properties have been mapped.";}
r+="</body>";r+="</html>";return r;}
function showComparison(){var w;w=window.open('','','left=0,top=0,width=815,height=850,scrollbars=1,resizable=1,toolbar=0,location=0,directories=0,status=0,menubar=0');w.document.write(getComparisonHTML(true));w.document.close();}
