
var errImage = new Image(15,15)
var clrImage = new Image(15,15)

errImage.src = "/i/formError.gif"
clrImage.src = "/i/clear.gif"

function Eclass(fname,valType) {
  this.fname = fname
  this.valType = valType
}

var rqFlds = new Array("yourName","Email","describeYourself","nnSubject","Comments","Zip")

/* Note -
   BusName = eBusName for error flag
*/


function checkMe(fname,cktype,opt) {  
  //onChange="checkMe('capabilities','a')"
  /*
    if 'a' => alpha numeric
    if '1' => numeric
	if '+1' => positive only
	if '@' => email
    if 'date'
	if 'tel' => phone#
	if 'hasValue'
  */
  
   var v = document.forms["contactForm"]
   var f = new JSForm(v)
   var tp = f.get(fname).toString()  // grab its value
   
   if (cktype!="hasValue") {
     tp.trimSpaces()
     f.set(fname,tp)
   }
    
  if(cktype=="@") {
    if (tp.length > 0 && (tp.lastIndexOf("@") == -1 || tp.lastIndexOf(".")==-1 || (tp.lastIndexOf(".") <= (tp.lastIndexOf("@")+1)))) {
	  toggleError(fname,1)
	} else {
	  toggleError(fname,0)
	}
  } else if (cktype=="a") {
      if (!isValidChar(tp)) {
	  toggleError(fname,1)
	} else {
	  toggleError(fname,0)
	}
  } else if (cktype=="1" || cktype=="2") {
      if (!isANumeric(tp)) {
	    toggleError(fname,1)
	  } else {
	    toggleError(fname,0)
	  } 
  }	else if (cktype=="date") {
     if(!isBlank(tp)) {
       if (!isValidDate(tp)) {
	     toggleError(fname,1)
	   } else {
	     toggleError(fname,0)
	   }   
	 }
  } else if (cktype=="+1") {
      if (!isANumeric(tp,1)) {
	    toggleError(fname,1)
	  } else {
	    toggleError(fname,0)
	  }   
  } else if (cktype=="tel") {
      if (!isANumeric(tp,1) || tp.length < 10 || tp.length > 10) {
 	    toggleError(fname,1)
	  } else {
	    toggleError(fname,0)
	  }    
  } else if (cktype=="hasValue") {
     if (isNaN(opt)) {      // not optional 
       if (isBlank(tp)) {
	     toggleError(fname,1)
	   } else {
	     toggleError(fname,0)
	   }
	 }
  }
}

function toggleError(fname,oof) {
  if(oof==1)  { // on
      document.images["e"+fname].src = errImage.src
  } else {       // off
    document.images["e"+fname].src = clrImage.src
  }
}

				  
function mainValidation() {
  var v = document.forms["contactForm"]
  var f = new JSForm(v)  
  var tp, tp2   // temp vars
  var tx = new Array(4)
  var fnHasErr = ""
  var addedErr = ""

  for(var j=0; j < rqFlds.length; j++) {
    tp3 = f.getType(rqFlds[j])
	if (tp3!="radio" && tp3!="checkbox" && tp3!="select-one" && tp3!="select-multiple") {
      tp = trimAllSpaces(f.get(rqFlds[j]))
	  f.set(rqFlds[j],tp)	
    } else {
	  tp = f.get(rqFlds[j])
	}
	
	if (isBlank(tp) || document.images["e"+rqFlds[j]].src == errImage.src) {
      toggleError(rqFlds[j],1)
	  if (fnHasErr.length == 0) fnHasErr = rqFlds[j]
	} 
  }
  
  if (v.Comments.value.length > 2500) {
    toggleError("Comments",1)
    if (fnHasErr.length == 0) fnHasErr = "Comments"
  }
  
  if (fnHasErr.length > 0) {
    alert("There are error(s) in the fields marked with a red 'X'.\n \n These fields have either been left blank, or contain an incorrect format or 'special characters' " + addedErr + "\n\n [Special characters that should not be used are: ~ ` $ % ^ & * ( ) [ ] { } | < > . \"] \n\n Please correct these errors before submitting again. \n\n Position your mouse over the red 'X' to see a description of the correct type of entry.")
	var tp = f.getType(fnHasErr)			
    if (tp != "radio" && tp != "checkbox" && tp != "hidden") { 
	  v.elements[fnHasErr].focus()
    } 
  } else {	
	v.submit();
  }
}
