// phUtils.js

var docloc = "" + document.location;
var docparts = docloc.split("/");
var docname = docparts[docparts.length-1];
if (docname == "") docname = "index.html";

// query for slideshow(index)

var query = "";
var query_pos = docname.indexOf("?");
if (query_pos != -1)
{
	var query = docname.substring(query_pos+1);
	docname = docname.substring(0,query_pos);
}

var docroot = docname.replace(/\.html.*/,"");
	// docroot = the unique id of the page
var root_dir = "/";
	// root dir = a site relative path to the
	// www directory, set specially for file:// urls
	if (docloc.match("file://"))
	{
		root_dir = "";
		for (i=0; i<docparts.length && docparts[i] != "www"; i++)
		{
			root_dir += docparts[i]+"/";
		}
		root_dir += "www/";
	}
var file_dir = root_dir + "files/" + docroot + "/";
	// the directory for unqualified content file names
	// (the files owned by this html file)


//------------------------------------------
// Utilities
//------------------------------------------

function dbg(level,msg)
{
	if (level<=debug_level) 
		if ((typeof console != 'undefined') && console && console.log) 
			console.log(msg);
}

function setCookie(c_name,value,expiredays)
	// cookies dont work very well with file:// protocol
	// at least at this time in firefox, so don't set them 
{
	if (root_dir == "/")
	{
		dbg(9,"SetCookie("+c_name+","+value+")");
		var exdate=new Date();
		exdate.setDate(exdate.getDate()+expiredays);
		document.cookie = 
			c_name + "=" +/*escape(*/value/*)*/+ "; " +
			((expiredays==null) ? "" : "expires="+exdate.toGMTString() + "; ") +
			"path=/";
	}
}

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;
			tcookie = /*unescape(*/document.cookie.substring(c_start,c_end)/*)*/;
			dbg(9,"Got cookie("+c_name+")="+tcookie);
			return tcookie;
		}
	}
}


function prettyDate(from_date)
{
	var month = [
		"January",
		"Februrary",
		"March",
		"April",
		"May",
		"June",
		"July",
		"August",
		"September",
		"October",
		"November",
		"December"];
	var from_parts = from_date.match(/(\d\d\d\d)-(\d\d)-(\d\d)/);
	var retval = 
		month[ from_parts[2]-1 ] + " " + 
		from_parts[3] + ", " +
		from_parts[1];
	return retval;
}

