/** 
* @projectDescription Inroads Google Maps API Interace 	
*
* @author	Kevin Rice kevin@inroads.us
* @version	1.1 
*/

google.load("maps", "2.x");	
var directionsPanel;
var directions;
var newwindow;

function loadEmailWindow(ec)
{
	 new Ajax.Request('/search/googlemap_search.php', {
	     method: 'post',
	     parameters: {action: 'efdisplay', course: ec},
		 onSuccess: function(transport) { $('largeContainer').innerHTML = transport.responseText;
 showWindow('largeContainer'); },
       onLoading: function() { printProcessWindow('Loading Email-A-Friend Window'); },
       onComplete: function() { closeProcessWindow(); }
	 });

}

function getDirectionsGoogle(endpoint)
{
	 showWindow('gdirectionsContainer');
   startadd =  $('gdaddress').value;
   endadd   = endpoint;
		aswindow_width = get_document_window_width();
		aswidth = convert_width(955,aswindow_width);
		asleft = calculate_left(aswidth,aswindow_width);
		$('searchContainer').style.left = asleft+'px';
		$('searchContainer').innerHTML = "<div id=\"asHeaderContainer\" style=\"width:955px;height:40px\" onMouseOver=\"dragWindow('searchContainer')\"><div id=\"asHeader\" style=\"width:860px\" ><h1 style=\"font-size:20px;color:#28903a;\">Public Courses Directions</h1></div><div class=\"closeBtn\" style=\"margin-right:20px\"><a href=\"javascript:elementFade('searchContainer');\"><img src=\"/images/blueclose.gif\" alt=\"Close the search window\" width=\"24\" height=\"24\" border=\"0\" /></a></div><div class=\"clearDivs\"><!-- --></div></div><iframe id=\"searchframe\" name=\"searchframe\" width=\"955\" height=\"550\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\" src=\"http://maps.google.com/maps?f=d&hl=en&geocode=&saddr=" +startadd+"&daddr="+endadd+"\"></iframe><br>";
		 	elementAppear('searchContainer');
		
		return false;
}


function sendEmail(f)
{
	 new Ajax.Request('/search/googlemap_search.php', {
	     method: 'post',
	     parameters: $(f).serialize(),
		 onSuccess: function(transport) { showWindow('largeContainer'); },
         onLoading: function() { printProcessWindow('Sending Email'); },
         onComplete: function() { closeProcessWindow(); }
	 });

}

/**
* @author	Kevin Rice kevin@inroads.us
* 
*/
var gmLocator = {
    options: {
		map_draggable: false,	
		disable_dragging:true,
		mapController:false,
		largemapcontrol3d:false,
		smallzoomcontrol3d:false,
		scrollwheel:false,
		scalecontrol:false,	
		maptypecontrol:false,	
		menumaptypecontrol:false,
		marker_clickable:true,
		display_single: true
	},
	vars: {
		zoom: 10,
		minZoomLevel: 8,
		maxZoomLevel: 15,
		map: false,
		marker: true,
		locations: [],
		address: false,
		slider: null,
		sliderAry:[],
		initialLoad: true,
		ajaxrequest: null
	},
	
	locator: {
		finder: '/admin/locator.php'
	},
	
	//base parameters
	params: {
		action:'location_search',
		lat:38.5,
		lon:-90,
		numResults:100,
		mnlt:false,
		mxlt:false,
		mnln:false,
		mxln:false,
		bounds:'',
		postal_code:''
	},
	
	//recent request caches
	cache: {
		geo: {count:50,recs:[{call:false,response:{lat:false,lon:false}}]},
		location: {count:10,recs:[{call:false,response:false}]}
	},

	stopReturn: /**
	    * Catches the return key input and calls the repopulate function.
		* @param {Object} e	The event that fired the function.
		* @return {Boolean}	Returns false if return key is hit, true otherwise.	
	 */
	function stopReturn(e){
		if (window.event) keynum = e.keyCode;
		else if (e.which) keynum = e.which;
		if(keynum == e.KEY_RETURN){
			alert("Enter Key Hit")
			gmLocator.directions.display_directions();
			return false;
		}
	},
	
	resetPage: /**
	 * @param obj
	 * @return
	 */
	function resetPage(obj){
		//clear points
		gmLocator.loader.clearerror();
		gmLocator.loader.clearmessage();
		gmLocator.map.clearMarkers(gmLocator.vars.map,gmLocator.vars.locations);
		gmLocator.vars.map.enableDragging();
		if($('courses')) {
			while($('courses').rows.length > 0 ) {
				$('courses').deleteRow($('courses').rows.length - 1);
				}
		}
		
		gmLocator.locationList.locations.length = 0;
		gmLocator.locationList.locationsDist.length = 0;
		gmLocator.locationList.orderName = false;
		gmLocator.locationList.orderNum = false;
		
	},
	
	setSearchBounds: function setSearchBounds() {
		 G_PHYSICAL_MAP.getMinimumResolution = function () { return gmLocator.vars.minZoomLevel; };
		 G_NORMAL_MAP.getMinimumResolution = function () { return gmLocator.vars.minZoomLevel; };
         G_SATELLITE_MAP.getMinimumResolution = function () { return gmLocator.vars.minZoomLevel; };
         G_HYBRID_MAP.getMinimumResolution = function () { return gmLocator.vars.minZoomLevel; };
         G_PHYSICAL_MAP.getMaximumResolution = function () { return gmLocator.vars.maxZoomLevel; };
         G_NORMAL_MAP.getMaximumResolution = function () { return gmLocator.vars.maxZoomLevel; };
         G_SATELLITE_MAP.getMaximumResolution = function () { return gmLocator.vars.maxZoomLevel; };
         G_HYBRID_MAP.getMaximumResolution = function () { return gmLocator.vars.maxZoomLevel; }; 
	},
	
	populate: function populate(){
		if(GBrowserIsCompatible()) {
			if(!gmLocator.options.display_single)
			   gmLocator.setSearchBounds();
			
			//populate global params object
			gmLocator.vars.address = gmLocator.buildAddress(address);
			if(!gmLocator.vars.address){
				return	
			}
			
			//scan cache
			var cached = gmLocator.cache.geo.recs.detect(function(v,i){
				if(gmLocator.vars.address == v.call){
					//update lat and lng
					gmLocator.params.lat = v.response.lat;
					gmLocator.params.lon = v.response.lon;
					return true;
				}
			});
			
			if(cached){
				gmLocator.setLocation();
			}else{
				gmLocator.getLocation();
			}
		}
	},
	
	repopulate: function repopulate(){
		if(GBrowserIsCompatible()) {
			
			gmLocator.setSearchBounds();
			
			//populate global params object
			gmLocator.vars.address = gmLocator.buildAddress("");
			if(!gmLocator.vars.address){
				return	
			}
			
			//scan cache
			var cached = gmLocator.cache.geo.recs.detect(function(v,i){
				if(gmLocator.vars.address == v.call){
					//update lat and lng
					gmLocator.params.lat = v.response.lat;
					gmLocator.params.lon = v.response.lon;
					return true;
				}
			});
			
			if(cached){
				gmLocator.setLocation();
			}else{
				gmLocator.getLocation();
			}
		}
	},
	
	buildAddress: function buildAddress(address){
		var string = '';
		
		
		if(address == "")
		var address = $('address').value;
		
		if(address){
			if(address)string += address;
			
			//validation
			if(!string){
				gmLocator.resetPage();
				gmLocator.loader.message('Please enter an address that our system can search for.<br>');
			   return false;
			}
			
			if(string.match(/0/g)){
				if(string.length == string.match(/0/g).length){
					string='';
					gmLocator.resetPage();
					gmLocator.loader.message('Search Not Recognized');
					return false;
				}	
			}
			
		}else{
			gmLocator.resetPage();
			gmLocator.loader.message('Please enter a City and State OR a Zip Code.<br>');
			return false;
		}
		return string;
	},
	
	getLocation: function getLocation(){
		var geocoder = new GClientGeocoder();
		geocoder.getLocations(gmLocator.vars.address,function(response){
			//validation
			if(!response || response.Status.code != 200) {
				gmLocator.resetPage();
				gmLocator.loader.message('<div class="paddMsg"><p class="fB">Sorry, no locations found in this area.</p><p>While we have a vast network of locations, no locations were found using your current selection.</p><ul>Please refine your search by:<li>Altering your search parameters </li><li>Expanding your zoom level</li></ul></div>');
				
				return false;
			}else{
				locations = response.Placemark[0];
				
				//load results in cache
				gmLocator.cache.geo.recs.unshift({call:gmLocator.vars.address,response:{lat:locations.Point.coordinates[1],lon:locations.Point.coordinates[0]}});
				//check size of cache and remove if nessessary
				if(gmLocator.cache.geo.recs.length>gmLocator.cache.geo.count)gmLocator.cache.geo.recs.pop();
				
				//alert(Object.keys(locations)+"\n"+Object.values(locations));
				//set new points
				gmLocator.params.lat = locations.Point.coordinates[1];
				gmLocator.params.lon = locations.Point.coordinates[0];
				gmLocator.params.postal_code = locations.address;
				
				//set new location on map
				gmLocator.setLocation(new GLatLng(locations.Point.coordinates[1],locations.Point.coordinates[0]));
			}
		});
	},
	
	setLocation: function setLocation(point){
		if(!point){
			var point = new GLatLng(gmLocator.params.lat,gmLocator.params.lon);
		}
		
		GEvent.clearInstanceListeners(gmLocator.vars.map);
		
		//pan to center of address
		gmLocator.vars.map.setCenter(point,gmLocator.vars.zoom);
				
		if(gmLocator.vars.initialLoad == true) {
			gmLocator.map.cachedSetup(gmLocator.vars.map,false);
			gmLocator.vars.initialLoad = false;
			gmLocator.vars.map.savePosition();
		}
		
		//set map bounds for locations
		gmLocator.setBounds();
		setTimeout(function(){gmLocator.map.addEvents(gmLocator.vars.map);},100);
	},
	
	getFromHere: function getFromHere(){
		gmLocator.setSearchBounds();
		var point = gmLocator.vars.map.getCenter();
		
		//set new points
		gmLocator.params.lat = point.lat();
		gmLocator.params.lon = point.lng();
		
		//set map bounds for locations
		gmLocator.setBounds();
	},
	
	setBounds: function setBounds(){
		
		var bounds = gmLocator.vars.map.getBounds();
		
		var neltln = bounds.getSouthWest();
		
		var swltln = bounds.getNorthEast();
		
		gmLocator.params.bounds = new GLatLngBounds(swltln,neltln);
		gmLocator.params.mnlt = Math.min(swltln.lat(),neltln.lat());
		gmLocator.params.mxlt = Math.max(swltln.lat(),neltln.lat());
		gmLocator.params.mnln = Math.min(swltln.lng(),neltln.lng());
		gmLocator.params.mxln = Math.max(swltln.lng(),neltln.lng());

		//set cookie
		gmLocator.setCookie();
	},
	
	setCookie: function setCookie(){
		//store the new points
		Cookie.init({expires: 1,name: 'omex_map', path: '/'});
	    Cookie.setData('stLocLat',escape(gmLocator.params.lat));
	    Cookie.setData('stLocLon',escape(gmLocator.params.lon));
	    Cookie.setData('stLocZoom',escape(gmLocator.vars.zoom));
	
		//go get the locations
		gmLocator.getLocations();
	},
	
	getLocations: function getLocations(){	
		//clear bubble
		//gmLocator.map.bubble.hide()
		form = $('frm');
		
		var paraObj = {};
		Object.extend(paraObj,gmLocator.params);
		
		var params = Object.toQueryString(paraObj);
		
		//scan cache
		var cached = gmLocator.cache.location.recs.detect(function(v,i){
			if(params == v.call){
				return v;
			}
		});
		
		if(!gmLocator.options.display_single)
		{
			if(cached){
				gmLocator.showList(cached.response);
			}else{
				gmLocator.locatorService(gmLocator.locator.finder,params,gmLocator.showList);
			}
		}
		else
			gmLocator.show_single();
	},
	
	locatorService: function locatorService(url,params,callBack){
		
		gmLocator.resetPage(); 
		gmLocator.loader.start("Retreiving Courses");
		
		gmLocator.vars.ajaxrequest = new Ajax.Request(url, { 
			method: 'get',
			parameters: encodeURI(params), 
			onInteractive: function() { gmLocator.loader.update("Populating Map"); },
			onSuccess: function() { gmLocator.showList(); },
			on404: function() { 
			   gmLocator.loader.end();
			   gmLocator.loader.error("We could not find any courses in this area.<br/>");
			},
			onComplete: function () { gmLocator.loader.end(); }
		});
	},
	
	showList: function showList(){
		
		
		gmLocator.customService.getCourseService("getweather",gmLocator.params.postal_code);
		gmLocator.customService.getWeather();
		
	},	
	show_single: function show_single(){
				
				//create and add location to map
				var point = new GLatLng(gmLocator.params.lat,gmLocator.params.lon);
				
				var marker = new GMarker(point, {clickable:gmLocator.options.marker_clickable});
				gmLocator.vars.map.addOverlay(marker);
				
				if(gmLocator.options.marker_clickable)
				   GEvent.addListener(gmLocator.vars.map, 'click', function() {
					   gmLocator.directions.loadDirectionsWindow(address);
				   });
				
		}

};	

gmLocator.directions = {
   directions_panel: null,
   gdirect: false,
   reverse: false,
   full_path: null,
   addresses: [],
   initialize: function initialize() {
		
		var processName="Loading";

		var directions_iframe           = new Element('iframe', {id:'directions_frame',name:'directions_frame',style:"margin:0px 10px;",width:"730",height:"500",frameborder:"0",scrolling:"no",marginheight:"0",marginwidth:"0",src:"include/directions.php"});	
		
		var directions_container        = new Element('div', {id:'gdirectionsContainer',style:"display:none"});
		var directions_header           = new Element('div', {id:'gdHeader'});
		var directions_header_text      = new Element('div');
		$(directions_header_text).addClassName('gdHeader_text')
		var directions_header_close     = new Element('div');	
		$(directions_header_close).addClassName('gdHeader_close')
		var directions_form_div         = new Element('div', {id:'gdirectionsForm',className:'form',style:'border:none;'});	
		var directions_footer           = new Element('div', {id:'gdFooter'});	
		
        var form_table                  = new Element('table', {cellpadding:0,cellspacing:0,style:'width:710px;'});
        var form_tbody                  = new Element('tbody');
        var form_tr                     = new Element('tr');
        var label_td                    = new Element('td',{style:"width:70px;line-height:19px;",valign:'top'});
        var address_td                  = new Element('td',{style:"width:300px;line-height:19px;",valign:'top'});
        var buttons_td                  = new Element('td',{style:"width:300px;line-height:19px;",valign:'top',align:'right'});
        var form_buttons_tbl            = new Element('table', {cellpadding:0,cellspacing:0,style:'width:710px;margin:0px 10px;'});
        var form_buttons_tbody          = new Element('tbody');
        var form_buttons_tr             = new Element('tr');
        var reverse_td                  = new Element('td',{style:"width:195px;line-height:19px;",valign:'top'});
        var submit_td                   = new Element('td',{style:"width:195px;line-height:19px",valign:'top',align:'right'});
        var spacer_td                   = new Element('td',{style:"width:320px;",valign:'top',align:'right'});
		
        var directions_form             = new Element('form', {id:'gdirections_form',className:'form',name:'gdirections_form',action:'include/directions.php',method:'post',target:'directions_frame',style:'margin:15px 0px;'});	
		
		var directions_seperator        = new Element('img', {src:'images/map/map_seperator.png',title:""});
		var directions_header_close_img = new Element('img', {src:'images/map/map_close.gif',title:"Close"});
		var directions_inroads          = new Element('img', {src:'images/map/inroads-map.gif',title:"Inroads, LLC",style:"vertical-align:top"});
		var reverse_img                 = new Element('img', {src:'images/map/reverse-directions.gif',style:"cursor:pointer;",align:'middle'});
		
		var email_friend_link           = new Element('a', {href:'email-a-friend.php',id:"email_friend",title:"Email a Friend",className:'map_friend_link'});
		var print_directions_link       = new Element('a', {id:"print_directions",className:'map_friend_link',style:"cursor:pointer;"});
		var hide_directions_link        = new Element('a', {id:"hide_directions",className:'map_friend_link',style:"cursor:pointer;"});

	    //alert('Initialization Function Links');
		var endpoint                    = new Element('input', {type:'hidden',name:'endpoint',id:'endpoint'});	
		var address_inpt                = new Element('input', {onkeypress:'return gmLocator.stopReturn(event)',type:'text',name:'gdaddress',id:'gdaddress',value:'',size:30,maxlength:50,className:'input',style:'width:300px'});	
		var submit_inpt                 = new Element('img', {align:'middle',src:'images/map/get-directions.gif',style:"cursor:pointer;"});	

	    //alert('Initialization Function Inputs');
		var line_break                  = new Element('br');

	    //alert('Initialization Function break');
		directions_header_text.insert("Get Directions");
		directions_header_close.insert(directions_header_close_img); 
		directions_header.insert(directions_header_close); 	
		directions_header.insert(directions_header_text); 
		directions_header.insert(directions_header_text); 
	    //alert('Initialization Function Directions Header created');
        
		reverse_td.insert(reverse_img);
		submit_td.insert(submit_inpt);
		spacer_td.insert('&nbsp;');

	    //alert('Initialization Function Directions H');
		label_td.insert('From:');
		address_td.insert(address_inpt);

	    //alert('Initialization Function Directions');
		email_friend_link.insert('Email a Friend');
		print_directions_link.insert('Print Directions');
		print_directions_link.onclick = gmLocator.directions.print_directions;
		hide_directions_link.insert('Show Direction Steps');
		hide_directions_link.onclick = gmLocator.directions.show_directions;

	    //alert('Initialization Function Directions');
		buttons_td.insert(print_directions_link);
		buttons_td.insert(line_break);
		buttons_td.insert(hide_directions_link);

	    //alert('Initialization Function Directions');
		form_buttons_tr.insert(reverse_td);
		form_buttons_tr.insert(submit_td);
		form_buttons_tr.insert(spacer_td);
		form_buttons_tbody.insert(form_buttons_tr);
		form_buttons_tbl.insert(form_buttons_tbody);

	    //alert('Initialization Function Directions');
		form_tr.insert(label_td);
		form_tr.insert(address_td);
		form_tr.insert(buttons_td);
		form_tbody.insert(form_tr);
		form_table.insert(form_tbody);

		directions_form.insert(endpoint); 
		directions_form.insert(form_table); 
		directions_form.insert(form_buttons_tbl); 
		directions_form.insert('<div class="clearDivs"><!-- --></div>'); 
        
		if(Cookie.getData("cururl") != undefined)
			elem = Cookie.getData("cururl");
		else
			elem = 'harrisburg';
		
		directions_form_div.insert($(elem).innerHTML); 
		directions_form_div.insert(directions_seperator); 	
		directions_form_div.insert(directions_form); 
		
		directions_footer.insert('Powered by ');
		directions_footer.insert(directions_inroads);
		
		directions_container.insert(directions_header); 	
		directions_container.insert(directions_form_div); 
		directions_container.insert(directions_iframe); 
		directions_container.insert(directions_footer); 
		
		dbody.insert(directions_container); 
		 directions_container.style.zindex = 1;
		directions_header_close_img.observe('click',gmLocator.directions.hideDirectionsWindow);
		reverse_img.observe('click',gmLocator.directions.reverse_directions);
		submit_inpt.observe('click',gmLocator.directions.display_directions);
		//address_inpt.observe('keypress',gmLocator.stopReturn);
   },
   handle_errors: function handle_errors(){
	   if (gmLocator.directions.gdirect.getStatus().code == G_GEO_UNKNOWN_ADDRESS)
	     alert("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: " + gmLocator.directions.gdirect.getStatus().code);
	   else if (gmLocator.directions.gdirect.getStatus().code == G_GEO_SERVER_ERROR)
	     alert("A geocoding or directions request could not be successfully processed, yet the exact reason for the failure is not known.\n Error code: " + gmLocator.directions.gdirect.getStatus().code);
	   
	   else if (gmLocator.directions.gdirect.getStatus().code == G_GEO_MISSING_QUERY)
	     alert("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: " + gmLocator.directions.gdirect.getStatus().code);

	//   else if (gdir.getStatus().code == G_UNAVAILABLE_ADDRESS)  <--- Doc bug... this is either not defined, or Doc is wrong
	//     alert("The geocode for the given address or the route for the given directions query cannot be returned due to legal or contractual reasons.\n Error code: " + gdir.getStatus().code);
	     
	   else if (gmLocator.directions.gdirect.getStatus().code == G_GEO_BAD_KEY)
	     alert("The given key is either invalid or does not match the domain for which it was given. \n Error code: " + gmLocator.directions.gdirect.getStatus().code);

	   else if (gmLocator.directions.gdirect.getStatus().code == G_GEO_BAD_REQUEST)
	     alert("A directions request could not be successfully parsed.\n Error code: " + gmLocator.directions.gdirect.getStatus().code);
	    
	   else alert("An unknown error occurred.");
	   
	},
   create: function create() {
      gmLocator.directions.gdirect = new GDirections(gmLocator.vars.map, gmLocator.directions.directions_panel);
   },
   load_directions: function load_directions() {
      gmLocator.directions.gdirect.load(parent.gmLocator.directions.full_path);
   },
   display_directions: function display_directions() {
	      the_frame = get_iframe('directions_frame');
		  gmLocator.directions.addresses = [$('gdaddress').value, address];
		  gmLocator.directions.make_path();
		  
		  if(!the_frame.gmLocator.directions.gdirect)
		     the_frame.gmLocator.directions.gdirect = new GDirections(the_frame.gmLocator.vars.map, the_frame.gmLocator.directions.directions_panel);
          
		  GEvent.addListener(the_frame.gmLocator.directions.gdirect, "load", function(){
		      if($('hide_directions').innerHTML == "Show Direction Steps")
		      {
		    	  the_frame.gmLocator.effects.slideLeftIn('dir_cont');
		    	  $('hide_directions').update('Hide Direction Steps');
		      }
		  });
		  
	      GEvent.addListener(the_frame.gmLocator.directions.gdirect, "error", the_frame.gmLocator.directions.handle_errors);
	      
		  the_frame.gmLocator.directions.gdirect.load(gmLocator.directions.full_path);
		  return false;
	   },
   make_path: function make_path() {
	  if(gmLocator.directions.reverse)
		 gmLocator.directions.full_path = "from: "+gmLocator.directions.addresses[1]+" to: "+gmLocator.directions.addresses[0];
	  else
		 gmLocator.directions.full_path = "from: "+gmLocator.directions.addresses[0]+" to: "+gmLocator.directions.addresses[1];
	  
   },
   reverse_directions: function reverse_directions() {
	   the_frame = get_iframe('directions_frame');
	   
      if(gmLocator.directions.reverse)
    	  gmLocator.directions.reverse = false;
	  else
		  gmLocator.directions.reverse = true;

      gmLocator.directions.make_path();
      the_frame.gmLocator.directions.load_directions();
   },
   print_directions: function print_directions(e) {
	   print_iframe('directions_frame');
   },
   loadDirectionsWindow: function loadDirectionsWindow(endpoint)
   {
		 gmLocator.effects.makeAppear('gdirectionsContainer');
	   	$('endpoint').value = endpoint;
   },
   hideDirectionsWindow: function hideDirectionsWindow(e)
   {
      gmLocator.effects.makeFade('gdirectionsContainer');
   },
   show_directions: function show_directions()
   {
	   the_frame = get_iframe('directions_frame');
      if($('hide_directions').innerHTML == "Show Direction Steps")
      {
    	  the_frame.gmLocator.effects.slideLeftIn('dir_cont');
    	  $('hide_directions').update('Hide Direction Steps');
      }
      else
      {
    	  the_frame.gmLocator.effects.slideLeftOut('dir_cont');
		  $('hide_directions').update('Show Direction Steps');
	   }
      
   }
};

gmLocator.effects = { 
	slideLeftIn: function slideLeftIn(element) 
	{
	  element = $(element);
	  new Effect.SlideRightIn(element, {duration: .5, queue: 'end'}); 
	},
	slideLeftOut: function slideRightOut(element) 
	{
	  element = $(element);
	  new Effect.SlideLeftOut(element, {duration: .5, queue: 'end'}); 
	},
   raiseBlind: function raiseBlind(element) 
	{
      element = $(element);
      new Effect.BlindUp(element, {duration: .5, queue: 'end'}); 
   },
 
   lowerBlind: function lowerBlind(element)
	{
     element = $(element);
     new Effect.BlindDown(element, {duration: .5, queue: 'end'}); 
   },
 
   makeFade: function makeFade(element) {
     element = $(element);
     new Effect.Fade(element, {duration: .5, queue: 'end'}); 
   },
 
   slideDown: function slideDown(element) {
     element = $(element);
      
          new Effect.SlideDown(element, {duration: .5, queue: 'end'}); 
   },
 
   slideUp: function slideUp(element) {
     element = $(element);
          new Effect.SlideUp(element, {duration: .5, queue: 'end'}); 
   },
 
   makeAppear: function makeAppear(element) {
     element = $(element);
     new Effect.Appear(element, {duration: .5, queue: 'end'}); 
   },
 
   dragWindow: function dragWindow(element) {
	   element = $(element);
	   new Draggable(element);
   }
};

gmLocator.loader = {
	initialize: function initialize() {
	
		var window_width = get_document_window_width();
		width = convert_width(250,window_width);
		var window_height = get_document_window_height();
		height = convert_height(80,window_height);
		var left = calculate_left(width,window_width);
		var top = calculate_top(height,window_height);
		
		var processName="Loading";
		var popUpWindow = new Element('div', {id:'process',style:"text-align:center;position:absolute;"+"left:"+left+"px;top:"+top+"px;width:250px;border:1px solid #28903a;height:35px;padding:40px 5px 5px 5px;display:none;z-index:1000;"});
		var popUpInner  = new Element('span', {id:'innerProcessText'});
		popUpInner.insert(processName);
		popUpWindow.insert(popUpInner);
		popUpWindow.insert("&hellip;<br />");
		popUpWindow.insert("Please Wait&hellip;");		
		dbody.insert(popUpWindow); 
		
		var processName1="We're Sorry:";
		var popUpWindow1 = new Element('div', {id:'errormessage', onclick: "elementFade(this)",style:"cursor:pointer;text-align:center;position:absolute;"+"left:"+left+"px;top:"+top+"px;width:250px;border:1px solid #28903a;height:35px;padding:40px 5px 5px 5px;display:none;z-index:1000;"});
		var popUpInner1  = new Element('span', {id:'innerErrorMessageText'});
		popUpInner1.insert(processName1);
		popUpWindow1.insert(popUpInner1);
		popUpWindow1.insert("<br />");
		popUpWindow1.insert("Click to Close");		
		dbody.insert(popUpWindow1);
		
		var popUpWindow2 = new Element('div', {id:'message', onclick: "elementFade(this)",style:"cursor:pointer;text-align:center;position:absolute;"+"left:"+left+"px;top:"+(top-40)+"px;width:250px;height:75px;border:1px solid #28903a;padding:40px 5px 5px 5px;display:none;z-index:1000;"});
		var popUpInner2  = new Element('span', {id:'innerMessageText',style:"text-align:left"});
		popUpWindow2.insert(popUpInner2);
		popUpWindow2.insert("Click to Close");		
		dbody.insert(popUpWindow2);
	},
	
	start: function start(message) {
		if ( document.getElementById("process") )
		{
				document.getElementById("innerProcessText").innerHTML=message;
				gmLocator.effects.makeAppear("process");
		}
	},
	
	update: function update(message) {
		if ( document.getElementById("process") )
		{
				document.getElementById("innerProcessText").innerHTML=message;
		}
	},
	
	end: function end() {
		if ( document.getElementById("process") )
		{
			gmLocator.effects.makeFade("process");
		}		
	},
	
	clearerror: function clearerror() {
		if ( document.getElementById("errormessage") )
		{
			if(document.getElementById("errormessage").display != "none")
			gmLocator.effects.makeFade("errormessage");
		}		
	},
	
	error: function error(message) {
		if ( document.getElementById("errormessage") )
		{
			document.getElementById("innerErrorMessageText").innerHTML=message;
			gmLocator.effects.makeAppear("errormessage");
		}		
	},
	
	clearmessage: function clearmessage() {
		if ( document.getElementById("message") )
		{
			//document.getElementById("innerProcessText").innerHTML=processName;
			if(document.getElementById("message").display != "none")
			gmLocator.effects.makeFade("message");
		}		
	},
	
	message: function message(message) {
		if ( document.getElementById("message") )
		{
			document.getElementById("innerMessageText").innerHTML=message;
			gmLocator.effects.makeAppear("message");
		}		
	}
};

gmLocator.slider = {
	create:function create(sliderType,mnr,mxr,sv) {
		$(sliderType+"_min").innerHTML = mnr;
		$(sliderType+"_max").innerHTML = mxr;
		
		
		var handles= [sliderType+"_handle_min",sliderType+"_handle_max"];
		new Control.Slider(handles, $(sliderType), {
		  range: $R(mnr, mxr),
		  values: $R(mnr, mxr),
		  sliderValue: [mnr, mxr],         
    	  restricted: true,   
		  onSlide: function(value) {
		  	$(sliderType+"_input").value = value;
			val = value.toString();
			v = val.split(",");
		  	$(sliderType+"_min").innerHTML = v[0];
		  	$(sliderType+"_max").innerHTML = v[1];
		  },
		  onChange: function(value) { 
		  	$(sliderType+"_input").value = value;
		  }
		});
	}
};

gmLocator.map = {
        
		setup:function setup(map,options) {
	        if(options)
			   map = gmLocator.vars.map = new google.maps.Map2($(map),{size: options});
	        else
			   map = gmLocator.vars.map = new google.maps.Map2($(map));

			//var customUI = map.getDefaultUI();
			var topRight = new GControlPosition(G_ANCHOR_TOP_RIGHT, new GSize(10,10));
			var bottomRight = new GControlPosition(G_ANCHOR_BOTTOM_RIGHT, new GSize(10,10));
			var bottomLeft = new GControlPosition(G_ANCHOR_BOTTOM_LEFT, new GSize(80,15));
			var topLeft = new GControlPosition(G_ANCHOR_TOP_LEFT, new GSize(10,10));
			
			if(gmLocator.options.largemapcontrol3d) {
				var largemapcontrol3d = new GLargeMapControl3D();
				map.addControl(largemapcontrol3d);
			}
			
			if(gmLocator.options.smallzoomcontrol3d) {
				var smallzoomcontrol3d = new GSmallZoomControl3D();
				map.addControl(smallzoomcontrol3d);
			}
			
			if(gmLocator.options.scalecontrol) {
				var scalecontrol = new GScaleControl();
				map.addControl(scalecontrol);
			}
			
			if(gmLocator.options.maptypecontrol) {
				var mapControl = new GMapTypeControl();
				map.addControl(mapControl);
			}
			            
			if(!gmLocator.options.map_draggable)
			   map.disableDragging();
			//map.setUI(customUI);

			if(!gmLocator.options.display_single)
			{
				if(gmLocator.vars.initialLoad == true){
					gmLocator.map.initialSetup(map);
				}else{
					gmLocator.map.cachedSetup(map,true);
				}
			}
		},
		
		initialSetup: function initialSetup(map){
			map.setCenter(new GLatLng(gmLocator.params.lat, gmLocator.params.lon), 3);
			
			//if(!skiploader)
			//gmLocator.loader.message("<div style=\"text-align:center;font-weight:bold;padding-bottom:5px;\">Welcome to PublicCourses.com</div><div style=\"text-align:center;padding-bottom:5px;\">Please enter a <strong>city and state</strong> or <strong>zip code</strong> above to find a list of courses in your area</div>");
		
		},
		
		cachedSetup: function cachedSetup(map,init) {
			
			map.setCenter(new GLatLng(gmLocator.params.lat, gmLocator.params.lon), gmLocator.vars.zoom);
			
			//get map container
			var obj = map.getContainer();
			if(gmLocator.vars.mapController){
				obj = $(gmLocator.vars.mapController);
			}
			
			if(init){
				gmLocator.map.addEvents(map);
				var point = new GLatLng(gmLocator.params.lat,gmLocator.params.lon);
				gmLocator.setBounds(point);
			}
			
		},
		
		addEvents: function addEvents(map){
			if(!gmLocator.options.display_single)
			{
				GEvent.addListener(map, "infowindowopen", function() {
					map.disableDragging();
					map.savePosition();
				});
				
				GEvent.addListener(map, "infowindowbeforeclose", function() {
					//map.returnToSavedPosition();
					//map.enableDragging();
					//gmLocator.getFromHere()
				});
				
				GEvent.addListener(map, "infowindowclose", function() {
					//map.returnToSavedPosition();
					map.enableDragging();
					//gmLocator.getFromHere()
				});
				
				GEvent.addListener(map, "moveend", function() {
					if(map.draggingEnabled())
					gmLocator.getFromHere();
				});
				
				GEvent.addListener(map, "movestart", function() {
					//clear bubble
					//gmLocator.map.bubble.hide()
				});
			}
		},
		
		clearMarkers: function clearMarkers(map,locations){
			if(locations.length>0)while(locations.length>0)map.removeOverlay(locations.shift());
		},
		
		centerOnThis: function centerOnThis(id) {
			mk = gmLocator.map.bubble.gmarkers[id];
			GEvent.trigger(mk, 'click');
		}	
};

gmLocator.map.icon = {	
	icon_dir: "images/map_icons/",
	icon_height: 20,
	icon_width: 20,
	iconType: {},
	location: function location(type){
		var icon = new GIcon();
		icon.image = gmLocator.map.icon.icon_dir+gmLocator.map.icon.iconType[type]+".png";
		icon.printImage = gmLocator.map.icon.icon_dir+gmLocator.map.icon.iconType[type]+".gif";
		icon.mozPrintImage = gmLocator.map.icon.icon_dir+gmLocator.map.icon.iconType[type]+"-ff.gif";
		icon.transparent = gmLocator.map.icon.icon_dir+gmLocator.map.icon.iconType[type]+"-ie.png";
		icon.iconSize = new GSize(gmLocator.map.icon.icon_height, gmLocator.map.icon.icon_width);
		icon.imageMap=[0,20,0,0,5,1,19,6,10,8,6,9,1,11,1,20];
		//icon.shadowSize = new GSize(55, 55);
		icon.iconAnchor = new GPoint(0,20);
		icon.infoWindowAnchor = new GPoint(0,0);
		return icon;
	}
};

gmLocator.stringManipulator = {
	basename: function basename(path, suffix) {	 
	    var b = path.replace(/^.*[\/\\]/g, '');
	    
	    if (typeof(suffix) == 'string' && b.substr(b.length-suffix.length) == suffix) {
	        b = b.substr(0, b.length-suffix.length);
	    }
	    
	    return b;
	},
	
	wordwrap: function wordwrap( str, int_width, str_break, cut ) {
	    
	    var m = ((arguments.length >= 2) ? arguments[1] : 75   );
	    var b = ((arguments.length >= 3) ? arguments[2] : "\n" );
	    var c = ((arguments.length >= 4) ? arguments[3] : false);
	 
	    var i, j, l, s, r;
	 
	    str += '';
	 
	    if (m < 1) {
	        return str;
	    }
	 
	    for (i = -1, l = (r = str.split("\n")).length; ++i < l; r[i] += s) {
	        for(s = r[i], r[i] = ""; s.length > m; r[i] += s.slice(0, j) + ((s = s.slice(j)).length ? b : "")){
	            j = c == 2 || (j = s.slice(0, m + 1).match(/\S*(\s)?$/))[1] ? m : j.input.length - j[0].length || c == 1 && m || j.input.length + (j = s.slice(m).match(/^\S*/)).input.length;
	        }
	    }
	 
	    return r.join("\n");
	},
	
	phone_number: function phone_number(sPhone,type){
		sPhone = sPhone.replace(/[^0-9]/g,'');
		
	    if(sPhone.length > 10 && sPhone.substr(0,1) == "1" )
			sPhone = sPhone.substr(1,10);
		
		//if(sPhone.length != 10) return false;
	
	    sArea = sPhone.substr(0,3);
		sPrefix = sPhone.substr(3,3);
		sNumber = sPhone.substr(6,4);
		
		phonePat = new Object();
		
		phonePat.standard = "(" + sArea + ") " + sPrefix + "-" + sNumber;
		phonePat.european = sArea + "." + sPrefix + "." + sNumber;
		phonePat.stripped = sArea+""+sPrefix+""+sNumber;
		
		return phonePat[type];
	},
	
	sanitize: function sanitize(cleanup)
	{
		cleanup = cleanup.toLowerCase();
		cleanup = cleanup.gsub(/[^a-z0-9_]/,'-');
			
		return cleanup;
	}

};

gmLocator.customService = {	
	getCourseService: function getCourseService(type,course,callBack){
		
			var myAjax = new Ajax.Request("/admin/locator.php", { 
				method: 'get', 
				parameters: {action: type, id: course},
				asynchronous:false,
				onComplete: function(transport) {
					gmLocator.map.bubble.ajaxresult = transport.responseText;
				},
				onFailure: function() { alert("Your search returned no results for this area."); }
			});
		
	},

   updateClicks: function updateClicks(course) {
      new Ajax.Request('/admin/locator.php', {
         method: 'post',
         parameters: { action: 'updateclicks', id: course }
      });
   },
	
	getWeather: function getWeather() {
		var weather = gmLocator.map.bubble.ajaxresult.evalJSON();
		
		if($('weatherContainer'))
		{		
			weatherHTML = "<table cellpadding='0' cellspacing='0' align='center' width='200px'>";
			weatherHTML += "<tr><td align='center'>";
			weatherHTML += "<h2 class='pcH2' style='margin:0px;padding:0px'><span class='hAltBlue'>"+weather.city[0]+"</span></h2>";
			weatherHTML += "</td></tr><tr><td>";
			weatherHTML += "<table cellpadding='0' cellspacing='0' width='200px'>";
			weatherHTML += "<tr><th width='200px'>Current Conditions</th></tr>";
			weatherHTML += "<tr><td width='200px' height='85px' class='smallweather'>";
			weatherHTML += "<table cellpadding='0' cellspacing='0'>";
			weatherHTML += "<tr><td align='center' width='200px'>"+weather['current_conditions']['condition'][0]+"</td></tr>";
			weatherHTML += "<tr><td align='center'><img src='http://www.google.com/"+weather['current_conditions']['icon'][0]+"' alt='"+weather['current_conditions']['condition'][0]+"' /></td></tr>";
			weatherHTML += "<tr><td align='center'>"+weather['current_conditions']['temp'][0]+"&deg; F</td></tr>";
			weatherHTML += "<tr><td align='center'>"+weather['current_conditions']['wind'][0]+"</td></tr>";
			weatherHTML += "</table>";
			weatherHTML += "</td></tr>";
			weatherHTML += "<tr><th>Forecast Conditions</th></tr>";
			weatherHTML += "<tr><td><table cellpadding='0' cellspacing='0'>";
			weatherHTML += "<tr>";
				
			if(Object.isArray(weather['forecast_conditions']))
			{
				weather['forecast_conditions'].each(function(w)
				{
					if(w['day'] != 'Today')
					{
						weatherHTML += "<td align='center' valign='center' width='70px' height='85px' class='smallweather' ><table cellpadding='0' cellspacing='0' >";
						weatherHTML += "<tr><td align='center' >"+w['day'][0]+"</td></tr>";
						weatherHTML += "<tr><td align='center'><img src='http://www.google.com/"+w['icon'][0]+"' alt='"+w['condition'][0]+"' /></td></tr>";
						weatherHTML += "<tr><td align='center'><span class='mangoText' >"+w['high'][0]+"&deg;</span> / <span class='hAltBlue' >"+w['low'][0]+"&deg;</span></td></tr>";
						weatherHTML += "<tr><td align='center'>&nbsp;</td></tr>";
						weatherHTML += "</table></td>";
					}
				});
			}
			weatherHTML += "</tr>";
			weatherHTML += "</table>";
			weatherHTML += "</td></tr>";
			weatherHTML += "</table>";
			
			$('weatherContainer').innerHTML = weatherHTML;
		}
	},
	
	selectType: function selectType(element){
		id = element.name;
		
		if($(id).value == "" && gmLocator.params[id] == "")
		{
			//alert(element.src);
			//element.src = element.src.replace(/.gif/,"-selected.gif");
			//alert(element.src);
			$(id).value = "selected";
		}
		else
		{
			//alert(element.src);
			//element.src = element.src.replace(/-selected.gif/,".gif");
			//alert(element.src);
			$(id).value = "";
		}
		
	},
	
	showVideo: function showVideo(vd) {
		alert("Show VIdeo");
		vid = $('videoContainer');
		aswindow_width = get_document_window_width();
		aswidth = convert_width(500,aswindow_width);
		aswindow_height = get_document_window_height();
		asheight = convert_height(305,aswindow_height);
		asleft = calculate_left(aswidth,aswindow_width);
		astop = calculate_top(asheight,aswindow_height);		
		vid.style.left = asleft+'px';
		vid.style.top = astop+'px';    
		vid.style.display = '';
		$('video').innerHTML = AC_FL_PreloadContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0','width','320','height','240','movie',vd,'quality','high','allowfullscreen','false' );
		
	},
		
	hideVideo: function hideVideo() {
		vid = ($('videoContainercms'))?$('videoContainercms'):$('vidContainer');
		vid.style.display = 'none';
		$('video').innerHTML = '';
	},
	
	usStates: { AL:"Alabama",  
			AK:"Alaska", 
			AR:"Arkansas",  
			AZ:"Arizona",   
			CA:"California",  
			CO:"Colorado",  
			CT:"Connecticut", 
			DC:"District Of Columbia",  
			DE:"Delaware",   
			FL:"Florida",  
			GA:"Georgia",  
			HI:"Hawaii",
			IA:"Iowa",   
			ID:"Idaho",  
			IL:"Illinois",  
			IN:"Indiana",   
			KS:"Kansas",  
			KY:"Kentucky",  
			LA:"Louisiana",
			MA:"Massachusetts",
			MD:"Maryland",    
			ME:"Maine",    
			MI:"Michigan",  
			MN:"Minnesota",
			MO:"Missouri", 
			MS:"Mississippi",    
			MT:"Montana",
			NC:"North Carolina",
			ND:"North Dakota",
			NE:"Nebraska",
			NH:"New Hampshire",
			NJ:"New Jersey",
			NM:"New Mexico",
			NV:"Nevada",
			NY:"New York",
			OH:"Ohio",  
			OK:"Oklahoma",  
			OR:"Oregon",  
			PA:"Pennsylvania",  
			RI:"Rhode Island",  
			SC:"South Carolina",  
			SD:"South Dakota",
			TN:"Tennessee",  
			TX:"Texas",  
			UT:"Utah",  
			VA:"Virginia", 
			VT:"Vermont",   
			WA:"Washington", 
			WI:"Wisconsin",  
			WV:"West Virginia",   
			WY:"Wyoming" }
};

gmLocator.map.bubble = {
	ajaxresult: false,
	gmarkers: [],
	
	location: function location(i,point,icon,name,tabs,arrf,arrb,index){
		
		var marker = new GMarker(point,{icon:icon,title:name});
		
		GEvent.addListener(marker, "click", function() {
        //gmLocator.customService.updateClicks(i);
		  marker.openInfoWindowTabsHtml(tabs);
		});
			
		gmLocator.locationList.locations.push(arrf);
		gmLocator.locationList.locationsDist.push(arrb);
		
		gmLocator.map.bubble.gmarkers[i] = marker;
		gmLocator.vars.locations.push(marker);
	}
};

gmLocator.locationList = {
	sortList: function sortList(orderBy) {
		
		rows = $('courses').rows.length;
		
		courselist = new Array();
		
		if(orderBy == "name")
			if(!gmLocator.locationList.orderName)
			{
				gmLocator.locationList.locations.sort();
				gmLocator.locationList.orderName = true;
			}
			else
			{
				gmLocator.locationList.locations.reverse();
				gmLocator.locationList.orderName = false;
			}
		else
			if(!gmLocator.locationList.orderNum)
			{
				gmLocator.locationList.locationsDist.sort(function(a,b) 
				{
					itemsa = a.split("|");
					itemsb = b.split("|");
					//alert(b+" - "+a);
					return itemsa[0] - itemsb[0];
				});
				gmLocator.locationList.orderNum = true;
			}
			else
			{
				gmLocator.locationList.locationsDist.sort(function(a,b) 
				{
					itemsa = a.split("|");
					itemsb = b.split("|");
					//alert(b+" - "+a);
					return itemsb[0] - itemsa[0];
				});
				gmLocator.locationList.orderNum = false;
			}
		
		while($('courses').rows.length > 0 ) $('courses').deleteRow($('courses').rows.length - 1);
				
		for(i=0;i<gmLocator.locationList.locations.length;i++)
		{
			var w=$('courses').insertRow(i);
			var x=w.insertCell(0);
  			var y=w.insertCell(1);
			x.style.padding = '2px 0px';
			y.style.padding = '0px 7px 3px 5px';
			
			courserow = gmLocator.locationList.locations[i].split("|");
			coursedist = gmLocator.locationList.locationsDist[i].split("|");
			
			if(orderBy == "name")
			{
				if(courserow[2] == 'PR' || courserow[2] == 'PE' || courserow[2] == 'PN')
					style = 'style = "cursor:pointer;color:#ff0000"';
				else
					style = 'style = "cursor:pointer;color:#28903a"';
				
				if((courserow[2] == 'PR' || courserow[2] == 'PE' || courserow[2] == 'PN') && (courserow[8] != 'RS' && courserow[8] != 'RR') && courserow[8] != "MI")
				{
					style = 'style = \"cursor:pointer;color:#ff0000\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['private'];
				}
				else if(courserow[2] == 'DF' && (courserow[8] != 'RS' && courserow[8] != 'RR') && courserow[8] != "MI")
				{
					style = 'style = \"cursor:pointer;color:#0056A6\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['semi_private'];
				}
				else if((courserow[2] == 'DF' && (courserow[8] == 'RS' || courserow[8] == 'RR')) || ((courserow[2] == 'PR' || courserow[2] == 'PE' || courserow[2] == 'PN') && (courserow[8]== 'RS' || courserow[8] == 'RR')))
				{
					style = 'style = \"cursor:pointer;color:#9B3F98\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['resort'];
				}
				else if((courserow[2] == 'DF' && courserow[8] == 'MI') || ((courserow[2] == 'PR' || courserow[2] == 'PE' || courserow[2] == 'PN') && courserow[8] == 'MI'))
				{
					style = 'style = \"cursor:pointer;color:#79603C\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['military'];
				}
				else
				{
					style = 'style = \"cursor:pointer;color:#278E38\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['public'];
				}
				
				company = courserow[0];
				
				if(parseInt(courserow[3]) > 1  && courserow[5] != 'yes')
				{
					var iconimg = gmLocator.map.icon.iconType['sponsor'];
					company = "<strong>"+company.truncate(35)+"</strong>";
				}
						
				//w.onclick = "gmLocator.map.centerOnThis("+courserow[4]+");";
				
				x.innerHTML="<img style=\"cursor:pointer\" onclick=\"gmLocator.map.centerOnThis("+courserow[4]+")\" src=\"http://www.publiccourses.com/images/mapimages/"+iconimg+".gif\">";
				y.innerHTML="<span "+style+" onclick=\"gmLocator.map.centerOnThis("+courserow[4]+")\" class='gmaptip'>"+company.truncate(35)+"</span><br><span style=\"font-size:10px;cursor:pointer\" onclick=\"gmLocator.map.centerOnThis("+courserow[4]+")\">"+courserow[6]+", "+courserow[7]+" ("+courserow[1]+"mi.)</span>";
				//z.innerHTML=dist;
				//z.align="center";
				
			}
			else
			{
				if(coursedist[2] == 'PR' || coursedist[2] == 'PE' || coursedist[2] == 'PN')
					style = 'style = "cursor:pointer;color:#ff0000"';
				else
					style = 'style = "cursor:pointer;color:#28903a"';
				
				if((coursedist[2] == 'PR' || coursedist[2] == 'PE' || coursedist[2] == 'PN') && (coursedist[8] != 'RS' && coursedist[8] != 'RR') && coursedist[8] != "MI")
				{
					style = 'style = \"cursor:pointer;color:#ff0000\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['private'];
				}
				else if(coursedist[2] == 'DF' && (coursedist[8] != 'RS' && coursedist[8] != 'RR') && coursedist[8] != "MI")
				{
					style = 'style = \"cursor:pointer;color:#0056A6\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['semi_private'];
				}
				else if((coursedist[2] == 'DF' && (coursedist[8] == 'RS' || coursedist[8] == 'RR')) || ((coursedist[2] == 'PR' || coursedist[2] == 'PE' || coursedist[2] == 'PN') && (coursedist[8]== 'RS' || coursedist[8] == 'RR')))
				{
					style = 'style = \"cursor:pointer;color:#9B3F98\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['resort'];
				}
				else if((coursedist[2] == 'DF' && coursedist[8] == 'MI') || ((coursedist[2] == 'PR' || coursedist[2] == 'PE' || coursedist[2] == 'PN') && coursedist[8] == 'MI'))
				{
					style = 'style = \"cursor:pointer;color:#79603C\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['military'];
				}
				else
				{
					style = 'style = \"cursor:pointer;color:#278E38\"';
					var iconimg = "flag-"+gmLocator.map.icon.iconType['public'];
				}
				
				company = coursedist[1];
				
				if(parseInt(coursedist[3]) > 1  && coursedist[5] != 'yes')
				{
					var iconimg = gmLocator.map.icon.iconType['sponsor'];
					company = "<strong>"+company.truncate(35)+"</strong>";
				}
						
				//w.onclick = "gmLocator.map.centerOnThis("+coursedist[4]+");";
				
				x.innerHTML="<img style=\"cursor:pointer\" onclick=\"gmLocator.map.centerOnThis("+coursedist[4]+")\" src=\"http://www.publiccourses.com/images/mapimages/"+iconimg+".gif\">";
				y.innerHTML="<span  "+style+" onclick=\"gmLocator.map.centerOnThis("+coursedist[4]+")\" class='gmaptip'>"+company.truncate(35)+"</span><br><span style=\"font-size:10px;cursor:pointer\" onclick=\"gmLocator.map.centerOnThis("+coursedist[4]+")\">"+coursedist[6]+", "+coursedist[7]+" ("+coursedist[0]+"mi.)</span>";
				
				//z.innerHTML=coursedist[0];	
				//z.align="center";
			}
		}
		
	},
	locations: [],
	locationsDist: [],
	orderName: false,
	orderNum: false
}