function ValidateForm(form)
{

	var x = form.elements;
	for (var i=0;i<x.length;i++)
	{
		EleObj=x[i].id;
		LastIndex = EleObj.substring(EleObj.length-2,EleObj.length)
		switch(LastIndex)
		{
			case "_R":
				if(ValidateForm_Required(x[i],x[i].title)==false)
					return false;
			break;
			case "_P":
				if(ValidateForm_Password(x[i],x[i].title,6)==false)
					return false;
			break;
			case "_E":
				if(ValidateForm_Email(x[i],x[i].title)==false)
					return false;
			break;
			case "_C":
				if(ValidateForm_Confirm(x[i-1],x[i],x[i].title)==false)
					return false;
			break;
			case "_I":
				if(ValidateForm_Required(x[i],x[i].title)==false)
					return false;
				if(ValidateForm_Numeric(x[i],'0123456789',x[i].title)==false)
					return false;
			break;
			case "_N":
				if(ValidateForm_Numeric(x[i],'0123456789',x[i].title)==false)
					return false;
			break;
			case "_A":
			FieldArray = form.elements[x[i].name];
			if(ValidateForm_CheckArray(x[i],FieldArray,x[i].title)==false)			
				return false;
			break;
		}		
	}
return true;
}
function ValidateForm_Required(Ctrl,msg)
{
	ElementType = Ctrl.type;
	ElementTypeString = ElementType.toUpperCase();
	switch(ElementTypeString)
	{
		case "CHECKBOX":
			if(Ctrl.checked == false)
			{
				alert(msg);
				Ctrl.focus();
				return false;
			}
		break;
		default :
			if(trimString(Ctrl.value) == "")
			{
				alert(msg);
				Ctrl.focus();
				return false;
			}
		break;		
		
	}
	return true;
}

function ValidateForm_Password(Ctrl,msg,Minlen)
{
	var charpos = Ctrl.value.search("[^A-Za-z0-9]"); 
	if(trimString(Ctrl.value).length < Minlen ||  charpos >= 0) 
      { 
      	alert(msg);
		Ctrl.focus();
		return false;
      } 
		
	return true;
}
function ValidateForm_CheckArray(Ctrl,FieldArray,msg)
{
	MyCheck = true;
	for (var j=0;j<FieldArray.length;j++)
	{
		if(FieldArray[j].checked)
			MyCheck = false;
		
	}
	if(MyCheck)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}	
	return true;
}
function ValidateForm_Checked(Ctrl,msg)
{
	if(Ctrl.checked == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}
function ValidateForm_Numeric(Ctrl,valid_chars,msg)
{
	if(chkNumericValidate(Ctrl.value,valid_chars) == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}
function chkNumericValidate(strString,strValidChars)
{
   var strChar;
   var blnResult = true; 
  	for (i = 0; i < strString.length && blnResult == true; i++)
   {
	  strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
      {
    	   blnResult = false;
      }
   }
   return blnResult;
}
function ValidateForm_Email(Ctrl,msg)
{
	if(chkEmailValidate(Ctrl.value) == false)
	{
		alert(msg);
		Ctrl.focus();
		return false;
	}
	return true;
}

function ValidateForm_Confirm(Ctrl1,Ctrl2,msg)
{
	if(Ctrl1.value != Ctrl2.value)
	{
		alert(msg);
		Ctrl2.focus();
		return false;
	}
	return true;
}

function chkEmailValidate(str)
{
	return(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(str));
}
function trimString (str)
{
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}
 function getObject(nameStr) 
 {
    var ie  = (document.all);
    var ns4 = document.layers? true : false;
    var dom = document.getElementById && !document.all ? true : false;

    if (dom) {
        return document.getElementById(nameStr);
    } else if (ie) {
        return document.all[nameStr];
    } else if (ns4) {
        return document.layers[nameStr];
    }
}
function counterUpdate(opt_countedTextBox, opt_countBody, opt_maxSize) 
{
  var countedTextBox = opt_countedTextBox ?
    opt_countedTextBox : "countedTextBox";
  var countBody = opt_countBody ? opt_countBody : "countBody";
  var maxSize = opt_maxSize ? opt_maxSize : 1024;
    
  var field = document.getElementById(countedTextBox);
  if (field && field.value.length >= maxSize) 
  {
    field.value = field.value.substring(0, maxSize);
  }
  var txtField = document.getElementById(countBody);
  if (txtField) 
  {  
    txtField.innerHTML = field.value.length;
  }
}			

<!-- Original:  Nannette Thacker -->
<!-- http://www.shiningstar.net -->

function checkNumeric(objName,minval, maxval,comma,period,hyphen)
{
	var numberfield = objName;
	if (chkNumeric(objName,minval,maxval,comma,period,hyphen) == false)
	{
		numberfield.select();
		numberfield.focus();
		return false;
	}
	else
	{
		return true;
	}
}

function chkNumeric(objName,minval,maxval,comma,period,hyphen)
{
// only allow 0-9 be entered, plus any values passed
// (can be in any order, and don't have to be comma, period, or hyphen)
// if all numbers allow commas, periods, hyphens or whatever,
// just hard code it here and take out the passed parameters
var checkOK = "0123456789" + comma + period + hyphen;
var checkStr = objName;
var allValid = true;
var decPoints = 0;
var allNum = "";

for (i = 0;  i < checkStr.value.length;  i++)
{
ch = checkStr.value.charAt(i);
for (j = 0;  j < checkOK.length;  j++)
if (ch == checkOK.charAt(j))
break;
if (j == checkOK.length)
{
allValid = false;
break;
}
if (ch != ",")
allNum += ch;
}
if (!allValid)
{	
alertsay = "Please enter only these values \""
alertsay = alertsay + checkOK + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}

// set the minimum and maximum
var chkVal = allNum;
var prsVal = parseInt(allNum);
if (chkVal != "" && !(prsVal >= minval && prsVal <= maxval))
{
alertsay = "Please enter a value greater than or "
alertsay = alertsay + "equal to \"" + minval + "\" and less than or "
alertsay = alertsay + "equal to \"" + maxval + "\" in the \"" + checkStr.name + "\" field."
alert(alertsay);
return (false);
}
}


