function myXMLHttpRequest (){
	var xmlhttplocal = false;
	if (typeof XMLHttpRequest != 'undefined') {
		try {
			xmlhttplocal = new XMLHttpRequest ();
		}
		catch (e) {
  			xmlhttplocal = false;
		}
	}
	if (!xmlhttplocal) {
		try {
			xmlhttplocal = new ActiveXObject ("Msxml2.XMLHTTP")
		}
		catch (e) {
			try {
				xmlhttplocal = new ActiveXObject ("Microsoft.XMLHTTP")
			}
			catch (E) {
				xmlhttplocal = false;
				alert ('Su navegador no soporta aplicaciones Ayax y esta página lo utiliza. En los niveles de seguridad de su Navegador active la opción: Permitir Activex y Javascript');
			}
  		}
	}
	return (xmlhttplocal);
}

function showResult(str){
	if (str.length == 0 || str.length == 1 || str.length == 2){
		temp = document.getElementById ('livesearch');
		if (temp) {		
			if(str!=''){
				temp.innerHTML="(Escriba al menos 4 caracteres): " +str;
				temp.style.border="";
			}else{
	  			temp.innerHTML="(Escriba al menos 4 caracteres): " +str;
	  		}
	  		return;
	  	}
	}

	resul = document.getElementById ('livesearch');
	if (resul) {
		var respuesta = new String;
		xmlhttp = new myXMLHttpRequest ();
		if (xmlhttp) {
				miurl= "proceso-caja-busqueda.php?q="+str;
				xmlhttp.open ("GET", miurl, true);
				errormatch = new RegExp ("^ERROR:");			
				xmlhttp.onreadystatechange = function () {
					if (xmlhttp.readyState == 4) {
						respuesta = xmlhttp.responseText;
						if (respuesta.match (errormatch)){	
							respuesta = respuesta.substring (6, respuesta.length);
							resul.innerHTML = respuesta;
						}else{
							resul.innerHTML = respuesta;
							resul.style.border="1px solid #A5ACB2";	
							resul.style.padding="5px 5px 5px 5px";
						}
					}
				}	
		}
		xmlhttp.send (null);		
	}

}//fun

function Descarga(){
	v_challenge = document.getElementById ('recaptcha_challenge_field');
	v_response = document.getElementById ('recaptcha_response_field');
	subtitulo = document.getElementById ('idsubtitulo');
	if (subtitulo.value=='') {
		alert('No se encuentra el identificador del subtitulo. Recargue la página.');	
		return false;
	}
	
 	var respuesta = new String;
	xmlhttp = new myXMLHttpRequest ();
	if (xmlhttp) {
			miurl = "descargar.php?id=" +subtitulo.value+ "&c=0&chal=" +v_challenge.value+ "&res="+v_response.value;
			xmlhttp.open ("GET", miurl, true);
			errormatch = new RegExp ("^ERROR:");			
			xmlhttp.onreadystatechange = function () {
				if (xmlhttp.readyState == 4) {
					respuesta = xmlhttp.responseText;
					if (respuesta.match (errormatch)){	
						respuesta = respuesta.substring (6, respuesta.length);
						alert(respuesta);
					}else{
						if(respuesta=="OK"){
							var elemIF = document.createElement("iframe");
							elemIF.src = "descargar.php?id=" +subtitulo.value+ "&c=1";
							elemIF.style.display = "none";
							document.body.appendChild(elemIF); 							
						}					
					}
				}
			}	
	}
	xmlhttp.send (null);
	return false;
}//fun

function Notifico(){
	alert('Escriba el nombre de la serie o película en la caja y haga clic en los resultados que van apareciendo debajo.');
	return false;
	
}
