// ACCESO LOGIN
$(document).ready(function(){
	$("#form_login").submit(function() {
			$.ajax({
			   type: "POST",
			   url: "/includes/system/login/comprueba.php",
			   data: $("#form_login").serialize(),
			   success: function(contenido){
					 var resp=contenido.split("_");

					 if (resp[0] == 'OK'){
					 	$("#div_error").html('');
					 	$("#div_ok").html('<img src="/includes/images/ok.png" /> Bienvenido '+resp[1]);
					 	$("#div_ok").show('slow');
					 	setTimeout('location.href="/"',1500);
						}
					else{
					$("#div_error").html('');
					$("#div_error").html('<img src="/includes/images/error.png" />'+resp[1]);
					$("#div_error").show('slow');

					setTimeout('$("#div_error").hide("slow")',2900);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					jAlert('No se ha podido conectar con el servidor');
				}
			});
		return false
	});



// FORMULARIO CONTACTANOS

	$("#form_contactanos").submit(function() {
			$.ajax({
			   type: "POST",
			   url: "/includes/system/formu/contactanos_data.php",
			   data: $("#form_contactanos").serialize(),
			   success: function(contenido){
					 var resp=contenido.split("_");

					 if (resp[0] == 'OK'){
					 	$("#div_envio_correcto1").html('');
					 	$("#form_contactanos").html('');
						$("#div_envio_correcto1").html('<img src="/includes/images/ok.png" />   '+resp[1]);
						$("#div_envio_correcto1").show('slow');
					 	}
					else{
					$("#div_error1").html('');
					$("#div_error1").html('<img src="/includes/images/error.png" />   '+resp[1]);
					$("#div_error1").show('slow');

					setTimeout('$("#div_error1").hide("slow")',2900);
					}
				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					jAlert('No se ha podido conectar con el servidor');
				}
			});
		return false
	});


// PEDIDO - ZONA CARRITO

    	$("#seleccion_final > li > a").click(function () {
		var id_producto = $(this).attr('id');
		var cantidad = $("#cantidad_"+id_producto).val();
		$.ajax({
			   type: "POST",
			   url: "/includes/system/actualiza_pedido.php",
			   data: 'id_producto='+id_producto+'&cantidad='+cantidad+'&apartado=pedido',
			   success: function(contenido){
			   	var resp=contenido.split("_");
				if (resp[0] == 'OK')
					{
						if (resp[1] == 'borrado')
						{
							$("#div_prod_"+id_producto).html('');
							$(".subtotal").html('<p>Sub-Total:'+resp[2]+' &euro;</p>');
						}
						else
						{
							$("#total_"+id_producto).html(resp[1]+' &euro;');
							$(".subtotal").html('<p>Sub-Total:'+resp[2]+' &euro;</p>');
						}
					}
					else
						jAlert(contenido);

				},
				error: function (XMLHttpRequest, textStatus, errorThrown) {
					jAlert('No se ha podido conectar con el servidor');
				}
			});
			return false;
    });



// CONFIRMACION DE PEDIDO- ENVIO MAIL Y GUARDADO DATOS

	$("#confirmar_compra").click(function() {

		jConfirm('Desea proceder con el pedido?', 'Confirmation', function(r) {
		    if(r)
		    {

				$.ajax({
				   type: "POST",
				   url: "/includes/system/confirm_pedido/confirmacion_pedido_data.php",
				   success: function(contenido){
						 var resp=contenido.split("_");

						 if (resp[0] == 'OK')
						 {
						 	$("#div_confirm_compra").html('');
						 	$("#div_envio_correcto1").html('');
						 	$("#div_envio_correcto1").html('<img src="/includes/images/ok.png" />   '+resp[1]);
							$("#div_envio_correcto1").show('slow');
						 }
						 else
						 {
							$("#div_error1").html('');
							$("#div_error1").html('<img src="/includes/images/error.png" />   '+resp[1]);
							$("#div_error1").show('slow');
							setTimeout('$("#div_error1").hide("slow")',2900);
						 }
					},
					error: function (XMLHttpRequest, textStatus, errorThrown) {
						jAlert('No se ha podido conectar con el servidor');
					}
				});


			}
		});


		return false
	});




});





