
	function convertIt(_v) {
		var _dollars=parseInt(_v);
		var _cents=parseInt((_v-_dollars)*100);
		var _negative=_dollars<0;
		if(_negative){_dollars=-_dollars;_cents=-_cents;}
		while(_cents.toString().length<2)_cents="0"+_cents;
		var _dA=_dollars.toString().split("");
		var _d="";
		for(var i=_dA.length-1;i>=0;i--) {
			var _comma="";
			if((_dA.length-i)%3==0 && i!=0)_comma=",";
			_d=_comma+_dA[i]+_d;
		}
		var _neg_sign=_negative?"-":"";
		var _result="$"+_neg_sign+_d;
		return _result;
	}
	
	function showStatTable() {
		document.getElementById("stats").style.display = '';
	}
	
	function showAbout() {
	var dteNow = new Date();
	var intYear = dteNow.getFullYear(); 
		alert("Mobile Statistical Application\n\n©" + intYear + " Bay East Association of REALTORS®.\n\nReal-time stats pulled from the MLS.\n\nInformation deemed accurate but not guaranteed.  ");
	}

	function clearCurrent() {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "activeCount");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "REOActive");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "PSSActive");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "pendingCount");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "REOPending");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "PSSPending");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "ListingsSoldMonthToDate");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "ListingsSoldYearToDate");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "monthSupply");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageListPriceSold");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "MedianListPriceSold");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageSoldPrice");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "SaleToListPriceRatio");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageDaysOnMarket");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageDollarSqFtListed");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageDollarSqFtSold");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "MostExpensiveListing");
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "LeastExpensiveListing");
	}

	function statMe() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets.php?city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					getAnswer(oXmlHttp.responseText);
				} else {
					getAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				getAnswer("loading");
			}
		};
		oXmlHttp.send(null);
	}
	
	function activeCount() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=activeCount&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "activeCount");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "activeCount");
			}
		};
		oXmlHttp.send(null);
	}

	
	function REOActive() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=REOActive&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "REOActive");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "REOActive");
			}
		};
		oXmlHttp.send(null);
	}
	
	function PSSActive() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=PSSActive&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "PSSActive");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "PSSActive");
			}
		};
		oXmlHttp.send(null);
	}
	
	function pendingCount() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=pendingCount&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "pendingCount");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "pendingCount");
			}
		};
		oXmlHttp.send(null);
	}
	
	function REOPending() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=REOPending&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "REOPending");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "REOPending");
			}
		};
		oXmlHttp.send(null);
	}
	
	function PSSPending() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=PSSPending&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "PSSPending");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "PSSPending");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	function ListingsSoldMonthToDate() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=ListingsSoldMonthToDate&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "ListingsSoldMonthToDate");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "ListingsSoldMonthToDate");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	function ListingsSoldYearToDate() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=ListingsSoldYearToDate&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "ListingsSoldYearToDate");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "ListingsSoldYearToDate");
			}
		};
		oXmlHttp.send(null);
	}
	
	function monthSupply() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=monthSupply&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "monthSupply");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "monthSupply");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	function AverageListPriceSold() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=AverageListPriceSold&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "AverageListPriceSold");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageListPriceSold");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	function MedianListPriceSold() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=MedianListPriceSold&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "MedianListPriceSold");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "MedianListPriceSold");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	function AverageSoldPrice() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=AverageSoldPrice&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "AverageSoldPrice");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageSoldPrice");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	
	function SaleToListPriceRatio() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=SaleToListPriceRatio&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "SaleToListPriceRatio");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "SaleToListPriceRatio");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	
	function AverageDaysOnMarket() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=AverageDaysOnMarket&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "AverageDaysOnMarket");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageDaysOnMarket");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	
	function AverageDollarSqFtListed() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=AverageDollarSqFtListed&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "AverageDollarSqFtListed");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageDollarSqFtListed");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	function AverageDollarSqFtSold() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=AverageDollarSqFtSold&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "AverageDollarSqFtSold");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "AverageDollarSqFtSold");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	
	
	function MostExpensiveListing() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=MostExpensiveListing&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "MostExpensiveListing");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "MostExpensiveListing");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	function LeastExpensiveListing() {
		var city = document.getElementById("citySelect").value;
		var type = document.getElementById("typeSelect").value;
		var oXmlHttp = zXmlHttp.createRequest();
		oXmlHttp.open("get", "includes/rets_refined.php?query=LeastExpensiveListing&city=" + city + "&type=" + type, true);
		oXmlHttp.onreadystatechange = function () {
			if (oXmlHttp.readyState == 4) {
				if (oXmlHttp.status == 200) {
					fillAnswer(oXmlHttp.responseText, "LeastExpensiveListing");
				} else {
					fillAnswer("An error occurred: " + oXmlHttp.statusText); //statusText is not always accurate
				}
			} else {
				fillAnswer("<img src=\"images/ajax-loader.gif\" />", "LeastExpensiveListing");
			}
		};
		oXmlHttp.send(null);
	}
	
	
	
	
	function getAnswer(properti) {
		var properties = document.getElementById("stats");
		properties.innerHTML = properti;
	}
	
	function fillAnswer(properti, id) {
		var properties = document.getElementById(id);
		properties.innerHTML = properti;
	}
