function exc(c){
	
	var r1c1Obj = document.getElementById("r_1_c_1");
	var r1c2Obj = document.getElementById("r_1_c_2");
	var r1c3Obj = document.getElementById("r_1_c_3");

	var r2c1Obj = document.getElementById("r_2_c_1");
	var r2c2Obj = document.getElementById("r_2_c_2");
	var r2c3Obj = document.getElementById("r_2_c_3");

	var r3c1Obj = document.getElementById("r_3_c_1");
	var r3c2Obj = document.getElementById("r_3_c_2");
	var r3c3Obj = document.getElementById("r_3_c_3");
	
	var r4c1Obj = document.getElementById("r_4_c_1");
	var r4c2Obj = document.getElementById("r_4_c_2");
	var r4c3Obj = document.getElementById("r_4_c_3");
	

	if(c == "THB"){
			
			r1c1Obj.innerHTML = CommaFormatted(R["r_1_c_1"].toFixed(2)) + " THB"; 
			r1c2Obj.innerHTML = CommaFormatted(R["r_1_c_2"].toFixed(2)) + " THB";
			r1c3Obj.innerHTML = CommaFormatted(R["r_1_c_3"].toFixed(2)) + " THB";

			r2c1Obj.innerHTML = CommaFormatted(R["r_2_c_1"].toFixed(2)) + " THB"; 
			r2c2Obj.innerHTML = CommaFormatted(R["r_2_c_2"].toFixed(2)) + " THB";
			r2c3Obj.innerHTML = CommaFormatted(R["r_2_c_3"].toFixed(2)) + " THB";

			r3c1Obj.innerHTML = CommaFormatted(R["r_3_c_1"].toFixed(2)) + " THB"; 
			r3c2Obj.innerHTML = CommaFormatted(R["r_3_c_2"].toFixed(2)) + " THB";
			r3c3Obj.innerHTML = CommaFormatted(R["r_3_c_3"].toFixed(2)) + " THB";
			
			r4c1Obj.innerHTML = CommaFormatted(R["r_4_c_1"].toFixed(2)) + " THB"; 
			r4c2Obj.innerHTML = CommaFormatted(R["r_4_c_2"].toFixed(2)) + " THB";
			r4c3Obj.innerHTML = CommaFormatted(R["r_4_c_3"].toFixed(2)) + " THB";
			
	}else{ 
			var R_1_C_1 = R["r_1_c_1"]/ex[c];
			var R_1_C_2 = R["r_1_c_2"]/ex[c];
			var R_1_C_3 = R["r_1_c_3"]/ex[c];

			r1c1Obj.innerHTML = CommaFormatted(R_1_C_1.toFixed(2)) + " " + c; 
			r1c2Obj.innerHTML = CommaFormatted(R_1_C_2.toFixed(2)) + " " + c;
			r1c3Obj.innerHTML = CommaFormatted(R_1_C_3.toFixed(2)) + " " + c;
			
			var R_2_C_1 = R["r_2_c_1"]/ex[c];
			var R_2_C_2 = R["r_2_c_2"]/ex[c];
			var R_2_C_3 = R["r_2_c_3"]/ex[c];

			r2c1Obj.innerHTML = CommaFormatted(R_2_C_1.toFixed(2)) + " " + c; 
			r2c2Obj.innerHTML = CommaFormatted(R_2_C_2.toFixed(2)) + " " + c;
			r2c3Obj.innerHTML = CommaFormatted(R_2_C_3.toFixed(2)) + " " + c;

			var R_3_C_1 = R["r_3_c_1"]/ex[c];
			var R_3_C_2 = R["r_3_c_2"]/ex[c];
			var R_3_C_3 = R["r_3_c_3"]/ex[c];

			r3c1Obj.innerHTML = CommaFormatted(R_3_C_1.toFixed(2)) + " " + c; 
			r3c2Obj.innerHTML = CommaFormatted(R_3_C_2.toFixed(2)) + " " + c;
			r3c3Obj.innerHTML = CommaFormatted(R_3_C_3.toFixed(2)) + " " + c;
			
			var R_4_C_1 = R["r_4_c_1"]/ex[c];
			var R_4_C_2 = R["r_4_c_2"]/ex[c];
			var R_4_C_3 = R["r_4_c_3"]/ex[c];

			r4c1Obj.innerHTML = CommaFormatted(R_4_C_1.toFixed(2)) + " " + c; 
			r4c2Obj.innerHTML = CommaFormatted(R_4_C_2.toFixed(2)) + " " + c;
			r4c3Obj.innerHTML = CommaFormatted(R_4_C_3.toFixed(2)) + " " + c;
	}
}

function CommaFormatted(amount)
{
	var delimiter = ",";
	var a = amount.split('.',2)
	var d = a[1];
	var i = parseInt(a[0]);
	if(isNaN(i)) { return ''; }
	var minus = '';
	if(i < 0) { minus = '-'; }
	i = Math.abs(i);
	var n = new String(i);
	var a = [];
	while(n.length > 3)
	{
		var nn = n.substr(n.length-3);
		a.unshift(nn);
		n = n.substr(0,n.length-3);
	}
	if(n.length > 0) { a.unshift(n); }
	n = a.join(delimiter);
	if(d.length < 1) { amount = n; }
	else { amount = n + '.' + d; }
	amount = minus + amount;
	return amount;
}
