// search map has its own js file, but still uses common
// ###############################################################################################################################################
//	COMMON FUNCTIONS - used on several pages
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	formatDollars2(unformatted)
//		called by
//			getComps()
// 

// GLOBAL VARS
// icons
var iconBlue, iconRed, iconYellow, iconGreen, customIcons, icon_CL;
	
	
function formatDollars2(unformatted) {
	// huh?
	unformatted += '';
	var x, x1, x2, rgx;
	x = unformatted.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return '$' + x1;
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	chkCharacter(data)
//		called by
//			NOT CURRENTLY USED
// 
function chkCharacter(data) {
	var success = false, 
		iChars = "!@#$%^&*()+=-[]\\\';,./{}|\":<>?~", 
		i;

	for (i = 0; i < data.length; i++) {
		if (iChars.indexOf(data.charAt(i)) !== -1) {
			success = true;
			break;
		}
	}
	return success;
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	stripBadData (str)
//		called by
//			submitContact()
//			idxSetMapArea()
// 			download_data () - s_map_x_x_x.js
// 
function stripBadData(str) {
	//alert(str);
	var myRegExp = /^~+|\!+|\@+|\$+|\%+|\^+|&+|\*+|\(+|\)+|\++|\=+|\\+|'+|"+/ig;
	str = str.replace(myRegExp, '');
	//alert(str);
	return str;
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	countWords(string)
//		called by
//			findAddress()
// 
function countWords(string) {
	var num = 0,
		s = string.split(' '), 
		z;
	//string.replace(/\s/g,' ');
	for (z = 0; z < s.length; z++) {
		if (s[z].length > 0) {
			num++;
		}
	}
	return num;
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	tF2yN(val)
//		called by
//			NOT CURRENTLY USED
// 
function tF2yN(val) {
	var valYN;
	if (val) {
		valYN = 'Yes';
	}
	if (!val) {
		valYN = 'No';
	}
	return valYN;
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	getCookie(c_name)
//		called by
//			checkCookie()
//			setCookieMapReset()
//			sm_load() - s_map_x_x_x.js
// 
// If cookie exists, get cookie string
// Else return empty string
function getCookie(c_name) {
	var c_start, c_end;
	if (document.cookie.length > 0) {
		c_start = document.cookie.indexOf(c_name + "=");
		if (c_start !== -1) {
			c_start = c_start + c_name.length + 1;
			c_end = document.cookie.indexOf(";", c_start);
			if (c_end === -1) {
				c_end = document.cookie.length;
			}
			return unescape(document.cookie.substring(c_start, c_end));
		}
	}
	return "";
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	setCookie(c_name,value,expiredays)
//		called by 
//			checkCookie()
//			setCookieMapReset()
// 
function setCookie(c_name, value, expiredays) {
	var exdate, cookieVal;
	exdate = new Date();
	exdate.setDate(exdate.getDate() + expiredays);
	cookieVal = c_name + "=" + escape(value) + ((expiredays === null) ? "" : ";expires=" + exdate.toGMTString()) + "; path=/";
	//alert(cookieVal);
	document.cookie = cookieVal;
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	checkCookie()
//		called by 
//			search_map.php onload event
// 
// map_session cookie
// 0 = mlsid, 1=street_address, 2=city_zip, 3=property_type, 4=price_min, 5=price_max, 6=beds, 7=baths, 8=sqft_min, 9=sqft_max, 10=ll_ll, 11=ll_ur, 12=mcLat, 13=mcLng, 14=mz, 15=fullAddress, 16=mapextReset
//
function checkCookie() {
	// these used to be global
	var map_session, msArr;
	map_session = getCookie('map_session');
	// if cookie is set, fill in the search form values based on the cookie
	if (map_session !== null && map_session !== "") {
		//alert('set cookie section -- Map session cookie: '+map_session);
		// 
		msArr = map_session.split('~');
		//alert('set cookie section -- msArr: ' + msArr);
		if (msArr[0] !== null && msArr[0] !== "") {
			document.getElementById("f_mlsid").value = msArr[0];
		}
		if (msArr[1] !== null && msArr[1] !== "") {
			document.getElementById("f_street_address").value = msArr[1];
		}
		// TESTING
		//if (msArr[2]!==null && msArr[2]!=="") {document.getElementById("f_city_zip").value = msArr[2];}
		
		// property type is an issue - before multiple types were not allowed, now they are and its broken
		//if (msArr[3]!=null && msArr[3]!="") {document.getElementById("f_prop_type").value = msArr[3];}
		
		if (msArr[4] !== null && msArr[4] !== "") {
			document.getElementById("f_price_min").value = msArr[4];
		}
		if (msArr[5] !== null && msArr[5] !== "") {
			document.getElementById("f_price_max").value = msArr[5];
		}
		if (msArr[6] !== null && msArr[6] !== "") {
			document.getElementById("f_beds").value = msArr[6];
		}
		if (msArr[7] !== null && msArr[7] !== "") {
			document.getElementById("f_baths").value = msArr[7];
		}
		if (msArr[8] !== null && msArr[8] !== "") {
			document.getElementById("f_sqft_min").value = msArr[8];
		}
		if (msArr[9] !== null && msArr[9] !== "") {
			document.getElementById("f_sqft_max").value = msArr[9];
		}
	}
	// if cookie is NOT set, create it and set it to nothing
	else {
		//map_session=prompt('Please enter your name:',"");
		map_session = '';
		if (map_session !== null && map_session !== "") {
			setCookie('map_session', map_session, 1);
		}
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	setCookieMapReset()
//		called by 
//			Home Page links
// 
// Set the map reset cookie value so search map knows to reset the map extent to the 
// desired geographic area described by each link on the home page.
//
function setCookieMapReset(resetVal) {
	var map_session, msArr;
	map_session = getCookie('map_session');
	// if cookie is set, split it into an array
	if (map_session !== null && map_session !== "") {
		//alert('set cookie section -- Map session cookie: '+map_session);
		msArr = map_session.split('~');
	}
	// if cookie is NOT set, create an empty array
	else {
		//map_session=prompt('Please enter your name:',"");
		msArr = new Array(17);
	}
	// set the mapreset value to either TRIUE or FALSE - passed to the function
	msArr[16] = resetVal;		
	map_session = msArr.join('~');
	//alert("setCookieMapReset(resetVal) -- map_session var :" + map_session);
	setCookie('map_session', map_session, 1);
}

// this deletes the cookie when called
function delete_cookie_1(name, path, domain) {
	if (getCookie(name)) {
		document.cookie = name + "=" +
		((path) ? ";path=" + path : "") +
		((domain) ? ";domain=" + domain : "") +
		";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

function del_cookie(name) {
	if (getCookie(name)) {
		document.cookie = name +
		'=; expires=Thu, 01-Jan-70 00:00:01 GMT;';
	}
}



//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	GLOBAL VARS 
//		called by
//			pi_GM_load()
//			sm_load() - s_map_x_x_x.js
//
//  google marker icon definitions
// 
function setIconVars() {

	iconBlue = new GIcon(); 
	iconBlue.image = 'http://labs.google.com/ridefinder/images/mm_20_blue.png';
	iconBlue.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	iconBlue.iconSize = new GSize(12, 20);
	iconBlue.shadowSize = new GSize(22, 20);
	iconBlue.iconAnchor = new GPoint(6, 20);
	iconBlue.infoWindowAnchor = new GPoint(5, 1);

	iconRed = new GIcon(); 
	iconRed.image = 'http://labs.google.com/ridefinder/images/mm_20_red.png';
	iconRed.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	iconRed.iconSize = new GSize(12, 20);
	iconRed.shadowSize = new GSize(22, 20);
	iconRed.iconAnchor = new GPoint(6, 20);
	iconRed.infoWindowAnchor = new GPoint(5, 1);
		
	iconYellow = new GIcon(); 
	iconYellow.image = 'http://labs.google.com/ridefinder/images/mm_20_yellow.png';
	iconYellow.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	iconYellow.iconSize = new GSize(12, 20);
	iconYellow.shadowSize = new GSize(22, 20);
	iconYellow.iconAnchor = new GPoint(6, 20);
	iconYellow.infoWindowAnchor = new GPoint(5, 1);

	iconGreen = new GIcon(); 
	iconGreen.image = 'http://labs.google.com/ridefinder/images/mm_20_green.png';
	iconGreen.shadow = 'http://labs.google.com/ridefinder/images/mm_20_shadow.png';
	iconGreen.iconSize = new GSize(12, 20);
	iconGreen.shadowSize = new GSize(22, 20);
	iconGreen.iconAnchor = new GPoint(6, 20);
	iconGreen.infoWindowAnchor = new GPoint(5, 1);

	customIcons = [];
	customIcons["00"] = iconGreen;
	customIcons["01"] = iconRed;
	customIcons["04"] = iconYellow;
	customIcons["999"] = iconBlue;

	icon_CL = new GIcon();
	icon_CL.image = 'http://gmaps-samples.googlecode.com/svn/trunk/markers/circular/greencirclemarker.png';
	icon_CL.iconSize = new GSize(32, 32);
	icon_CL.iconAnchor = new GPoint(16, 16);
	icon_CL.infoWindowAnchor = new GPoint(25, 7);

}

//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	createMarker(point, type, cmp_addr, cmp_bldgsf, cmp_date, cmp_price, cmp_bed, cmp_bath)
//		called by
//			getComps()
// 
function cmp_createMarker(point, type, cmp_addr, cmp_bldgsf, cmp_date, cmp_price, cmp_bed, cmp_bath) {
	//alert("BEGIN cmp_createMarker");
	//alert(customIcons);
	var marker, html;
	marker = new GMarker(point, customIcons[type]);

	html = '<p style="font-size:9pt;margin:-2px;text-align:left;">' + 
		cmp_addr + '<p>Last Sale: ' + cmp_date + '  ' + cmp_price + '<br>' + cmp_bldgsf + ' sqft  ' + 
		cmp_bed + ' Beds ' + cmp_bath + ' Baths<br>';

	GEvent.addListener(marker, 'click', function() {
		marker.openInfoWindowHtml(html);
	});
	GEvent.addListener(marker, 'mouseover', function() {
		marker.openInfoWindowHtml(html);
	});
	return marker;
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	removeTableRows(tableid)
//		called by
//			getComps()
// 
function removeTableRows(tableid) { 
    var table, rows;
	table = document.getElementById(tableid); 
    rows = table.rows; 
    while (rows.length > 2) { // length=0 -> stop 
        table.deleteRow(rows.length - 1);
	}
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	RemoveAllChildren(PARENT)
//		called by
//			download_data() - s_map_x_x_x.js
// 
function RemoveAllChildren(PARENT) {	
	while (PARENT.hasChildNodes()) {
		PARENT.removeChild(PARENT.childNodes[0]);
	}
}
//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	BuildTable2Record(cmp_addr,cmp_subd,cmp_date,cmp_price,cmp_heatsf,cmp_bldgsf,cmp_yrblt,cmp_bed,cmp_bath,cmp_pool,cmp_waterfront,cmp_landsf,cmp_ppsf)
//		called by
//			getComps()
// 
function BuildTable2Record(cmp_addr, cmp_subd, cmp_date, cmp_price, cmp_heatsf, cmp_bldgsf, cmp_yrblt, cmp_bed, cmp_bath, cmp_pool, cmp_waterfront, cmp_landsf, cmp_ppsf) {
	var tblBody, newRow, newCell_0, newCell_1, newCell_2, newCell_3,
		newCell_4, newCell_5, newCell_6, newCell_7, newCell_8, newCell_9,
		newCell_10, newCell_11, newCell_12, newCell_13;
	
	tblBody = document.getElementById("CompTable").tBodies[0];
	newRow = tblBody.insertRow(-1);
	
	// !! CAN'T WE USE CLASSES HERE?

	newCell_0 = newRow.insertCell(0);
	newCell_0.style.width = "4px";
	newCell_0.style.borderTop = "1px solid #CCCCCC";
	//newCell0.innerHTML = '<input type="checkbox" name="1" value="1">'  ;

	newCell_1 = newRow.insertCell(1);
	newCell_1.style.width = "290px";
	newCell_1.style.fontSize = "8pt";
	newCell_1.style.textTransform = "capitalize";
	newCell_1.style.borderTop = "1px solid #CCCCCC";
	newCell_1.innerHTML = cmp_addr;

	newCell_2 = newRow.insertCell(2);
	newCell_2.style.width = "150px";
	newCell_2.style.fontSize = "8pt";
	newCell_2.style.textTransform = "capitalize";
	newCell_2.style.borderTop = "1px solid #CCCCCC";
	newCell_2.innerHTML = cmp_subd;
	
	newCell_3 = newRow.insertCell(3);
	newCell_3.style.width = "55px";
	newCell_3.style.fontSize = "8pt";
	newCell_3.style.borderTop = "1px solid #CCCCCC";
	newCell_3.innerHTML = cmp_price;
	
	newCell_4 = newRow.insertCell(4);
	newCell_4.style.width = "60px";
	newCell_4.style.fontSize = "8pt";
	newCell_4.style.borderTop = "1px solid #CCCCCC";
	newCell_4.innerHTML = cmp_date;
	
	newCell_5 = newRow.insertCell(5);
	newCell_5.style.width = "60px";
	newCell_5.style.fontSize = "8pt";
	newCell_5.style.borderTop = "1px solid #CCCCCC";
	newCell_5.innerHTML = cmp_ppsf;

	newCell_6 = newRow.insertCell(6);
	newCell_6.style.width = "35px";
	newCell_6.style.fontSize = "8pt";
	newCell_6.style.borderTop = "1px solid #CCCCCC";
	newCell_6.innerHTML = cmp_heatsf;
	
	newCell_7 = newRow.insertCell(7);
	newCell_7.style.width = "35px";
	newCell_7.style.fontSize = "8pt";
	newCell_7.style.borderTop = "1px solid #CCCCCC";
	newCell_7.innerHTML = cmp_bldgsf;
	
	newCell_8 = newRow.insertCell(8);
	newCell_8.style.width = "30px";
	newCell_8.style.fontSize = "8pt";
	newCell_8.style.borderTop = "1px solid #CCCCCC";
	newCell_8.innerHTML = cmp_bed;
	
	newCell_9 = newRow.insertCell(9);
	newCell_9.style.width = "30px";
	newCell_9.style.fontSize = "8pt";
	newCell_9.style.borderTop = "1px solid #CCCCCC";
	newCell_9.innerHTML = cmp_bath;

	newCell_10 = newRow.insertCell(10);
	newCell_10.style.width = "35px";
	newCell_10.style.fontSize = "8pt";
	newCell_10.style.borderTop = "1px solid #CCCCCC";
	newCell_10.innerHTML = cmp_yrblt;
	
	newCell_11 = newRow.insertCell(11);
	newCell_11.style.width = "30px";
	newCell_11.style.fontSize = "8pt";
	newCell_11.style.borderTop = "1px solid #CCCCCC";
	newCell_11.innerHTML = cmp_landsf;
	
	newCell_12 = newRow.insertCell(12);
	newCell_12.style.width = "30px";
	newCell_12.style.fontSize = "8pt";
	newCell_12.style.borderTop = "1px solid #CCCCCC";
	newCell_12.innerHTML =  cmp_pool;
	//alert("HEY");
	//newCell_13 = newRow.insertCell(13);
	//newCell_13.style.width = "30px";
	//newCell_13.style.fontSize = "8pt";
	//newCell_13.style.borderTop = "1px solid #CCCCCC";
	//newCell_13.innerHTML = cmp_waterfront;
	

	//document.getElementById(SubjectContainer).style.visibility = "visible";
	//document.getElementById(CompsContainer).style.visibility = "visible";

	// makes the table appear on the page
	document.getElementById('CompTable').style.display = "";
	// table should be built and displayed
}



//	COMMON
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	getComps(a_street,a_city,a_zipcode,a_county,taxid,taxid3,zoom)
//		called by
//			findAddress()
//			property_info.php initialization inline javascript
// 
function getComps(a_street, a_city, a_zipcode, a_county, taxid, taxid3, zoom) {
	var err, sr_url;
	removeTableRows('CompTable');
	document.getElementById("subject_status").innerHTML = "";
	document.getElementById("comp_status").innerHTML = "";
	
	if (taxid !== '') {
		sr_url = '/cgi-bin/proxy.cgi?url=http://florida.imapp.com/avm/comps.xml?pid=' + taxid3 + '&saledate=12&srid=4326&';
	}
	else {
		// appears county is now optional
		sr_url = '/cgi-bin/proxy.cgi?url=http://florida.imapp.com/avm/search.xml?addr=' + a_street + '&city=' + a_city + '&zip=' + a_zipcode  + '&srid=4326&';
	}

	//alert(sr_url);
	//return;
	GDownloadUrl(sr_url, function (data) {

		var xml, matches, matchesLength,
			criteriaInf, cr_saledate, cr_bed_count, cr_garage, cr_bldg_size, 
			cr_yr_built, cr_distance, cr_use_code, cr_stories, cr_pool, cr_land_size, 
			cr_bath_count, cr_fireplace, cr_waterfront, 
			subjectInf, subd, landsf, heatsf, bldgsf, yrblt, pool, 
			value, bath, bed, price, mktv, waterfront, date, addr, addr2, subj_x, subj_y, 
			type, point, marker,
			match, 
			projected, pv_min, pv_mid, pv_max, pv_value_min, pv_value_mid, pv_value_max, pv_ppsf_min, pv_ppsf_mid, pv_ppsf_max, 
			comparables, cmpLength, i, cmp_subd, cmp_mvr, cmp_garage, cmp_date, 
			cmp_sale_age, cmp_price, cmp_mktv, cmp_value, cmp_yrblt, cmp_heatsf, cmp_bldgsf, cmp_compsf, 
			cmp_bath, cmp_bed, cmp_pool, cmp_waterfront, cmp_landsf, cmp_addr, cmp_addr2, 
			cmp_vr, cmp_avr, cmp_q, cmp_ppsf,
			cmp_fireplace, cmp_assv, cmp_stories, cmp_sel, cmp_dist, cmp_x, cmp_y;
		
		xml = GXml.parse(data);

		// if multiple matches, say user needs to be more specific
		// common_1_0_9.js has an attempt to guess multiple matches
		try {
			matches = xml.documentElement.getElementsByTagName("matches");
			matchesLength = matches.length;
			//alert ("matchesLength " + matchesLength);
			// WTF?
			if (matchesLength > 0) {
				document.getElementById("subject_status").innerHTML = "<b>Multiple matches found. Please be more specific.</b>";
				return;
			}
		}
		catch (err) {
			alert("catch -- match -- matches = 0");
		}
		
		//alert ("HEY criteria ");
		try {
			//  CRITERIA - get the result count and display
			criteriaInf = xml.documentElement.getElementsByTagName("criteria");
			//alert ("start criteriaInf.length " + criteriaInf);
			if (criteriaInf.length === 0) {
				//alert ("criteriaInf.length = 0");
				document.getElementById("subject_status").innerHTML = "<b>Problem retrieving property, no matches found.</b>";
				return;
			}
			//alert ("criteriaInf.length " + criteriaInf.length);
			cr_saledate = criteriaInf[0].getElementsByTagName("saledate")[0].childNodes[0].nodeValue;
			cr_bed_count = criteriaInf[0].getElementsByTagName("bed_count")[0].childNodes[0].nodeValue;
			cr_garage = criteriaInf[0].getElementsByTagName("garage")[0].childNodes[0].nodeValue;
			cr_bldg_size = criteriaInf[0].getElementsByTagName("bldg_size")[0].childNodes[0].nodeValue;
			cr_yr_built = criteriaInf[0].getElementsByTagName("yr_built")[0].childNodes[0].nodeValue;
			cr_distance = criteriaInf[0].getElementsByTagName("distance")[0].childNodes[0].nodeValue;
			cr_use_code = criteriaInf[0].getElementsByTagName("use_code")[0].childNodes[0].nodeValue;
			cr_stories = criteriaInf[0].getElementsByTagName("stories")[0].childNodes[0].nodeValue;
			cr_pool = criteriaInf[0].getElementsByTagName("pool")[0].childNodes[0].nodeValue;
			cr_land_size = criteriaInf[0].getElementsByTagName("land_size")[0].childNodes[0].nodeValue;
			cr_bath_count = criteriaInf[0].getElementsByTagName("bath_count")[0].childNodes[0].nodeValue;
			cr_fireplace = criteriaInf[0].getElementsByTagName("fireplace")[0].childNodes[0].nodeValue;
			cr_waterfront = criteriaInf[0].getElementsByTagName("waterfront")[0].childNodes[0].nodeValue;
		}
		catch (err) {
			//alert("Problem retrieving Criteria");
			document.getElementById("subject_status").innerHTML = "<b>Problem retrieving property, no matches found.</b>";
			return;
		}

		
		try {
			// SUBJECT PropInfo - get the result count and display
			// ARE THESE ALWAYS GOING TO BE PRESENT?
			// IF SO, WE NEED TO GET RID OF ALL THESE TRY/CATCH
			try {
				subjectInf = xml.documentElement.getElementsByTagName("subject");
			}
			catch (err) {
				document.getElementById("subject_status").innerHTML = "<b>Subject property not found (no subject element)</b>";
			}
			try {
				subd = subjectInf[0].getElementsByTagName("subd")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				subd = 'n/a';
			}
			try {
				landsf = subjectInf[0].getElementsByTagName("landsf")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				landsf = 'n/a';
			}
			try {
				heatsf = subjectInf[0].getElementsByTagName("heatsf")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				heatsf = 'n/a';
			}
			try {
				bldgsf = subjectInf[0].getElementsByTagName("bldgsf")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				bldgsf = 'n/a';
			}
			if ((heatsf === '0') && (bldgsf > 0)) {
				heatsf = "n/a";
			}
			if ((bldgsf === '0') && (heatsf > 0)) {
				bldgsf = "n/a";
			}
			try {
				yrblt = subjectInf[0].getElementsByTagName("yrblt")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				yrblt = 'n/a';
			}
			try {
				pool = subjectInf[0].getElementsByTagName("pool")[0].childNodes[0].nodeValue;
				if (pool) {
					pool = 'Yes';
				}
				else if (!pool) {
					pool = 'No';
				}
				else {
					pool = 'n/a';
				}
			}
			catch (err) {
				pool = 'n/a';
			}
			
			try {
				value = subjectInf[0].getElementsByTagName("value")[0].childNodes[0].nodeValue;
				value = formatDollars2(value);
			}
			catch (err) {
				value = 'n/a';
			}
			
			try {
				bath = subjectInf[0].getElementsByTagName("bath")[0].childNodes[0].nodeValue;
				if ((bath === '0.0') || (bath === '0')) {
					bath = 'n/a';
				}
			}
			catch (err) {
				bath = 'n/a';
			}
			
			try {
				bed = subjectInf[0].getElementsByTagName("bed")[0].childNodes[0].nodeValue;
				if (bed === '0') {
					bed = 'n/a';
				}
			}
			catch (err) {
				bed = 'n/a';
			}
			
			try {
				price = subjectInf[0].getElementsByTagName("price")[0].childNodes[0].nodeValue;
				price = formatDollars2(price);
			}
			catch (err) {
				price = 'n/a';
			}
			
			try {
				mktv = subjectInf[0].getElementsByTagName("mktv")[0].childNodes[0].nodeValue;
				mktv = formatDollars2(mktv);
			}
			catch (err) {
				mktv = '';
			}
			
			try {
				waterfront = subjectInf[0].getElementsByTagName("waterfront")[0].childNodes[0].nodeValue;
				if (waterfront) {
					waterfront = 'Yes';
				}
				else if (!waterfront) {
					waterfront = 'No';
				}
				else {
					waterfront = 'n/a';
				}
			}
			catch (err) {
				waterfront = 'n/a';
			}
			
			try {
				date = subjectInf[0].getElementsByTagName("date")[0].childNodes[0].nodeValue;
				if (date === '') {
					date = 'n/a';
				}
			}
			catch (err) {
				date = 'n/a';
			}
			
			try {
				addr = subjectInf[0].getElementsByTagName("addr")[0].childNodes[0].nodeValue;
				addr2 = addr;
				addr = addr.replace(/<br>/g, ' ');
			}
			catch (err) {
				addr = 'n/a';
			}
			
			try {
				subj_x = subjectInf[0].getElementsByTagName("x")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				subj_x = '';
			}
			
			try {
				subj_y = subjectInf[0].getElementsByTagName("y")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				subj_y = '';
			}
		}
		catch (err) {
			alert("Problem retriving Subject info");
			document.getElementById("subject_status").innerHTML = "<b>Subject property not found (no subject element)</b>";
		}
		
		
		try {
			// add subject property to map
			type = '01';
			//alert(subj_y + " " + subj_x + " " + type + " " + addr + " " + heatsf + " " + date + " " + price + " " + bed + " " + bath);
			point = new GLatLng(subj_y, subj_x);
			//alert("HEY1");
			marker = cmp_createMarker(point, type, addr, heatsf, date, price, bed, bath);
			//alert("HEY2");
			map.addOverlay(marker);
			//alert("HEY3");
			// zoom map to location of comps)
			map.setCenter(new GLatLng(subj_y, subj_x), zoom);
			//alert("HEY4");
		}
		catch (err) {
			alert("err: " + err);
			alert("Problem adding subject to map");
			document.getElementById("subject_status").innerHTML = "<b>Problem adding subject to map</b>";
		}
		
		try {			
			document.getElementById("pub_landsf").innerHTML = landsf;
			document.getElementById("pub_heatsf").innerHTML = heatsf;
			document.getElementById("pub_bldgsf").innerHTML = bldgsf;
			document.getElementById("pub_yrblt").innerHTML = yrblt;
			document.getElementById("pub_pool").innerHTML = pool;
			//document.getElementById("pub_value").innerHTML = value;
			document.getElementById("pub_bath").innerHTML = bath;
			document.getElementById("pub_bed").innerHTML = bed;
			document.getElementById("pub_price").innerHTML = price;
			//document.getElementById("pub_mktv").innerHTML = mktv;
			//document.getElementById("pub_waterfront").innerHTML = waterfront;
			document.getElementById("pub_date").innerHTML = date;
			
			// changed way of showing sale info 9/3/2009
			// document.getElementById("pub_sale").innerHTML = price + ' on ' + date;
			
			document.getElementById("pub_addr").innerHTML = addr;
			document.getElementById("pub_subd").innerHTML = subd;
			
			document.getElementById("SubjectContainer").style.visibility = "visible";			

			match = "0";
		}
		catch (err) {
			alert("Problem adding Subject Property Public Records");
			document.getElementById("subject_status").innerHTML = "<b>Subject Property Public Records</b>";
			//if (match == "0") {
				//}
			//else alert("Problem retrieving subject property.");
		}

		
		try {
			
			// default projected
			projected = xml.documentElement.getElementsByTagName("projected");
			
			try {
				pv_min = projected[0].getElementsByTagName("min")[0].childNodes[0].nodeValue;
				pv_min = formatDollars2(pv_min);
			}
			catch (err) {
				pv_min = 'n/a';
			}
			
			try {
				pv_mid = projected[0].getElementsByTagName("mid")[0].childNodes[0].nodeValue;
				pv_mid = formatDollars2(pv_mid);
			}
			catch (err) {
				pv_mid = 'n/a';
			}
			
			try {
				pv_max = projected[0].getElementsByTagName("max")[0].childNodes[0].nodeValue;
				pv_max = formatDollars2(pv_max);
			}
			catch (err) {
				pv_max = 'n/a';
			}

			// value projected
			try {
				pv_value_min = projected[0].getElementsByTagName("value")[0].getElementsByTagName("min")[0].childNodes[0].nodeValue;	
				pv_value_min = formatDollars2(pv_value_min);
			}
			catch (err) {
				pv_value_min = 'n/a';
			}
			
			try {
				pv_value_mid = projected[0].getElementsByTagName("value")[0].getElementsByTagName("mid")[0].childNodes[0].nodeValue;
				pv_value_mid = formatDollars2(pv_value_mid);
			}
			catch (err) {
				pv_value_mid = 'n/a';
			}
			
			try {
				pv_value_max = projected[0].getElementsByTagName("value")[0].getElementsByTagName("max")[0].childNodes[0].nodeValue;
				pv_value_max = formatDollars2(pv_value_max);
			}
			catch (err) {
				pv_value_max = 'n/a';
			}
						
			// ppsf projected
			try {
				pv_ppsf_min = projected[0].getElementsByTagName("ppsf")[0].getElementsByTagName("min")[0].childNodes[0].nodeValue;	
				pv_ppsf_min = formatDollars2(pv_ppsf_min);
			}
			catch (err) {
				pv_ppsf_min = 'n/a';
			}
			
			try {
				pv_ppsf_mid = projected[0].getElementsByTagName("ppsf")[0].getElementsByTagName("mid")[0].childNodes[0].nodeValue;
				pv_ppsf_mid = formatDollars2(pv_ppsf_mid);
			}
			catch (err) {
				pv_ppsf_mid = 'n/a';
			}
			
			try {
				pv_ppsf_max = projected[0].getElementsByTagName("ppsf")[0].getElementsByTagName("max")[0].childNodes[0].nodeValue;
				pv_ppsf_max = formatDollars2(pv_ppsf_max);
			}
			catch (err) {
				pv_ppsf_max = 'n/a';
			}
		}
		catch (err) {
			alert("Problem retrieving Projected Value");
		}
		
		try {
			// document.getElementById("pv_min").innerHTML = pv_min;
			// document.getElementById("pv_mid").innerHTML = pv_mid;
			// document.getElementById("pv_max").innerHTML = pv_max;
			
			//document.getElementById("pv_value_min").innerHTML = pv_value_min;
			document.getElementById("pv_value_mid").innerHTML = pv_value_mid;
			//document.getElementById("pv_value_max").innerHTML = pv_value_max;

			//document.getElementById("pv_ppsf_min").innerHTML = pv_ppsf_min;
			document.getElementById("pv_ppsf_mid").innerHTML = pv_ppsf_mid;
			//document.getElementById("pv_ppsf_max").innerHTML = pv_ppsf_max;
			
			//document.getElementById("SubjectContainer").style.display = "inline";
			//document.getElementById("CompsContainer").style.display = "inline";
		}
		//catch (err) {alert("Problem displaying Projected Value");}
		catch (err) {}


		
		try {
			comparables = xml.documentElement.getElementsByTagName("comparables");
		}
		catch (err) {
			document.getElementById("comp_status").innerHTML = "<b>No comparable matches found (err1)</b>";
			return;
		}

		if (comparables.length === 0) {
			document.getElementById("comp_status").innerHTML = "<b>No comparable matches found (err2)</b>";
			return;
		}
		  
		// loop through all XML records
		cmpLength = comparables.length;
		//for (i = 0; i < cmpLength; i++) {
		for (i = cmpLength; i--;) {

			try {
				cmp_subd = comparables[i].getElementsByTagName("subd")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_subd = 'n/a';
			}
			
			try {
				cmp_mvr = comparables[i].getElementsByTagName("mvr")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_mvr = 'n/a';
			}
			try {
				cmp_garage = comparables[i].getElementsByTagName("garage")[0].childNodes[0].nodeValue;
				if (cmp_garage) {
					cmp_garage = 'Yes';
				}
				else if (!cmp_garage) {
					cmp_garage = 'No';
				}
				else {
					cmp_garage = 'n/a';
				}
			}
			catch (err) {
				cmp_garage = 'n/a';
			}
			try {
				cmp_date = comparables[i].getElementsByTagName("date")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_date = 'n/a';
			}
			try {
				cmp_sale_age = comparables[i].getElementsByTagName("sale_age")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_sale_age = 'n/a';
			}
			try {
				cmp_price = comparables[i].getElementsByTagName("price")[0].childNodes[0].nodeValue;
				cmp_price = formatDollars2(cmp_price);
			}
			catch (err) {
				cmp_price = 'n/a';
			}
			try {
				cmp_mktv = comparables[i].getElementsByTagName("mktv")[0].childNodes[0].nodeValue;
				cmp_mktv = formatDollars2(cmp_mktv);
			}
			catch (err) {
				cmp_mktv = 'n/a';
			}
			try {
				cmp_value = comparables[i].getElementsByTagName("value")[0].childNodes[0].nodeValue;
				cmp_value = formatDollars2(cmp_value);
			}
			catch (err) {
				cmp_value = 'n/a';
			}
			try {
				cmp_yrblt = comparables[i].getElementsByTagName("yrblt")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_yrblt = 'n/a';
			}
			try {
				cmp_heatsf = comparables[i].getElementsByTagName("heatsf")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_heatsf = 'n/a';
			}
			try {
				cmp_bldgsf = comparables[i].getElementsByTagName("bldgsf")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_bldgsf = 'n/a';
			}
			
			if ((cmp_heatsf === '0') && (cmp_bldgsf > 0)) {
				cmp_heatsf = "n/a";
			}
			if ((cmp_bldgsf === '0') && (cmp_heatsf > 0)) {
				cmp_bldgsf = "n/a";
			}
			
			try {
				cmp_compsf = comparables[i].getElementsByTagName("compsf")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_compsf = 'n/a';
			}
			try {
				cmp_bath = comparables[i].getElementsByTagName("bath")[0].childNodes[0].nodeValue;
				if ((cmp_bath === '0.0') || (cmp_bath === '0')) {
					cmp_bath = 'n/a';
				}
			}
			catch (err) {
				cmp_bath = 'n/a';
			}
			try {
				cmp_bed = comparables[i].getElementsByTagName("bed")[0].childNodes[0].nodeValue;
				if (cmp_bed === '0') {
					cmp_bed = 'n/a';
				}
			}
			catch (err) {
				cmp_bed = 'n/a';
			}
			try {
				cmp_pool = comparables[i].getElementsByTagName("pool")[0].childNodes[0].nodeValue;
				if (cmp_pool === 'true') {
					cmp_pool = 'Yes';
				}
				else if (cmp_pool === 'false') {
					cmp_pool = 'No';
				}
				else {
					cmp_pool = 'n/a';
				}
			}
			catch (err) {
				cmp_pool = 'n/a';
			}
			try {
				cmp_waterfront = comparables[i].getElementsByTagName("waterfront")[0].childNodes[0].nodeValue;
				if (cmp_waterfront === 'true') {
					cmp_waterfront = 'Yes';
				}
				else if (cmp_waterfront == 'false') {
					cmp_waterfront = 'No';
				}
				else {
					cmp_waterfront = 'n/a';
				}
			}
			catch (err) {
				cmp_waterfront = 'n/a';
			}
			try {
				cmp_landsf = comparables[i].getElementsByTagName("landsf")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_landsf = 'n/a';
			}
			try {
				cmp_addr = comparables[i].getElementsByTagName("addr")[0].childNodes[0].nodeValue;
				// WHERE IS THIS USED?
				cmp_addr2 = cmp_addr;
				cmp_addr = cmp_addr.replace(/<br>/g, ' ');
			}
			catch (err) {
				cmp_addr = 'n/a';
			}
			try {
				cmp_mvr = comparables[i].getElementsByTagName("mvr")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_mvr = 'n/a';
			}
			try {
				cmp_vr = comparables[i].getElementsByTagName("vr")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_vr = 'n/a';
			}
			try {
				cmp_avr = comparables[i].getElementsByTagName("avr")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_avr = 'n/a';
			}
			try {
				cmp_q = comparables[i].getElementsByTagName("q")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_q = 'n/a';
			}
			try {
				cmp_ppsf = comparables[i].getElementsByTagName("ppsf")[0].childNodes[0].nodeValue;
				cmp_ppsf = formatDollars2(cmp_ppsf);
			}			
			catch (err) {
				cmp_ppsf = 'n/a';
			}


			
			try {
				cmp_fireplace = comparables[i].getElementsByTagName("fireplace")[0].childNodes[0].nodeValue;
				if (cmp_fireplace === 'true') {
					cmp_fireplace = 'Yes';
				}
				else if (cmp_fireplace === 'false') {
					cmp_fireplace = 'No';
				}
				else {
					cmp_fireplace = 'n/a';
				}
			}
			catch (err) {
				cmp_fireplace = 'n/a';
			}
			
			try {
				cmp_assv = comparables[i].getElementsByTagName("assv")[0].childNodes[0].nodeValue;
				cmp_assv = formatDollars2(cmp_assv);
			}
			catch (err) {
				cmp_assv = 'n/a';
			}
			
			try {
				cmp_stories = comparables[i].getElementsByTagName("stories")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_stories = 'n/a';
			}
				
			try {
				cmp_sel = comparables[i].getElementsByTagName("sel")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_sel = 'n/a';
			}
			
			try {
				cmp_dist = comparables[i].getElementsByTagName("dist")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_dist = 'n/a';
			}
			
			try {
				cmp_x = comparables[i].getElementsByTagName("x")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_x = 'n/a';
			}
			
			try {
				cmp_y = comparables[i].getElementsByTagName("y")[0].childNodes[0].nodeValue;
			}
			catch (err) {
				cmp_y = 'n/a';
			}

			if (cmp_sel === 'true') {
				BuildTable2Record(cmp_addr, cmp_subd, cmp_date, cmp_price, cmp_heatsf, cmp_bldgsf, cmp_yrblt, cmp_bed, cmp_bath, cmp_pool, cmp_waterfront, cmp_landsf, cmp_ppsf);
				// add comps to map
				type = '00';
				point = new GLatLng(cmp_y, cmp_x);
				marker = cmp_createMarker(point, type, cmp_addr2, cmp_compsf, cmp_date, cmp_price, cmp_bed, cmp_bath);
				map.addOverlay(marker);	
			}	
		}
		document.getElementById("CompsContainer").style.visibility = "visible";
		document.getElementById("CompRecs").style.visibility = "visible";
		document.getElementById("mapGM").style.visibility = "visible";
	});

}



// ###############################################################################################################################################
//  	PROPERTY INFO Functions
//
//	came from prop_info_1_0_6.js 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
// FUNCTIONS
//
//
//	popup(mylink, windowname)
//
//	popup2(mylink, windowname)
//
//	calculatePayment(form)
//		Jeff Hoffman - PropertyKey Inc.
//
//	formatDollars(unformatted)
//		Jeff Hoffman - PropertyKey Inc.
//
//	focusDown(ele)
//
//	blurDown(ele)
//
//	submitContact(mlsid,realtor,realtor_email)
//
//	VEOnObliqueEnterHandler()
//
//	VEGetMap(a_street)
//
//	load(full_address)
//
//	initialize()
//
//	handleNoFlash(errorCode)
//

//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	popup(mylink, windowname)
//		called by 
//			NOT CURRENTLY USED
// 
function popup(mylink, windowname) {
	var href;
	if (!window.focus) {
		return true;
	}
	if (typeof(mylink) === 'string') {
		href = mylink;
	}
	else {
		href = mylink.href;
	}
	window.open(href, windowname, 'width=450,height=500,scrollbars=yes');
	return false;
}
//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	popup2(mylink, windowname)
//		called by 
//			NOT CURRENTLY USED
// 
// UMMM - just add parameters for width, height instead of making a new function
function popup2(mylink, windowname) {
	var href;
	if (!window.focus) {
		return true;
	}
	if (typeof(mylink) === 'string') {
		href = mylink;
	}
	else {
		href = mylink.href;
	}
	window.open(href, windowname, 'width=980,height=650,scrollbars=yes');
	return false;
}

//
var existingDown = 0;
//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	calculatePayment(form)
//		called by 
//			mortgage calculator form
// Jeff Hoffman - PropertyKey Inc.
// 
function calculatePayment(form) {
	var price, down, taxes, insurance, princ, intRate, months, 
		basePayment, pmtSpan;
	
	price = form.price.value; 
	price = price.replace(/^\$|,/g, "");
	form.price.value = formatDollars(price);
	down = form.down.value; 
	if (down.indexOf('%') > 0) {
		down = down.replace(/%/, '').replace(/\((.*)\)/, '').replace(/^\s+|\s+$/, '');
		form.down.value = down + "%" + " (=" + formatDollars(price * down / 100) + ")";
		down = price * down/100;
	} 
	else {
		down = down.replace(/^\$|,/g, "");
		form.down.value = formatDollars(down);
	}
	taxes = form.taxes.value; 
	taxes = taxes.replace(/^\$|,/g, "");
	form.taxes.value = formatDollars(taxes);
	insurance = form.insurance.value; 
	insurance = insurance.replace(/^\$|,/g, "");
	form.insurance.value = formatDollars(insurance);
	princ = price - down;
	intRate = (form.intrate.value / 100) / 12;
	months = form.term.value * 12;
	basePayment = Math.floor((princ * intRate) / (1 - Math.pow(1 + intRate, (-1 * months))) * 100) / 100;
	basePayment += (taxes / 12) + (insurance / 12);
	
	// form.payment.value = formatDollars(basePayment.toFixed(2));
			
	pmtSpan = document.getElementById("pmtValue");
	pmtSpan.innerHTML = formatDollars(basePayment.toFixed(2));
}
//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	formatDollars(unformatted)
//		called by
//			calculatePayment()
// Jeff Hoffman - PropertyKey Inc. - modified version by Brian May - MapWise Inc.
//
function formatDollars(unformatted) {
	var x, x1, x2;
	unformatted += '';
	x = unformatted.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');
	}
	return '$' + x1 + x2;
}

//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	focusDown(ele)
//		called by
//			property_info.php - mortgage form
// Jeff Hoffman - PropertyKey Inc. - modified version by Brian May - MapWise Inc.
// THIS DOESN"T DO ANYTHING
function focusDown(ele) {
/*
	existingDown = ele.value;
	ele.value = '';
*/
}

//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	focusDown(ele)
//		called by
//			property_info.php - mortgage form
// Jeff Hoffman - PropertyKey Inc. - modified version by Brian May - MapWise Inc.
// THIS DOESN"T DO ANYTHING
function blurDown(ele) {
/*
	if (ele.value == '') { ele.value = existingDown; }
*/
}
// end mortgage calc - Jeff Hoffman - PropertyKey Inc.


//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	submitContact()
//		called by 
//			property_info.php onSubmit from contact form
//
function submitContact() {
	//alert("BEGIN submitContact()");

	var myname = document.getElementById("myname").value;
	var email = document.getElementById("email").value;	
	var phone = document.getElementById("phone").value;	
	var comments = document.getElementById("comments").value;
	var purpose = document.getElementById("purpose").value;	
	
	myname = stripBadData (myname);
	phone = stripBadData (phone);
	comments = stripBadData (comments);
	
	if (myname === "") {
		alert("Please enter your name in the contact form.");
		return false;
	}
	if (email === "") {
		alert("Please enter your email address in the contact form.");
		return false;
	}
	
	var emailExp = /^[\w\-\.\+]+\@[a-zA-Z0-9\.\-]+\.[a-zA-z0-9]{2,4}$/;
	if (!email.match(emailExp)) {
		alert("Please enter a valid email address");
		return false;
	}
	
	if (phone === "") {
		alert("Please enter your 10-digit phone number in the contact form.");
		return false;
	}

	if ((phone.length < 10) || (phone.length > 14)) {
		alert("Please enter a 10-digit phone number in the contact form.");
		return false;
	}		

    with (new Date) {
        var contact_date = String((getFullYear() * 100 + getMonth() + 1) * 100 + getDate());
    } 
	var url = '/service/ws_contact.php?mlsid=' + mlsid + '&myname=' + myname + '&email=' + email + '&phone=' + phone + '&purpose=' + purpose + '&comments=' + comments + '&contact_date=' + contact_date + '&realtor=' + realtor + '&realtor_email=' + realtor_email + '&cmd=update&'
	//alert(url);
		
	GDownloadUrl(url, function(data) {}	)
	alert("Your message has been sent. The listing agent will contact you.");
	
	return false;
}


//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	VEOnObliqueEnterHandler()
//		called by 
//			VEGetMap(a_street)
// Check to see if virtual earth birds eye is available for location
// 
function VEOnObliqueEnterHandler()
{
	if(map_ve.IsBirdseyeAvailable())
	{
		//var TopOfNeedle = new VELatLong(47.622, -122.3491); 
		//map.SetBirdseyeScene(TopOfNeedle);
		map_ve.SetBirdseyeScene(veLocation);
		//map_ve.SetBirdseyeScene(TopOfNeedle);
	}
}

//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	VEGetMap(a_street)
//		called by 
//			property_info.php - end of page inline javascript before Streetmaps
//  Initialize virtual earth birds eye
// 
function VEGetMap(a_street)
{
	if (lat != null) {
	map_ve = null;
	map_ve = new VEMap('myMap');
	var ve_point = new VELatLong(lat, lng);
	var pinLocation = ve_point;
	veLocation = ve_point;
	var pinid = 0;
	}
	map_ve.LoadMap(veLocation, 17, 'Hybrid', false);
	
	// Let me know if a birdseye scene is available
	map_ve.AttachEvent("onobliqueenter", VEOnObliqueEnterHandler);
	
	var shape = new VEShape(VEShapeType.Pushpin, veLocation);
	//shape.SetTitle('My pushpin');
	shape.SetDescription(a_street);
	pinid++;
	map_ve.AddShape(shape);
}

// streetview
var myPano;
//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	pi_GS_initialize()
//		called by 
//			property_info.php - end of page inline javascript after VE and before GM
//  Initialize google streetmap
//
function pi_GS_initialize() {
	var myLoc = new GLatLng(lat,lng);
	panoramaOptions = { latlng:myLoc };
	myPano = new GStreetviewPanorama(document.getElementById("mapGM_sv"), panoramaOptions);
	GEvent.addListener(myPano, "error", pi_GS_handleNoFlash);
}
//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	pi_GS_handleNoFlash(errorCode)
//		called by 
//			pi_GS_initialize()
// determine if flash is available for google streetmap
// 
function pi_GS_handleNoFlash(errorCode) {
	//alert(errorCode);
	if (errorCode == "FLASH_UNAVAILABLE") {
	alert("Error: Flash doesn't appear to be supported by your browser");
	return;
	}
	if (errorCode == "600") {
		document.getElementById("mapGM_sv").innerHTML = '<span style="font-family:arial;font-size:10pt;font-weight:bold;">Streetview not available at this location.</p>';
	}
}

//	PROPERTY_INFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	pi_GM_load(full_address)
//		called by 
//			property_info.php - end of page inline javascript after Streetmaps
//
// Initialize google maps, set map to property location
// 
function pi_GM_load(full_address) {
	if (GBrowserIsCompatible()) {
		document.getElementById("mapGM").style.visibility = "hidden";
		map = new GMap2(document.getElementById("mapGM"));
		map.addControl(new GLargeMapControl3D());
		map.addControl(new GScaleControl());
		map.addControl(new GMapTypeControl());
		map.addMapType(G_SATELLITE_3D_MAP);
		map.setMapType(G_NORMAL_MAP);
		//map.setMapType(G_HYBRID_MAP); 		
		
		// call function to setup icons - in common.js
		setIconVars();
		
		if (!lat) {
			geocoder = new GClientGeocoder();
			if (geocoder) {
				geocoder.getLatLng(full_address,function(point) {
					if (!point) {
						alert(full_address + " not found");
					} else {
						map.setCenter(point, 18);
						var marker = new GMarker(point);
						//map.addOverlay(marker);

						//marker.openInfoWindowHtml(address);
					} 
				});
			}
		}
		else{
			var point = new GLatLng(lat,lng);
			map.setCenter(point, 18);
			var marker = new GMarker(point);
			//map.addOverlay(marker);
			//marker.openInfoWindowHtml(address);
		}
		//layer1 = new GTileLayerOverlay(new GTileLayer(null,null,null,{
		//	tileUrlTemplate: 'http://wms4.mapwise.com/cgi-bin/tilecache-2.03/tilecache.py/1.0.0/parcels-all-outline/{Z}/{X}/{Y}.png?type=google',
		//	isPng:true}));
		//map.addOverlay(layer1);
		// from cvrmls
		document.getElementById("mapGM").style.visibility = "visible";
		//pi_showGmap(point) ;
		
		calculatePayment(document.getElementById("mtgcalc"));
	}
}

// PROPINFO
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// 
//
function pi_showGmap(point){
			// add subject property to map
			var type = '01';
			//alert(subj_y + " " + subj_x + " " + type + " " + addr + " " + heatsf + " " + date + " " + price + " " + bed + " " + bath);
			//var point = new GLatLng(subj_y,subj_x);
			//alert("HEY1");
			//var marker = cmp_createMarker(point, type, addr, heatsf, date, price, bed, bath);
			var marker = new GMarker(point, customIcons[type]);
			//alert("HEY2");
			map.addOverlay(marker);
			//alert("HEY3");
			// zoom map to location of comps)
			map.setCenter(new GLatLng(subj_y, subj_x), zoom);
			//alert("HEY4");
		}


// ###############################################################################################################################################
//  	COMPARABLES (AVM) PAGE Functions 
//
//	came from comp_1_0_3.js 
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// FUNCTIONS
//
//
//	cmp_load()
//
//	cmp_go()
//
//	findAddress(address)
//
//	doAddressStuff(response)
//
//	getAddressComponents()
//
//	setOriginalStreet()
//
//	checkAddress()
//
//	checkAccuracy()
//
//	checkUnit()
//

// RE_EVALUATE NEED FOR GLOBALS VARS
address2 = "";
a_street = "";
a_street_orig = "";
a_city = "";
a_state = "";
a_zipcode = "";
a_county = "";
accuracy = "";
lat = "";
lng = "";
match = "0";
taxid = "";
taxid3 = "";


//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	cmp_load()
//		called by 
//			comparables.php onLoad()
// initialize google map
// 
function cmp_load() {

	if (GBrowserIsCompatible()) {
		map = new GMap2(document.getElementById("mapGM"));
		map.addControl(new GLargeMapControl3D());
		map.addControl(new GScaleControl());
		//map.setCenter(new GLatLng(26.0, -80.3), 9);
		map.setCenter(new GLatLng(28.7, -83.3), 6);
		map.setMapType(G_NORMAL_MAP);
		map.addControl(new GMapTypeControl());
		geocoder = new GClientGeocoder();
		//layer1 = new GTileLayerOverlay(new GTileLayer(null,null,null,{
		//	tileUrlTemplate: 'http://wms4.mapwise.com/cgi-bin/tilecache-2.03/tilecache.py/1.0.0/parcels-all-outline/{Z}/{X}/{Y}.png?type=google',
		//	isPng:true}));
		setIconVars();
	}
}

//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	cmp_go()
//		called by 
//			comprables.php address search form onsubmit
// When form is submitted from comparables.php, 
//	if an address was entered, call findAddress()
//	else throw an error
// 
function cmp_go() {

	try {address = unescape(document.getElementById("f_street_address").value);}
	catch (err) {alert("Problem extracting address from form.");};

	findAddress(address);
}
//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	findAddress(address)
//		called by 
//			cmp_go()
//
//  If address length is zero, throw an error
// Clean up the string
// count the words - if less than 4 words, throw an error
// call the google maps geocoder
//	upon geocode completeion - call doAddressStuff to 
// Upon successful completion of doAddressStuff(), call getComps()
// 
function findAddress(address) {

	if (address.length == 0){
		alert ("Please enter an Address");
		return;
	}
	
	var address = address.replace(/\+/g," ");
	var address = address.replace(/,/g," ");
	var address = address.replace(/%20/g," ");
	var address = address.replace(/%2C/g," ");
	var address = address.replace(/ TE /g," TER ");
	//alert("Address - after char replacements: " + address);
	
	var words = countWords(address);
	if (words < 4) {
		alert("Please enter a complete address");
		return;
	}
	
	// used to check if a unit was present in the original address later in processing
	address_orig = address;
	
	geocoder.getLocations(address, doAddressStuff);

	// Need to wait for the geocoder to return results, before we can move on
	//setTimeout('map.addOverlay(layer1);',500);
	setTimeout('getComps(a_street,a_city,a_zipcode,a_county,taxid,taxid3,13)',500);
}
//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	doAddressStuff(response)
//		called by 
//			Inside findAddress() - google maps gecoder callback function
//
// If geocode was not successful, throw an error
// get place name
// get lat/long and set a lat/lng point object
// call getAddressComponents() to get street, city, state, zipcode
// call checkAddress() - if no street, city or zipcode OR outside FL, then throw an error 
// call checkAccuracy() to get accuracy, i.e. street, city, etc from google
//	if accuracy less than 6, throw an error
//	if accuracy 6 or 7, tell user we may not be able to find it
// call checkUnit() to see if an apt# or unit is present, if so add it to the street name returned from google
// 
function doAddressStuff(response) {

	if (!response || response.Status.code != 200) {
		alert("Sorry, we were unable to geocode that address")
		return;
	}
	
	name = response.name;
	status = response.Status.code;
	//alert("google geocoder status: " + status);
	place = response.Placemark[0];
	// alert("google geocoder place: " + place);

	lat = place.Point.coordinates[1];
	lng = place.Point.coordinates[0];
	//alert("lng: " + lng);
	//alert("lat: " + lat);
	point = new GLatLng(place.Point.coordinates[1],place.Point.coordinates[0]);
	
	var stat = getAddressComponents();
	//if (stat) {stat = setOriginalStreet();}
	if (stat) {stat = checkAddress();}
	if (stat) {stat = checkAccuracy();}
	if (stat) {stat = checkUnit();}
	//if (stat) {stat = displayAddressComp();}
	//if (stat) {stat = addAddressToMap(address,lat,lng);}

}

//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	getAddressComponents()
//		called by 
//			doAddressStuff()
// get street, city, state, zipcode
// 
function getAddressComponents() {
	// BEGIN Get Address Components
	
	try {
		a_state = place.AddressDetails.Country.AdministrativeArea.AdministrativeAreaName;
		//alert("google geocoder place a_state: " + a_state);
	}
	catch (err) {a_state = "";}
	// google keeps screwing around with putting in and taking out the SubAdministrativeArea part - for now, its in\
	try {
		a_county = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.SubAdministrativeAreaName;
		//alert("google geocoder place a_county: " + a_county);
	}
	catch (err) {a_county = "";}
	try {
		a_city = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.LocalityName;
		//alert("google geocoder place a_city: " + a_city);
	}
	catch (err) {a_city = "";}
	try {
		a_street = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.Thoroughfare.ThoroughfareName;
		//alert("google geocoder place a_street: " + a_street);
	}
	catch (err) {a_street = "";}
	try {
		a_zipcode = place.AddressDetails.Country.AdministrativeArea.SubAdministrativeArea.Locality.PostalCode.PostalCodeNumber;
		//alert("google geocoder place a_zipcode: " + a_zipcode);
	}
	catch (err) {a_zipcode = "";}

	//alert("a_street: " + a_street + " a_city: " + a_city + " a_state: " + a_state + " a_zipcode:" + a_zipcode);

	return true;
	// END Get Address Components
}
//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	setOriginalStreet()
//		called by 
//			doAddressStuff()
//			NOT CURRENTLY USED
//
function setOriginalStreet() {

	// BEGIN Set Original Street Name, in case we need to use just the street number and name, i.e. if google doesn't find the street and to get the unit out
	
	// problem - if the city, state and zipcode do not match what was originally entered, you can't remove them
	// solution - use word trimming starting from last word
	
	// get last word, replace '-' w/ nothing, see if its an integer, if so, remove it
	
	// get last word, see if it matches a list of states (full and abbrev name) - although right now only need to check for fla, can't use anything else, then delete it
	
	// city
	
	// punt on this whole bs and make a web service that parses addresses using existing python code
	
	var sRegExInput = new RegExp(a_state, 'i');
	//alert(sRegExInput);
	a_street = a_street_orig.replace(sRegExInput, "");
	//alert(a_street);
	
	var sRegExInput = new RegExp(a_city, 'i');
	//alert(sRegExInput);
	a_street = a_street.replace(sRegExInput, "");
	//alert(a_street);
	
	var sRegExInput = new RegExp(a_zipcode, 'i');
	//alert(sRegExInput);
	a_street_orig = a_street.replace(sRegExInput, "");
	a_street_orig = a_street_orig.toUpperCase();
	a_street_orig = unescape(a_street_orig);
	
	//alert("a_street_orig: " + a_street_orig);
	
	return true;
	// END Set Original Street Name
}
//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	checkAddress()
//		called by 
//			doAddressStuff()
// if no street, city, or zipcode, tell user not enough info entered.
// if address is outside FL, throw an error
// 
function checkAddress() {
	
	if ((a_street == "") || (a_city == "") || (a_zipcode == "") ) {
		//alert("Please provide a complete or more specific address.");
		return false;
	}
	
	if (a_state != 'VA') {
		alert("Virginia is currently the only searchable state");
		return false;
	}
	//if (a_state != 'FL') {
	//	alert("Florida is currently the only searchable state");
	//	return false;
	//}
	
	return true;
	
}
//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	checkAccuracy()
//		called by 
//			doAddressStuff()
// check accuracy result from google maps geocode
// 
function checkAccuracy() {
	// BEGIN Check accuracy of address result
	accuracy = place.AddressDetails.Accuracy
	
	// 8 = address, 7 = intersection, 6 = street, 5 = zipcode
	if (accuracy  < 6) {
		alert("We can't find the address. The address entered may not be enough information, please try again.");
		return false;
	}
	if ((accuracy == 7) || (accuracy == 6)){
		alert("Address entered may not be accurate enough.");
		//alert(address2);
		a_street = a_street_orig;
	}
	//alert("Geocode accuracy: " + accuracy);
	// END Check accuracy of address result
	
	return true;
}
//	COMP
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	checkUnit()
//		called by 
//			doAddressStuff()
//
function checkUnit() {
	// BEGIN Check Unit
	// see if an apt# or unit is present, if so add it to the street name returned from google
	
	var myRegExp = /unit.\w+\s|apt.\w+\s|#.\w+\s|suite.\w+\s|ste.\w+\s/i;
	var matchPos1 = address_orig.search(myRegExp);
	if(matchPos1 != -1) {
		//a_street = a_street_orig;
		//alert("a_street with unit: " + address_orig);
		var aunit = myRegExp.exec(address_orig);
		unit = aunit.join();
		unit = escape(unit);

		//alert(a_street);
		//alert(unit);
		a_street = a_street + " " + unit;
		//alert(a_street);
	}

	// END Check Unit
	return true;
}

// ###############################################################################################################################################
//	HOME PAGE functions
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//	idxSetMapArea(area)
//		called by 
//			form on home page - <form action="search_map.php" method="get" onsubmit="idxSetMapArea('address');" >
//
function idxSetMapArea(area) {
	//alert("map_session: " + map_session);
	//if (map_session!==null && map_session!=="") {
		msArr = [];
		msArr.length = 15;
	//}
	//else {
	//	msArr = map_session.split('~');
	//}

	if (area == 'address') {
		//alert("HI");
		var address = document.getElementById('hp_address').value;
		address = stripBadData (address);
		msArr[15] = address;
		//alert("msArr: " + msArr);
	}
	map_session = msArr.join("~");
	//alert("map_session: " + map_session);
	setCookie('map_session', map_session, 1);
	
	//alert("END idxSetMapArea(area)");
}	