//INICIO
$(document).ready(function(){
	setInterval(function() {
    jQuery.each(jQuery.browser, function(i) {
    	$('.menu3').css({ opacity: '0' }).stop().animate({ opacity: '1' }, "slow", "swing");
    });
	}, 3000);

});



function loadImage(image){	
		$("#imgen_tienda").css('background-image', 'url("./images/tienda/'+image+'")');
		$("#link_imagen").attr("href",'./images/tiendagrande/'+image);
	}


//POPUPS
function open_popup(url, name, h, w){
	window.open(url, 'Popup','height='+h+',width='+w+',toolbar=no,menubar=no,location=no');
}

function open_popup1(url, name, h, w){
	window.open(url, 'Popup','height='+h+',width='+w+',toolbar=no,menubar=no,location=no,scrollbars=yes');
}
function deleteProduct(p){
	$.post("ajax_delete_product.php",{"identificador":p},function(){
		window.location.href='pedido.php';
	});
}

function validaForm(){
	//Validación de campos vacios
	var errores = $("#errors");
	errores.html("");
	var formok = true;
	
	if(document.getElementById("pedidoVacio").value== 1){
		errores.append("<div>Tiene que seleccionar mínimo un producto para realizar un pedido</div>");
		formok = false;
	}
	if(isVoid("nombre") == true){
		errores.append("<div>Debe especificar su nombre completo</div>");
		formok = false;
	}
	if(isVoid("direccion") == true){
		errores.append("<div>Debe especificar una Dirección de Envío</div>");
		formok = false;
	}
	if(isVoid("telefono") == true){
		errores.append("<div>Debe especificar un número de Teléfono</div>");
		formok = false;
	}
	if(isVoid("email") == true){
		errores.append("<div>Debe especificar una dirección de Email valida</div>");
		formok = false;
	}
	if(isVoid("numero") == true){
		errores.append("<div>Debe especificar el Número de la Dirección</div>");
		formok = false;
	}
	if(isVoid("poblacion") == true){
		errores.append("<div>Debe especificar la Población de envío</div>");
		formok = false;
	}
	if(isVoid("cpostal") == true){
		errores.append("<div>Debe especificar el Codigo Postal de envío</div>");
		formok = false;
	}
	//Validación especifica de campos (Email y Cpostal)
	if(validarMail($("#email").val()) == false){
		errores.append("<div>El formato de la dirección de Email no es válido (cuenta@dominio.ext)</div>");
		formok = false;
	}
	
	return formok;
}

//VALIDADORES
function isVoid(elem){
	var valor = $("#"+elem).val();
	if(valor.length > 0){
		return false;
	}else{
		return true;
	}
}
function validarMail(mail){
	reg = /^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/
	return reg.test(mail);
}

function checkNumber(event){
	if(window.event){
		if((event.keyCode > 47 && event.keyCode < 58)) {
			return true;
		}else{
			return false;
		}
	}else{
		if((event.which > 47 && event.which < 58)) {
			return true;
		}else{
			return false;
		}
	}
}

function validarProducto(){
	var tipo = $("#tipo").val();
	var producto = $("#producto").val();
	var talla = $("#talla").val();
	var color = $("#color").val();
	var cantidad = $("#cantidad").val();

	$.post("ajax_validar_producto.php",{"tipo":tipo, "producto":producto, "talla":talla, "color":color, "cantidad":cantidad},function(data){
		$("#confirmacion").html(data);
		$("#confirmacion").jqmShow();
	});
}

function efectoTexto(intColor){
	
	alert(intVisible);
	if(!intColor)
		intColor=1;
	else
		intColor=0;
		
	if(intColor)
		alert('1');
	else
		alert('0');
		
	
}
