<div id="divdialogBulto" title="Add Package" style="display:none">
	<input type="hidden" id="txtFecha" name="Fecha">
	<input type="hidden" id="txtIdUsuario" name="IdUsuario">

	<TABLE align="CENTER" width="300px">
		<tr>
			<th>
				 <div align="LEFT">
					 Length
				 </div>
			</th>

			<th>
				 <div align="LEFT">
					 Width
				 </div>
			</th>

			<th>
				 <div align="LEFT">
					 High
				 </div>
			</th>

			<th>
				 <div align="LEFT">
					 Weight
				 </div>
			</th>

		</tr>

		<tr>
			<th>
				 <div align="LEFT">
					 <input type="text" name="Length" id="txtLength" size="5px" onkeypress="return esInteger(event);" placeholder="MTS">
				 </div>
			</th>

			<th>
				 <div align="LEFT">
					 <input type="text" name="Width" id="txtWidth" size="5px" onkeypress="return esInteger(event);" placeholder="MTS">
				 </div>
			</th>

			<th>
				 <div align="LEFT">
					 <input type="text" name="Hight" id="txtHight" size="5px" onkeypress="return esInteger(event);" placeholder="MTS">
				 </div>
			</th>

			<th>
				 <div align="LEFT">
					 <input type="text" name="Weight" id="txtWeight" size="5px" onkeypress="return esInteger(event);" placeholder="KG">
				 </div>
			</th>

		</tr>


	</TABLE>

</div>

<script language="Javascript">

	$(function(){

		dialogBulto = $( "#divdialogBulto" ).dialog({

			autoOpen: false,
			height: 200,
			width: 600,
			modal: true,
			buttons: {
				"Add": AddBulto,
				Cancel: function() {
					dialogBulto.dialog( "close" );
				}
			}
		});





	});


	function AgregarBulto(FECHA,USUARIO_ID)
	{


		$("#txtFecha").val(FECHA);
		$("#txtIdUsuario").val(USUARIO_ID);



 		dialogBulto.dialog("open");
	}

	function AddBulto()
	{
		var data = "Fecha=" + $("#txtFecha").val();
		data += "&IdUsuario=" + $("#txtIdUsuario").val();
		data += "&Length=" + $("#txtLength").val();
		data += "&Width=" + $("#txtWidth").val();
		data += "&Hight=" + $("#txtHight").val();
		data += "&Weight=" + $("#txtWeight").val();



		if($("#txtLength").val()>2.40)
		{

			alert("Exceeds Length, please contact your executive");

			dialogBulto.dialog( "close" );
			return false;


		}else if($("#txtWidth").val()>1.20)
		{
			alert("Exceeds Width, please contact your executive");

			dialogBulto.dialog( "close" );
			return false;



		}else if($("#txtHight").val()>2.20)
		{
			alert("Exceeds Hight, please contact your executive");

			dialogBulto.dialog( "close" );
			return false;


		}else if($("#txtWeight").val()>1500)
		{
			alert("Exceeds Weight, please contact your executive");

			dialogBulto.dialog( "close" );
			return false;


		}else{

					$.ajax({

						async: true,
						type: "POST",
						url: "transacciones/guarda_bulto.php",
						data: data,
						dataType: "xml",
						success: function(xml) {

							var id=1;
							var calc;
							var sIdBulto  = $(xml).find('IdBulto').text();
							var sAlto = 	$(xml).find('Alto').text();
							var sAncho  = $(xml).find('Ancho').text();
							var sLargo  = $(xml).find('Largo').text();
							var sPeso  = $(xml).find('Peso').text();
							var sCBM  = $(xml).find('CBM').text();
							var sSumaPeso  = $(xml).find('SumaPeso').text();
							var sKiloVol  = $(xml).find('KiloVol').text();

							if (sIdBulto!="")
							{
								var sBulto = '<tr id="trBulto_' + sIdBulto + '">';
								sBulto += '<td><div align="center"><img SRC="../images/iconEliminar.png" width="20px" style="cursor:hand" title="Delete POD" onclick="eliminarBulto('+ sIdBulto +')"></div></th>';
								sBulto += '<td><div align="CENTER">' + sLargo + '</div></td>';
								sBulto += '<td><div align="CENTER">' + sAncho + '</div></td>';
								sBulto += '<td><div align="CENTER">' + sAlto + '</div></td>';
								sBulto += '<td><div align="CENTER">' + sPeso + '</div></td>';
								sBulto += '</tr>';

								$("#tbodyBulto").append(sBulto);

								$("#txtKGLCL").val(sSumaPeso);
								$("#txtCBMLCL").val(sCBM);

								$("#txtKG").val(sSumaPeso);
								$("#txtCBM").val(sCBM);

								calc=parseInt(sCBM*167);
								$("#txtKGVOL").val(calc);



								$("#txtKGAIRLCL").val(sSumaPeso);
								$("#txtCBMAIRLCL").val(sCBM);

								calc=parseInt(sCBM*167);
								$("#txtKGVOLAIRLCL").val(calc);



							}
								LimpiaCamposBulto();
								dialogBulto.dialog( "close" );

							return true;

						},
						error: function (request, status, error) {

							alert(status + ": " + error);
							return false;

						}

					});

		}





	}


	function eliminarBulto (sIdBulto) {


		var data = "IdBulto=" + sIdBulto;


		$.ajax({

			async: true,
			type: "POST",
			url: "transacciones/elimina_bulto.php",
			data: data,
			dataType: "xml",
			success: function(xml) {

				$("#trBulto_" + sIdBulto).remove();

				var sCBM  = $(xml).find('CBM').text();
				var sSumaPeso  = $(xml).find('SumaPeso').text();
				var sKiloVol  = $(xml).find('KiloVol').text();


				$("#txtKGLCL").val(sSumaPeso);
				$("#txtCBMLCL").val(sCBM);
// 				$("#txtKGVOLLCL").val(sKiloVol);


				return true;

			},
			error: function (request, status, error) {

				alerta(status + ": " + error);
				return false;

			}

		});
	}

	function LimpiaCamposBulto() {

		$("#txtLength").val("");
		$("#txtWidth").val("");
		$("#txtHight").val("");
		$("#txtWeight").val("");


	}



	</script>