var groupArray = { 22 : { group_id: 1 }, 1 : { group_id: 1 }, 23 : { group_id: 1 }, 24 : { group_id: 2 }, 2 : { group_id: 2 }, 25 : { group_id: 2 }, 26 : { group_id: 3 }, 3 : { group_id: 3 }, 27 : { group_id: 3 }, 19 : { group_id: 4 }, 4 : { group_id: 4 }, 20 : { group_id: 5 }, 5 : { group_id: 5 }, 31 : { group_id: 6 }, 6 : { group_id: 6 }, 32 : { group_id: 6 }, 21 : { group_id: 7 }, 7 : { group_id: 7 }, 8 : { group_id: 8 }, 18 : { group_id: 9 }, 17 : { group_id: 9 }, 30 : { group_id: 9 }, 16 : { group_id: 9 }, 15 : { group_id: 9 }, 29 : { group_id: 9 }, 14 : { group_id: 9 }, 9 : { group_id: 9 }, 28 : { group_id: 9 }, 10 : { group_id: 10 }, 11 : { group_id: 11 }, 12 : { group_id: 12 }, 13 : { group_id: 13 }}; var myInt = 0; var product_options = ''; var sizeArray = [{ prod_id: '1', options: '' }, { prod_id: '2', options: '' }, { prod_id: '3', options: '' }, { prod_id: '4', options: '' }, { prod_id: '5', options: '' }, { prod_id: '6', options: '' }, { prod_id: '7', options: '' }, { prod_id: '8', options: '' }, { prod_id: '9', options: '' }, { prod_id: '10', options: '' }, { prod_id: '11', options: '' }, { prod_id: '12', options: '' }, { prod_id: '13', options: '' }, ]; var v_quantity = 0; var v_total_price = 0; var v_index = -1; var lineNo = 0; var RecipientNo = 0; var RecipientNumber = 0; var OrderLineNumber = 0; var size_options = ' '; var recip_nums = new Array(); var order_nums = new Array(); var myShip2Int = 0; var ship2No = 0; var ShipToSectionNumber = 0; function format_number(pnumber,decimals){ if (isNaN(pnumber)) { return 0}; if (pnumber=='') { return 0}; var snum = new String(pnumber); var sec = snum.split('.'); var whole = parseFloat(sec[0]); var result = ''; if(sec.length > 1){ var dec = new String(sec[1]); dec = String(parseFloat(sec[1])/Math.pow(10,(dec.length - decimals))); dec = String(whole + Math.round(parseFloat(dec))/Math.pow(10,decimals)); var dot = dec.indexOf('.'); if(dot == -1){ dec += '.'; dot = dec.indexOf('.'); } while(dec.length <= dot + decimals) { dec += '0'; } result = dec; } else{ var dot; var dec = new String(whole); dec += '.'; dot = dec.indexOf('.'); while(dec.length <= dot + decimals) { dec += '0'; } result = dec; } return result; } function calcPrice(lineNo, RecipientNo) { var v_price = '0.00'; v_quantity = $('#' + RecipientNo.toString() + 'quantity' + lineNo.toString()).val(); v_index = $('#' + RecipientNo.toString() + 'product' + lineNo).val(); if(!isNaN(parseInt(v_quantity)) && v_quantity > 0) { $('#' + RecipientNo.toString() + 'product' + lineNo.toString()).removeAttr("disabled").attr("enabled","enabled"); $('#' + RecipientNo.toString() + 'size' + lineNo.toString()).removeAttr("disabled").attr("enabled","enabled"); // $('#submit_order').removeAttr("disabled").attr("enabled","enabled"); } else { $('#' + RecipientNo.toString() + 'product' + lineNo.toString()).removeAttr("enabled").attr("disabled","disabled"); $('#' + RecipientNo.toString() + 'size' + lineNo.toString()).removeAttr("enabled").attr("disabled","disabled"); // $('#submit_order').removeAttr("enabled").attr("disabled","disabled"); } if(v_index > ''){ if(v_quantity == '' || isNaN(parseInt(v_quantity)) || v_quantity < 0) { v_quantity = 0; } v_price = $('#' + RecipientNo.toString() + 'size' + lineNo.toString()).val() * v_quantity; if(v_price == 0) { v_price = '0'; } $('#' + RecipientNo.toString() + 'price' + lineNo.toString()).val(format_number(v_price,2)); var tmp_value = 0; $.each($('.price'), function(i, val) { tmp_value += parseFloat(val.value); }); $('#total_price').val(format_number(tmp_value,2)); if(tmp_value> 0) { $('#submit_order').removeAttr("disabled").attr("enabled","enabled"); } else { $('#submit_order').removeAttr("enabled").attr("disabled","disabled"); } size_options = sizeArray[groupArray[v_index]['group_id'] - 1]['options']; v_price = '0.00'; } } function removeOrderLine(lineNo, RecipientNo) { if(confirm("Are you sure you want to remove the order line?")) { $('#' + RecipientNo.toString() + 'row' + lineNo.toString()).remove();/* myInt--; $('input#' + RecipientNo.toString() + 'quantity' + (myInt).toString()).focus();*/ var tmp_value = 0; $.each($('.price'), function(i, val) { tmp_value += parseFloat(val.value); }); $('#total_price').val(format_number(tmp_value,2)); calcPrice(lineNo, RecipientNo); var i = 0; // alert(lineNo); while(order_nums[RecipientNo][i] <= lineNo && order_nums[RecipientNo][i] != 'undefined') { // alert(order_nums[RecipientNo][i] + ' - ' + lineNo); i++; } order_nums[RecipientNo].splice(i,1); return false; } } function processProductChange(lineNo, RecipientNo) { calcPrice(lineNo, RecipientNo); $('#' + RecipientNo.toString() + 'size' + lineNo.toString()).html(size_options).change(); } function GenerateOrderLine(OrderLineNumber, RecipientNumber) { order_nums[RecipientNumber].push(OrderLineNumber); var myOrderLine ='\n\n\n\n\n\n\n\n\n\n\n\n' + 'X\n\n'; calcPrice(OrderLineNumber, RecipientNumber); OrderLineNumber++; return myOrderLine; }; function GenerateShipToSection(ShipToSectionNumber) { recip_nums.push(ShipToSectionNumber); order_nums[ShipToSectionNumber] = new Array(); var myShipToSection = '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n\n\n' + '\n' + '
' + '\nShip To Address' + '\n
' + '\nName: ' + '\n' + '\n' + '\n
' + '\nStreet: ' + '\n' + '\n' + '\n
' + '\n ' + '\n' + '\n' + '\n
' + '\nCity: ' + '\n' + '\n ' + '\nState: ' + '\nZip: ' + '\n
' + '\n This is a Business Address' + '\n
' + '\n Ship now' + '\n
' + '\n To Arrive the week of ' + '\n / ' + '\n
' + '\n Gift Wrapping (add $.50 per box)' + '\n
' + '\n Greetings From ' + '\n
 
' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n' + '\n
QtyDescriptionSizeTotal 
' + '\n' + '\n
' + '\n
\nRemove Recipient\n' + '
\n'; ShipToSectionNumber++; return myShipToSection; }; function removeShipToSection(ship2No) { if(confirm("Are you sure you want to remove the ship to section?")) { $("#ship2row" + ship2No.toString()).remove(); // $('input#ship_name' + (--ship2No).toString()).focus(); var i = 0; // alert(ship2No); while(recip_nums[i] <= ship2No && recip_nums[i] != 'undefined') { // alert(recip_nums[i] + ' - ' + ship2No); i++; } recip_nums.splice(i,1); return false; } } function popVals() { $('#recip_nums').val(recip_nums.join()); var len = recip_nums.length; for(var i = 0; i < len; i++) { $('#order_nums' + recip_nums[i]).val(order_nums[recip_nums[i]].join()); } } $(document).ready(function() { $('#add_ship_to' + RecipientNumber.toString()) .click(function() { $('#ship_to_head0').append(GenerateShipToSection(myShip2Int)); myShip2Int++; $('#add_product' + RecipientNumber.toString()) .click(function() { size_options = ""; var recip = this.id.unformat('add_product{0}')[0]; $('#order_head' + recip).append(GenerateOrderLine(myInt, recip)); myInt++; }).click(); RecipientNumber++; }).click(); $("#bill_name").focus(); });