function isEmpty(oControl) { 
	var sType; 
	var bEmpty = true;
	var i;

	if (!oControl) 
		return true; 

	if (!isNaN(oControl.length)) { 
		bEmpty = true;

		for (i = 0; i < oControl.length; i++) { 
			bEmpty = bEmpty && isEmpty(oControl[i]);
			if (!bEmpty) break;
		}
	} else { 
		sType = oControl.type;

		if (sType == "select") { 
			bEmpty = (oControl.options[selectedIndex].value.length == 0);
		} else if ((sType == "checkbox")||(sType == "radio")) { 
			bEmpty = (!oControl.checked);
		} else { 
			bEmpty = (oControl.value.length == 0);
		} 
	}
	return bEmpty;
} 

function focusInput(oControl) { 
	var oField = (oControl.length? oControl[0] : oControl); 
	if (oField.focus && !oField.disabled) { 
		oField.focus(); 
		return true;
	} else { 
		return false; 
	} 
} 

function checkEmpty(oControl, sAlert, oControlAlt) { 
	if (!oControl) { 
		return false;
	} else if (isEmpty(oControl)) { 
		if (sAlert) alert(sAlert);
		if (!focusInput(oControl)) { 
			focusInput(oControlAlt); 
		} 
		return true;
	} else { 
		return false;
	}
} 

function copyValue (oSrc, oDest) { 
	var valSrc = ((oSrc.type.search(/^select/) == -1)? oSrc.value : oSrc.options[oSrc.selectedIndex].value);
	var i;

	if (oDest.type.search(/^select/) != -1) { 
		for (i = 0; i < oDest.length - 1; i++) { 
			if (oDest.options[i].value == valSrc) { 
				oDest.options[i].selected = true; 
				break;
			} 
		} 
	} else { 
		oDest.value = valSrc;
	} 
}
function setControlValue (ctrl, v) { 
	var sVal = ""; 
	var i;

	if (typeof(v) != "object") {
		sVal = v;
	} else if (v.options) {
		sVal = v.options[v.selectedIndex].value; 
	} else if (v.value) {
		sVal = v.value;
	}

	if (ctrl.options) { 
		for (i = 0; i < ctrl.length - 1; i++) { 
			if (ctrl.options[i].value == sVal) { 
				ctrl.options[i].selected = true; 
				break;
			} 
		} 
	} else { 
		ctrl.value = sVal;
	} 
}
function disableInput(oControl, bDisable) { 
	var sType = oControl.type ; 
	if (bDisable) { 
		if ((sType == "text")||(sType == "password")||(sType == "textarea")) 
			oControl.value = ""; 
		else if (sType.search(/^select/) != -1) {
			oControl.selectedIndex = -1;
		} 
		oControl.onfocus = oControl.blur;
	} else { 
		oControl.onfocus = ""; 
	} 
	return !!(bDisable);
}
function toPage(sPage) {
	var oForm;
	if (document.forms.length > 0) { 
		oForm = document.forms[0]; 
		if (oForm.topage) { 
			oForm.topage.value = sPage;
		} 
		if (!!validate) { 
			if (validate(oForm)) { 
				oForm.submit();
			} 
		} 
		return false;
	} else {
		location.href = location.pathname + "?d=" + sPage;
		return false;
	}
}
function confirmData(oConfirm, sMessage) { 
	var i; 
	var oOrigin; 
	var sName = oConfirm.name.replace(/confirm/gi, ""); 

	for (i=0; i < oConfirm.form.elements.length; i++) { 
		oOrigin = oConfirm.form.elements[i]; 
		if (oOrigin.name) { 
			if (oOrigin.name == sName) 
				break;
		} 
	} 

	if (!oOrigin) return true; 

	if ((oOrigin.value == "")||(oConfirm.value == "")) { 
		oConfirm.value = "";
		return true;
	} else if (oOrigin.value == oConfirm.value) { 
		return true; 
	} else {
		alert(sMessage);
		oConfirm.select();
		return false;
	}
}

function mtnPage(oControl) { 
	var sAction = (oControl.name.substring(0,1) == "m" ? "m" : "d");
	var oForm = oControl.form;
	
	oForm.topage.value = "maintain";
	if (validate(oForm)) {
		oForm.a.value = sAction;
		oForm.submit();
	}
	return false;
}
function getDate (sDate) {
	var arrDate = sDate.match(/(^\d{1,2})\/(\d{1,2})\/(\d{4}$)/);
	if (arrDate) {
		return new Date(arrDate[3], arrDate[2] - 1, arrDate[1]);
	} else { 
		return null;
	}
}
function checkEmail(oControl, message) { 
	var email = oControl.value.replace(/^\s+|\s+$/g, ""); 
	var bValid = true;
	
	oControl.value = email;
	if (email != "") { 
		if (email.search(/^\w[\w\.\-]*@\w[\w\-\.]+\w$/gi) == -1) {
			bValid = false;
			if (message) alert(message); 
			oControl.value = "";
			oControl.focus();
		}
	} 

	return bValid;
}


