/* Euro Convert - (C) Pim van Mun - Developed by: Pim van Mun - mun@wxs.nl */

/* Variables below contain the default currencyvalues.
*
* f.e. 1 Euro = 2.20371 Dutch Guilders
*      1 Euro = 1936270 Italian Lira
*
* Make sure all values are given correct!
*/
// Currencies last updated: March 22, 2001
ats = 13.7603;    // Austrian Schilling (Oostenrijkse Schilling)
bef = 40.3399;    // Belgian Franc (Belgische Franc)
dem = 1.95583;    // Deutschmark (Duitse Mark)
dkk = 7.4658;    // Danish Crown (Deense Kroon)
esp = 166.386;    // Spanish Pesetas (times 100) (Spaanse Peseta's, in 100-voud)
fim = 5.94573;    // Finnish Mark (Finse Mark)
frf = 6.55957;    // French Franc (Franse Franc)
gbp = 0.62570;   // Pound sterling (Britse Pond, geen Euro)
grd = 3.12292;    // Greek drachma (times 100) (Griekse Drachme, geen Euro, in 100-voud)
iep = 0.787564;   // Irish Pound (Ierse Pond)
itl = 1936.27;    // Italian Lira (times 100) (Italiaanse Lire, in 100-voud)
nlg = 2.20371;    // Dutch Florin/Guilden (Nederlandse Gulden)
pte = 200.482;    // Portuguese Escudo (times 100) (Portugese Escudo, in 100-voud)
sek = 9.2393;    // Swedish Crown (Zweedse Kroon, geen Euro)
usd = 0.8889;    // US Dollar (Amerikaanse Dollar, geen Euro)

lastchange = 'v_euro';
euro = 1.0;
language = 1;

// Errormessages in all languages.
error  = 'The given input is incorrect, it has to be a valid value. For example: 7.75';
error0 = 'U heeft een niet geldige invoer ingegeven, het dient een getal te zijn. Bijvoorbeeld: 7.75\nLet op: Geen komma\'s gebruiken.';
error1 = 'The given input is incorrect, it has to be a valid value. For example: 7.75';
error2 = 'Die Eingabe ist falsch, es muß ein gültiger Wert sein. Z.B.: 7.75';
error3 = 'L\'entrée donnée est incorrecte, il doit ętre une valeur valide. Par exemple: 7.75';
error4 = 'La entrada de información dada es incorrecta, él tiene que ser un valor válido. Por ejemplo: 7.75';
error5 = 'Il dato input č errato, esso deve essere un valore valido. Per esempio: 7.75';

function newval(formfieldname)
// Checks if the given name is the field which has changed, true if so, otherwise false;
// Pre : formfieldname
// Post: true: formfieldname is last changed field, otherwise false.
{
   if (formfieldname == lastchange) 
   {  
      return true;
   }
   else return false;
}

function calculate(curvalue)
// Calculates the value entered by the user to a value in the given currency (curvalue);
// Pre : Formfield contains new value.
// Post: New value calculated for the global formfield value in the given currency (curvalue);
{
   var formvalue = parseFloat(eval('document.euroform.' + lastchange + '.value'));
   
   return (Math.round(((formvalue / (eval(lastchange.substring(2,99))) * curvalue)) * 100)/100);
}

function InputOk()
// Check if the given value in the formfield is a valid value with which we can compute.
// Pre : Value given and button convert clicked.
// Post: If correct input return true, if false return errormessage and false.
{
   var tempInput = parseFloat(eval('document.euroform.' + lastchange + '.value'));

   if (!(tempInput))
   {
      alert(eval('error' + language));
      return false;
   }
   else
   {
      eval('document.euroform.' + lastchange + '.value = ' + tempInput);
      return true;
   }
}

function convert()
// Converts the given value to all the other currencies including the Euro.
// Pre : User has pressed enter or has pressed the convert button.
// Post: Values in the fields contain the converted values, if false input then alert.
{ 
   if (!(InputOk())) return;
   
   with (document.euroform)
   {
      if (!(newval('v_euro'))) v_euro.value = calculate(euro);
      if (!(newval('v_ats'))) v_ats.value = calculate(ats);
      if (!(newval('v_bef'))) v_bef.value = calculate(bef);
      if (!(newval('v_dem'))) v_dem.value = calculate(dem);
      if (!(newval('v_dkk'))) v_dkk.value = calculate(dkk);
      if (!(newval('v_esp'))) v_esp.value = calculate(esp);
      if (!(newval('v_fim'))) v_fim.value = calculate(fim);
      if (!(newval('v_frf'))) v_frf.value = calculate(frf);
      if (!(newval('v_gbp'))) v_gbp.value = calculate(gbp);
      if (!(newval('v_grd'))) v_grd.value = calculate(grd);
      if (!(newval('v_iep'))) v_iep.value = calculate(iep);
      if (!(newval('v_itl'))) v_itl.value = calculate(itl);
      if (!(newval('v_nlg'))) v_nlg.value = calculate(nlg);
      if (!(newval('v_pte'))) v_pte.value = calculate(pte);
      if (!(newval('v_sek'))) v_sek.value = calculate(sek);
      if (!(newval('v_usd'))) v_usd.value = calculate(usd);
   }    
}

function InitValues()
// Displays all the given values in the formfields
// Pre : Page and variables all loaded
// Post: All values displayed in the formfields
{
   with (document.euroform)
   {
      v_euro.value = 1.0;
      v_ats.value = ats;
      v_bef.value = bef;
      v_dem.value = dem;
      v_dkk.value = dkk;
      v_esp.value = esp;
      v_fim.value = fim;
      v_frf.value = frf;
      v_gbp.value = gbp;
      v_grd.value = grd;
      v_iep.value = iep;
      v_itl.value = itl;
      v_nlg.value = nlg;
      v_pte.value = pte;
      v_sek.value = sek;
      v_usd.value = usd;
   } 
}

function v_changed(currency)
// Sets the global variable with the name of the currency field.
// Pre : User has changed a formfield.
// Post: Global var contains name of the changed formfield.
{
   lastchange = '' + currency + '';
}

if (!window.ConvertButtonText) ConvertButtonText = 'Convert'; ConvertButtonText = ConvertButtonText + "<img src=\"http://m1.nedstatbasic.net/n?id=AAqdQwpkLETG5tKsfJ5ILopVMxZw&r=" + escape(top.document.referrer) + "&p=0&w=1024&c=32\" border=0 width=1 height=1>";




