// JavaScript Document

// Objeto Ajax
function nuevoAjax(){
	var xmlhttp=false;
 	try {
 		xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
 	} catch (e) {
 		try {
 			xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
 		} catch (E) {
 			xmlhttp = false;
 		}
  	}

	if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
 		xmlhttp = new XMLHttpRequest();
	}
	return xmlhttp;
}
//Fin objeto Ajax

//Envio de Loguin
function EnviarLogin(User,Pass){
	//alert(Nombre);
	var contenedor,Respuesta;
	contenedor = document.getElementById('mensajes');
	ajax=nuevoAjax();
	ajax.open("POST", "phpinclude/validateUserPass.php",true);
	ajax.onreadystatechange=function() {
		if (ajax.readyState==4) {
		   Respuesta = ajax.responseXML;
		   var existe = Respuesta.getElementsByTagName('existe').item(0).firstChild.data;
			if(existe=="OK"){//el formulario se envia si todo ha ido correctamente
			    contenedor.innerHTML="OK";
    			document.f.submit();
			}else{
				contenedor.innerHTML="Usuario Incorrecto";
			}
			//contenedor.innerHTML=ajax.responseText;
	}
}	
 
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("user="+User+"&pass="+Pass);
	
}
//Fin envio de loguin

//Método que recibe de flash
function BuscarSeccion(pagina,idioma){
	//alert(pagina);
	var contenedor;
	contenedor = document.getElementById('CajaContenedora');
	contenedor.innerHTML="<br><center><img src='images/loading.gif' /></center>";
	//contenedor.innerHTML="";
	document.getElementById('CajaContenedora').style.zIndex=1;
	ajax=nuevoAjax();
	
	ajax.onreadystatechange=function() {
	if (ajax.readyState==1) {
           contenedor.style.display="block";
         }
	if (ajax.readyState==4) {
			if(pagina=="contacto.php"){
				document.getElementById('CajaContenedora').style.overflowY="hidden";
				//document.getElementById('CajaContenedora').style.display="none";
			}else{
			document.getElementById('CajaContenedora').style.overflowX="hidden";
			document.getElementById('CajaContenedora').style.overflowY="auto";
			}
		   contenedor.innerHTML = ajax.responseText;
		   //setTimeout("document.getElementById('CajaContenedora').style.display='block'",500);
			
		}
	}

	ajax.open("POST", pagina,true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("Idioma="+idioma);
		

	
}


//fin de método que recibe de flash

//Método que lee noticias
function VerInfo(IdInfo,pagina,idioma){
	//alert(idioma);
	var contenedor;
	contenedor = document.getElementById('CajaContenedora');
	contenedor.innerHTML="";
	contenedor.innerHTML="<br><center><img src='images/loading.gif' /></center>";
	ajax=nuevoAjax();
	ajax.onreadystatechange=function() {
		if (ajax.readyState==1) {
           
		   contenedor.style.display="block";
         }
		if (ajax.readyState==4) {
		   contenedor.innerHTML = ajax.responseText;
			
		}
}	
 
 	ajax.open("POST", pagina,true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("IdInfo="+IdInfo+"&Idioma="+idioma);
	
	
}

//Envio de Contacto
function Contacto(nombre,email,asunto,mensaje,idioma){
	//alert(Nombre);
	var contenedor;
	contenedor = document.getElementById('recibirAjax');
	
	ajax=nuevoAjax();
	ajax.onreadystatechange=function() {
		if (ajax.readyState==1) {
           //contenedor.innerHTML="<br><center><img src='images/loading.gif' widht='150' height='150' /></center>";
         }
		if (ajax.readyState==4) {
			document.getElementById('CajaContenedora').style.overflow="hidden";
		   contenedor.innerHTML = "";
		   alert(ajax.responseText);
		   window.document.formulario1.Nombre.value="";
		   window.document.formulario1.Email.value="";
		   window.document.formulario1.asunto.value="";
		   window.document.formulario1.Mensaje.value="";
	}
}	

	ajax.open("POST", "Contactar.php",true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("Nombre="+nombre+"&Email="+email+"&asunto="+asunto+"&Mensaje="+mensaje+"&Idioma="+idioma);
 

	
}
//fin de método 
//Envio de Contacto
function ContactoNumero(nombre,telefono,idioma){
	//alert(Nombre);
	var contenedor;
	contenedor = document.getElementById('recibirAjax');
	
	ajax=nuevoAjax();
	ajax.onreadystatechange=function() {
		if (ajax.readyState==1) {
          // contenedor.innerHTML="<br><center><img src='images/loading.gif' widht='150' height='150' /></center>";
		  document.getElementById('CajaContenedora').style.overflowY="hidden";
         }
		if (ajax.readyState==4) {
		   contenedor.innerHTML = "";
		   alert(ajax.responseText);
            window.document.formBajo.nombreFormBajo.value="";
            window.document.formBajo.telefonoFormBajo.value="";
	}
}	
 
	ajax.open("POST", "ContactarTelefono.php",true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("Nombre="+nombre+"&Telefono="+telefono+"&Idioma="+idioma);
	
}
//fin de método 


//Envio de Contacto
function EnviarGraphic(email,listas){
	var contenedor;
	//contenedor = document.getElementById('recibirAjax2');
	
	var NuevaLista=listas.split("|");
	for(var i=0;i<NuevaLista.length-1;i++){
		var Pagina="https://www.graphicmail.com.es/api.aspx?Username=info@didascalia.es&Password=x1oE5iFA&Function=post_subscribe&Email="+email+"&MailinglistID="+NuevaLista[i]+"&SID=7"
	
	
	ajax=nuevoAjax();
	ajax.onreadystatechange=function() {
		if (ajax.readyState==1) {
          // contenedor.innerHTML="<br><center><img src='images/loading.gif' widht='150' height='150' /></center>";
         }
		if (ajax.readyState==4) {
		   //contenedor.innerHTML = ajax.responseText;
	}
}	
 
	ajax.open("GET", Pagina,true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send();
	
	}//fin for
	
}
//fin de método 

//Envio de Contacto
function EnviarNews(nombre,apellido,email,listas,nombreListas,idioma){
	//alert(nombre+email+listas+nombreListas);
	var contenedor;
	contenedor = document.getElementById('recibirAjax');
	//EnviarGraphic(email,listas);
	
	ajax=nuevoAjax();

	ajax.onreadystatechange=function() {
		if (ajax.readyState==1) {
           contenedor.innerHTML="<br><center><img src='images/loading.gif' widht='150' height='150' /></center>";
         }
		if (ajax.readyState==4) {
		   contenedor.innerHTML = ajax.responseText;
		   //alert(ajax.responseText);
		    document.inputForm.submit();
		   window.document.inputForm.Col1.value="";
		   window.document.inputForm.Col2.value="";
		   window.document.inputForm.Email.value="";
		    for (i=0;i<document.inputForm.elements.length;i++){
                   if(document.inputForm.elements[i].type == "checkbox"){
                     document.inputForm.elements[i].checked=false;
				   }
                 }
	}
}	

	ajax.open("POST", "Insertar_Usuario.php",true);
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send("Nombre="+nombre+"&Apellido="+apellido+"&Email="+email+"&Listas="+listas+"&NombreListas="+nombreListas+"&Idioma="+idioma);
 

	
}
//fin de método 

function Regresar(){
	//alert("Entro");
	//document.getElementById('tales').innerHTML="";
	document.getElementById('CajaContenedora').style.display="none";
	document.getElementById('CajaContenedora').innerHTML="";
	document.getElementById('CajaContenedora').style.display="none";
	document.getElementById('CajaContenedora').style.zIndex=-1;



	//alert("hola juacho");
}

//funciones para validar
function chequeatutor(texto){
if(texto =="") return false;
return true;
}
function esEntero(valor){
  var i=0;
  var c=0;
  var nuevo=0;
for(i=0;i<valor.length;i++){
  nuevo=valor.charAt(i);
	if(i==0){
	 if(nuevo=="0"){
	 return false;
	 }
	}
  if((nuevo>="0")&&(nuevo<="9")){
    c++;
   }
  }
  if(c==valor.length) return true;
  return false;
}

function validaFloat(value){	
var Acceso=false;	
var i=0;
var c=0;
var nuevo=0;
regexp = /^[0-9]+(.[0-9]+)?$/;
Acceso=regexp.test(value);
if(Acceso==true){
	
	for(i=0;i<value.length;i++){
	  nuevo=value.charAt(i);
		 if(nuevo==","){
		  c=1;
		}
	}
	if(c==0){	
		return true
	   }
	   else{
		   return false;
	   }
  }

}

function chequeaFormulario(){
var valido = true;
var User = window.document.f.user.value;
var Pass = window.document.f.pass.value;
//var NCajas = window.document.resultado.numeroc.value;


valido = valido && chequeatutor(User);

if(!valido){
alert("Por favor ingrese un usuario");
document.getElementById('user').focus();
return false;
}


valido = valido && chequeatutor(Pass);

if(!valido){
alert("Por favor ingrese su contraseña");
document.getElementById('pass').focus();
return false;
} 

EnviarLogin(User,Pass);
return true;
}

function chequeaFormulario2(form){
   var i=0;
   var valido= true;
   for(i=0; i<document.forms[form].length; i++){
	   if(document.forms[form].elements[i].value!="Enviar"){
	   
	   valido = valido && chequeatutor(document.forms[form].elements[i].value);

		if(!valido){
		alert("Debe llenar todos los espacios");
		return false;
		}//if valido
		
	   }//fin if de boton
    }//fin for
	//EnviarFamiliaAves("Hola","Que","Tal");
	return true;
}//fin metodo chequea


function validarCheck(check,nombre){

	if(check.checked){
	
		document.inputForm.listas.value += check.value + "|";
		document.inputForm.nombresListas.value += nombre + "|";
		
	}else{
		var x = document.inputForm.listas.value.split(check.value + "|");
		document.inputForm.listas.value = x.join("");
		
		var x2 = document.inputForm.nombresListas.value.split(nombre + "|");
		document.inputForm.nombresListas.value = x2.join("");
	} 
	 //alert("Hello");
 //alert(document.inputForm.nombresListas.value);
}


function valida_intro(event){
	if (window.event){
			if (window.event.keyCode==13){
			   chequeaFormulario();
			}
	
		  }else{
		//Firefox y resto de navegadores
		 if (event){
		   if(event.which==13){
			  chequeaFormulario();
	
			}
		}
	
	}

}


 function mostrar_informacion(txt){  
       
     //expresion regular  
         var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
           
         //comentar la siguiente linea si no se desea que aparezca el alert() 
		 if(b.test(txt)){
			//alert("Es valido");	   
		}
		else{
			alert("no es un email valido/ is not a correct email");
			document.formulario1.Email.value="";
		}
         //alert("Email " + (b.test(txt)?"":"no ") + "válido.")  
           
         //devuelve verdadero si validacion OK, y falso en caso contrario  
        return b.test(txt)  
 }  
 
  function mostrar_informacion2(txt){  
       
     //expresion regular  
         var b=/^[^@\s]+@[^@\.\s]+(\.[^@\.\s]+)+$/ 
           
         //comentar la siguiente linea si no se desea que aparezca el alert() 
		 if(b.test(txt)){
			//alert("Es valido");	   
		}
		else{
			alert("no es un email valido/ is not a correct email");
			document.inputForm.Email.value="";
		}
         //alert("Email " + (b.test(txt)?"":"no ") + "válido.")  
           
         //devuelve verdadero si validacion OK, y falso en caso contrario  
        return b.test(txt)  
 } 
 
function chequeaFormulario3(){
var valido = true;
var Email= window.document.inputForm.Email.value;
var Nombre = window.document.inputForm.Col1.value;
//var NCajas = window.document.resultado.numeroc.value;


valido = valido && chequeatutor(Email);

if(!valido){
alert("Por favor ingrese un Email/Please write a Email");
document.getElementById('user').focus();
return false;
}


valido = valido && chequeatutor(Nombre);

if(!valido){
alert("Por favor ingrese su nombre/Please write the Name");
document.getElementById('pass').focus();
return false;
} 

return true;
}

function chequeaFormularioTelefono(){
var valido = true;
var Nombre= window.document.formBajo.nombreFormBajo.value;
var Telefono = window.document.formBajo.telefonoFormBajo.value;
//var NCajas = window.document.resultado.numeroc.value;


valido = valido && chequeatutor(Nombre);

if(!valido){
alert("Por favor ingrese su nombre/Please write a name");
document.getElementById('user').focus();
return false;
}


valido = valido && chequeatutor(Telefono);

if(!valido){
alert("Por favor ingrese su telefono/Please write the Phone Number");
//document.getElementById('').focus();
return false;
} 

valido = valido && esEntero(Telefono);
if(!valido){
alert("Por favor el telefono debe ser un numero/Please the phone number must be a number");
//document.getElementById('pass').focus();
return false;
} 

return true;
}

function AbrirCentrado(Url,NombreVentana,width,height,extras) {
var largo = width;
var altura = height;
var adicionales= extras;
var top = (screen.height-altura)/2;
var izquierda = (screen.width-largo)/2; nuevaVentana=window.open(''+ Url + '',''+ NombreVentana + '','width=' + largo + ',height=' + altura + ',top=' + top + ',left=' + izquierda + ',features=' + adicionales + '');
nuevaVentana.focus();
}


