
function formatnumber(number)   // 1.- It rounds the number up two decimals:  ( 1.234 ==> 1.23 ) and ( 1.456 ==> 1.46 )
{				// 2.- It adds a 0 before the point, if there is not any one:  ( .12 ==> 0.12 )
 var i = 0;			// 3.- It formats the two decimals: ( 1 ==> 1.00 ) and ( 1.2 ==> 1.20 )
 var result = "";
 var limit = 0;

 num = (Math.round(number*100))/100;	// ROUND THE NUMBER UP TWO DECIMALS
 num = num + "";

 var len = num.length;
 var posit = num.indexOf(".");

 if (num == "NaN")			// CONTROL OF THE MISTAKES
     result = "...";
 else{
     if (posit == "-1")
        result = num + ".00";
     else{
	if (posit == "0")		// ADD THE 0 BEFORE THE POINT
	   result = "0";
	
        limit = posit;
         
        if ((len-posit) >= 3)
            result = result + num;
        else{
            for (i=0; i<limit; i++)                 // ADD THE CHARS FROM THE 0 UNTIL THE CHAR BEFORE THE POINT
                result = result + num.charAt(i);
    
            result = result + ".";
            if ((len-posit) == 2)
                result = result + num.charAt(limit+1) + "0";
            else
                if ((len-posit) == 1)
                    result = result + "00";
           }
        }
     }
 
 return(result);
}

function convert(country, currency)
{
  var euros;

  if (country != "EUR"){
     eval("euros = document.cal." + country + ".value/" + currency + ";");
     eval("document.cal.EUR.value = formatnumber(euros);");
    }
  else{
     euros = document.cal.EUR.value;
     //document.cal.EUR.value = formatnumber(document.cal.EUR.value);
    }
  
  if (country != "ESP")  document.cal.ESP.value = formatnumber(euros*166.38);
};


