function setupWin(url, name, width, height) {w = window.open(url, 'name', "width=" + width + ",height=" + height + ",status=no,resizable=yes,menubar=no,location=no,scrollbars=yes"); w.focus();}

function trim(str) {var ret; if(typeof(str) != "string") str = str + ""; return str.replace(/(^\s+)|(\s+$)/gi, "");}

function checkNonEmpty(ctrl, errorMsg){
	var empty = true;
	var msg;
	if(typeof(ctrl) == "undefined") {alert("checkNonEmpty error: the field does not exists [" + ctrl.name + "]\n"); return false;}
	if(ctrl.type == "select-one" || ctrl.type == "select-multiple") empty = (ctrl.options[ctrl.selectedIndex].text == "");
	else empty = (trim(ctrl.value)=="");
	if(empty) {alert(errorMsg); ctrl.focus(); return false;}
	else return true;}

function checkNumeric(ctrl, errorMsg) {
	var i;
	var numeric = true;
	if(typeof(ctrl) == "undefined") {alert("checkNumeric error: the field does not exists [" + ctrl.name + "]\n"); return false;}
	if(ctrl.type != "text") {alert("checkNumeric error: the field is not a textbox [" + ctrl.name + "]\n"); return false;}
	for(i=0; i<ctrl.value.length; i++)
		if(ctrl.value.charAt(i) > "9" || ctrl.value.charAt(i) <"0") numeric = false;
	if(!numeric) {alert(errorMsg); ctrl.focus(); return false;}
	else return true;
}

function checkDate(ctrl, errorMsg) {
	var i;
	var isdate = true;
	var val;
	var dateparts;
	var intYear, intMonth, intDay;
	var daysInMonth = new Array(31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31);
	var nDays;
	if(typeof(ctrl) == "undefined") {alert("checkDate error: the field does not exists [" + ctrl.name + "]\n"); return false;}
	if(ctrl.type != "text") {alert("checkDate error: the field is not a textbox [" + ctrl.name + "]\n"); return false;}
	val = ctrl.value;
	dateparts = val.split("/");
	if(dateparts.length != 3) isdate = false;
	else {
		intYear = dateparts[2];
		intMonth = dateparts[1];
		intDay = dateparts[0];
		if(!isNumeric(intYear) || !isNumeric(intMonth) || !isNumeric(intDay)) isdate = false;
		else {
			intYear = parseInt(intYear, 10);
			intMonth = parseInt(intMonth, 10);
			intDay = parseInt(intDay, 10);
			if(intYear <= 50) intYear += 2000;
			if(intYear >= 51 && intYear < 100) intYear += 1900;
			if(intMonth == 0 || intMonth > 12 || intDay == 0 || intYear > 9999) isdate = false;
			else {
				if (intMonth==2) nDays = ((intYear%4==0) && (!(intYear%100==0) || (intYear%400==0)))?29:28;
				else nDays = daysInMonth[intMonth-1];
				if(intDay > nDays) isdate = false;
			}
		}
	}
	if(!isdate) {alert(errorMsg); ctrl.focus(); return false;}
	else return true;
}

function isNumeric(str) {
	var i;
	var numeric = true;
	for(i=0; i<str.length; i++)
		if(str.charAt(i) > "9" || str.charAt(i) <"0") numeric = false;
	return numeric;
}

function isNumericSigned(str) {
	var i;
	var start = 0;
	var numeric = true;
	if (str.charAt(0)=="-" || str.charAt(0)=="+") start = 1;
	for(i=start; i<str.length; i++)
		if(str.charAt(i) > "9" || str.charAt(i) <"0") numeric = false;
	return numeric;
}