
/*  FUNCIONES AL CARGAR LA WEB */
function encaja_contenedor(){
	$('#caja_contenido').css({minHeight:$(window).height() - 230});

}

window.onresize = function(){
	encaja_contenedor();
}

window.onload= function(){
	encaja_contenedor();
}



/*  FUNCIONES HOME DESTACADOS */

function desaparece_destacados(){
	a = document.getElementsByTagName("div");

	for(i=0; i<a.length; i++)
	{
		if(a[i].getAttribute("class") && a[i].getAttribute("class") == "home_destacados_principal_caja")
		{
			id_borrar=a[i].getAttribute("id");
			$('#'+id_borrar).fadeOut(1000);
			$('#boton_'+id_borrar).css({'color':'white'});			
		}
	}
	
	a = document.getElementsByTagName("iframe");

	for(i=0; i<a.length; i++)
	{
		if(a[i].getAttribute("class") && a[i].getAttribute("class") == "videoyoutube")
		{
			id_borrar=a[i].getAttribute("id");
						
			document.getElementById(id_borrar).src="";	
	
		}
	}
}

function aparece_destacado(destacado){
	$('#destacado_principal' + destacado).fadeIn(1000);
	$('#boton_destacado_principal'+destacado).css({'color':'red'});
}

function aparece_destacado_secunfuera(destacado){
	$('#secun_cajafuera' + destacado).clearQueue();
	$('#secun_cajafuera'+destacado).css({'display':'block'});
	$('#secun_cajafuera'+destacado).animate({"width": "200px"});
}

function desaparece_destacado_secunfuera(destacado){
	$('#secun_cajafuera' + destacado).clearQueue();
	$('#secun_cajafuera'+destacado).animate({"width": "0px"});
	
}

function ponlink_youtube(ruta, id){
	document.getElementById(id).src=ruta;	
}

/* FUNCIONES LOGIN */



function comprueba_datos_login(){
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  var xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
  var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
  {
  if(xmlhttp.readyState==1){
	  document.getElementById('caja_login_loader').style.display='block';
  }
  else if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	 var aux= xmlhttp.responseText;
	 
	 document.getElementById('caja_login_loader').style.display='none';
	 if(aux == "fail") { alert('nombre de usuario o contraseña incorrectos');}
	 	else { window.location='personal.php';}
	 	
    }
  }
xmlhttp.open("POST","ajax/comprueba_login.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

var user=document.getElementById('text_usuario').value;
var pass=document.getElementById('text_pass').value;

xmlhttp.send("user=" + user + '&pass=' + pass);	
}

function login(){
	var user=document.getElementById('text_usuario').value;
	var pass=document.getElementById('text_pass').value;
	
	var fails="";
	if (user=="") fails="*nombre de usuario no válido \n";
	if (pass=="") fails= fails + "*contraseña no válida";
	
	if(fails == "") comprueba_datos_login(); else alert(fails);
		
}


/*REGISTRO*/

function continua_registro(){
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  var xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
  var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
  {
  if(xmlhttp.readyState==1){
	  document.getElementById('caja_registrarme_loader').style.display='block';
  }
  else if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	 var aux= xmlhttp.responseText;
	 
	 document.getElementById('caja_registrarme_loader').style.display='none';
	 if(aux == "fail") { alert('El email introducido ya se encuentra en nuestra base de datos');}
	 	else {
			if(aux==1){
				alert('datos recibidos correctamente, para completar tu registro deberás confirmar el email que acabamos de enviarte'); 
				
				window.location='index.php';
			}
			if(aux==2){
				alert('No se han podido guardar tus datos, por favor prueba de nuevo');
			}
			if(aux == "fail2"){alert('El email introducido ya se encuentra en nuestra base de datos. Te hemos vuelto a enviar un email de confirmación. Si no lo recibes asegúrate de mirar en tu carpeta de SPAM o CORREO NO DESEADO. Si sigues teniendo problemas para registrarte por favor ponte en contacto con nosotros a través de rexona_soporte@gestazion.com');}
			
		}	
    }
  }
xmlhttp.open("POST","ajax/registrar.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

	var nombre=document.getElementById('text_nombre').value;
	var apellidos=document.getElementById('text_apellidos').value;	
	var email=document.getElementById('text_email').value;
	var pass1=document.getElementById('text_pass1').value;
	var pass2=document.getElementById('text_pass2').value;
	var telefono=document.getElementById('text_telefono').value;
	var fecha=document.getElementById('ano').value + '-' + document.getElementById('mes').value + '-' + document.getElementById('dia').value;
	var provincia=document.getElementById('provincia').value;
	var sexo=document.getElementById('sexo').value;
	var check_comunicaciones=document.getElementById('check_comunicaciones').checked;
	var check_bases=document.getElementById('check_bases').checked;


xmlhttp.send("nombre=" + nombre + '&apellidos=' + apellidos + '&email=' + email + '&pass=' + pass1 + '&telefono=' + telefono + '&fecha=' + fecha + '&provincia=' + provincia + '&sexo=' + sexo + '&check_comunicaciones=' + check_comunicaciones + '&check_bases=' + check_bases);	
}


/*LOGIN*/

function comprueba_datos_login(){
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  var xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
  var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
  {
  if(xmlhttp.readyState==1){
	  document.getElementById('caja_login_loader').style.display='block';
  }
  else if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	 var aux= xmlhttp.responseText;
	 
	 document.getElementById('caja_login_loader').style.display='none';
	 if(aux == "fail") { alert('nombre de usuario o contraseña incorrectos');}
	 	else { window.location='?sec=personal';}
	 	
    }
  }
xmlhttp.open("POST","ajax/comprueba_login.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

var user=document.getElementById('text_usuario').value;
var pass=document.getElementById('text_pass').value;

xmlhttp.send("user=" + user + '&pass=' + pass);	
}

function login(){
	var user=document.getElementById('text_usuario').value;
	var pass=document.getElementById('text_pass').value;
	
	var fails="";
	if (user=="") fails="*nombre de usuario no válido \n";
	if (pass=="") fails= fails + "*contraseña no válida";
	
	if(fails == "") comprueba_datos_login(); else alert(fails);
		
}


/* LIMPIA CUADROS DE TEXTO */

function limpia_Cuadro(id, texto){
	
	if(document.getElementById(id).value == texto){
		
		if(id == "text_pass"){
			document.getElementById(id).type="password";
		}
		
		document.getElementById(id).value = "";
	}
}

function escribe_Otravez(id, texto){
	if(document.getElementById(id).value == ""){
		if(id == "text_pass"){
			document.getElementById(id).type="text";
		}		
		document.getElementById(id).value = texto;
	}
}


/* RECUERDA PASS */

function enviar_pass(){
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
  var xmlhttp=new XMLHttpRequest();
}else{// code for IE6, IE5
  var xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
  {
  if(xmlhttp.readyState==1){
	  document.getElementById('caja_recuerda_loader').style.display='block';
  }
  else if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
	 var aux= xmlhttp.responseText;
	 
	 document.getElementById('caja_recuerda_loader').style.display='none';
	 if(aux == "fail") { alert('no hay ningún usuario con ese email');}
	 	else {
			if(aux=="1"){
				alert('Te hemos enviado tu contraseña a tu dirección de email');
				window.location='index.php';
			}
			if(aux=="0"){
				alert('No hemos podido enviarte tu contraseña, por favor, inténtalo más tarde');
			}
			
		}
	 	
    }
  }
xmlhttp.open("POST","ajax/envia_pass.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");

var user=document.getElementById('text_recuerda_usuario').value;

xmlhttp.send("user=" + user);	
}

function recuerdame(){
	var user=document.getElementById('text_recuerda_usuario').value;
	
	
	var fails="";
	if (user=="") fails="*nombre de usuario no válido \n";
	
	if(fails == "") enviar_pass(); else alert(fails);
		
}

