var labelsIndex; var bAutoclear; var bConverted; var txtSelShip; var txtConvert; var visibleDiv; var labelsEnglishDim; var labelsEnglishShip; var labelsMetricDim; var labelsMetricShip; var labels; var xmlResults = new Array(); var convertHongKongStandard; var convertInternationalStandard; var convertNewStandard; var convertNegotiated; var convert; var constants; var constant; var constantsToVol; var constantDimToVol; var conversionFactor; var convertIndex; var convertTypeIndex; var dimFactorLabels; var dimFactorIndex; var cfToCm; var cmToCf; var lbToKg; var kgToLb; var inTocm; var cmToin; var win; var bCalc; $(document).ready(function () { if(!/Safari/i.test(navigator.userAgent) || (document.location.href.indexOf("firstRun") == -1)) { initializePage(); } }); function initializePage() { // If parent is not our own site, display logo div. $("#divLogo").hide(); var url = null; try { url = top.location.href; } catch(err) { $("#divLogo").show(); } if((top === self) || (url == undefined)) { $("#divLogo").show(); } // Initialize the alertBox div for use as a modal dialog. // This replaces the version of the "alert" function in VBScript that allows // setting the buttons and title of the dialog. Javascript does not provide // such a feature directly. $("#alertBox").dialog({ autoOpen: false }); $("#alertBox").dialog({ buttons: [ { text: "OK", click: function () { $(this).dialog("close"); } } ] }); $("#confirmBox").dialog({ autoOpen: false }); $("#confirmBox").dialog({ buttons: [ { text: "Yes", click: function () { $(this).dialog("close"); bAutoclear = true; clearAll(); bAutoclear = false;} }, { text: "No", click: function() { $(this).dialog("close"); calcShip();} } ] }); // Initialize the page after everything is loaded and ready to run labelsIndex = 0; win = null; visibleDiv = null; bCalc = false; cfToCm = 0.0283; cmToCf = 35.3147; lbToKg = 0.4536; kgToLb = 2.2046; cmToin = 0.393701; inTocm = 2.54; bConverted = false; bAutoclear = false; labelsEnglishDim = new Array("Feet","Lbs","In"); labelsEnglishShip = new Array("Feet","Lbs","In"); labelsMetricDim = new Array("Meters","Kgs","Cm"); labelsMetricShip = new Array("Meters","Kgs","Cm"); dimFactorIndex = 0; dimFactorLabels = new Array(new Array("194 In./Lb.","7,000 Cm./Kg."), new Array("166 In./Lb.","6,000 Cm./Kg."), new Array("138 In./Lb.","5,000 Cm./Kg.")); labels = new Array(labelsEnglishDim, labelsEnglishShip, labelsMetricDim, labelsMetricShip); constants = new Array(1728,1000000); // English, Metric; constantsToVol = new Array(12,100); // English, Metric; convertHongKongStandard = new Array(194,7000); // English, Metric; convertInternationalStandard = new Array(166,6000); convertNewStandard = new Array(138,5000); convertNegotiated = new Array(0,0); convert = new Array(convertHongKongStandard, convertInternationalStandard,convertNewStandard,convertNegotiated); convertIndex = 0; convertTypeIndex = 0; var tempArrayVar = convert[convertTypeIndex]; conversionFactor = tempArrayVar[convertIndex]; constant = constants[convertIndex]; constantDimToVol = constantsToVol[convertIndex] // Replaces onkeypress="checkEnter(event)" from the Body tag $('body').keypress(function(event){ if(event.keyCode == 13) { calcShip()}; }); // Moved here from the onload event of the Body tag in order to ensure the variables are initialized before the event is executed. initDisplay(); } // Function to call in place of the original VBScript "alert" function. function alertDialog(message, title) { alert(message); } function confirmClearData() { if (confirm("Would you like to clear the data?")) { clearAll(); } else { calcShip(); } } function ignoreInput() { event.returnValue=false; } function convertResults() { var b; if($('#txtShipChgWt0').text() > "0") { b = bConverted; calcShip(); if(b) { if(convertIndex == 0) { $('#cvLbl').text("Metric"); } else { $('#cvLbl').text("English"); } $('#cvLbl').text($('#cvLbl').text()); return; } } else { return; } x = visibleDiv; y = labelsIndex; visibleDiv = $('#divShipHeader')[0]; bAll = true; var xmlDoc = new SoftXMLLib(); xmlDoc.loadXML(xmlResults[0]); $('#txtShipChgWt0').text(parseFloat($(xmlDoc.documentElement).find("shipchgwt").text())); $('#txtShipVolWt0').text(parseFloat($(xmlDoc.documentElement).find("shipvolwt").text())); xmlDoc.loadXML(xmlResults[1]); $('#txtShipChgWt1').text(parseFloat($(xmlDoc.documentElement).find("shipchgwt").text())); $('#txtShipVolWt1').text(parseFloat($(xmlDoc.documentElement).find("shipvolwt").text())); xmlDoc.loadXML(xmlResults[2]); $('#txtShipChgWt2').text(parseFloat($(xmlDoc.documentElement).find("shipchgwt").text())); $('#txtShipVolWt2').text(parseFloat($(xmlDoc.documentElement).find("shipvolwt").text())); if(convertIndex == 0) { $('#txtShipChgWt0').text(FormatNumber(parseFloat($('#txtShipChgWt0').text()) * lbToKg, 2, true, false, false)); if(($('#txtShipChgWt0').text() - Math.floor($('#txtShipChgWt0').text())) > .5) { $('#txtShipChgWt0').text(FormatNumber(Math.floor($('#txtShipChgWt0').text()) + 1,2, true, false, false)); } else if(parseFloat($('#txtShipChgWt0').text() - Math.floor($('#txtShipChgWt0').text())) > 0) { $('#txtShipChgWt0').text(FormatNumber(Math.floor($('#txtShipChgWt0').text()) + .5,2, true, false, false)); } $('#txtShipVolWt0').text(FormatNumber(parseFloat($('#txtShipVolWt0').text()) * lbToKg,2, true, false, false)); $('#txtShipChgWt1').text(FormatNumber(parseFloat($('#txtShipChgWt1').text()) * lbToKg,2, true, false, false)); if(($('#txtShipChgWt1').text() - Math.floor($('#txtShipChgWt1').text())) > .5) { $('#txtShipChgWt1').text(FormatNumber(Math.floor($('#txtShipChgWt1').text()) + 1,2, true, false, false)); } else if(parseFloat($('#txtShipChgWt1').text() - Math.floor($('#txtShipChgWt1').text())) > 0) { $('#txtShipChgWt1').text(FormatNumber(Math.floor($('#txtShipChgWt1').text()) + .5,2, true, false, false)); } $('#txtShipVolWt1').text(FormatNumber(parseFloat($('#txtShipVolWt1').text()) * lbToKg,2, true, false, false)); $('#txtShipChgWt2').text(FormatNumber(parseFloat($('#txtShipChgWt2').text()) * lbToKg,2, true, false, false)); if(($('#txtShipChgWt2').text() - Math.floor($('#txtShipChgWt2').text())) > .5) { $('#txtShipChgWt2').text(FormatNumber(Math.floor($('#txtShipChgWt2').text()) + 1,2, true, false, false)); } else if(parseFloat($('#txtShipChgWt2').text() - Math.floor($('#txtShipChgWt2').text())) > 0) { $('#txtShipChgWt2').text(FormatNumber(Math.floor($('#txtShipChgWt2').text()) + .5,2, true, false, false)); } $('#txtShipVolWt2').text(FormatNumber(parseFloat($('#txtShipVolWt2').text()) * lbToKg,2, true, false, false)); if(labelsIndex == 0) { $('#txtShipDim0').val(FormatNumber(parseFloat($('#txtShipDim0').val()) * cfToCm,2, true, false, false)); $('#txtShipWt0').val(FormatNumber(parseFloat($('#txtShipWt0').val()) * lbToKg,2, true, false, false)); $('#txtShipDim1').text($('#txtShipDim0').text()); $('#txtShipWt1').text($('#txtShipWt0').text()); $('#txtShipDim2').text($('#txtShipDim0').text()); $('#txtShipWt2').text($('#txtShipWt0').text()); $('#txtShipDim3').text($('#txtShipDim0').text()); $('#txtShipWt3').text($('#txtShipWt0').text()); } labelsIndex = 3; } else { $('#txtShipChgWt0').text(FormatNumber(((parseFloat($('#txtShipChgWt0').text()) * kgToLb)+.5).toFixed(0),2, true, false, false)); $('#txtShipVolWt0').text(FormatNumber(parseFloat($('#txtShipVolWt0').text()) * kgToLb,2, true, false, false)); $('#dimFactorLabel0').text(dimFactorLabels[0][0]); $('#txtShipChgWt1').text(FormatNumber(((parseFloat($('#txtShipChgWt1').text()) * kgToLb)+.5).toFixed(0),2, true, false, false)); $('#txtShipVolWt1').text(FormatNumber(parseFloat($('#txtShipVolWt1').text()) * kgToLb,2, true, false, false)); $('#dimFactorLabel1').text(dimFactorLabels[1][0]); $('#txtShipChgWt2').text(FormatNumber(((parseFloat($('#txtShipChgWt2').text()) * kgToLb)+.5).toFixed(0),2, true, false, false)); $('#txtShipVolWt2').text(FormatNumber(parseFloat($('#txtShipVolWt2').text()) * kgToLb,2, true, false, false)); $('#dimFactorLabel2').text(dimFactorLabels[2][0]); if(labelsIndex == 2) { $('#txtShipDim0').val(FormatNumber(parseFloat($('#txtShipDim0').val()) * cmToCf,2, true, false, false)); $('#txtShipWt0').val(FormatNumber(parseFloat($('#txtShipWt0').val()) * kgToLb,2, true, false, false)); $('#txtShipDim1').text($('#txtShipDim0').text()); $('#txtShipWt1').text($('#txtShipWt0').text()); $('#txtShipDim2').text($('#txtShipDim0').text()); $('#txtShipWt2').text($('#txtShipWt0').text()); $('#txtShipDim3').text($('#txtShipDim0').text()); $('#txtShipWt3').text($('#txtShipWt0').text()); } labelsIndex = 1; } convertBk = convertIndex; if(convertIndex == 0) { convertIndex = 1; } else { convertIndex = 0; } dimFactorIndex = 2; setLabels(); dimFactorIndex = 1; setLabels(); dimFactorIndex = 0; setLabels(); convertIndex = convertBk; labelsIndex = y; visibleDiv = x; bConverted = true; if(convertIndex == 0) { $('#cvLbl').text("English"); } else { $('#cvLbl').text("Metric"); } $('#cvLbl2').text($('#cvLbl').text()); } var calc; function initDisplay() { detailLines(); selShip(document.getElementById('rbShip1')); selConvert($('#rbConvert1')); $('#txtDtlQty0').focus(); if(location.href.indexOf("file://") > -1) { calc = new ActiveXObject("cwCalc.Calc"); } } function selShip(opt) { var bCalc; bCalc = false; $('#divShip')[0].style.display = ""; visibleDiv = document.getElementById('divShip'); $('#' + opt.value)[0].style.display = ""; if(opt.value != "divDetail") { document.getElementById('divDetail').style.display = "none"; } txtSelShip = opt.nextSibling.textContent; labelsIndex = parseInt(opt.id.substr(opt.id.length-1))-1; if((convertIndex == 0 && labelsIndex > 1) || (convertIndex == 1 && labelsIndex <= 1)) { if($.trim($('#txtShipChgWt0').text()) > "0"){ bCalc = true}; } convertIndex = 0; if(labelsIndex > 1){ convertIndex = 1}; var tempArrayVar = convert[convertTypeIndex]; conversionFactor = tempArrayVar[convertIndex]; constant = constants[convertIndex]; constantDimToVol = constantsToVol[convertIndex]; dimFactorIndex = 2; setLabels(); dimFactorIndex = 1; setLabels(); dimFactorIndex = 0; setLabels(); enableEntryFields(); if(! bAutoclear) { if(bCalc) { confirmClearData(); } } } function selConvert(opt) { if(visibleDiv == null) { return; } txtConvert = opt.next().text(); var id = opt[0].id; convertTypeIndex = parseFloat(id.substr(id.length-1))-1; var tempArrayVar = convert[convertTypeIndex]; conversionFactor = tempArrayVar[convertIndex]; setLabels(); } function setLabels() { var i; if(txtConvert != "") { //document.all.divLabel.innerText = txtSelShip + " @ " + txtConvert; } try { // MLT - this doesn't appear to do anything since there are no tags with "dimension" as their id. This may be a leftover from // the full version of the calculator. I've commented out these two lines and the two in the catch to avoid javascript errors. // I left them here for use in the conversion of the full application if/when we get there. $("#dimension").text(labels[labelsIndex][0]); } catch(err) { //for(i = 0; i < visibleDiv.all("dimension").length - 1; i++) //visibleDiv.all("dimension")(i).innerText = labels[labelsIndex](0); } for(i = 0; i < $(visibleDiv).find('span[id^="weight"]').length; i++) $(visibleDiv).find('#weight' + i).text(labels[labelsIndex][1]); for (i = 0; i < $(visibleDiv).find('span[id^="dimensionIncrement"]').length; i++) $(visibleDiv).find('#dimensionIncrement' + i).text(labels[labelsIndex][2]); $('#dimFactorLabel' + dimFactorIndex).text(dimFactorLabels[dimFactorIndex][convertIndex]); bConverted = false; if(convertIndex == 0) { $('#cvLbl').text("Metric"); } else { $('#cvLbl').text("English"); } $('#cvLbl2').text($('#cvLbl').text()); } function enableEntryFields() { var b; b = false; if($('#rbKnowWeight2')[0].checked) { b = true; } if(labelsIndex == 0 || labelsIndex == 2) { $('#txtShipDim0')[0].disabled = true; $('#txtShipWt0')[0].disabled = true; for(i = 3; i < $('input[id^=txtDtlWt]').length + 3; i++) $('#txtDtlWt' + i)[0].disabled = b; } else { $('#txtShipDim0')[0].disabled = false; $('#txtShipWt0')[0].disabled = b; } } function getAttrValue(ctrl, attrName) { var retval = ""; if (typeof ctrl.attr(attrName) != 'undefined') { retval = ctrl.attr(attrName); } return retval; } function clearAll() { var tbl; $('#rbConvert1')[0].checked = true; $('#rbKnowWeight1')[0].checked = true; selConvert($('#rbConvert1')); selWeight($('#rbKnowWeight1')); dimFactorIndex = 2; setLabels(); dimFactorIndex = 1; setLabels(); dimFactorIndex = 0; setLabels(); $('#txtShipDim0').val("0"); $('#txtShipDim1').text("0"); $('#txtShipDim2').text("0"); $('#txtShipWt0').val("0"); $('#txtShipWt1').text("0"); $('#txtShipWt2').text("0"); $('#txtShipChgWt0').text("0"); $('#txtShipVolWt0').text("0"); $('#txtShipChgWt1').text("0"); $('#txtShipVolWt1').text("0"); $('#txtShipChgWt2').text("0"); $('#txtShipVolWt2').text("0"); $('#txtShipQty').text(""); tbl = document.getElementById('detailTable'); while(tbl.rows.length > 3) { tbl.deleteRow(tbl.rows.length-1); } detailLines(); } function detailLines() { var tbl, rows, i, start; tbl = document.getElementById("detailTable"); var selValue = parseFloat(document.getElementById("detailSel").value); rows = selValue + 3; start = tbl.rows.length; if(tbl.rows.length > rows) { while(tbl.rows.length > rows) { tbl.deleteRow(tbl.rows.length-1); } return; } //i = tbl.rows.length; i = firstMissingRow(); if(i != -1) { while(tbl.rows.length < rows) { makeRow(tbl, i); i = i + 1; } } if(visibleDiv != null) { enableEntryFields(); } } function firstMissingRow() { var numRows = parseInt($('#detailSel')[0].value); var firstMissingRow = -1; if($('input[id^=btnClear]').length < numRows) { for(i = 3; i < numRows + 3; i++) { if($('#btnClear' + i)[0] == undefined) { firstMissingRow = i; break; } } } return firstMissingRow; } function clearOne(btn) { var tbl, tr, i, start; tbl = $('#detailTable')[0]; tr = $('#' + btn.target.id).parent().parent()[0]; i = tr.rowIndex; $(tr).find('input[type=text]').each(function(intIndex){$(this)[0].value='0';}); for(index = 0; index < $(tr).find('span').length; index++) $(tr).find('span')[index].innerHTML = ""; } function delOne(btn) { var tbl, tr, i, start; tbl = $('#detailTable')[0]; tr = $('#' + btn.target.id).parent().parent()[0]; i = tr.rowIndex; tbl.deleteRow(i); detailLines(); } function makeRow(tbl, iX) { var tr, td, inp; tr = tbl.insertRow(tbl.rows.length); td = tr.insertCell(-1); td.align = "center"; td.setAttribute('style', 'white-space: nowrap'); inp = document.createElement("input"); inp.setAttribute('type', 'button'); $(inp).click(clearOne); inp.setAttribute('name', 'btnClear' + iX); inp.setAttribute('id', 'btnClear' + iX); inp.setAttribute('value', 'C'); inp.setAttribute('width', '16'); inp.setAttribute('title', 'Clear Row'); $(td).append(inp); inp = document.createElement("input"); inp.setAttribute('type', 'button'); $(inp).click(delOne); inp.setAttribute('name', 'btnDel' + iX); inp.setAttribute('id', 'btnDel' + iX); inp.setAttribute('value', ' X '); inp.setAttribute('title', 'Delete Row'); $(td).append(inp); $(td).append(' '); inp = document.createElement("input"); inp.setAttribute('type', 'text'); inp.setAttribute('name', 'txtDtlQty' + iX); inp.setAttribute('id', 'txtDtlQty' + iX); inp.setAttribute('value', '0'); inp.setAttribute('size', '10'); $(inp).focus(function() {selectContents(this);}); $(td).append(inp); $(td).append(' '); inp = document.createElement("input"); inp.setAttribute('type', 'hidden'); inp.setAttribute('name', 'txtItem' + iX); inp.setAttribute('id', 'txtItem' + iX); inp.setAttribute('value', '~'); $(td).append(inp); td = tr.insertCell(-1); td.align = "center"; inp = document.createElement("input"); inp.setAttribute('type', 'text'); //inp.setAttribute('onfocus', 'javascript:this.select()'); $(inp).focus(function() {selectContents(this);}); inp.setAttribute('name', 'txtDtlLen' + iX); inp.setAttribute('id', 'txtDtlLen' + iX); inp.setAttribute('value', '0'); inp.setAttribute('size', '10'); $(td).append(inp); td = tr.insertCell(-1); td.align = "center"; inp = document.createElement("input"); inp.setAttribute('type', 'text'); //inp.setAttribute('onfocus', 'javascript:this.select()'); $(inp).focus(function() {selectContents(this);}); inp.setAttribute('name', 'txtDtlWidth' + iX); inp.setAttribute('id', 'txtDtlWidth' + iX); inp.setAttribute('value', '0'); inp.setAttribute('size', '10'); $(td).append(inp); td = tr.insertCell(-1); td.align = "center"; inp = document.createElement("input"); inp.setAttribute('type', 'text'); //inp.setAttribute('onfocus', 'javascript:this.select()'); $(inp).focus(function() {selectContents(this);}); inp.setAttribute('name', 'txtDtlHeight' + iX); inp.setAttribute('id', 'txtDtlHeight' + iX); inp.setAttribute('value', '0'); inp.setAttribute('size', '10'); $(td).append(inp); td = tr.insertCell(-1); td.align = "center"; inp = document.createElement("span"); inp.setAttribute('name', 'txtDtlVol' + iX); inp.setAttribute('id', 'txtDtlVol' + iX); inp.style.fontSize="x-small"; $(td).append(inp); td = tr.insertCell(-1); td.align = "center"; td.id="tdDtlWt1" + iX; inp = document.createElement("input"); inp.setAttribute('type', 'text'); //inp.setAttribute('onfocus', 'javascript:this.select()'); $(inp).focus(function() {selectContents(this);}); inp.setAttribute('name', 'txtDtlWt' + iX); inp.setAttribute('id', 'txtDtlWt' + iX); inp.setAttribute('value', '0'); inp.setAttribute('size', '10'); $(td).append(inp); td = tr.insertCell(-1); td.align = "center"; td.id="tdDtlWt2" + iX; inp = document.createElement("span"); inp.setAttribute('name', 'txtDtlWtTot' + iX); inp.setAttribute('id', 'txtDtlWtTot' + iX); inp.style.fontSize="x-small"; $(td).append(inp); } function selectContents(obj) { setTimeout(function() {obj.select();}, 100); } function selWeight(opt) { if($(opt).val() == "V1") { for(i = 3; i < (parseFloat($('#detailSel').val()) + 3); i++) { $('#tdDtlWt1'+i).show(); $('#tdDtlWt2'+i).show() $('#txtDtlWt'+i).val(0); } $('#hdShipWt').show(); $('#hdShipWt2').show(); $('#tdShipWt0').show(); $('#tdShipWt1').show(); $('#tdShipWt2').show(); $('#tdShipWt3').show(); $('#tdShipWt4').show(); $('#hdDtlWt11').show(); $('#hdDtlWt12').show(); $('#hdDtlWt21').show(); $('#hdDtlWt22').show(); $('#txtShipWt0').val("0"); $('#txtShipWt1').val("0"); } else { for (i = 3; i < (parseFloat($('#detailSel').val()) + 3); i++) { $('#tdDtlWt1'+i).hide(); $('#tdDtlWt2'+i).hide(); $('#txtDtlWt'+i).val(.0001); } $('#hdShipWt').hide(); $('#hdShipWt2').hide(); $('#tdShipWt0').hide(); $('#tdShipWt1').hide(); $('#tdShipWt2').hide(); $('#tdShipWt3').hide(); $('#tdShipWt4').hide(); $('#hdDtlWt11').hide(); $('#hdDtlWt12').hide(); $('#hdDtlWt21').hide(); $('#hdDtlWt22').hide(); $('#txtShipWt0').val(".0001"); $('#txtShipWt1').val(".0001"); if(bCalc) { calcShip(); } } } function calcShip() { selConvert($('#rbConvert3')); dimFactorIndex = 2; doCalc(); selConvert($('#rbConvert2')); dimFactorIndex = 1; doCalc(); selConvert($('#rbConvert1')); dimFactorIndex = 0; doCalc(); } function doCalc() { var parms; setLabels(); if((labelsIndex == 0 || labelsIndex == 2)) { parms = makeParms(1, getVars(), getDetail()); if(parms.length < 100) { $('#txtShipWt0').val("0"); $('#txtShipDim0').val("0"); $('#txtShipWt1').text("0"); $('#txtShipDim1').text("0"); $('#txtShipWt2').text("0"); $('#txtShipDim2').text("0"); $('#txtShipChgWt' + dimFactorIndex).text("0"); return; } } else { parms = makeParms(0, getVars(), getShip()); } getData(parms); bCalc = true; } function getServerData(xmlDoc) { // For some reason the relative url "postHandler.asp?request=cwCalc" doesn't work. Had to build-up the full url from the current location.href. var url = document.location.href.substring(0, document.location.href.indexOf("ChargeableWeightSample_new.htm")) + "postHandler.asp?request=cwCalc"; //var url = "http://www.acuitivesolutions.com/costrite/postHandler.asp?request=cwCalc"; var lib = new SoftXMLLib(); var AJAX = lib.createAjaxObject(); if (AJAX) { AJAX.open("POST", url, false); AJAX.send(xmlDoc.DOM); return AJAX.responseText; } else { return false; } } function getData(parms) { var xmlDoc; xmlDoc = new SoftXMLLib(); xmlDoc.loadXML(parms); b = false; // file:// was not found in the url if(document.location.href.indexOf("file://") == -1) { xmlDoc.loadXML(getServerData(xmlDoc)); if(xmlDoc.loadXMLError == 0) b = true; } else { xmlDoc.loadXML(calc.calc(parms)); if(xmlDoc.loadXMLError == 0) b = true; } if(b) { if($(xmlDoc.DOM).find("error").length > 0) { alertDialog($(xmlDoc.DOM).find("error").text(), "Cube"); return; } if((labelsIndex == 0 || labelsIndex == 2)) { $('#txtShipWt0').val(FormatNumber(parseFloat($(xmlDoc.documentElement).find("shipwt").text()), 2, true, false, false)); $('#txtShipDim0').val(FormatNumber(parseFloat($(xmlDoc.documentElement).find("shipvol").text()), 2, true, false, false)); $('#txtShipDim1').text(FormatNumber(parseFloat($(xmlDoc.documentElement).find("shipvol").text()), 2, true, false, false)); $('#txtShipWt1').text(FormatNumber(parseFloat($(xmlDoc.documentElement).find("shipwt").text()), 2, true, false, false)); $('#txtShipDim2').text(FormatNumber(parseFloat($(xmlDoc.documentElement).find("shipvol").text()), 2, true, false, false)); $('#txtShipWt2').text(FormatNumber(parseFloat($(xmlDoc.documentElement).find("shipwt").text()), 2, true, false, false)); detailReturns($(xmlDoc.documentElement).find("detail")); } else { shipVolUnrounded = $('#txtShipDim0').val(); $('#txtShipDim1').text($('#txtShipDim0').val()); $('#txtShipDim2').text($('#txtShipDim0').val()); $('#txtShipWt1').text($('#txtShipWt0').val()); $('#txtShipWt2').text($('#txtShipWt0').val()); } x = $(xmlDoc.documentElement).find("shipvolwt").text(); $('#txtShipVolWt' + dimFactorIndex).text(FormatNumber(parseFloat(x), 2, true, false, false)); x = $(xmlDoc.documentElement).find("shipchgwt").text(); x = parseFloat(x); if(parseFloat(x.toFixed(2)) != parseFloat(x.toFixed(0))) { if(labelsIndex == 0 || labelsIndex == 1 || (x - Math.floor(x)) > .5) { // english system; x = Math.floor(x) + 1 // lb; } else if(parseFloat(x.toFixed(2)) != parseFloat((x.toFixed(0)) + 0.5)) { x = Math.floor(x) + 0.5 //kg; } } $('#txtShipChgWt'+dimFactorIndex).text(FormatNumber(x, 2, true, false, false)); xmlResults[dimFactorIndex] = xmlDoc.getDocXML(); } } function detailReturns(detail) { if((detail == undefined) || (detail.length == 0)){ return;} var i, j, k, arr, vol, tot; var offset; k = 0; tot = 0; for(i = 0; i < detail.length; i++) { arr = detail.eq(i).text().split(","); for (j = k; j < $('input[id^=txtDtlQty]').length; j++) { offset = j + 3; if($('#txtDtlQty' + offset).val() != "" || $('#txtDtlLen' + offset).val() == "" || $('#txtDtlWidth' + offset).val() == "" || $('#txtDtlHeight' + offset).val() == "") { if($('#txtDtlQty' + offset).val() > 0 && $('#txtDtlLen' + offset).val() > 0 && $('#txtDtlWidth' + offset).val() > 0 && $('#txtDtlHeight' + offset).val() > 0) { $('#txtDtlWtTot' + offset).text((parseFloat($('#txtDtlWt' + offset).val()) * $('#txtDtlQty' + offset).val()).toFixed(2)); vol = parseFloat($('#txtDtlQty' + offset).val()) * (parseFloat($('#txtDtlLen' + offset).val())+.01).toFixed(0) * (parseFloat($('#txtDtlWidth' + offset).val())+.01).toFixed(0) * (parseFloat($('#txtDtlHeight' + offset).val())+.01).toFixed(0); var tmpTxt = FormatNumber(parseFloat(arr[0]),2, true, false, false); $('#txtDtlVol' + offset).text(tmpTxt); tot = tot + vol; k = j + 1; j = $('input[id^=txtDtlQty]').length; } } } } } function makeParms(detailFlag, variables, data){ var str; str = "" + detailFlag + ""; str = str + "" + variables + ""; str = str + "" + data + ""; return str + ""; } function getVars(){ var str; str = (constant / conversionFactor); return str + "," + constantDimToVol; } function getShip(){ return $('#txtShipDim0').val() + "," + $('#txtShipWt0').val(); } function getDetail() { var str, i, qty; str = ""; qty = 0; for(i = 3; i < $('input[id^=txtDtlQty]').length + 3; i++) { $('#txtDtlQty' + i)[0].style.backgroundColor = "White"; $('#txtDtlLen' + i)[0].style.backgroundColor = "White"; $('#txtDtlWidth' + i)[0].style.backgroundColor = "White"; $('#txtDtlHeight' + i)[0].style.backgroundColor = "White"; $('#txtDtlWt' + i)[0].style.backgroundColor = "White"; } for(i = 3; i < $('input[id^=txtDtlQty]').length + 3; i++) { if($('#txtDtlWt' + i)[0].value == "" || $('#txtDtlQty' + i)[0].value == "" || $('#txtDtlLen' + i)[0].value == "" || $('#txtDtlWidth' + i)[0].value == "" || $('#txtDtlHeight' + i)[0].value == "") { if(! (($('#txtDtlWt' + i)[0].value == "0" || $('#txtDtlWt' + i)[0].value == ".0001" || $('#txtDtlWt' + i)[0].value == "0.0001") && $('#txtDtlQty' + i)[0].value == "0" && $('#txtDtlLen' + i)[0].value == "0" && $('#txtDtlWidth' + i)[0].value == "0" && $('#txtDtlHeight' + i)[0].value == "0")) { if($('#txtDtlQty' + i)[0].value == "") { $('#txtDtlQty' + i).style.backgroundColor = "Yellow"; $('#txtDtlQty' + i).focus(); } if($('#txtDtlLen' + i)[0].value == "") { $('#txtDtlLen' + i).style.backgroundColor = "Yellow"; $('#txtDtlLen' + i).focus(); } if(txtDtlWidth(i)[0].value == "") { $('#txtDtlWidth' + i).style.backgroundColor = "Yellow"; $('#txtDtlWidth' + i).focus(); } if($('#txtDtlHeight' + i)[0].value == "") { $('#txtDtlHeight' + i).style.backgroundColor = "Yellow"; $('#txtDtlHeight' + i).focus(); } if($('#rbKnowWeight1')[0].checked && $('#txtDtlWt' + i)[0].value == "") { $('#txtDtlWt' + i).style.backgroundColor = "Yellow"; $('#txtDtlWt' + i).focus(); } return ""; } } if(! ($('#txtDtlWt' + i)[0].value > 0 && $('#txtDtlQty' + i)[0].value > 0 && $('#txtDtlLen' + i)[0].value > 0 && $('#txtDtlWidth' + i)[0].value > 0 && $('#txtDtlHeight' + i)[0].value > 0)) { if(! (($('#txtDtlWt' + i)[0].value == "0" || $('#txtDtlWt' + i)[0].value == ".0001" || $('#txtDtlWt' + i)[0].value == "0.0001") && $('#txtDtlQty' + i)[0].value == "0" && $('#txtDtlLen' + i)[0].value == "0" && $('#txtDtlWidth' + i)[0].value == "0" && $('#txtDtlHeight' + i)[0].value == "0")) { if($('#txtDtlQty' + i)[0].value <= 0) { $('#txtDtlQty' + i)[0].style.backgroundColor = "Yellow"; $('#txtDtlQty' + i)[0].focus(); } if($('#txtDtlLen' + i)[0].value <= 0) { $('#txtDtlLen' + i)[0].style.backgroundColor = "Yellow"; $('#txtDtlLen' + i)[0].focus(); } if($('#txtDtlWidth' + i)[0].value <= 0) { $('#txtDtlWidth' + i)[0].style.backgroundColor = "Yellow"; $('#txtDtlWidth' + i)[0].focus(); } if($('#txtDtlHeight' + i)[0].value <= 0) { $('#txtDtlHeight' + i)[0].style.backgroundColor = "Yellow"; $('#txtDtlHeight' + i)[0].focus(); } if($('#rbKnowWeight1')[0].checked && $('#txtDtlWt' + i)[0].value <= 0) { $('#txtDtlWt' + i)[0].style.backgroundColor = "Yellow"; $('#txtDtlWt' + i)[0].focus(); } return ""; } } } for (i = 3; i < $('input[id^=txtDtlQty]').length + 3; i++) { if(! ($('#txtDtlQty' + i)[0].value == "" || $('#txtDtlLen' + i)[0].value == "" || $('#txtDtlWidth' + i)[0].value == "" || $('#txtDtlHeight' + i)[0].value == "")) { if($('#txtDtlQty' + i)[0].value > 0 && $('#txtDtlLen' + i)[0].value > 0 && $('#txtDtlWidth' + i)[0].value > 0 && $('#txtDtlHeight' + i)[0].value > 0) { str = str + "" + $('#txtDtlQty' + i)[0].value + "," + $('#txtDtlLen' + i)[0].value + "," + $('#txtDtlWidth' + i)[0].value + "," + $('#txtDtlHeight' + i)[0].value + "," + $('#txtDtlWt' + i)[0].value + ""; qty = qty + parseFloat($('#txtDtlQty' + i)[0].value); } } } $('#txtShipQty').text(qty); return str; }