function clearSearchBox(searchBox, defaultValue)
{
   if (searchBox.value == defaultValue)
   {
      searchBox.value = '';
   }
}
//------------------------------------------------------------------------------------
//this function hide/displays articles
// in: obj = div name
function displayMenu(obj) 
{
	var el = document.getElementById(obj);
	var filters=new Array("stories_locations","stories_subjects", "stories_practitioners");


	if ( el.style.display == "block" ) 
	{			        
		el.style.display = "none";	
		setCookie(obj, "none", 365);
	}
	else 
	{
		
		//stories filters		
		$(obj).getElementsBySelector('li a').each(function(a)
		{			
			a.up(1).getElementsBySelector('a.filter_selected').invoke('removeClassName','filter_selected');
			
		});		

		el.style.display = "block";		
		setCookie(obj, "block", 365);

		for(var x in filters)
		{		
			var cookieValue = getCookie(filters[x])
			if(cookieValue!=null && cookieValue!="")
			{
				var el2 = nodeGet(filters[x]);
				if(el!=el2)
				{
					el2.style.display = "none";	
					setCookie(filters[x], "none", 365);					
				}
			}
		}	

	}
}
//------------------------------------------------------------------------------------
//This function adjust the height of the left_bar to 100% of the parent height;
//not in use
function AdjustCols(obj) {

	var elm = document.getElementById(obj);
	elm.style.height = 'auto';
	var x = elm.offsetHeight;
	elm.style.height = x + "px";
}
//--------------------------------------------------------------------------------------------------------------------------
// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) 
{
	if ( getCookie( name ) )
	{
		document.cookie = name + "=" + ( ( path ) ? ";path=" + path : "") + ( ( domain ) ? ";domain=" + domain : "" ) + ";expires=Thu, 01-Jan-1970 00:00:01 GMT";
	}
}

//--------------------------------------------------------------------------------------------------------------------------

function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=")
  if (c_start!=-1)
    { 
    c_start=c_start + c_name.length+1 
    c_end=document.cookie.indexOf(";",c_start)
    if (c_end==-1) c_end=document.cookie.length
    return unescape(document.cookie.substring(c_start,c_end))
    } 
  }
return ""
}

//-----------------------------------------------------------------------------------------------------------------------
function setCookie(c_name,value,expiredays)
{
	var exdate=new Date()
	exdate.setDate(exdate.getDate() + expiredays)
	document.cookie = c_name + "=" + escape(value) +	((expiredays==null) ? "" : "; expires=" + exdate.toGMTString())
}

//-----------------------------------------------------------------------------------------------------------------------
//This function gets the filter state from cookie and reloads it.
function LoadFilterState()
{
	var filters=new Array("stories_list","stories_locations","stories_subjects","stories_themes", "stories_latest", "stories_practitioners");

	for(var x in filters)
	{		
		var cookieValue = getCookie(filters[x])
		if(cookieValue!=null && cookieValue!="")
		{
			var el = document.getElementById(filters[x]);
			el.style.display = cookieValue;			
		}
	}	
	
}
//-----------------------------------------------------------------------------------------------------------------------
function include(pURL, div) 
{
	lang_code = getCookie('lang_code');
	pURL = pURL + '_' + lang_code + '.xml';
	//alert(pURL);
	xmlHttp=GetXmlHttpObject();
	
	if (xmlHttp==null)
	{
		alert ("Your browser does not support AJAX!");
		return;
	}
	
	//this section defines the action for the xml http request object
	xmlHttp.onreadystatechange=function()
	{			
		//ready state 4 is triggered when loading is complete
		if (xmlHttp.readyState==4)
		{	
			document.getElementById(div).innerHTML=xmlHttp.responseText;
		}
	}

	//send request, by calling the open/send method of the xml http object
	xmlHttp.open("GET",pURL,true);
	xmlHttp.send(null);

}
//----------------------------------------------------------------------------------------------------------------
//GET XML HTTP REQUEST OBJECT
// out: xml http request object
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 InItStoryIndex() 
{
	var URL = unescape(document.referrer);
	var path = URL.split("/");
	var refURL = path[path.length-1].split("?");
	

	//alert("prevURL = "+getCookie('prevURL'));
	//alert("referrer = " + refURL[0]);
	if(getCookie('prevURL')==refURL[0])
	{
		//retrieve filtered page from cookie
		//reload the page using AJAX
		var url = "table_contents.aspx;";
		if(getCookie('url')!=null)
			url = getCookie('url');
		GoToFilteredPage(url);

		if(getCookie('selectedFilter')!=null)
		{
			var el = getCookie("selectedFilter");
			try{
				$(el).addClassName('filter_selected');
			}catch(err){}
		}	
		//reload selected filters from cookie
		LoadFilterState();		
	}
	

	//stories filters
	$$('ul.menuToDiv').each(		
		function(ul)
		{
			//alert(ul.attributes.getNamedItem('id').value);
			ul.getElementsBySelector('ul li a').each(function(a)
			{
				//alert(a.id);
				a.onclick=function()
				{	
					new Ajax.Updater($('storyFilters').readAttribute('rel'),  a.href);											

					a.up(1).getElementsBySelector('a.filter_selected').invoke('removeClassName','filter_selected');
					a.addClassName('filter_selected');			   
					setCookie("selectedFilter", a.attributes.getNamedItem("id").value, 365); 
					setCookie("url", a.href, 365);  
					setCookie("prevURL", refURL[0], 365);

					return false;
				}
			});


			


			ul.getElementsBySelector('li a.main_filter').each(
				function(a)
				{
					a.onclick=function()
					{
						new Ajax.Updater($('storyFilters').readAttribute('rel'),  a.href);						

						a.up(1).getElementsBySelector('a.filter_selected').invoke('removeClassName','filter_selected');					
						setCookie("url", a.href, 365); 
						var filters=new Array("stories_locations","stories_subjects", "stories_practitioners");	
						$('stories_locations').style.display="none";
						$('stories_subjects').style.display="none";
						$('stories_practitioners').style.display="none";
						
						return false;					
						
					}
				}
			);
		});   
}

function InItAlbum()
{
	//photo gallery and album_details
	location.href='#albumDiv';
	location.href="#album_ex_albumDiv";
}

//----------------------------------------------------------------------------------------------------------------
//collapse all open filters
function collapse()
{	
	var filters=new Array("stories_locations","stories_subjects", "stories_practitioners");	
	for(var x in filters) $(filters[x]).style.display = "none";		
	return false;
}

//----------------------------------------------------------------------------------------------------------------
//reload div with filtered data
function GoToFilteredPage(url)
{ 
	 var hash = Math.random(); 
	 var pars = 'hash='+hash;
	 var ajax = new Ajax.Updater({success: 'storiesDiv'},url,{method: 'post', parameters: pars, evalScripts: false});          
}     



//----------------------------------------------------------------------------------------------------------------
//gets the Node
function nodeGet(id)
{
	var result;
	if(id)
	{
		if(id.nodeType){ //param is node object
			result = id;
		}else{ //param is text id
			result = document.getElementById(id);
		}
	}
	return result;
}