

function addLoadEvent(func) {
  var oldonload = window.onload;
  if (typeof window.onload != 'function') {
    window.onload = func;
  } else {
    window.onload = function() {
      oldonload();
      func();
    }
  }
}

//addLoadEvent(nameOfSomeFunctionToRunOnPageLoad);
//addLoadEvent(function() {
//  /* more code to run on page load */ 
//});
//http://www.sitepoint.com/blogs/2004/05/26/closures-and-executing-javascript-on-page-load/


function hideAllBut (className) {
	var all = document.all ? document.all :
		document.getElementsByTagName('*');
	var elements = new Array();
	var classen = new Array();
	var included = new Boolean();
	var icon = new Boolean();
	for (var e = 0; e < all.length; e++){
		included = false;
		icon = false;
		classen = all[e].className.split(" ");
		for (var c = 0; c < classen.length; c++){
			if (classen[c] == "catthumb"){
				icon = true;
			}
			if (classen[c] == className){
				included = true;
			}
		}
		if (icon == true && included == false){
			all[e].style.display = "none";
		} else if (icon == true && included == true) {
			all[e].style.display = "block";
		}
	}						
}

function showMyCategory (catname) {
    var showthis = '';
    if(!catname) { 
        showthis = 'All Stories';
    } else {
        showthis = catname;    
    }
	document.getElementById("catname").innerHTML = showthis;
}

function showMyTitle (title) {
    var showthis = '';
    if(!title) { 
        showthis = '(choose a story)';
    } else {
        showthis = title;    
    }
	document.getElementById("storyname").innerHTML = showthis;
}

function rtrim(strInput) {

  while (1) {
    if (strInput.substring(strInput.length - 1, strInput.length) != " ")
      break;
    strInput = strInput.substring(0, strInput.length - 1);
  }

  return strInput;
}

function ltrim(strInput) {

  while (1) {
    if (strInput.substring(0, 1) != " ")
      break;
    strInput = strInput.substring(1, strInput.length);
  }

  return strInput;
}

function trim(strInput) {
  var tmpstr = ltrim(strInput);

  return rtrim(tmpstr);

}

function sentencecase(strInput)
{
	strInput = trim(strInput);
	strInput = ' ' + strInput;
	strInput=strInput.toLowerCase();
	var firstcharlc=strInput.charAt(1);
	var firstcharuc=firstcharlc.toUpperCase();
	firstcharuc = " " + firstcharuc;
	firstcharlc = " " + firstcharlc;
	strInput=strInput.replace(firstcharlc, firstcharuc);

	strInput=trim(strInput);

	var len = strInput.length;
	
	var spacePos = strInput.indexOf(' ');

	while (spacePos != -1) {
		var firstcharlc = strInput.charAt(spacePos+1);
		var firstcharuc=firstcharlc.toUpperCase();
		firstcharuc = " " + firstcharuc;
		firstcharlc = " " + firstcharlc;
		strInput=strInput.replace(firstcharlc, firstcharuc);
		strInput=trim(strInput);
		spacePos = strInput.indexOf(' ',spacePos+1);
	}
	
	return strInput;
}

function frontMousing(strInput)
{
	document.getElementById('front_blurb').className = 'active';
	document.getElementById('front_blurb').innerHTML = strInput;
}

function frontNormal()
{
	document.getElementById('front_blurb').className = 'idle';
	document.getElementById('front_blurb').innerHTML = '<p>&nbsp;</p>';
}