	var locations = [];
	var MAX_MYLOCATIONS = 5;
	var start=0;
	var numHits=10;
	var searchTxt="";
	var searchDay="";
	var jsonRes;
	var searches = [];

	var dayNames = [];
	dayNames[0]='Sunday';
	dayNames[1]='Monday';
	dayNames[2]='Tuesday';
	dayNames[3]='Wednesday';
	dayNames[4]='Thursday';
	dayNames[5]='Friday';
	dayNames[6]='Saturday';

	var monthAbbrs = [];
	monthAbbrs[0]='Jan';
	monthAbbrs[1]='Feb';
	monthAbbrs[2]='Mar';
	monthAbbrs[3]='Apr';
	monthAbbrs[4]='May';
	monthAbbrs[5]='Jun';
	monthAbbrs[6]='Jul';
	monthAbbrs[7]='Aug';
	monthAbbrs[8]='Sep';
	monthAbbrs[9]='Oct';
	monthAbbrs[10]='Nov';
	monthAbbrs[11]='Dec';

	function initMap(mapElemID) {
		setDiv(mapElemID,'Loading...',null,'block');
		map = createGoogleMap(mapElemID);
		google.maps.event.addListener(map, "rightclick",function(event){showContextMenu(event.latLng);});
	}

	function moveMap(srcID,destID,newClass) {
		setDiv(srcID,null,null,'none');
		setDiv(destID,null,null,'block');
		$("#mapdiv").prependTo("#"+destID);
		$("#mapdiv").attr('class', newClass);
		google.maps.event.trigger(map, "resize");
		setBoundsToMarkers(map);
	}


	function clickOnlyEvents(chk) {
		setCookie("mySearch_OnlyEvents",chk,30);
		if (chk) {
			setDiv("evSearchDetails",null,null,"block");
			searchDay=document.frmFilters.mnuDays.selectedIndex;
			if (searchDay>6) searchDay='';
		} else {
			setDiv("evSearchDetails",null,null,"none");
			searchDay='';
		}
	}

	function getNewSearch(txt) {
		searchTxt=txt;
		getResults(0);
	}

	function getResultsWithDatePicker() {
		if ($("#datepicker").datepicker("getDate")!=null) {
			getResults(0);
		} else {
			setTimeout(function() {getResultsWithDatePicker();},100);
		}
	}

	function getResults(start) {
		for (var i=searches.length-1;i>=0;i--) {
			ajaxQ.cancelRequest(searches[i],false);
		}
		var ftype="events";
		var onlyWithEvents=0;
		if (document.frmFilters.chkOnlyEvents.checked) onlyWithEvents=1;
		var dt=$("#datepicker").datepicker("getDate");
		if (dt==null) {
			dt=new Date();
		}
		var yr=dt.getFullYear();
		var mt=dt.getMonth()+1;
		var dd=dt.getDate();
		var path = rootpath + '/ajax/ajx_searchResults.php';
		var qstring='formtype='+encodeURIComponent(ftype)+'&Lat='+encodeURIComponent(currPosLat)+'&Lng='+encodeURIComponent(currPosLng)+'&keywords='+encodeURIComponent(searchTxt)+'&startNum='+encodeURIComponent(start)+'&numHits='+encodeURIComponent(numHits)+'&Day='+encodeURIComponent(searchDay)+'&Year='+encodeURIComponent(yr)+'&Month='+encodeURIComponent(mt)+'&Date='+encodeURIComponent(dd)+'&hasEvents='+encodeURIComponent(onlyWithEvents);
		ajaxQ.setResultsElem('outputelem','searchResults');
		ajaxQ.setResultsFunction('callfunction',"processResults(ajaxResponseText,'"+ftype+"');",'json');
		ajaxQ.setLoadOb('searchResults','<img src="images/loading.gif">','overwrite');
		setDiv('pagination_bottom','');
		var searchIdx = ajaxQ.addRequest('get',path,qstring);
		searches[searches.length]=searchIdx;
	}
	
	function processResults(json,formType) {
		jsonRes=json;
		printResults();
		scroll(0,0);
		for (var i=0;i<searches.length;i++) {
			if (searches[i]==jsonRes['ajaxQindex']) {
				searches.splice(i,1);
				break;
			}
		}
	}

	function printResults() {
		removeAllMarkersFromMap();
		var bounds = new google.maps.LatLngBounds();
		var output="";
		var dayOutputs = [];
		var stars = [];
		var ratings = [];
		for (var i=0;i<7;i++) {dayOutputs[i]="";}

		if(jsonRes['set']['num']>0) {
			var hsID=-1;
			var hsCount=1;
			var dayIdxMin=0;
			var dayIdxMax=6;
			if (searchDay!="") {
				dayIdxMin=searchDay;
				dayIdxMax=searchDay;
				dayIdx=searchDay;
			}

			for (var i=0;i<jsonRes['set']['num'];i++) {
				var ev=jsonRes['results'][i];
				if (ev['ID']!=hsID) {
					if (hsID!=-1) {
						var daysOP=getDaysOutputFromArray(dayOutputs,hsID);
						if (daysOP=="") { daysOP='<span class="emptyResults">No events or specials have been posted for this hot spot.</span>';	}
						output+=daysOP + '<div style="clear: left; padding-left: 22px;">'+
							'</div></div>';
						for (var j=0;j<7;j++) {
							dayOutputs[j]="";
						}
					}
					var marker='blue'+hsCount;
					bounds=addPointToMap(map,ev,bounds,marker);
					output+= addHsToList(ev,hsCount);
					//setDiv('searchResults','<ul>','append');
					hsID=ev['ID'];
					hsCount++;
				}
				stars[stars.length]=ev['evID'];
				ratings[ratings.length]=ev['Rating'];
				if (ev['Frequency']=='weekly') {
					var days=ev['DaysInt'];
					var dayIdx=1;
					if ((searchDay+"")!="") {
						dayIdx=1<<searchDay;
						dayIdxMin=searchDay;
						dayIdxMax=searchDay;
					}
					var rtCnt=0;
					if (ev['ratingCount']!="") rtCnt=ev['ratingCount'];

					for (var j=dayIdxMin;j<=dayIdxMax;j++) {
						if (days==0) break;
						if (days & dayIdx) { 
							dayOutputs[j]+= getEventText(ev['evID'],ev['Title'],rtCnt,j);
							days=days & ~dayIdx;
						}
						dayIdx = dayIdx<<1;
					}
				} else if (ev['Frequency']=='once' && ((searchDay+"")=="" || searchDay==ev['dayNum'])) {
					var rtCnt=0;
					if (ev['ratingCount']!="") rtCnt=ev['ratingCount'];
					dayOutputs[ev['dayNum']]+= getEventText(ev['evID'],ev['Title'],rtCnt,ev['dayNum']);
				}
			}

			output+=getDaysOutputFromArray(dayOutputs,hsID);

			setDiv('searchResults',output+'<div style="clear: left;"></div></div>');
			for (var i=0;i<stars.length;i++) {
				var rtg=0;
				if (ratings[i]!="") rtg=ratings[i];
				$("div[id^=rating_"+stars[i]+"_]").each(function(index) {
					$(this).rating('ajax/ajax_rating.php', {maxvalue:5, curvalue:rtg, id:stars[i], cancel:false, ajax_callback: callback_eventRating });
				});
			}

			var currPos=[];
			currPos['CLt']=currPosLat;
			currPos['CLn']=currPosLng;
			currPos['Name']=currPosText;
			bounds=addPointToMap(map,currPos,bounds,'red');
			setBoundsToMarkers(map);

			var pagText=js_setPagination(jsonRes['set']['start'],jsonRes['set']['total'],jsonRes['set']['max']);
			setDiv('pagination_bottom',pagText);

		} else {
//			setDiv('searchResults','<h4>No Hot Spots were found for your search.  Please try another search.</h4><br />'+jsonRes['sql']);
			setDiv('searchResults','<h4>No Hot Spots were found for your search.  Please try another search.</h4><br />');
		}
	}

	function callback_eventRating(data) {
		var jsonData=eval('('+data+')');
		if (jsonData['results']!='undefined') {
			if (jsonData['result']=='success') {
			}
		}
	}

	function getDaysOutputFromArray(dayOutputs,hsID) {
		var output="";

		var dt=$("#datepicker").datepicker("getDate");
		var wkday=dt.getDay();
		var yr=dt.getFullYear();
		var mt=dt.getMonth();
		var dd=dt.getDate();
		for (var i=wkday;i<7;i++) {
			if (dayOutputs[i]!="") {
				var newdt=new Date(yr,mt,dd+(i-wkday),0,0,0,0);
				output+='<ul class="eventList '+dayNames[i]+'List" id="hsres_'+hsID+'_ev_'+i+'"><h1>'+dayNames[i]+", "+monthAbbrs[newdt.getMonth()]+" " +newdt.getDate()+'</h1>'+dayOutputs[i]+'</ul>';
			}
		}
		for (var i=0;i<wkday;i++) {
			if (dayOutputs[i]!="") {
				var newdt=new Date(yr,mt,dd+(7-wkday)+i,0,0,0,0);
				output+='<ul class="eventList '+dayNames[i]+'List" id="hsres_'+hsID+'_ev_'+i+'"><h1>'+dayNames[i]+", "+monthAbbrs[newdt.getMonth()]+" " +newdt.getDate()+'</h1>'+dayOutputs[i]+'</ul>';
			}
		}



		return output;
	}

	function addHsToList(hs,idx) {
		var dist=parseFloat(hs['Distance']);
		var img='images/logoFaded.gif';
		if (hs['Image']!='' && hs['Image']!=null) img='hotspots/pics/'+hs['ID']+'/thumbs/'+hs['Image'];
		var specials='';
	
		var hsTxt = '<div class="container" id="hsres_'+hs['ID']+'">'+
				'<div class="hsInfoContainer">'+
					'<div class="hsInfo" id="hsInfo_'+hs['ID']+'">'+
						'<img src="images/map/blue'+(idx)+'.png" class="pin">'+
						'<img src="'+img+'" class="hsMain" />'+
						hs['Name']+
						//'<a href="hotspot.php?id='+hs['ID']+'" target="BM_hsProfile" onMouseOut="removeCircleFromMap(gMapCircle);" onMouseover="bringFrontMarker('+idx+');addCircleToMap(map, 75, '+hs['CLt']+', '+hs['CLn']+');">'+hs['Name']+'</a>'+
						'<div class="address">'+hs['StreetAddress']+' '+hs['City']+', '+hs['State']+'</div>'+
						'<div class="miles">'+(dist).toFixed(2)+' miles</div>'+
					'</div>'+
					'<a href="javascript: void(0)" onClick="addEventToHS('+hs['ID']+",'"+escape(hs['Name'])+"'"+');" class="eventFlag">'+
						'<img src="images/plus.png" alt="Add an event/special to '+hs['Name']+'" title="Add an event/special to '+hs['Name']+'" />Add Event/Special'+
					'</a>' + 
					'<a href="javascript: void(0)" onClick="addCommentToHS('+hs['ID']+",'"+escape(hs['Name'])+"'"+');" class="eventFlag">'+
						'<img src="images/comment.png" alt="Comment/Review '+hs['Name']+'" title="Comment/Review '+hs['Name']+'" />Post Review/Comment'+
					'</a>' +
					'<a href="javascript: void(0)" onClick="addFlagToHS('+hs['ID']+",'"+escape(hs['Name'])+"'"+');" class="eventFlag">'+
						'<img src="images/flag.png" alt="Flag '+hs['Name']+' (inaccurate, no longer open, etc.)" title="Flag this hot spot (inaccurate, no longer open, etc.)" />Flag/Report'+
					'</a>'+
				'</div>';
		//setDiv('searchResults',hsTxt,'append');
		return hsTxt;
	}

	function navResults(pageNum) {
		ajaxQ.cancelAll();
		//var addy=window.location;
		//window.location = addy + "#" + pageNum;
		start=pageNum;
		getResults(pageNum);
	}

	function js_setPagination(start,total,numHits) {
		var txt='';
		var extraPages=0;
		var numPages=15;
		var numPagesRemaining=numPages;
		var currPage=Math.floor(start/numHits+1);
		var numPrev=Math.floor((numPages-1)/2);
		var maxPrev=Math.floor(start/numHits);
		var maxNext=Math.floor((total-start-1)/numHits);
		if (numPrev>maxPrev) {
			extraPages=numPrev-maxPrev;
			numPrev=maxPrev;
		}
	
		numNext=numPages-numPrev-1;
		if (numNext>maxNext) {
			extraPages=numNext-maxNext;
			numNext=maxNext;
			if (numPrev<maxPrev) {
				if ((numPrev+extraPages)>=maxPrev) numPrev=maxPrev;
				else numPrev=numPrev+extraPages;
			}
		}
	
		var prevTxt='';
		//check to see whether or not to add a first page button because this after page 2 of the results
		if (numPrev>1) {
			prevTxt+='<li><a href="javascript: navResults(0);"><img src="images/firstRes.gif" alt="First Page of Results" class="sr_prevnextimg"></a></li>';
			numPagesRemaining--;
		}
		//check to see whether or not to add a previous button because this is not page 1 of the results
		if (numPrev>0) {
			prevTxt+='<li><a href="javascript: navResults('+(start-numHits)+');"><img src="images/prev.gif" alt="Previous Page of Results" class="sr_prevnextimg"></a></li>';
			numPagesRemaining--;
		}
	
		var nextTxt='';
		//check to see whether or not to add a next button because there are more results than what are displayed
		if (numNext>0) {
			nextTxt+='<li><a href="javascript: navResults('+(parseFloat(start)+parseFloat(numHits))+');"><img src="images/next.gif" alt="Next Page of Results" class="sr_prevnextimg"></a></li>';
			numPagesRemaining--;
		}
		//check to see whether or not to add a last page button because there is more than 1 page beyond this one
		if (numNext>1) {
			nextTxt+='<li><a href="javascript: navResults('+(Math.floor((total-1)/numHits))*numHits+');"><img src="images/lastRes.gif" alt="Last Page of Results" class="sr_prevnextimg"></a></li>';
			numPagesRemaining--;
		}
	
	/*	numPagesRemaining=numPages-numPagesRemaining;
		while(numPagesRemaining>2) {
			numPrev--;
			numNext--;
			numPagesRemaining=numPagesRemaining-2;
		}
		if (numPagesRemaining>0) {
			if (numNext>numPrev) numNext--;
			else numPrev--;
		}
		var i=0;
		while (numPrev<2 && currPage-i>1) {
			numPrev++;
			numNext--
			i++;
		}
	*/
	//	if (numPrev<2 && currPage<=2) {
	//		numPrev=2;
	//		numNext=numNext-2;
	//	}
	
		if (numPrev>0 || numNext>0) {
			txt=prevTxt;
			//put up the pagination numbers
			for (var k=numPrev;k>0;k--) {	//first the previous pages
				txt+='<li><a href="javascript: navResults('+(10*(currPage-k-1))+');" class="sr_pagNumLink">'+(currPage-k)+'</a></li>';
			}
			txt+= '<li class="sr_currPage">'+currPage+'</li>';				//then the current page
			for (var k=1;k<=numNext;k++) {	//then the next pages
				txt+='<li><a href="javascript: navResults('+(10*(currPage+k-1))+');" class="sr_pagNumLink">'+(currPage+k)+'</a></li>';
			}
			txt+=nextTxt;
		}
		if (txt!='') txt='<ul class="sr_pagList">'+txt+'</ul>';
	return txt;
	}

	function fillDate() {
		var searchDate=getCookie("mySearchDate");
		searchDay=getCookie("mySearchDay");
		if (searchDate==undefined) {
			var d = new Date();
			searchDate=d;
		}
		$('#datepicker').datepicker('setDate',searchDate);
		$('#ev_datepicker').datepicker('setDate',searchDate);

		if (searchDay==undefined) {
			var dd = new Date();
			searchDay=dd.getDay();
		}
		if (searchDay!="") {
			document.frmFilters.mnuDays.selectedIndex=searchDay
		} else {
			document.frmFilters.mnuDays.selectedIndex=7;
		}
	}

	function setDateCookie(searchDate) {
		if (searchDate!="") {
			setCookie("mySearchDate",searchDate,1);
			for (var i=0;i<7;i++) {
				if (searchDate.match(dayNames[i])) {
					document.frmFilters.mnuDays.selectedIndex=i;
					changeWeekday(i);
					break;
				}
			}
		}
	}
	function setDayCookie(searchDayIdx) {
		setCookie("mySearchDay",searchDayIdx,1);
	}

	function changeWeekday(dayIdx) {
		if (dayIdx>6 || !document.frmFilters.chkOnlyEvents.checked) dayIdx='';
		searchDay=dayIdx;
		setDayCookie(searchDay);
		getResults(0);
	}

	function addEventToHS(id,subjectName) {
		clearRadioGroup(document.frmEv.radEvFreq);
		clearRadioGroup(document.frmEv.chkDays);
		document.frmEv.evTitle.value="";
		setDiv("evCharLeft","");
		setDiv("evFreq2_once",null,null,"none");
		setDiv("evFreq2_weekly",null,null,"none");
		$('#evFormBox').dialog('option', 'title',"Add an Event or Special @ "+unescape(subjectName));
		document.frmEv.hsID.value=id;
		$('#evFormBox').fadeIn("slow").dialog('open');
	}

	function addCommentDlg(type,id,subjectName) {
		setDiv('commForm_subjectName',unescape(subjectName));
		document.frmComment.txtComments.value="";
		document.frmComment.commType.value=type;
		document.frmComment.subjectID.value=id;
		document.frmComment.commRatingVal.value="";
		setDiv("commRating","");
		$('#commentFormBox').fadeIn("slow").dialog('open');
		$("#commRating").rating('ajax/ajax_null.php', {maxvalue:5, curvalue:0, id:id, cancel:false, pre_callback: setCommRating, oneShot: false });
	}

	function addCommentToEvent(eventid,subjectName) {
		addCommentDlg('event',eventid,subjectName);
	}

	function addCommentToHS(hsid,subjectName) {
		addCommentDlg('hotspot',hsid,subjectName);
	}

	function setCommRating(val) {
		document.frmComment.commRatingVal.value=val;
	}


	function addFlagDlg(id,subjectName) {
		clearRadioGroup(document.frmFlag.radFlag);
		document.frmFlag.txtComments.value="";
		document.frmFlag.subjectID.value=id;
		setDiv("flag_subjectName",unescape(subjectName));
		$('#flagFormBox').fadeIn("slow").dialog('open');
	}

	function addFlagToHS(id,subjectName) {
		document.frmFlag.commType.value="hotspot";
		setDiv("flag_nonexistent",null,null,"block");
		addFlagDlg(id,subjectName);
	}

	function addFlagToEvent(id,subjectName) {
		document.frmFlag.commType.value="event";
		setDiv("flag_nonexistent",null,null,"none");
		addFlagDlg(id,subjectName);
	}

	function saveFlag(type,id,comm,radFlag) {
		var flag=getRadioVal(radFlag);
		var path = rootpath + '/ajax/ajax_flag.php';
		var qstring='type='+encodeURIComponent(type)+'&id='+encodeURIComponent(id)+'&comm='+encodeURIComponent(comm)+'&flag='+encodeURIComponent(flag);
		ajaxQ.setResultsFunction('callfunction',"processSaveFlag(ajaxResponseText);",'json');
		ajaxQ.setLoadOb('flagFormResults','<img src="images/wait.gif">','overwrite');
		ajaxQ.addRequest('post',path,qstring);
	}

	function processSaveFlag(json) {
		if (json['result']=='success') {
			setDiv("flagFormResults","Thank you for helping us keep BeerMagnet clean and accurate!");
			setTimeout(function() {
				$('#flagFormBox').fadeOut('slow').dialog('close');
				setDiv("flagFormResults",""); },2000);
		} else {
			setDiv("flagFormResults","An error occurred and the report could not be sent.  Please try again.");
			if (json['msg']!='undefined' && json['msg']!=undefined) {
				setDiv("flagFormResults",'<br /><br />'+json['msg'],'append');
			}
		}
				
	}
	function saveComment(type,id,comm,rating) {
		var path = rootpath + '/ajax/ajax_rating.php';
		var qstring='type='+encodeURIComponent(type)+'&id='+encodeURIComponent(id)+'&comm='+encodeURIComponent(comm)+'&rating='+encodeURIComponent(rating);
		ajaxQ.setResultsFunction('callfunction',"processSaveComments(ajaxResponseText);",'json');
		ajaxQ.setLoadOb('commFormResults','<img src="images/wait.gif">','overwrite');
		ajaxQ.addRequest('post',path,qstring);
	}

	function processSaveComments(json) {
		if (json['result']=='success') {
			setDiv("commFormResults","Thank you for your review!");
			setTimeout(function() {
				$('#commentFormBox').fadeOut('slow').dialog('close');
				setDiv("commFormResults",""); },1500);
		} else {
			setDiv("commFormResults","An error occurred and the review could not be sent.  Please try again.");
			if (json['msg']!='undefined' && json['msg']!=undefined) {
				setDiv("commFormResults",'<br /><br />'+json['msg'],'append');
			}
		}
				
	}

	function freqChange(showDiv) {
		setDiv('evFreq2_weekly',null,null,'none');
		setDiv('evFreq2_once',null,null,'none');
		setDiv(showDiv,null,null,'block');
	}

	function saveEvent(frm) {
		var errMsg="";
		var dayVal=0;
		var freq=getRadioVal(frm.radEvFreq);
		var id=frm.hsID.value;
		var title=frm.evTitle.value.trim();
		var reasonCount=1;
		
		if (id=="" || id=="undefined" || id=="NaN") {
			errMsg+=reasonCount+". A valid hot spot was not selected.\n";
			reasonCount++;
		}
		if (title=="" || title=="undefined") {
			errMsg+=reasonCount+". The description (\""+title+"\") is not valid.\n";
			reasonCount++;
		}

		if (freq=='weekly') {
			for(var i=0; i < frm.chkDays.length; i++) if(frm.chkDays[i].checked) dayVal+= parseInt(frm.chkDays[i].value);
			if (dayVal<=0) {
				errMsg+=reasonCount+". The weekday(s) when this event/special takes place were not specified.\n";
				reasonCount++;
			}
		} else if (freq=='once') {
			var dt=$("#ev_datepicker").datepicker("getDate");
			if (dt!="") {
				dayVal=dt.getFullYear()+'-'+(dt.getMonth()+1)+'-'+dt.getDate();
			} else {
				errMsg+=reasonCount+". The date when this event/special takes place was not specified.\n";
				reasonCount++;
			}
		} else {
			errMsg+=reasonCount+". Whether this event/special is a one time occasion or a weekly occurance was not specified.\n";
			reasonCount++;
		}

		if (errMsg!="") { alert("The event/special could not be saved for the following reason(s):\n\n"+errMsg); }
		else {
			var path = rootpath + '/ajax/ajax_events.php';
			var qstring='type=saveNewEvent&id='+encodeURIComponent(id)+'&title='+encodeURIComponent(title)+'&freq='+encodeURIComponent(freq)+'&dayVal='+encodeURIComponent(dayVal);
			ajaxQ.setResultsFunction('callfunction',"processSaveEvent(ajaxResponseText);",'json');
			ajaxQ.setLoadOb('evFormResults','<img src="images/wait.gif">','overwrite');
			ajaxQ.addRequest('post',path,qstring);
		}
	}

	function shouldAddEventToPage(freq,when) {
		if (freq=='once') {
			var dateComps=when.split('-');
			var dayOne=$("#datepicker").datepicker("getDate");
			var dayEight=new Date(dayOne.getFullYear(), dayOne.getMonth(), dayOne.getDate() + 7,0,0,0,0);
			var evDate=new Date(dateComps[0],dateComps[1]-1,dateComps[2],0,0,0,0);
			if (evDate>=dayOne && evDate<dayEight) { 
				if (searchDay=='') { return true; }
				if (searchDay==evDate.getDay()) { return true; }
			}
		} else if (freq=='weekly') {
			if (searchDay=='') { return true; }
			if (when & Math.pow(2,searchDay)) { return true; }
		}

		return false;
	}

	function getEventText(evID,title,ratingCount,divSuffix) {
		return '<li class="event">'+
				'<div id="rating_'+evID+'_'+divSuffix+'" class="rating"></div>'+
				'<div class="ratingCountDiv">('+ratingCount+')</div>'+
				'<a href="javascript: void(0)" onClick="addFlagToEvent('+evID+",'"+title+"'"+');" class="eventFlag">'+
					'<img src="images/flag.png" alt="Flag this event/special (inaccurate, no longer offered, etc.)" title="Flag this event/special (inaccurate, no longer offered, etc.)" />'+
				'</a>'+
				'<a href="javascript: void(0)" onClick="addCommentToEvent('+evID+",'"+title+"'"+');" class="eventFlag">'+
					'<img src="images/comment.png" alt="Comment/Review this event/special" title="Comment/Review this event/special" />'+
				'</a>' +
				title+
				'</li>';
	}

	function addEventToHSres(hsID,evID,title,freq,when,rating,ratingCount) {
		var blnAdded=false;
		if (searchDay!="") {
			$("ul[id^=hsres_"+hsID+"_ev_]").each(function(index) {
				$(this).append(getEventText(evID,title,ratingCount,searchDay));
			});
			blnAdded=true;
		} else {
			for (var i=0;i<7;i++) {
				if (when & Math.pow(2,i)) {
					if ($("ul#hsres_"+hsID+"_ev_"+i).length==0) {  //if the UL does not exist, need to add the UL and THEN append this getEventText
						var found=false;
						for (var j=i-1;j>=0;j--) {
							if ($("ul#hsres_"+hsID+"_ev_"+j).length!=0) {
								$('<ul id="hsres_'+hsID+'_ev_'+i+'" class="eventList '+dayNames[i]+'List"><h1>'+dayNames[i]+'</h1></ul>').insertAfter($("ul#hsres_"+hsID+"_ev_"+j));
								found=true;
								break;
							}
						}
						if (!found) {
							for (var j=i+1;j<6;j++) {
								if ($("ul#hsres_"+hsID+"_ev_"+j).length!=0) {
									$('<ul id="hsres_'+hsID+'_ev_'+i+'" class="eventList '+dayNames[i]+'List"><h1>'+dayNames[i]+'</h1></ul>').insertBefore($("ul#hsres_"+hsID+"_ev_"+j));
									found=true;
									break;
								}
							}
						}
						if (!found) {
							$('<ul id="hsres_'+hsID+'_ev_'+i+'" class="eventList '+dayNames[i]+'List"><h1>'+dayNames[i]+'</h1></ul>').insertAfter($("#hsInfo_"+hsID));
						}
					}

					$("ul#hsres_"+hsID+"_ev_"+i).each(function(index) {
						$(this).append(getEventText(evID,title,ratingCount,searchDay));
						found=true;
					});
				}
			}
			blnAdded=true;
		}

		if (blnAdded) {
			$("div[id^=rating_"+evID+"_]").each(function(index) {
				$(this).rating('ajax/ajax_rating.php', {maxvalue:5, curvalue:rating, id:evID, cancel:false, ajax_callback: callback_eventRating });
			});
		}
	}

	function processSaveEvent(json) {
		if (json['result']=='success') {
			setDiv("evFormResults","Thank you for helping us keep BeerMagnet fans in the know!");
			setTimeout(function() {
				$('#evFormBox').fadeOut('slow').dialog('close');
				setDiv("evFormResults",""); },2000);
			if (shouldAddEventToPage(json['frequency'],json['when'])) {
				addEventToHSres(json['hsID'],json['evID'],json['title'],json['frequency'],json['when'],0,0);
			}
		} else {
			setDiv("evFormResults","An error occurred and the event/special could not be saved.  Please try again.");
			if (json['msg']!='undefined' && json['msg']!=undefined) {
				setDiv("evFormResults",'<br /><br />'+json['msg'],'append');
			}
		}
				
	}

	function restoreSearchPrefs() {
		fillDate();
		var chkEventsOnly=getCookie("mySearch_OnlyEvents");
		var blnChk=false;
		(chkEventsOnly=='true'? blnChk=true : blnChk=false);
		document.frmFilters.chkOnlyEvents.checked=blnChk;
		clickOnlyEvents(blnChk);
	}


