String.prototype.startsWith = function(str) {return (this.match("^"+str)==str)}
String.prototype.endsWith = function(str) {return (this.match(str + "$")==str)}
String.prototype.trim = function() {return this.replace(/^\s+|\s+$/g, '')}

function show( id ) { 
	if(document.getElementById(id) != null)
		document.getElementById(id).style.display = ''; 
} 
function hide( id ) { 
	if(document.getElementById(id) != null)
		document.getElementById(id).style.display = 'none';
}

function getXMLHttpRequest () {
	
	try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {};
	try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {};
	try { return new XMLHttpRequest(); } catch(e) {};
    return null;
}


function popUp(URL) {
	window.open(URL, 'notes', 'toolbar=0,scrollbars=1,location=0,statusbar=1,menubar=0,resizable=1,width=400,height=300');
}

function setAll() {
	// this function is called on a screen when the checkbox at the top is toggled
	// we want to find all checkboxes named "selected[]" and make them the same as this one

	var theForm = document.getElementById("selectionForm");
	var masterChecked = document.getElementById("checkMaster").checked;
	var theElement;

	for(i=0; i < theForm.elements.length; i++) {
		theElement = theForm.elements[i];
		if(theElement.name == "selected[]") {
			theElement.checked = masterChecked;
		}
	}
}

function htmlspecialchars(str) {
	if (typeof(str) == "string") {
		str = str.replace(/&/g, "&amp;"); /* must do &amp; first */
		str = str.replace(/"/g, "&quot;");
		str = str.replace(/'/g, "&#039;");
		str = str.replace(/</g, "&lt;");
		str = str.replace(/>/g, "&gt;");
	}
	return str;
}

function showDescription(thumbUrl, title, description, e) {
	document.getElementById('descriptionPopup').style.display = '';
	document.getElementById('descriptionPopup').innerHTML = 
		"<img src='" + thumbUrl + "'><div><h2>" + title + "</h2></div><div>" + description + "</div>";
	positionDescription(e);
}

function positionDescription(e) {
	document.getElementById('descriptionPopup').style.left = e.clientX + 10 + "px";
	document.getElementById('descriptionPopup').style.top = e.clientY + 10 + "px";
}

function hideDescription() {
	document.getElementById('descriptionPopup').style.display = 'none';
}