
var itemswindow;
function popitem_window(details,imw,imh)
{
if (itemswindow)
		{
		itemswindow.close();
		}
    w=imw+30;
    h=imh+80;
	itemswindow=window.open(details, "FullSize", "toolbar=no,menubar=no,scrollbars=yes,directories=no,width="+w+",height="+h);
	itemswindow.focus();
	return false;

}

function change_campgrounds_status(theStatus)
	{
	theLoc=self.location;
	if (theStatus==true)
		{
		theLoc=theLoc+'&shcmpg=1';
		}
	else
		{
		theLoc=theLoc+'&shcmpg=2';		
		}
	theLoc=str_replace('.php?', '.php', theLoc);
	theLoc=str_replace('.php', '.php?', theLoc);
	window.location=theLoc;	
	}
	


function str_replace(search, replace, subject) {
   
    var f = search, r = replace, s = subject;
    var ra = r instanceof Array, sa = s instanceof Array, f = [].concat(f), r = [].concat(r), i = (s = [].concat(s)).length;
 
    while (j = 0, i--) {
        if (s[i]) {
            while (s[i] = (s[i]+'').split(f[j]).join(ra ? r[j] || "" : r[0]), ++j in f){};
        }
    };
 
    return sa ? s : s[0];
}

		
	
/** WEATHER SEARCH **/
function weather_lookup(inputString) 
		{
		if(inputString.length == 0) 
			{
			// Hide the suggestion box.
			$('#weather_suggestions').hide();
			} 
		else 
			{
			inputString=inputString+"1WEATHER1";
			$.post("_ajax/autocomplete.ajax.php", {queryString: ""+inputString+""}, 
			function(data)
				{
				if(data.length >0) 
					{
					$('#weather_suggestions').show();
					$('#weather_autoSuggestionsList').html(data);
					}
				});
			}
		} // lookup

	function weather_fill(thisValue) {
		
		$('#weather_inputString').val(thisValue);
		setTimeout("$('#weather_suggestions').hide();", 200);
	}
	
function sm_weather_search(inputString)
	{		
	$.post("_ajax/sm_weather.ajax.php", {queryString: ""+inputString+""}, 
		function(data)
			{			
			if(data.length >0) 
				{				
				$('#SmWeather').html(data);
				}
			});
	
	}
	
	
//
var iFrameLoaded=new Array();
function showhide_path_iframe(theId,parentid,countid)
	{	
	theelement=document.getElementById(theId);
	if (theelement.style.display=='none')
		{
		theelement.style.display='';	
		if (iFrameLoaded[countid]!=1)
			{
			theelement.src="find_a_path_iframe.php?resId="+parentid+"&theCount="+countid;
			//iFrameLoaded[countid]=1;
			}
		}
	else
		{
		theelement.style.display='none';
		//theelement.src="find_a_path_iframe.php?resId="+parentid+"&theCount="+countid;		
		}
	
	}
	

function dist_between_to_zoom(tdistance)
	{
	var	theZoom=5;	
	var Adjuster=-1;
	if (tdistance<40)
		{
		theZoom=11;
		}
	if (tdistance<80)
		{
		theZoom=10;
		}
	else if (tdistance<120)
		{
		theZoom=9;
		}	
	else if (tdistance<200)
		{
		theZoom=8;
		}	
	else if (tdistance<500)
		{
		theZoom=7;
		}
	else if (tdistance<1200)
		{
		theZoom=6;
		}
	
	theZoom=theZoom+Adjuster;
	return theZoom;	
	}
	



function link_tracker(dsturl,compid) 
	{
    if(document.images)
		{
        (new Image()).src="_click_track.php?dsturl="+dsturl+"&cpid="+compid+"&frmloc="+document.location;
	    }    
	}
	
	
function swap_home_img_rollovers(theid,theimg)
	{
	document.getElementById(theid).style.background="url("+theimg+")";	
	}
	
	
/***********************
* G MAPS API ON DEMAND *
***********************/
	var map;
	var geocoder = null;
	var marker = null;
	
function handleApiReady() {
    var myLatlng = new google.maps.LatLng(-26,134);
    var myOptions = {
      zoom: 4,
      center: myLatlng,
	  scrollwheel: false,
      mapTypeId: google.maps.MapTypeId.ROADMAP
    }
    //var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	var geocoder = new google.maps.Geocoder();
	map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
	
	google.maps.event.addListener(map, 'click', function(event) 
		{
		resetMap();
	    placeMarker(event.latLng);
		//document.getElementById("txtLatitude").value = event.latLng.toUrlValue(6);
		theEventLat=event.latLng.lat(1);
		theEventLat=round_the_latlong(theEventLat);
		
		
		theEventLong=event.latLng.lng(1);
		theEventLong=round_the_latlong(theEventLong);
		
    	document.getElementById("txtLatitude").value = theEventLat;
    	document.getElementById("txtLongitude").value = theEventLong;
    	
		});
  }
  
  	
function placeMarker(location) {
  marker = new google.maps.Marker({
      position: location, 
      map: map
  });
  
  map.setCenter(location);
  
 // document.getElementById('txtLatitude').value = marker.lat();
 // document.getElementById('txtLongitude').value = marker.lat();

}
 	
function resetMap() 
	{
	//infowindow.close();
	
	  if (marker != null) 
		{
		marker.setMap(null);
		marker = null;
		}
  
	}
	

function round_the_latlong(theval)
	{
	theval=theval*10000;
	theval=Math.round(theval);
	theval=theval/10000;
	return theval;
	}
	
	
	
 function display_map_holder()
 	{
	document.getElementById('HomeMap_Vis').innerHTML=document.getElementById('HomeMap_Hidden').innerHTML;
    
	}
  
 function appendBootstrap() {
	var script = document.createElement("script");
    script.type = "text/javascript";
    script.onload = function() {
      //google.maps.loadScripts();
    };
    script.onreadystatechange= function () {
      if (this.readyState == 'loaded' || this.readyState == 'complete') {
        google.maps.loadScripts();
      }
    };
    script.src = "http://maps.google.com/maps/api/js?sensor=false&callback=handleApiReady";
    document.body.appendChild(script);
  display_map_holder();
  }


function change_dd_value(theId,theVal)
	{		
	document.getElementById(theId).value=theVal;	
	}
	
function load_town_names(theStateid,selectElementId,checkedVal)
	{	
	$.getJSON("_jqphp/search_dd1.php",{wih: 'TR1', stateid: theStateid, ajax: 'true'}, function(j){
      var options = '';
      for (var i = 0; i < j.length; i++) 
	  	{
		checkdisplay='';
		if (checkedVal==j[i].optionValue)
			{
			checkdisplay='  selected="selected"';			
			}
        options += '<option value="' + j[i].optionValue + '" '+checkdisplay+'>' + j[i].optionDisplay + '';
      	}
    $("select#"+selectElementId).html(options);
    })
	}



	
function load_lightbox_gallery(idName)
	{
		$(function() {
        $('#'+idName+' a').lightBox();
    });
	}



 function placeMarker(location) {
  marker = new google.maps.Marker({
      position: location, 
      map: map
  });
  
  map.setCenter(location);
  
 // document.getElementById('txtLatitude').value = marker.lat();
 // document.getElementById('txtLongitude').value = marker.lat();

}
function round_the_latlong(theval)
	{
	theval=theval*10000;
	theval=Math.round(theval);
	theval=theval/10000;
	return theval;
	}
	
	
function resetMap() 
	{
	//infowindow.close();
	
	  if (marker != null) 
		{
		marker.setMap(null);
		marker = null;
		}
  
	}
 function createLetterMarker(lat,long, index,thetext)
  		{
		var letter = String.fromCharCode("A".charCodeAt(0) + index);        
		var image = "http://www.wilddownunder.com/images/maps/marker/marker" + letter + ".png";
        if (letter=='A')
			{
			var image = "http://www.wilddownunder.com/images/maps/marker/yellow" + letter + ".png";
        	}
		
		var latlng = new google.maps.LatLng(lat,long);		 
		var infowindow = new google.maps.InfoWindow({
			content: thetext
		});
		var marker = new google.maps.Marker({
			position: latlng,
			map: map,
		icon: image
		});
		google.maps.event.addListener(marker, 'click', function() {
		  infowindow.open(map,marker);
		});
		
		}
		
		
	function createcampmarker(lat,long, thetext,ico)
  		{		

		var image = "http://www.wilddownunder.com/images/_map_ico/"+ico;
      
		var latlng = new google.maps.LatLng(lat,long);		 
		var infowindow = new google.maps.InfoWindow({
			content: thetext,
			 maxWidth: 420,
			 pixelOffset: new google.maps.Size(0,10)
		});
		var marker = new google.maps.Marker({
			position: latlng,
			map: map,
		icon: image
		});
		google.maps.event.addListener(marker, "click", function(e) {
			infowindow.open(map,marker);
    	});
		
		}



		
	
	
