function setFormFocus(){
var frm = document.forms[0];		
var done = false;
	if (document.forms.length == 0) return;
 	for (f = 0; f < frm.elements.length; f++){
 		if (! done){
		 	if ( frm.elements[f].type.substr(0,5) != "selec" && frm.elements[f].type != "hidden" && frm.elements[f].type != "reset" && frm.elements[f].type != "submit" && ! frm.elements[f].disabled && ! frm.elements[f].readOnly){
				frm.elements[f].focus();
	 			done = true;
	  		 }
 		}
 	} 	
}
// ============
function preSubmit(){
var errMsg = '';
var frm = document.forms[0];	
	// Button the user pressed
 	actionKey=arguments[0];
	actionKey=actionKey.toUpperCase();
	actionKey=actionKey.substring(0,4);	// get the first four letters of the buttons text			
	res = false;
	// Just get confirmation before deletion
 	if (actionKey == 'DELE'){
 		res = window.confirm('Are you sure you want to delete this record?');
 		if (res == false ) { // if users clicks the popup windows cancel button  scan all 'action' buttons and set their value to Cancel
 			// Then we can submit the form as if the user clicked the form's 'Cancel' button
	 		for(f=0;f<frm.action.length;f++){ // 
	 			frm.action[f].value = 'Cancel'; // 
	 		}
 		}
	 	return(true);
 	} 	
	altTextLen=0;
	altTextErr = false;
	altTextErrText='';	
	// Scan the validation data ( arg[0] = the id of the button the user pressed
	for (var i=1;i < arguments.length; i++) {
		// Break up each validation data set
		arData =  arguments[i].split('|'); 
		// break up the first param into the button(s) we need to validate
		arButtons = arData[0].split('/'); 
		// Scan all the buttons - usually only 1
		for (var b=0;b < arButtons.length; b++) {	
			// make a 4-char Ucase versio n of the button
			valBtnKey=arButtons[b].toUpperCase();
			valBtnKey=valBtnKey.substring(0,4);	// get the first four letters of the val buttons text			
			// DO they match? If so we run the test
			if (valBtnKey==actionKey){	
  				fldName=arData[1];	//[0] is the button/list of buttons we need to test
  				fldData = frm.elements[fldName].value;
  				fldData = trim(fldData);
  				funcName=arData[2];
  				errText=arData[3];
  				ok=true;
  				myErr='';
	  			switch (funcName){
	  				case 'isFileName':
		  				ok = isFileName(fldData);
	  					break;
	  				case 'isAltText':
	  					altTextLen = altTextLen + fldData.length;
	  					altTextErrText = errText;
	  					break;
	  				case 'isText':
	  					ok = 	fldData.length > 0;
	  					break;
	  				case 'isNum':
	  					ok = isInteger(fldData);
	  					break;
	  				case 'isDate':
	  					ok = isDate(fldData);
	  					break;
	  				case 'isOptEmail':
	  					if ( fldData.length > 0 ) ok = isEmailAddr(fldData);
	  					else ok = true;
	  					break;
	  				case 'isEmail':
	  					ok = isEmailAddr(fldData);
	  					break;
	  			}
	  			if (! ok) errMsg +=  errText  + '\n';
			}	  			
  		} // End of for loop parsing validators
 	}
	if (altTextErrText) { // There was an altText test - did it pass?	
		if (altTextLen < 1 ) errMsg +=  altTextErrText  + '\n';
	} 	
 	if (errMsg) alert( 'Data input errors: \n' + errMsg );
 	else res=true;
 	return(res);
}
// ===============
function isFileName(fileName){
	// must be something!
	if(fileName.length < 1) return(false);
	// look for valid extensions
	dots = fileName.split(".")
	//get the part AFTER the LAST period.
	myFileType = dots[dots.length-1];
	myFileType = myFileType.toUpperCase();
	if (myFileType != 'JPG' && myFileType != 'GIF' ) return (false);
	return(true);
}
// ===============
function isInteger(s){
	var i;
    for (i = 0; i < s.length; i++){   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
// ============
function stripCharsInBag(s, bag){
	var i;
    var returnString = "";
    // Search through string's characters one by one. If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++){   
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}
// ==============
function daysInFebruary (year){
	// February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.
    return (((year % 4 == 0) && ( (!(year % 100 == 0)) || (year % 400 == 0))) ? 29 : 28 );
}
// ==========
function DaysArray(n) {
	for (var i = 1; i <= n; i++) {
		this[i] = 31
		if (i==4 || i==6 || i==9 || i==11) {this[i] = 30}
		if (i==2) {this[i] = 29}
   } 
   return this
}
// ========
function isDate(dtStr){
// Declaring valid date character, minimum year and maximum year
var dtCh= "/";
var minYear=1900;
var maxYear=2100;
	
	var daysInMonth = DaysArray(12)
	var pos1=dtStr.indexOf(dtCh)
 
	if (pos1<1){
		dtCh='-'; // if / doesnt work try -
		pos1=dtStr.indexOf(dtCh)
	}
	var pos2=dtStr.indexOf(dtCh,pos1+1)
	var strDay=dtStr.substring(0,pos1)
	var strMonth=dtStr.substring(pos1+1,pos2)
	var strYear=dtStr.substring(pos2+1)
	strYr=strYear
	if (strDay.charAt(0)=="0" && strDay.length>1) strDay=strDay.substring(1)
	if (strMonth.charAt(0)=="0" && strMonth.length>1) strMonth=strMonth.substring(1)
	for (var i = 1; i <= 3; i++) {
		if (strYr.charAt(0)=="0" && strYr.length>1) strYr=strYr.substring(1)
	}
	month=parseInt(strMonth)
	day=parseInt(strDay)
	year=parseInt(strYr)
	if (pos1==-1 || pos2==-1){
		return false
	}
	if (strMonth.length<1 || month<1 || month>12){
		return false
	}
	if (strDay.length<1 || day<1 || day>31 || (month==2 && day>daysInFebruary(year)) || day > daysInMonth[month]){
		return false
	}
	if (strYear.length != 4 || year==0 || year<minYear || year>maxYear){
		return false
	}
	if (dtStr.indexOf(dtCh,pos2+1)!=-1 || isInteger(stripCharsInBag(dtStr, dtCh))==false){
		return false
	}
return true
}
// ============
function isEmailAddr(email)
{
  var result = false
  var theStr = new String(email)
  var index = theStr.indexOf("@");
  if (index > 0)
  {
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}
// ==============
function checkMaxLength (textarea, evt, maxLength) {
   // ignore shift click for select
  if (textarea.selected && evt.shiftKey)  return true;
   if (evt.ctrlKey)  return true;
  var allowKey = false;
  if (textarea.selected && textarea.selectedLength > 0) allowKey = true;
  else {
  		var keyCode =  document.layers ? evt.which : evt.keyCode;
  	 	// Look for special keys
  		if ( ! isAlphaNum(keyCode)) return true;
  		allowKey = (textarea.value.length < maxLength);
  }
  if ( textarea.value.length > maxLength) {
  		textarea.value = textarea.value.substring(0,maxLength);
  }
  textarea.selected = false;
  return allowKey;
}
function isAlphaNum(keyCode){
	if ( (keyCode>=48 && keyCode <= 90) || keyCode >= 144 || keyCode==13 || keyCode==32 ) return true;
	else return false;
}
// ============
function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also removes
   // consecutive spaces and replaces it with one space. If something besides
   // a string is passed in (null, custom object, etc.) then return the input.
   if (typeof inputString != "string") { return inputString; }
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function

//onkeypress="return entersubmit(event,this.form)"   
function entersubmit(event,ourform) {
	alert()
  if (event && event.which == 13)
    ourform.submit();
  else
    return true;}
// =========
function gotFocus(el) {
	 xbSetElClass(el,'fieldFocus');
}
function lostFocus(el) {
	 xbSetElClass(el,'fieldBlur');
}

var formAction = String("");
 
 