//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>You must select at least one product to checkout.</div>");
		formok = false;
	}
	if(isVoid("nombre") == true){
		errores.append("<div>You must specify your name.</div>");
		formok = false;
	}
	if(isVoid("direccion") == true){
		errores.append("<div>You must specify a shipping address.</div>");
		formok = false;
	}
	if(isVoid("telefono") == true){
		errores.append("<div>You must specify a phone number.</div>");
		formok = false;
	}
	if(isVoid("email") == true){
		errores.append("<div>You must specify a valid email address.</div>");
		formok = false;
	}
	if(isVoid("numero") == true){
		errores.append("<div>You must specify a address number.</div>");
		formok = false;
	}
	if(isVoid("poblacion") == true){
		errores.append("<div>You must specify a shipping city.</div>");
		formok = false;
	}
	if(isVoid("cpostal") == true){
		errores.append("<div>You must specify a shipping postal code.</div>");
		formok = false;
	}
	//Validación especifica de campos (Email y Cpostal)
	if(validarMail($("#email").val()) == false){
		errores.append("<div>The email address is not valid.</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();
	});
}
