/**
 * @author rick
 */
var centerLatitude = 42.45452612576739;
var centerLongitude = -75.0727128982544;
var startZoom = 15;
var map;
var markerHash={};
var highlightHash={};
var HighlightIDs = [];
var catHash={};
var gdir;
var currentMarker;
var currentCat;
var currentList;
var theMarkers;
var theCats = {};
var oldLevel = 0;
var directionForm;
var whatList;
var lastList = "";
var welcomeMsg = 0;
var welcomeMsgStr = "";
var OneontaFAQStr = "";
var WebSiteFAQStr = "";
var MessageHash = {};
var couponIcon = null;
var giftIcon = null;
var ootm = null;
var couponHash = {};
var couponHash2 = {};
var finalCuoponHash = {};
var couponIDs = "";
var usingEventOrCat = "";
var theKeyWords = "";
var currentRightBar = "rightBar";
var smsaddress = {};
var DISPLAY_OOTM_LOGO_BUBBLE = true; 
var  OOTMBubble;

//added for display
//************************************************************

function init() {
	map = new GMap($("map"));
	map.addControl(new GSmallMapControl());
	map.addControl(new GMapTypeControl());
	
	map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
	
	
couponIcon = new GIcon();
couponIcon.image = 'markers/image_coupon.png';
couponIcon.shadow = 'markers/shadow_coupon.png';
couponIcon.iconSize = new GSize(31,32);
couponIcon.shadowSize = new GSize(47,32);
couponIcon.iconAnchor = new GPoint(16,32);
couponIcon.infoWindowAnchor = new GPoint(16,0);
couponIcon.printImage = 'markers/printImage_coupon.gif';
couponIcon.mozPrintImage = 'markers/mozPrintImage_coupon.gif';
couponIcon.printShadow = 'markers/printShadow_coupon.gif';
couponIcon.transparent = 'markers/transparent_coupon.png';
couponIcon.imageMap = [9,3,10,4,10,5,10,6,11,7,27,8,27,9,22,10,16,11,26,12,26,13,26,14,26,15,26,16,26,17,26,18,26,19,26,20,26,21,26,22,26,23,26,24,26,25,26,26,26,27,26,28,26,29,6,29,6,28,6,27,6,26,6,25,6,24,6,23,6,22,6,21,6,20,6,19,6,18,6,17,6,16,6,15,4,14,3,13,3,12,3,11,8,10,10,9,9,8,7,7,6,6,5,5,5,4,5,3];

giftIcon = new GIcon();
giftIcon.image = 'markers/image_gift.png';
giftIcon.printImage = 'markers/printImage_gift.gif';
giftIcon.mozPrintImage = 'markers/mozPrintImage_gift.gif';
giftIcon.iconSize = new GSize(25,23);
giftIcon.shadow = 'markers/shadow_gift.png';
giftIcon.transparent = 'markers/transparent_gift.png';
giftIcon.shadowSize = new GSize(37,23);
giftIcon.printShadow = 'markers/printShadow_gift.gif';
giftIcon.iconAnchor = new GPoint(13,23);
giftIcon.infoWindowAnchor = new GPoint(13,0);
giftIcon.imageMap = [13,0,17,1,17,2,17,3,17,4,23,5,23,6,23,7,23,8,23,9,23,10,23,11,23,12,23,13,23,14,23,15,24,16,24,17,24,18,24,19,24,20,22,21,21,22,12,22,0,21,0,20,0,19,0,18,0,17,1,16,1,15,1,14,1,13,1,12,1,11,1,10,1,9,1,8,2,7,3,6,4,5,8,4,8,3,8,2,8,1,11,0];

ootm = new GIcon();
ootm.image = 'markers/image_ootm.png';
ootm.printImage = 'markers/printImage_ootm.gif';
ootm.mozPrintImage = 'markers/mozPrintImage_ootm.gif';
ootm.iconSize = new GSize(42,24);
ootm.shadow = 'markers/shadow_ootm.png';
ootm.transparent = 'markers/transparent_ootm.png';
ootm.shadowSize = new GSize(54,24);
ootm.printShadow = 'markers/printShadow_ootm.gif';
ootm.iconAnchor = new GPoint(21,24);
ootm.infoWindowAnchor = new GPoint(21,0);
ootm.imageMap = [36,0,39,1,40,2,40,3,41,4,41,5,41,6,41,7,41,8,41,9,41,10,41,11,41,12,40,13,39,14,38,15,35,16,32,17,32,18,32,19,32,20,32,21,32,22,32,23,7,23,7,22,7,21,7,20,7,19,7,18,7,17,6,16,2,15,1,14,0,13,0,12,0,11,0,10,0,9,0,8,0,7,0,6,0,5,0,4,0,3,1,2,2,1,4,0];





	var start = "";
	var end = "";


	//get the highlight markers
	//resetHighlights();
	

	

 	
 

	
	
    for(z = 0; z < couponHash2.length; z++)
    {
          var item = couponHash2[z];
          couponHash[item.id] = {
                  'id' : item.id,
                  'coupon_id' : item.id,
                  'C1': item.busname,
                  'C2': item.desc,
                  'C3': item.expdate
               };


    }

	
	
	

	/*
	if (lastList == "Cat") {
		resetMarkers(61, "Restaurants");
		
	}
	else if(lastList == "Event")
	{
		getEvents(0,0,0,0, "");
		
	}
	else if (lastList == "") {
		resetMarkers(61, "Restaurants");
		
	}
	*/
    
    getEvents(0,0,0,0, "");
	
	


	
	//var gdir = new GDirections(map,$("coupon"));
	//var togo = "from: 75 Oneida St. Oneonta, NY 13820 to: 378 Main St, Oneonta, NY 13820";
	//gdir.load(togo, {getSteps:true});
	//gdir.load(togo);
}
function checkCat(id, level)
{
	//collect all the submenus for this selection
	
	
	var index = 0;
	var content = "";
	var nlevel = level + 1;
	
	var FIRST_TIME = true;
	var catStr = "";
	
	var count = 0;
	for(i = 0; i < theCats.length; i++)
	{
		var c = theCats[i];
		if(c.id == id)
			catStr = c.name;
		if (c.parent_id == id) {
			
			//if(FIRST_TIME == true){
			//	content += "<a href=\"#\" onclick=\"checkCat(0," + nlevel + "); return false;\">All</a>";
			//	FIRST_TIME = false;
	
			//}
			content += "<a href=\"#\" onclick=\"checkCat(" + c.id + "," + nlevel + "); return false;\">" + c.name + "</a>";
			count++;
		//<a href="#" onclick="resetMarkers(2,1); return false;">Restaurants</a>
		}
	}
	
	if(content.length == 0 || oldLevel == level){
		document.getElementById("menuHoverDiv").innerHTML = "";
	}
	if(content.length > 0 && oldLevel > level){
		document.getElementById("menuHoverDiv").innerHTML = "";
	}
	
	 
	if(content.length == 0){
		//load the listings
		resetMarkers(id, catStr);
		
	}
	else{
	var adiv = document.createElement("div");
	adiv.id = "hoverMenu";
	var con = document.createElement("div");
	con.id = "hoverMenuContainer";
	
	adiv.innerHTML = content;
	
	if(level == 1){
		con.style.top = "70px";
		con.style.left = "25px";
		con.style.posLeft = 25;
		con.style.posTop = 70;
	}
	else if (level == 2){
		con.style.top = "70px";
		con.style.left = "165px";
		con.style.posLeft = 165;
		con.style.posTop = 70;

	}
	else if (level == 3){
		con.style.top = "70px";
		con.style.left = "305px";
		con.style.posLeft = 305;
		con.style.posTop = 70;

	}
	
	con.style.width = "140px";
	con.style.height = "" + count * 30 + "px";
	con.appendChild(adiv);
	
	var aspot = document.getElementById("menuHoverDiv");
	
	aspot.appendChild(con);
	oldLevel = level;
		
	}
	
}


function DisplayPermanentMarkers(DISPLAY_BUBBLE)
{
	for (i = 0; i < highlightHash.length; i++) 
 	{
			
		var current = highlightHash[i];
		if( current.id == 1780)
		{
			var lat = highlightHash[i].lat;
			var lng = highlightHash[i].lng;
			if (highlightHash[i].lat > 100) {
				lat *= .000001;
				lng *= .000001;
			}
			
			HighlightIDs[current.id] = addMarker(lat, lng, current.id, "O");
			if(DISPLAY_BUBBLE)
			{
				
				//var message = "Special Promotion<br/> Personalize your brand by<br/> adding your character logo<br/> or icon to the map<br/> Contact Mary for details<br/> <a href=\"mailto:mr@OneontaOnTheMap.com\">mr@OneontaOnTheMap.com<br/> ";
				
				//HighlightIDs[current.id].openInfoWindowHtml( message);
			}
			
			
		}
		

 	}

}



function resetMarkers(currentcat, catStr)
{
	map.clearOverlays();
	
	var FIRST_TIME = true;
	
	currentCat = currentcat;
	
	markerHash = {};
	
	// flash a working message
	document.getElementById("workingMsg").innerHTML = "Working...";
	

	
	// to search entire dir
	var searchWord = document.sFormCat.searchCat.value;
	
	
		new Ajax.Request( 'display/changecat', 
	{ 	method: 'post',
	    parameters: {cat_id: currentcat, name: searchWord},
		onComplete: function(request){
		
			theMarkers = eval("(" + request.responseText + ")");
			
		var content = "";
       usingEventOrCat = "Cat";
     
		
		//the first two are for the highlight
		var forHighLight = 2;
		
		if(theMarkers.length == 0)
			document.getElementById("workingMsg").innerHTML = "There were no results for this search.";
		else
			document.getElementById("workingMsg").innerHTML = "";
			
			
		for (i = 0; i < theMarkers.length; i++) {
		
			var current = theMarkers[i];
			
			var NO_ADDRESS = false;
			
			if(current.noaddress == 1)
				NO_ADDRESS = true;
			
			
			var lat = current.lat;
			var lng = current.lng;
			if(lat == null || lng == null)
			{
				lat =  centerLatitude;
				lng =  centerLongitude;
				NO_ADDRESS = true;
				
			}
			if (current.lat > 100) {
				lat *= .000001;
				lng *= .000001;
			}
			
			
			if (FIRST_TIME && current.displaylocation == 1) {
			
				map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
				
				
				//get the currentCat
				//currentcat = current.cat_id;

				FIRST_TIME = false;
			}
			

				var name =  current.name;
				if(name == null)
					name = "";
					
				var street = current.street;
				if(street == null)
					street = "";
					
				var city = current.city;
				if(city == null)
					city = "";
				
				var state = current.state;
				if(state == null)
					state = "";
				
				var zip = current.zip;
				if(zip == null)
					zip = "";
					
				var phone = current.phone;
				if(phone == null)
					phone = "";
					
				var fax = current.fax;
				if(fax == null)
					fax = "";
					
				var webtext = current.webtext;
				if(webtext == null)
					webtext = "";
					
				var weburl = current.weburl;
				if(weburl == null)
					weburl = "";
					
				var info = current.info;
				if(info == null)
					info = "";
					
				var header = current.infoheader;
				if(header == null)
					header = "";
					
				var imageurl = current.imageurl;
				if(imageurl == null)
					imageurl = "";
					
				var coupon = current.couponid;
				if(coupon == 0)
				coupon = null;


           var symbol = current.symbols;
           if(symbol == null)
              symbol = "";

           var video = current.video;
           if(video == null)
              video = "";


			marker = null;
         if(coupon != null)
            marker = addMarker(lat, lng, current.id, "C");
         else  if(symbol.match("G=") != null)
        	 marker = addMarker(lat, lng, current.id, "G");
         else 
        	 marker = addMarker(lat, lng, current.id, "YES");

			  //grab any highlight data
				markerHash[current.id] = {
				'marker': marker,
				'name': name,
				'noaddress': NO_ADDRESS,
				'street': street,
				'city': city,
				'state': state,
				'zip': zip,
				'phone': phone,
				'fax': fax,
				'webtext': webtext,
				'weburl': weburl,
				'info': info,
            'video': video,
				'header': header,
				'imageurl': imageurl,
				'coupon': coupon,
				'lat': lat,
				'lng': lng,
            'symbol': symbol,
				'visible': true
 			};

	
			
				
			

			
			if(current.cat_id == currentCat ||
				current.cat_id2 == currentCat ||
				current.cat_id3 == currentCat ||
            current.cat_id4 == currentCat ||
            current.cat_id5 == currentCat ||
				current.cat_id6 == currentCat)
			{
				
	
            //create the HTML for the rightBar
            content += "<a href=\""   +   location.href   +   "display/loc?theID=" + current.id + "\" onclick=\"focusPoint(" + current.id + "); return false;\">" + current.name;
 
           if(symbol.match("M=") != null)
               content += " &nbsp;<img src='/images/menuicon.gif' />";
           if(symbol.match("W=") != null)
               content += " &nbsp;<img src='/images/tinywifi.gif' />";
           if(symbol.match("G=") != null)
               content += " &nbsp;<img src='/images/tigrbox.gif' />";
           
            if(coupon != null)
            {
                content += " &nbsp;<img src='/markers/tinybluecoup.gif' />";
                /*
                couponHash[coupon] = {
                   'id' : current.id,
                   'coupon_id' : coupon,
                   'C1': "",
                   'C2': "",
                   'C3': ""
                };
                couponIDs += "" + coupon + ",";
                */
            }
            content += " </a>";

          


					
			}
			if(currentcat == -1)
			{
           content += "<a href=\"#\" onclick=\"focusPoint(" + current.id + "); return false;\">" + current.name;
            if(symbol.match("M=") != null)
               content += "&nbsp;<img src='/images/menuicon.gif' />";
            if(symbol.match("W=") != null)
                content += " &nbsp;<img src='/images/butwifi.gif' />";
            if(symbol.match("G=") != null)
                content += " &nbsp;<img src='/images/tigrbox.gif' />";
            
           if(coupon != null)
                content += "&nbsp;<img src='/markers/image_coupon.gif' />"

           content += "</a>";
			}
			
		
		}
		document.getElementById(currentRightBar).innerHTML = content;
      document.getElementById(currentRightBar).id = 'rightBarBusiness';
      currentRightBar =  'rightBarBusiness';
		
		for(var j in theCats){
			if(theCats[j].id == currentcat)
			catStr = theCats[j].name;
		}

     
		var regexStr = "/<(style|script)[^<>]*>.*?</\\1>|</?[a-z][a-z0-9]*[^<>]*>|<!--.*?-->/";
		
		if(catStr.match(regexStr))
		{
			catStr = "Coupons";
		}
		
		if(catStr.length > 15)
         catStr = catStr.substring(0,13) + "...";
 

		document.getElementById("rbhItems").innerHTML = catStr;
		
		
		
		DisplayPermanentMarkers(DISPLAY_OOTM_LOGO_BUBBLE);
		DISPLAY_OOTM_LOGO_BUBBLE = false;


		}	
	}); // end of the new Ajax.Request() call	

		
	

			
		

		
	
}
function DisplayHighlight(id, ADD_MARKER)
{

	
	
	for(var i in highlightHash)
 	{
		if (highlightHash[i].id == id) 
		{
			var current = highlightHash[i];
         var lat = highlightHash[i].lat;
			var lng = highlightHash[i].lng;
			if (highlightHash[i].lat > 100) {
				lat *= .000001;
				lng *= .000001;
			}

			var NO_ADDRESS = false;

			if(current.noaddress == 1)
				NO_ADDRESS = true;

            var name =  current.name;
				if(name == null)
					name = "";

				var street = current.street;
				if(street == null)
					street = "";

				var city = current.city;
				if(city == null)
					city = "";

				var state = current.state;
				if(state == null)
					state = "";

				var zip = current.zip;
				if(zip == null)
					zip = "";

				var phone = current.phone;
				if(phone == null)
					phone = "";

				var fax = current.fax;
				if(fax == null)
					fax = "";

				var webtext = current.webtext;
				if(webtext == null)
					webtext = "";

				var weburl = current.weburl;
				if(weburl == null)
					weburl = "";

				var info = current.info;
				if(info == null)
					info = "";

				var header = current.infoheader;
				if(header == null)
					header = "";

				var imageurl = current.imageurl;
				if(imageurl == null)
					imageurl = "";

				var coupon = current.couponid;
				if(coupon == 0)
				coupon = null;


           var symbol = current.symbols;
           if(symbol == null)
              symbol = "";

           var video = current.video;
           if(video == null)
              video = "";


			

          
           
           
           
           var marker = null;
           if(ADD_MARKER)
           {
	         if(coupon != null)
		            marker = addMarker(lat, lng, current.id, "C");
		         else  if(symbol.match("G=") != null)
		        	 marker = addMarker(lat, lng, current.id, "G");
		         else 
		        	 marker = addMarker(lat, lng, current.id, "YES");
           }
           else
           {
        	   marker = HighlightIDs[id];
           }
	           var portableHash = {};

           //grab any highlight data
				portableHash[i] = {
				'marker': marker,
				'name': name,
				'noaddress': NO_ADDRESS,
				'street': street,
				'city': city,
				'state': state,
				'zip': zip,
				'phone': phone,
				'fax': fax,
				'webtext': webtext,
				'weburl': weburl,
				'info': info,
            'video': video,
				'header': header,
				'imageurl': imageurl,
				'coupon': coupon,
				'lat': lat,
				'lng': lng,
            'symbol': symbol,
				'visible': true
 			};



	            if(coupon != null)
	            {
	                /*
	            	couponHash[coupon] = {
	                   'id' : current.id,
	                   'coupon_id' : coupon,
	                   'C1': "",
	                   'C2': "",
	                   'C3': ""
	                };
	                couponIDs += "" + coupon + ",";
	                */
	            }


	        	/*
	            //the ajax call to get all coupons
	            new Ajax.Request( 'display/getcoupons',
	        	{ 	method: 'post',
	        	    parameters: {cou_id: couponIDs},
	        		onComplete: function(request2){
	               theCoupons = eval("(" + request2.responseText + ")");

	               for (z = 0; z < theCoupons.length; z++) {

	                  var cc = theCoupons[z];
	                 couponHash[cc.id].C1 = cc.busname;
	                  couponHash[cc.id].C2 = cc.desc;
	                  couponHash[cc.id].C3 = cc.expdate;

	               }
	               
	            }
	            });
	            */


			//marker = addMarker(lat, lng, highlightHash[i].id);
			getHighlight(portableHash,i, marker);
			break;
			
			
		}
		
	
	}

			

	
	

	
}






function resetSearchReslts(html)
{
	
	for(var i in markerHash)
 	{
			if(usingEventOrCat == "Cat")
            html += "<a href=\"#\" onclick=\"focusPoint(" + i + "); return false;\">" + markerHash[i].name + "</a>";
         else
            html += "<a href=\"#\" onclick=\"focusEvent(" + i + "); return false;\">" + markerHash[i].name + "</a>";
	
 	}
		document.getElementById(currentRightBar).innerHTML = html;
  	if(usingEventOrCat == "Cat")
      {
      document.getElementById(currentRightBar).id = 'rightBarBusiness';
      currentRightBar = 'rightBarBusiness';
      }
      else
      {
         document.getElementById(currentRightBar).id = 'rightBarEvent';
         currentRightBar = 'rightBarEvent';

      }
		
}

function searchResults()
{
 
	var FOUND = false;
	var html = "";
	
	
	var searchWord = document.sForm.searchIt.value;
	
	
	if(searchWord.length == 0)
	{
		resetSearchReslts(html);
		
	}
		
	
 
 	
	var matchStr = searchWord.toUpperCase();
	
	
		for (var i in markerHash) {
			var tempId = i;
			var listStr = markerHash[i].name.toUpperCase();
			if (listStr.match(matchStr) != null) {
            if(usingEventOrCat == "Cat")
               html += "<a href=\"#\" onclick=\"focusPoint(" + tempId + "); return false;\">" + markerHash[i].name + "</a>";
            else
               html += "<a href=\"#\" onclick=\"focusEvent(" + tempId + "); return false;\">" + markerHash[i].name + "</a>";
				FOUND = true;
			}
			
			
		}
		if (FOUND == true) {
			document.getElementById(currentRightBar).innerHTML = html;
			document.getElementById("workingMsg").innerHTML = "";
         if(usingEventOrCat == "Cat")
            {
               document.getElementById(currentRightBar).id = 'rightBarBusiness';
               currentRightBar = 'rightBarBusiness';
            }
         else
            {
              document.getElementById(currentRightBar).id = 'rightBarEvent';
               currentRightBar = 'rightBarEvent';

            }

			
		
		}
		else
		{
			document.getElementById("workingMsg").innerHTML = "There were no results from that search.";
				
		}

	
	
}

function resetCatReslts(html)
{
	for(var i in theCats)
 	{
		if (theCats[i].parent_id == 7) {
			html += "<a href=\"#\" onclick=\"checkCat(" + theCats[i].id + ", 1); return false;\">" + theCats[i].name + "</a>";
		}
 	}
	document.getElementById("leftBar").innerHTML = html;
		
}
function searchCats()
{
 
	var FOUND = false;
	var html = "";
	
	var searchWord = document.sFormCat.searchCat.value;
	
	if(searchWord.length == 0)
	{
		resetCatReslts(html);
		return false;
	}
		
	
 
 	
	var matchStr = searchWord.toUpperCase();

	for(i = 0; i < theCats.length; i++)
 	{
		var tempId = i;
		c = theCats[i];
		var listStr = c.name;
		listStr = listStr.toUpperCase();
		if(listStr.match(matchStr) != null)
		{
			html += "<a href=\"#\" onclick=\"checkCat(" + c.id + ", 1); return false;\">" + c.name + "</a>";
			//<a href="#" onclick="checkCat(1,1); return false;">Restaurants</a>
			FOUND = true;
		}
		
	
 	}
 if(FOUND == true)
 {
 	document.getElementById("leftBar").innerHTML = html;
 }

	
	
}

function getEvents(syear,smonth,sday,eyear,emonth,eday, func)
{
	map.clearOverlays();
	
	var FIRST_TIME = true;
	
	
	removeHoverMenu();
	
	//empty marker hash
	//markerHash = {};

   // to search entire dir
	var searchWord = document.sForm.searchit.value;
		
		new Ajax.Request( 'display/getEvents', 
	{ 	method: 'post', 
		parameters: {syear: syear, smonth: smonth, sday: sday, eyear: eyear, emonth: emonth, eday: eday, search: searchWord},
		onSuccess: function(request){
		
			theEvents = eval("(" + request.responseText + ")");
			
		var content = "";
      usingEventOrCat = "Event";
		
		
		for(i=0;i<theEvents.length; i++) {
			
			var current =theEvents[i];
				
			
			
			var lat = current.lat;;
			var lng = current.lng;
			var SEND_CAUTION_MESSAGE = false;
			if(lat == null)
				lat = centerLatitude;
			if(lng == null){
				lng = centerLongitude;
				SEND_CAUTION_MESSAGE = true;
			}
			
			if(current.link == 1)
				SEND_CAUTION_MESSAGE = true;
				
		
			
			if (FIRST_TIME) {
			map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
			//map.setCenter(new GLatLng(lat, lng), startZoom);
			FIRST_TIME = false;
			}
			
			
			var DateInfo = "";
			if(current.startDate.match(current.endDate))
				DateInfo = "Date of Event = " + current.startDate;
			else
				DateInfo = "Dates of Event = " + current.startDate + " to " + current.endDate;
				
				
			
			marker = addMarkerEvent(lat, lng, current.id);
			markerHash[current.id] = {
				'marker': marker,
				'name': current.name,
				'sponsor': current.sponsor,
				'street': current.street,
				'city': current.city,
				'state': current.state,
				'zip': current.zip,
				'phone': current.phone,
				'webtext': current.weburl,
				'weburl': current.weburl,
				'info': current.info,
				'startDate': current.startDate,
				'endDate': current.endDate,
				'contactEmail': current.contactEmail,
				'eventHours': current.eventHours,
				'lat': lat,
				'lng': lng,
				'link': current.link,
				'caution': SEND_CAUTION_MESSAGE,
				'visible': true
			};
			
			//create the HTML for the rightBar
			content += "<a href=\"#\" onclick=\"focusEvent(" + current.id + "); return false;\">" + current.name +  current.evline + "</a>";
		//<a href="#" onclick="focusPoint(1); return false;">The Corfu Diner</a>
		
		
			
	
		}
		document.getElementById(currentRightBar).innerHTML = content;
      document.getElementById(currentRightBar).id = 'rightBarEvent';
      currentRightBar = 'rightBarEvent';

		var c = "Events";
		document.getElementById("rbhItems").innerHTML = c;
		
		whatList = "Events";
			
		
		
		
		DisplayPermanentMarkers(DISPLAY_OOTM_LOGO_BUBBLE);
		DISPLAY_OOTM_LOGO_BUBBLE = false;


		},
		onFailure: function(request){
			FailureMsg = eval("(" + request.responseText + ")");
			alert(FailureMsg);
		}	
		
	}); // end of the new Ajax.Request() call	
		
		

		
	
}






function addMarker(latitude, longitude, id, coupon){
	var marker = null;
   if(coupon === "C")
      {
		marker =  new GMarker(new GLatLng(latitude, longitude), couponIcon);
		GEvent.addListener(marker, 'click', function(){
		focusPoint(id);
	});
     map.addOverlay(marker);
      }
   
   if(coupon === "O")
   {
		marker =  new GMarker(new GLatLng(latitude, longitude), ootm);
		GEvent.addListener(marker, 'click', function(){
			DisplayHighlight(id,false);
	});
  map.addOverlay(marker);
   }
   if(coupon === "G")
   {
  marker =  new GMarker(new GLatLng(latitude, longitude), giftIcon);
  	 GEvent.addListener(marker, 'click', function(){
		focusPoint(id);
	});
  map.addOverlay(marker);
   }
   if(coupon === "NO")
     {
     marker =  new GMarker(new GLatLng(latitude, longitude));
       GEvent.addListener(marker, 'click', function(){
		focusPoint(id);
	});
   
   }
 if(coupon === "YES")
    {
      marker =  new GMarker(new GLatLng(latitude, longitude));
     	 GEvent.addListener(marker, 'click', function(){
		focusPoint(id);
	});
     map.addOverlay(marker);
    }
 
 
 
	return marker;
}
function addMarkerEvent(latitude, longitude, id){
	var marker = new GMarker(new GLatLng(latitude, longitude));
	GEvent.addListener(marker, 'click', function(){
		focusEvent(id);
	});
	map.addOverlay(marker);
	return marker;
}


function focusPoint(id){
	

	addressText = getAddress2(id, markerHash[id].marker, markerHash);
		
	
}
function focusEvent(id){
	
	var addressText = getTheEvent(id);

}
function getTheEvent(id)
{

	removeHoverMenu();	
	
	new Ajax.Request( 'addhit/hit',
	{ 	method: 'post',
	    parameters: {name: markerHash[id].name},
		onComplete: function(request){
         var result =eval( "(" + request.responseText + ")" );
      }});
	
	
	var addressHTML = document.createElement("div");
	

	
	var insideaddressHTML = "<b>" + markerHash[id].name + "</b><br/>";
	
	if(markerHash[id].link == 0)
	{
	
		insideaddressHTML += markerHash[id].street + "<br/>"
		+ markerHash[id].city + ", " + markerHash[id].state + " " + markerHash[id].zip + "<br/>"
	
	}
	if(markerHash[id].phone != null && markerHash[id].phone.length > 0)
		insideaddressHTML += "Phone: " + markerHash[id].phone + "<br/><br/>";
	
	if(markerHash[id].sponsor != null && markerHash[id].sponsor.length > 0)
		insideaddressHTML += "Sponsor: " + markerHash[id].sponsor + "<br/>";

	if(markerHash[id].webtext.length > 0)
	{
		insideaddressHTML += "<a href=\"" + markerHash[id].weburl + "\" >"  + markerHash[id].webtext + "</a><br/>";
	}
	
	if(markerHash[id].contactEmail.length > 0)
	{
		insideaddressHTML += 'Contact Email: <a href="mailto:' + markerHash[id].contactEmail + '">' + markerHash[id].contactEmail + '</a><br/>';
	}
	
	
	if(markerHash[id].link == 0)
	{
		if(markerHash[id].startDate.match(markerHash[id].endDate))
			insideaddressHTML += "Event DATE: " + markerHash[id].startDate + "<br/>";
		else
			insideaddressHTML += "Event DATES: " + markerHash[id].startDate + " to " + markerHash[id].endDate + "<br/>";
			
		insideaddressHTML += "Event Hours: " + markerHash[id].eventHours + "<br/>";
	}
	
	//if(markerHash[id].caution == true)
		//insideaddressHTML += '<br/><span style="color : #ff0000;">Note:</span> This map marker does not show the actual location of the event.  Use the address above.';
	
	
	
	addressHTML.style.height = "200px";
	addressHTML.style.width = "365px";
	addressHTML.style.margin = "1px";

	
	
	addressHTML.innerHTML = insideaddressHTML;
	
	
	var directionslatlng = "" + markerHash[id].lat + " " + markerHash[id].lng;

	
	directionsHTML = DirectionsFunction(directionslatlng);

	
	infoHTML = markerHash[id].info;
	if(infoHTML != null)
		if(infoHTML.length == 0)
			infoHTML = null;
	
	
	if (infoHTML == null) {
		
		
		if(markerHash[id].caution == true){
			var tabs = [new GInfoWindowTab("Address", addressHTML)];
			markerHash[id].marker.openInfoWindowTabsHtml(tabs);
			
		}
		else
		{
			var tabs = [new GInfoWindowTab("Address", addressHTML),
			new GInfoWindowTab("Directions",directionsHTML)];
			markerHash[id].marker.openInfoWindowTabsHtml(tabs);
			
		}
		
		
		
	}
	else {
	
	
		//get the title of the info window
		index = infoHTML.indexOf('\n');
		title = infoHTML.substring(0, index);
		infoHTML = infoHTML.substring(index + 1, infoHTML.length);
		
		
		var tab3Test = document.createElement("div");
		tab3Test.style.height = "150px";
		tab3Test.style.width = "365px";
		tab3Test.style.border = "ridge";
		//tab3Test.style.backgroundColor = "#95A87B";
		tab3Test.style.padding = "5px";
		tab3Test.style.margin = "5px";
		tab3Test.style.overflow = "auto";
		//tab3Test.innerHTML = "1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>10<br/>11<br/>12<br/>13<br/>14<br/>15<br/>16<br/>17<br/>18<br/>19<br/>";
		tab3Test.innerHTML = infoHTML;
		
		
		if(markerHash[id].caution == true){
			var tabs = [new GInfoWindowTab(" Address ", addressHTML), new GInfoWindowTab(" " + title + " ", tab3Test)];
			markerHash[id].marker.openInfoWindowTabsHtml(tabs);
		}
		else{
			var tabs = [new GInfoWindowTab(" Address ", addressHTML), new GInfoWindowTab(" " + title + " ", tab3Test),
			new GInfoWindowTab("Directions", directionsHTML)];
			markerHash[id].marker.openInfoWindowTabsHtml(tabs);
			
		}
		
		
		
	}

	currentMarker = markerHash[id].marker;
			
			


	
}

function removeHoverMenu()
{
	//remove any Hover menu
	document.getElementById("menuHoverDiv").innerHTML = "";
	
}


function PrintCoupon(couponHTML)
{
	
	var url = location.href;
	
	
	index = url.indexOf('#');
	url = url.substring(0, index);
	url += 'display/printit?image=' + couponHTML;

   var browser=navigator.appName;
   var b_version=navigator.appVersion;
   var version=parseFloat(b_version);
   if ((browser =="Microsoft Internet Explorer") && (version == 4 ))
   {
         document.location= url;
  }
   else
  {
 var newwin = window.open(url,
	"Print",
	"width=450, height=500 ,directories=no,menubar=no,toolbar=o,scrollbars=no,left=0,top=0,screenX=0,screenY=0");
  }



	
	
}

function theMessage(id)
{
	//get the proper message
	var infoHTML = MessageHash[id-1].themessage;
		
	//get the title of the info window
	//index = infoHTML.indexOf('\n');
	//infoTitle = infoHTML.substring(0, index);
	//infoHTML = infoHTML.substring(index + 1, infoHTML.length);
	
	var infoDiv = document.createElement("div");
	infoDiv.style.height = "180px";
	infoDiv.style.width = "335px";
	infoDiv.style.border = "ridge";
	//tab3Test.style.backgroundColor = "#95A87B";
	infoDiv.style.padding = "5px";
	infoDiv.style.margin = "5px";
	infoDiv.style.overflow = "auto";
	//tab3Test.innerHTML = "1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>10<br/>11<br/>12<br/>13<br/>14<br/>15<br/>16<br/>17<br/>18<br/>19<br/>";
	infoDiv.innerHTML = infoHTML;
	
	//now display it
	tabs = [new GInfoWindowTab("Dummy", infoDiv)];
	
	var marker = addMarker(centerLatitude, centerLongitude, 0);
	marker.openInfoWindowTabsHtml(tabs);

		
}
function theMessageRick(url)
{
	
		
	var newwin = window.open(url,
	"Information",
	"width=700, height=750,directories=no,menubar=yes,toolbar=no,scrollbars=yes,left=0,top=0,screenX=0,screenY=0");

		

}
// not used
function getFaqMessage()
{

	var infoHTML = OneontaFAQStr;
		
	//get the title of the info window
	index = infoHTML.indexOf('\n');
	infoTitle = infoHTML.substring(0, index);
	infoHTML = infoHTML.substring(index + 1, infoHTML.length);
	
	var infoDiv = document.createElement("div");
	infoDiv.style.height = "180px";
	infoDiv.style.width = "335px";
	infoDiv.style.border = "ridge";
	//tab3Test.style.backgroundColor = "#95A87B";
	infoDiv.style.padding = "5px";
	infoDiv.style.margin = "5px";
	infoDiv.style.overflow = "auto";
	//tab3Test.innerHTML = "1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>10<br/>11<br/>12<br/>13<br/>14<br/>15<br/>16<br/>17<br/>18<br/>19<br/>";
	infoDiv.innerHTML = infoHTML;
	
	infoHTML = "";
	
	infoHTML = WebSiteFAQStr;
		
	//get the title of the info window
	index = infoHTML.indexOf('\n');
	infoTitle = infoHTML.substring(0, index);
	infoHTML = infoHTML.substring(index + 1, infoHTML.length);
	
	var infoDiv2 = document.createElement("div");
	infoDiv2.style.height = "180px";
	infoDiv2.style.width = "335px";
	infoDiv2.style.border = "ridge";
	//tab3Test.style.backgroundColor = "#95A87B";
	infoDiv2.style.padding = "5px";
	infoDiv2.style.margin = "5px";
	infoDiv2.style.overflow = "auto";
	//tab3Test.innerHTML = "1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>10<br/>11<br/>12<br/>13<br/>14<br/>15<br/>16<br/>17<br/>18<br/>19<br/>";
	infoDiv2.innerHTML = infoHTML;
	
	
	
	
	tabs = [new GInfoWindowTab("Oneonta FAQ", infoDiv),
	new GInfoWindowTab("Web Site FAQ", infoDiv2)];

	
	var marker = addMarker(centerLatitude, centerLongitude, 0);
	marker.openInfoWindowTabsHtml(tabs);

		
}
function setBackPage(id)
{
   //document.location.replace(document.location.href + "display/loc?theID=" + id);
   //document.location.href = document.location.href + "display/loc?theID=" + id;
   //window.alert(document.location.href + "display/loc?theID=" + id);
}

function grabData(data, type)
{
	var startindex = data.indexOf(type);
	var tempString = data.substring(startindex, data.length);
	var endindex = tempString.indexOf('\n');
	var result = tempString.substring(2, endindex);
	return result;
}


function getAddress2(id, theMarker, theHash)
{
			
	removeHoverMenu();		

   //if( theHash[id].symbol.match("C1=") === null)
     //  theHash[id].marker = addMarker(lat, lng,  theHash[id].id, "YES");
	
	
	var NO_ADDRESS =  theHash[id].noaddress;
	var NO_INFO = false;
	var NO_IMAGE = false;
	var NO_DIRECTIONS = false;
	var NO_COUPON = false;
   var NO_VIDEO = false;

   new Ajax.Request( 'addhit/hit',
	{ 	method: 'post',
	    parameters: {name: theHash[id].name},
		onComplete: function(request){
         var result =eval( "(" + request.responseText + ")" );
      }});

	
	
	//*********************************************************************
	//************** get address info ***********************************
	var addressHTML = document.createElement("div");
	addressHTML.style.height = "170px";
	addressHTML.style.width = "335px";
	addressHTML.style.margin = "5px";
	
	
	
	
	
	var insideaddressHTML = "<b>" +  theHash[id].name + "</b><br/>";
	
	if(NO_ADDRESS == false)
	{
		insideaddressHTML +=  theHash[id].street + "<br/>"
		+  theHash[id].city + ", " +  theHash[id].state + " " +  theHash[id].zip + "<br/>"
	}
	insideaddressHTML += "Phone: " +  theHash[id].phone + "<br/>";
	
	var faxNumber =  theHash[id].fax;
	
	if(faxNumber != null && faxNumber.length > 0)
	{
		insideaddressHTML += "Fax: " +  theHash[id].fax + "<br/>";

	}
	
	if( theHash[id].webtext.length > 0)
	{
		insideaddressHTML += '<a href="' +  theHash[id].weburl +
       '" onmousedown="setBackPage('+ id   + ');"' +
       ' >'  +  theHash[id].webtext +
       '</a><br/>';
	}
   //add a CR before icons
   insideaddressHTML +='<br/>';



	//added 5-2-09 for special symbols
    if( theHash[id].symbol.match("M="))
    {
 		insideaddressHTML += '<div style="margin-top:5px; margin:5px;"><img src="/images/menuicon.gif"/>&nbsp;<a href="' + grabData(theHash[id].symbol,"M=") + '" >&nbsp;Click for Menu.</a></div>';

    }
    if( theHash[id].symbol.match("W="))
    {
        insideaddressHTML += '<div style="margin-top:5px; margin:5px;"><img src="/images/butwifi.gif"/>&nbsp;' + grabData(theHash[id].symbol,"W=") + '</div>';

    }
    if( theHash[id].symbol.match("F="))
    {
        insideaddressHTML += '<div style="margin-top:5px; margin:5px;"><img src="/images/imgfacebookicon.gif"/>&nbsp;<a href="' + grabData(theHash[id].symbol,"F=") + '" >&nbsp;Facebook Page</a></div>';

    }
    if( theHash[id].symbol.match("T="))
    {
         insideaddressHTML += '<div style="margin-top:5px; margin:5px;"><img src="/images/imgtwittericon.gif"/>&nbsp;<a href="' + grabData(theHash[id].symbol,"T=") + '" >&nbsp;Twitter Page</a></div>';
    }
    
 
     
     
     
    if( theHash[id].coupon != null)
       {
       insideaddressHTML += '<scan style="margin-top:5px; margin:5px;"><img src="/markers/image_coupon.png"/>&nbsp;This Business is providing a money saving Coupon or Special.</scan>';
       }

      if( theHash[id].symbol.match("L="))
       {
         startindex = theHash[id].symbol.indexOf('L=');
         index =  theHash[id].symbol.indexOf('\n');
         var localBusText =   theHash[id].symbol.substring(startindex+2, index-1);
         insideaddressHTML += '<scan style="margin-top:5px; margin:5px;"><img src="/images/symstarown.gif"/>&nbsp;' + localBusText + '</scan>';

       }

	

   addressHTML.innerHTML = insideaddressHTML;

	//**********************************************************************************
	
	
	
	//add info about no geo marker
	if(NO_ADDRESS == true)
	{
		var cautionHTML = document.createElement("div");
		cautionHTML.style.position = "absolute";
		cautionHTML.style.bottom = "5px";
		cautionHTML.style.color = "red";
		cautionHTML.style.fontsize = "smaller";
		cautionHTML.innerHTML = "NOTE:This map marker does not show the location of the listing.  No address given.";
		addressHTML.appendChild(cautionHTML); 
		NO_DIRECTIONS = true;

	}
	
	
	
	
	//********************************************************************************
	//***************** get address for directions **************************
	
	//addressForDir =  theHash[id].name
	addressForDir =   theHash[id].street
	+ ", " +  theHash[id].city
	+ ", " +  theHash[id].state
	+ " " +  theHash[id].zip;
	
	addressForDir = "" +  theHash[id].lat + " " +  theHash[id].lng;

	
	directionsHTML = DirectionsFunction(addressForDir);
	//***********************************************************************************
	
	
	
	
	// **********************************************************************************
	//*********** check for the optional parameters info picture coupon ******************
   var videoHTML = theHash[id].video;
   if(videoHTML != null && videoHTML.length == 0)
   {
       videoHTML = null;
       NO_VIDEO = true;
    }
	
	var infoHTML =  theHash[id].info;
	if(infoHTML != null && infoHTML.length == 0)
	{
		infoHTML = null;
		NO_INFO = true;
	}
	
	var imageurl =  theHash[id].imageurl;
	if(imageurl != null && imageurl.length == 0)
	{
		imageurl = null;
		NO_IMAGE = true;
	}
	
	var coupon =  theHash[id].coupon;
	if(coupon == null)
	{
		coupon = null;
		NO_COUPON = true;
	}
		
	
	if(infoHTML != null)
	{
		var infoHeader =  theHash[id].header;
		if(infoHeader != null && infoHeader.length == 0)
			infoHeader = null;
		
		if(infoHeader == null)
		{
			//get the title of the info window
			index = infoHTML.indexOf('\n');
			infoTitle = infoHTML.substring(0, index);
			infoHTML = infoHTML.substring(index + 1, infoHTML.length);
		}
		else
		{
			infoTitle = infoHeader;
		}
		
		
		
		
		var infoDiv = document.createElement("div");
		infoDiv.style.height = "210px";
		infoDiv.style.width = "335px";
		infoDiv.style.border = "ridge";
		//tab3Test.style.backgroundColor = "#95A87B";
		infoDiv.style.padding = "3px";
		infoDiv.style.margin = "3px";
		infoDiv.style.overflow = "auto";
		//tab3Test.innerHTML = "1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>10<br/>11<br/>12<br/>13<br/>14<br/>15<br/>16<br/>17<br/>18<br/>19<br/>";
		infoDiv.innerHTML = infoHTML;
		
	}

   if(videoHTML != null)
   {
      var videoDiv = document.createElement("div");
		videoDiv.style.height = "210px";
		videoDiv.style.width = "335px";
		videoDiv.style.border = "ridge";
		//tab3Test.style.backgroundColor = "#95A87B";
		videoDiv.style.padding = "3px";
		videoDiv.style.margin = "3px";
		videoDiv.style.overflow = "auto";
		//tab3Test.innerHTML = "1<br/>2<br/>3<br/>4<br/>5<br/>6<br/>7<br/>8<br/>9<br/>10<br/>11<br/>12<br/>13<br/>14<br/>15<br/>16<br/>17<br/>18<br/>19<br/>";
		videoDiv.innerHTML = videoHTML;

   }



	if(imageurl != null)
	{
		var imageHTML = '<img src="images/' + imageurl + '" alt="Oneonta NY directory", NAME="thecurrentimageame" />';
		
		var imageDiv = document.createElement("div");
		imageDiv.style.height = "170px";
		imageDiv.style.width = "335px";
		imageDiv.style.border = "ridge";
		imageDiv.style.padding = "5px";
		imageDiv.style.margin = "5px";
		imageDiv.style.overflow = "auto";
		imageDiv.innerHTML = imageHTML;
		

		
	}
	if(coupon != null)
	{
      var busname = "";
      var desc = "";
      var expdate = "";


       //get the business name
      busname = couponHash[coupon].C1;
      desc = couponHash[coupon].C2;
      expdate = couponHash[coupon].C3;
 		
	  var couponImageDiv = document.createElement("div");




     couponImageDiv.innerHTML ='           <div id="ccHolder">    <div class="roundedcornr_box_704110">' +
   '<div class="roundedcornr_top_704110"><div></div></div>' +
      '<div class="roundedcornr_content_704110">' +
         '<p id="thecBusinessName">' + busname + '</p>' +
         '<p id="thecDescription">' + desc + '</p>' +
        ' <p id="thecendDate">' + expdate + '</p>' +
      '</div>' +
   '<div class="roundedcornr_bottom_704110"><div></div></div>' +
'</div></div>';
		
		
		
		var printcouponForm = document.createElement("form");
		printcouponForm.id='name-input';
		printcouponForm.setAttribute("action","");
		printcouponForm.onsubmit = function() {PrintCoupon( theHash[id].coupon); return false;};
		printcouponForm.innerHTML = '<input type="submit" value="Print Coupon or Send it to your Cell Phone"/>';

		var textcouponForm = document.createElement("form");
		textcouponForm.id='name-input';
		textcouponForm.setAttribute("action","");
		textcouponForm.onsubmit = function() {TextCoupon( theHash[id].coupon); return false;};
		textcouponForm.innerHTML = '<input type="submit" value="Go Green: Send the coupon to your Cell Phone"/>';

      
     
     var theHTML = '<div id="textMessageFormID">'
	+ '<form onSubmit="sendTextMessage(); return false;" name="textMessageForm" action="" method="" accept-charset="utf-8">';
	 theHTML += '<input type="submit" value="Go Green: Send the coupon to your Cell Phone" /><br/>';
    theHTML += '<span id="adleft">10 digit Cell Number No - or ():</span><span id="adcontent"><input type="text" id="cellnumID" name="cellName" style="width:85px;"/></span><br/>';
	 theHTML += '<span id="adleft">Cell Carrier<select id="cellcid" name="cellc"><option value=""></option>';
    		for (i = 0; i < smsaddress.length; i++) {
           var c =  smsaddress[i];
           theHTML += '<option value="'+c.address+'">'+c.name+'</option>';
         }
   theHTML += '</select></span>';
   theHTML += '<input type="hidden" id="busnameid" name="address" value="'+busname +'"/>'
   theHTML += '<input type="hidden" id="descidd" name="address" value="'+ desc +'"/>'
   theHTML += '<input type="hidden" id="expdateid" name="address" value="'+ expdate +'"/>'
  
      
    theHTML += ' </form> </div>';

   var textMessageForm = document.createElement("div");
   textMessageForm.innerHTML = theHTML;


		
		
		var couponDiv = document.createElement("div");
		//couponDiv.style.height = "170px";
		//couponDiv.style.width = "365px";
		//couponDiv.style.border = "ridge";
		couponDiv.style.padding = "5px";
		couponDiv.style.margin = "5px";
		//couponDiv.style.overflow = "auto";
      couponDiv.appendChild(couponImageDiv);
      couponDiv.appendChild(printcouponForm);
		//couponDiv.appendChild(textcouponForm);
		
	}
	//**********************************************************************************
	
	
	
	
	//**********************************************************************************
	//******************** build the tabs ***********************************************
	var tabs = [];
	var tabsIndex = 0
	var giftText = "";
	if( theHash[id].symbol.match("G="))
    {
       	startindex = theHash[id].symbol.indexOf('G=');
        index =  theHash[id].symbol.indexOf('\n');
        giftText =   theHash[id].symbol.substring(startindex+2, index-1);
        
		
       
		tabs[tabsIndex++] = new GInfoWindowTab(giftText, infoDiv);
        tabs[tabsIndex++] = new GInfoWindowTab("Address", addressHTML);
	   if(NO_COUPON == false)
	    	tabs[tabsIndex++] = new GInfoWindowTab("Coupon", couponDiv);
	    if(NO_IMAGE == false)
	    	tabs[tabsIndex++] = new GInfoWindowTab("Photo", imageHTML);
	   if(NO_VIDEO == false)
	      tabs[tabsIndex++] = new GInfoWindowTab("Video", videoDiv);
	    if(NO_DIRECTIONS == false)
	    	tabs[tabsIndex++] = new GInfoWindowTab("Directions", directionsHTML);
        
        
        
        
     }
	else if(NO_COUPON == false)
	{
	
		
    	tabs[tabsIndex++] = new GInfoWindowTab("Coupon", couponDiv);		
		tabs[tabsIndex++] = new GInfoWindowTab("Address", addressHTML);
		if(NO_INFO == false)
			tabs[tabsIndex++] = new GInfoWindowTab(infoTitle, infoDiv);
		if(NO_IMAGE == false)
			tabs[tabsIndex++] = new GInfoWindowTab("Photo", imageHTML);
		   if(NO_VIDEO == false)
		      tabs[tabsIndex++] = new GInfoWindowTab("Video", videoDiv);
		if(NO_DIRECTIONS == false)
			tabs[tabsIndex++] = new GInfoWindowTab("Directions", directionsHTML);
	}
	else
	{
	
		tabs[tabsIndex++] = new GInfoWindowTab("Address", addressHTML);
		if(NO_COUPON == false)
		    	tabs[tabsIndex++] = new GInfoWindowTab("Coupon", couponDiv);
		if(NO_INFO == false)
			tabs[tabsIndex++] = new GInfoWindowTab(infoTitle, infoDiv);
		if(NO_IMAGE == false)
			tabs[tabsIndex++] = new GInfoWindowTab("Photo", imageHTML);
		   if(NO_VIDEO == false)
		      tabs[tabsIndex++] = new GInfoWindowTab("Video", videoDiv);
		if(NO_DIRECTIONS == false)
			tabs[tabsIndex++] = new GInfoWindowTab("Directions", directionsHTML);
	}
	
	// set the marker
	
	if(NO_IMAGE == false)
	{

		//reset the size of the marker if we have an image
		GEvent.addListener( theHash[id].marker, "infowindowopen", function() {
		var imgHeight = document.thecurrentimageame.height;
		//var imgWidth = document.images[imageurl].width;
		if (imgHeight > 170) {
			addressHTML.style.height = "" +  imgHeight + "px";
			
		}
	  });

	}
  if(tabsIndex > 4)
      addressHTML.style.width = "420px";


	
	 theHash[id].marker.openInfoWindowTabsHtml(tabs);
	
	whatList = "Locations";
	currentMarker =   theMarker;
			
			


	
}
function sendTextMessage()
{
   var num = $("cellnumID").value;
   var carr = $("cellcid").value;
   var id = $("couphashid").value;
   var busname = $("busnameid").value;
   var desc  = $("descid").value;
   var expdate  = $("expdateid").value;
  new Ajax.Request( 'display/sendtxt',
	{ 	method: 'post',
	    parameters: {num: num, carr: carr, busname:busname, desc:desc,expdate:expdate},
		onComplete: function(request){
         var result =eval( "(" + request.responseText + ")" );
      }});



}

function getHighlight(portableHash, id, theMarker)
{

      getAddress2(id, theMarker,portableHash);

 }

function DirectionsFunction(addressD)
{
//create an HTML DOM form element
	/*
	directionForm = null;
	directionForm = document.createElement("form");

	directionForm.name = 'directionForm';
	directionForm.id='direction-input';
	directionForm.setAttribute("action","");
	directionForm.onsubmit = function() {createDirections(); return false;};
	directionForm.innerHTML = '<fieldset style="width:150px;">'
	+ '<legend>From Here</legend>'
	+ '<label for="FromHere">Type in Address</label>'
	+ 'Street: <input type="text" id="FromHereID" name="FromHere" style="width:150%;"/>'
	+ 'City: '
	+ '<input type="submit" value="Go"/>'
	+ '<input type="hidden" id="addressD" name="address" value="'+ addressD +'"/>'
	//+ '<input type="hidden" id="latitude" name="m[lat]" value="' + lat + '"/>'
	+ '</fieldset>';
	*/
	
	
	directionForm = null;
	directionForm = document.createElement("div");
	
	
	directionForm.innerHTML = '<div id="dirctionFormID">'
	+ '<form onSubmit="createDirections(); return false;" name="directionForm" action="" method="" accept-charset="utf-8">'
	+ '<fieldset style="width:325px;">'
	+ '<legend id="dirLegendID">Type your starting Address Here</legend>'
	+ '<p><span id="adleft">Street:</span><span id="adcontent"><input type="text" id="streetID" name="streetName" style="width:225px;"/></span></p>'
	+ '<p><span id="adleft">City:</span><span id="adcontent"><input type="text" id="cityID" name="cityName" style="width:75px;"/></span>'
	+ '<span id="adleft">State:</span><span id="adcontent"><input type="text" id="stateID" name="stateName" style="width:25px;"/></span>'
	+ '<span id="adleft">Zip:</span><span id="adcontent"><input type="text" id="zipID" name="zipName" style="width:50px;"/></span></p>'
	+ '<input type="hidden" id="addressD" name="address" value="'+ addressD +'"/>'
	+ '<p><input type="submit" value="Get Directions" /></p>'
	+ '</fieldset>'
	+ '</form>'
	+ '</div>';
	
	
	return directionForm;
}

function createDirections()
{
	//var addressD = $("addressD").value;
	//var FromHere = $("FromHereID");
	
		//var addressD = document.directionForm.address.value;
		//var fromHere = document.directionForm.FromHere.value;
		var addressD = $("addressD").value;
		var fromHere = $("streetID").value + ' , '
		+ $("cityID").value + ' , '
		+ $("stateID").value + ' '
		+ $("zipID").value;
	
	
		
	var url = location.href;
	
	
	index = url.indexOf('#');
	url = url.substring(0, index);
	url = url + 'display/getdirections?from=' + fromHere + '&to=' + addressD;


   var browser=navigator.appName;
   var b_version=navigator.appVersion;
   var version=parseFloat(b_version);
   if ((browser =="Microsoft Internet Explorer") && (version == 4 ))
   {
         document.location= url;
  }
   else
  {
 var newwin = window.open(url,
	"Print",
	"width=580, height=750,directories=no,menubar=no,toolbar=no,scrollbars=yes,left=0,top=0,screenX=0,screenY=0");
  }

   
		
		
		/*
		gdir = new GDirections(map, $("directions"));
		var togo = "from: " + fromHere +
		" to: " +
		addressD;
		
		GEvent.addListener(gdir, "load", this.DirectionsLoadEvent());
		GEvent.addListener(gdir, "error", this.DirectionsErrorEvent());
		//GEvent.addListener(gdir, "addoverlay", this.DirectionsSuccessEvent());
		
		
		gdir.load(togo, {
			"getSteps": true,
			"preserveViewport": false,
			"getPolyline": false,
			"locale": locale });
		//gdir.load(togo);
		
		*/
		
	return false;
	
}
function DirectionsLoadEvent()
{
		//window.alert(gdir.getStatus() + " load event");
		
		
		var html = '<table width="100" border="0"><tr><td><form onClick="PrintDirections();return false;" accept-charset="utf-8">' +
		'<input type="submit" value="Print Directions" /></form></td><td>' +
		'<form  onClick="ClearDirections();return false;" accept-charset="utf-8">' +
		'<input type="submit" value="Clear Directions" /></form></td></tr></table>';
		
		
		document.getElementById("directionsTop").innerHTML = html;
		
		var dt = document.getElementById("directionsTop");
		dt.style.display = "block";
		var d = document.getElementById("directions");
		d.style.display = "block";
		
	
}
function DirectionsSuccessEvent()
{
	
	window.alert(gdir.getStatus() + " overlay event");
	/*
	var error = gdir.getStatus();
	if (error) 
		;
	else {
	
		var html = '<table width="100" border="0"><tr><td><form onClick="PrintDirections();return false;" accept-charset="utf-8">' +
		'<input type="submit" value="Print Directions" /></form></td><td>' +
		'<form  onClick="ClearDirections();return false;" accept-charset="utf-8">' +
		'<input type="submit" value="Clear Directions" /></form></td></tr></table>';
		
		
		document.getElementById("directionsTop").innerHTML = html;
		
		var dt = document.getElementById("directionsTop");
		dt.style.display = "block";
		var d = document.getElementById("directions");
		d.style.display = "block";

	}
	*/
}
function placemenu(theone)
{
	var theHTML = "| ";
	
		while(true)
		{
			DONE = false;
			index = theone.indexOf('^');
			if (index == -1) {
				index = theone.length;
				DONE = true;
			}
			
				
			theData = theone.substring(0,index);
			theone = theone.substring(index+1);
			
			index = theData.indexOf('|');
			theText = theData.substring(0,index);
			theURL = theData.substring(index+1);
			if(theURL.indexOf("theMess") != -1)
			{
				theHTML += 	"<a href=\"#\" onclick=\"" + theURL + "; return false;\">" + theText + "</a>  |";
				
			}
			
			else
			{
				theHTML += "<a href=\"" + theURL + "\">" + theText + "</a>   |"; 
			}
			
			
			
			if(DONE == true)
				break;

		
	}
	document.getElementById("topmenu2").innerHTML = theHTML;
	document.getElementById("topmenu2").style.display = "inline";
	


}
function ClearDirections()
{
	gdir.clear();
	document.getElementById("directionsTop").innerHTML = "";
	var dt = document.getElementById("directionsTop");
	dt.style.display = "none";
	var d = document.getElementById("directions");
	d.style.display = "none";

	currentMarker.closeInfoWindow();
	
}
function PrintDirections()
{
	window.print();
}


function DirectionsErrorEvent()
{
	var message = "An unknown error occurred.";

    if (gdir.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
        message = "No corresponding geographic location could be found for one of the specified addresses. This may be due to the fact that the address is relatively new, or it may be incorrect.\nError code: " + gdir.getStatus().code;
    else if (gdir.getStatus().code == G_GEO_SERVER_ERROR)
        message = "A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gdir.getStatus().code;
    else if (gdir.getStatus().code == G_GEO_MISSING_QUERY)
        message = "The HTTP q parameter was either missing or had no value. For geocoder requests, this means that an empty address was specified as input. For directions requests, this means that no query was specified in the input.\n Error code: " + gdir.getStatus().code;
    else if (gdir.getStatus().code == G_GEO_BAD_KEY)
        message = "The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gdir.getStatus().code;
    else if (gdir.getStatus().code == G_GEO_BAD_REQUEST)
        message = "A directions request could not be successfully parsed.\n Error code: " + gdir.getStatus().code;

    window.alert("<strong>Message:</strong>" + message);
}

function processAddress(request)
{
	
	address = request.responseText;
	
	var directionsText = "Go straight down Main St and take a left on<br/> chestnut st and drive for one mile.";
	//var menuText = "soups<br/>Sandwiches<br/>Salads<br/>Pizza<br/>Coffee<br/>";
	var menuText = document.createElement("div");
	menuText.innerHTML = '<fieldset style="overflow: auto; height: 100%;">'
	+ 'soups<br/>Sandwiches<br/>Salads<br/>Pizza<br/>Coffee<br/>Tea<br/>Soft Drinks<br/>Tea';
	var tabs = [
			new GInfoWindowTab("Address",addressText),
			new GInfoWindowTab("Directions",directionsText),
			new GInfoWindowTab("Menu",menuText)];
	
	//markerHash[id].marker.openInfoWindowHtml(markerHash[id].address);
	markerHash[id].marker.openInfoWindowTabsHtml(tabs);	


}



//*********************************************************************




function createMarker(){
	var lng = $("longitude").value;
	var lat = $("latitude").value;
	var formValues=Form.serialize('name-input');
	new Ajax.Request( 'http://192.168.0.120:3000/chap_three/create', 
	{ 	method: 'post', 
		parameters: formValues,
		onComplete: function(request){
			//parse the result to JSON (simply by eval-ing it)
			res=eval( "(" + request.responseText + ")" );
			//check to see if it was an error or success
			if(!res.success) {
				alert(res.content);
			} else {
				//create anew marker and add its info window
				var latlng = new GLatLng(parseFloat(lat),parseFloat(lng));
				var marker = addMarkerToMap(latlng, res.content);
				map.addOverlay(marker);
				map.closeInfoWindow();
			} // end of the res.success check
		}
	}); // end of the new Ajax.Request() call
}

function addMarkerToMap(latlng, html) {
	var marker = new GMarker(latlng);
	GEvent.addListener(marker, 'click', function() {
	var markerHTML = html;
	marker.openInfoWindowHtml(markerHTML);
	});
	return marker;
}
function listMarkers() {
	var request = GXmlHttp.create();
	//tell the request where to retrieve data from.
	request.open('GET', 'http://192.168.0.120:3000/chap_three/list', true);
	//tell the request what to do when the state changes.
	request.onreadystatechange = function() {
		if (request.readyState == 4) {
		//parse the result to JSON,by eval-ing it. 
		//The response is an array of markers
		markers=eval( "(" + request.responseText + ")" );
		for (var i = 0 ; i < markers.length ; i++) {
			var marker=markers[i].attributes
			var lat=marker.lat;
			var lng=marker.lng;
			//check for lat and lng so MSIE does not error
			//on parseFloat of anull value
			if (lat && lng) {
				var latlng = new GLatLng(parseFloat(lat),parseFloat(lng));
				//var html = '<div font-family: sans-serif >'
				var html = document.createElement("div");
				html.font = 'arial';
				html.innerHTML = '<b>Name </b>' + marker.name;
				var marker = addMarkerToMap(latlng, html);
				map.addOverlay(marker);
			} // end of if lat and lng
		} // end of for loop
	} //if
} //function
request.send(null);
}

function HideRightBar()
{
	Element.addClassName('body', 'rightbar-off');
}	
function ShowRightBar()
{
	Element.removeClassName('body', 'rightbar-off');
}
function makeAbsolute()
{
	 var adiv = document.createElement("div");
	 
	 adiv.style.position = "absolute";
	 adiv.style.top = "200px";
	 adiv.style.left = "150px";
	 adiv.style.zIndex = "9999999";
	 adiv.style.border = "medium double #C1CCB3";
	 adiv.style.width = "140px";
	 adiv.style.height = "30px";
	 adiv.style.backgroundColor = "#95A87B";
	 adiv.innerHTML = "Tires";
	 
	 var aspot = document.getElementById("leftBar");
	 aspot.appendChild(adiv);
	 
	 
	 
	 
}
	


	var myGlobalHandlers = {
		onCreate: function(){
			Element.show('systemWorking');
		},

		onComplete: function() {
			if(Ajax.activeRequestCount == 0){
				Element.hide('systemWorking');
			}
		}
	};

	Ajax.Responders.register(myGlobalHandlers);





window.onload = init;
window.onunload = GUnload;
