// JavaScript Document

function ProcessForm() {
		var vMultiplier;
		var vBuffer;
		
		if (document.frmDensityCalc.optMeasurement[0].checked) {
			vMultiplier = 1728;       /* 12 (W) * 12 (H)  * 12 (L)    convert inches to feet  */
		
		} else {
		
			if (document.frmDensityCalc.optMeasurement[1].checked) {
			
				vMultiplier = 1;
			
			} else {
			
				alert("Choose Measurement");
			
			}
		
		}
		
		document.frmDensityCalc.txtTotalCubicFeet.value = 0;
		document.frmDensityCalc.txtTotalPCF.value = 0;
		
		// if (document.frmDensityCalc.txtWeight.value.length > 0) {
		
			if (isNaN(document.frmDensityCalc.txtWeight.value) || (document.frmDensityCalc.txtWeight.value.length == 0) ) {
			
				alert("Enter valid weight value");
				document.frmDensityCalc.txtWeight.select();
			
			} else {
			
				if (document.frmDensityCalc.txtWeight.value > 0) {
				
				
				if (document.frmDensityCalc.txtQty1.value.length != 0) {
				
					if (document.frmDensityCalc.txtLength1.value.length != 0) {
					
						if (document.frmDensityCalc.txtWidth1.value.length != 0) {
						
							if (document.frmDensityCalc.txtHeight1.value.length != 0) {
							
							document.frmDensityCalc.txtCubicFeet1.value = "";
							
							
							computepcf(document.frmDensityCalc.txtQty1, document.frmDensityCalc.txtLength1, document.frmDensityCalc.txtWidth1, document.frmDensityCalc.txtHeight1, document.frmDensityCalc.txtCubicFeet1, vMultiplier)
					
							if (document.frmDensityCalc.txtCubicFeet1.value.length !=0) {
								document.frmDensityCalc.txtTotalCubicFeet.value = parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) + parseFloat(document.frmDensityCalc.txtCubicFeet1.value);
								
								}
							}
						}
					}
				}
		
		
				if (document.frmDensityCalc.txtQty2.value.length != 0) {
					if (document.frmDensityCalc.txtLength2.value.length != 0) {
						if (document.frmDensityCalc.txtWidth2.value.length != 0) {
							if (document.frmDensityCalc.txtHeight2.value.length != 0) {
							document.frmDensityCalc.txtCubicFeet2.value = "";
							
							computepcf(document.frmDensityCalc.txtQty2, document.frmDensityCalc.txtLength2, document.frmDensityCalc.txtWidth2, document.frmDensityCalc.txtHeight2, document.frmDensityCalc.txtCubicFeet2, vMultiplier)
							
							if (document.frmDensityCalc.txtCubicFeet2.value.length !=0) {
								document.frmDensityCalc.txtTotalCubicFeet.value = parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) + parseFloat(document.frmDensityCalc.txtCubicFeet2.value);
								}
							}
						}
					}
				}
		
		
		
				if (document.frmDensityCalc.txtQty3.value.length != 0) {
				
					if (document.frmDensityCalc.txtLength3.value.length != 0) {
					
						if (document.frmDensityCalc.txtWidth3.value.length != 0) {
						
							if (document.frmDensityCalc.txtHeight3.value.length != 0) {
							
							document.frmDensityCalc.txtCubicFeet3.value = "";
							
							computepcf(document.frmDensityCalc.txtQty3, document.frmDensityCalc.txtLength3, document.frmDensityCalc.txtWidth3, document.frmDensityCalc.txtHeight3, document.frmDensityCalc.txtCubicFeet3, vMultiplier)
							
							if (document.frmDensityCalc.txtCubicFeet3.value.length !=0) {
								document.frmDensityCalc.txtTotalCubicFeet.value = parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) + parseFloat(document.frmDensityCalc.txtCubicFeet3.value);
								}
							}
						}
					}
				}
		
		
		
				if (document.frmDensityCalc.txtQty4.value.length != 0) {
				
					if (document.frmDensityCalc.txtLength4.value.length != 0) {
					
						if (document.frmDensityCalc.txtWidth4.value.length != 0) {
						
							if (document.frmDensityCalc.txtHeight4.value.length != 0) {
							
							document.frmDensityCalc.txtCubicFeet4.value = "";
							
							computepcf(document.frmDensityCalc.txtQty4, document.frmDensityCalc.txtLength4, document.frmDensityCalc.txtWidth4, document.frmDensityCalc.txtHeight4, document.frmDensityCalc.txtCubicFeet4, vMultiplier)
							
							if (document.frmDensityCalc.txtCubicFeet4.value.length !=0) {
								document.frmDensityCalc.txtTotalCubicFeet.value = parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) + parseFloat(document.frmDensityCalc.txtCubicFeet4.value);
								}
							}
						}
					}
				}
		
				if (document.frmDensityCalc.txtQty5.value.length != 0) {
				
					if (document.frmDensityCalc.txtLength5.value.length != 0) {
					
						if (document.frmDensityCalc.txtWidth5.value.length != 0) {
						
							if (document.frmDensityCalc.txtHeight5.value.length != 0) {
							
							document.frmDensityCalc.txtCubicFeet5.value = "";
							
							computepcf(document.frmDensityCalc.txtQty5, document.frmDensityCalc.txtLength5, document.frmDensityCalc.txtWidth5, document.frmDensityCalc.txtHeight5, document.frmDensityCalc.txtCubicFeet5, vMultiplier)
							
							if (document.frmDensityCalc.txtCubicFeet5.value.length !=0) {
								document.frmDensityCalc.txtTotalCubicFeet.value = parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) + parseFloat(document.frmDensityCalc.txtCubicFeet5.value);
								}
							}
						}
					}
				}
		
				if (document.frmDensityCalc.txtQty6.value.length != 0) {

					if (document.frmDensityCalc.txtLength6.value.length != 0) {

						if (document.frmDensityCalc.txtWidth6.value.length != 0) {

							if (document.frmDensityCalc.txtHeight6.value.length != 0) {

							document.frmDensityCalc.txtCubicFeet6.value = "";

							computepcf(document.frmDensityCalc.txtQty6, document.frmDensityCalc.txtLength6, document.frmDensityCalc.txtWidth6, document.frmDensityCalc.txtHeight6, document.frmDensityCalc.txtCubicFeet6, vMultiplier)

							if (document.frmDensityCalc.txtCubicFeet6.value.length !=0) {

								document.frmDensityCalc.txtTotalCubicFeet.value = parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) + parseFloat(document.frmDensityCalc.txtCubicFeet6.value);

								}

							}

						}

					}

				}

				if (document.frmDensityCalc.txtQty7.value.length != 0) {

					if (document.frmDensityCalc.txtLength7.value.length != 0) {

						if (document.frmDensityCalc.txtWidth7.value.length != 0) {

							if (document.frmDensityCalc.txtHeight7.value.length != 0) {

							document.frmDensityCalc.txtCubicFeet7.value = "";

							computepcf(document.frmDensityCalc.txtQty7, document.frmDensityCalc.txtLength7, document.frmDensityCalc.txtWidth7, document.frmDensityCalc.txtHeight7, document.frmDensityCalc.txtCubicFeet7, vMultiplier)

							if (document.frmDensityCalc.txtCubicFeet7.value.length !=0) {

								document.frmDensityCalc.txtTotalCubicFeet.value = parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) + parseFloat(document.frmDensityCalc.txtCubicFeet7.value);

								}

							}

						}

					}

				}

				if (document.frmDensityCalc.txtQty8.value.length != 0) {

					if (document.frmDensityCalc.txtLength8.value.length != 0) {

						if (document.frmDensityCalc.txtWidth8.value.length != 0) {

							if (document.frmDensityCalc.txtHeight8.value.length != 0) {

							document.frmDensityCalc.txtCubicFeet8.value = "";

							computepcf(document.frmDensityCalc.txtQty8, document.frmDensityCalc.txtLength8, document.frmDensityCalc.txtWidth8, document.frmDensityCalc.txtHeight8, document.frmDensityCalc.txtCubicFeet8, vMultiplier)

							if (document.frmDensityCalc.txtCubicFeet8.value.length !=0) {

								document.frmDensityCalc.txtTotalCubicFeet.value = parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) + parseFloat(document.frmDensityCalc.txtCubicFeet8.value);

								}

							}

						}

					}

				}



				if (document.frmDensityCalc.txtTotalCubicFeet.value != 0 && document.frmDensityCalc.txtTotalCubicFeet.value < 750) {

					document.frmDensityCalc.txtTotalPCF.value  = format2digitnumber(parseFloat(document.frmDensityCalc.txtWeight.value) / parseFloat(document.frmDensityCalc.txtTotalCubicFeet.value) );
					} else {
					if (document.frmDensityCalc.txtTotalCubicFeet.value >= 750) {
					alert ("Please call CTL due to the density of this shipment.  Regular rates may not apply. (603) 881-3350");
					document.frmDensityCalc.txtTotalPCF.value = 0
					}
				}
		
			}
		
		
		}
	// }
	

	function computepcf(in_qty, in_length, in_width, in_height, in_cubicfeet,  in_multiplier) {
	
		if (isNaN(in_qty.value))  {
		
			alert("Please enter a vaild Quantity.");
			in_qty.select();
		
		} else {
		
			if (isNaN(in_length.value))  {
			
				alert("Please enter a vaild length.");
				in_length.select();
				
			} else {
			
				if (isNaN(in_width.value))  {
				
				alert("Please enter a vaild Width.");
				in_width.select();
				
				} else {
				
					if (isNaN(in_height.value))  {
					
						alert("Please enter a vaild Height.");
						in_height.select();
					
					} else {
					
					    if (in_height.value >= 47) {
						in_cubicfeet.value = format2digitnumber((in_qty.value * in_length.value * in_width.value * 96) / in_multiplier);
						} else {
						in_cubicfeet.value = format2digitnumber((in_qty.value * in_length.value * in_width.value * in_height.value) / in_multiplier);
						}
						}
					
					}
				}
			}
		}
	}
	
	function format2digitnumber(in_number) {
	var vNumber

		vNumber = parseInt(in_number * 100);
		
		return parseFloat(vNumber) / 100.;
	
	
	}


