

blnFlash = true;

//------------------------------------------------------------------------------------
var proxyServerName = "www.apartmentshowcase.com";
var proxyServerPort = "80";
var proxyServerPath = "/JSReqHandler";
var geocodeServerName = "geocode.access.mapquest.com";
var serverPort = "80";
var serverPath = "mq";
var myPxyServer = "www.apartmentshowcase.com";
var myPxyPort = "80";
var myPxyPath = "/JSReqHandler";
var mqMapServer = "map.access.mapquest.com";
var mqGcServer = "geocode.access.mapquest.com";
var mqRtServer = "route.access.mapquest.com";
var mqSptServer = "spatial.access.mapquest.com";
var mqMapPort = "80";
var mqGcPort = "80";
var mqRtPort = "80";
var mqSptPort = "80";
var serverPath = "mq";
var mqPath = "mq";
var strInput = '';
var comm_name = "";
var result_address = "";
var latLgn = new Array();
var latitude = "";
var pois = new Array();
var poiTypes = new Array();
var poiIcons = new Array();
var chainTypes = new Array();
var foodTypes = new Array();
var givenList = new Array();

//-------------------------------------------------------------------------------------

function startMap(){
	myMap = new MQTileMap($('mapWindow'));
	myLZControl = new MQLargeZoomControl(myMap);
	myMap.addControl(myLZControl, new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(20,20)));
	myVControl = new MQViewControl(myMap);
	myMap.addControl(myVControl, new MQMapCornerPlacement(MQMapCorner.TOP_RIGHT, new MQSize(20,20)));
	myIcon = new MQMapIcon();
}

function startExpMap(){
	myMap = new MQTileMap($('mq_map'));
	myLZControl = new MQLargeZoomControl(myMap);
	myMap.addControl(myLZControl, new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(20,20)));
	myVControl = new MQViewControl(myMap);
	myMap.addControl(myVControl, new MQMapCornerPlacement(MQMapCorner.TOP_RIGHT, new MQSize(20,20)));
	myIcon = new MQMapIcon();
}



function shrinkDivs(div){
	switch (div){
		case "both":
			document.getElementById('resultsDiv').style.height = "0px";
			document.getElementById('resultsDiv').innerHTML = '';
			document.getElementById('inputDiv').style.height = "0px";
			document.getElementById('inputDiv').innerHTML = '';
			break;
		case "results":
			document.getElementById('resultsDiv').style.height = "0px";
			document.getElementById('resultsDiv').innerHTML = '';
			break;
		case "input":
			document.getElementById('inputDiv').style.height = "0px";
			document.getElementById('inputDiv').innerHTML = '';
			break;
	}
}


//-------------------------------------------------------------------------------------
function expandResultsDiv(){
	document.getElementById('resultsDiv').style.width = "auto";
	document.getElementById('resultsDiv').style.height = "auto";
}


//-------------------------------------------------------------------------------------
function doIfFlashStr(){
	strInput = '';
	if(blnFlash == true){
		strInput += "<h3>Flash ";
	}
	else {
		strInput += "<h3>JS Proxy ";
	}
}

//-------------------------------------------------------------------------------------
function doFlashGeocode(){
	var myGcExec = new MQExec(mqGcServer,mqPath,mqGcPort);

    var myAddr = new MQAddress();
    myAddr.setStreet(document.getElementById("street").value);
    myAddr.setCity(document.getElementById("city").value);
    myAddr.setState(document.getElementById("state").value);
    myAddr.setPostalCode(document.getElementById("postalcode").value);
    myAddr.setCountry("US");

    myGcExec.geocode(myAddr,new MQLocationCollection(),new MQAutoGeocodeCovSwitch(),onGcEnd);
}


//---------------------------------------------------------------------------------------
function doProxyGeocode(street, city, state, zip){
	var myGcExec = new MQExec(mqGcServer,mqPath,mqGcPort,myPxyServer,myPxyPath,myPxyPort);
	var myGcLocColl = new MQLocationCollection("MQGeoAddress");
    var myAddr = new MQAddress();

    myAddr.setStreet(street);
    myAddr.setCity(city);
    myAddr.setState(state);
    myAddr.setPostalCode(zip);
    myAddr.setCountry("US");

 	myGcExec.geocode(myAddr,myGcLocColl,new MQAutoGeocodeCovSwitch());
	onGcEnd(myGcLocColl);
}

//My Geocode Function
function doGeocode(street, city, state, zip) {
		//This object is the EXEC object, just like you should all know and love from your server code, with a nice shiny constructor
         var geoExec = new MQExec(geocodeServerName,serverPath,serverPort);
		//An address object, just like in server-side, except now it has an MQ on the front
         var address = new MQAddress();
		//populate the address object with the information from the form
        address.setStreet(street);
        address.setCity(city);
        address.setState(state);
        address.setPostalCode(zip);
        address.setCountry("US");
		
		//call the geocode function of the exec object - give it the address object to be geocoded
		//and the locationcollection to hold the results
		var GcRetLocColl = new MQLocationCollection();
         geoExec.geocode(address, GcRetLocColl, new MQAutoGeocodeCovSwitch(), onGcEnd);
}

function setName(name){
	comm_name = name;
}
function getName(){
	return comm_name;
}
function setLatLgn(lat){
	latitude = lat;
}
function getLat(){
	return latitude;
}



//---------------------------------------------------------------------------------------
function onGcEnd(GcRetLocColl){
	shrinkDivs("both");
	var myRetAddr = GcRetLocColl.get(0);
	popupInfo(myRetAddr.getMQLatLng().getLatitude(), myRetAddr.getMQLatLng().getLongitude());
}	

// Expanded Listing Popup
function popupInfo(lat,lon){	
	myPoint = new MQPoi(new MQLatLng(lat,lon));
	newCenter = new MQLatLng(lat,lon);
	myMap.setCenter(newCenter,8);
	//set any rollover and pop-up text]
	var str = street.split(' ').join('%20');
	var city1 = city.split(' ').join('%20');
	myIcon = new MQMapIcon();
	myIcon.setImage("/images/mapquest/house.gif",32,32,true,false);		 
	var is_minor = parseFloat(navigator.appVersion.toLowerCase());
	var iePos  = navigator.appVersion.toLowerCase().indexOf('msie');
	var is_mac = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1);
    if (iePos !=-1) {
       if(is_mac) {
           var iePos = navigator.userAgent.toLowerCase().indexOf('msie');
           is_minor = parseFloat(navigator.userAgent.toLowerCase().substring(iePos+5,navigator.userAgent.toLowerCase().indexOf(';',iePos)));
       }
       else is_minor = parseFloat(navigator.appVersion.toLowerCase().substring(iePos+5,navigator.appVersion.toLowerCase().indexOf(';',iePos)));
    }
	var is_ie = (iePos != -1);
	if (is_ie && is_minor < 7&& parseFloat(navigator.appVersion.toLowerCase().substring(iePos + 5, navigator.appVersion.toLowerCase().indexOf(';', iePos)))) {
		var toandfrom = "Not supported, please <br/>upgrade to IE7 or use Firefox.";
	}
	else {
		var from = "<a href='javascript:void(0);' onclick=fillFrom('" + str + "','" + city1 + "','" + state + "','" + zip + "'); >from here</a>";
		var to = "<a href='javascript:void(0);' onclick=fillTo('" + str + "','" + city1 + "','" + state + "','" + zip + "'); >to here</a>";
		var toandfrom = to+' | '+from
	}
	myPoint.setInfoTitleHTML(name);
	if (photo != ""){
		var address = '<img src="'+photo+'" width="50" height="50" alt="thumbnail" />'+'<p>'+street+'<br/>'+city+'<br/>'+state+' '+zip+'</p>'+'<div class="tofrom">Directions: '+toandfrom+'</div>';
	}
	else{
		var address = '<p>'+street+'<br/>'+city+'<br/>'+state+' '+zip+'</p>'+'<div class="tofrom">Directions: '+toandfrom+'</div>';
	}
	myPoint.setInfoContentHTML(address);
	myPoint.setIcon(myIcon);
	myPoint.setKey('32');
	myMap.addPoi(myPoint);
	strInput = '';
	strInput += "<h3>GPS Coordinates</h3><ul>";	
	strInput += "<li><strong>X:</strong> "+lat+"&deg;</li>";	
	strInput += "<li><strong>Y:</strong> "+lon+"&deg;</li>";	
	strInput += "<input type='hidden' ID='lat' value="+lat+" />";
	strInput += "<input type='hidden' ID='lon' value="+lon+" /><br/>";
	document.getElementById('coordinates').innerHTML = strInput;
	
}


//****************************************************************************************************************
//***********BEGIN ROUTING FUNCTIONS******************************************************************************
//-----------------------------------------------------------------------------------------
function fillFrom(street, city, state, zip){
	shrinkDivs("both");
	var str = street.split('%20').join(' ');
	var city1 = city.split('%20').join(' ');
		strInput = '';
		strInput += "<br/><table border='0'><tr><td><table ID='Table1Rt' border='0'><tr><td colspan='2'><b>FROM:</b></td></tr>";
		strInput += "<tr><td>Street: </td><td><input type='text' ID='Fstreet' style='border-bottom:1px solid #000' value='"+str+"' ></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='Fcity' style='border-bottom:1px solid #000' value='"+city1+"' ></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='Fstate' style='border-bottom:1px solid #000' SIZE='2' maxlength='2' value='"+state+"' ></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='Fpostalcode' style='border-bottom:1px solid #000' SIZE='5' maxlength='5' value='"+zip+"' ></td></tr></table>";
		strInput += "</td><td>&nbsp</td><td><table ID='Table2Rt' border='0'><tr><td colspan='2'><b>TO:</b></td></tr>";
		strInput += "<tr><td>Street: </td><td><input type='text' ID='Tstreet' style='border-bottom:1px solid #000' value=''></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='Tcity' style='border-bottom:1px solid #000' value=''></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='Tstate' style='border-bottom:1px solid #000' SIZE='2' maxlength='2' value=''></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='Tpostalcode' style='border-bottom:1px solid #000' SIZE='5' maxlength='5' value=''></td></tr></table>";
		strInput += "<tr><td colspan='3'><table ID='Table3Rt' border='0'><td><b>Language:</b><select id='lang'>";
		strInput += "<option value ='english'>English</option><option value ='spanish'>Spanish</option><option value ='german'>German</option>";
		strInput += "<option value ='french'>French</option><option value ='italian'>Italian</option><option value ='danish'>Danish</option>";
		strInput += "<option value ='dutch'>Dutch</option><option value ='norwegian'>Norwegian</option><option value ='swedish'>Swedish</option>";
		strInput += "<option value ='british english'>British English</option><option value ='iberian spanish'>Iberian Spanish</option>";
		strInput += "<option value ='iberian portuguese'>Iberian Portuguese</option></select>";
		strInput += "<input type='button' style='margin-left:20px;' value='Get Route' onclick='doFlashRoute()' id='btnFlRoute'></td></tr></table></td></tr></table>";
		
	document.getElementById('inputDiv').innerHTML = strInput;
	document.getElementById('inputDiv').style.height = "auto";
}

function fillTo(street, city, state, zip){
	shrinkDivs("both");
	var str = street.split('%20').join(' ');
	var city1 = city.split('%20').join(' ');
		strInput = '';
		strInput += "<br/><table border='0'><tr><td><table ID='Table1Rt' border='0'><tr><td colspan='2'><b>FROM:</b></td></tr>";
		strInput += "<tr><td>Street: </td><td><input type='text' ID='Fstreet' style='border-bottom:1px solid #000' value='' ></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='Fcity' style='border-bottom:1px solid #000' value='' ></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='Fstate' style='border-bottom:1px solid #000' SIZE='2' maxlength='2' value='' ></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='Fpostalcode' style='border-bottom:1px solid #000' SIZE='5' maxlength='5' value='' ></td></tr></table>";
		strInput += "</td><td>&nbsp</td><td><table ID='Table2Rt' border='0'><tr><td colspan='2'><b>TO:</b></td></tr>";
		strInput += "<tr><td>Street: </td><td><input type='text' ID='Tstreet' style='border-bottom:1px solid #000' value='"+str+"' ></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='Tcity' style='border-bottom:1px solid #000' value='"+city1+"' ></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='Tstate' style='border-bottom:1px solid #000' SIZE='2' maxlength='2' value='"+state+"' ></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='Tpostalcode' style='border-bottom:1px solid #000' SIZE='5' maxlength='5' value='"+zip+"' ></td></tr></table>";
		strInput += "<tr><td colspan='3'><table ID='Table3Rt' border='0'><td><b>Language:</b><select id='lang'>";
		strInput += "<option value ='english'>English</option><option value ='spanish'>Spanish</option><option value ='german'>German</option>";
		strInput += "<option value ='french'>French</option><option value ='italian'>Italian</option><option value ='danish'>Danish</option>";
		strInput += "<option value ='dutch'>Dutch</option><option value ='norwegian'>Norwegian</option><option value ='swedish'>Swedish</option>";
		strInput += "<option value ='british english'>British English</option><option value ='iberian spanish'>Iberian Spanish</option>";
		strInput += "<option value ='iberian portuguese'>Iberian Portuguese</option></select>";
		strInput += "<input type='button' style='margin-left:20px;' value='Get Route' onclick='doFlashRoute()' id='btnFlRoute'></td></tr></table></td></tr></table>";
		

	document.getElementById('inputDiv').innerHTML = strInput;
	document.getElementById('inputDiv').style.height = "auto";
}


//---------------------------------------------------------------------------------------
function doFlashRoute(){
	var myTAddress = new MQAddress();
	var myFAddress = new MQAddress();
	var myGExec = new MQExec(mqGcServer,mqPath,mqGcPort);
	var myAddressColl = new MQLocationCollection();
	var myGcResultCollColl = new MQLocationCollectionCollection();

	myFAddress.setStreet(document.getElementById("Fstreet").value);
	myFAddress.setCity(document.getElementById("Fcity").value);
	myFAddress.setState(document.getElementById("Fstate").value);
	myFAddress.setPostalCode(document.getElementById("Fpostalcode").value);
	myFAddress.setCountry("US");
	myTAddress.setStreet(document.getElementById("Tstreet").value);
	myTAddress.setCity(document.getElementById("Tcity").value);
	myTAddress.setState(document.getElementById("Tstate").value);
	myTAddress.setPostalCode(document.getElementById("Tpostalcode").value);
	myTAddress.setCountry("US");
	myAddressColl.add(myFAddress);
	myAddressColl.add(myTAddress);

	myGExec.batchGeocode(myAddressColl,myGcResultCollColl,new MQAutoGeocodeCovSwitch(),onFlashRtGcEnd);
}


//------------------------------------------------------------------------------------
function onFlashRtGcEnd(myGcResultCollColl){
	myCollColl = myGcResultCollColl;
	myRExec = new MQExec(mqRtServer,mqPath,mqRtPort);
	myRExec.createSessionEx(new MQSession(),onFlashRtSessCreate);
}


//------------------------------------------------------------------------------------
function onFlashRtSessCreate(mySessionId){
	var myOptions = new MQRouteOptions();
	var myRtResults = new MQRouteResults();
	var myRtColl = new MQLocationCollection("MQGeoAddress");

	myOptions.setMaxShapePointsPerManeuver(200);
	myOptions.setLanguage(document.getElementById("lang").value);

	for (intX = 0; intX < myCollColl.getSize();intX++){
		myRtColl.add(myCollColl.get(intX).get(0));
	}

	myRExec.doRoute(myRtColl,myOptions,myRtResults,mySessionId,null,onRtEnd);
}


//-------------------------------------------------------------------------------------
function doProxyRoute(){
	var myTAddress = new MQAddress();
	var myFAddress = new MQAddress();
	var myOptions = new MQRouteOptions();
	var myGExec = new MQExec(mqGcServer,mqPath,mqGcPort,myPxyServer,myPxyPath,myPxyPort);
	var myRExec = new MQExec(mqRtServer,mqPath,mqRtPort,myPxyServer,myPxyPath,myPxyPort);
	var mySessID = myRExec.createSessionEx(new MQSession());
	var myGcColl = new MQLocationCollection("MQGeoAddress");
	var myRtResults = new MQRouteResults();
	var myAddressColl = new MQLocationCollection();
	var myRtColl = new MQLocationCollection("MQGeoAddress");
	var myGcResultCollColl = new MQLocationCollectionCollection();

	myOptions.setMaxShapePointsPerManeuver(200);

	myFAddress.setStreet(document.getElementById("Fstreet").value);
	myFAddress.setCity(document.getElementById("Fcity").value);
	myFAddress.setState(document.getElementById("Fstate").value);
	myFAddress.setPostalCode(document.getElementById("Fpostalcode").value);
	myFAddress.setCountry("US");
	myTAddress.setStreet(document.getElementById("Tstreet").value);
	myTAddress.setCity(document.getElementById("Tcity").value);
	myTAddress.setState(document.getElementById("Tstate").value);
	myTAddress.setPostalCode(document.getElementById("Tpostalcode").value);
	myTAddress.setCountry("US");
	myOptions.setLanguage(document.getElementById("lang").value);
	myAddressColl.add(myFAddress);
	myAddressColl.add(myTAddress);

	myGExec.batchGeocode(myAddressColl,myGcResultCollColl);
	for (intX = 0; intX < myGcResultCollColl.getSize();intX++){
		myRtColl.add(myGcResultCollColl.get(intX).get(0));
	}
	myRExec.doRoute(myRtColl,myOptions,myRtResults,mySessID);
	onRtEnd(myRtResults,mySessID,myRtColl);
}


//---------------------------------------------------------------------------------------
function onRtEnd(myRouteRes){
	var myTrkRtColl = new MQTrekRouteCollection();
	var myManeuverColl = new MQManeuverCollection();
	var myManStr = '';
	var myTrkStr = '';
	var myMinutes = myRouteRes.getTime()/60;

	shrinkDivs("results");
	if (myMinutes > 60) {
		if (myMinutes/60 == 1) {
			var myTotTime = '1 hr ';
		}
		else {
			var myTotTime = Math.round((myMinutes/60)*100)/100 + ' hrs';
		}
	}
	else {
		var myTotTime = myMinutes + ' min';
	}
	var myDist = Math.round(myRouteRes.getDistance()*100)/100;

	myTrkRtColl = myRouteRes.getTrekRoutes();
	myManeuverColl = myTrkRtColl.get(0).getManeuvers();

	for (intX = 0; intX < myManeuverColl.getSize(); intX ++){
		myManDist = Math.round(myManeuverColl.get(intX).getDistance()*100)/100;
		myManStr = (intX +1) +  '. ' + myManeuverColl.get(intX).getNarrative() + '(Distance: ' + myManDist + ' mi)';
		myTrkStr = myTrkStr + myManStr + '<br/><hr/>';
	}
	document.getElementById('resultsDiv').innerHTML = "<h3>Routing Result</h3><hr/><b>DRIVING DIRECTIONS: </b><br/><hr/>" + myTrkStr + "<b>Total Time: </b>" + myTotTime + "<b> Total Distance: </b>" + myDist + " miles<hr/><br/>";
	expandResultsDiv();

}



//****************************************************************************************************************
//***********BEGIN BATCH GEOCODING FUNCTIONS******************************************************************************
//-------------------------------------------------------------------------------------
function doFlashBatchGeocode(list){
	givenList = list;
	var myBGExec = new MQExec(geocodeServerName,serverPath,serverPort);
	var myAddressColl = new MQLocationCollection();
	var myBGcResultCollColl = new MQLocationCollectionCollection();
	
                var i = list.length;
                var a = 0;
                for (a = 0; a < i; a++) {
                    var myAddress = new MQAddress();
					myAddress.setStreet(list[a][0]);
					myAddress.setCity(list[a][1]);
					myAddress.setState(list[a][2]);
					myAddress.setPostalCode(list[a][3]);
					myAddress.setCountry("US");
					myAddressColl.add(myAddress);
                }
   myBGExec.batchGeocode(myAddressColl,myBGcResultCollColl,new MQAutoGeocodeCovSwitch(),onBatchGcEnd);
}




//---------------------------------------------------------------------------------------
function onBatchGcEnd(myLocCollColl){
	var myLocColl = new MQLocationCollection();
	var myRetAddr = new MQGeoAddress();
	var myStrOut = '';
	myMap.removeAllPois();

	myStrOut += "<h3>Batch Geocoding Result</h3><hr/>";
	for (var intB = 0;intB < myLocCollColl.getSize();intB ++) {
		myLocColl = myLocCollColl.get(intB);
	    myStrOut += "<br/>===========  LOCATION COLLECTION # " +  intB +   "  ===================<br/>";
		//alert("current comm_name = "+list[intB][4]);
	    for (var intA = 0; intA < myLocColl.getSize();intA ++) {
	    	myRetAddr = myLocColl.get(intA);
			popupBatchInfo(myRetAddr.getStreet(), myRetAddr.getCity(), myRetAddr.getState(), givenList[intB][3], myRetAddr.getMQLatLng().getLatitude(), myRetAddr.getMQLatLng().getLongitude(), givenList[intB][4], givenList[intB][5], givenList[intB][6], givenList[intB][7], givenList[intB][8], givenList[intB][9]);
	   }
	}
	document.getElementById('completeArray').value = latLgn;		
	
}
// Search Results Popup
function popupBatchInfo(street, city, state, zip, lat, lon, cname, photo, link, builder, price, hometype){
	
	//alert("current comm_name1 = "+cname);
	strInput += "<input type='hidden' ID='street"+latLgn.length+"' value='"+street+"' />";
	strInput += "<input type='hidden' ID='city"+latLgn.length+"' value='"+city+"' />";
	strInput += "<input type='hidden' ID='state"+latLgn.length+"' value='"+state+"' />";
	strInput += "<input type='hidden' ID='zip"+latLgn.length+"' value='"+zip+"' />";
	strInput += "<input type='hidden' ID='lat"+latLgn.length+"' value='"+lat+"' />";
	strInput += "<input type='hidden' ID='lon"+latLgn.length+"' value='"+lon+"' /><br/>";
	document.getElementById('completeAddr').innerHTML = strInput;		
	latLgn[latLgn.length]=[street, city, state, zip, lat,lon];
	//Create a new MQPoi object and set its location
	myPoint = new MQPoi(new MQLatLng(lat,lon));
	newCenter = new MQLatLng(lat,lon);
	myMap.setCenter(newCenter,8);
	//set any rollover and pop-up text]
	var str = street.split(' ').join('%20');
	var city1 = city.split(' ').join('%20');
	var is_minor = parseFloat(navigator.appVersion.toLowerCase());
	var iePos  = navigator.appVersion.toLowerCase().indexOf('msie');
	var is_mac = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1);
    if (iePos !=-1) {
       if(is_mac) {
           var iePos = navigator.userAgent.toLowerCase().indexOf('msie');
           is_minor = parseFloat(navigator.userAgent.toLowerCase().substring(iePos+5,navigator.userAgent.toLowerCase().indexOf(';',iePos)));
       }
       else is_minor = parseFloat(navigator.appVersion.toLowerCase().substring(iePos+5,navigator.appVersion.toLowerCase().indexOf(';',iePos)));
    }
	var is_ie = (iePos != -1);
	if (is_ie && is_minor < 7&& parseFloat(navigator.appVersion.toLowerCase().substring(iePos + 5, navigator.appVersion.toLowerCase().indexOf(';', iePos)))) {
		var toandfrom = "Not supported, please <br/>upgrade to IE7 or use Firefox.";
	}
	else {
		var from = "<a href='javascript:void(0);' onclick=fillFrom('" + str + "','" + city1 + "','" + state + "','" + zip + "'); >from here</a>";
		var to = "<a href='javascript:void(0);' onclick=fillTo('" + str + "','" + city1 + "','" + state + "','" + zip + "'); >to here</a>";
		var toandfrom = to+' | '+from
	}
	myIcon = new MQMapIcon();
	myIcon.setImage("/images/mapquest/house.gif",32,32,true,false);
	var listingURL = "<a href="+link+" alt='Click for more details' >"+cname+"</a>";		 
	myPoint.setInfoTitleHTML(listingURL);
	infoSummary = '<p>'+builder+'<br/>'+price+'<br/>'+hometype+'</p>';
	if (photo != ""){
		var address = '<img src="'+photo+'" width="50" height="50" alt="thumbnail" />'+'<p>'+street+'<br/>'+city+'<br/>'+state+' '+zip+'</p>'+'<div class="tofrom">Directions: '+toandfrom+'</div>';
	}
	else{
		var address = '<p>'+street+'<br/>'+city+'<br/>'+state+' '+zip+'</p>'+'<div class="tofrom">Directions: '+toandfrom+'</div>';
	}
	myPoint.setInfoContentHTML(infoSummary+address);
		
	
	//Set the custom icon for the POI
	myPoint.setIcon(myIcon);
	
	
	//you can set a Key value to help keep track of the POIs you put on the map
	myPoint.setKey('32');
	//Add the POI to the map
	myMap.addPoi(myPoint);
	//return latLgn;

}

//******************************************************************************************************************
//***********BEGIN REVERSE GEOCODING FUNCTIONS**********************************************************************
//-------------------------------------------------------------------------------------
function prepareRevGc(){
	shrinkDivs("both");

		strInput += " Reverse Geocoding Input</h3>";
		strInput += "<table border='0' ID='TableRGc'><tr><td><b>Latitude:</b></td>";
		strInput += "<td><input type='text' ID='LATin' size='30' value='38.895' /></td>";
		strInput += "</tr><tr><td><b>Longitude:</b></td>";
		strInput += "<td><input type='text' ID='LONGin' size='30' value='-77.036697' /></td>";
		strInput += "</tr><tr><td><b>Data Source ID:</b></td>";
		strInput += "<td><input type='text' ID='MAPin' size='30' value='navt' /></td>";
		strInput += "</tr><tr><td><b>Geocode Source ID:</b></td>";
		strInput += "<td><input type='text' ID='GEOin' size='30' value='us_postal' /></td></tr>";

		strInput += "<br/><tr colspan='2'><td><input type='button' value='Reverse Geocode' onclick='doFlashRevGc()' id='btnFlGC'/></td></tr></table>";
		

	document.getElementById('inputDiv').innerHTML = strInput;
	document.getElementById('inputDiv').style.height = "auto";
}


//-------------------------------------------------------------------------------------
//function doFlashRevGc(){
//	var myRevGcExec = new MQExec(mqMapServer,serverPath,serverPort);
//	var myRevGcLocColl = new MQLocationCollection("MQGeoAddress");
//	var myRevGcLL = new MQLatLng(document.getElementById("LATin").value,document.getElementById("LONGin").value);
//	myMapSource = '';
//	myMapSource = document.getElementById("MAPin").value;
//	myGeoSource = '';
//	myGeoSource = document.getElementById("GEOin").value;
//
//    myRevGcExec.reverseGeocode(myRevGcLL,myRevGcLocColl,myMapSource,myGeoSource,onRevGcEnd);
//}
//Another option
//function doFlashRevGc(LATin, LONGin){
//	var myRevGcExec = new MQExec(mqMapServer,serverPath,serverPort);
//	var myRevGcLocColl = new MQLocationCollection("MQGeoAddress");
//	var myRevGcLL = new MQLatLng(LATin,LONGin);
//	myMapSource = '';
//	myMapSource = 'navt';
//	myGeoSource = '';
//	myGeoSource = 'us_postal';
//	alert("in js = "+latlonCollect.length);
//    myRevGcExec.reverseGeocode(myRevGcLL,myRevGcLocColl,myMapSource,myGeoSource,onRevGcEnd);
//}
//trying batch reverse
function doBatchFlashRevGc(){
	var myRevGcExec = new MQExec(mqMapServer,serverPath,serverPort);
	var myRevGcLocColl = new MQLocationCollection("MQGeoAddress");
	myMapSource = '';
	myMapSource = 'navt';
	myGeoSource = '';
	myGeoSource = 'us_postal';
	for (a = 0; a < latlonCollect.length; a++) {
		var myRevGcLL = new MQLatLng(latlonCollect[a][0], latlonCollect[a][1]);
		//alert("in js = " + latlonCollect[a][2]);
		myRevGcExec.reverseGeocode(myRevGcLL, myRevGcLocColl, myMapSource, myGeoSource, onRevGcEnd);
	}
}

//Flash reverse Geocode
function doFlashRevGc(lat,lon){
	var myRevGcExec = new MQExec(mqMapServer,serverPath,serverPort);
	var myRevGcLocColl = new MQLocationCollection("MQGeoAddress");
	myMapSource = '';
	myMapSource = 'navt';
	myGeoSource = '';
	myGeoSource = 'us_postal';
	var myRevGcLL = new MQLatLng(lat,lon);
	myRevGcExec.reverseGeocode(myRevGcLL, myRevGcLocColl, myMapSource, myGeoSource, onRevGcEnd);
	
}
//---------------------------------------------------------------------------------------
function doProxyRevGc(lat,lon){
	var myRevGcExec = new MQExec(mqMapServer,mqPath,mqMapPort,myPxyServer,myPxyPath,myPxyPort);
	var myRevGcLocColl = new MQLocationCollection("MQGeoAddress");
	var myRevGcLL = new MQLatLng(lat,lon);
	myMapSource = '';
	myMapSource = 'navt';
	myGeoSource = '';
	myGeoSource = 'us_postal';


 	myRevGcExec.reverseGeocode(myRevGcLL,myRevGcLocColl,myMapSource,myGeoSource);
	onRevGcEnd(myRevGcLocColl);
}

//---------------------------------------------------------------------------------------
//function doProxyRevGc(){
//	var myRevGcExec = new MQExec(mqMapServer,mqPath,mqMapPort,myPxyServer,myPxyPath,myPxyPort);
//	var myRevGcLocColl = new MQLocationCollection("MQGeoAddress");
//	var myRevGcLL = new MQLatLng(document.getElementById("LATin").value,document.getElementById("LONGin").value);
//	myMapSource = '';
//	myMapSource = document.getElementById("MAPin").value;
//	myGeoSource = '';
//	myGeoSource = document.getElementById("GEOin").value;
//
//
// 	myRevGcExec.reverseGeocode(myRevGcLL,myRevGcLocColl,myMapSource,myGeoSource);
//	onRevGcEnd(myRevGcLocColl);
//}
//--------------------------Old version ------------------------------------
//function onRevGcEnd(GcRetLocColl){
//	shrinkDivs("results");
//
//	var myRetAddr = GcRetLocColl.get(0);
//	var strGcResults = '';
//		strGcResults += "<h3>Reverse Geocoding Result</h3><hr/>";
//		strGcResults += "<b>Result Code:</b><br/>";
//		strGcResults += myRetAddr.getResultCode() + "<br/><br/>";
//		strGcResults += "<b>Address:</b><br/>";
//		strGcResults += myRetAddr.getStreet() + ", " + myRetAddr.getCity() + ", " + myRetAddr.getState() + " " + myRetAddr.getPostalCode() + " " + myRetAddr.getCountry() + "<br/><br/>";
//		strGcResults += "<b>Lat/Lng:</b><br/>";
//		strGcResults += myRetAddr.getMQLatLng().getLatitude() + ", " + myRetAddr.getMQLatLng().getLongitude() + "<br/><br/>";
//		strGcResults += "<b>Source:</b><br/>";
//		strGcResults += myRetAddr.getSourceId() + "<br/><br/>";
//	
//	document.getElementById('resultsDiv1').innerHTML = strGcResults;
//}

//--------------------------POI version ------------------------------------
function onRevGcEnd(GcRetLocColl){
	shrinkDivs("results");

	var myRetAddr = GcRetLocColl.get(0);
//	var poi = new MQPoi(myRetAddr.getMQLatLng());
//    poi.setInfoTitleHTML(myRetAddr.getStreet());
//    poi.setInfoContentHTML(myRetAddr.getStreet() + "<br/>" + myRetAddr.getCity() + "<br/>" + myRetAddr.getState() + " " + myRetAddr.getPostalCode());
//    poi.setKey(myRetAddr.getKey());
//    myMap.addPoi(poi);
	var mystreet = myRetAddr.getStreet();
	//alert(myRetAddr.getStreet());
	var str = mystreet.split(' ').join('%20');		
	var strGcResults = '';
		strGcResults += "<input type='hidden' ID='pstreet' value="+str+" />";
		strGcResults += "<input type='hidden' ID='pcity' value="+myRetAddr.getCity()+" />";
		strGcResults += "<input type='hidden' ID='pstate' value="+myRetAddr.getState()+" />";
		strGcResults += "<input type='hidden' ID='pzip' value="+myRetAddr.getPostalCode()+" />";
		
	document.getElementById('resultsDiv1').innerHTML = strGcResults;
	return ;
}
//******************************************************************************************************************
//***********BEGIN GET SERVER INFO FUNCTIONS************************************************************************
//-------------------------------------------------------------------------------------
function prepareGetInfo(){
	shrinkDivs("both");

		doIfFlashStr();
		strInput += "Get Server Information Input</h3>";
		strInput += "<table ID='Table1' border='0'><tr><td><b>Server: </b></td><td><input type='text' ID='infoserver' value='geocode.access.mapquest.com'></td></tr>";
		strInput += "<tr><td><b>Port: </b></td><td><input type='text' ID='infoport' value='80'></td></tr>";
		strInput += "<tr><td><b>Path: </b></td><td><input type='text' ID='infopath' SIZE='2' maxlength='2' value='mq'></td></tr>";
		strInput += "<tr><td><b>Type: </b></td><td><select id='infotype'><option value ='0'>Coverage</option><option value ='1'>MapDataSelector</option></select></td</tr>";
		if(blnFlash == true){
			strInput += "<br/><tr colspan='2'><td><input type='button' value='Get Server Info' onclick='doFlashGetInfo()' id='btnFlGetInfo'/></td></tr></table>";
		}
		else {
			strInput += "<br/><tr colspan='2'><td><input type='button' value='Get Server Info' onclick='doProxyGetInfo()' id='btnPxyGetInfo'/></td></tr></table>";
		}

	document.getElementById('inputDiv').innerHTML = strInput;
	document.getElementById('inputDiv').style.width = "300px";
	document.getElementById('inputDiv').style.height = "230px";
}


//-------------------------------------------------------------------------------------
function doFlashGetInfo(){
	var myInfoExec = new MQExec(document.getElementById('infoserver').value,document.getElementById('infopath').value,document.getElementById('infoport').value);

    myInfoExec.getServerInfo(parseInt(document.getElementById('infotype').value),onGetInfoEnd);
}


//---------------------------------------------------------------------------------------
function doProxyGetInfo(){
	var myInfoExec = new MQExec(document.getElementById('infoserver').value,document.getElementById('infopath').value,document.getElementById('infoport').value,myPxyServer,myPxyPath,myPxyPort);
    var myXML = myInfoExec.getServerInfo(parseInt(document.getElementById('infotype').value));

    onGetInfoEnd(myXML);
}


//---------------------------------------------------------------------------------------
function onGetInfoEnd(myInfoXML){
	shrinkDivs("results");

	var strInfoResults = '';
		strInfoResults += "<h3>Get Server Information Result</h3>";
		strInfoResults += "<textarea rows='15' cols='100' id='taResultXML' accessKey='y' name='taResultData'>";
		strInfoResults += "</textarea>";

	document.getElementById('resultsDiv').innerHTML = strInfoResults;
	expandResultsDiv();
	document.getElementById('taResultXML').value = mqXmlToStr(myInfoXML);

}





//****************************************************************************************************************
//***********BEGIN ROUTE MATRIX FUNCTIONS*************************************************************************
//-------------------------------------------------------------------------------------
function prepareRouteMatrix(){
	shrinkDivs("both");

		doIfFlashStr();
		strInput += "Route Matrix Input</h3>";
		strInput += "<table id='rm' border='0'><tr><td><table ID='Table1RM' border='0'><tr><td colspan='2'><b>Location 1:</b></td></tr>";
		strInput += "<tr><td>Street: </td><td><input type='text' ID='1street' value='3710 Hempland Road'></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='1city' value='Mountville'></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='1state' SIZE='2' maxlength='2' value='PA'></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='1postalcode' SIZE='5' maxlength='5' value='17554'></td></tr></table>";
		strInput += "</td><td>&nbsp</td><td><table ID='Table2RM' border='0'><tr><td colspan='2'><b>Location 2:</b></td></tr>";
		strInput += "<tr><td>Street: </td><td><input type='text' ID='2street' value='300 Granite Run Drive'></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='2city' value='Lancaster'></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='2state' SIZE='2' maxlength='2' value='PA'></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='2postalcode' SIZE='5' maxlength='5' value='17601'></td></tr></table>";
		strInput += "</td><td>&nbsp</td><td><table ID='Table3RM' border='0'><tr><td colspan='2'><b>Location 3:</b></td></tr>";
		strInput += "<tr><td>Street: </td><td><input type='text' ID='3street' value='100 Hershey Park Drive'></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='3city' value='Hershey'></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='3state' SIZE='2' maxlength='2' value='PA'></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='3postalcode' SIZE='5' maxlength='5' value='17033'></td></tr></table>";
		strInput += "</td><td>&nbsp</td><td><table ID='Table4RM' border='0'><tr><td colspan='2'><b>Location 4:</b></td></tr>";
		strInput += "<tr><td>Street: </td><td><input type='text' ID='4street' value='501 E. Pratt Street'></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='4city' value='Baltimore'></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='4state' SIZE='2' maxlength='2' value='MD'></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='4postalcode' SIZE='5' maxlength='5' value='21202'></td></tr></table>";
		strInput += "<tr colspan='2'><td>&nbsp</td></tr><tr colspan='2'><td><b>Type: </b><select id='RtMxtype'><option value='true'>All to All</option><option value='false'>One to All</option></select></td></tr></table>";
		if(blnFlash == true){
			strInput += "<br/><tr colspan='2'><td><input type='button' value='Do Route Matrix' onclick='doFlashRtMx()' id='btnFlRtMx'/></td></tr></table>";
		}
		else {
			strInput += "<br/><tr colspan='2'><td><input type='button' value='Do Route Matrix' onclick='doProxyRtMx()' id='btnPxyRtMx'/></td></tr></table>";
		}

	document.getElementById('inputDiv').innerHTML = strInput;
	//document.getElementById('inputDiv').style.width = "950px";
	document.getElementById('inputDiv').style.height = "auto";
}


//-------------------------------------------------------------------------------------
function doFlashRtMx(){
	var myAddress1 = new MQAddress();
	var myAddress2 = new MQAddress();
	var myAddress3 = new MQAddress();
	var myAddress4 = new MQAddress();
	var myBGExec = new MQExec(mqGcServer,mqPath,mqGcPort);
	var myBGcResultCollColl = new MQLocationCollectionCollection();
	myAddressColl = new MQLocationCollection();

	if(document.getElementById('RtMxtype').value == "true") {
		myAlltoAllFlag = true;
	}
	else {
		myAlltoAllFlag = false;
	}

	myAddress1.setStreet(document.getElementById("1street").value);
	myAddress1.setCity(document.getElementById("1city").value);
	myAddress1.setState(document.getElementById("1state").value);
	myAddress1.setPostalCode(document.getElementById("1postalcode").value);
	myAddress1.setCountry("US");
	myAddress2.setStreet(document.getElementById("2street").value);
	myAddress2.setCity(document.getElementById("2city").value);
	myAddress2.setState(document.getElementById("2state").value);
	myAddress2.setPostalCode(document.getElementById("2postalcode").value);
	myAddress2.setCountry("US");
	myAddress3.setStreet(document.getElementById("3street").value);
	myAddress3.setCity(document.getElementById("3city").value);
	myAddress3.setState(document.getElementById("3state").value);
	myAddress3.setPostalCode(document.getElementById("3postalcode").value);
	myAddress3.setCountry("US");
	myAddress4.setStreet(document.getElementById("4street").value);
	myAddress4.setCity(document.getElementById("4city").value);
	myAddress4.setState(document.getElementById("4state").value);
	myAddress4.setPostalCode(document.getElementById("4postalcode").value);
	myAddress4.setCountry("US");
	myAddressColl.add(myAddress1);
	myAddressColl.add(myAddress2);
	myAddressColl.add(myAddress3);
	myAddressColl.add(myAddress4);


	myBGExec.batchGeocode(myAddressColl,myBGcResultCollColl,new MQAutoGeocodeCovSwitch(),onRtMxBatchGcEnd);
}


//---------------------------------------------------------------------------------------
function doProxyRtMx(){
	var myAddress1 = new MQAddress();
	var myAddress2 = new MQAddress();
	var myAddress3 = new MQAddress();
	var myAddress4 = new MQAddress();
	var myBGExec = new MQExec(mqGcServer,mqPath,mqGcPort,myPxyServer,myPxyPath,myPxyPort);
	var myRtMxExec = new MQExec(mqRtServer,mqPath,mqRtPort,myPxyServer,myPxyPath,myPxyPort);
	var myBGcResultCollColl = new MQLocationCollectionCollection();
	var myRtMxResults = new MQRouteMatrixResults();
	var myRtMxColl = new MQLocationCollection();
	myAddressColl = new MQLocationCollection();

	if(document.getElementById('RtMxtype').value == "true") {
		myAlltoAllFlag = true;
	}
	else {
		myAlltoAllFlag = false;
	}

	myAddress1.setStreet(document.getElementById("1street").value);
	myAddress1.setCity(document.getElementById("1city").value);
	myAddress1.setState(document.getElementById("1state").value);
	myAddress1.setPostalCode(document.getElementById("1postalcode").value);
	myAddress1.setCountry("US");
	myAddress2.setStreet(document.getElementById("2street").value);
	myAddress2.setCity(document.getElementById("2city").value);
	myAddress2.setState(document.getElementById("2state").value);
	myAddress2.setPostalCode(document.getElementById("2postalcode").value);
	myAddress2.setCountry("US");
	myAddress3.setStreet(document.getElementById("3street").value);
	myAddress3.setCity(document.getElementById("3city").value);
	myAddress3.setState(document.getElementById("3state").value);
	myAddress3.setPostalCode(document.getElementById("3postalcode").value);
	myAddress3.setCountry("US");
	myAddress4.setStreet(document.getElementById("4street").value);
	myAddress4.setCity(document.getElementById("4city").value);
	myAddress4.setState(document.getElementById("4state").value);
	myAddress4.setPostalCode(document.getElementById("4postalcode").value);
	myAddress4.setCountry("US");
	myAddressColl.add(myAddress1);
	myAddressColl.add(myAddress2);
	myAddressColl.add(myAddress3);
	myAddressColl.add(myAddress4);


	myBGExec.batchGeocode(myAddressColl,myBGcResultCollColl);
	for(var intX = 0; intX < myBGcResultCollColl.getSize(); intX ++) {
		myRtMxColl.add(myBGcResultCollColl.get(intX).get(0));
	}
	myRtMxExec.doRouteMatrix(myRtMxColl,myAlltoAllFlag,new MQRouteOptions(),myRtMxResults);
	onRtMxEnd(myRtMxResults);
}


//---------------------------------------------------------------------------------------
function onRtMxBatchGcEnd(RtMxCollColl){
	var myRtMxExec = new MQExec(mqRtServer,mqPath,mqRtPort);
	var myRtMxResults = new MQRouteMatrixResults();
	var myRtMxColl = new MQLocationCollection();

	if(document.getElementById('RtMxtype').value == "true") {
		myAlltoAllFlag = true;
	}
	else {
		myAlltoAllFlag = false;
	}

	for(var intX = 0; intX < RtMxCollColl.getSize(); intX ++) {
		myRtMxColl.add(RtMxCollColl.get(intX).get(0));
	}

	myRtMxExec.doRouteMatrix(myRtMxColl,myAlltoAllFlag,new MQRouteOptions(),myRtMxResults,onRtMxEnd);
}


//---------------------------------------------------------------------------------------
function onRtMxEnd(myRtMatResults){
	var myStrOut = '';

	myStrOut += "<h3>Route Matrix Results</h3><hr/>";
	myStrOut += "<b>All to All: </b>" + myRtMatResults.getAllToAllFlag() + "<br/>";
	if (myRtMatResults.getAllToAllFlag()) {
    	for (var intOut = 0; intOut < myAddressColl.getSize(); intOut ++) {
      		var myO = '';
      		myO += "<br/>---------------------------------------------------------------------------<br/>";
      		myO += "<b>FROM:</b><br/>";
      		myO += myAddressColl.get(intOut).getStreet() + "<br/>";
      		myO += myAddressColl.get(intOut).getCity() + ", " + myAddressColl.get(intOut).getState() + "<br/>";
      		myO += myAddressColl.get(intOut).getPostalCode() + "<br/>";
      		myO += myAddressColl.get(intOut).getCountry() + "<br/>";
      		for (var intIN = 0; intIN < myAddressColl.getSize(); intIN ++) {
      			if (intIN != intOut) {
      				var myD = '';
       				myD += "<br/><b>TO:</b><br/>";
      				myD += myAddressColl.get(intIN).getStreet() + "<br/>";
      				myD += myAddressColl.get(intIN).getCity() + ", " + myAddressColl.get(intIN).getState() + "<br/>";
      				myD += myAddressColl.get(intIN).getPostalCode() + "<br/>";
      				myD += myAddressColl.get(intIN).getCountry() + "<br/><br/>";
      				myD += "<br/><b>Time: </b>" + Math.round(myRtMatResults.getTime(0,intIN)/60*100)/100  + " minutes<br/><br/>";
      				myD += "<b>Distance: </b>" + Math.round(myRtMatResults.getDistance(0,intIN)*100)/100 + " miles<br/>";
      				myStrOut += myO + myD;
      			}
      		}
      	}
      }
      else {
      	var myOrigin = '';
      	myOrigin += "<br/>---------------------------------------------------------------------------<br/>";
      	myOrigin += "<b>FROM:</b><br/>";
      	myOrigin += myAddressColl.get(0).getStreet() + "<br/>";
      	myOrigin += myAddressColl.get(0).getCity() + ", " + myAddressColl.get(0).getState() + "<br/>";
      	myOrigin += myAddressColl.get(0).getPostalCode() + "<br/>";
      	myOrigin += myAddressColl.get(0).getCountry() + "<br/>";
      	for (var intR = 1; intR < myAddressColl.getSize(); intR ++) {
      		var myDest= '';
       		myDest += "<br/><b>TO:</b><br/>";
      		myDest += myAddressColl.get(intR).getStreet() + "<br/>";
      		myDest += myAddressColl.get(intR).getCity() + ", " + myAddressColl.get(intR).getState() + "<br/>";
      		myDest += myAddressColl.get(intR).getPostalCode() + "<br/>";
      		myDest += myAddressColl.get(intR).getCountry() + "<br/><br/>";
      		myDest += "<br/><b>Time: </b>" + Math.round(myRtMatResults.getTime(0,intR)/60*100)/100  + " minutes<br/><br/>";
      		myDest += "<b>Distance: </b>" + Math.round(myRtMatResults.getDistance(0,intR)*100)/100 + "  miles<br/>";
      		myStrOut += myOrigin + myDest;
      	}
     }

	document.getElementById("resultsDiv").innerHTML = myStrOut;
	expandResultsDiv();

}



//****************************************************************************************************************
//***********BEGIN SEARCH FUNCTIONS*******************************************************************************
//-------------------------------------------------------------------------------------
function prepareSearch(street, city, state, zip){
	shrinkDivs("both");
	
		strInput = "";
		strInput += "<h3>Search Input</h3> ";
		strInput += "<b>Perform a radius search around the following address:</b><br/>";
		strInput += "<table ID='TableS1' border='0'><tr><td>Street: </td><td><input type='text' ID='srchStreet' value='"+street+"'/></td></tr>";
		strInput += "<tr><td>City: </td><td><input type='text' ID='srchCity' value='"+city+"'/></td></tr>";
		strInput += "<tr><td>State: </td><td><input type='text' ID='srchState' SIZE='2' maxlength='2' value='"+state+"'/></td></tr>";
		strInput += "<tr><td>Zip/Postal: </td><td><input type='text' ID='srchPostalCode' SIZE='5' maxlength='5' value='"+zip+"'/></td></tr>";
		strInput += "</table><br/>";
		strInput += "<b>Search Options:</b><br/><table ID='TableS2' border='0'>";
		strInput += "<tr><td>Radius (miles):</td><td><input size='2' id='srchRadius' type='text' value='35' size='2'/></td>";
		strInput += "<tr><td>Max results:</td><td><input size='3' id='srchMaxResults' type='text' value='10' size='3'/></td></table>";
		strInput += "<br/><tr colspan='2'><td><input type='button' value='Search' onclick='doFlashSearch(street, city, state, zip)' id='btnFlRtMx'/></td></tr></table>";
		

	document.getElementById('inputDiv').innerHTML = strInput;
	document.getElementById('inputDiv').style.width = "auto";
	document.getElementById('inputDiv').style.height = "auto";
}


//-------------------------------------------------------------------------------------
function doFlashSearch(street, city, state, zip){
	var myGcExec = new MQExec(mqGcServer,mqPath,mqGcPort);
	var myAddress = new MQAddress();
	
	var str = street.split('%20').join(' ');
	myAddress.setStreet(str);
	myAddress.setCity(city);
	myAddress.setState(state);
	myAddress.setPostalCode(zip);
	myAddress.setCountry("US");

	myGcExec.geocode(myAddress,new MQLocationCollection(),new MQAutoGeocodeCovSwitch(),onFlSearchGcEnd);
}


//---------------------------------------------------------------------------------------
function doProxySearch(){
	var myGcExec = new MQExec(mqGcServer,mqPath,mqGcPort,myPxyServer,myPxyPath,myPxyPort);
	var mySrchExec = new MQExec(mqSptServer,mqPath,mqSptPort,myPxyServer,myPxyPath,myPxyPort);
    var myAddress = new MQAddress();
	var myLocColl = new MQLocationCollection();
	var strCriteria = new MQRadiusSearchCriteria();
	var myDBLQueryColl = new MQDBLayerQueryCollection();
	var myDBLQuery = new MQDBLayerQuery();
	var mySearchResults = new MQFeatureCollection();

	myAddress.setStreet(street);
    myAddress.setCity(city);
    myAddress.setState(state);
    myAddress.setPostalCode(zip);
    myAddress.setCountry("US");

//	myGcExec.geocode(myAddress,myLocColl);
//	var myGeoAddress = myLocColl.get(0);
	var thisLat = document.getElementById('lat').value;
	var thisLon = document.getElementById('lon').value;

	strCriteria.setMaxMatches(document.getElementById('srchMaxResults').value);
	strCriteria.setRadius(document.getElementById('srchRadius').value);
	strCriteria.setCenter(new MQLatLng(thisLat,thisLon), 8);

	myDBLQuery.setDBLayerName("MQA.NTPois");
	myDBLQueryColl.add(myDBLQuery);

	mySrchExec.search(strCriteria,mySearchResults,'',myDBLQueryColl);
	onSearchEnd(mySearchResults);
}


//---------------------------------------------------------------------------------------
function onFlSearchGcEnd(myLocationColl){
	var myGeoAddress = myLocationColl.get(0);
	var mySrchExec = new MQExec(mqSptServer,mqPath,mqSptPort);
	var strCriteria = new MQRadiusSearchCriteria();
	var myDBLQueryColl = new MQDBLayerQueryCollection();
	var myDBLQuery = new MQDBLayerQuery();
	var radius = '7';
	var maxResults = '35';
	var thisLat = myGeoAddress.getMQLatLng().getLatitude();
	var thisLon = myGeoAddress.getMQLatLng().getLongitude();
	//alert('in on flash search end');
	strCriteria.setMaxMatches(maxResults);
	strCriteria.setRadius(radius);
	strCriteria.setCenter(new MQLatLng(thisLat,thisLon), 9);

	myDBLQuery.setDBLayerName("MQA.NTPois");
	myDBLQueryColl.add(myDBLQuery);

	mySrchExec.search(strCriteria,new MQFeatureCollection(),'',myDBLQueryColl,null,null,onSearchEnd);
}


//---------------------------------------------------------------------------------------
function onSearchEnd(mySrchResults){
	var origin = myMap.getCenter();
    myMap.removeAllPois();
	var ids = new MQStringCollection();
	var strSrchResults = '';

	strSrchResults += "<h3>Search Results</h3><hr/>";
	strSrchResults += "<table border='0'><tr><td><b>Result No.</b></td><td><b>Name</b></td><td><b>Distance from Origin (miles)</b></td></tr>";

	for(var i=0;i < mySrchResults.getSize();i++) {
			myResult = mySrchResults.get(i);
			ids.add(myResult.getKey());
    		doFlashGetRecInfo(myResult.getKey());
	}
	
	 //Add the search origin
    var myPoint = new MQPoi(origin, 9);
    var is_minor = parseFloat(navigator.appVersion.toLowerCase());
	var iePos  = navigator.appVersion.toLowerCase().indexOf('msie');
	var is_mac = (navigator.userAgent.toLowerCase().indexOf("mac")!=-1);
    if (iePos !=-1) {
       if(is_mac) {
           var iePos = navigator.userAgent.toLowerCase().indexOf('msie');
           is_minor = parseFloat(navigator.userAgent.toLowerCase().substring(iePos+5,navigator.userAgent.toLowerCase().indexOf(';',iePos)));
       }
       else is_minor = parseFloat(navigator.appVersion.toLowerCase().substring(iePos+5,navigator.appVersion.toLowerCase().indexOf(';',iePos)));
    }
	var is_ie = (iePos != -1);
	if (is_ie && is_minor < 7&& parseFloat(navigator.appVersion.toLowerCase().substring(iePos + 5, navigator.appVersion.toLowerCase().indexOf(';', iePos)))) {
		var toandfrom = "Not supported, please <br/>upgrade to IE7 or use Firefox.";
	}
	else {
		var from = "<a href='javascript:void(0);' onclick=fillFrom('" + str + "','" + city1 + "','" + state + "','" + zip + "'); >from here</a>";
		var to = "<a href='javascript:void(0);' onclick=fillTo('" + str + "','" + city1 + "','" + state + "','" + zip + "'); >to here</a>";
		var toandfrom = to+' | '+from
	}
	
	myPoint.setIcon(myIcon);
    myPoint.setInfoTitleHTML(name);
	if (photo != ""){
		var address = '<img src="'+photo+'" width="50" height="50" alt="thumbnail" />'+'<p>'+street+'<br/>'+city+'<br/>'+state+' '+zip+'</p>'+'<div class="tofrom">Directions: '+toandfrom+'</div>';
	}
	else{
		var address = '<p>'+street+'<br/>'+city+'<br/>'+state+' '+zip+'</p>'+'<div class="tofrom">Directions: '+toandfrom+'</div>';
	}
	myPoint.setInfoContentHTML('<div style="width:200px;">' + address + '</div>');
	myPoint.setKey('Origin');
    myMap.addPoi(myPoint);
    myMap.setCenter(origin,9);
	expandResultsDiv();

}




//******************************************************************************************************************
//***********BEGIN GET RECORD INFO FUNCTIONS************************************************************************
//-------------------------------------------------------------------------------------
function prepareGetRecInfo(){
	shrinkDivs("both");

		doIfFlashStr();
		strInput += "Get Record Information Input</h3>";
		strInput += "<table ID='Table1' border='0'><tr><td><b>Server: </b></td><td><input type='text' ID='recinfoserver' value='spatial.access.mapquest.com'></td></tr>";
		strInput += "<tr><td><b>Port: </b></td><td><input type='text' ID='recinfoport' value='80'></td></tr>";
		strInput += "<tr><td><b>Path: </b></td><td><input type='text' ID='recinfopath' SIZE='2' maxlength='2' value='mq'></td></tr>";
		strInput += "<tr><td><b>Table Name: </b></td><td><input type='text' ID='recinfodbl' SIZE='20' maxlength='20' value='MQA.test'></td></tr>";
		strInput += "<tr><td><b>Record Id: </b></td><td><input type='text' ID='recinfoid' SIZE='20' maxlength='20' value='280718'></td></tr>";
		strInput += "<tr><b>Field:</b></td><td><select id='recinfofield'>";
		strInput += "<option value ='T'>Type</option><option value ='Lat'>Latitude</option>";
		strInput += "<option value ='Lng'>Longitude</option></select></td></tr>";
		if(blnFlash == true){
			strInput += "<br/><tr colspan='2'><td><input type='button' value='Get Record Info' onclick='doFlashGetRecInfo()' id='btnFlGetInfo'/></td></tr></table>";
		}
		else {
			strInput += "<br/><tr colspan='2'><td><input type='button' value='Get Record Info' onclick='doProxyGetRecInfo()' id='btnPxyGetInfo'/></td></tr></table>";
		}

	document.getElementById('inputDiv').innerHTML = strInput;
	document.getElementById('inputDiv').style.width = "320px";
	document.getElementById('inputDiv').style.height = "auto";
}



function doFlashGetRecInfo(poiKey){
	var myRecInfoExec = new MQExec(mqSptServer,mqPath,mqMapPort);
	var myFieldNameColl = new MQStringCollection();
	var myResults = new MQRecordSet();
	var myDBLQuery = new MQDBLayerQuery();
	var myRecIdColl = new MQStringCollection();
	myFieldNameColl.add("N");
	myFieldNameColl.add("Address");
	myFieldNameColl.add("City");
	myFieldNameColl.add("State");
	myFieldNameColl.add("ZIP");
	myFieldNameColl.add("Phone");
	myFieldNameColl.add("Facility");
	myFieldNameColl.add("Food");
	myFieldNameColl.add("ChainId");
	myFieldNameColl.add("Lat");
	myFieldNameColl.add("Lng");
	myFieldNameColl.add("T");
	myDBLQuery.setDBLayerName("MQA.NTPois");
	myRecIdColl.add(poiKey);

    myRecInfoExec.getRecordInfo(myFieldNameColl,myDBLQuery,myResults,myRecIdColl,onGetRecInfoEnd);
}

//---------------------------------------------------------------------------------------
function doProxyGetRecInfo(poiKey){
	var myRecInfoExec = new MQExec(mqSptServer,mqPath,mqMapPort,myPxyServer,myPxyPath,myPxyPort);
	var myFieldNameColl = new MQStringCollection();
	var myResults = new MQRecordSet();
	var myDBLQuery = new MQDBLayerQuery();
	var myRecIdColl = new MQStringCollection();

	myFieldNameColl.add("N");
	myFieldNameColl.add("Address");
	myFieldNameColl.add("City");
	myFieldNameColl.add("State");
	myFieldNameColl.add("ZIP");
	myFieldNameColl.add("Phone");
	myFieldNameColl.add("Facility");
	myFieldNameColl.add("Food");
	myFieldNameColl.add("ChainId");
	myFieldNameColl.add("Lat");
	myFieldNameColl.add("Lng");
	myFieldNameColl.add("T");
	myDBLQuery.setDBLayerName("MQA.NTPois");
	myRecIdColl.add(poiKey);

    myRecInfoExec.getRecordInfo(myFieldNameColl,myDBLQuery,myResults,myRecIdColl);
    onGetRecInfoEnd(myResults);
}




function onGetRecInfoEnd(myRS){
	shrinkDivs("results");
	var poi = new MQPoi(new MQLatLng(myRS.getField("Lat"), myRS.getField("Lng")));
	poi.type = myRS.getField("T");
	//var neededPOI = document.getElementById(poi.type);
	//if (neededPOI != null && neededPOI.checked || switchDisplay()) {
	var icon = new MQMapIcon();
	icon.setImage("/images/mq_icons/" + myRS.getField("T") + ".gif", 20, 20, true, false);
	poi.setInfoTitleHTML(myRS.getField("N"));
	poi.setInfoContentHTML('<div style="width:200px;">' + myRS.getField("Address") + "<br/>" + myRS.getField("City") + "<br/>" + myRS.getField("State") + " " + myRS.getField("ZIP") + '<BR/>Phone: ' + myRS.getField("Phone") + '</div>');
	poi.setIcon(icon);
	myMap.addPoi(poi);
	poi.setVisible( false );
	pois[pois.length] = poi;
	//alert(checkPoiType(poi.type));
	// distinct
	if (!checkPoiType(poi.type)) {
		poiTypes[poiTypes.length] = poi.type;
		poiIcons[poiIcons.length] = "/images/mq_icons/" + myRS.getField("T") + ".gif";
		//alert(poiTypes.length);
	}
	
	return;
	//}
}	
	function checkPoiType(type)
	{
		for(var i = 0; i < poiTypes.length; i++)
			if(poiTypes[i]==type) return true;
		return false;
	}



//  For dynamic display of pois
function enableDisplayTypes()
{
	var types = $("display_types");
	var div = $("poi_checklist");
//	 alert(poiTypes.length);
//	 alert(pois.length);
	for(var i = 0; i < poiTypes.length; i++)
	{
		
		var dt = document.createElement("li");
		dt.className="dt";
		div.appendChild(dt);
		
		var input = document.createElement("input");
		input.setAttribute("type","checkbox");
		input.id = poiTypes[i];
		input.value = poiTypes[i];
		input.onclick = switchDisplay;
		dt.appendChild(input);
		input.checked = true;
		
		var icon = document.createElement("img");
		icon.src = poiIcons[i];
		icon.alt = "icon";
		dt.appendChild(icon);
		
		var label = document.createElement("label");
		label.innerHTML = displayTypes['dt'+poiTypes[i]];
		dt.appendChild(label);
		
	}
	function switchDisplay()
	{
		var inputs = types.getElementsByTagName("input");
		for(var i = 0; i < pois.length; i++)
		{
			var visible = false;
			for(var j = 0; j < inputs.length; j++)
				if( inputs[j].value == pois[i].type && inputs[j].checked )
				{
					visible = true; break;
				}
			pois[i].setVisible( visible );
		}
	}
}

//****************************************************************************************************************
//***********BEGIN CREATE SESSION FUNCTIONS***********************************************************************
//-------------------------------------------------------------------------------------
function prepareCreateSession(){
	shrinkDivs("both");

		doIfFlashStr();
		strInput += "Create Session Input</h3>";
		if(blnFlash == true){
			strInput += "<input type='button' value='Create Session' onclick='doFlSesCreate()' id='btnFlCrSession'/>";
		}
		else {
			strInput += "<input type='button' value='Create Session' onclick='doPxySesCreate()' id='btnPxyCrSession'/>";
		}

	document.getElementById('inputDiv').innerHTML = strInput;
	//document.getElementById('inputDiv').style.width = "240px";
	document.getElementById('inputDiv').style.height = "auto";
}


//-------------------------------------------------------------------------------------
function doFlSesCreate(){
	var myRExec = new MQExec(mqRtServer,mqPath,mqRtPort);
	myRExec.createSessionEx(new MQSession(),onCrSessionEnd);
}


//-------------------------------------------------------------------------------------
function doPxySesCreate(){
	var myRExec = new MQExec(mqRtServer,mqPath,mqRtPort,myPxyServer,myPxyPath,myPxyPort);
	var mySessID = myRExec.createSessionEx(new MQSession());
	onCrSessionEnd(mySessID);
}

//---------------------------------------------------------------------------------------
function onCrSessionEnd(mySessionId){
	shrinkDivs("results");

	var strResults = '';
	strResults += "<h3>Create Session Results</h3><hr/>";
	strResults += mySessionId;

	document.getElementById('resultsDiv').innerHTML = strResults;
	expandResultsDiv();

}




//****************************************************************************************************************
//***********BEGIN GET SESSION FUNCTIONS**************************************************************************
//-------------------------------------------------------------------------------------
function prepareGetSession(){
	shrinkDivs("both");

		doIfFlashStr();
		strInput += "Get Session Input</h3>";
			strInput += "<input type='text' size='50' value='paste session id here' id='txtSessionId'/><br/><br/>";

		if(blnFlash == true){
			strInput += "<input type='button' value='Get Session' onclick='doFlSesGet()' id='btnFlGetSession'/>";
		}
		else {
			strInput += "<input type='button' value='Get Session' onclick='doPxySesGet()' id='btnPxyGetSession'/>";
		}

	document.getElementById('inputDiv').innerHTML = strInput;
	//document.getElementById('inputDiv').style.width = "335px";
	document.getElementById('inputDiv').style.height = "auto";
}


// GET SESSION FUNCTIONS HERE


//---------------------------------------------------------------------------------------
function onGetSessionEnd(myGSessionId){
	shrinkDivs("results");

	var strResults = '';
	strResults += "<h3>Get Session Results</h3><hr/>";
	strResults += myGSessionId;

	document.getElementById('resultsDiv').innerHTML = strResults;
	dexpandResultsDiv();

}

function writeDoc(){
	document.getElementById('poiRequest').innerHTML = myInput;
	document.getElementById('clearChecked').innerHTML = checkInput;
}

function showPois(){
	clearPOIs();
	enableDisplayTypes();
	checkAll();
	$('display_types').show();
}

function checkAll(){
	var types = $("poi_checklist");
	var inputs = types.getElementsByTagName("input");
	for (var j = 0; j < inputs.length; j++) {
		inputs[j].checked = true;
		displaySwitch();
	}
	
}
function clearAll(){
	var types = $("poi_checklist");
	var inputs = types.getElementsByTagName("input");
	for (var j = 0; j < inputs.length; j++) {
		inputs[j].checked = false;
		displaySwitch();
	}
	
}
function displaySwitch() {
	var inputs = $("display_types").getElementsByTagName("input");
	for(var i = 0; i < pois.length; i++) {
		var visible = false;
		for(var j = 0; j < inputs.length; j++) {
			if( inputs[j].value == pois[i].type && inputs[j].checked ) {
				visible = true; break;
				}
			}
		pois[i].setVisible( visible );
		
	}
}

