var xmlHttp;

function GetXmlHttpObject(){
	var xmlHttp=null;
	try  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	 } catch (e)  {
		// Internet Explorer
		try{
			xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
		}catch (e){
		xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
		}
	}
	return xmlHttp;
}




function DeleteMessage(MessageID,sent){
	if (confirm('OK to delete this message?'))
		document.location.href="/messagedelete.php?Sent="+sent+"&MessageID="+MessageID;
}


function DeleteImage(ImageID,ImageKey,Mode,ReturnTo){
	if (confirm('OK to delete this picture?'))
		document.location.href="imagedelete.php?Mode="+Mode+"&ImageID="+ImageID + "&ImageKey="+ImageKey + "&ReturnTo=" + ReturnTo;
}


function DeleteParkPhoto(ImageID,ImageKey,ParkID,Index){
	if (confirm('OK to remove this photo?'))
		document.location.href="imagedelete.php?Mode=P&ImageID="+ImageID + "&ImageKey="+ImageKey + "&Index="+Index+"&ParkID=" + ParkID;
}

function showCampgroundDetails(divID){
	var display = 'none';

	if(divID==0)
		display='block';
	

	for (i=1;i<6;i++){		
		if(divID==i){
			document.getElementById('cg'+i).style.display='block';					
			document.getElementById('cg'+i).style.height='400px';
		}else{
			document.getElementById('cg'+i).style.display=display;
			document.getElementById('cg'+i).style.height='';
		}
		

	}
}

function toggleCG(SiteID, boolChecked){
	document.location.href="toggleselect.php?SiteID="+SiteID+"&checked="+boolChecked;
}

function CookieSite(objCheckBox){

 var CheckedSites=Get_Cookie('CheckedSites');

 if (CheckedSites==null){
  CheckedSites = '';
 }

 // alert(objCheckBox.value);

 
  if (objCheckBox.checked){ 
    Set_Cookie('CheckedSites', CheckedSites + ' ' + objCheckBox.value,1,'/', '', '' );
  } else {
   CheckedSites=CheckedSites.replace(objCheckBox.value,'');
   Set_Cookie('CheckedSites', CheckedSites,1,'/', '', '' );
 } 

}

// this function gets the cookie, if it exists
function Get_Cookie(name) {
 var start = document.cookie.indexOf( name + "=" );
 var len = start + name.length + 1;
 if ((!start) && (name != document.cookie.substring(0, name.length))){
  return null;
 }

 if (start == -1){
  return null;
 }

 var end = document.cookie.indexOf( ";", len );
 if ( end == -1 ) end = document.cookie.length;
 return unescape(document.cookie.substring(len, end));
}
	


function Set_Cookie(name,value,expires,path,domain,secure) {
 // set time, it's in milliseconds
 var today = new Date();
 today.setTime(today.getTime());

 if(expires){
  expires=expires*1000*60*60*24;
 }
 var expires_date = new Date(today.getTime()+(expires));

 document.cookie = name + "=" +escape(value) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}



function ClearSelect(){
 if (confirm("OK to remove all selected camprounds from list?"))
  document.location='clearselect.php';
}





// ====================================================================
//       URLEncode and URLDecode functions
//
// Copyright Albion Research Ltd. 2002
// http://www.albionresearch.com/
//
// You may copy these functions providing that 
// (a) you leave this copyright notice intact, and 
// (b) if you use these functions on a publicly accessible
//     web site you include a credit somewhere on the web site 
//     with a link back to http://www.albionresarch.com/
//
// If you find or fix any bugs, please let us know at albionresearch.com
//
// SpecialThanks to Neelesh Thakur for being the first to
// report a bug in URLDecode() - now fixed 2003-02-19.
// ====================================================================
function URLEncode(ecode)
{
	// The Javascript escape and unescape functions do not correspond
	// with what browsers actually do...
	var SAFECHARS = "0123456789" +					// Numeric
					"ABCDEFGHIJKLMNOPQRSTUVWXYZ" +	// Alphabetic
					"abcdefghijklmnopqrstuvwxyz" +
					"-_.!~*'()";					// RFC2396 Mark characters
	var HEX = "0123456789ABCDEF";

	var plaintext = ecode;
	var encoded = "";
	for (var i = 0; i < plaintext.length; i++ ) {
		var ch = plaintext.charAt(i);
	    if (ch == " ") {
		    encoded += "+";				// x-www-urlencoded, rather than %20
		} else if (SAFECHARS.indexOf(ch) != -1) {
		    encoded += ch;
		} else {
		    var charCode = ch.charCodeAt(0);
			if (charCode > 255) {
			    alert( "Unicode Character '" 
                        + ch 
                        + "' cannot be encoded using standard URL encoding.\n" +
				          "(URL encoding only supports 8-bit characters.)\n" +
						  "A space (+) will be substituted." );
				encoded += "+";
			} else {
				encoded += "%";
				encoded += HEX.charAt((charCode >> 4) & 0xF);
				encoded += HEX.charAt(charCode & 0xF);
			}
		}
	} // for
 
	return encoded;
}

function URLDecode(ecode )
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = ecode;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
 
   return plaintext;
}
 

function popup(doc, sh, sw){
	var opts = "";
	
	var l = (screen.width - sw) / 2;
	var t = (screen.height - sh) / 2;
	
	opts = "scrollbars=yes";
	opts += ",width=" + sw ;
	opts += ",height=" + sh ;
	opts += ",top=" + t;
	opts += ",left=" + l;
	opts += ",address=no";
	opts += ",directories=no";
	opts += ",location=no";
	opts += ",menubar=no";
	opts += ",status=no";
	opts += ",toolbar=no";
	opts += ",resizable=no";
	
	window.open(doc,'',opts);

}


function help(doc){
 popup('help-'+doc+'.php',600,600);
}

function LaunchEmail(ToWho){

 
 window.open('mailto:'+ ToWho);

}




function leftTrim(sString){
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	return sString;
}


function rightTrim(sString){
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}


function allTrim(sString) {
	while (sString.substring(0,1) == ' '){
		sString = sString.substring(1, sString.length);
	}
	while (sString.substring(sString.length-1, sString.length) == ' '){
		sString = sString.substring(0,sString.length-1);	
	}
	return sString;
}



