/* Euro Convert - (C) Pim van Mun - Developed by: Pim van Mun - mun at wxs dot nl, PHP feed Patrick OBeirne Sysmod.com */

var ConvertButtonText, eur, v_eur_value, lastchange, language, updated;

ConvertButtonText = 'Convert';
ConvertButtonText = ConvertButtonText + "<img nosave src=\"http://www.nedstat.nl/cgi-bin/nedstat.gif?name=calceuro\" border=0 width=1 height=1><img src=\"http://nl.nedstatbasic.net/cgi-bin/referstat.gif?name=calceuro&refer=" + (escape(top.document.referrer)) + "\" width=1 height=1 border=0>";

eur = 1.0;
v_eur_value = eur ;
lastchange = 'v_eur';
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_eur'))) v_eur.value = calculate(eur);
      if (!(newval('v_usd'))) v_usd.value = calculate(usd);
      if (!(newval('v_jpy'))) v_jpy.value = calculate(jpy);
      if (!(newval('v_dkk'))) v_dkk.value = calculate(dkk);
      if (!(newval('v_gbp'))) v_gbp.value = calculate(gbp);
      if (!(newval('v_sek'))) v_sek.value = calculate(sek);
      if (!(newval('v_chf'))) v_chf.value = calculate(chf);
      if (!(newval('v_hrk'))) v_hrk.value = calculate(hrk);
      if (!(newval('v_nok'))) v_nok.value = calculate(nok);
      if (!(newval('v_bgn'))) v_bgn.value = calculate(bgn);
      if (!(newval('v_ron'))) v_ron.value = calculate(ron);
      if (!(newval('v_czk'))) v_czk.value = calculate(czk);
      if (!(newval('v_ils'))) v_ils.value = calculate(ils);
      if (!(newval('v_huf'))) v_huf.value = calculate(huf);
      if (!(newval('v_ltl'))) v_ltl.value = calculate(ltl);
      if (!(newval('v_lvl'))) v_lvl.value = calculate(lvl);
      if (!(newval('v_rub'))) v_rub.value = calculate(rub);
      if (!(newval('v_pln'))) v_pln.value = calculate(pln);
      if (!(newval('v_cny'))) v_cny.value = calculate(cny);
      if (!(newval('v_inr'))) v_inr.value = calculate(inr);
      if (!(newval('v_aud'))) v_aud.value = calculate(aud);
      if (!(newval('v_cad'))) v_cad.value = calculate(cad);
   }    
}


/* Initializes formfields to value of 1 euro
   can only do when form loaded and variables defined
   Pre : Page and variables all loaded
   Post: All values displayed in the formfields
*/
function InitValues()
{
   lastchange = 'v_eur';
   with (document.euroform)
   {
      v_eur.value = 1.0;
      v_usd.value = usd;
      v_jpy.value = jpy;
      v_dkk.value = dkk;
      v_gbp.value = gbp;
      v_sek.value = sek;
      v_chf.value = chf;
      v_hrk.value = hrk;
      v_nok.value = nok;
      v_bgn.value = bgn;
      v_ron.value = ron;
      v_czk.value = czk;
      v_ils.value = ils;
      v_huf.value = huf;
      v_ltl.value = ltl;
      v_lvl.value = lvl;
      v_rub.value = rub;
      v_pln.value = pln;
      v_cny.value = cny;
      v_inr.value = inr;
      v_aud.value = aud;
      v_cad.value = cad;
   } 
}


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 + '';
}

