// JavaScript Document
function limpia_input(input){
	input.value = '';
	return true;
}

function ltrim(s) {
	return s.replace(/^\s+/, "");
}

function rtrim(s) {
	return s.replace(/\s+$/, "");
}

function trim(s) {
	return rtrim(ltrim(s)); 
}
function validarEntero(valor){ 
	if (valor == ''){
		valor = true
	}else{
		valor = isNaN(valor)
	}
	return valor;
}
function isEmailAddress(stremail){
	var s = stremail
	var filter=/^[A-Za-z][A-Za-z0-9_.-]*@[A-Za-z0-9_-]+\.[A-Za-z0-9_.]+[A-za-z]$/;
	if (s.length == 0 ) return true;
	if (filter.test(s))
	return true;
	else
	return false;
}
function IsNumber(e) {
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla==8 || tecla==0) return true;
	patron = /\d/; // Solo acepta numeros
	te = String.fromCharCode(tecla);
	return patron.test(te);
}

function IsNombre(e){
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla==8 || tecla==0) return true;
	patron = /[a-zA-ZáéíóúñÁÉÍÓÚÑ\s-]/;
	te = String.fromCharCode(tecla);
	return patron.test(te); 
}

function IsTexto(e){
	tecla = (document.all) ? e.keyCode : e.which;
	if (tecla==8 || tecla==0) return true;
	patron = /[a-zA-Z0-9_.,:;@áéíóúñÁÉÍÓÚÑ\s-]/;
	te = String.fromCharCode(tecla);
	return patron.test(te); 
}


function carga_categorias(){
	jQuery('#contenedor-izq-home-relativo').animate({left:'-720px'},"slow");
			
	jQuery.ajax({
        type: "POST",
        url: "categorias_ajax.php",
        data: "tipo=1",
        success: function(msg){
			jQuery('#contenedor-izq-home').html(msg);
			
			/**** llenado de categorias ********/
			jQuery.ajax({
        		type: "POST",
        		url: "categorias_ajax.php",
        		data: "tipo=2",
        		success: function(msg){
					jQuery('#contenedor-categorias').hide();
					jQuery('#contenedor-categorias').html(msg);
					//jQuery('#contenedor-categorias').fadeTo("slow", 0.5);
					jQuery('#contenedor-categorias').slideDown("slow");
				}
			});			
			/***********************************/			
        }       
    });		
}

function carga_subcategorias(id_cate){
	jQuery('.categorias_despliega').css('color','#FFF');
	jQuery('.categorias_despliega').css('background','');
	jQuery('.subcategorias_despliega').hide();
	jQuery('#categoria_'+id_cate).css('color','#0099FF');
	jQuery('#categoria_'+id_cate).css('background','url(imagenes/franja-categorias.jpg) 5px 2px no-repeat');
	jQuery('.li_categoria').css('height','30px');
	jQuery('#li_categoria_'+id_cate).css('height','100%');
	jQuery('#subcategorias_'+id_cate).css('padding-left','10px');
	jQuery('#subcategorias_'+id_cate).slideDown("slow");	
	jQuery('.subcategorias_despliega').css('width','260px');
}

function carga_productos(id){	
	jQuery('.sub').css('color','#FFF');
	jQuery('#sub_'+id).css('color','#0099FF');
	jQuery.ajax({
        type: "POST",
        url: "carruselProductos.php",
        data: "id_sub="+id,
        success: function(msg){			
            jQuery('#area-carrusel').html(msg);      
        }       
    });	
}

function carga_categoria_directo(id){
	
	jQuery('#contenedor-izq-home-relativo').animate({left:'-720px'},"slow");
			
	jQuery.ajax({
        type: "POST",
        url: "categorias_ajax.php",
        data: "tipo=1",
        success: function(msg){
			jQuery('#contenedor-izq-home').html(msg);
			
			/**** llenado de categorias ********/
			jQuery.ajax({
        		type: "POST",
        		url: "categorias_ajax.php",
        		data: "tipo=2",
        		success: function(msg){
					jQuery('#contenedor-categorias').hide();
					jQuery('#contenedor-categorias').html(msg);
					//jQuery('#contenedor-categorias').fadeTo("slow", 0.5);
					jQuery('#contenedor-categorias').slideDown("slow");
					carga_subcategorias(id);
				}
			});			
			/***********************************/			
        }       
    });
}

function carga_detalle_producto(id_producto,id_subcategoria){
	jQuery('#contenedor-izq-home-relativo').hide();
	jQuery('#banner-pide-loq-quieras').animate({top:'30px'},"normal");
	jQuery('#banner-pide-loq-quieras').animate({left:'20px'},"normal");
	jQuery('#contenedor-categorias-relativo').animate({left:'20px'},"normal");	
	jQuery('#btn-volver').show();
	jQuery.ajax({
        type: "POST",
        url: "carruselProductosDetalle.php",
        data: "id_sub="+id_subcategoria,
        success: function(msg){			
            jQuery('#area-carrusel').html(msg);
			/****** carga del detalle del producto *****************/			
			jQuery.ajax({
				type: "POST",
				url: "detalleProducto.php",
				data: "id_producto="+id_producto,
				success: function(msg){			
					jQuery('#area-detalle-producto').hide();
					jQuery('#area-detalle-producto').html(msg);
					jQuery('#area-detalle-producto').slideDown('slow');
				}       
			});
			/***** fin carga de detalle de producto ***************/
        }       
    });
	
}

function agranda_carrusel(){	
/*
	jQuery('.section').animate({width:'380px'},"normal");	
	jQuery('.section-img').animate({width:'340px'},"normal");
	jQuery('#footer-trasparente').animate({width:'370px'},"normal");
	jQuery('#div_btn_next').animate({left:'300px'},"normal");
	jQuery('#div_btn_prev').animate({left:'330px'},"normal");
	jQuery('.carrusel-home').animate({left:'574px'},"normal");
	jQuery('.carrusel-home').animate({width:'440px'},"normal");
	jQuery('.planes_imge').animate({width:'380px'},"normal");
	jQuery('.img_carrusel').animate({width:'340px'},"normal");
*/


	jQuery('.carrusel-home').css('left','574px');
	jQuery('.carrusel-home').css('width','440px');
	jQuery('.section').css('width','380px');
	jQuery('.section-img').css('width','340px');
	jQuery('#footer-trasparente').css('width','370px');
	jQuery('#div_btn_next').css('left','300px');
	jQuery('#div_btn_prev').css('left','330px');
	jQuery('.planes_imge').css('width','380px');
	jQuery('.img_carrusel').css('width','340px');
	
	
}
function achica_carrusel(){

	jQuery('.section').css('width','180px');
	jQuery('.section-img').css('width','140px');
	jQuery('#footer-trasparente').css('width','180px');
	jQuery('#div_btn_next').css('left','100px');
	jQuery('#div_btn_prev').css('left','130px');	
	jQuery('.carrusel-home').css('width','180px');
	jQuery('.carrusel-home').css('left','774px');
	jQuery('.planes_imge').css('width','180px');
	jQuery('.img_carrusel').css('width','140px');
	
}

function agrega_producto(id){
	jQuery('#cant_productos').css('color','#FFFF00');
	jQuery('#cant_productos').css('font-weight','bold');
	
	jQuery.ajax({
		type: "POST",
		url: "carroDeProductos.php",
		data: "id_producto="+id,
		success: function(msg){			
			if(msg == 'error'){
				alert('El producto seleccionado ya se encuentra en sus preferencias.');	
			}
			else {
				jQuery('#cant_productos').html(msg);      
			}
		}       
	});
}

function quita_producto(id){
	jQuery.ajax({
		type: "POST",
		url: "carroDeProductos.php",
		data: "sacar_producto=1&id_producto="+id,
		success: function(msg){			
			jQuery('#contenido-productos-seleccionados').html(msg);      
		}       
	});
}

function showLightboxFormUA(pag,ancho,alto){
       var texto = pag;	   
       Lightview.show({ href: texto, rel: 'iframe', options: { width: ancho,height: alto, scrolling:'true' }});
}

function enviar_mensaje() {
	var email = jQuery('#txt_email').val();
	var mensaje = jQuery('#txt_mensaje').val();
	if(!isEmailAddress(email) || email == ''){
		jQuery('#mensaje_error').html('El formato del e-mail es incorrecto.');
		return false;
	}
	jQuery.ajax({
		type: "POST",
		url: "carroDeProductos.php",
		data: "enviar=1&email="+email+"&mensaje="+mensaje,
		success: function(msg){			
			location.href='agradecimientos.php?msg=La solicitud ha sido enviada, gracias.';
		}       
	});	
}

function enviar_contacto() {
	var nombre = jQuery('#txt_nombre').val();
	var email = jQuery('#txt_email').val();
	var mensaje = jQuery('#txt_mensaje').val();
	var error = '';
	var foco = '';
	
	if(trim(nombre) == ''){
		error = 'Debe completar el campo nombre';
		foco = 'txt_nombre';
	}
	else if(!isEmailAddress(email) || email == ''){
		error = 'El e-mail ingresado es incorrecto';
		foco = 'txt_email';
	}
	else if(trim(mensaje) == ''){
		error = 'Debe completar el campo mensaje';
		foco = 'txt_mensaje';
	}
	
	if(error==''){
		jQuery.ajax({
			type: "POST",
			url: "contacto.php",
			data: "enviar=1&email="+email+"&mensaje="+mensaje+"&nombre="+nombre,
			success: function(msg){			
				//jQuery('#mensajes').html('El correo fue enviado, pronto nos contactaremos, gracias.');
				location.href='agradecimientos.php?msg=El correo fue recibido, pronto nos contactaremos. Gracias.';
				
			}       
		});
	}
	else{
		jQuery('#mensajes').html(error);
		jQuery('#'+foco).focus();
		return false;
	}	
}

function realiza_busqueda(){
	var valor_buscado = jQuery('#txt_busqueda_header').val();	
	if(trim(valor_buscado) == ''){
		alert('Debe ingresar alg\u00FAn texto para realizar la b\u00FAsqueda');
		return false;
	}
	carga_categorias();	
	jQuery('#contenedor-izq-home-relativo').hide();
	jQuery('#banner-pide-loq-quieras').animate({top:'30px'},"normal");
	jQuery('#banner-pide-loq-quieras').animate({left:'20px'},"normal");
	jQuery('#contenedor-categorias-relativo').animate({left:'20px'},"normal");	

	jQuery.ajax({
        type: "POST",
        url: "carruselProductosDetalle.php",
        data: "id_sub=",
        success: function(msg){			
            jQuery('#area-carrusel').html(msg);
			/****** carga del detalle del producto *****************/			
			jQuery.ajax({
				type: "POST",
				url: "busqueda.php",
				data: "valor_buscado="+valor_buscado,
				success: function(msg){			
					jQuery('#area-detalle-producto').html(msg);
					jQuery('#btn-volver').show();
				}       
			});
			/***** fin carga de detalle de producto ***************/
        }       
    });
}

function enviar_solicitud_especial() {
	
	var nombre = jQuery('#txt_nombre').val();
	var email = jQuery('#txt_email').val();
	var lugar = jQuery('#txt_lugar').val();
	var mensaje = jQuery('#txt_mensaje').val();
	var error = '';
	var foco = '';
	
	if(trim(nombre) == ''){
		error = 'Debe completar el campo nombre';
		foco = 'txt_nombre';
	}
	else if(!isEmailAddress(email) || email == ''){
		error = 'El e-mail ingresado es incorrecto';
		foco = 'txt_email';
	}
	else if(trim(lugar) == ''){
		error = 'Debe completar el campo lugar';
		foco = 'txt_nombre';
	}
	else if(trim(mensaje) == ''){
		error = 'Debe completar el campo mensaje';
		foco = 'txt_mensaje';
	}
	
	if(error==''){
		jQuery.ajax({
			type: "POST",
			url: "pideLoQueQuieras.php",
			data: "enviar=1&email="+email+"&mensaje="+mensaje+"&nombre="+nombre+"&lugar="+lugar,
			success: function(msg){			
				jQuery('#mensajes').html('El correo fue recibido, pronto nos contactaremos. Gracias.');
				jQuery('#btn_enviar').attr('disabled','disabled');
			}       
		});
	}
	else{
		jQuery('#mensajes').html(error);
		jQuery('#'+foco).focus();
		return false;
	}	
}

function enviar_correo_amigo() {
	
	var nombre = jQuery('#txt_nombre').val();
	var email = jQuery('#txt_email').val();
	var mensaje = jQuery('#txt_mensaje').val();
	var id_p = jQuery('#id_p').val();
	var error = '';
	var foco = '';
	
	if(trim(nombre) == ''){
		error = 'Debe completar el campo nombre';
		foco = 'txt_nombre';
	}
	else if(!isEmailAddress(email) || email == ''){
		error = 'El e-mail ingresado es incorrecto';
		foco = 'txt_email';
	}
	else if(trim(mensaje) == ''){
		error = 'Debe completar el campo mensaje';
		foco = 'txt_mensaje';
	}
	
	if(error==''){
		jQuery.ajax({
			type: "POST",
			url: "cuentaleAmigo.php",
			data: "enviar=1&email="+email+"&mensaje="+mensaje+"&nombre="+nombre+"&id_p="+id_p,
			success: function(msg){			
				//jQuery('#interno').html(msg);
				location.href='agradecimientos.php?msg=El correo ha sido enviado satisfactoriamente, gracias.';
			}       
		});
	}
	else{
		jQuery('#mensajes').html(error);
		jQuery('#'+foco).focus();
		return false;
	}		
}

function paginacion(num_pag,total_paginas) {
	
	for(i=1; i <= total_paginas; i++){
		jQuery('.pag_'+i).hide();		
	}
	
	jQuery('.pag_'+num_pag).fadeIn('slow');														  
}

