/*
 * File Name =  verifies.js  ( global form verify & checking routines )
 * JavaScript source amended by KB    
 */

//***** "WillMaster's  currency formatting function - source acknowledged  ****************************
//   Give the function an amount and it will return that amount rounded to the nearest hundredth and with two digits 
//   following a decimal point. Caution .... use for final display only !

  function Formatit(amount)
 	{
 var i = parseFloat(amount);
 if(isNaN(i)) { i = 0.00; }
 var minus = '';
 if(i < 0) { minus = '-'; }
 i = Math.abs(i);
 i = parseInt((i + .005) * 100);
 i = i / 100;
 s = new String(i);
 if(s.indexOf('.') < 0) { s += '.00'; }
 if(s.indexOf('.') == (s.length - 2)) { s += '0'; }
 s = minus + s;
 return s;
	}
// end of function Formatit()


// In future Could do a really neat Final 2 dec place format on numbers but sadly older browsers will give error. 
// Needs JavaScript 1.5, JScript - 5.5, IE 5.5 or Netscape - 6.0 - 'cos toFixed function not supported earlier.
//     For example .............. hb = (hb.toFixed (2))  
//*****************************************************


////////// only inbound funcs are       NoDec  & bounds    ///////////////////////////////////////////////////
//*****   all we really want to do is stop non-numeric values and warn on Negative Values and certain decimals ! 


//*****   keith func to trap decimals where we only want whole numbers - 
//*****   NB Many fields will be ok to have decimals 
function NoDec(nx)  //  NODEC 
{
  var zap = false;
  var f = decapitate(nx.value);
  f = money(f);

 abcint = parseInt (nx.value) ;
   if (abcint < nx.value) 	
       {
     zap = true;
     alert ( "Whole numbers only please");
       }
  if (zap)
  {     reset(nx);     return false;   }
//********* zap blanks the offending field ****************************
}



function money(f) // ********** Need this one ***********************
{      if (f=="") f = 0.0;    return f-0.0;   }

function reset(e)   // ********** Need this one ***********************
{   e.value = "";     e.focus();  }
// **********  Yes isNaN is a JS func to check for a numeric value
function check_number(x)  { return !(isNaN(x));  }

function       // ********** Need this one ***********************
decapitate(s){
  if (s.charAt(0)=="0")
      s = s.slice(1);  	
  return s;   //******     removes leading zeros 
}


// **************  BIGVAL ************************************************
// *** This function checks for NON NUMERIC  +  Negative Values   
function bounds(e)
{
  var zap = false;
  var f = decapitate(e.value);
  f = money(f);
  if(!check_number(f)) //***  Calls isNaN JS func to check for a numeric value
  {
  zap = true;
  alert ( "Inappropriate input, please enter a number");
  }

  if (f<0.0)  //************ LOOKING FOR NEG VAL ******************888   
  {
    zap = true;
    alert("A negative amount is not acceptable here")
  }
  
 // else
 // if (e.maxval && f>e.maxval)
 // {
 //   zap = !confirm("That number is surprisingly high\nAre you sure it is right?");
 // }
 // else
 // if (e.minval && f<e.minval)
 // {
 //   zap = true;
 //   alert ("That number is too small \nThe minimum is " +e.minval);
 // }

  if (zap)
  {
    reset(e);
    return false;
  }
  else
    return true;
} //****************** END of BIGVAL ********************************



//***** keith's surplus functions ************************************************
// 
function NoNeg(nx)
{
//  abcint = nx.value ;
//  if (abcint < 0.0) { zap = !confirm ("Positive numbers only please") };
//*********************************************
}

function NoNum(nx)   //*********************************************
{
//  abcint = nx.value ;
//  if (isNaN (abcint)) 
// { confirm ("Unacceptable input, please enter a **** number")  }
}





