ecorganic = {}

ecorganic.pedidos = {
	// VARIABLES CONFIGURACION
	url_formulario 			: '/exec/ajax/pedidos.php',
	id_pedidos_formulario	: 'form_pedidos',
	id_pedidos_boton		: 'pedido_boton_formulario',
	id_pedidos_img			: 'pedido_imagen_ok',
	id_error				: 'error_pedidos_',

	// VARIABLES INTERNAS
	pedidos_enviado			: false,

	// FUNCIONES
	formularioProcesar : function () {
		if (this.pedidos_enviado) return;

		// CONSULTA AJAX
		$.ajax({
			type 	: 'POST',
			url 	: this.url_formulario,
			data 	: $('#' + this.id_pedidos_formulario).serialize(),
			context : this,
			success : function(respuesta){
				$('.error').hide();

				if (respuesta != 'ok') {
					if (respuesta.substring(0, 8) == 'errores-')
						$.each(respuesta.split('-'), function(posicion, nombre) {
							if ($('#' + this.id_error + nombre)) $('#' + this.id_error + nombre).show();
						}.bind(this));
				} else {
					this.pedidos_enviado = true;
					$('#' + this.id_pedidos_boton).html('ENVIADO');
					$('#' + this.id_pedidos_img).show();
				}
			}
		});
	}
}

ecorganic.tienda = {
	// VARIABLES CONFIGURACION
	url_formulario 			: '/exec/ajax/tienda.php',
	id_pedidos_formulario	: 'form_tienda',
	id_pedidos_boton		: 'tienda_boton_formulario',
	id_error				: 'error_tienda_',

	// VARIABLES INTERNAS
	formulario_enviado		: false,

	// FUNCIONES
	formularioProcesar : function () {
		if (this.formulario_enviado) return;

		// CONSULTA AJAX
		$.ajax({
			type 	: 'POST',
			url 	: this.url_formulario,
			data 	: $('#' + this.id_pedidos_formulario).serialize(),
			context : this,
			success : function(respuesta){
				$('.error').hide();

				if (respuesta != 'ok') {
					if (respuesta.substring(0, 8) == 'errores-')
						$.each(respuesta.split('-'), function(posicion, nombre) {
							if ($('#' + this.id_error + nombre)) $('#' + this.id_error + nombre).show();
						}.bind(this));
				} else {
					this.formulario_enviado = true;
					$('#' + this.id_pedidos_boton).html('ENVIADO');
				}
			}
		});
	}
}
