var currentdestinations = [];
var destinfos = [];
var destbubbles = [];
var destbubbles2 = [];
var gatheraddresses = [];
var destboxes = [];
var cpdestinations = [];
var destarray=[];

var currentbusinesses = [];
var bizinfos = [];
var bizbubbles = [];
var bizboxes = [];
var sbusinesses = [];

var bizinfo;
var bizbubble;
var bizbox;

var resultcount=0;
var prevcount;
var querycount;

var proxsearchstring;
var searchradius = 10;
var totalresults = 500;
var activeresult;
var activeresulttype;
var destnumber;
var activetextinput;
var currentquery;
var current_results;
var current_business_name;
var loadinganimation='<div align="center" style="padding:10px;"><img src="/globalgraphics/general/LoadingProgressBar.gif" /> Loading...</div>';

var cpresultslocation;
var cpresultsheader;
var cpresultscontrols;
var bizresultslocation;
var bizresultsheader;
var biznavresultslocation;


function setsearchresultglobals(){
	cpresultslocation = document.getElementById("cplanetresults");
	cpresultsheader = document.getElementById("cpresultsheader");
	cpresultscontrols = document.getElementById("cpresultscontrols");
	bizresultslocation = document.getElementById("resultsmaster");
	bizresultsheader = document.getElementById('resultsheader');
	biznavresultslocation = document.getElementById("resultsnav");
}


function localgetdestinationcall(idtocall, orderby){	
	getdestinations(idtocall, orderby, 'self');
	
}
//**********************THE CLEANSTRING FUNCTION IS IN THE MAPFUNCTION.JS FILE - TEMP MOVED IT HERE UNTIL MAPFUNCTIONS IS INTEGRATED INTO THIS FILE.
function cleansearchstring(searchstring){
	var newstring=searchstring.replace(/,/g, '');
	newstring=newstring.replace(/'/g, '\'');
	
	//alert(newstring);
	return newstring;
}



//THE FOLLOWING 5 FUNCTIONS PROCESSES THE RESULTS FROM A CPLANET DATABASE QUERY ***************************************
function getdestinations(tourid, orderby, wherefrom){


//*****************COMMENTED OUT ALL DISPLAYRESULTS CALLS	 
	var bounds = new GLatLngBounds();
	var request = GXmlHttp.create();

	 //Resets the page.
	 
//*****************COMMENTED OUT MAP DISPLAY FUNCTIONS
	 //expandmappane();
	 
	 //SETS LOADING IMAGE
	 //cpresultslocation.innerHTML = loadinganimation;

	 currentdestinations = [];
	 var destresults_html = '';
	 var d = new Date();
	 var currentitme = d.getTime();
	 var publiconly;
	 var issearch='true';
	 
	 
//*****************CHANGED THIS TO REPRESENT THE DESTINATIONWINDOW FIELD NAME	 
	 var whatuserspage = document.getElementById("HiddenFieldDestUserName").value;
	 
	 if(whatuserspage==currentuser){
		publiconly = 0;
	 }else{
		publiconly = 1;
	 }
 
 //THE FOLLOWING SWITCH CREATES THE CORRECT DATAFILE VARIABLE DEPENDING ON THE LOCATION OF THE CALL AND THE TYPE
	
	 switch (wherefrom){
		
		case 'search':
			clearmap();
			var datafile = 'controls/Destinationsearch.aspx?tourid='+tourid+'&orderby='+orderby+'&time='+currentitme+'&ispublic='+publiconly+'&issearch='+issearch;
		break;
		
		case 'iframe':
			clearmap();
			var datafile = 'Destinationsearch.aspx?tourid='+tourid+'&orderby='+orderby+'&time='+currentitme+'&ispublic='+publiconly;
		break;
		
		case 'prox_storefronts':
			var datafile = 'controls/areasearchxml.aspx?lat='+currentlocation[0].lat+'&lng='+currentlocation[0].lng+'&distance='+globalproxdistance+'&type=3';
			//THE FOLLOWING STATEMENT ADD THE CURRENT DESTINATION FLAG TO THE BOUNDS OF THE MAP
			var flagpoint = new GLatLng(currentlocation[0].lat,currentlocation[0].lng);
		 	bounds.extend(flagpoint);
		break;
		
		case 'hubtour':
//****************TURNED OFF CLEAR MAP CALL
			//clearmap();
			var datafile = 'controls/Destinationsearch.aspx?tourid='+tourid+'&orderby='+orderby+'&time='+currentitme+'&ispublic='+publiconly;
		break;
		
		default:
			clearmap();
			var datafile = 'controls/Destinationsearch.aspx?tourid='+tourid+'&orderby='+orderby+'&time='+currentitme+'&ispublic='+publiconly;
		break;
		
	 }
 
	//alert(datafile);
		 
		 i=0;
	 	 destresults_html = '<div style="width:90%; height:auto;">';
	 	
     	 request.open("GET", datafile, true);
     	  
     	 request.onreadystatechange = function() {
        	if (request.readyState == 4) {
			   if(request.status == 200){
        	
         		var xmlDoc = '';
         		 
         		xmlDoc = GXml.parse(request.responseText);
				//alert(xmlDoc);
         		 // obtain the array of markers and loop through it
         		 var destinations = xmlDoc.documentElement.getElementsByTagName("destination");
				 destnumber = destinations.length;
				 
          		 if(destnumber>totalresults){
					 destnumber = totalresults;
				 }
				 
				 if(destnumber>0){
          		
					for (var i = 0; i < destnumber; i++) {
						 // obtain the attribues of each marker
//							
							var tourid = GXml.value(destinations[i].getElementsByTagName("TourID")[0]);
							var tourname = GXml.value(destinations[i].getElementsByTagName("TourName")[0]);
							var tourowner = GXml.value(destinations[i].getElementsByTagName("TourOwner")[0]);
							var tourdescription = GXml.value(destinations[i].getElementsByTagName("TourDescription")[0]);
							var destinationid = GXml.value(destinations[i].getElementsByTagName("DestinationID")[0]);
							var associated = GXml.value(destinations[i].getElementsByTagName("Associated")[0]);
							var associatedid = parseFloat(GXml.value(destinations[i].getElementsByTagName("AssociatedID")[0]));
							var dname = GXml.value(destinations[i].getElementsByTagName("DestinationName")[0]);
							var description = GXml.value(destinations[i].getElementsByTagName("DestinationDescription")[0]);
							var tags = GXml.value(destinations[i].getElementsByTagName("Tags")[0]);
							var public = GXml.value(destinations[i].getElementsByTagName("isPublic")[0]);
							var address1 = GXml.value(destinations[i].getElementsByTagName("Address1")[0]);
							var address2 = GXml.value(destinations[i].getElementsByTagName("Address2")[0]);
							var city = GXml.value(destinations[i].getElementsByTagName("City")[0]);
							var state = GXml.value(destinations[i].getElementsByTagName("State")[0]);
							var zip = GXml.value(destinations[i].getElementsByTagName("Zip")[0]);
							var country = GXml.value(destinations[i].getElementsByTagName("Country")[0]);
							var phone = GXml.value(destinations[i].getElementsByTagName("Phone")[0]);
							var fax = GXml.value(destinations[i].getElementsByTagName("Fax")[0]);
							var website = GXml.value(destinations[i].getElementsByTagName("Website")[0]);
							var email = GXml.value(destinations[i].getElementsByTagName("Email")[0]);
							var datecreated = GXml.value(destinations[i].getElementsByTagName("DateCreated")[0]);
							var destinationdate = GXml.value(destinations[i].getElementsByTagName("DestinationDate")[0]);
							var datemodified = GXml.value(destinations[i].getElementsByTagName("DateModified")[0]);
							var glat = parseFloat(GXml.value(destinations[i].getElementsByTagName("Latitude")[0]));
							var glng = parseFloat(GXml.value(destinations[i].getElementsByTagName("Longitude")[0]));
							var point = new GLatLng(glat,glng);
							var gzoom = parseFloat(GXml.value(destinations[i].getElementsByTagName("Zoom")[0]));
							var gmaptype = GXml.value(destinations[i].getElementsByTagName("MapType")[0]);
							var markericon = GXml.value(destinations[i].getElementsByTagName("Marker")[0]);
							var user = GXml.value(destinations[i].getElementsByTagName("User")[0]);
							var hasmedia = GXml.value(destinations[i].getElementsByTagName("HasMedia")[0]);
							var desttype = GXml.value(destinations[i].getElementsByTagName("Type")[0]);
							var ip = GXml.value(destinations[i].getElementsByTagName("Ip")[0]);
							var coupon = GXml.value(destinations[i].getElementsByTagName("Coupon")[0]);
							
							//alert(coupon);
							
							currentdestinations[i]= new popdestinations(tourid, tourname, tourowner, tourdescription, destinationid, associated, associatedid, dname, description, tags, public, address1, address2, city, state, zip, country, phone, fax, website, email, datecreated, destinationdate, datemodified, point, glat, glng, gzoom, gmaptype, markericon, user, hasmedia, desttype, ip, coupon);
							
						if ((glat)&&(glng)){
							var destination = createdestination(i);
							map.addOverlay(destination);
							var usernameraw=currentdestinations[i].user;
							var username=usernameraw.toLowerCase();
							if(username==currentuser){
								destination.enableDragging();
							}
							if (currentdestinations[i].marker){
								//alert(markericons[i]);
								var markerpath  = "/globalgraphics/markers/";
								var dmarker = markerpath+currentdestinations[i].marker;
								destination.setImage(dmarker);
							}else{
								destination.setImage(markerstandard);
							}
							
							if(wherefrom == 'sethub'){
								var dmarker = markerpath+'location_marker.png';
								destination.setImage(dmarker);
							}
						
							destresults_html+=destinfos[i];
							bounds.extend(point);
						}else{
							destresults_html += '<strong>'+dname+'</strong><font size=1>(has no location)</font><br><br>';
						}
						
					}
					
					destresults_html += '</div>';
					 
					
					if(wherefrom!='prox_storefronts'){
						 // ===== determine the zoom level from the bounds =====
						 if(map.getBoundsZoomLevel(bounds)>17){
							 var newzoom=17;
						 }else{
							 var newzoom=map.getBoundsZoomLevel(bounds);
						 }
						 map.setZoom(newzoom);
		
						// ===== determine the centre from the bounds ======
						var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
						var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
						map.setCenter(new GLatLng(clat,clng));
					}
					
					activetourid=tourid;
					activetourname=tourname;
					
				  }else{
					
						results_html='No Cplanet destinations found.</div>';
						
				  }
					
			   	}else{
					results_html='Unformated data file.</div>';
					
				}
				
				displayresults(i, wherefrom, destresults_html);
         	}
			
     	}
		
		
		
		request.send(null);
		
		
}


function popdestinations(tourid, tourname, tourowner, tourdescription, destinationid, associated, associatedid, name, description, desttags, public, address1, address2, city, state, zip, country, phone, fax, weblink, email, datecreated, datemanual, datemodified, point, lat, lng, zoom, maptype, marker, user, hasmedia, desttype, ip, coupon){
	
	this.tourid=tourid;
	this.tourname=tourname;
	this.tourowner=tourowner;
	this.tourdescription=tourdescription;
	this.destinationid=destinationid;
	this.associated=associated;
	this.associatedid=associatedid;
	this.name=name;
	this.description=description;
	this.desttags=desttags;
	this.public=public;
	this.address1=address1;
	this.address2=address2;
	this.city=city;
	this.state=state;
	this.zip=zip;
	this.country=country;
	this.phone=phone;
	this.fax=fax;
	this.weblink=weblink;
	this.email=email;
	this.datecreated=datecreated;
	this.datemanual=datemanual;
	this.datemodified=datemodified;
	this.point = point;
	this.lat = lat;
	this.lng = lng;
	this.zoom= zoom;
	this.maptype=maptype;
	this.marker=marker;
	this.user=user;
	this.hasmedia=hasmedia;
	this.desttype=desttype;
	this.ip=ip;
	this.coupon=coupon;
	
}

//THIS FUNCTION POPULATES THE MAP WITH MARKERS FROM AN INTERNET SEARCH DONE FROM THE PRESENTATION PAGE.
function createdestination(i) {
	
		var markonmap = true;
		var htmltab2="";
		var label1='Info';
		var label2='Details';
		var label3='Search area';
		
	    var point = new GLatLng(currentdestinations[i].lat,currentdestinations[i].lng);
        var cpdestination = new GMarker(point, {icon:dynamicmarker, draggable: true});
		
		var gatheraddress=builddesthtmltab1(i, markonmap);
		var desttab2 = builddesthtmltab2(i);
		
		var cleanaddress=cleansearchstring(gatheraddress);
		
		var locsearchlayout='<div id="business_search" style="padding-left:5px; padding-top:1px" runat="server">'
		+'<span style="font-weight:bold;">Search for something close by:</span><br />'
		+'<span class="minifont">Business Name or Business Catagory</span><br />'
		+'<input type="text" id="txtBusinessSearchBubble" name="textfield" size="25" onfocus="setenterkey(\'txtBusinessSearchBubble\')" /><br />'
		+'<span class="minifont">City, State, Zip</span><br />'
		+'<input type="text" id="txtBusinessSearchLocationBubble" name="textfield" size="25" value="'+cleanaddress+'"/><br />'
		+'<input id="btnBusinessSearchBubble" type="button" value="Search" onclick="showLocation(\'business\', \'bubble\')" />'
		+'<div style="padding-top:3px; margin-top:3px; border-top:solid 1px #666666;"><a href="javascript:connecttoone(\''+i+'\')">Connect to this</a>  |  <a href="javascript:connectall()">Connect all</a></div></div>';
		
        // save the info we need to use later for the side_bar
        cpdestinations[i] = cpdestination;
        destinfos[i] = destinfo;
		destbubbles[i] = destbubble;
		destbubbles2[i] = desttab2;
		gatheraddresses[i] = cleanaddress;
		destboxes[i] = destbox;
		        
		 GEvent.addListener(cpdestination, "click", function() {
			activeresult=i;
			activeresulttype = 'cplanet';
			activemarker=cpdestination;
			//createtype='business';
			//setmastercreatetype(createtype);
			//genericinfobox(biz);
			cpdestination.openInfoWindowTabsHtml([new GInfoWindowTab(label1,destbubbles[i]), new GInfoWindowTab(label2,desttab2), new GInfoWindowTab(label3,locsearchlayout)]);
        });

        return cpdestination;
		
}


function showdestination(i) {
	
		var label1='Info';
		var label2='Details';
		var label3='Search area';
		var point = new GLatLng(currentdestinations[i].lat,currentdestinations[i].lng);
		
		var locsearchlayout='<div id="business_search" style="padding-left:5px; padding-top:1px" runat="server">'
		+'<span style="font-weight:bold;">Search for something close by:</span><br />'
		+'<span class="minifont">Business Name or Business Catagory</span><br />'
		+'<input type="text" id="txtBusinessSearchBubble" name="textfield" size="25" onfocus="setenterkey(\'txtBusinessSearchBubble\')" /><br />'
		+'<span class="minifont">City, State, Zip</span><br />'
		+'<input type="text" id="txtBusinessSearchLocationBubble" name="textfield" size="25" value="'+gatheraddresses[i]+'"/><br />'
		+'<input id="btnBusinessSearchBubble" type="button" value="Search" onclick="showLocation(\'business\', \'bubble\')" />'
		+'<div style="padding-top:3px; margin-top:3px; border-top:solid 1px #666666;"><a href="javascript:connecttoone(\''+i+'\')">Connect to this</a>  |  <a href="javascript:connectall()">Connect all</a></div></div>';
		
		//Resets the page.
		expandmappane();
		//setlayout('mapfullbottom');
		//swapcontent('localinfo');
		
		activemarker=cpdestinations[i];
		activeresult=i;
		activeresulttype = 'cplanet';
		//genericinfobox(biz);
		configmap(point, currentdestinations[i].zoom, currentdestinations[i].maptype);
		//map.setCenter(point, currentdestinations[i].zoom);
		cpdestinations[i].openInfoWindowTabsHtml([new GInfoWindowTab(label1,destbubbles[i]), new GInfoWindowTab(label2,destbubbles2[i]), new GInfoWindowTab(label3,locsearchlayout)]);
}


//THIS FUNCTIONS TAKES THE VARIABLES OF EACH SEARCH RESULTS AND FORMATS THE HTML THAT IS DISPLAYED IN THE BUBBLES AND RESULTS DIVS
function builddesthtmltab1(i, markonmap){
	var gatheraddress='';
	destinfo='';
	destbubble='<div style="width:275px;">';
	destbox='';
	
	
	if (currentdestinations[i].name!=""){
		destinfo+='<b><a href="javascript:showdestination(' + i + ')">' + currentdestinations[i].name + '</a></b>';
		destbubble+='<strong>'+currentdestinations[i].name+'</strong>';
		destbox+=currentdestinations[i].name;
	}
	
	if (currentdestinations[i].address1!=""){
		destinfo+='<br>'+currentdestinations[i].address1;
		destbubble+='<br>'+currentdestinations[i].address1;
		destbox+='\n'+currentdestinations[i].address1;
		gatheraddress+=currentdestinations[i].address1;
	}
	if (currentdestinations[i].address2!=""){
		destinfo+='<br>'+currentdestinations[i].address2;
		destbubble+='<br>'+currentdestinations[i].address2;
		destbox+='\n'+currentdestinations[i].address2;
	};
	if (currentdestinations[i].city!=""){
		destinfo+='<br>'+currentdestinations[i].city;
		destbubble+='<br>'+currentdestinations[i].city;
		destbox+='\n'+currentdestinations[i].city;
		gatheraddress+=' '+currentdestinations[i].city;
	}
	if (currentdestinations[i].state!=""){
		destinfo+=', '+currentdestinations[i].state;
		destbubble+=', '+currentdestinations[i].state;
		destbox+=', '+currentdestinations[i].state;
		gatheraddress+=' '+currentdestinations[i].state;
	}
	if (currentdestinations[i].zip!=""){
		destinfo+=', '+currentdestinations[i].zip;
		destbubble+=', '+currentdestinations[i].zip;
		destbox+=', '+currentdestinations[i].zip;
	}
	if (currentdestinations[i].country!=""){
		destinfo+=', '+currentdestinations[i].country;
		destbubble+=', '+currentdestinations[i].country;
		destbox+=', '+currentdestinations[i].country;
	}
	if (currentdestinations[i].phone!=""){
		destinfo+='<br>'+currentdestinations[i].phone;
		destbubble+='<br>'+currentdestinations[i].phone;
		destbox+='\n'+currentdestinations[i].phone;
	}
	
	if (currentdestinations[i].description!=""){
		var trucdescript=currentdestinations[i].description.slice(0,26 )+'...';
		destinfo+='<br>'+trucdescript;
		destbox+='\n'+trucdescript;
	}
	
	if (currentdestinations[i].weblink!=""){
		if (currentdestinations[i].weblink.search("http://") == -1) {
			destinfo+='<br><a href="javascript:framewebsite(\'http://'+currentdestinations[i].weblink+'\')"><span class="minifont">Website</span></a>';
			destbubble+='<br><a href="javascript:framewebsite(\'http://'+currentdestinations[i].weblink+'\')">Website</a>';
			destbox+='\nhttp://'+currentdestinations[i].weblink;
		}else{
			destinfo+='<br><a href="javascript:framewebsite(\''+currentdestinations[i].weblink+'\')"><span class="minifont">Website</span></a>';
			destbubble+='<br><a href="javascript:framewebsite(\''+currentdestinations[i].weblink+'\')">Website</a>';
			destbox+='\n'+currentdestinations[i].weblink;
		}
	}
	
	if (currentdestinations[i].coupon!=""){
		//var printtrigger = 'alt="<a href=\"javascript:printimage(\''+currentdestinations[i].coupon+'\')\">Click here to print</a>"';
		
		var sendtoprintpath = cleanstring(currentdestinations[i].coupon);
		
		destinfo+='<br><table width="100%" cellspacing="0" cellpadding="0" border="0"><tr>'+
			'<td align="center"><a href="'+currentdestinations[i].coupon+'" class="highslide" onclick="return hs.expand(this)">'+
			'<img src="/globalgraphics/general/coupon.gif" title="Click here to open coupon" border="0" /></a>'+
			'<div class="highslide-caption"><a href="javascript:printimage(\''+sendtoprintpath+'\')"><span class="cpfontheading">Click here to print</span></a></div></td>'+
			'<td align="center"><div class="cpfontbold" align="center"><span style="font-size:9px; font-weight:normal;">sponsored by:</span><br/>'+currentdestinations[i].user+'</div></td></tr></table>';
			
		destbubble+='<br><table width="100%" cellspacing="0" cellpadding="0" border="0"><tr>'+
			'<td align="center"><a href="'+currentdestinations[i].coupon+'" class="highslide" onclick="return hs.expand(this)">'+
			'<img src="/globalgraphics/general/coupon.gif" title="Click here to open coupon" border="0" /></a>'+
			'<div class="highslide-caption"><a href="javascript:printimage(\''+sendtoprintpath+'\')"><span class="cpfontheading">Click here to print</span></a></div></td>'+
			'<td align="center"><div class="cpfontbold" align="center"><span style="font-size:9px; font-weight:normal;">sponsored by:</span><br/>'+currentdestinations[i].user+'</div></td></tr></table>';
			
		//destinfo+='<br><table width="100%" ><tr><td align="right"><a href="javascript:opencoupon(\''+currentdestinations[i].coupon+'\')"><img src="/globalgraphics/general/coupon.gif" alt="Click to Open Coupon." onmouseover="this.style.cursor=\'pointer\'" border="0" /></a></td></tr></table>';
		//destbubble+='<br><table width="100%" ><tr><td align="left"><a href="javascript:opencoupon(\''+currentdestinations[i].coupon+'\')"><img src="/globalgraphics/general/coupon.gif" alt="Click to Open Coupon." onmouseover="this.style.cursor=\'pointer\'" border="0" /></a></td></tr></table>';
	}
	
	destinfo+='<table width="100%" cellspacing="0" cellpadding="0"><tr>';
	destbubble+='<table width="100%" cellspacing="0" cellpadding="0"><tr>';
	
//	if (currentdestinations[i].weblink!=""){
//		destinfo+='<br><a href="'+currentdestinations[i].weblink+'" onclick="return hs.htmlExpand(this, { objectType: \'iframe\', contentId:\'iframecontent\', preserveContent: false } )"><span class="minifont">Website</span></a>';
//		destinfo+='<td><a href="javascript:framewebsite(\''+currentdestinations[i].weblink+'\')"><span class="minifont">Website</span></a></td>';
//		destbubble+='<br><a href="'+currentdestinations[i].weblink+'" onclick="return hs.htmlExpand(this, { objectType: \'iframe\', contentId:\'iframecontent\', preserveContent: false } )">Website</a>';
//		destbubble+='<td><a href="javascript:framewebsite(\''+currentdestinations[i].weblink+'\')">Website</a></td><td width="25%"></td>';
//		destbox+='\n'+currentdestinations[i].weblink;
//	}

	var usernameraw=currentdestinations[i].user;
	var username=usernameraw.toLowerCase();
	//alert('Raw='+usernameraw+', Lowercase='+username);
	if(username==currentuser){
		destinfo+='<td bgcolor="#CCCCCC" style="border:solid 1px #666666;" align="left"><a href="javascript:addeditmedia(\''+currentdestinations[i].destinationid+'\')"><span class="minifont">Add/Edit Media</span></a></td>';
	}
	
	
	if (currentdestinations[i].hasmedia=='True'){
		var cleandestname=cleanstring(currentdestinations[i].name);
		
		destinfo+='<td align="right" ><a href="javascript:framewebsite(\'/destwindow.aspx?destid='+currentdestinations[i].destinationid+'\')"><span class="minifont"><img src="/globalgraphics/general/ctherebutton_small.gif" alt="Cthere - open a window to this destination." onmouseover="this.style.cursor=\'pointer\'" border="0" /></span></a></td>';
		//destbubble+='<br><a href="'+currentdestinations[i].weblink+'" onclick="return hs.htmlExpand(this, { objectType: \'iframe\', contentId:\'iframecontent\', preserveContent: false } )">Website</a>';
		destbubble+='<td align="center"><a href="javascript:framewebsite(\'/destwindow.aspx?destid='+currentdestinations[i].destinationid+'\')"><img src="/globalgraphics/general/ctherebutton.gif" alt="Cthere - open a window to this destination." onmouseover="this.style.cursor=\'pointer\'" border="0" /></a></td>';
		//destbox+='\n'+currentdestinations[i].weblink;
	}
	
	destinfo+='</tr></table>';
	destbubble+='</tr></table>';
	
	var cleanaddress=cleansearchstring(gatheraddress);
	
	//destinfo+='<br>';
	if(markonmap==true){
		destbubble+='<span class="textlinks"><table width="275px" border="0" cellpadding="3"><tr>';
		
		if ((currentdestinations[i].city!="")&&(currentdestinations[i].state!="")){
			destbubble+='<td><div align="left" ><a href="javascript:callgeocode(\''+cleanaddress+'\')">Search &amp; Explore</a>     |</div></td>';
		}else{
			destbubble+='<td><div align="left" >Search &amp; Explore     |</div></td>';
		}
		
		if(username!=currentuser){
			if(currentdestinations[i].associated==1){
				destbubble+='<td><div align="right"><a href="javascript:unassociatecpdestination()">Remove</a></div></td></tr>';
			}else{
				destbubble+='<td><div align="right"><a href="javascript:savecplanetdestination()">Add to My Stuff</a></div></td></tr>';
			}
		}else{
			destbubble+='<td><div align="right"><a href="javascript:saveactivemarker(\'edit\')">Edit</a></div></td></tr>';
		}
		
		
		destbubble+='<tr><td><div align="left"><a href="javascript:buildshare(\'dest\')">Share destination</a>     |</div></td>';
		destbubble+='<td><div align="right"><a href="javascript:prepforsend(\''+i+'\', \'cpdest\')">Send to me</a></div></td>';
		destbubble+='</tr></table></span>';
	}
	
	destinfo+='<hr>';
	destbubble+='</div>';
	
	return gatheraddress;
}


function builddesthtmltab2(i){
	
	var desttab2='<div style="width:275px;">';
	
	var directioinpoint=currentdestinations[i].lat+','+currentdestinations[i].lng;
	var name = cleanstring(currentdestinations[i].name);
	var directionstab ='<div class="bubble1" id="bubble"><span class="titlefont">Directions:<a href="javascript:setdirectionbubble(\'to\', \''+directioinpoint+'\', \''+name+'\' )">To Here  </a>- or -<a href="javascript:setdirectionbubble(\'from\', \''+directioinpoint+'\', \''+name+'\')">  From Here</a></span></div><hr>';
	
	desttab2+=directionstab;
	desttab2+='<div style="width:100%; height:120px; overflow:auto;">'
	
	if (currentdestinations[i].name!=""){
		desttab2+='<br><b>Name: </b>'+currentdestinations[i].name;
	}
	
	if (currentdestinations[i].description!=""){
		desttab2+='<br><b>Description: </b>'+currentdestinations[i].description;
	}
	
	if (currentdestinations[i].datemanual!=""){
		desttab2+='<br><b>Date: </b>'+currentdestinations[i].datemanual;
	}
	
	if (currentdestinations[i].email!=""){
		desttab2+='<br><a href="mailto:'+currentdestinations[i].email+'">Contact Email</a>';
	}
	
	if (currentdestinations[i].datecreated!=""){
		desttab2+='<hr><span class="minifont">Date Created: '+currentdestinations[i].datecreated+'</span>';
	}
	
	if (currentdestinations[i].datemodified!=""){
		desttab2+='<br><span class="minifont">Last Modified: '+currentdestinations[i].datemodified+'</span>';
	}
	
	if (currentdestinations[i].user!=""){
		desttab2+='<br><span class="minifont">Created by: '+currentdestinations[i].user+'</span>';
	}
	
	if (currentdestinations[i].desttype!=""){
		desttab2+='<br><span class="minifont">Destination Type: '+currentdestinations[i].desttype+'</span>';
	}
	
	if (currentdestinations[i].destinationid!=""){
		desttab2+='<br><span class="minifont">Destination Type: '+currentdestinations[i].destinationid+'</span>';
	}
	
	desttab2+='</div></div>';
	
	return desttab2;
	
}


function searchyahoo(searchtype, nav, whatsearch, biz){
	
	switch (searchtype){
			case 'venue':
				if (nav == 'next'){
				   clearmap();
				   querycount=querycount+1;
				}
			
				if (nav == 'initial'){
					resultcount = 0;
					querycount=1;
					clearmap();
				}
				
				if (nav == 'prev'){
					if(resultcount>40){
						resultcount = Number(resultcount) - 40;
					}else{
						resultcount = 0;
					}
					querycount=querycount-1;
					clearmap();
				}
				
				var searchstring_yahoo = 'controls/localsearch.aspx?bus='+currentquery+'&add='+mod_searchstring+'&cat='+currentvenue+'&rad='+searchradius+'&start='+resultcount;
				getbizsearch(searchstring_yahoo, searchtype, true);
			break;
		
			case 'prox':
				var business='*';
				var radius='0.5';
				var venueid='*';
				markerimage = markerstandard;
				
				if (nav == 'next')
				{	
					resultcount = Number(resultcount) + 20;
					querycount=querycount+1;
					clearmap();
					var searchstring_yahoo = proxsearchstring+resultcount;
					//restorelocation();
				}
				
				if (nav == 'initial')
				{
					resultcount = 0;
					querycount=1;
					
					if (activeresulttype == 'yahoo'){
						bizlocation=currentbusinesses[biz].address1+' '+currentbusinesses[biz].city+' '+currentbusinesses[biz].state;
						if(nav=='initial'){
							proxlocation=bizlocation;
							proxlocation_name=currentbusinesses[biz].name;
							proxlocation_lat=currentbusinesses[biz].lat;
							proxlocation_lng=currentbusinesses[biz].lng;
						}
					}
					if (activeresulttype == 'cplanet'){
						bizlocation=currentdestinations[biz].address1+' '+currentdestinations[biz].city+' '+currentdestinations[biz].state;
						if(nav=='initial'){
							proxlocation=bizlocation;
							proxlocation_name=currentdestinations[biz].name;
							proxlocation_lat=currentdestinations[biz].lat;
							proxlocation_lng=currentdestinations[biz].lng;
						}
					}
					
					var searchstring_yahoo = 'controls/localsearch.aspx?bus='+business+'&add='+bizlocation+'&cat='+venueid+'&rad='+radius+'&start='+resultcount;
					proxsearchstring = 'controls/localsearch.aspx?bus='+business+'&add='+bizlocation+'&cat='+venueid+'&rad='+radius+'&start=';
					
				}
				
				if (nav == 'prev')
				{
					if(resultcount>40){
						resultcount = Number(resultcount) - 40;
					}else{
						resultcount = 0;
					}
					querycount=querycount-1;
					clearmap();
					var searchstring_yahoo = proxsearchstring+resultcount;
					//restorelocation();
				}

				getbizsearch(searchstring_yahoo, searchtype, true);

		break;
		
			case 'search':
				
				if (whatsearch == 'sponsor'){
					currentbizsearchterm = sponsorsearchterm;
					markerimage =  markerpath+sponsormarker;
				}else{
					markerimage = markerstandard;
					//globallocation=mod_searchstring;
				}
				
				if (nav == 'next')
				{
					resultcount = Number(resultcount) + 20;
					querycount=querycount+1;
					clearmap();
					//restorelocation();
				}
				
				if (nav == 'initial')
				{
					resultcount = 0;
					querycount=1;
					clearmap();
				}
				
				if (nav == 'prev')
				{
					if(resultcount>40){
						resultcount = Number(resultcount) - 40;
					}else{
						resultcount = 0;
					}
					querycount=querycount-1;
					clearmap();
					//restorelocation();
				}
				
				//alert('currentsearchterm: '+currentbizsearchterm+'\nGlobalLocation: '+globallocation);
				var searchstring_yahoo = 'controls/localsearch.aspx?bus='+currentbizsearchterm+'&add='+globallocation+'&cat=*&rad=10&start='+resultcount;
				
				//alert(searchstring_yahoo);
			
				switch (whatsearch){
					case 'create':
						getbizsearch(searchstring_yahoo, searchtype, false);
					break;
					
					case 'storefront':
						buildstorefrontlist(searchstring_yahoo, searchtype, false);
					break;
					
					case 'sponsor':
						getbizsearch(searchstring_yahoo, 'sponsor', true);
					break;
					
					default:
						getbizsearch(searchstring_yahoo, searchtype, true);
					break;	
				}
			break;
		}
		
}




function resultsnav(searchtype, markonmap, resultstatus){
	
	//alert(resultcount);
	if(((resultcount-prevcount)<20)&&(querycount>1)){
		resultstatus='done';	
	}
	
	if(searchtype=='venue'){
		var navfunction_next = 'javascript:searchyahoo(\'venue\', \'next\')';
		var navfunction_prev = 'javascript:searchyahoo(\'venue\', \'prev\')';
	}
	
	if(searchtype=='prox'){
	   var navfunction_next = 'javascript:searchyahoo(\'prox\', \'next\')';
	   var navfunction_prev = 'javascript:searchyahoo(\'prox\', \'prev\')';
	}
	
	if(searchtype=='search'){
	   var navfunction_next = 'javascript:searchyahoo(\'search\', \'next\')';
	   var navfunction_prev = 'javascript:searchyahoo(\'search\', \'prev\')';
	}
	
	if(searchtype=='sponsor'){
	   var navfunction_next = 'javascript:searchyahoo(\'search\', \'next\', \'sponsor\')';
	   var navfunction_prev = 'javascript:searchyahoo(\'search\', \'prev\', \'sponsor\')';
	}
	
	//alert(resultcount);
	if ((resultcount<20)&&(resultstatus!='done')){
		
		var navstring = '<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
					  '<tr><td width="30%"><div id="resultsnext" align="left"></div></td>'+
					  '<td width="30%" valign="middle"></td>'+
					  '<td width="30%"><div id="resultsnext" align="right"></div></td>'+
					  '</tr></table>';
		
		if(destnumber<5){
			var navstring = '';
			//alert('destnumber is less than 5');
		}
	}
	
	if ((resultcount==20)&&(resultstatus!='done')){
		var navstring = '<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
					  '<tr><td width="30%"><div id="resultsnext" align="left"></div></td>'+
					  '<td width="30%" valign="middle"></td>'+
					  '<td width="30%"><div id="resultsnext" align="right"><a href="'+navfunction_next+'"><img src="/globalgraphics/general/next.gif" alt="Next 20 destinations." width="50" height="20" border="0" /></a></div></td>'+
					  '</tr></table>';
					  
	}
	
	if ((resultcount>20)&&(resultstatus!='done')){
		var navstring = '<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
					  '<tr><td width="30%"><div id="resultsnext" align="left"><a href="'+navfunction_prev+'"><img src="/globalgraphics/general/previous.gif" alt="Previous 20 destinations." width="50" height="20" border="0" /></a></div></td>'+
					  '<td width="30%" valign="middle"></td>'+
					  '<td width="30%"><div id="resultsnext" align="right"><a href="'+navfunction_next+'"><img src="/globalgraphics/general/next.gif" alt="Next 20 destinations." width="50" height="20" border="0" /></a></div></td>'+
					  '</tr></table>';
					  
	}
	
	if (resultstatus=='done'){
		var navstring = '<table width="100%" border="0" cellspacing="0" cellpadding="0">'+
					  '<tr><td width="30%"><div id="resultsnext" align="left"><a href="'+navfunction_prev+'"><img src="/globalgraphics/general/previous.gif" alt="Previous 20 destinations." width="50" height="20" border="0" /></a></div></td>'+
					  '<td width="30%" valign="middle"></td>'+
					  '<td width="30%"><div id="resultsnext" align="right"></div></td>'+
					  '</tr></table>';
					  
	}
	
	if (markonmap==true){
		biznavresultslocation.innerHTML = navstring;
	}
	
}

//THE FOLLOWING 4 FUNCTIONS PROCESSES THE RESULTS FROM A YAHOO LOCAL SEARCH QUERY ***************************************
function getbizsearch(datafile, searchtype, markonmap){
	
	//alert(querycount);
	bizresults_html='<div style="width:90%; height:auto;">';
	
	bizresultslocation.innerHTML = loadinganimation;
	
	   var bounds = new GLatLngBounds();
     	 var request = GXmlHttp.create();
     	 request.open("GET", datafile, true);
     	 request.onreadystatechange = function() {
        	if (request.readyState == 4) {
				 if(request.status == 200){
					var xmlDoc = GXml.parse(request.responseText);
         		 // obtain the array of markers and loop through it
         			var bs_results = xmlDoc.documentElement.getElementsByTagName("destination");
					
					prevcount=resultcount;
					resultcount=(Number(resultcount)+(bs_results.length));
					resultsnav(searchtype, markonmap);
					
					for (var x = 0; x < bs_results.length; x++) {
						 // obtain the attribues of each marker
						 	
							var bs_tourid = GXml.value(bs_results[x].getElementsByTagName("TourID")[0]);
							var bs_destinationid = GXml.value(bs_results[x].getElementsByTagName("DestinationID")[0]);
							var bs_dname = GXml.value(bs_results[x].getElementsByTagName("DestinationName")[0]);
							var bs_description = GXml.value(bs_results[x].getElementsByTagName("DestinationDescription")[0]);
							var bs_glat = parseFloat(GXml.value(bs_results[x].getElementsByTagName("Latitude")[0]));
							var bs_glng = parseFloat(GXml.value(bs_results[x].getElementsByTagName("Longitude")[0]));
							var bs_point = new GLatLng(bs_glat,bs_glng);
							var bs_gzoom = parseFloat(GXml.value(bs_results[x].getElementsByTagName("zoom")[0]));
							var bs_venue = GXml.value(bs_results[x].getElementsByTagName("Venue")[0]);
							var bs_date = GXml.value(bs_results[x].getElementsByTagName("TheDate")[0]);
							var bs_website = GXml.value(bs_results[x].getElementsByTagName("Website")[0]);
							var bs_logo = GXml.value(bs_results[x].getElementsByTagName("Logo")[0]);
							var bs_address = GXml.value(bs_results[x].getElementsByTagName("Address1")[0]);
							var bs_address2 = GXml.value(bs_results[x].getElementsByTagName("Address2")[0]);
							var bs_city = GXml.value(bs_results[x].getElementsByTagName("City")[0]);
							var bs_state = GXml.value(bs_results[x].getElementsByTagName("State")[0]);
							var bs_zip = GXml.value(bs_results[x].getElementsByTagName("Zip")[0]);
							var bs_region = GXml.value(bs_results[x].getElementsByTagName("Region")[0]);
							var bs_country = GXml.value(bs_results[x].getElementsByTagName("Country")[0]);
							var bs_phone = GXml.value(bs_results[x].getElementsByTagName("Phone")[0]);
							
							currentbusinesses[x]= new popbusinesses(bs_dname, bs_description, bs_address, bs_address2, bs_city, bs_state, bs_zip, bs_country, bs_phone, bs_website, bs_glat, bs_glng, bs_gzoom);
							
							if (markonmap==true){
								var sbusiness = markbizsearch(x);
								map.addOverlay(sbusiness);
								sbusiness.setImage(markerimage);
								bounds.extend(bs_point);
								bizresults_html+=bizinfos[x];
							}else{
								bizresults_html += '<a href="javascript:markbizresult(' + x + ')"><b>' + bs_dname + '</b></a><br>' + bs_address + '<br>' + bs_city + ', ' + bs_state + ', ' + bs_country + '<br>' + bs_phone + '<hr>';
							}
							
												
					}
					
					bizresults_html += '</div>';
					
				}else{
					
					bizresults_html='No destinations found.';

					if(querycount>1){
						resultsnav(searchtype, markonmap, 'done');
					}
					
				}
				
				if (markonmap==true){
					if(x>0){
						if(x>2){
							map.setZoom(map.getBoundsZoomLevel(bounds));
		
							// ===== determine the centre from the bounds ======
							var clat = (bounds.getNorthEast().lat() + bounds.getSouthWest().lat()) /2;
							var clng = (bounds.getNorthEast().lng() + bounds.getSouthWest().lng()) /2;
							map.setCenter(new GLatLng(clat,clng));
						}
					}
					current_results=bizresults_html;
					displayresults('bizsearch', bizresults_html);
				}else{
					displayresults('bizsearch', bizresults_html);
				}
				locationbubble(true);
       	    }
			
     	}
      	request.send(null);

}


function popbusinesses(name, description, address1, address2, city, state, zip, country, phone, weblink, lat, lng, zoom){
	
	this.name=name;
	this.description=description;
	this.address1=address1;
	this.address2=address2;
	this.city=city;
	this.state=state;
	this.zip=zip;
	this.country=country;
	this.phone=phone;
	this.weblink=weblink;
	this.lat = lat;
	this.lng = lng;
	this.zoom= zoom;
	
}


//THIS FUNCTION POPULATES THE MAP WITH MARKERS FROM AN INTERNET SEARCH DONE FROM THE PRESENTATION PAGE.
function markbizsearch(biz) {
	
		var markonmap = true;
		var htmltab2="";
		var label1='Info';
		var label2='Directions';
		
	    var point = new GLatLng(currentbusinesses[biz].lat,currentbusinesses[biz].lng);
        var sbusiness = new GMarker(point, {icon:dynamicmarker});
		buildhtml(biz, markonmap);
		
		var directioinpoint=currentbusinesses[biz].lat+','+currentbusinesses[biz].lng;
		var name = currentbusinesses[biz].name;
		current_business_name = currentbusinesses[biz].name;
		var directionstab ='<div class="bubble1" id="bubble"><span class="titlefont">DIRECTIONS:<br><br><a href="javascript:setdirectionbubble(\'to\', \''+directioinpoint+'\', \''+name+'\' )">To Here  </a>   OR   <a href="javascript:setdirectionbubble(\'from\', \''+directioinpoint+'\', \''+name+'\')">  From Here</a></span></div>';
		
        // save the info we need to use later for the side_bar
        sbusinesses[biz] = sbusiness;
        bizinfos[biz] = bizinfo;
		bizbubbles[biz] = bizbubble;
		bizboxes[biz] = bizbox;
        
		 GEvent.addListener(sbusiness, "click", function() {
			activeresult=biz;
			activeresulttype = 'yahoo';
			activemarker=sbusiness;
			createtype='business';
			setmastercreatetype(createtype);
			//panoClient.getNearestPanorama(point, showPanoData);
			//genericinfobox(biz);
			sbusiness.openInfoWindowTabsHtml([new GInfoWindowTab(label1,bizbubbles[biz]), new GInfoWindowTab(label2,directionstab)]);
        });

        return sbusiness;
}


function showsearchbiz(biz) {
	
		var label1='C-Info';
		var label2='Directions';
		var point = new GLatLng(currentbusinesses[biz].lat,currentbusinesses[biz].lng);
        
		var directioinpoint=currentbusinesses[biz].lat+','+currentbusinesses[biz].lng;
		var name = currentbusinesses[biz].name;
		current_business_name = currentbusinesses[biz].name;
		
		var directionstab ='<div class="bubble1" id="bubble"><span class="titlefont">DIRECTIONS:<br><br><a href="javascript:setdirectionbubble(\'to\', \''+directioinpoint+'\', \''+name+'\' )">To Here  </a>   OR   <a href="javascript:setdirectionbubble(\'from\', \''+directioinpoint+'\', \''+name+'\')">  From Here</a></span></div>';
		
		//Resets the page.
		expandmappane();
		
		activemarker=sbusinesses[biz];
		activeresult=biz;
		activeresulttype = 'yahoo';
		//panoClient.getNearestPanorama(point, showPanoData);
		//genericinfobox(biz);
		map.setCenter(point, destinationzoom);
		sbusinesses[biz].openInfoWindowTabsHtml([new GInfoWindowTab(label1,bizbubbles[biz]), new GInfoWindowTab(label2,directionstab)]);
}


//THIS FUNCTIONS TAKES THE VARIABLES OF EACH SEARCH RESULTS AND FORMATS THE HTML THAT IS DISPLAYED IN THE BUBBLES AND RESULTS DIVS
function buildhtml(biz, markonmap){
	
	var gatheraddress='';
	bizinfo='';
	bizbubble='<div style="width:275px;">';
	bizbox='';
	
	
	if (currentbusinesses[biz].name!=""){
		bizinfo+='<b><a href="javascript:showsearchbiz(' + biz + ')">' + currentbusinesses[biz].name + '</a></b>';
		bizbubble+='<strong>'+currentbusinesses[biz].name+'</strong>';
		bizbox+=currentbusinesses[biz].name;
	}
	
	if (currentbusinesses[biz].address1!=""){
		bizinfo+='<br>'+currentbusinesses[biz].address1;
		bizbubble+='<br>'+currentbusinesses[biz].address1;
		bizbox+='\n'+currentbusinesses[biz].address1;
		gatheraddress+=currentbusinesses[biz].address1+' ';
	}
	if (currentbusinesses[biz].address2!=""){
		bizinfo+='<br>'+currentbusinesses[biz].address2;
		bizbubble+='<br>'+currentbusinesses[biz].address2;
		bizbox+='\n'+currentbusinesses[biz].address2;
	};
	if (currentbusinesses[biz].city!=""){
		bizinfo+='<br>'+currentbusinesses[biz].city;
		bizbubble+='<br>'+currentbusinesses[biz].city;
		bizbox+='\n'+currentbusinesses[biz].city;
		gatheraddress+=currentbusinesses[biz].city+' ';
	}
	if (currentbusinesses[biz].state!=""){
		bizinfo+=', '+currentbusinesses[biz].state;
		bizbubble+=', '+currentbusinesses[biz].state;
		bizbox+=', '+currentbusinesses[biz].state;
		gatheraddress+=currentbusinesses[biz].state;
	}
	if (currentbusinesses[biz].zip!=""){
		bizinfo+=', '+currentbusinesses[biz].zip;
		bizbubble+=', '+currentbusinesses[biz].zip;
		bizbox+=', '+currentbusinesses[biz].zip;
	}
	if (currentbusinesses[biz].county!=""){
		bizinfo+=', '+currentbusinesses[biz].country;
		bizbubble+=', '+currentbusinesses[biz].country;
		bizbox+=', '+currentbusinesses[biz].country;
	}
	if (currentbusinesses[biz].phone!=""){
		bizinfo+='<br>'+currentbusinesses[biz].phone;
		bizbubble+='<br>'+currentbusinesses[biz].phone;
		bizbox+='\n'+currentbusinesses[biz].phone;
	}
	
	
	if (currentbusinesses[biz].weblink!=""){
		
		bizinfo+='<br><a href="javascript:framewebsite(\''+currentbusinesses[biz].weblink+'\')"><span class="minifont">Website</span></a>';
		bizbubble+='<br><a href="javascript:framewebsite(\''+currentbusinesses[biz].weblink+'\')">Website</a>';
		bizbox+='\n'+currentbusinesses[biz].weblink;
	}
	
	var cleanaddress=cleansearchstring(gatheraddress);
	
	if(markonmap==true){
		bizbubble+='<br><br><span class="textlinks"><table width="275px" border="0" cellpadding="3">';
		bizbubble+='<tr><td><div align="left" width="40%" ></div></td>';
		bizbubble+='<td><div align="right" ><a href="javascript:saveactivemarker(\'business\')">Add to My Stuff</a></div></td></tr>';
		bizbubble+='<tr><td><div align="left"><a href="javascript:buildlocationseach(\''+cleanaddress+'\')">What\'s close by</a> |</div></td>';
		bizbubble+='<td><div align="right"><a href="javascript:prepforsend(\''+biz+'\', \'yahoo\')">Send to me</a></div></td>';
		bizbubble+='</tr></table></span>';
	}
	
	bizinfo+='<br><hr>';
	bizbubble+='</div>';
}


//HANDLES RESULTS FROM SEARCHFUNCTIONALITY.JS
function displayresults(i, wherefrom, destresults_html){
	
	
	try{
		if(wherefrom!='prox_storefronts'){
			//PUTS THE TOUR SHARING FUNCTIONALITY IN THE RESULTS PANE.
			var tourcontrols='<div id="tourcontrols">'+
							 '<table width="100%" cellpadding="0"><tr>'+
							 '<td align="left"><a href="javascript:buildshare(\'tour\')">'+
							 '<b>Share</b><span class="minifont"> this tour</span></a></td>'+
							 '<td align="right"><a href="javascript:associatetour(\''+currentdestinations[i].tourid+'\', \''+currentuser+'\')">'+
							 '<b>Add</b><span class="minifont"> this tour to my stuff</span></a></td>'+
							 '</tr></table></div>';
				//tourcontrols+='<td><a href="javascript:testconnections()">Connect</a></td>';
				
			var resultsheader='<div class="header" id="cpresultsheader">'+currentdestinations[i].tourname+'</div>';
		}
	
	
		var cpresultsheader = currentdestinations[0].tourname;
	}catch(err){
		var cpresultsheader = '';
	}
	
	switch (wherefrom){
		
		case 'invitation':
			var extragreeting = '<div id="welcomemessage" style="height:270px;">'
								+'<table width="100%" border="0" >'
								+'<tr><td align="center" class="cpfontbold">You have been invited to see </td></tr>';
				if(i!=1){		
					extragreeting += '<tr><td align="center" class="cpfontbold">the Cplanet Tour titled:</td></tr>'
									+'<tr><td align="center" class="cpfontheading">'+currentdestinations[i].tourname+'<hr></td></tr>'
									+'<tr><td align="center"><a href="javascript:displayresults(\'invitetour\')"><b>Click here to view this tour</b></a><br></td></tr>'
								    +'<tr><td align="center">Click the "Cthere" button to view the destination info and media (i.e. picture galleries, video, 3D models, etc.)</td></tr>';
									
					invitetourhtml=destresults_html;
					
				}else{
					extragreeting += '<tr><td align="center" class="cpfontbold">the Cplanet Destination titled:</td></tr>'
									+'<tr><td align="center" class="cpfontheading">'+currentdestinations[i].name+'<hr></td></tr>'
									+'<tr><td align="left">'+destresults_html+'</td></tr>';
					//alert(currentdestinations[i].hasmedia);
					if(currentdestinations[i].hasmedia=='True'){
						extragreeting += '<tr><td align="center">Click the "Cthere" button to view the destination info and media (i.e. picture galleries, video, 3D models, etc.)</td></tr>';
					}
					
					showdestination('0');
					
				}
				
			extragreeting += '</table></div>';
			
			cpresultsheader.innerHTML = 'Welcome to Cplanet';
			cpresultslocation.innerHTML = extragreeting;
			highslidecontrol('cpresultshtml');
		break;
		
		case 'invitetour':
			//USE THE HTML FROM THE GLOBAL VARIABLE SET WHEN THE TOUR INVITATION GREETING WAS POSTED.
			cpresultslocation.innerHTML = invitetourhtml;
			cpresultsheader.innerHTML = cpresultsheader;
			cpresultscontrols.innerHTML = tourcontrols;
		break;
		
		case 'poximitysearch':
			bizresultslocation.innerHTML = destresults_html;
			highslidecontrol('resultshtml');
			bizresultsheader.innerHTML='Featured Storefronts';
		break;
		
		case 'prox_storefronts':
			bizresultslocation.innerHTML = destresults_html;
			highslidecontrol('resultshtml');
			bizresultsheader.innerHTML='Featured Destinations';
		break;
		
		case 'bizsearch':
			bizresultslocation.innerHTML = destresults_html;
			highslidecontrol('resultshtml');
			bizresultsheader.innerHTML='Search Results';
		break;
		
		case 'sethub':
			destarray[0] = currentdestinations[0];
			hubbubble = destbubbles[0];
		break;
		
		case 'hubtour':
			//highslidecontrol('cpresultshtml');
//THE FOLLOWING FUNCTION IS IN THE STOREFRONT.JS
			cpresultslocation.innerHTML = destresults_html;
			cpresultsheader.innerHTML = cpresultsheader;
			cpresultscontrols.innerHTML = tourcontrols;
			highslidecontrol('cpresultshtml');
			connecttohub();
		break;
		
		case 'hubtourdestwin':
			connecttohub();
		break;
		
		default:
			cpresultslocation.innerHTML = destresults_html;
			cpresultsheader.innerHTML = cpresultsheader;
			cpresultscontrols.innerHTML = tourcontrols;
			highslidecontrol('cpresultshtml');
		break;
		
	 }
	
}

function connecttohub(){
	//alert('Connecting Destinations');
	var lat = parseFloat(destarray[0].lat);
	var lng = parseFloat(destarray[0].lng);
	//alert(lat+'\n'+lng);
	
	if(destarray[0].description != ''){
		custombubblehtml = '<div style="width:525px; height:auto;">'+destarray[0].description+'</div>';
	}else{
		custombubblehtml = hubbubble;
	}
	
	 var point = new GLatLng(lat,lng);
     var hubmarker = new GMarker(point, {icon:location_marker});
	 map.addOverlay(hubmarker, {zIndexProcess:100000000000});
	 hubmarker.openInfoWindowHtml(custombubblehtml);
	
	
	setTimeout("connecttodest("+lat+","+lng+")",500);
}
