// JavaScript Document
//carga pagina funciones_luxor.php en apartamentos.php
$(document).ready(function() {

	//  para menu apartamentos
	$("ul#sliding-navigation li").click(function(){
		$("ul#sliding-navigation li a").css({ 'color':'#555'});
		$(this).find('a').css({ 'color':'#eee'});
		var active = $(this).find("a").attr("id");
		var pagina= "funciones_luxor.php?accion=a&tipo="+active;
		var destino="hld_1";
		$("#"+destino).load(pagina);
		//cargarContenido(pagina,destino);
		pagina= "funciones_luxor.php?accion=b&tipo="+active;
		destino="ubica";
		$("div#coin-slider").removeAttr("id"); //para liberar el id "coin-slider" y no crear conflictos 
		document.getElementById("ubica").innerHTML="";//borra el contenido del contenedor
		$("#"+destino).load(pagina);//carga pagina en contenedor especifico	
		$("div#cont_caract").css({ 'display':'block'});
	});
	
	$("#btn_reserva").click(function(evento){
      	evento.preventDefault();
			cont='pop';
			ancho=600;
			alto='auto';
			fech1=$("#inn").val();
			fech2=$("#out").val();
			canti1=$("#select option:selected").val();
			
			var divz=window.document.createElement('div');
			divz.setAttribute("id",cont);
			divz.style.display='none';
			var texto= window.document.createTextNode("");
			divz.appendChild(texto);
			window.document.body.appendChild(divz);
			$("#pop").html('<div style="background:#FFF; padding: 40px 0;-moz-border-radius:40px;-webkit-border-radius:40px;"><img src="imagen/cargando_imagen.gif" width="43" height="40"/></div>');
			$("#pop").load("formulario.php",{ 'fe1':fech1, 'fe2':fech2,'cant':canti1});
			
			var fondo=window.document.createElement('div');
			fondo.setAttribute("id","fondo_dom");
			fondo.style.display='none';
			var texto= window.document.createTextNode("");
			fondo.appendChild(texto);
			window.document.body.appendChild(fondo);
			$("#fondo_dom").fadeTo("normal",0.65)
			var ventana=window.document;
			var aux='#'+cont+'';
		   //adecuar tamaño
			if(ancho=='auto')
				var img_w='auto';
			else{
				var img_w = ancho+'px'}
			//alert(img_w);	
			if(alto=='auto')
				var img_h='auto';
			else{
				var img_h = alto+'px'}
			//alert(img_h);
			//Darle el alto y ancho 
		   $(aux).css('width', img_w); 
		   $(aux).css('height', img_h); 
			  //Consigue valores de la ventana del navegador 
			var w = $(ventana).width(); 
			var h = $(ventana).height()+16;
			//para el fondo
		   $("#fondo_dom").css('width', w+'px'); 
		   $("#fondo_dom").css('height', h+'px');
			//Centra el popup    
			contenedor_w=$("#"+cont).width();
			contenedor_h=$("#"+cont).height();
			//alert(contenedor_h);
		   w = (w/2) - (contenedor_w/2); 
		   h = 120;
		   $(aux).css("left",w + "px"); 
		   $(aux).css("top",h + "px");
		   
		   //temporizador, para que no aparezca de golpe
			setTimeout("mostrar('"+cont+"')",200);
			setTimeout("mostrar('fondo_dom')",180);
  	});
	
// para sugerencias

	var suge = $('#sugeren').height();
	var suge_1 = $('#sugeren_1').height();
	dife=suge-suge_1;
	if(suge<suge_1){
		$('div#sugeren').css('height', suge_1);}
	else{
		a=dife%2;
		tope=dife/2;
		bote=(dife-a)/2+a;
		$('div#sugeren_1').css('padding-top', tope+10);
		$('div#sugeren_1').css('padding-bottom', bote+5);
		//$('div#sugeren_1').css('height', suge);
	}
	// evento enviar sugerencia
	$("#btn_contacto").click(function(evento){
		if(revisa_form())
		{
			$.post('enviar_contacto.php', { 			
					nombre_s: $('#nombre_s').val(),
					ciudad_s: $('#ciudad_s').val(),
					telefono_s: $('#telefono_s').val(),
					email_s: $('#email_s').val(),
					asunto_s: $('#asunto_s option:selected').text(),
					mensaje_s: $('#mensaje_s').val()},
					function(data) {
						if(data==1) {
							alert('Mensaje Enviado.')
							$('#contacto input[type="text"],#contacto textarea').val("");
						}
						else alert('Lo sentimos presione F5 e intente nuevamente.')					
			});
		}
	});
	
	$("div#logo").click(function(){
		window.document.location.href ='index.php';
	});	
});

//revisar formulario
function revisa_form(){
$('#contacto #tab input , #contacto #tab textarea' ).removeClass('error').removeClass('valid');
        //ckeck if inputs aren't empty
        var fields = $('#contacto #tab table input[type=text],#contacto #tab table textarea');
        var error = 0;
		fields.each(function(){
            var value = $(this).val();
            if( value.length<3 ) {
                $(this).addClass('error');
                error++;
            } else {
                $(this).addClass('valid');
            }
        }); 
		cen=1;// email correcto
		aux = $("#email_s").val();
		
		if(!(/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(aux)))
			cen=0;
		aux2 = $("#email_s").val().length;
		if(cen==0 && aux2>2)
		{
			$('#email_s').removeClass('valid').addClass('error');
			error++;
		}
		
		if(!error) return true;
		else return false;
}

//inicializar ayax
function nuevoAjax_x(xmlhttp){
   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
}
//para cargar una pagina en un contenedor
function cargarContenido(pagina,destino){
   var contenedor;
   var ajax;
   contenedor = window.document.getElementById(destino);
   ajax = nuevoAjax_x(ajax);
   ajax.open("GET", pagina, true);
   ajax.onreadystatechange=function() {
      if (ajax.readyState==4) {
         contenedor.innerHTML = ajax.responseText;
      }
   }
   ajax.send(null);
}
//********************************************
/*   mostrar  */
function mostrar(cont) { 
	var aux='#'+cont+'';
	$(aux).fadeIn('slow'); 
} //checkHover
//Función para cerrar el popup

function cerrar(nodo){
	var aux='#'+nodo+'';
	$(aux).fadeOut('slow');
	$("#fondo_dom").fadeOut('slow');
	setTimeout("ayuda('fondo_dom')",500);
	setTimeout("ayuda('"+nodo+"')",500);
	}

function ayuda(nodo){
	var del=window.document.getElementById(nodo);
	del.parentNode.removeChild(del);
	}




