// JavaScript Document
function change_map(nom_sucursal){
		
		var latitud=0;
		var longitud=0;
		var direccion="";
		var titulo=""
		
		if(nom_sucursal=="Perinorte"){//19.603150,-99.190350
			latitud=19.603150;
			longitud=-99.190350;
			direccion="Centro Comercial Perinorte<br/>Autopista México - Querétaro Km 30.5<br/>Cuautitlán Izcalli, Edo. de Méx.<br/>Tels: 58939677 y 58939477";
			titulo="El Tinacal Perinorte"
		}else if(nom_sucursal=="Satélite"){//19.512974,-99.233562
			latitud=19.512974;
			longitud=-99.233562;
			direccion="Pafnuncio Padilla No. 17<br/>Cd. Satélite, Naucalpan<br/>Edo. de México<br/>Tels. 55722597 y 55725506";
			titulo="El Tinacal Satélite"
		}else if(nom_sucursal=="Tlalnepantla"){//19.527533,-99.208302
			latitud=19.527533;
			longitud=-99.208302;
			direccion="Aculco No. 7 esquina Gustavo Baz<br/>No. 222 Col. La Loma, Tlanepantla<br/>Edo. de México<br/>Tel. 53977475";
			titulo="El Tinacal Tlalnepantla"
		}else if(nom_sucursal=="Tepotzotlán"){//19.705223,-99.205599
			latitud=19.705223;
			longitud=-99.205599;
			direccion="Autopista Mexico-Queretaro km 42.5.<br/>(Junto a la Terminal de Autobuses<br/>de Tepotzotlan)<br/>Tel. 58762177";
			titulo="El Tinacal Tepotzotlán"
		}else if(nom_sucursal=="Izcalli Tradicional"){//19.660148,-99.208659
			latitud=19.660148;
			longitud=-99.208659;
			direccion="Andador Islandia No.29<br/>Col. Centro Urbano, Cuautitlan Izcalli.<br/>(Entre Operagua y Waldo's)<br/>Tel. 58735402";
			titulo="El Tinacal Izcalli Tradicional"
		}
		
		$('#titulo_sucursal').fadeOut(500,function(){
				$('#titulo_sucursal').html(nom_sucursal);
            	$('#titulo_sucursal').fadeIn(500);	
        });
		
		$('#dir_sucursal').fadeOut(500,function(){
				$('#dir_sucursal').html(direccion);
            	$('#dir_sucursal').fadeIn(500);	
        });
		
		var latlng = new google.maps.LatLng(latitud, longitud);
        var settings = {
            zoom: 15,
            center: latlng,
            mapTypeControl: false,
            mapTypeControlOptions: {style: google.maps.MapTypeControlStyle.DROPDOWN_MENU},
            navigationControl: false,
            navigationControlOptions: {style: google.maps.NavigationControlStyle.SMALL},
            mapTypeId: google.maps.MapTypeId.ROADMAP
    	};
				var map = new google.maps.Map(document.getElementById("map_canvas"), settings);
				
				var companyImage = new google.maps.MarkerImage('imgs/maps/logo.png',
					new google.maps.Size(50,50),
					new google.maps.Point(0,0),
					new google.maps.Point(25,50)
				);

				var companyShadow = new google.maps.MarkerImage('imgs/maps/logo_shadow.png',
					new google.maps.Size(70,50),
					new google.maps.Point(0,0),
					new google.maps.Point(35, 50));

				var companyPos = new google.maps.LatLng(latitud, longitud);
				var companyMarker = new google.maps.Marker({
					position: companyPos,
					map: map,
					icon: companyImage,
					shadow: companyShadow,
					title:titulo,
					zIndex: 1
					});
				
				google.maps.event.addListener(companyMarker, 'click', function() {
					infowindow.open(map,companyMarker);
				});	
	}
	
	
	function send_step(){
        var nombre_resv = true;
        var email_resv = true;
        var telefono_resv = true;
        var lugares_resv = true;
	
        var elemento_nombre = document.getElementById("nombre").value;
        var elemento_email = document.getElementById("email").value;
        var elemento_telefono = document.getElementById("telefono").value;
        var elemento_lugares = document.getElementById("lugares").value;
        
        if(elemento_nombre == "Nombre" || elemento_nombre == ""){
             nombre_resv =  false;
        }
        if(elemento_email == "Email" || elemento_email == ""){
             email_resv =  false;
        }else{
            var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;	
            if (!filter.test(elemento_email)){
                 email_resv = false;
            }
        }
        
        if(elemento_telefono == "Teléfono" || elemento_telefono == ""){
             telefono_resv =  false;
        }
        if(elemento_lugares == "Acompañantes" || elemento_lugares == ""){
             lugares_resv =  false;
        }
        
        if (nombre_resv && email_resv && telefono_resv && lugares_resv){
            $.post(
                "scripts/funciones.php",
                {
                    action:'reservacion',
                    nombre_resv: $("#nombre").val(),
                    email_resv: $("#email").val(),
                    telefono_resv: $("#telefono").val(),
                    sucursal_resv: $("#sucursal").val(),
                    lugares_resv: $("#lugares").val(),
					dia_resv: $("#dia").val(),
					mes_resv: $("#mes").val(),
					anio_resv: $("#anio").val(),
					hora_resv: $("#hora").val()
                },
                function(data){
                    if (data){
                        $('#formulario_reservacion').fadeOut(500,function(){
                                $('#exito_reservacion').fadeIn(500);	
                        });
                    }else{
                        $('#formulario_reservacion').fadeOut(500,function(){
                                $('#error_reservacion').fadeIn(500);	
                        });
                    };
            });
        }else{
            $('#msg_error').fadeIn(200);
            var t=setTimeout("restore_error()",2000);
        }
    }
    
    
    function restore_error(){
        $('#msg_error').fadeOut(200);
    }
    
    function restore_form(status){
        if(status=='success'){
            $('#exito_reservacion').fadeOut(500,function(){
            $('#formulario_reservacion').fadeIn(500);	
        });
        }else{
            $('#error_reservacion').fadeOut(500,function(){
            $('#formulario_reservacion').fadeIn(500);	
            });
        }
    }
    
    
    function clean_nombre(){
        var elemento = document.getElementById("nombre");
         if(elemento.value == "Nombre"){
             elemento.value = ""; 
         }
    }
    
    function clean_email(){
        var elemento = document.getElementById("email");
         if(elemento.value == "Email"){
             elemento.value = ""; 
         }
    }
    
    function clean_telefono(){
        var elemento = document.getElementById("telefono");
         if(elemento.value == "Teléfono"){
             elemento.value = ""; 
         }
    }
    
    function clean_lugares(){
        var elemento = document.getElementById("lugares");
         if(elemento.value == "Acompañantes"){
             elemento.value = ""; 
         }
    }
    
    function send_news(){
        var nombre_news = true;
        var email_news = true;
        
        var elemento_nombre = document.getElementById("nombreBoletin").value;
        var elemento_email = document.getElementById("emailBoletin").value;
    
        
        if(elemento_nombre == "Nombre" || elemento_nombre == ""){
             nombre_news =  false;
        }
        if(elemento_email == "Email" || elemento_email == ""){
             email_news =  false;
        }else{
            var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;	
            if (!filter.test(elemento_email)){
                 email_news = false;
            }
        }
        
    
        
        if (nombre_news && email_news){
            $.post(
                "scripts/funciones.php",
                {
                    action:'newsletter',
                    nombre_news: $("#nombreBoletin").val(),
                    email_news: $("#emailBoletin").val(),
    
                },
                function(data){
                    if (data){
                        $('#newsletter_form').fadeOut(500,function(){
                                $('#newsletter_exito').fadeIn(500);	
                        });
                    }else{
                        $('#newsletter_form').fadeOut(500,function(){
                                $('#newsletter_error').fadeIn(500);	
                        });
                    };
            });
        }else{
            $('#newsletter_datos').fadeIn(200);
            var t=setTimeout("restore_error_news()",2000);
        }
    }
    function restore_error_news(){
        $('#newsletter_datos').fadeOut(200);
    }
    function clean_nombre_news(){
        var elemento = document.getElementById("nombreBoletin");
         if(elemento.value == "Nombre"){
             elemento.value = ""; 
         }
    }
    
    function clean_email_news(){
        var elemento = document.getElementById("emailBoletin");
         if(elemento.value == "Email"){
             elemento.value = ""; 
         }
    }
    
    function restore_news(status){
        if(status=='success'){
            $('#newsletter_exito').fadeOut(500,function(){
            $('#newsletter_form').fadeIn(500);	
        });
        }else{
            $('#newsletter_error').fadeOut(500,function(){
            $('#newsletter_form').fadeIn(500);	
            });
        }
    }
	
	function submit_reservacion(codigo_tecla){
		if(codigo_tecla==13){
			send_step();
		}
	}
	function submit_newsletter(codigo_tecla){
		if(codigo_tecla==13){
			send_news();
		}
	}
