var strBaseURL = "";

function Left(str, n){
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}
function Right(str, n){
    if (n <= 0)
       return "";
    else if (n > String(str).length)
       return str;
    else {
       var iLen = String(str).length;
       return String(str).substring(iLen, iLen - n);
    }
}

	/* ===================================
	General functions used across the site
	====================================== */
	// Show or hide an element with a given ID
	// Change the corresponding +/- sign (if it exists)
	function ShowHide(id) {
		if (document.getElementById(id)) {
			if (document.getElementById(id).style.display == "block") {
				document.getElementById(id).style.display = "none";
				if (document.getElementById('img_' + id))
					document.getElementById('img_' + id).src = strBaseURL + "images/plus.gif"
			} else {
				document.getElementById(id).style.display = "block";
				if (document.getElementById('img_' + id))
					document.getElementById('img_' + id).src = strBaseURL + "images/minus.gif";
			}
		}
	}
	// Show an element with a given ID
	// Change the corresponding +/- sign (if it exists)
	function Show(id) {
		if (document.getElementById(id)) {
			document.getElementById(id).style.display = "block";
			if (document.getElementById('img_' + id))
				document.getElementById('img_' + id).src = strBaseURL + "images/minus.gif";
		}
	}
	// Hide an element with a given ID
	// Change the corresponding +/- sign (if it exists)
	function Hide(id) {
		if (document.getElementById(id)) {
			document.getElementById(id).style.display = "none";
			if (document.getElementById('img_' + id))
				document.getElementById('img_' + id).src = strBaseURL + "images/plus.gif";
		}
	}

	// Recursively show all elements above a given one
		function ShowRecursive(id) {
		Show(id);
		if (document.getElementById(id)) {
			if (document.getElementById(id).parentid) {
				ShowRecursive(document.getElementById(id).parentid);
			}
		}
	}

	/* ===================================
	Functions used in the menu frame
	====================================== */
	// Set the selected menu item to a specified ID
	// Expands menu items above this to ensure it is displayed
	// Called from the content frame
	function SetSelectedID(id) {
		if (document.getElementById('SelectedID').value != '') {
			if (document.getElementById(document.getElementById('SelectedID').value)) {
				document.getElementById(document.getElementById('SelectedID').value).className = '';
			}
		}
		if (document.getElementById(id)) {
			document.getElementById('SelectedID').value = id;
			document.getElementById(id).className = 'SelectedMenu';
		} else {
			var regEx = /_i\d+/;
			id = id.replace(regEx, '_i0');
			if (document.getElementById(id)) {
				document.getElementById('SelectedID').value = id;
				document.getElementById(id).className = 'SelectedMenu';
			}
		}
		id = id.replace('-', '');
		Show(id.substring(0, id.lastIndexOf('_')));
	}
	
	// Reload the menu - called from the content frame when a publication or issue has changed
	function ReloadMenu() {
		document.getElementById('Form1').submit();
	}
	function ReloadMenu(id) {
		document.getElementById('SelectedID').value = id;
		document.getElementById('Form1').submit();
	}
	
	
	/* ===================================
	Functions used in the menu frame
	====================================== */
	// Highlight a given menu item
	function HighlightMenu(id) {
		HighlightMenu2(id, 20);
	}
	// Called by HighlightMenu above
	// First checks that the menu frame is loaded
	// If not, waits until it is
	// Then calls SetSelectedID()
	function HighlightMenu2(id, intTries) {
		if (window.top.frameMenu.document.getElementById(id)) {
			window.top.frameMenu.SetSelectedID(id);
		} else {
			if (intTries > 0)
				setTimeout("HighlightMenu('" + id + "', " + (intTries-1) + ");", 100);
		}
	}

