﻿var conexion1;
var conexion2;
var conexion3;

function addEvent(elemento,nomevento,funcion,captura)
{
  if (elemento.attachEvent)
  {
    elemento.attachEvent('on'+nomevento,funcion);
    return true;
  }
  else  
    if (elemento.addEventListener)
    {
      elemento.addEventListener(nomevento,funcion,captura);
      return true;
    }
    else
      return false;
}

function crearXMLHttpRequest() 
{
  var xmlHttp=null;
  if (window.ActiveXObject) 
    xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
  else 
    if (window.XMLHttpRequest) 
      xmlHttp = new XMLHttpRequest();
  return xmlHttp;
}

function procesarTraduccion()
{
    sb = document.getElementById("TradResultado");
    if(conexion1.readyState == 4)
        sb.innerHTML = conexion1.responseText;
}
  
function procesarDestino()
{
    sb = document.getElementById("trdDestino");    
    if(conexion2.readyState == 4)
        sb.innerHTML = conexion2.responseText;
}

function procesarTraductor()
{
    sb = document.getElementById("trdTraductor");    
    if(conexion3.readyState == 4)
        sb.innerHTML = conexion3.responseText;
}


function getTraduccion(batch)
{
	fr=document.getElementById("f");
	variables="?Origen=" + fr.Origen.value + "&Destino=" + fr.Destino.value + "&Traductor=" + fr.Traductor.value + "&MiArea=" + fr.MiArea.value;
//	cad = "http://localhost/traductor/codes/trdResultado.php" + variables;
	cad = "http://www.traductor.es/codes/trdResultado.php" + variables;
	conexion1=crearXMLHttpRequest();
	conexion1.onreadystatechange = procesarTraduccion;
	conexion1.open('GET',cad, true);
	conexion1.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	conexion1.send();  
}

function getDestino(){
	fr=document.getElementById("f");
	variables="?origen=" + fr.Origen.value; 
//	cad = "http://localhost/traductor/codes/destino.php" + variables;
	cad = "http://www.traductor.es/codes/destino.php" + variables;
	conexion2=crearXMLHttpRequest();
	conexion2.onreadystatechange = procesarDestino;
	conexion2.open('GET',cad, true);
	conexion2.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	conexion2.send();  
}

function getTraductor(){
	fr=document.getElementById("f");
	variables="?origen=" + fr.Origen.value + "&destino=" + fr.Destino.value; 
//	cad = "http://localhost/traductor/codes/eltraductor.php" + variables;
	cad = "http://www.traductor.es/codes/eltraductor.php" + variables;
	conexion3=crearXMLHttpRequest();
	conexion3.onreadystatechange = procesarTraductor;
	conexion3.open('GET',cad, true);
	conexion3.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	conexion3.send();  
}

function moverOD(o,d){
	fr=document.getElementById("f");
	fr.Origen.value=o;
	var op1 = new Option(d, d); 
	fr.Destino.appendChild(op1);
	fr.Destino.value=d;
	getTraductor();
}

