function checkNumeric(value)
{
      var anum=/(^\d+$)|(^\d+\.\d+$)/;
      if (anum.test(value))
      	return true;
      return false;
}

function exchange(transport){
	var suma = $('txtsuma');
	var exchangeRate = transport.responseText;
	var rezultat = $('txtrezultat');
	var tva = $('txttva');
	var resultAndTva = $('txtreztva');
	
	//alert("rata este : " + exchangeRate);
	//if(!isNaN(suma.value)){
		var rez = suma.value * exchangeRate;
		rezultat.value = rez.toFixed(4);
		
		rez = rezultat.value * 19 / 100;
		tva.value = rez.toFixed(4);
		
		rez = parseFloat(rezultat.value) + parseFloat(tva.value);
		resultAndTva.value = rez.toFixed(4);
	//}
	//else{
	//	rezultat.value = "";
	//	tva.value = "";
	//	resultAndTva.value = ;
	//}
} 

function exchangeAtDate(transport){
	var suma = $('txtsuma_conv');
	var exchangeRate = transport.responseText;
	//alert("rate = :" + exchangeRate + "-");
	var rezultat = $('txtrezultat_conv');
	var tva = $('txttva_conv');
	var resultAndTva = $('txtreztva_conv');
	
	//alert("rata este : " + exchangeRate);
	//if(!isNaN(suma.value)){
		var rez = suma.value * exchangeRate;
		rezultat.value = rez.toFixed(4);
		
		rez = rezultat.value * 19 / 100;
		tva.value = rez.toFixed(4);
		
		rez = parseFloat(rezultat.value) + parseFloat(tva.value);
		resultAndTva.value = rez.toFixed(4);
	//}
	//else{
	//	rezultat.value = "";
	//	tva.value = "";
	//	resultAndTva.value = ;
	//}
} 

function exchangeAjax(){
	var from = $('lstdin');
	var to = $('lstin');
	
	var	url = 'libs/exchangeRate.php?from=' + from.value + '&to=' + to.value;
	
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    exchange(transport);
	  }
	});
}

function exchangeAjaxAtDate(){
	//alert('Aici');
	
	var from = $('lstdin_conv');
	var to = $('lstin_conv');
	
	//var month;
	//if($('month_conv').value < 10) month = "0" + $('month_conv').value;
	//else month = $('month_conv').value;
	
	//var timestamp = "" + $('year_conv').value + "-" + month + "-" + $('day_conv').value;
	//var url = 'libs/exchangeRate.php?from=' + from.value + '&to=' + to.value + "&timestamp=" + timestamp;
	
	var url = 'libs/exchangeRate.php?from=' + from.value + '&to=' + to.value + 
	"&year=" + $('year_conv').value + "&month=" + $('month_conv').value + "&day=" + $('day_conv').value;	
	//alert(url);
	new Ajax.Request(url, {
	  method: 'get',
	  onSuccess: function(transport) {
	    exchangeAtDate(transport);
	  }
	});
	
}

function chkDigits(obj)
{
   if (isNaN(document.getElementById(obj).value))
   {
    alert("Please enter digits");
    document.getElementById(obj).value = "";
    document.getElementById(obj).focus();
    document.getElementById(obj).select();
    return false;
  }
  return true;
}

