// JavaScript Document
$(document).ready(function (){
/*****
var delet  = $('<div title="Mensaje"><p>Desea elimianr este producto.</p></div>');
$(".quitarprod").click(function(){
								delet.dialog( "option", "buttons", { "Ok": function() { $(this).dialog("close"); } } );
								});
/*********/
var caja  = $('<div title="Mensaje"><p>Usted no ha ingresado un valor...</p><p>Por favor ingrese una cantidad para agregar al carrito .</p></div>');
var caja2 = $('<div title="Mensaje"><p>El valor ingresado es incorrecto...</p><p>El valor es mayor a la cantidad disponible en stock, porfavor ingrese la cantidad correcta .</p></div>');
$("#enviar").click(function (){
			if($("#cantidad").val() == "" || $("#cantidad").val() == 0){
				caja.dialog();
				$("#cantidad").focus();
				//alert("no ingreso nada");
			}else if($("#cantidad_act").val() < $("#cantidad").val()){
				caja2.dialog();
				$("#cantidad").focus();
			}else{
				//remove all the class add the messagebox classes and start fading
			$("#msgbox").removeClass().addClass('messagebox').text('Agregando Producto....').fadeIn(1000);
			//check the username exists or not from ajax
			$.post("process_car.php",{ idproducto:$('#idproducto').val(),cantidad:$('#cantidad').val(),session:$('#session').val(),talla:$('input[name="chk_talla"]:checked').val(),oper:'add' } ,function(data)
        	{
		 	 if(data=='ok') //if correct login detail
		 	 {
		  	$("#msgbox").fadeTo(200,0.1,function()  //start fading the messagebox
			{ 
			  //add message and change the class of the box and start fading
			  $(this).html('Se agrego el producto al carrito').addClass('messageboxok').fadeTo(4000,1,
              function()
			  { 
			  	 //redirect to secure page
				 //document.location='secure.php';
				 //document.location='dashboard.php';
                 $("#msgbox").removeClass().text('');
				   
			  });
			  
			});
			 $("#cantidad").val("");
		  }
		  else
		  {
          $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
		  { 
		  //add message and change the class of the box and start fading
		  $(this).html('No se agregar el producto').addClass('messageboxerror').fadeTo(4000,1,function(){
																												   $("#msgbox").removeClass().text('');
																												   });
		  //$(".messageboxerror").removeClass();
		  });	
		  }	
        });
			}

});
$("#factura").click(function (){
			$("#textfield").attr('disabled','');
			$("#textfield2").attr('disabled','');
			$("#textfield3").attr('disabled','');
});
$("#boleta").click(function (){
			$("#textfield").val('');
			$("#textfield2").val('');
			$("#textfield3").val('');
			$("#textfield").attr('disabled','disabled');
			$("#textfield2").attr('disabled','disabled');
			$("#textfield3").attr('disabled','disabled');
			
});
});

function EliminarDato(producto_id,session_id){
var msg = confirm("Desea eliminar este producto de carrito?")
if ( msg ) {
		$.ajax({
				url: 'process_car.php',
				type: "POST",
				data: "idproducto="+producto_id+"&session="+session_id+"&oper=del",
				success: function(){
						//$("#fila-"+producto_id).remove();
						window.location.href = 'compraCarrito.php';
				}
		});
}
return false;
}

