var reqAjax;
function convertCurrency($id) {
	var _amount = $jQ('#amount-'  + $id).val();
	if (isNaN(_amount)) {
		$jQ('#convResult-' + $id).html('<span id="error">Invalid amount entered</span>');
		return
	}
	var _curr_from = $jQ('#curr_from-' + $id).val();
	var _curr_to = $jQ('#curr_to-' + $id).val();
	$jQ('#curreXbody-' + $id).block({
		message: curreX_Loader,
		css: {
			border: 'none',
			background: 'transparent'
		}
	});
	try {
		reqAjax = $jQ.ajax({
			type: "POST",
			url: curreX_Backend_URL,
			dataType: "json",
			data: "action=convert" + "&amount=" + _amount + "&currfrom=" + _curr_from + "&currto=" + _curr_to,
			success: function (json) {
				$jQ('#convResult-' + $id).html('&nbsp;');
				$jQ('#curreXbody-' + $id).unblock();
				switch (json.errcode) {
				case 'ERR-100':
					
					if (_curr_to != 'USD'){
						var _convamount = json.result == '0' ? '0.00': json.result;
						var _amount = parseFloat(_convamount);
						_amount = _amount.toFixed(_decimal_places);
						$jQ('#price-' + $id).html( _curr_to + ' ' + _amount );
					
					}else{
						var _amount = $jQ('#amount-'  + $id).val();
						$jQ('#price-' + $id).html( '$' + _amount );
					}
					document.getElementById('curreX-' + $id).style.display = 'none';
					break;
				case 'ERR-200':
					$jQ('#convResult-' + $id).html(json.errmsg);
					break;
				default:
					$jQ('#convResult-' + $id).html(json.errmsg);
					break
				}
			},
			error: function (xhr, msg, ex) {
				alert(xhr.responseText);
				reqAjax = null
			}
		})
	} catch(e) {
		alert(e)
	}
}
function toggleSelect(_object) {
	document.getElementById(_object).disabled = document.getElementById(_object).disabled == true ? false: true;
	if (document.getElementById(_object).disabled == true) document.getElementById(_object).selectedIndex = -1
}
function checkDecimal() {
	if (isNaN($jQ('#curreX-decimal-' + $id).val())) $jQ('#curreX-decimal-' + $id).val('')
}

function toggleCur(element){
      if(document.getElementById(element).style.display = 'none')
      {
        document.getElementById(element).style.display = 'block';
      }
      else if(document.getElementById(element).style.display = 'block')
      {
        document.getElementById(element).style.display = 'none';
      }
}
