function getkey(e)
{
if (window.event)
   return window.event.keyCode;
else if (e)
   return e.which;
else
   return null;
}


function goodchars(e, goods)
{
var key, keychar;
key = getkey(e);
if (key == null) return true;

// get character
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();
goods = goods.toLowerCase();

// check goodkeys
if (goods.indexOf(keychar) != -1)
	return true;

// control keys
if ( key==null || key==0 || key==8 || key==9 || key==13 || key==27 )
   return true;

// else return false
return false;
}

function addCommas(nStr)
{
	nStr += '';
	x = nStr.split('.');
	x1 = x[0];
	x2 = x.length > 1 ? '.' + x[1] : '';
	var rgx = /(\d+)(\d{3})/;
	while (rgx.test(x1)) {
		x1 = x1.replace(rgx, '$1' + ',' + '$2');
	}
	return x1 + x2;
}


function calculeaza() {
  if (document.getElementById('dince')) {
	  var cevaloare1 = document.getElementById('dince').value;
  }
  if (document.getElementById('ince')) {
	  var cevaloare2 = document.getElementById('ince').value;
  }

	var valuta1 = document.convertor.valuta1.value;
	var valuta2 = ((cevaloare1 * valuta1)/cevaloare2).toFixed(2);

	document.convertor.valuta2.value = valuta2;

	var valuta4 = (valuta2*1.19).toFixed(2);
	document.convertor.valuta4.value = valuta4;

	var valuta5 = (valuta4 - valuta2).toFixed(2);
	document.convertor.valuta5.value = valuta5;

	var sel2 = document.getElementById('ince');
	var sel2text = sel2.options[sel2.selectedIndex].text;

	document.getElementById('valutasel').innerHTML = sel2text;
}


function dince()
{
var str='';
str+='<select class="turnintodropdown" name="dince" id="dince" onChange="calculeaza()">';
for (key in valute)
{
str+='<option value="'+valute[key]+'"';
if (key=='EUR')
{
str+=' selected';
}

str+='>'+key+'</option>';
}
str+='<\/select>';

document.write(str);
}


function ince()
{
var str='';
str+='<select class="turnintodropdown" name="ince" id="ince" onChange="calculeaza()">';
for (key in valute)
{
str+='<option value="'+valute[key]+'">'+key+'</option>';
}
str+='<\/select>';

document.write(str);
}