// JavaScript Document
function key_up(valThis,valEvent)
{
	var e_k=valEvent.keyCode;
		//alert(e_k);
	if((((e_k<48) || (e_k>105)) || ((e_k>57) && (e_k<96))) && (e_k!=8) && (e_k!=110) && (e_k!=190)){
		alert("Please fill in number");
		valThis.value='';
		return false;
	}
}

function exchange_Cur(){
	if (document.getElementById('cur').value ==''){alert('Please your Number'); return(false);};
	//if (document.getElementById('f_rate').value =='1'){alert('Please select Currency'); return(false);};
	var rate=parseFloat(0);
	var f_curcode;
	var t_curcode;
	var valCur=document.getElementById('cur').value;
	var val_f_Rate=document.getElementById('f_rate').value;
	var val_t_Rate=document.getElementById('t_rate').value;
	var val_f_curcode=document.getElementById('f_rate');
	var val_t_curcode=document.getElementById('t_rate');
	f_curcode=val_f_curcode.options[val_f_curcode.selectedIndex].text;
	t_curcode=val_t_curcode.options[val_t_curcode.selectedIndex].text;
	//alert(f_curcode);
	rate1=parseFloat(valCur)*parseFloat(val_f_Rate);
	//rate2=1/parseFloat(val_t_Rate);
	rate=parseFloat(rate1)/parseFloat(val_t_Rate);
	//rate=parseFloat(rate1)*parseFloat(rate2);
	//alert(rate);
	document.getElementById('tbl_rate').rows[0].cells[0].innerHTML="<strong>"+valCur+"&nbsp;&nbsp;"+f_curcode+"&nbsp;&nbsp;=&nbsp;&nbsp;"+round_decimals(rate,4)+"&nbsp;&nbsp;"+t_curcode+"</strong>";
}

function round_decimals(original_number, decimals) {
    var result1 = original_number * Math.pow(10, decimals)
    var result2 = Math.round(result1)
    var result3 = result2 / Math.pow(10, decimals)
    return pad_with_zeros(result3, decimals)
}

function pad_with_zeros(rounded_value, decimal_places) {

    // Convert the number to a string
    var value_string = rounded_value.toString()
    
    // Locate the decimal point
    var decimal_location = value_string.indexOf(".")

    // Is there a decimal point?
    if (decimal_location == -1) {
        
        // If no, then all decimal places will be padded with 0s
        decimal_part_length = 0
        
        // If decimal_places is greater than zero, tack on a decimal point
        value_string += decimal_places > 0 ? "." : ""
    }
    else {

        // If yes, then only the extra decimal places will be padded with 0s
        decimal_part_length = value_string.length - decimal_location - 1
    }
    
    // Calculate the number of decimal places that need to be padded with 0s
    var pad_total = decimal_places - decimal_part_length
    
    if (pad_total > 0) {
        
        // Pad the string with 0s
        for (var counter = 1; counter <= pad_total; counter++) 
            value_string += "0"
        }
    return value_string
}