function checkForm() {


// this sets up the variables and arrays, as well as, the calls for other funcions.

	this.msgsep  	= '\n';
	this.blank   	= '';
	this.problem 	= new Array();
	this.display	= new Array();

        this.addMssg   	= _checkForm_addMssg;
	this.showAlrt 	= _checkForm_showAlrt;
	this.ckValue	= _checkForm_ckValue;
	this.loadVal	= _checkForm_loadVal;
 	
	
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(); field.focus seems to be cause for JS error in IE 5.5
	if (field.value );
	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;
}

// 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 && (field.options[field.selectedIndex].value != this.blank));
  if (/(checkbox|radio)/.test(field.type))
    return ( field.checked && (field.value != this.blank) );
  if (/(button|reset|submit)/.test(field.type))
    return false;
  return (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 )
}


function checkIt_speciesList (form) {

    var v = new checkForm();
	if ( ! v.ckValue(form.taxon)) v.addMssg(form.taxon,    "- Search term", 2);
	
	return v.showAlrt("Sorry, you need to fill in some more information!\n Please fill in the following field(s):\n",
  '\nThank you!');
}


function checkIt (form) {

	var v = new checkForm();

	if ((form.receivedType.value == "Selected Area") && (((form.north.value - form.south.value) > 5) || ((form.east.value - form.west.value) > 5))) {
		v.addMssg(form.north, "too broad.",6);		
		return v.showAlrt("Sorry, the area you have selected is ", "\nPlease draw your area again.");
	}	
	else {
        
        if ((form.receivedType.value == "Selected Area") && (((form.north.value - form.south.value) < 0.092) || ((form.east.value - form.west.value) < 0.092)) ) {
        //var al = "Less than\n";
        //al += "Initial Values: \n";
            if (form.north.value - form.south.value < 0.1) {
	        //al += "North: " + form.north.value + " South: " + form.south.value + "\n";
                var tempNorth = form.north.value;
                var tempSouth= form.south.value;
                form.north.value = ((tempNorth + tempSouth) / 2) + 0.05;
                form.south.value = ((tempNorth + tempSouth) / 2) - 0.05;
            }
            if (form.east.value - form.west.value < 0.1) {
	        //al += "East: " + form.east.value + " West: " + form.west.value + "\n";
                var tempEast = form.east.value;
                var tempWest = form.west.value;
                form.east.value = ((tempEast + tempWest) / 2) + 0.05;
                form.west.value = ((tempEast + tempWest) / 2) - 0.05;
            } 
            //al += "North: " + form.north.value + " South: " + form.south.value + "\n";
            //al += "East: " + form.east.value + " West: " + form.west.value + "\n";
            //alert(al);
        }

		if ( ( v.ckValue(form.SpeciesName)) && (! v.ckValue(form.spWiz)) )	v.addMssg(form.spWiz,    "- Please confirm the species name", 8);
	   	if ( ! v.ckValue(form.rdSpecies) )	v.addMssg(form.rdSpecies,    "- Species", 1);
	  	if ( ! v.ckValue(form.selFF) )   	v.addMssg(form.selFF,  "- Group", 0);
	  	if ( ! v.ckValue(form.rdRecords) )  	v.addMssg(form.rdRecords,  "- Time period", 2);
	  	if ( ( form.receivedText.value == "No area specified yet") || ( ! v.ckValue(form.rType))) {
	  		 	v.addMssg(form.receivedText,  "- Area", 5);
	  	}
		if ((document.geographic.rdSpecies[2].checked) && ( ! v.ckValue (form.selType))) {
	  			v.addMssg(form.rdSpecies,  "- Class", 3);
		}
	  	if ((document.geographic.rdSpecies[3].checked) && (! v.ckValue(form.SpeciesName))) 	{
	  			v.addMssg(form.rdSpecies,  "- Species name", 4);
		}
	
	  	return v.showAlrt("Sorry you need to complete some more steps. \n Please complete the following:\n",
		'\nThank you!');
	}
 
}


// -->



