function init() {
	// Perform JavaScript availability actions
	jscheck();
	
	// Register "click" handler *Not supported by IE6...
	// document.addEventListener("click",click_handler,false);
}

// Write a cookie with JavaScript to test if it's enabled
function jscheck() {
	document.cookie = "JavaScript=on";
	var cookie = document.cookie;
	if( cookie.indexOf("PHPSESSID") >= 0 ) {
		var nav_section_warning = document.getElementById("nav_section_warning");
		var nav_choices_warning = document.getElementById("nav_choices_warning");
		if( nav_section_warning!=null )
			nav_section_warning.style.display = "none";
		if( nav_choices_warning!=null )
			nav_choices_warning.style.display = "none";
	}
}

function getXhr(){
	var xhr = null; 
	if(window.XMLHttpRequest)
	   xhr = new XMLHttpRequest(); 
	else if(window.ActiveXObject){ // Internet Explorer 
	   try { xhr = new ActiveXObject("Msxml2.XMLHTTP"); }
	   catch (e) { xhr = new ActiveXObject("Microsoft.XMLHTTP"); }
	}
	/*else {
	   alert("No XMLHTTPRequest support..."); 
	   xhr = false; 
	}*/
	return xhr
}

function out_gal(gal_id){
	var xhr = getXhr()
	/*xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			alert(xhr.responseText);
		}
	}*/
	xhr.open("POST","includes/out.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("gal_id="+gal_id);
}

function display_desc(id_gallery,current_nopage){
	var xhr = getXhr()
	xhr.onreadystatechange = function(){
		//alert("Inside:"+xhr.readyState+"-"+xhr.status+"<");
		if(xhr.readyState == 4 && xhr.status == 200){
			var gallery_desc = xhr.responseText;
			//alert(gallery_desc);
			document.getElementById('gallery_desc').innerHTML = gallery_desc;
			scroll(0,0);
		}
	}
	xhr.open("POST","/describe.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("id_gallery="+id_gallery+"&current_nopage="+current_nopage);
}

function display_dir(descriptions_nopage,display){
	var xhr = getXhr()
	xhr.onreadystatechange = function(){
		//alert("Inside:"+xhr.readyState+"-"+xhr.status+"<");
		if(xhr.readyState == 4 && xhr.status == 200){
			var directory = xhr.responseText;
			//alert(gallery_desc);
			document.getElementById('directory').innerHTML = directory;
			if(display=="thumbs")
				document.getElementById('galleries').style.display = "none";
			else
				document.getElementById('galleries_desc').style.display = "none";
			document.getElementById('promo_right').style.display = "none";
		}
	}
	xhr.open("POST","/ajax_directory.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("descriptions_nopage="+descriptions_nopage);
}

function click_desc(elmt){
	//elmt.id="blue";
	//alert(elmt.className);
	//alert(this.);
	//var xhr = getXhr()
	/*xhr.onreadystatechange = function(){
		if(xhr.readyState == 4 && xhr.status == 200){
			alert(xhr.responseText);
		}
	}
	var element = document.getElementById("nav_section_warning");
	xhr.open("POST","includes/out.php",true);
	xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	xhr.send("gal_id="+gal_id);*/
}

function addBookmark(url, title) 
{ 
  if (!url) url = location.href; 
  if (!title) title = document.title; 
  
  //Gecko
  // Commented because the bookmarked page opens in the sidebar...
  // Uncommented because it seems to be working in the latest version of Firefox
  if ((typeof window.sidebar == "object") && (typeof window.sidebar.addPanel == "function")) {
	  window.sidebar.addPanel (title, url, "");
	  //alert('Please use Ctrl-D or your browser\'s bookmark function to bookmark this page\n\tas not all browsers have an inpage bookmark function. Enjoy!');
  }
  //IE4+ 
  else if (typeof window.external == "object") window.external.AddFavorite(url, title); 
  //Opera7+ 
  else if (window.opera && document.createElement) 
  { 
    var a = document.createElement('A'); 
    if (!a) alert('Please use Ctrl-D or your browser\'s bookmark function to bookmark this page\n\tas not all browsers have an inpage bookmark function. Enjoy!'); //IF Opera 6 
    a.setAttribute('rel','sidebar'); 
    a.setAttribute('href',url); 
    a.setAttribute('title',title); 
    a.click(); 
  } 
  else alert('Please use Ctrl-D or your browser\'s bookmark function to bookmark this page\n\tas not all browsers have an inpage bookmark function. Enjoy!'); 
  
  return true; 
}

