<!--
// Bankier.pl 
// Skrypt do kalkulatorow
// Autor: Tomasz Mechlinski
// powstanie: 13.04.2000
//
//  Obiekty: 
//
// waluta  (wartosc_inicjujaca, pole_wyswietlajace, lista_z_walutami) 
// procent (wartosc_inicjujaca, ilosc_miejsc_po_przecinku, pole_wyswietlajace)
// miesiac (wartosc_inicjujaca, pole_wyswietlajace)
// liczba  (wartosc_inicjujaca, ilosc_miejsc_po_przecinku, pole_wyswietlajace)
// 
//  Metody
//  set()         - ustawienie wartosci w polu_wyswietlajacym
//  change()      - obsluga zdarzenia onkeyup !
//  focus()       - obsluga zdarzenia onfocus !
//  blur()	  - obsluga zdarzenia onblur  !
//  getvalue()    - pobranie wartosci
//  setvalue()    - ustawienie wartosci
//  setvalue()    - ustawienie wartosci
//  update()	  - ponowne wpisanie wartosci w polu_wyswietlajacym (np. przy zmianie kursu)
//
// ---------------------------------------------------------------------------
//   Funkcje:
//
//  IntToPl(liczba, przyp)   - zwraca liczbę w postaci słownej
//			     - przyp = 0  - liczba normalna
//			     - przyp = 1  - porządkowa żeńska
//			     - przyp = 2  - porządkowa męska
// ***************************************************************************
// ***************************************************************************

   function getvalue()
   {
     return this.value
   }
   
   function setvalue(val)
   {
     this.value = (isNaN(val) || !isFinite(val)) ? 0 : val
     this.set()
   }
   
   function update()
   {
     this.set()
   }
   
// ***************************************************************************
// Obiekt waluta
// ***************************************************************************

  function waluta(value_, target_, kurs_)
  {
    this.value = this.string_ = value_
    this.kurs = kurs_
    this.target = target_
    waluta.prototype.set = waluta_set
    waluta.prototype.get = waluta_get
    waluta.prototype.change = waluta_change
    waluta.prototype.focus = waluta_focus
    waluta.prototype.blur = waluta_blur
    waluta.prototype.getvalue = getvalue
    waluta.prototype.setvalue = setvalue
    waluta.prototype.update = update
    this.set()
  }

  function waluta_set()
  {
    this.target.value = format(przelicz(this.value, this.kurs.value));
    this.string_ = this.target.value
  } 
  
  function waluta_get()
  {
    this.value = pobierz(convert(this.target, 0), this.kurs.value)
  }
  
  function waluta_change()
  {
    if (this.target.value != this.string_)
    {
      this.get()
      this.target.value = insert_separs(this.target.value, 1)
      this.string_ = this.target.value
    }
  }

  function waluta_focus()
  {
    this.target.select()
  }
  
  function waluta_blur()
  { 
    this.set()
  }
  
// ***************************************************************************
// Obiekt procent
// ***************************************************************************
  
  function procent(value_, dot_, target_)
  {
    this.value = this.string_ = value_
    this.target = target_
    this.dot = dot_
    procent.prototype.set = procent_set
    procent.prototype.get = procent_get
    procent.prototype.change = procent_change
    procent.prototype.focus = procent_focus
    procent.prototype.blur = procent_blur
    procent.prototype.getvalue = getvalue
    procent.prototype.setvalue = setvalue
    procent.prototype.update = update
    this.set()
  }
  
  function procent_set()
  { 
//    this.target.value = format(this.value);
    this.target.value = insert_separs(Math.round(this.value*Math.pow(10, this.dot))/Math.pow(10, this.dot));
    unit_on(this.target, " %", 0)
    this.string_ = this.target.value
  } 
  
  function procent_get()
  {
    this.value = convert(this.target, 0)
  }
  
  function procent_change()
  {
    if (this.target.value != this.string_)
    {
      this.get()
      this.target.value = insert_separs(this.target.value, 1)
      this.string_ = this.target.value
    }
  }
  
  function procent_focus()
  {
    unit_off(this.target)
    this.string_ = this.target.value
    this.target.select()
  }
  
  function procent_blur()
  { 
    this.set()
  }

// ***************************************************************************
// Obiekt miesiac
// ***************************************************************************
  
  function miesiac(value_, target_)
  {
    this.value = this.string_ = value_
    this.target = target_
    miesiac.prototype.set = miesiac_set
    miesiac.prototype.get = miesiac_get
    miesiac.prototype.change = miesiac_change
    miesiac.prototype.focus = miesiac_focus
    miesiac.prototype.blur = miesiac_blur
    miesiac.prototype.getvalue = getvalue
    miesiac.prototype.setvalue = setvalue
    miesiac.prototype.update = update
    this.set()
  }
  
  function miesiac_set()
  { 
    this.target.value = insert_separs(this.value)
    unit_on(this.target, " mc", 0)
    this.string_ = this.target.value
  } 
  
  function miesiac_get()
  {
    this.value = convert(this.target, 0)
  }
  
  function miesiac_change()
  {
    if (this.target.value != this.string_)
    {
      this.get()
      this.target.value = insert_separs(this.target.value, 1)
      this.string_ = this.target.value
    }
  }
  
  function miesiac_focus()
  {
    unit_off(this.target)
    this.string_ = this.target.value
    this.target.select()
  }
  
  function miesiac_blur()
  { 
    this.set()
  }

// ***************************************************************************
// Obiekt liczba
// ***************************************************************************
  
  function liczba(value_, dot_, target_)
  {
    this.value = this.string_ = value_
    this.target = target_
    this.dot = dot_
    liczba.prototype.set = liczba_set
    liczba.prototype.get = liczba_get
    liczba.prototype.change = liczba_change
    liczba.prototype.focus = liczba_focus
    liczba.prototype.blur = liczba_blur
    liczba.prototype.getvalue = getvalue
    liczba.prototype.setvalue = setvalue
    liczba.prototype.update = update
    this.set()
  }
  
  function liczba_set()
  { 
    this.target.value = insert_separs(Math.round(this.value*Math.pow(10, this.dot))/Math.pow(10, this.dot));
    this.string_ = this.target.value
  } 
  
  function liczba_get()
  {
    this.value = convert(this.target, 0)
  }
  
  function liczba_change()
  {
    if (this.target.value != this.string_)
    {
      this.get()
      this.target.value = insert_separs(this.target.value, 1)
      this.string_ = this.target.value
    }
  }
  
  function liczba_focus()
  {
    this.string_ = this.target.value
    this.target.select()
  }
  
  function liczba_blur()
  { 
    this.set()
  }

//************************************************************************************
  function str_len(string_)
  {
    return string_.length;
  }

  function str_insert(string_, char_, index)
  {
    string_+="";
    str1=string_.substr(0,index);
    str2=string_.substr(index);
    str1=str1.concat(char_);
    str1=str1.concat(str2);
    return str1;
  }

  function erase_separs(string_)
  {
    i = 0;  string_ += "";
    while ((i=string_.indexOf(".",i)) != -1) {
      string_ = string_.substring(0,i) + string_.substr(i+1); }
    string_ = string_.replace(",",".")
    return string_;
  }  

  function insert_separs(string_, erase)
  {
    if (erase) string_ = erase_separs(string_); else string_ += "";
    string_ = string_.replace(".",",")
    dot = string_.lastIndexOf(",");
    i = string_.length;
    if (dot>-1) {i-=i-dot;}
    if((string_.substr(0,1)=='-') || (string_.substr(0,1)=='+'))
      while (i>4)
        { string_ = str_insert(string_,".",i -= 3); }
    else
      while (i>3)
        { string_ = str_insert(string_,".",i -= 3); }
    return string_;
  }

  function add_zero(string_)
  {
    if (!string_) {string_="0";}
    dot = string_.lastIndexOf(",");
    if (dot != -1) {
      string_ = string_.substr(0,dot+3);    
      if (str_len(string_)-2==dot)
        string_ += "0";
    } else {
      string_ += ",00";    
    }
    return string_;    
  }  
  
  function check_value(value, on_error_value)
  {
    if (isNaN(parseFloat(value))) { value = on_error_value; }
    return value; 
  }
  
  function format(string_)
  {
     string_ = insert_separs(string_)
     string_ = add_zero(string_)
     return string_
  }

  function unit_off(sender)
  {
    sender.value = convert(sender, 0)
  }
  
  function unit_on(sender, unit, on_error_value)
  {
//    sender.value = convert(sender, on_error_value);
    sender.value += unit;
  }

  function convert(sender, on_error_value)
  {
//    alert(parseFloat(check_value(erase_separs(sender.value), on_error_value)));
    return parseFloat(check_value(erase_separs(sender.value), on_error_value));
  }

  function pobierz(value, currency)
  {
    return value
//    return value*document.forma.elements[currency].value
  }

  function przelicz(value, currency)
  {
//    return value/document.forma.elements[currency].value
    return value
  }
// -----------------------------------------------------------------------------------

// ************************************************************************************
//-->
