/*
Template: common.js
Purpose:  Provides JavaScript required by site, generally speaking.
Author:   Gerry Stanford (Some code snarfed from the web)
Date Written: November of 2007
*/

/* Function to allow an event to be added to window.onload, as some individual
pages need to do so and the main window.onload is located in a seoarate script. */
function addLoadEvent(func) {
	var oldonload = window.onload;
	if (typeof window.onload != 'function') {
		window.onload = func;
	} else {
		window.onload = function() {
        	oldonload();
			func();
		}
	}
}

/***************** SUCCESS STORIES *********************/
function resetJumpMenu(occ) {
	ob = document.getElementById("successStoryMenu");
	ob.options[occ].selected = true;
}
function loadFile(fn) {
	if (fn != "") {	window.frames.successStoryContent.location.href = fn; }
}
function init (occ) {
	setLinkToNewWindow();
	if (window.frames && window.frames.successStoryContent) {
		$('#subBtn').hide();
		resetJumpMenu(occ);
		$('#successStoryMenu').change( function() { loadFile('cm/'+this.options[this.selectedIndex].value); } );
	}
}
/*************** END SUCCESS STORIES *******************/


/* The following is to allow links to new windows, as HTML Strict does not allow
"target="_blank" in anchor tags. To use, just make sure the a tag to be linked
to a new window has a class of newwindow. */
function setLinkToNewWindow() {
	var links = document.getElementsByTagName('a');
    for (var i=0;i < links.length;i++) {
        if (links[i].className == 'newwindow') {
			links[i].onclick = function() {
                window.open(this.href);
                return false;
            };
        }
    }
}

//
// TRIMMING FUNCTIONS 
//
// Trim the left side of a value. 
function ltrim(argvalue) {
	while (1) {
    	if (argvalue.substring(0, 1) != " ") break;
		argvalue = argvalue.substring(1, argvalue.length);
	}
	return argvalue;
}
// Trim the right side of a value. 
function rtrim(argvalue) {
	while (1) {
		if (argvalue.substring(argvalue.length - 1, argvalue.length) != " ") break;
		argvalue = argvalue.substring(0, argvalue.length - 1);
	}
	return argvalue;
}
// Trim both sides of a value. 
function trim(argvalue) {
	var tmpstr = ltrim(argvalue);
	return rtrim(tmpstr);
}

