/*********************************************************************************************/
/*	                                                                                   		 */
/*    Lou Chandler   ,      Denis O'Neill , 			                   P-377        	 */
/*	  Bill Kelly     , 		Alvin Jones					                   3/1/2002      	 */	
/*							                                   		 						 */	
/*    Summary - To Validate all text-boxes on each page. when Validation passes all tests,   */
/*				call the associated Calculate Function  									 */
/*											   												 */
/*********************************************************************************************/
		
function validate(frm)							//Validates all text boxes on the page
{
var passvalidate = true;						//Represents if the function passes or fails
var str = "";
for(i=4; i<(frm.elements.length); i++)            // loop through form elements
    {
	var el = frm.elements[i];					//el = the element of the form at this time
	if(frm.elements[i].type == "text") 			//A NEW TEST - tests to see if the element at hand is either a text field or a button.  this will only let text fields pass on the check to see if it is numeric or not.
	 	{	
		str = stripNonDigits(el.value);				//this calls a function to strip any non-digits
		frm.elements[i].value=str;	
		if(frm.elements[i].value == "")
			{
			frm.elements[i].value=0;
			}	
		/*if(isEmpty(el))								//If el is empty then,
	        {
			alert("Please check all fields for valid values.");		
	        passvalidate = false;					//Pass = Fail if a box is empty.
			break;
	        }				
			 if(notNumeric(el))							//If el is not a numeric vaule then,
		        {
		        alert("Please enter a numeric value into all entry boxes.");
				passvalidate = false;					//Pass = Fail if a box does not contain a numeric value
				break;
		        }
			*/
			}
			/*
		if (passvalidate) 
			{	*/						//If Pass Not= Fail Then,
			calculate(frm);							//Perform Calculate Function
			//}
		}		
}

function isEmpty(field)							//Purpose: To detect if the field at hand is empty
  {
  str = field.value;							//entering the field value into the variable str
  if(str == "") 
  // make sure not to put a space between those quotes!
    {
    return true;
    }
  else
    {
    for(j=0; j<str.length; j++)
      {
      if(str.charAt(j) != " ")
      // make sure to put a space between those quotes!
        {
        return false;
        }
      }
    }
  return true;
  }
  

function notNumeric(field)
  {
  var errCount = 0;
  var numdecs = 0;                    // number of decimal points
  for(j=0;j<field.value.length;j++)
    {
    c = field.value.charAt(j);        // short hand notation for character at position j
//    alert("test for comma on : " + c);
    if((c >= 0 && c <= 9) || c=="." || (j==0 && c == "-"))
      {
      if(c==".") 
        {
        numdecs++;          // count the number of decimal points
        }
      }
    else
      {
      errCount++;                    // if it's none of those, increment error counter
      break;                         // no need to continue looping, it's not a number
      }
    }
  // error if count is non-zero or there are more than one decimal point
  if(errCount > 0 || numdecs > 1)
    {
    return true;
    }
  return false;
  }
  
function stripNonDigits(str)
  {
  newStr = "";
  for(j=0; j<str.length; j++)
    {
    c = str.charAt(j);
if(c >= "0" && c <= "9")
      {
      newStr += c;
      }
    }
  return newStr;
  }

  
function setfocus(el)
{
	el.select();
	el.focus();
}
