<!--

var previo="";
var previo_voz="";
var xmlHttpReq = false;
var xmlHttpReq_ejec=false;
var self = this;
if (window.XMLHttpRequest) {self.xmlHttpReq = new XMLHttpRequest();}else{
if (window.ActiveXObject) {self.xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");}
}

var xmlHttpReq_voz = false;
var xmlHttpReq_voz_ejec=false;
if (window.XMLHttpRequest) {self.xmlHttpReq_voz = new XMLHttpRequest();}else{
if (window.ActiveXObject) {self.xmlHttpReq_voz = new ActiveXObject("Microsoft.XMLHTTP");}
}

function cambiar_idiomas(i){
var origen=document.getElementById("origen-"+i).value;
var dest=document.getElementById("destino-"+i).value;
if(origen=="auto"){origen="es";}
document.getElementById("origen-"+i).value=dest;
document.getElementById("destino-"+i).value=origen;
}

function traducir(){
if(!xmlHttpReq_ejec){
var origen=document.getElementById("origen-t").value;
var dest=document.getElementById("destino-t").value;
if(origen==dest){
alert("ERROR: El idioma de origen es igual al de destino.");
document.getElementById("destino-t").focus();
return false;
}
var txt=document.getElementById("texto").value;
if(txt!=""){
previo=document.getElementById("salida").innerHTML;
document.getElementById("salida").innerHTML='<div class="traducido" style="background:url(images/cargando.gif) no-repeat center center;"></div>';
self.xmlHttpReq.open("POST", "traducir.php", true);
self.xmlHttpReq.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
self.xmlHttpReq.onreadystatechange = function(){
if (self.xmlHttpReq.readyState==4){
xmlHttpReq_ejec=false;
if(self.xmlHttpReq.status!=200){
document.getElementById("salida").innerHTML=previo;
if(document.getElementById("traduccion")){
document.getElementById("traduccion").innerHTML='<span style="color:#E80000;font-weight:bold;">Error al conectar con el traductor, por favor actualiza esta página.</span>';
}
return;
}
var html=self.xmlHttpReq.responseText;
document.getElementById('copiar-tr').innerHTML='<strong>Traducir</strong> / <span onclick="copiar_tr();">Usar traducción</span>';
if(html.substr(0,5)!="ERROR"&&html!=""){
document.getElementById("salida").innerHTML=html;
}else{
document.getElementById("salida").innerHTML=previo;
if(document.getElementById("traduccion")){
document.getElementById("traduccion").innerHTML='<span style="color:#E80000;font-weight:bold;">Error al conectar con el traductor, por favor actualiza esta página.</span>';
}
}
}
}
xmlHttpReq_ejec=true;
self.xmlHttpReq.send('origen='+origen+'&destino='+dest+'&txt='+escape(txt));
document.getElementById('texto').scrollTop=0;
}
}
}

function verificar(txt){
if(txt.length>1000){
document.getElementById('texto').value=txt.substr(0,1000);
}
document.getElementById('caracteres-escritos').innerHTML=txt.length;
return;
}

function copiando(){
if(window.clipboardData){
window.clipboardData.setData("Text", document.getElementById("traduccion").innerHTML);
}
}

function leer(c){
if(!xmlHttpReq_voz_ejec){
var txt=document.getElementById("traduccion").innerHTML;
if(txt.length>0){
previo_voz=document.getElementById('voz').innerHTML;
document.getElementById('voz').innerHTML='&nbsp;';
self.xmlHttpReq_voz.open("POST", "voz.php", true);
self.xmlHttpReq_voz.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
self.xmlHttpReq_voz.onreadystatechange = function(){
if (self.xmlHttpReq_voz.readyState==4){
xmlHttpReq_voz_ejec=false;
if(self.xmlHttpReq_voz.status!=200){
document.getElementById("voz").innerHTML=previo_voz;
return;
}
var html=self.xmlHttpReq_voz.responseText;
if(html.substr(0,5)!="ERROR"&&html!=""){
document.getElementById("voz").innerHTML=html;
}else{
document.getElementById("voz").innerHTML=previo_voz;
}
}
}
xmlHttpReq_voz_ejec=true;
self.xmlHttpReq_voz.send('clave='+escape(c));
}
}
}

function parar(){
if(document.getElementById("audio")){
document.getElementById("audio").innerHTML='&nbsp;';
document.getElementById("voz").innerHTML=previo_voz;
}
}

function desplaza(){
if(document.getElementById('traduccion')){
document.getElementById('traduccion').scrollTop=document.getElementById('texto').scrollTop;
}
}

function desplaza_tr(){
if(document.getElementById('texto')){
document.getElementById('texto').scrollTop=document.getElementById('traduccion').scrollTop;
}
}

function traducir_web(){
document.getElementById('boton-web').innerHTML='<img src="images/cargando_small.gif" width="24" height="24" />';
document.getElementById('boton-web').style.background='none';
document.getElementById('url').readOnly=true;
}

function copiar_tr(){
if(document.getElementById("traduccion")){
if(document.getElementById("traduccion").innerText){
document.getElementById("texto").value=document.getElementById("traduccion").innerText;
}else{
document.getElementById("texto").value=document.getElementById("traduccion").textContent;
}
}
}

//-->
