if(!(mainKey)) var mainKey = "mjtd%7Clu6znua2n9%2C7l%3Do5-la70q";
if(!(miniKey)) var miniKey = "mjtd%7Clu6tn1u7n5%2C75%3Do5-lw2aq";

	var myMap;
	var listingLatLng
	var currentRadius

	//Proxy server variables
	var proxyServerName = "";
	var proxyServerPort = "";
	var ProxyServerPath = "jsreqhandler.cfm";
	
	//set up the connection to the geocode server
	var geoServerName = "geocode.access.mapquest.com";
	var geoServerPort = "80";
	var geoServerPath = "mq";
	var geoExec = new MQExec(geoServerName, geoServerPath, geoServerPort, proxyServerName,ProxyServerPath, proxyServerPort );
	
	//set up the connection to the Spatial search server
	var spatServerName = "spatial.access.mapquest.com";
	var spatServerPort = "80";
	var spatServerPath = "mq";
	var searchExec = new MQExec(spatServerName, spatServerPath, spatServerPort, proxyServerName,ProxyServerPath, proxyServerPort );

	function doPOIs(){
		//poiPOICol = new MQPoiCollection();

		tlPix = myMap.pixToLL(new MQPoint(0,0));
		brPix = myMap.pixToLL(new MQPoint(parseInt($('mapWindow').style.width),parseInt($('mapWindow').style.height)));
		tlLL = new MQLatLng(tlPix.lat,tlPix.lng);
		brLL = new MQLatLng(brPix.lat,brPix.lng);

		opt = document.frmPOIMaps.poiSet;

		// build container
		if($('mqwntdiv')){
			$('mqwntdiv').innerHTML = null;
		}else{
			// init the new WNT layer
			tmp1 = document.createElement("div");
			tmp1.id = "mqwntdiv";
			tmp1.style.position = "absolute";
			tmp1.style.top = "0px";
			tmp1.style.left = "0px";
			tmp1.style.cursor = "auto";
			tmp1.style.zIndex = "9";
			$('mqtiledmap').appendChild(tmp1);
		}
		

		var index = 0;
		maxMatch = parseInt(50 / opt.length);
		maxMatch = 10;
		for (var intLoop = 0; intLoop < opt.length; intLoop++) {
			if ((opt[intLoop].selected) || (opt[intLoop].checked)) {
				/*
				var sCriteria = new MQRectSearchCriteria();
	            sCriteria.setMaxMatches(10);
				sCriteria.setUpperLeft(tlLL);
				sCriteria.setLowerRight(brLL);
				*/
				getPoiCol(opt[intLoop].value,opt[intLoop].value,maxMatch);
			}
		}

		if ($F('customPOI')){
			if (!(isNaN($F('customPOI')))){
					getPoiCol($F('customPOI'),4100,maxMatch);
				}
		}

//		listingPOI = new MQPoi(listingLatLng);
//		poiPOICol.add(listingPOI);
//		myMap.replacePois(poiPOICol);
	
		return true;

		
	};

	function getPoiCol(intLoop,ico,maxMatch){
	            var sCriteria = new MQRadiusSearchCriteria();
	            sCriteria.setMaxMatches(10);
	            sCriteria.setRadius(currentRadius);
	            sCriteria.setCenter(listingLatLng);

				//Setup search source - in this case, the Test DB table
				var dbLayerQueryCollection = new MQDBLayerQueryCollection();
				var dbLayerQuery = new MQDBLayerQuery();
				dbLayerQuery.setDBLayerName("MQA.NTPois");
				dbLayerQuery.setExtraCriteria("facility = " + intLoop);
				dbLayerQueryCollection.add(dbLayerQuery);
				
				var searchRes = new MQFeatureCollection();
				searchExec.search(sCriteria, searchRes,'', dbLayerQueryCollection);
	
	            for( var i=0; i<searchRes.getSize(); i++) {
					resultPoint = searchRes.get(i);
					tmp2LL = resultPoint.getCenterLatLng();
					tmp2 =document.createElement("div");
					tmp2.id = ico + (i + "hd");
					tmp2.poiName = resultPoint.getName();
					tmp2.className="poiIcon poi" + ico;

					tmp2.style.left = (myMap.llToPix(tmp2LL).x - parseInt($('mqtiledmap').style.left) - 6) + "px";
					tmp2.style.top = (myMap.llToPix(tmp2LL).y - parseInt($('mqtiledmap').style.top) - 17) + "px";
					Event.observe(tmp2,"mouseover",function(){popOverPoi(this.id)});
					Event.observe(tmp2,"mouseout",function(){killOverPoi(this.id)});
					$('mqwntdiv').appendChild(tmp2);

				/*
				            poiCon = new MQMapIcon();
							poiCon.setShadow("",0,0,0,0,false);
							poiCon.setImage(sharedImagePath + "poi_" + ico + ".png",14,17,false,true);
							poiCon.setAnchorOffset(new MQPoint(-6,-17));
	
	                        resultPoint = searchRes.get(i);
	                        latlng = resultPoint.getCenterLatLng();
							poi = new MQPoi(resultPoint.getCenterLatLng());
							poi.setIcon(poiCon);

	                        poi.setInfoTitleHTML(resultPoint.getName());
	                        poi.setKey(resultPoint.getKey());
	
							poiPOICol.add(poi);
				*/
	            }

	};
	
	function popOverPoi(id){
		if (document.all) {
			srcID = $(event.srcElement);
		} else {
			srcID = $(id);
		}
		currX = parseInt(srcID.style.left);
		currY = parseInt(srcID.style.top);

		if($('onePoiOver')){$('onePoiOver').remove();}
		xxx =document.createElement("div");
		xxx.id = "onePoiOver";
		xxx.style.position = "absolute";
		xxx.style.zIndex = 100;

		xxx.style.left = currX + "px";
		xxx.style.top = (currY - 25) + "px";
		//xxx.style.width = "315px";
		//xxx.style.height = "55px";
		xxx.style.border = "1px Solid #000";
		xxx.style.background = "#fff7ce";
		xxx.style.color = "#000";
		xxx.style.whiteSpace = "nowrap";
		xxx.style.padding = "4px";
		
		xxx.innerHTML = srcID.poiName;
		$('mqwntdiv').appendChild(xxx);
//		xxx.show();


	};

	function whatQ(w,h,x,y){
		qx = 0;
		if (x > (w/3)){qx = 1};
		if (x > ((w/3)*2)){qx = 2};
		if (y > (h/2)){qx = (qx + 3)};
		//alert(w+":"+h+":"+x+":"+y+":"+qx);
		return(qx);
	};


	function killOverPoi(){
		if($('onePoiOver')){$('onePoiOver').remove();}
	};
	
	function showPoiMap(liLat,liLng){
		if (!(myMap)){
			listingLatLng = new MQLatLng(liLat,liLng);
			myMap = new MQTileMap($('mapWindow'),9, listingLatLng,"map",mainKey);
			$('mapWindow').style.visibility = 'hidden';
			$('poiWindow').style.visibility = 'hidden';
			myZControl = new MQZoomControl(myMap);
			myMap.addControl(myZControl, new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,15)));
			myViewControl = new MTViewControl(myMap);
			myMap.addControl(myViewControl);
			myScales = new MQMapCornerPlacement(MQMapCorner.TOP_RIGHT,new MQSize(0,20));
			myMap.setLogoPlacement(MQMapLogo.SCALES,myScales);

			// user tracking
			dbTrack();
			myMap.enableDragging(1);

			currentRadius = new MQLatLng(myMap.pixToLL(new MQPoint(0,0)).lat,myMap.pixToLL(new MQPoint(0,0)).lng).arcDistance(new MQLatLng(myMap.pixToLL(new MQPoint(myMap.getSize().getWidth(),0)).lat,myMap.pixToLL(new MQPoint(myMap.getSize().getWidth(),0)).lng),new MQDistanceUnits(0));


            propIcon = new MQMapIcon();
			//poiCon.setShadow(sharedImagePath + "p_shadow.png",2,6,17,11,true);
			propIcon.setShadow(sharedImagePath + "spacer.gif",0,0,0,0,false);
			//propIcon.setShadow("",0,0,0,0,false);
//			if (featuredProperty){
//				propIcon.setImage(sharedImagePath + "feat_prop.png",58,40,false,true);
//				propIcon.setAnchorOffset(new MQPoint(-29,-40));
//			}else{
				propIcon.setImage(sharedImagePath + "hb_gold.png",21,23,false,true);
				propIcon.setAnchorOffset(new MQPoint(-10,-23));
//			}

			listingPOI = new MQPoi(listingLatLng);
			listingPOI.setIcon(propIcon);
			myMap.addPoi(listingPOI);

			MQEventManager.addListener(myMap,"moveend",doPOIs);
			MQEventManager.addListener(myMap,"zoomend",doPOIs);
			MQEventManager.addListener(myMap,"moveend",dbTrack);
			MQEventManager.addListener(myMap,"zoomend",dbTrack);
			
			new Effect.BlindDown('poiMap', { afterFinish: function() {
					$('mapWindow').style.visibility = 'visible';
					$('poiWindow').style.visibility = 'visible';
				}
			});
		}else{
			if ($('poiMap').visible()){
				$('mapWindow').style.visibility = 'hidden';
				$('poiWindow').style.visibility = 'hidden';
				new Effect.BlindUp('poiMap');
			}else{
				new Effect.BlindDown('poiMap', { afterFinish: function() {
						$('mapWindow').style.visibility = 'visible';
						$('poiWindow').style.visibility = 'visible';
					} 
				});
			}
		}
	};

	function dbTrack(){
		var pars = "page_type=detail&map_type=" + myMap.getMapType();
		var myAjax = new Ajax.Request("jsdbtrack.cfm", {method:"post", postBody:pars});
		//var myAjax = new Ajax.Request("JSDBTrack.cfm");
		//var myAjax = new Ajax.Request("jsdbtrack.cfm", {method:"post", postBody:"page_type=detail"});
	};
	// Thumb Track
	function dbThumbTrack(){
		var pars = "page_type=detailthumb";
		var myAjax = new Ajax.Request("jsdbtrack.cfm", {method:"post", postBody:pars});
	};

	function cfRDMapquest(tnLat,tnLng,dspMap){
		propDetailMiniMap = new MQTileMap($(dspMap),9, new MQLatLng(tnLat,tnLng),"map",miniKey);
		propDetailMiniMap.setLogoPlacement(MQMapLogo.SCALES,new MQMapCornerPlacement(MQMapCorner.TOP_LEFT, new MQSize(0,5000)));
		propDetailMiniMap.enableDragging(0);


        miniPropIcon = new MQMapIcon();
		miniPropIcon.setShadow(sharedImagePath + "spacer.gif",0,0,0,0,false);
		miniPropIcon.setImage(sharedImagePath + "hb_gold.png",21,23,false,true);
		miniPropIcon.setAnchorOffset(new MQPoint(-10,-23));

		miniListingPOI = new MQPoi(new MQLatLng(tnLat,tnLng));
		miniListingPOI.setIcon(miniPropIcon);
		propDetailMiniMap.addPoi(miniListingPOI);

		dbThumbTrack();		

	};

	
			/*	===============================================================	*/
			//	Begin Custom View Type Control
			/*	===============================================================	*/
			function MTViewControl()
			{
				browser = getBrowserInfo();
				this.map = null;
				this.position=new MQMapCornerPlacement(MQMapCorner.TOP_RIGHT,new MQSize(-1,-1));
				this.elem = document.createElement("div");
				this.elem.style.position = "absolute";
				this.elem.style.overflow = "visible";
				
				temp=document.createElement("ul");
				temp.className="map-view screen";
				this.elem.appendChild(temp);

				temp1=document.createElement("li");
				temp1.className="map-view-street";
				temp.appendChild(temp1);

				this.streetview=document.createElement("img");
				this.streetview.className="";
				this.streetview.border=0;
				this.streetview.src= sharedImagePath + "viewControl/icon-btn-street-view.gif";
				this.streetview.alt="View Street Map";
				this.streetview.title="View Street Map";
				temp1.appendChild(this.streetview);
				temp1=document.createElement("li");
				temp1.className="map-view-hybrid";
				temp.appendChild(temp1);
				this.hybridview=document.createElement("img");
				this.hybridview.className="";
				this.hybridview.border=0;
				this.hybridview.src=sharedImagePath + "viewControl/icon-btn-hybrid-view.gif";
				this.hybridview.alt="View Hybrid Map";
				this.hybridview.title="View Hybrid Map";
				temp1.appendChild(this.hybridview);
				temp1=document.createElement("li");
				temp1.className="map-view-aerial";
				temp.appendChild(temp1);
				this.aerialview=document.createElement("img");
				this.aerialview.className="";
				this.aerialview.border=0;
				this.aerialview.src=sharedImagePath + "viewControl/icon-btn-aerial-view.gif";
				this.aerialview.alt="View Aerial Image";
				this.aerialview.title="View Aerial Image";
				temp1.appendChild(this.aerialview);
			};
			

			MTViewControl.prototype=new MQControl();
			MTViewControl.prototype.constructor=MTViewControl;
			MTViewControl.prototype.initialize=function(map){
				this.map=map;
				this.type=CONTROL_TYPE;
				Event.observe(this.streetview,'click',this.eventCallback("eventmonitor"));
				Event.observe(this.streetview,'mouseover',this.eventCallback("eventmonitor"));
				Event.observe(this.streetview,'mouseout',this.eventCallback("eventmonitor"));
				Event.observe(this.aerialview,'click',this.eventCallback("eventmonitor"));
				Event.observe(this.aerialview,'mouseover',this.eventCallback("eventmonitor"));
				Event.observe(this.aerialview,'mouseout',this.eventCallback("eventmonitor"));
				Event.observe(this.hybridview,'click',this.eventCallback("eventmonitor"));
				Event.observe(this.hybridview,'mouseover',this.eventCallback("eventmonitor"));
				Event.observe(this.hybridview,'mouseout',this.eventCallback("eventmonitor"));
				if(this.map.getMapType()=="map")this.streetview.addClassName("a");
				if(this.map.getMapType()=="sat")this.aerialview.addClassName("a");
				if(this.map.getMapType()=="hyb")this.hybridview.addClassName("a");
			};
			MTViewControl.prototype.eventmonitor=function(evt){
				switch(evt.type){
					case"click":
						if(Event.element(evt)==this.streetview)this.selectMode("street");
						if(Event.element(evt)==this.aerialview)this.selectMode("aerial");
						if(Event.element(evt)==this.hybridview)this.selectMode("hybrid");
					break;
					case"mouseover":Event.element(evt).addClassName("o");
					break;
					case"mouseout":Event.element(evt).removeClassName("o");
					break;
				}
			};
			MTViewControl.prototype.updateControl=function(mtype){
				switch(mtype){
					case"map":this.aerialview.removeClassName("a");
						this.hybridview.removeClassName("a");
						this.streetview.addClassName("a");
					break;
					case"sat":this.hybridview.removeClassName("a");
						this.streetview.removeClassName("a");
						this.aerialview.addClassName("a");
					break;
					case"hyb":this.aerialview.removeClassName("a");
						this.streetview.removeClassName("a");
						this.hybridview.addClassName("a");
					break;
				}
			};
			MTViewControl.prototype.selectMode=function(mode){
				var mtype=this.map.getMapType();
				var newMT="noChange";
				if(mode=="street"&&mtype!="map"){newMT="map";}
				if(mode=="aerial"&&mtype!="sat"){newMT="sat";}
				if(mode=="hybrid"&&mtype!="hyb"){newMT="hyb";}
				//if(newMT!="noChange"){this.map.setMapType(newMT);}
				if(newMT!="noChange"){this.map.setMapType(newMT);dbTrack();}
			};
			MTViewControl.prototype.getHeight = function()
			{
				return 20;
			};
			MTViewControl.prototype.getWidth = function()
			{
				return 136;
			};
			/*	===============================================================	*/
			//	End Custom View Type Control
			/*	===============================================================	*/

