
/*
Function force_numeric($value)
 Accepts a string and returns only numeric parts of that string, only returns first decimal point found. 

Typical usage:

<script language="javascript" src="/javascript/force_numeric.js" type="text/javascript"></script>

<form name="form1">
 <input type="text" name="test" id = "test1" onChange="this.value = force_numeric(this.value);"> 
</form>


*/

function force_numeric($ref) {
//  alert($val)
  $val = $ref.value
  $val_len = $val.length
  $used_dec = 0
  $pos = 0	
  $output = ""

  if ($val_len > 0) 
   {
   while ($pos <= $val_len) {
	    $cur_char = $val.charAt($pos)
		if ($cur_char >= "0" ) 
			{
		    if ( $cur_char <= "9") 
				{
				 $output = $output + $cur_char 
				 }
			 }

		if ($cur_char == ".") 
			{ 
			if( $used_dec == 0) 
		 		{
			 	$output = $output + $cur_char
			 	$used_dec = 1;
			 	}
			}

		$pos++
	 	} 
	 
   }
$ref.value = $output
if ($output != $val)
 {
 // warn user that they put in invalid input
 alert("This field only accepts numeric input!")
 // give them a chance to edit the entry
 $ref.focus()
 }

 }

function force_numeric_int($ref) {
//  alert($val)
  $val = $ref.value
  $val_len = $val.length
  $used_dec = 0
  $pos = 0	
  $output = ""

  if ($val_len > 0) 
   {
   while ($pos <= $val_len) {
	    $cur_char = $val.charAt($pos)
		if ($cur_char >= "0" ) 
			{
		    if ( $cur_char <= "9") 
				{
				 $output = $output + $cur_char 
				 }
			 }
		$pos++
	 	} 
	 
   }
$ref.value = $output
if ($output != $val)
 {
 // warn user that they put in invalid input
 alert("This field only accepts integer input!")
 // give them a chance to edit the entry
 $ref.focus()
 }

 }


