
function checkForm() {

	this.msgsep  	= '\n';
	this.blank   	= '';
	this.problem 	= new Array();
	this.display	= new Array();
	
	this.Date 	= /^(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)\s([1-9]|[1-3][0-9]),\s[0-2][0-9][0-9][0-9]$/;
//USA		
	this.State 	= /^(A[AEKLPRSZ]|C[AOT]|DC|DE|FL|FM|GA|GU|HI|I[ADLN]|KS|KY|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|SC|SD|T[NTX]|UT|V[AIT]|W[AIVY])$/i;
//USA
//	this.Zip	= /^d(5)([-]?d(4))?$/;
//Canada
	this.Zip	= /^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/;
	this.Phone	= /^\(?\d{3}\)?\D?\d{3}\D?\d{4}$/;
	this.Email	= /^([0-9a-z_&.+-]+!)*[0-9a-z_&.+-]+@(([0-9a-z]([0-9a-z-]*[0-9a-z])?\.)+[a-z]{2,3}|([0-9]{1,3}\.){3}[0-9]{1,3})$/i;
	this.notEmail	= /^(((postmaster|root|hostmaster|mailer-daemon|webmaster)@(wyvernwood|frame)\.com)|.*@(.*\.(wyvernwood|frame)\.com|localhost\.com|127\.0\.0\.1))$/i;
	this.Decimal	=/^-?\d*\.?\d*$/;
	this.Integer	=/^-?\d*$/;
	this.Currency	=/^-?\d{1,3}(,\d{3})*$/;
//	this.Currency	=/^-?\d{1,3}(,\d{3})*\.\d{2}$/; //with decimal
	this.addMssg   	= _checkForm_addMssg;
	this.showAlrt 	= _checkForm_showAlrt;
	this.ckValue	= _checkForm_ckValue;
	this.loadVal	= _checkForm_loadVal;
 	this.phoneOk	= _checkForm_phone;
	this.EmailOk	= _checkForm_email;
	this.ZipOk	= _checkForm_zip;
	this.StateOk	= _checkForm_State;
	this.DateOk	= _checkForm_Date;
	this.DecimalOk	= _checkForm_Decimal;
	this.IntegerOk	= _checkForm_Integer;	
	this.CurrencyOk	=_checkForm_Currency;
	this.NumberInRange=	_checkForm_NumberInRange;
	
return this;  }

// this function adds msgs to the alert so that you get all of the alerts in one box
// rather than going from one to the next.  That way the user can see all of the 
// problems at once rather than getting frustrated going back again and again if there 
// are problems.
function _checkForm_addMssg (field, msg, arrynum) {
  if ( ! this.problem[arrynum]) { 
	if (field.value || field.focus) field.focus();
	this.problem[arrynum] = msg;}
}



// This makes the alert and shows the list of problems.
function _checkForm_showAlrt (head, foot) {

	var y=0

    	for (var x = 0; x < 15; x++) {
	if (! this.problem[x] == '') {
		this.display[y] = this.problem[x];
		y++;
		}
	}

	if (this.problem.length) {
	      	alert((head ? head + this.msgsep : '') + this.display.join(this.msgsep) + (foot ? this.msgsep + foot : ''));
	     	return false;
	}
    	return true;
}

//string trim
function trim(str) {
 var res="";
 var startFg=true;
 for(var i=0; i< str.length; i++) {
   if (str.charAt(i) != " " && startFg==true) {
     res =str.substring(i,str.length);
     startFg=false;
  }
 }

 var res2="";
 startFg=true;
 for(var j=res.length-1; j>=0; j--) {
   if (res.charAt(j) != " " && startFg==true) {
     res2=res.substring(0,j+1);
     startFg=false;
  }
 }
  return res2;

}//trim()

// This checks the values of the fields to ensure they have been filled out.
// It will check all types of fields with one function.
function _checkForm_ckValue (field) {
  if ( ! field.type && field.length ) {
    for (var x = 0; x < field.length; x++)
      if (field[x].type && this.ckValue(field[x]))
        return true;
    return false;
  }
  if (/select/.test(field.type))
    return (field.selectedIndex != -1 && (trim(field.options[field.selectedIndex].value) != this.blank));
  if (/(checkbox|radio)/.test(field.type))
    return ( field.checked && (trim(field.value) != this.blank) );
  if (/(button|reset|submit)/.test(field.type))
    return false;
  return (trim(field.value) != this.blank)
}

// This is a function necessary when checking the validity of fields.
function _checkForm_loadVal (field) {
  if ( ! field.type && field.length ) {
    for (var x = 0; x < field.length; x++) {
      if (field[x].type) {
        var value = this.loadVal(field[x]);
        if (value) return value;
      }
    }
    return null;
  }
  if (/select/.test(field.type))
    return ( (field.selectedIndex != -1 && (field.options[field.selectedIndex].value != this.blank))
      ? field.options[field.selectedIndex].value : null );
  if (/(checkbox|radio)/.test(field.type))
    return ( (field.checked && (field.value != this.blankValue)) ? field.value : null );
  return ( ( ! /(button|reset|submit)/.test(field.type) && (field.value != this.blank)) ? field.value : null )
}


// These functions are used to check validity of field values.
function _checkForm_phone (p) 
{ 
	return ( this.Phone.test(p) ) 
}

function _checkForm_email (e) 
{ 
	return ( this.Email.test(e) && ! this.notEmail.test(e) ) 
}

function _checkForm_zip (z) 
{ 
	return ( this.Zip.test(z) ) 
}

function _checkForm_State (s) 
{ 
	return ( this.State.test(s) )  
}

function _checkForm_Date (d) 
{ 
	return ( this.Date.test(d) )  
}

function _checkForm_Decimal (n) 
{ 
	return ( this.Decimal.test(n) )  
}

function _checkForm_Integer (n) 
{ 
	return ( this.Integer.test(n) )  
}

function _checkForm_Currency (n) 
{ 
	return ( this.Currency.test(n) )  
}

function _checkForm_NumberInRange (field1,Min1,Max1) 
{ 
	var val1=parseInt(field1.value);
	
	if (val1>=Min1 && val1<=Max1){
		return true
	}else{
		return false
	}
}



