function clearFields(theForm, theFields) {
  for(i=0;i<theForm.length;i++)
    if( theForm.elements[i].type == "text" || theForm.elements[i].type == "textarea" )
      for(j=0;j<theFields.length;j++) {
        tmpArray = theFields[j].split("=");
        if( tmpArray[0] == theForm.elements[i].name && theForm.elements[i].value == tmpArray[1] )
          clearField(theForm.elements[i], tmpArray[1])
  }
}
function clearField(theField, theValue) {
  if(theField.value==theValue) theField.value="";
}
function setField(theField,defaultValue) {
	if( theField.value == "" ) theField.value = defaultValue;
}
function trim(val) {
  return lTrim(rTrim(val));
}
function lTrim(val) {
  while(true) {
    if (val.substring(0, 1) != " ")
      break;
    val = val.substring(1, val.length);
  }
  return val;
}
function rTrim(val) {
  while(true) {
    if (val.substring(val.length - 1, val.length) != " ")
      break;
    val = val.substring(0, val.length - 1);
  }
  return val;
}
function setErrLbl(sLId,bErr) {
	try {
		var oLbl = document.getElementById(sLId);
		var sErr = 'error';
		var sDel = ' ';
		if(!bErr) oLbl.className = stripAttrib(oLbl.className, sErr, sDel);
		else oLbl.className += ' '+sErr;
	} catch(E){ }
}
function stripAttrib(sSrc, sSrch, sDelim) {
	var sRtn = sSrc;
	try {
		var a1 = sSrc.split(sDelim);
		var a2 = [ ];
		if(a1.length >= 1) {
		  for(var itm in a1) {
		    if(a1[itm] != sSrch) a2.splice(a2.length,0,a1[itm]);
		  }
		  sRtn = a2.join(sDelim);
		}
	} catch(E) {}
	return sRtn;
}