/* $Id: common.js,v 1.1 2002/07/06 03:37:16 jeroen Exp $ */

function validateEmail(s) {
	var re = /^[0-9a-zA-Z_\.]+@[0-9a-zA-Z\-\.]+\.[0-9a-zA-Z]+$/;
	return re.test(trim(s));
}

// removes any erroneous whitespaces
function trim(s) {
	var left = /^\s+/;
	var right = /\s+$/;
	return s.replace(right,"").replace(left,"");
}

function empty(s) {
	return (trim(s)=="");
}

function popup(url) {
	var options = "width="+screen.availWidth/2+",height="+screen.availHeight/2+",scrollbars=yes,resizable=yes,toolbar=no";
	pw = window.open(url, 'pw', options);
	pw.focus();
}

function toNumber(fld) {
	var tmp = "";
	s = fld.value;
	for (var i=0; i<s.length; i++) {
		if (!isNaN(s.charAt(i))&&s.charAt(i)!=" ") {
			tmp += s.charAt(i);
		}
	}
	if (tmp == "") tmp = 0;
	fld.value = tmp;
}

function validateFloat(name) {
	if (trim(name.value)=="") return false;
	return !isNaN(name.value);
}

// returns true when value is element in array, false otherwise
function isPartOf(val, ar) {
	for (var i = 0;i<ar.length;i++) {
		if (val == ar[i]) {
			return true;
		}
	}
	return false;
}

function redirect(url, target) {
	if (url != '#' && url != '') {
		if (target == "_new") {
			// open new window
			var popup = window.open(url,'popup');
			popup.focus();
		}
		else {
			// redirect to url
			location.href = url;
		}
	}
}

function setText(text) {
	if (text != '#' && text != '') {
		window.status = text;
	}
}

function clearText() {
	window.status='';
}