// JavaScript Document
function setValue(idName, val) {
	if (! document.getElementById(idName)) {
		window.alert(idName + " No Such Element");
	} else {
		(document.getElementById(idName)).value=val;
	}
}
function getElement(idName) {
	if (! document.getElementById(idName)) {
		window.alert(idName + " No Such Element");
	} else {
		return document.getElementById(idName);
	}
}
function getValue(idName) {
	if (! document.getElementById(idName)) {
		window.alert(idName + " No Such Element");
	} else {
		return (document.getElementById(idName)).value;
	}
}
function setFocus(idName) {
	if (! document.getElementById(idName)) {
		window.alert(idName + " No Such Element");
	} else {
		(document.getElementById(idName)).focus();
	}
}
function setDisplay(idName, val) {
	if (! document.getElementById(idName)) {
		window.alert(idName + " No Such Element");
	} else {
		(document.getElementById(idName)).style.display=val;
	}
}
function setInnerHtml(idName, val) {
	if (! document.getElementById(idName)) {
		window.alert(idName + " No Such Element");
	} else {
		(document.getElementById(idName)).innerHTML=val;
	}
}
function ltrim(sString) 
	{
	while (sString.substring(0,1) == ' ')
	{
		sString = sString.substring(1, sString.length);
	}
	return sString;
}
function rtrim(sString) 
{
	while (sString.substring(sString.length-1, sString.length) == ' ')
	{
		sString = sString.substring(0,sString.length-1);
	}
	return sString;
}
function trim(str) {
	return rtrim(ltrim(str));
}
function trimField(idName) {
	if (! document.getElementById(idName)) {
		window.alert(idName + " No Such Element");
	} else {
		setValue(idName, trim(getValue(idName)));
		return getValue(idName);
	}
}
function validateEmail(fldId) {
	if (getValue(fldId) !== "") {
		var reEmail = /.+@.+\..+/;
		if ( ! reEmail.test(trimField(fldId)) ) {
			return false;
		}
	}
	return true;
}
function setForm( ctrl, act, nextPage ) {
	setValue("ctrl", ctrl);
	setValue("act", act);
	setValue("nextPage", nextPage);
}
function sendForm( form, ctrl, act, nextPage ) {
	setForm( ctrl, act, nextPage );
	getElement(form).submit();
}
function ajax(url, parms, func) {
	new Ajax.Request(url, 
					 {method: "post", 
					  parameters: parms,
					  onComplete: func});
}
function ajaxParms(url, parms, cDiv) {
	new Ajax.Request(url, 
					 {method: "post", 
					  parameters: parms,
					  onComplete: function(req){setInnerHtml(cDiv, req.responseText);}});
}
function ajaxForm(url, frm, cDiv) {
	new Ajax.Request(url, 
					 {method: "post", 
					  parameters: $(frm).serialize('true'),
					  onComplete: function(req){setInnerHtml(cDiv, req.responseText);}});
}
function setResponse(req, cDiv) {
	setInnerHtml(cDiv, req.responseText);
}
