// Manifesto: $Id: library.js,v 1.15 2006/11/28 15:00:57 spud Exp $
// license: GNU LGPL
// copyright 2001-2004: dada typo and contributors

function isEmpty(s) { return ((s == null) || (s.length == 0)) }
function isWhitespace(s) {
	if (isEmpty(s)) return true;
	if (s == "\t") return true;
	if (s == "\n") return true;
	if (s == "\r") return true;
	return false;
}
function hasWhitespace(s) {
	var i;
	var whitespace = " \t\n\r";
	for (i = 0; i < s.length; i++) {
		var c = s.charAt(i);
		if (whitespace.indexOf(c) != -1) return true;
	}
	return false;
}
function isValidEmail(str) {
	var emailpat = /^[\w\.]+@[\w\.]+\.?[\w\.]?\.\w{2,4}/;
	if (emailpat.test(str)) {
		return true;
	} else {
		return false;
	}
}
function inArray(arr,item) {
	if (typeof arr != "object") return false;
	for(var i=0;i<arr.length;i++) {
		if (arr[i] == item) return true;
	}
}
function get_subdir(form) {
	var fname = form.filename.value;
	var num = 0;
	for (var x = 0; x < fname.length; x++) {
		num += fname.charCodeAt(x);
	}
	var total = num % 13 + 1;
	window.alert("Subdirectory for " + fname + " should be "  + total);
	return false;
}
function newWin(url) {
	if (arguments.length > 1) {
		var height = arguments[1];
		var width = arguments[2];
	} else {
		var height = 400;
		var width = 400;
	}
	if (arguments.length == 4) {
		window.open(url,'New','top=80,left=80,width='+width+',height='+height+','+arguments[3]);
	} else {
		window.open(url,'New','top=80,left=80,width='+width+',height='+height+',toolbar=no,menubar=no,scrollbars=yes');
	}
	return false;
}
function showHide(ref,disp) {
	if ((disp == 'table-row-group' || disp == 'table-row') && navigator.appName.indexOf("Microsoft") > -1) {
		disp = 'block';
	}
	if (typeof ref == "string") {
		ref = getObjectRef(document,ref);
	}
	if (ref) {
		if (ref.style.display == disp) {
			ref.style.display = 'none';
		} else {
			ref.style.display = disp;
		}
	}
	return false;
}
menuactive = 0;
timeOn = null;
m = null;
function showMenu() {
	var obj = getObjectRef(document,m);
	// hide all the other menus now
	var navrow = obj.parentNode.parentNode;
	var childdivs = navrow.getElementsByTagName('div');
	for(var i=0;i<childdivs.length;i++) {
		if (childdivs[i].className == 'dhtmlmenu') {
			childdivs[i].style.display = 'none';
		}
	}
	if (timeOn != null) {
		clearTimeout(timeOn);
		hideMenu();
	}
	obj.style.display = 'block';
	return false;
}
function hideMenu() {
	if (menuactive == 0) {
		var obj = getObjectRef(document,m);
		obj.style.display = 'none';
	}
	return false;
}
function menuMouseOver(obj) {
	clearTimeout(timeOn);
	menuactive = 1;
}
function menuMouseOut(obj) {
	menuactive = 0;
	setTimeout('hideMenu()', 400)
}
function setTimer() {
 timeOn = setTimeout('timedOut()',800)
}
function timedOut() {
	hideMenu();
}
