document.write('<table cellpadding=0 cellspacing=0 width="230">');
try {
	var key, val, strVar;
	strVar = "";
	
	for(var i=0; i < vForexs.length; i++)
	{
		key = vForexs[i];
		val = vCosts[i];
			
		document.write('<tr><td>' + key + '</td><td align="right">' + val + '</td></tr>');
		strVar = strVar + key + "-" + val + ";";
	}
	document.write('<img src="update.php?cur='+strVar+'" height=0 width=0 style="display:none">');
}
catch (error) { document.write('');}
document.write('</table>');


function _hide(id){
	return document.getElementById ? document.getElementById(id) : document.all ? document.all[id] : document.layers[id]
}


function changeCurrency(amount, from, to) {
	var tmp = amount.toString().replace(/\_hide|\,/g,'');
	var varCur;
	if(from > -1) {
		varCur = vCosts[from];
//		eval('varCur = vCost' + from + ';');
		tmp = parseFloat(tmp) * parseFloat(varCur.toString().replace(/\_hide|\,/g,''));
	}
	if(to > -1) {
//		eval('varCur = vCost' + to + ';');
		varCur = vCosts[to];
		tmp = parseFloat(tmp) / parseFloat(varCur.toString().replace(/\_hide|\,/g,''));
	}
	prefix = null;
	tmp = tmp.toString();
	if((pos = tmp.indexOf(".")) > -1) {
		prefix = tmp.substr(pos, 3);
		tmp = tmp.substr(0, pos);
	}
	for(var i=0; i < Math.floor((tmp.length - (1 + i))/3); i++)
		tmp = tmp.substring(0, tmp.length - (4*i + 3)) + ',' + tmp.substring(tmp.length - (4*i+3));
	if(prefix != null) tmp = tmp + prefix;
	return tmp;
}

function DoChangeCurrency() {
	amount = _hide('currency_amount').value;
	from = _hide('currency_from').value;
	to = _hide('currency_to').value;
	_hide('currency_result').innerHTML = changeCurrency(amount, from, to);
}

function ImportCurrency() {
	var key, val;
	from = _hide('currency_from');
	to = _hide('currency_to');
	for(var i=0; i < 12; i++) {
		key = vForexs[i];
//		eval('key = vForex' + i + ';');
		if(typeof key != 'undefined') {
			from.options[i] = new Option(key, i);
			to.options[i] = new Option(key, i);
		}
	}
	from.options[i] = new Option("VND", -1);
	to.options[i] = new Option("VND", -1);
}
