//////////////////////////////////////////////////////////////////////////////
// some useful js functions for calculators
//////////////////////////////////////////////////////////////////////////////
function filter_keys_int(e) {
  var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
  status = charCode;
  if(charCode > 31 && (charCode <48 || charCode>57)) {
    return false;
  }
}
//////////////////////////////////////////////////////////////////////////////
function filter_keys_float(e) {
  var charCode = (navigator.appName == "Netscape") ? e.which : e.keyCode;
  status = charCode;
  // 44 = ,
  // 46 = .
  if(charCode > 31 && ((charCode <48 || charCode>57) && charCode != 46 && charCode != 44)) {
    return false;
  }
} 
//////////////////////////////////////////////////////////////////////////////
function parseItem(aItemStr, aType) {
  var res = null;
  if(aType == 'int') {
    if(!isNaN(parseInt(aItemStr)))
      res = parseInt(aItemStr);
  }
  else if(aType == 'float') {
    splitArr=aItemStr.split(',');
    aItemStr = '';
    for(var i=0;i<splitArr.length;i++) {    
      if(aItemStr=='')
        aItemStr = splitArr[i];
      else  
        aItemStr = aItemStr + '.' + splitArr[i];
    }  
    if(!isNaN(parseFloat(aItemStr)))
      res = parseFloat(aItemStr);    
  }  
  return res;
}
//////////////////////////////////////////////////////////////////////////////
function round_amount(aAmount, aDec) {    
  var str=''+(Math.round(aAmount*Math.pow(10,aDec))/Math.pow(10,aDec));

  var dot_pos=str.indexOf('.');
  if(dot_pos<0) {
    str = str+".";   
    for(var i=0;i<aDec;i++)    
      str = str+'0';
    return str;  
  }  
  
  var new_str='';
  new_str = str.substring(0,dot_pos+1);
  new_str = new_str + str.substring(dot_pos+1,dot_pos+aDec+1);
  while(new_str.length-dot_pos<=aDec) {  
    new_str = new_str + "0";    
  }  
  return new_str;
}
//////////////////////////////////////////////////////////////////////////////
function strip_char(aText, aChar){
  if(aText!=null){
    splitArr=aText.split(aChar);
    if(splitArr!=null){
      aText=splitArr[0];
      for(i=1;i<splitArr.length;i++){
        aText=aText + splitArr[i];
      }
    }
  }
  return aText;
}
//////////////////////////////////////////////////////////////////////////////
function parse_amount(aAmount, aWithDot) {
  var foo_chr;
  var foo_res='';
  for(var i=0;i<aAmount.length;i++) {
    foo_chr = aAmount.charAt(i);
    if(aWithDot==true) {
      if(!isNaN(parseInt(foo_chr)) || foo_chr=='.')
        foo_res=foo_res + foo_chr;      
    }  
    else {
      if(!isNaN(parseInt(foo_chr)))
        foo_res=foo_res + foo_chr;
    }    
  }
  return foo_res;
}


