var ajaxRun = false;

function createRequestObject() {
	var ro;
	var browser = navigator.appName;
	
	if(browser == "Microsoft Internet Explorer") { ro = new ActiveXObject("Microsoft.XMLHTTP"); }
	else { ro = new XMLHttpRequest(); }

	return ro;
	}

var http = createRequestObject();

function ajax_convertir() {
	var fecha = document.getElementById('fecha').value
	var importe = document.getElementById('importe').value;
	var monedaOrigen = document.getElementById('moneda_origen').value;
	var monedasDestino = document.getElementById('monedas_destino');
	var language = document.getElementById('language').value;

	monedasSeleccionadas = 0;
	for (i = 0; i < monedasDestino.length; i++)
		{ if (monedasDestino.options[i].selected == true) { monedasSeleccionadas++; } }
	
	if ((monedaOrigen != 'NULL') && (monedasSeleccionadas > 0)) {
		
		monedasDestinoString = '';
		for (i = 0; i < monedasDestino.length; i++)
			{ if (monedasDestino.options[i].selected == true) { monedasDestinoString = monedasDestinoString+'&monedas_destino[]='+monedasDestino.options[i].value; } }

		var uri = '/web20/convertidor/convertidor.php?lang='+language+'&fecha='+fecha+'&importe='+importe+'&moneda_origen='+monedaOrigen+monedasDestinoString;
		if (ajaxRun == false) {
			ajaxRun = true;

			document.getElementById('div_convertidor').innerHTML = 'Convirtiendo<br /><img src="/web20/convertidor/img/loading.gif" alt="Conveirtiendo..." />';
			document.getElementById('div_convertidor').style.cursor = 'wait';
	
			http.open('get', uri);
			http.onreadystatechange = ajax_convertir_response;
			http.send(null);
			}
		}
	}

function ajax_convertir_response() {
    if(http.readyState == 4){
        var response = http.responseText;
		ajaxRun = false;

		document.getElementById('div_convertidor').innerHTML = response;
		document.getElementById('div_convertidor').style.cursor = 'default';
    	}
	}

function ajax_convertir_paging(monedaOrigen, monedasDestino, fecha, importe, language, pagina) {
	monedasDestinoString = '';
	for (i = 0; i < monedasDestino.length; i++)
		{ monedasDestinoString = monedasDestinoString+'&monedas_destino[]='+monedasDestino[i]; }

	var uri = '/web20/convertidor/convertidor.php?lang='+language+'&fecha='+fecha+'&importe='+importe+'&moneda_origen='+monedaOrigen+monedasDestinoString+'&pagina='+pagina;

	if (ajaxRun == false) {	
		ajaxRun = true;

		http.open('get', uri);
		http.onreadystatechange = ajax_convertir_response;
		http.send(null);
		}

	return false;
	}

function todas_las_monedas() {
	var items = document.getElementById('monedas_destino');
//	alert(items.length);
	for (i=items.length-1; i >= 0; i--)
		{ items.options[i].selected = true; }
	}