$(document).ready(function(){
	$(function(){

    $('a[href*=#]').click(function() {
    
    if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') 
        && location.hostname == this.hostname) {
        
            var $target = $(this.hash);
            
            $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
            
            if ($target.length) {
            
                var targetOffset = $target.offset().top;
                
            

				$('html,body').animate({scrollTop: targetOffset}, 1000, 'easeOutCubic');
				//$('html,body').animate({scrollTop: targetOffset}, 2000, 'easeOutBack');

                    
                return false;
                
            }
            
        }
        
    });
    
	});
	
	
	$('.lnk_servicios').click(function () {
					var imgServ = $(this).attr('id');
					$('#servicios_img').animate( { opacity: 0 }, 'slow', 'swing',  function() { 
					 	$('#servicios_img').html('<img src="qoolcms/sitio/archivos/galeria/'+imgServ+'" alt="'+imgServ+'">');
						$('#servicios_img').animate( { opacity: 1 }, 'slow', 'swing' );
					 });
				});
				
				$('.lnk_obras').click(function () {
					var IdImagen = $(this).attr('id');
					$.ajax({
						type						: 	'POST',
						url							: 	'qoolcms/sitio/plantillas/defecto/includes/obras.php',
						data						: 	'IdImagen=' + IdImagen,
						dataType					: 	'html',
						beforeSend					: 	function() { $('#obras_img').html('Cargando...'); },
						success						: 	function(response) { 
															$('#obras_img').html(response);
														}
					});	
				});
				$('.lnk_productos').click(function () {
					var IdImagen = $(this).attr('id');
					$.ajax({
						type						: 	'POST',
						url							: 	'qoolcms/sitio/plantillas/defecto/includes/productos.php',
						data						: 	'IdImagen=' + IdImagen,
						dataType					: 	'html',
						beforeSend					: 	function() { $('#productos_img').html('Cargando...'); },
						success						: 	function(response) { 
															$('#productos_img').html(response);
														}
					});	
				});				
				//Suscripciones
				$('#enviar').click(function () {
					var nombre = $('#nombre').val();
					nombre = nombre.replace(/(^\s*)|(\s*$)/g,"");
					var telefono = $('#telefono').val();
					telefono = telefono.replace(/(^\s*)|(\s*$)/g,"");
					var email = $('#email').val();
					email = email.replace(/(^\s*)|(\s*$)/g,"");
					if(nombre == ""){
			    		alert('Por favor digita tu nombre completo para poder suscribirte');
						return;
					}
					if(email == ""){
			    		alert('Por favor digita tu correo electrónico para completar tu suscripción');
						return;
					}else{
						var filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
						if (!filtro.test($('#email').val())){
							alert('Por favor rectifica tu correo electrónico');
							return;
						}
					}
					if(telefono == ""){
			    		alert('Por favor digita tu número telefónico para poder suscribirte');
						return;
					}
					
					$.ajax({
						type						: 	'POST',
						url							: 	'qoolcms/sitio/plantillas/defecto/includes/suscripcion.php',
						data						: 	"nombre="+nombre+"&email="+email+"&telefono="+telefono,
						success						: 	function(response) { 
															alert('Gracias por suscribirte a nuestro sitio web.');
															 	$('#nombre').val('');
																$('#telefono').val('');
																$('#email').val('');
														}
					});
					
					
					
					
				});
				
				
				
				//Contacto
				$('#con_enviar').click(function () {
					var con_nombre = $('#con_nombre').val();
					con_nombre = con_nombre.replace(/(^\s*)|(\s*$)/g,"");
					var con_telefono = $('#con_telefono').val();
					con_telefono = con_telefono.replace(/(^\s*)|(\s*$)/g,"");
					var con_email = $('#con_email').val();
					con_email = con_email.replace(/(^\s*)|(\s*$)/g,"");
					var con_comentario = $('#con_comentario').val();
					con_comentario = con_comentario.replace(/(^\s*)|(\s*$)/g,"");
					var con_empresa = $('#con_empresa').val();
					var con_ciudad = $('#con_ciudad').val();
					var con_pais = $('#con_pais').val();
					con_empresa = con_empresa.replace(/(^\s*)|(\s*$)/g,"");
					if(con_nombre == ""){
			    		alert('Por favor digita tu nombre completo.');
						return;
					}
					if(con_telefono == ""){
			    		alert('Por favor digita tu número telefónico.');
						return;
					}
					if(con_email == ""){
			    		alert('Por favor digita tu correo electrónico.');
						return;
					}else{
						var filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
						if (!filtro.test($('#con_email').val())){
							alert('Por favor rectifica tu correo electrónico');
							return;
						}
					}
					if(con_empresa == ""){
			    		alert('Por favor digita tu empresa.');
						return;
					}
					if(con_comentario == ""){
			    		alert('Por favor déjanos tu comentario.');
						return;
					}

					$.ajax({
						type						: 	'POST',
						url							: 	'qoolcms/sitio/plantillas/defecto/includes/contacto.php',
						data						: 	"nombre="+con_nombre+"&empresa="+con_empresa+"&email="+con_email+"&telefono="+con_telefono+"&ciudad="+con_ciudad+"&pais="+con_pais+"&comentario="+con_comentario,
						success						: 	function(response) { 
															alert('Gracias por ponerte en contacto con nosotros.');
														}
					});

					
				});
				
	
			$('#ref_enviar').click(function () {
					var ref_obra = $('#ref_obra').val();
					ref_obra = ref_obra.replace(/(^\s*)|(\s*$)/g,"");
					var ref_telefono = $('#ref_telefono').val();
					ref_telefono = ref_telefono.replace(/(^\s*)|(\s*$)/g,"");				
					var ref_direccion = $('#ref_direccion').val();
					ref_direccion = ref_direccion.replace(/(^\s*)|(\s*$)/g,"");
					var ref_email = $('#ref_email').val();
					ref_email = ref_email.replace(/(^\s*)|(\s*$)/g,"");
					var ref_comentario = $('#ref_comentario').val();
					ref_comentario = ref_comentario.replace(/(^\s*)|(\s*$)/g,"");
					if(ref_obra == ""){
			    		alert('Por favor digita la obra a cotizar.');
						return;
					}
					if(ref_telefono == ""){
			    		alert('Por favor digita tu número telefónico.');
						return;
					}
					if(ref_direccion == ""){
			    		alert('Por favor digita tu dirección.');
						return;
					}
					if(ref_email == ""){
			    		alert('Por favor digita tu correo electrónico.');
						return;
					}else{
						var filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
						if (!filtro.test($('#ref_email').val())){
							alert('Por favor rectifica tu correo electrónico');
							return;
						}
					}
					if(ref_comentario == ""){
			    		alert('Por favor déjanos tu comentario.');
						return;
					}
					$.ajax({
						type						: 	'POST',
						url							: 	'qoolcms/sitio/plantillas/defecto/includes/reformas.php',
						data						: 	"ref_obra="+ref_obra+"&ref_telefono="+ref_telefono+"&ref_direccion="+ref_direccion+"&ref_email="+ref_email+"&ref_comentario="+ref_comentario,
						success						: 	function(response) { 
															alert('Gracias por ponerte en contacto con nosotros.');
														}
					});

					
				});
	
});
