var map;
var centerLatitude = 37.09024;
var centerLongitude = -95.712891; 
var startZoom = 3;
var markerHash={};
var currentFocus=false;

var gmarkers = [];
var gmarkers_id = [];
var location_names = [];
var htmls = [];
var j = 0;

var mc = 0;
var n24 = 0;
var lc = 0;
var rp = 0;
var up = 0;

	
	var rest;
	var store;
	var pharmacy;
	var food;
	var cafe;
	var grocery;
	var hosp;
	var animal;
	var activity;
	var casino;
	var bar;
	var service;
	var other;
	var drive;
	
	     var lat_x = 37.09024;
         var lng_x = -95.712891;
		 

   var iconRest = new GIcon(); 
    iconRest.image = '/images/icons/restaurant.gif';
    iconRest.shadow = '/images/icons/restaurant_shadow.png';
    iconRest.iconSize = new GSize(32, 32);
    iconRest.shadowSize = new GSize(56, 32);
    iconRest.iconAnchor = new GPoint(16, 32);
    iconRest.infoWindowAnchor = new GPoint(16, 0);

    var iconStore = new GIcon(); 
    iconStore.image = '/images/icons/convienancestore.gif';
    iconStore.shadow = '/images/icons/convienancestore_shadow.png';
    iconStore.iconSize = new GSize(32, 32);
    iconStore.shadowSize = new GSize(65, 32);
    iconStore.iconAnchor = new GPoint(16, 32);
    iconStore.infoWindowAnchor = new GPoint(16, 0);
	
	var iconPharm = new GIcon(); 
    iconPharm.image = '/images/icons/pharmacy-us.gif';
    iconPharm.shadow = '/images/icons/pharmacy-us_shadow.png';
    iconPharm.iconSize = new GSize(32, 32);
    iconPharm.shadowSize = new GSize(65, 32);
    iconPharm.iconAnchor = new GPoint(16, 32);
    iconPharm.infoWindowAnchor = new GPoint(16, 0);
	
	var iconFood = new GIcon(); 
    iconFood.image = '/images/icons/gas.gif';
    iconFood.shadow = '/images/icons/gas_shadow.png';
    iconFood.iconSize = new GSize(32, 32);
    iconFood.shadowSize = new GSize(65, 32);
    iconFood.iconAnchor = new GPoint(16, 32);
    iconFood.infoWindowAnchor = new GPoint(16, 0);
	
		
	var iconCafe = new GIcon(); 
    iconCafe.image = '/images/icons/icon62.gif';
    iconCafe.shadow = '';
    iconCafe.iconSize = new GSize(32, 32);
    iconCafe.shadowSize = new GSize(65, 32);
    iconCafe.iconAnchor = new GPoint(16, 32);
    iconCafe.infoWindowAnchor = new GPoint(16, 0);
	
	var iconGroc = new GIcon(); 
    iconGroc.image = '/images/icons/grocerystore.gif';
    iconGroc.shadow = '/images/icons/grocerystore_shadow.png';
    iconGroc.iconSize = new GSize(32, 32);
    iconGroc.shadowSize = new GSize(65, 32);
    iconGroc.iconAnchor = new GPoint(16, 32);
    iconGroc.infoWindowAnchor = new GPoint(16, 0);
	
	
	var iconHospital = new GIcon(); 
    iconHospital.image = '/images/icons/hospitals.gif';
    iconHospital.shadow = '/images/icons/hospitals_shadow.png';
    iconHospital.iconSize = new GSize(32, 32);
    iconHospital.shadowSize = new GSize(65, 32);
    iconHospital.iconAnchor = new GPoint(16, 32);
    iconHospital.infoWindowAnchor = new GPoint(16, 0);	
	
	
	var iconAnimal = new GIcon(); 
    iconAnimal.image = '/images/icons/horsebackriding.gif';
    iconAnimal.shadow = '/images/icons/horsebackriding_shadow.png';
    iconAnimal.iconSize = new GSize(32, 32);
    iconAnimal.shadowSize = new GSize(65, 32);
    iconAnimal.iconAnchor = new GPoint(16, 32);
    iconAnimal.infoWindowAnchor = new GPoint(16, 0);
	

	var iconActivity = new GIcon(); 
    iconActivity.image = '/images/icons/sportvenue.gif';
    iconActivity.shadow = '/images/icons/sportvenue_shadow.png';
    iconActivity.iconSize = new GSize(32, 32);
    iconActivity.shadowSize = new GSize(65, 32);
    iconActivity.iconAnchor = new GPoint(16, 32);
    iconActivity.infoWindowAnchor = new GPoint(16, 0);	
	
	
	var iconCasino = new GIcon(); 
    iconCasino.image = '/images/icons/dollar.gif';
    iconCasino.shadow = '/images/icons/dollar_shadow.png';
    iconCasino.iconSize = new GSize(32, 32);
    iconCasino.shadowSize = new GSize(65, 32);
    iconCasino.iconAnchor = new GPoint(16, 32);
    iconCasino.infoWindowAnchor = new GPoint(16, 0);
	
	var iconBar = new GIcon(); 
    iconBar.image = '/images/icons/bar.gif';
    iconBar.shadow = '/images/icons/bar_shadow.png';
    iconBar.iconSize = new GSize(32, 32);
    iconBar.shadowSize = new GSize(65, 32);
    iconBar.iconAnchor = new GPoint(16, 32);
    iconBar.infoWindowAnchor = new GPoint(16, 0);
	
	var iconService = new GIcon(); 
    iconService.image = '/images/icons/man.gif';
    iconService.shadow = '/images/icons/man_shadow.png';
    iconService.iconSize = new GSize(32, 32);
    iconService.shadowSize = new GSize(65, 32);
    iconService.iconAnchor = new GPoint(18, 32);
    iconService.infoWindowAnchor = new GPoint(16, 0);
	

		
	var iconOther = new GIcon(); 
    iconOther.image = '/images/icons/mm_20_red.gif';
    iconOther.shadow = '/images/icons/mm_20_shadow.png';
    iconOther.iconSize = new GSize(12, 20);
    iconOther.shadowSize = new GSize(22, 20);
    iconOther.iconAnchor = new GPoint(6, 20);
    iconOther.infoWindowAnchor = new GPoint(5, 1);
	
	    var iconSearch = new GIcon(); 
    iconSearch.image = '/images/icons/grn-pushpin.gif';
    iconSearch.shadow = '';
    iconSearch.iconSize = new GSize(32, 32);
    iconSearch.shadowSize = new GSize(65, 32);
    iconSearch.iconAnchor = new GPoint(16, 32);
    iconSearch.infoWindowAnchor = new GPoint(16, 0);

	var iconDrive = new GIcon(); 
    iconDrive.image = '/images/icons/drivethru.gif';
    iconDrive.shadow = '';
    iconDrive.iconSize = new GSize(32, 32);
    iconDrive.shadowSize = new GSize(56, 32);
    iconDrive.iconAnchor = new GPoint(16, 32);
    iconDrive.infoWindowAnchor = new GPoint(16, 0);


    var customIcons = [];
	customIcons[1] = iconOther;
    customIcons[2] = iconRest;
    customIcons[3] = iconStore;
	customIcons[4] = iconPharm;
	customIcons[5] = iconFood;
    customIcons[6] = iconCafe;
	customIcons[7] = iconGroc;
	customIcons[8] = iconHospital;
	customIcons[9] = iconAnimal;
	customIcons[10] = iconActivity;
	customIcons[11] = iconCasino;
	customIcons[12] = iconBar;
	customIcons[13] = iconService;	
	customIcons[14] = iconOther;
	customIcons[15] = iconDrive;

	var markerGroups = { "1": [], "2": [], "3": [], "4": [], "5": [], "6": [], "7": [], "8": [], "9": [], "10": [], "11": [], "12": [], "13": [], "14": [], "15": []};
	
	var catArray = ['Blank', 'PleaseSelect', 'Restaurant', 'Store', 'Pharmacy', 'Food & Fuel', 'Cafe & Delis', 'Grocery Store', 'Hospital & Clinics', 'Animal Care', 'Activity', 'Casino', 'Bar & Club', 'Service', 'Other', 'Drive-Thru'];


	function checkUncheckAll(theElement) {
     var theForm = theElement.form, z = 0;
	 for(z=0; z<theForm.length;z++){
      if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
	  theForm[z].checked = theElement.checked;
	  }
     }
    }
	
	//Clearing Comment Section//
	function clearcomment() {
	document.getElementById("comments_here").innerHTML = "";
	//document.getElementById("welcome").innerHTML = "";//Comments//
	document.getElementById("body2commentbox").innerHTML = "";  //Comment Button//

	}

	var gmarkers = [];
	var gmarkers_id = [];
	var location_names = [];
    var htmls = [];
    var j = 0;



///////////////////////INIT///////////////////////////
function init() {

	map = new GMap2(document.getElementById("map"));
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(centerLatitude, centerLongitude), startZoom);
	geocoder = new GClientGeocoder();
	map.disableScrollWheelZoom();
	map.disableDoubleClickZoom();
	var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,20));
	var mapTypeControl = new GMapTypeControl();
	map.addControl(mapTypeControl, topRight);
	var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
    //pass in an initial point for the center
    //listout();
	//updateMarkers(new GLatLng(centerLatitude, centerLongitude));

	jsClock(); //CLOCK
	containerHeight = new fx.Height('toolsdiv', {duration: 400}); //Menu Drop
	containerHeight.hide();	
	GEvent.addListener(map,'dblclick',function(overlay,point) {
	updateMarkers(point);
	});	

	}

///////////////////////INIT///////////////////////////
function initGet(lat,lng,name,cat_num,submitter,address,city,state,zip,phone,website,notes,currentid) {
	//	var current = "<strong>" + 	name;
	
	map = new GMap2(document.getElementById("map"));
	map.clearOverlays();
	map.addControl(new GSmallMapControl());
	map.setCenter(new GLatLng(lat,lng), 14);
	geocoder = new GClientGeocoder();
	map.disableScrollWheelZoom();
	map.disableDoubleClickZoom();
	var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,20));
	var mapTypeControl = new GMapTypeControl();
	map.addControl(mapTypeControl, topRight);
	var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
    //pass in an initial point for the center
    //listout();
	
	
	var currentLink = "www.2itch.com/map/" + currentid;
	
	var full_map_address ="<small><a href='http://maps.google.com/maps?saddr="+
	address+"+"+
	city+"+"+
	state+
	"+"+
	zip+
	"&ie=UTF8&z=17&iwloc=addr' target='_blank'>Get Directions</a><br><a id='redLink' href='http://" + currentLink +"' target='_blank'>" + currentLink + "&nbsp;&nbsp;&nbsp;</a></small>";
	
	

	
	
	
var current = "<strong>" + 
					name +
					"</strong><br/><small><u>" +
					catArray[cat_num] +
					"</u></small><small> | Submitted by:" + submitter + "</small><br/>"+ 
					address +
					"<br/>" + city +
					", " +
					state +
					" "+
					zip +
					"<br/>ph: " +
					phone +
					"<br/><a href='http://" +
					website +
					"' target='_blank'>" +
					website + "</a><br/>" +
					full_map_address + "<br><table width='200' border='0'><tr><td>" + notes + "</td></tr></table>";

	//currentcomment(currentid);
	var point = new GLatLng(lat,lng);
	//var marker = new GMarker(point);
	var marker = new GMarker(point,{icon: customIcons[cat_num]});
	map.addOverlay(marker);
	updateMarkers(point);
	marker.openInfoWindowHtml(current); 
	commentingCurrent(currentid,name);
	
	containerHeight = new fx.Height('toolsdiv', {duration: 400}); //Menu Drop
	containerHeight.hide();
	GEvent.addListener(map,'dblclick',function(overlay,point) {
	updateMarkers(point);
	});	
	}


	function commentingCurrent(currentid,location_name) {
		 var commentformHTML = "<span class='totallocations'>" + location_name + "</span> &nbsp;&nbsp; <INPUT  TYPE='button' VALUE='Add Comment' NAME=button1 onclick=javascript:ReverseDisplay('commentbox')>";
		document.getElementById("body2commentbox").innerHTML = commentformHTML;
		
		push_id (currentid);
		
		
		  document.getElementById("comments_here").innerHTML = "<img title='Loading...' src='/images/ajax-loader.gif'>";
		  clear_counter();
		  marker_id = currentid;
		  var url2 = '/location/get_comments?num='+marker_id;
		  var request = GXmlHttp.create();
		  request.open('GET', url2, true);

       request.onreadystatechange = function() {
		   if (request.readyState == 4) {
	     var data = request.responseText;
    	 //GLog.writeUrl(data);
         var comments = eval('('+data+')');
		
		counter (0);

		document.getElementById("comments_here").innerHTML = "";
		//document.getElementById("welcome").innerHTML = "";
		for (var i=0; i < comments.length; i++) {
        
		var comment = "<span class='username'><strong>" + comments[i].user + "</strong></span > > <span id='comment_category'> " + comments[i].commentcategory + "</span> <br><span id='comment_created'>"+ comments[i].created_at + "</span><br>	<span id='comment_usercomment'>" + comments[i].usercomment + "</span>";
		
	var comment_type = comments[i].commentcategory;
	output_comment(comment);
	
	counter (comment_type);
				}
	   }}
	   request.send(null);
		  }
		  
		  
	
///////////////////////Current Marker Start ///////////////////////////
 
///////////////////////Current Marker END ///////////////////////////
///////////////////////Update Marker ///////////////////////////

function updateMarkers(point) {

	//HideContent("welcome"); ////////////////////HIDE WELCOME DIV


	if(document.myform.rest.checked == true)
		{ var rest = 2; }
	if(document.myform.rest.checked == false)
		{ var rest = 1; }
		
	if(document.myform.store.checked == true)
		{ var store = 3; }
	if(document.myform.store.checked == false)
		{ var store = 1; }
		
	if(document.myform.pharmacy.checked == true)
		{ var pharmacy = 4; }
	if(document.myform.pharmacy.checked == false)
		{ var pharmacy = 1; }
		
	if(document.myform.food.checked == true)
		{ var food = 5; }
	if(document.myform.food.checked == false)
		{ var food = 1; }
		
	if(document.myform.cafe.checked == true)
		{ var cafe = 6; }
	if(document.myform.cafe.checked == false)
		{ var cafe = 1; }
		
	if(document.myform.grocery.checked == true)
		{ var grocery = 7; }
	if(document.myform.grocery.checked == false)
		{ var grocery = 1; }
	
	if(document.myform.hosp.checked == true)
		{ var hosp = 8; }
	if(document.myform.hosp.checked == false)
		{ var hosp = 1; }
		
	if(document.myform.animal.checked == true)
		{ var animal = 9; }
	if(document.myform.animal.checked == false)
		{ var animal = 1; }
		
	if(document.myform.activity.checked == true)
		{ var activity = 10; }
	if(document.myform.activity.checked == false)
		{ var activity = 1; }
		
	if(document.myform.casino.checked == true)
		{ var casino = 11; }
	if(document.myform.casino.checked == false)
		{ var casino = 1; }
				
	if(document.myform.bar.checked == true)
		{ var bar = 12; }
	if(document.myform.bar.checked == false)
		{ var bar = 1; }
		
	if(document.myform.service.checked == true)
		{ var service = 13; }
	if(document.myform.service.checked == false)
		{ var service = 1; }
		
	if(document.myform.other.checked == true)
		{ var other = 14; }
	if(document.myform.other.checked == false)
		{ var other = 1; }
	
	if(document.myform.drive.checked == true)
		{ var drive = 15; }
	if(document.myform.drive.checked == false)
		{ var drive = 1; }
		

	var scripts = new Array();
	scripts[0] = rest;
	scripts[1] = store;
	scripts[2] = pharmacy;
	scripts[3] = food;
	scripts[4] = cafe;
	scripts[5] = grocery;
	scripts[6] = hosp;
	scripts[7] = animal;
	scripts[8] = activity;
	scripts[9] = casino;
	scripts[10] = bar;
	scripts[11] = service;
	scripts[12] = other;
	scripts[13] = drive;
	var result1 = scripts.join();	
		
	//remove the existing points
	
	map.clearOverlays();
	//clearcomment();////////Clear onclick 
	document.getElementById("sidetext").innerHTML = "";
		//create the boundary for the data to provide
		//initial filtering
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
			
	var url = '/nearby_locations?ne=' + northEast.toUrlValue() + '&sw=' + southWest.		toUrlValue()+'&ll='+point.		toUrlValue()+'&show='+result1;
	//log the URL for testing
	/**** GLog.writeUrl(url); ***/
	//retrieve the points using Ajax
		  		
	var request = GXmlHttp.create();
	 
	request.open('GET', url, true);
	
	
	request.onreadystatechange = function() {
	if (request.readyState == 4) {
	var data = request.responseText;
	var points = eval('('+data+')');
		//create each point from the list
	for (var i=0; i < points.length; i++) {
	var point = new GLatLng(points[i].latitude,points[i].longitude);

    var cat_num = points[i].category_id;
	
	var currentLink = "www.2itch.com/map/" + points[i].id;
	
	var full_map_address ="<small><a href='http://maps.google.com/maps?saddr="+
	points[i].address+"+"+
	points[i].city+"+"+
	points[i].state+"+"+
	points[i].zip+
	"&ie=UTF8&z=17&iwloc=addr' target='_blank'>Get Directions</a><br><a id='redLink' href='http://" + currentLink +"' target='_blank'>" + currentLink + "&nbsp;&nbsp;&nbsp;</a></small>";
	
	
	

	
	
	
	
	
	var category_num = points[i].category_id
    
	var current = "<strong>" + 
					points[i].name +
					"</strong><br/><small><u>" +
					catArray[cat_num] +
					"</u></small><small> | Submitted by:" + points[i].submitter + "</small><br/>"+ 
					points[i].address +
					"<br/>" + points[i].city +
					", " +
					points[i].state +
					" "+
					points[i].zip +
					"<br/>ph: " +
					points[i].phone +
					"<br/><a href='http://" + points[i].website + "' target='_blank'>" + points[i].website + "</a><br/>" +
					full_map_address + "<br><table width='200' border='0'><tr><td>" + points[i].notes + "</td></tr></table>";

    
	

///////////////////////Namelist ///////////////////////////	
	var namelist = "<strong><span class='orange'>"+ points[i].name +"</strong></span><br>"+ points[i].address+", "
		+ points[i].city + ", " + points[i].state + "<br><span class='categorylist'>"+ catArray[cat_num] +"</span>" ;
	var location_name = points[i].name;
	var marker_id = points[i].id;
	var type = points[i].category_id;
		if (j<50) {
		j++;
		}
		else {
		j = 0}
	var jnumber = [j];
	var marker = createMarker(point, current, type, marker_id, jnumber, location_name);
	map.addOverlay(marker);
	///////////////////////Marker ///////////////////////////
    gmarkers[j] = marker;
    gmarkers_id[j] = marker_id;
	location_names[j] = location_name;
	htmls[j] = current;
	listout(namelist,point);
	
	

///////////////////////Marker ///////////////////////////   
	}
	}
	}
	request.send(null);
	}
		
	var deselectCurrent = function() {}; // Empty function	
///////////////////////Sidetext Location List ///////////////////////////
	function listout(namelist,point) {
	    var listItem = document.createElement('li');
        var code = "<a href='javascript:myclick("+ j + ")'>"+ namelist +"</a>";
		listItem.innerHTML = code;
    	document.getElementById("sidetext").appendChild(listItem);
		HideContent('commentbox');
		
	}	
	//////////////////////HIDE N CLEAR ///////////////////////////
	function hidenclear() {
		HideContent("commentbox");
		clearForms();
		document.getElementById("flash_notice").innerHTML = "Thanks for 2itchin";
		setTimeout("new Effect.Fade('flash_notice');", 5000);
	}
	
	function hidenclearAdd() {
		HideContent("addbox");
		clearForms();
		document.getElementById("flash_notice").innerHTML = "Location Saved!<br>Thanks for 2itchin";
		setTimeout("new Effect.Fade('flash_notice');", 5000);
		document.getElementById("flash_button").innerHTML = "<input name='AddAnother' style='width:100px;' onClick=location.href='add' type='button' value='Add Another?' /> <br><input name='BackToMap' style='width:100px;' onClick=location.href='map' type='button' value='Back to Map' />";
	}
	
///////////////////////myclick ///////////////////////////	
      function myclick(j) {
        gmarkers[j].openInfoWindowHtml(htmls[j]);
	    commenting(j);
		comment_form(j);
		HideContent('commentbox');
		marker_id = gmarkers_id[j];
		push_id (marker_id);
		      }
 ////////////GET_ID////////////////////CLEAR FORMS///GET_ID///////////////////
	function push_id (marker_id) {
	id = '<input id="location_id" name="location_id"  type="hidden" value=' + marker_id + ' />'
    document.getElementById("get_id").innerHTML = id;
	clearCommentForm();

	}
	
	
	function clearForms()
	{
 	 var i;
 	 for (i = 0; (i < document.forms.length); i++) {
    document.forms[i].reset();
 	 }
	}
	
	function clearCommentForm ()
	{
	 document.getElementById("user").value = "";
	 document.getElementById("email").value = ""; 
 	 document.getElementById("web_site").value = ""; 
	 document.getElementById("usercomment").value = "";
	document.getElementById(jfldid).className = ""; 
	 
	}


//////////////GET_ID/////////////////////////GET_ID////////////////// //
////////////Hide Show2////////////////
function HideContent(d) {
document.getElementById(d).style.display = "none";
}
function ShowContent(d) {
document.getElementById(d).style.display = "block";
}
function ReverseDisplay(d) {
if(document.getElementById(d).style.display == "none") { document.getElementById(d).style.display = "block"; }
else { document.getElementById(d).style.display = "none"; }
}
////////////Hide Show2////////////////
 ///////////////////////Commenting ///////////////////////////	
		 function clear_counter() {
			mc = 0;
			n24 = 0;
			lc = 0;
			rp = 0;
			up = 0;
 		}
 
	function commenting(j) {
		  document.getElementById("comments_here").innerHTML = "<img title='Loading...' src='/images/ajax-loader.gif'>";
		  clear_counter();
		  marker_id = gmarkers_id[j];
		  var url2 = '/location/get_comments?num='+marker_id;
		  var request = GXmlHttp.create();
		  request.open('GET', url2, true);

       request.onreadystatechange = function() {
		   if (request.readyState == 4) {
	     var data = request.responseText;
    	 //GLog.writeUrl(data);
         var comments = eval('('+data+')');
		
		counter (0);

		document.getElementById("comments_here").innerHTML = "";
		//document.getElementById("welcome").innerHTML = "";
		for (var i=0; i < comments.length; i++) {
        
		var comment = "<span class='username'><strong>" + comments[i].user + "</strong></span > > <span id='comment_category'> " + comments[i].commentcategory + "</span> <br><span id='comment_created'>"+ comments[i].created_at + "</span><br>	<span id='comment_usercomment'>" + comments[i].usercomment + "</span>";
		
	var comment_type = comments[i].commentcategory;
	output_comment(comment);
	
	counter (comment_type);
				}
	   }}
	   request.send(null);
		  }

	
	
	
	
	
	
	
	function getSuggestions() {
		   document.getElementById("comments_here").innerHTML = "<img title='Loading...' src='/images/ajax-loader.gif'>";
		 
		  marker_id = 1;
		  var url2 = 'get_comments?num='+marker_id;
		  var request = GXmlHttp.create();
		  request.open('GET', url2, true);

       request.onreadystatechange = function() {
		   if (request.readyState == 4) {
	     var data = request.responseText;
    	 //GLog.writeUrl(data);
         var comments = eval('('+data+')');
		
		

		document.getElementById("comments_here").innerHTML = "";
		
		for (var i=0; i < comments.length; i++) {
        
		var comment = "<span class='username'><strong>" + comments[i].user + "</strong></span > > <span id='comment_category'> " + comments[i].commentcategory + "</span> <br><span id='comment_created'>"+ comments[i].created_at + "</span><br>	<span id='comment_usercomment'>" + comments[i].usercomment + "</span>";
		
		var comment_type = comments[i].commentcategory;
	
	output_comment(comment);
	
				}
	   }}
	   request.send(null);
		  }
		  
		  



	
///////////////////////COUNTER ///////////////////////////		
	function counter (comment_type){
		
		//document.getElementById("count").innerHTML= comment_count;
		if (comment_type == "Problem"){rp++;}
		if (comment_type == "Comment"){mc++;}  
		if (comment_type == "Closed"){lc++;}
		if (comment_type == "Not 24 Hours"){n24++;}
		if (comment_type == "Update"){up++;}
		document.getElementById("count").innerHTML= "Comments: <span class='green'>(" + mc + ")</span>   Not 24 Hours: <span class='red'>(" + n24 + ")</span>   Location Closed:  <span class='red'>(" + lc + ")</span>   Problems: <span class='red'>(" + rp + ")</span>  Updates: <span class='green'>(" + up + ")</span>";
		}
///////////////////////COUNTER ///////////////////////////	
///////////////////////Commenting ///////////////////////////	  

	function output_comment(comment) {

		  var listItem = document.createElement('li');
		  var code = comment
		  listItem.innerHTML = code;
		  document.getElementById("comments_here").appendChild(listItem);	  
	  }
		  

	function comment_form(j){	
		var location_name = location_names[j];
		
		var commentformHTML = "<span class='totallocations'>" + location_name + "</span> &nbsp;&nbsp; <INPUT  TYPE='button' VALUE='Add Comment' NAME=button1 onclick=javascript:ReverseDisplay('commentbox')>";
		
		
		document.getElementById("body2commentbox").innerHTML = commentformHTML;
	}


///////////////////////create Marker ///////////////////////////
  function createMarker(point, current, type, marker_id, jnumber, location_name) {
		var marker = new GMarker(point,{icon: customIcons[type]});
		//var maxContentDiv = document.createElement('div');
		//maxContentDiv.innerHTML = 'Loading...'
		markerGroups[type].push(marker);
		GEvent.addListener(marker, "click", function() {
        marker.openInfoWindowHtml(current);
		HideContent('commentbox');
		comment_form(jnumber);	
		push_id (marker_id);
		commenting(jnumber);
		var iw = map.getInfoWindow();
          GEvent.addListener(iw);
		 });
		
		GEvent.addListener(marker, "mouseover", function() {
		Tip(location_name);
		 });
		GEvent.addListener(marker, "mouseout", function() {
		UnTip();
		 });
		return marker;	
	}
	



//window.onload = containerHeight = new fx.Height('toolsdiv', {duration: 400});
//	containerHeight.hide();


	

/* SEARCH Functions *///////////////////////////
   function showAddress(address, latlng) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
			
		     map.clearOverlays();
			 map.setCenter(point, 13);
			 updateMarkers(point);
			 var marker = new GMarker(point, iconSearch);
			 
			 var get_LatLng = map.getCenter(latlng)
			 var lat_x
		  	 var lng_x
		     lat_x= get_LatLng.lat();
		     lng_x= get_LatLng.lng();
			 var myHtml = "<strong>"+ address + "</strong><br/>Latitude: " + lat_x + "<br/> Longitude: " + lng_x +
			 "</a>";
		 	
			 map.addOverlay(marker);
			 marker.openInfoWindowHtml(myHtml);
			 var iw = map.getInfoWindow();
			 var newHtml = 'new?lat_x='+lat_x+'&lng_x='+lng_x+'&address='+address;
			 
		  
            }
          }
        );
      }
    }

  
//Event.observe(window, 'load', init, false);
    
 
 //////////FOR ADD PAGE //////   
    function initialize() {      
      if (GBrowserIsCompatible()) { 
         geocoder = new GClientGeocoder();

         map = new GMap2(document.getElementById("map"));
         map.setCenter(new GLatLng(lat_x, lng_x), 3);  
         map.addControl(new GSmallMapControl());
		 map.disableScrollWheelZoom();
		 map.disableDoubleClickZoom();
         var marker = new GMarker(map.getCenter());
		 //updateMarkers2(new GLatLng(lat_x, lng_x));
         map.addOverlay(marker);
         }    
      }    
   function showAddAddress(address, latlng) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
		      map.clearOverlays();
			  map.setCenter(point, 12);
			  
             var marker = new GMarker(point);
			  
			 var get_LatLng = map.getCenter(latlng);
			 var lat_x;
		  	 var lng_x;
		     lat_x= get_LatLng.lat();
		     lng_x= get_LatLng.lng();
			 updateMarkers2(new GLatLng(lat_x, lng_x));
			 var myHtml = "<strong>"+ address + "</strong><br/>Latitude: " + lat_x + "<br/> Longitude: " + lng_x;
			 
			 
			 map.addOverlay(marker);
			 marker.openInfoWindowHtml(myHtml); 
             put_LatLng (lat_x,lng_x);  
			 
            }
          }
        );
      }
    }
///////////////////////////Check Map Search Switcher/////////////////////////////
  function addCheckit() {  
	var address = document.getElementById("location_address").value;
	var city = document.getElementById("location_city").value;
	var state = document.getElementById("location_state").value;
	var zip = document.getElementById("location_zip").value;
	var country = document.getElementById("location_country").value;
	var countrycode = document.getElementById("countrycode").value;
	
	if (countrycode == "1"){
	showAddAddressCheck(address+ ', ' +city+ ', ' +state+ ', ' + zip);
   }else
   showAddAddressCheck(address+ ', ' +city+ ', ' +state+ ', ' + zip + ', ' +country);
   }
	
	//////////////////SHOW USA AND INTERNATIONAL///////////////
	function showus () {
	HideContent("countryline");
	document.getElementById("location_country").value = "US";
	document.getElementById("state").innerHTML = '<label>State <em>*</em></label> <input id="location_state" name="location_state" size="1" type="text" maxlength="2" />';
	
	document.getElementById("zipcode").innerHTML = '<label>Zip </label> <input id="location_zip" name="location_zip" size="5" type="text" maxlength="5"/>';	
	}
	
	function showinternational () {
	ShowContent("countryline");
	document.getElementById("location_country").value = "";
	document.getElementById("state").innerHTML = '<label>State / Province </label> <input id="location_state" name="location_state" size="30" type="text" maxlength="50" />'
	
	document.getElementById("zipcode").innerHTML = '<label>Zip / Postal Code </label> <input id="location_zip" name="location_zip" size="15" type="text" maxlength="15"/>';	
	
	
	}
	//////////////////SHOW USA AND INTERNATIONAL///////////////
	function initAddForm (){
      	HideContent('ShowSubmit');
		clearForms();
		HideContent('countryline');
		document.getElementById("location_state").setAttribute("maxlength","2");
		document.getElementById("location_zip").setAttribute("maxlength","5");
		
	}
	
///////////////////////////Check Map Search Switcher/////////////////////////////	
	
	
	
    function showAddAddressCheck(address, latlng) {
      if (geocoder) {
        geocoder.getLatLng(
          address,
          function(point) {
            if (!point) {
              alert(address + " not found");
            } else {
		      map.clearOverlays();
			  map.setCenter(point, 14);
			  
             var marker = new GMarker(point);
			  
			 var get_LatLng = map.getCenter(latlng)

		     var lat_x= get_LatLng.lat();
		     var lng_x= get_LatLng.lng();
			 
			 var myHtml = "<strong>"+ address + "</strong><br/>Latitude: " + lat_x + "<br/> Longitude: " + lng_x + "<br><strong>Is this the correct location?</strong>";
			 ShowContent("ShowSubmit");
			 updateMarkers2(new GLatLng(lat_x, lng_x));	
			 map.addOverlay(marker);
			 marker.openInfoWindowHtml(myHtml); 
             put_LatLng (lat_x,lng_x);  

            }
          }
        );
      }
    }
    

    
    function put_LatLng (lat_x,lng_x){
    coordinance =   "<input id='location_latitude' name='location_latitude' type='hidden' value= "+ lat_x +" /><br><input id='location_longitude' type='hidden' name='location_longitude' value= "+lng_x+">"; 
    document.getElementById("latlng").innerHTML = coordinance;  
    document.getElementById("showlat").innerHTML = "<div class='form_lines'><label></label> Latitude: "+ lat_x + "</div>";
    document.getElementById("showlng").innerHTML = "<div class='form_lines'><label></label> Longitude: "+ lng_x + "</div>";
    }
    
   	function resetAddForm() {
    clearForms();
    document.getElementById("showlat").innerHTML = "";
    document.getElementById("showlng").innerHTML = "";
	document.getElementById("location_name").className = "";
	document.getElementById("location_category_id").className = "";
	document.getElementById("location_address").className = "";
	document.getElementById("location_city").className = "";
	document.getElementById("location_state").className = "";
	document.getElementById("location_country").className = "";
	document.getElementById("location_submitter").className = "";
	document.getElementById("location_submitter_email").className = "";
	document.getElementById("location_notes").className = "";
	HideContent("ShowSubmit");
	HideContent("countryline");
    }



/////////UPDATE2 for ADD PAGE!//////
function updateMarkers2(point) {
var rest = 2;
var store = 3; 		
var pharmacy = 4;
var food = 5; 
var cafe = 6; 
var grocery = 7; 
var hosp = 8; 
var animal = 9; 
var activity = 10; 
var casino = 11; 
var bar = 12;
var service = 13; 
var other = 14;
var drive =15;

var scripts = new Array();
scripts[0] = rest;
scripts[1] = store;
scripts[2] = pharmacy;
scripts[3] = food;
scripts[4] = cafe;
scripts[5] = grocery;
scripts[6] = hosp;
scripts[7] = animal;
scripts[8] = activity;
scripts[9] = casino;
scripts[10] = bar;
scripts[11] = service;
scripts[12] = other;
scripts[13] = drive;
var result1 = scripts.join();	
		
	//remove the existing points
	
	map.clearOverlays();
	//clearcomment();////////Clear onclick 
		//create the boundary for the data to provide
		//initial filtering
	var bounds = map.getBounds();
	var southWest = bounds.getSouthWest();
	var northEast = bounds.getNorthEast();
			
	var url = 'nearby_locations?ne=' + northEast.toUrlValue() + '&sw=' + southWest.		toUrlValue()+'&ll='+point.		toUrlValue()+'&show='+result1;
	//log the URL for testing
	/**** GLog.writeUrl(url); ***/
	//retrieve the points using Ajax
		  		
	var request = GXmlHttp.create();
	 
	request.open('GET', url, true);
	
	
	request.onreadystatechange = function() {
	if (request.readyState == 4) {
	var data = request.responseText;
	var points = eval('('+data+')');
		//create each point from the list
	for (var i=0; i < points.length; i++) {
	var point = new GLatLng(points[i].latitude,points[i].longitude);

    var cat_num = points[i].category_id;
	

		
		
	var full_map_address ="<a href='http://maps.google.com/maps?saddr="+
	points[i].address+"+"+
	points[i].city+"+"+
	points[i].state+
	"+"+
	points[i].zip+
	"&ie=UTF8&z=17&iwloc=addr' target='_blank'><small>Get Directions</a><br>LINK> www.2itch.com/map/" + points[i].id +" </small>";
	
	var category_num = points[i].category_id
    
	var current = "<strong>" + 
					points[i].name +
					"</strong><br/><small><u>" +
					catArray[cat_num] +
					"</small></u><br/>"+ 
					points[i].address +
					"<br/>" + points[i].city +
					", " +
					points[i].state +
					" "+
					points[i].zip +
					"<br/>ph: " +
					points[i].phone +
					"<br/><a href='http://" +
					points[i].website +
					"' target='_blank'>" +
					points[i].website + "</a><br/>" +
					full_map_address + "<br><table width='200' border='0'><tr><td>" + points[i].notes + "</td></tr></table>";

    
	

///////////////////////Namelist ///////////////////////////	
	var namelist = "<strong>"+ points[i].name +"</strong><br>"+ points[i].address+", "
		+ points[i].city + "," + points[i].state + "<br><span class='categorylist'>"+ catArray[cat_num] +"</span>" ;
	var location_name = points[i].name;
	var marker_id = points[i].id;
	var type = points[i].category_id;
		if (j<50) {
		j++;
		}
		else {
		j = 0}
	var jnumber = [j];
	var marker = createMarker(point, current, type, marker_id, jnumber, location_name);
	map.addOverlay(marker);
	///////////////////////Marker ///////////////////////////
    gmarkers[j] = marker;
    gmarkers_id[j] = marker_id;
	location_names[j] = location_name;
	htmls[j] = current;
	
	

///////////////////////Marker ///////////////////////////   
	}
	}
	}
	request.send(null);
	}
		

	
 //////////FOR ADD PAGE ^^^^^ //////  
 
 function jsClock(){
  var time = new Date()
  var hour = time.getHours()
  var minute = time.getMinutes()
  var second = time.getSeconds()
  var temp = "" + ((hour > 12) ? hour - 12 : hour)
  if(hour==0) temp = "12"
  if(temp.length==1) temp = " " + temp
  temp += ((minute < 10) ? ":0" : ":") + minute
  temp += ((second < 10) ? ":0" : ":") + second
  temp += (hour >= 12) ? " PM" : " AM"
  document.getElementById("clock").innerHTML = temp;
  id = setTimeout("jsClock()",1000)
  }
  
	function googleTakeOut () {
	document.getElementById("google_ad1").innerHTML = "";
	}
	
	

		
