$(document).ready(function () {	
	$(".lightbox").lightbox();

	$(document).click(function(e) {
        if(e.target.id == 'onlinestore') {
			$.blockUI({ message: '<img style="margin-top: 20px;" src="/_img/busy.gif" /><h1>Daten werden geladen</h1>' });
	        return true;
		}
		
		if(e.target.className == 'button') {
			$.blockUI({ message: '<img style="margin-top: 20px;" src="/_img/busy.gif" /><h1>Produkt wird hinzugefügt</h1>' });
			return true;
		}
	});
});

Util= {
	validateForm: function(id) {
		var result= true;
		$("#"+id + " input, #"+id + " textarea").each(function() {
			if($(this).attr("class") && $(this).attr("class").match("required")) {
				var itemresult= Util.validate($(this).attr("id"));
				result= result && itemresult;
			}
		});
		if(result) {
			$("#form_error").removeClass("error");
		} else {
			$("#form_error").addClass("error");
			$('.required.error').focus(function(e) {
				$(e.target).removeClass("error");
				$(e.target).unbind('focus');
			});	
		}
		return result;
	},
	validate: function(id) {
		var result= true;
		var obj= $("#"+id);
		var commands= $("#"+id).attr("class").split(" ");
		for(var i=0; i<commands.length; i++) {
			var command= commands[i].replace(/[0-9]/g, "");
			switch(command) {
				case("minlength"):
					var length= parseInt(commands[i].replace(/minlength/g, ""));
					result= result && (obj.val().length>=length);
					break;
				case("maxlength"):
					var length= parseInt(commands[i]);
					result= result && (obj.val().length<=length);
					break;
				default:
					result= result && (obj.val().length!=0);
					break;
			}
		}
		if(!result) {
			obj.addClass("error");
		} else {
			obj.removeClass("error");
		}
		return result;
	},
	checkRemove: function(url) {
		var result= confirm('Are you sure?');
		if(result) {
			window.location.href=url;
		}
	}
}