
function iniciar() {
	document.trans.source.focus();
}

function validar_url() {
	if (document.translator.url.value == "http://") {
		alert('Dirección URL incorrecta');
		document.translator.url.focus();
		return false;
	}
	else
		document.translator.submit();
}

function validar_txt() {
	if (document.trans.source.value.length == 0) {
		alert('El texto a traducir está vacío');
		document.trans.source.focus();
		return false;
	}
	if (document.trans.source.value.length >= 1024) {
		alert('El texto no puede tener más de 1024 caracteres');
		document.trans.source.focus();
		return false;
	}

	
  for(i=0; i<document.trans.source.value.length-1; i++) {
   if (document.trans.source.value.charCodeAt(i) == 13 && document.trans.source.value.charCodeAt(i+1) == 10) {
    if (i != document.trans.source.value.length-2) {
     document.trans.source.value = document.trans.source.value.substring(0, i+1) + " " + document.trans.source.value.substring(i+2, document.trans.source.value.length-1);
     i=i+2;
    } else {
     document.trans.source.value = document.trans.source.value.substring(0, i) + " ";
    }
   }
  }
	
	document.trans.orig.value = escape(document.trans.source.value);

	document.trans.submit();
}

function inputKeyPress(e,f){	if (e.keyCode == 13) doSubmit(f);	return true;}

function doSubmit(f) {
	var context = "news"; 	
	//if(f.q.value.length > 3){
		try{
			var query = f.q.value;	
			for (i=0;i<f.buscar.length;i++) { 		
				if (f.buscar[i].checked) { 
					context = f.buscar[i].value; 
					break; 
				}	
			}
		}catch(err){
		}
			
		if (context=="image") {
			//submitYaTV(context,query);			
			self.location.href = "http://busca.ya.com/search?origen=header&buscar="+query+"&destino=imagen";
		}else if (context=="news") {
			self.location.href = "http://busca.ya.com/search?origen=header&buscar="+query+"&destino=news";	
		}else{
			self.location.href = "http://busca.ya.com/search?origen=header&buscar="+query+"&destino=web"; 
		}


	//}else{
	//	alert("La búsqueda tiene que tener como mínimo 4 caracteres.");
	//}
}
function submitYaTV(format,query) {	
	var action = "http://buscar.ya.com/fast-cgi/tsc?adtest=&mandant=toi&portallanguage=es&userlanguage=es&device=html&context=img&iocr=yes&tax_max=&tax=&language=&ocontext=&dia=tsc&hdr=1&lang=primary&q="+query;	
	if (query.length<1) 
		action = "http://www.yatv.com";	
	self.location.href = action;
}
function submitYa(f,context,query) {			
		if (context == "news") {
			//f.action = "http://buscador.noticias.ya.com/Search";	
			//f.Q.value = query;
			window.location.href = "http://buscador.noticias.ya.com/Search?M=newsresults&Q=" + query;
		}else if (context == "dpd") {
			//f.action = "/Search";	
			//f.Q.value = query;
			window.location.href = "http://buscador.deportistadigital.com/Search?M=sportsresults&Q=" + query;	
		} else {
			//f.action = "http://buscar.ya.com/fast-cgi/tsc";
			//f.submit();	
			var redir = '';
		   redir +='http://buscar.ya.com/fast-cgi/tsc';
		   redir +='?type='+f.type.value;
		   redir +='&PortalLanguage='+f.PortalLanguage.value;
		   redir +='&UserLanguage='+f.UserLanguage.value;
		   redir +='&language='+f.language.value;
		   redir +='&lang='+f.lang.value;
		   redir +='&mandant='+f.mandant.value;
		   redir +='&device='+f.device.value;
		   redir +='&iocr='+f.iocr.value;
		   redir +='&search_type='+f.search_type.value;
		   redir +='&q='+f.q.value;
		   redir +='&context='+f.context.value; 
		   window.location.href = redir;

		}				
}