// arrays
var quotePriceArray = Array();
var coverageArray = Array();
var padArray = Array();
var mouldingArray = Array();
var accessoryArray = Array();
 

/**
 * Init page load
 */
 function initPage() {
	 myForm = document.quoteWizard;
	 var pid;
	 if(myForm.waste.value != 0) {
		 myForm.ckWaste.checked = true;
	 }
	 calculateQuoteBySqFt(myForm);
	 // do mouldings
	 for(k=0;k<mouldingArray.length;k++) {
		 
		 if(eval("document.quoteWizard.ckMoulding_"+mouldingArray[k]+".checked == true")) {
			 tagMoulding(myForm,eval("document.quoteWizard.ckMoulding_"+mouldingArray[k]));
		 }
	 }
	 // do accessories
	 for(k=0;k<accessoryArray.length;k++) {
		 
		 if(eval("document.quoteWizard.ckAcc_"+accessoryArray[k]+".checked == true")) {
			 tagAccessory(myForm,eval("document.quoteWizard.ckAcc_"+accessoryArray[k]));
		 }
	 }
 }
 
 /**
   * Recalculates the pad cost bases on a custom price
   */
  function calcCustomPadTotal(element) {
	  var rolls,cost;
	  var fName = element.name;
	  var pid = fName.substring(fName.indexOf("_",0)+1,fName.length);
	  if(!isNumeric(element.value) && element.value.length > 0) {
	    alert("Please enter a valid numeric value");
		return;
	  }
	  if(element.value.length > 0) {
		  rolls = parseInt(element.value);
	  } else {
		  rolls = 0;
	  }
	  cost = getQuoteCostByPid(rolls,pid) * rolls;
	  eval("document.quoteWizard.padCost_"+pid+".value = '"+formatCurrency(cost)+"'");
	  if(eval("document.quoteWizard.ckPad_"+pid+".checked == true")) {
	      updateProductFields(document.quoteWizard,'padTotal_',cost);
	  }
  }
 
 /**
  * Calc tax
  */
  function calcTax(frm) {
	  var state = frm.shipState.options[frm.shipState.selectedIndex].value;
	  if(state == 'UT') {
		  var ttl1 = parseFloat(eval("document.quoteWizard.prodTotal_"+p1+".value")) + 
		             parseFloat(eval("document.quoteWizard.padTotal_"+p1+".value")) + 
					 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p1+".value")) + 
					 parseFloat(eval("document.quoteWizard.accTotal_"+p1+".value"));
		  ttl1 = ttl1 * 0.061;
		  eval("document.quoteWizard.taxTotal_"+p1+".value = '"+formatCurrency(ttl1)+"'");
		  if(target != 'order'  && target != 'quote') {
			  var ttl2 = parseFloat(eval("document.quoteWizard.prodTotal_"+p2+".value")) + 
	     	             parseFloat(eval("document.quoteWizard.padTotal_"+p2+".value")) + 
						 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p2+".value")) + 
						 parseFloat(eval("document.quoteWizard.accTotal_"+p2+".value"));
			  ttl2 = ttl2 * 0.061;
			  eval("document.quoteWizard.taxTotal_"+p2+".value = '"+formatCurrency(ttl2)+"'");
			  var ttl3 = parseFloat(eval("document.quoteWizard.prodTotal_"+p3+".value")) + 
	  	           	     parseFloat(eval("document.quoteWizard.padTotal_"+p3+".value")) + 
						 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p3+".value")) + 
						 parseFloat(eval("document.quoteWizard.accTotal_"+p3+".value"));
		      ttl3 = ttl3 * 0.061;
			  eval("document.quoteWizard.taxTotal_"+p3+".value = '"+formatCurrency(ttl3)+"'");
			  var ttl4 = parseFloat(eval("document.quoteWizard.prodTotal_"+p4+".value")) + 
	         		     parseFloat(eval("document.quoteWizard.padTotal_"+p4+".value")) + 
						 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p4+".value")) + 
						 parseFloat(eval("document.quoteWizard.accTotal_"+p4+".value"));
			  ttl4 = ttl4 * 0.061;
			  eval("document.quoteWizard.taxTotal_"+p4+".value = '"+formatCurrency(ttl4)+"'");
			  var ttl5 = parseFloat(eval("document.quoteWizard.prodTotal_"+p5+".value")) + 
	          		     parseFloat(eval("document.quoteWizard.padTotal_"+p5+".value")) + 
						 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p5+".value")) + 
						 parseFloat(eval("document.quoteWizard.accTotal_"+p5+".value"));
		      ttl5 = ttl5 * 0.061;
			  eval("document.quoteWizard.taxTotal_"+p5+".value = '"+formatCurrency(ttl5)+"'");
			  var ttl6 = parseFloat(eval("document.quoteWizard.prodTotal_"+p6+".value")) + 
	       		         parseFloat(eval("document.quoteWizard.padTotal_"+p6+".value")) + 
						 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p6+".value")) + 
						 parseFloat(eval("document.quoteWizard.accTotal_"+p6+".value"));
			  ttl6 = ttl6 * 0.061;
			  eval("document.quoteWizard.taxTotal_"+p6+".value = '"+formatCurrency(ttl6)+"'");
		  }
	  } else {
		  eval("document.quoteWizard.taxTotal_"+p1+".value = '0.00'");
		  if(target != 'order'  && target != 'quote') {
			  eval("document.quoteWizard.taxTotal_"+p2+".value = '0.00'");
			  eval("document.quoteWizard.taxTotal_"+p3+".value = '0.00'");
			  eval("document.quoteWizard.taxTotal_"+p4+".value = '0.00'");
			  eval("document.quoteWizard.taxTotal_"+p5+".value = '0.00'");
			  eval("document.quoteWizard.taxTotal_"+p6+".value = '0.00'");
		  }
	  }
  }
 
/**
 * Calc sqft
 */
 function calculateSqFt(frm) {
	var len1 = frm.length1.value; 
	var width1 = frm.width1.value; 
	var len2 = frm.length2.value; 
	var width2 = frm.width2.value; 
	var len3 = frm.length3.value; 
	var width3 = frm.width3.value;
	var sqft1 = 0;
	var sqft2 = 0;
	var sqft3 = 0;
	// For Room #1
	if((len1 != "" && len1.length > 0 && isNumeric(len1)) && (width1 != "" && width1.length > 0 && isNumeric(width1))) {
		len1 = parseFloat(len1);
		width1 = parseFloat(width1);
		sqft1 = Math.ceil(len1 * width1);
	} else {
		if(!isNumeric(len1) ) {
			alert("Please enter a valid numeric value.");
			return;	
		} else {
			len1 = 0;
		}
		if(!isNumeric(width1)) {
			alert("Please enter a valid numeric value.");
			return;	
		} else {
			width1 = 0;
		}
	}
	// For Room #2
	if((len2 != "" && len2.length > 0 && isNumeric(len2)) && (width2 != "" && width2.length > 0 && isNumeric(width2))) {
		len2 = parseFloat(len2);
		width2 = parseFloat(width2);
		sqft2 = Math.ceil(len2 * width2);
	} else {
		if(!isNumeric(len2) ) {
			alert("Please enter a valid numeric value.");
			return;	
		} else {
			len2 = 0;
		}
		if(!isNumeric(width2)) {
			alert("Please enter a valid numeric value.");
			return;	
		} else {
			width2 = 0;
		}
	}
	// For Room #3
	if((len3 != "" && len3.length > 0 && isNumeric(len3)) && (width3 != "" && width3.length > 0 && isNumeric(width3))) {
		len3 = parseFloat(len3);
		width3 = parseFloat(width3);
		sqft3 = Math.ceil(len3 * width3);
	} else {
		if(!isNumeric(len3) ) {
			alert("Please enter a valid numeric value.");
			return;	
		} else {
			len3 = 0;
		}
		if(!isNumeric(width3)) {
			alert("Please enter a valid numeric value.");
			return;	
		} else {
			width3 = 0;
		}
	}
	// set form sqfts
	frm.sqft1.value = sqft1;
	frm.sqft2.value = sqft2;
	frm.sqft3.value = sqft3;
	frm.totSqft.value = sqft1 + sqft2 + sqft3;
	// calculate the rest of the page
	calculateQuoteBySqFt(frm);
	calculateGrandTotals(frm);
 }
 
 /**
  * Tags a pad row for selection
  */
  function tagPad(frm,element) {
	  var obj;
	  var fName = element.name;
	  var pid = fName.substring(fName.indexOf("_",0)+1,fName.length);
	  var totalPadCost = eval("document.quoteWizard.padCost_"+pid+".value");
	  // only allow one box checked at once
	  if(element.checked == true && totalPadCost != "" && totalPadCost.length > 0) {
		  for(i=0;i<padArray.length;i++) {
			  obj = eval("document.quoteWizard.ckPad_"+padArray[i]);
			  if(obj.name == element.name) {
				  obj.checked = true;
			  } else {
				  obj.checked = false;
			  }
		  }
	  } else {
		  totalPadCost = 0.00;
	  }
	  //update products on right side
	  updateProductFields(frm,'padTotal_',parseFloat(totalPadCost));
  }
  
  /**
   * Returns the total square feet for all three rooms
   */
  function getTotalSquareFeet(frm) {
	  var sqft1 = 0;
	  var sqft2 = 0;
	  var sqft3 = 0;
	  var wasteSqFt = 0;
	  var ttl;
	  if(frm.sqft1.value != '' && frm.sqft1.value.length > 0 && isNumeric(frm.sqft1.value)) {
		  sqft1 = frm.sqft1.value;
	  }
	  if(frm.sqft2.value != '' && frm.sqft2.value.length > 0 && isNumeric(frm.sqft2.value)) {
		  sqft2 = frm.sqft2.value;
	  }
	  if(frm.sqft3.value != '' && frm.sqft3.value.length > 0 && isNumeric(frm.sqft3.value)) {
		  sqft3 = frm.sqft3.value;
	  }
	  ttl = parseFloat(sqft1) + parseFloat(sqft2) + parseFloat(sqft3);
	  if(frm.ckWaste.checked) {
		  wasteSqFt = Math.ceil(parseFloat(ttl) * .10);
	  } 
	  frm.waste.value = wasteSqFt;
	  return ttl + wasteSqFt;
	  
  }
/**
 * Calculates the other fields based on sq ft
 */
 function calculateQuoteBySqFt(frm) {
	 var sqft,sqftPerRoll,rolls, cost,total;
	 sqft = getTotalSquareFeet(frm)
	 if(sqft > 0) {
		 frm.totSqft.value = sqft;
		 // output values for paddings
		 for(i=0;i<padArray.length;i++) {
			 rolls = Math.ceil(parseInt(sqft)/getRawCoverage(padArray[i]));
			 cost = getQuoteCostByPid(rolls,padArray[i]) * rolls;
			 eval("document.quoteWizard.padRolls_"+padArray[i]+".value = "+rolls);
			 eval("document.quoteWizard.padCost_"+padArray[i]+".value = '"+formatCurrency(cost)+"'");
			 if(eval("document.quoteWizard.ckPad_"+padArray[i]+".checked == true")) {
				 updateProductFields(frm,'padTotal_',cost);
			 }
		 }
		 // set number of boxes and board price for each line
		 setProductBoxes(frm,parseInt(sqft));
		 calculateGrandTotals(frm);
	 } else {
		 // reset fields
		 frm.totSqft.value = 0;
		 //frm.ckWaste.checked = false;
		 frm.waste.value = 0;
		 for(i=0;i<padArray.length;i++) {
			 eval("document.quoteWizard.padRolls_"+padArray[i]+".value = 0");
			 eval("document.quoteWizard.padCost_"+padArray[i]+".value = '0.00'");
		 }
		 setProductBoxes(frm,0);
		 updateProductFields(frm,'prodTotal_',0.00);
		 updateProductFields(frm,'padTotal_',0.00);
	 }
 }
 
 /**
  * Tags a moulding row for selection
  */
  function tagMoulding(frm,element) {
	  var fName = element.name;
	  var pid = fName.substring(fName.indexOf("_",0)+1,fName.length);
	  calculateMoulding(frm,eval("document.quoteWizard.mouldingItems_"+pid));
  }
  
  /**
  * Tags an accessory row for selection
  */
  function tagAccessory(frm,element) {
	  var fName = element.name;
	  var pid = fName.substring(fName.indexOf("_",0)+1,fName.length);
	  calculateAccessory(frm,eval("document.quoteWizard.accItems_"+pid));
  }
 
 /**
  * Calculates moulding cost
  */
 function calculateMoulding(frm,element) {
	 var cost,items,rowCost,rowSelected;
	 var totalCost = 0;
	 var fName = element.name;
	 var pid = fName.substring(fName.indexOf("_",0)+1,fName.length);
	 if(element.value != '' && element.value.length > 0 && isNumeric(element.value)) {
		 cost = getQuoteCostByPid(element.value,pid);
		 items = parseInt(element.value);
		 num = cost * items;
		 eval("document.quoteWizard.mouldingCost_"+pid+".value = '"+formatCurrency(num)+"'");
		 // calc total moulding cost
		 for(i=0;i<mouldingArray.length;i++) {
			 rowCost = eval("document.quoteWizard.mouldingCost_"+mouldingArray[i]+".value");
			 rowSelected = eval("document.quoteWizard.ckMoulding_"+mouldingArray[i]+".checked");
			 if(rowCost != "" && rowCost.length > 0 && rowSelected) {
				 totalCost += parseInt(rowCost);
			 }
		 }
		 frm.totalMouldingCost.value = formatCurrency(totalCost);
		 //update products on right side
		 updateProductFields(frm,'mouldingTotal_',totalCost);
	 } else {
		 eval("document.quoteWizard.mouldingCost_"+pid+".value = 0");
		 //update products on right side
		 updateProductFields(frm,'mouldingTotal_',0.00);
		 if(!isNumeric(element.value)) {
			alert("Please enter a numeric value.");
		 }
	 }
 }
 
 /**
  * Calculates accessory cost
  */
 function calculateAccessory(frm,element) {
	 var cost,items,rowCost,rowSelected;
	 var totalCost = 0;
	 var fName = element.name;
	 var pid = fName.substring(fName.indexOf("_",0)+1,fName.length);
	 if(element.value != '' && element.value.length > 0 && isNumeric(element.value)) {
		 cost = getQuoteCostByPid(element.value,pid);
		 items = parseInt(element.value);
		 num = cost * items;
		 eval("document.quoteWizard.accCost_"+pid+".value = '"+formatCurrency(num)+"'");
		 // calc total accessory cost
		 for(i=0;i<accessoryArray.length;i++) {
			 rowCost = eval("document.quoteWizard.accCost_"+accessoryArray[i]+".value");
			 rowSelected = eval("document.quoteWizard.ckAcc_"+accessoryArray[i]+".checked");
			 if(rowCost != "" && rowCost.length > 0 && rowSelected) {
				 totalCost += parseInt(rowCost);
			 }
		 }
		 frm.totalAccCost.value = formatCurrency(totalCost);
		 //update products on right side
		 updateProductFields(frm,'accTotal_',totalCost);
	 } else {
		 eval("document.quoteWizard.accCost_"+pid+".value = 0");
		 //update products on right side
		 updateProductFields(frm,'accTotal_',0.00);
		 if(!isNumeric(element.value)) {
			alert("Please enter a numeric value.");
		 }
	 }
 }
 
 /**
  * Updates the product fields
  * CLEAN THIS UP WITH AN ARRAY OF THE QUOTE PRODUCTS
  */
  function updateProductFields(frm,field,value) {
	  eval("document.quoteWizard."+field+p1+".value = '"+formatCurrency(value)+"'");
	  if(target != 'order' && target != 'quote') {
		  eval("document.quoteWizard."+field+p2+".value = '"+formatCurrency(value)+"'");
		  eval("document.quoteWizard."+field+p3+".value = '"+formatCurrency(value)+"'");
		  eval("document.quoteWizard."+field+p4+".value = '"+formatCurrency(value)+"'");
		  eval("document.quoteWizard."+field+p5+".value = '"+formatCurrency(value)+"'");
		  eval("document.quoteWizard."+field+p6+".value = '"+formatCurrency(value)+"'");
	  }
	  calculateGrandTotals(frm);
  }
  
  /**
   * Calculates the grand totals for the product fields
   */
   function calculateGrandTotals(frm) {
	  // calculate the tax values first
	  calcTax(frm);
	  var ttl1 = parseFloat(eval("document.quoteWizard.prodTotal_"+p1+".value")) + 
	             parseFloat(eval("document.quoteWizard.padTotal_"+p1+".value")) + 
				 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p1+".value")) +
				 parseFloat(eval("document.quoteWizard.accTotal_"+p1+".value")) +
				 parseFloat(eval("document.quoteWizard.taxTotal_"+p1+".value")) + 
				 parseFloat(eval("document.quoteWizard.shippingTotal_"+p1+".value"));
	  eval("document.quoteWizard.grandTotal_"+p1+".value = '"+formatCurrency(ttl1)+"'");
	  displayMessage(frm,p1,ttl1);
	  if(target != 'order'  && target != 'quote') {
		  var ttl2 = parseFloat(eval("document.quoteWizard.prodTotal_"+p2+".value")) + 
	             parseFloat(eval("document.quoteWizard.padTotal_"+p2+".value")) + 
				 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p2+".value")) + 
				 parseFloat(eval("document.quoteWizard.accTotal_"+p1+".value")) +
				 parseFloat(eval("document.quoteWizard.taxTotal_"+p2+".value")) + 
				 parseFloat(eval("document.quoteWizard.shippingTotal_"+p2+".value"));
	      eval("document.quoteWizard.grandTotal_"+p2+".value = '"+formatCurrency(ttl2)+"'");
		  displayMessage(frm,p2,ttl2);
		  var ttl3 = parseFloat(eval("document.quoteWizard.prodTotal_"+p3+".value")) + 
	             parseFloat(eval("document.quoteWizard.padTotal_"+p3+".value")) + 
				 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p3+".value")) + 
				 parseFloat(eval("document.quoteWizard.accTotal_"+p1+".value")) +
				 parseFloat(eval("document.quoteWizard.taxTotal_"+p3+".value")) + 
				 parseFloat(eval("document.quoteWizard.shippingTotal_"+p3+".value"));
	      eval("document.quoteWizard.grandTotal_"+p3+".value = '"+formatCurrency(ttl3)+"'");
		  displayMessage(frm,p3,ttl3);
		  var ttl4 = parseFloat(eval("document.quoteWizard.prodTotal_"+p4+".value")) + 
	             parseFloat(eval("document.quoteWizard.padTotal_"+p4+".value")) + 
				 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p4+".value")) + 
				 parseFloat(eval("document.quoteWizard.accTotal_"+p1+".value")) + 
				 parseFloat(eval("document.quoteWizard.taxTotal_"+p4+".value")) + 
				 parseFloat(eval("document.quoteWizard.shippingTotal_"+p4+".value"));
	      eval("document.quoteWizard.grandTotal_"+p4+".value = '"+formatCurrency(ttl4)+"'");
		  displayMessage(frm,p4,ttl4);
		  var ttl5 = parseFloat(eval("document.quoteWizard.prodTotal_"+p5+".value")) + 
	             parseFloat(eval("document.quoteWizard.padTotal_"+p5+".value")) + 
				 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p5+".value")) +
				 parseFloat(eval("document.quoteWizard.accTotal_"+p1+".value")) +
				 parseFloat(eval("document.quoteWizard.taxTotal_"+p5+".value")) +
				 parseFloat(eval("document.quoteWizard.shippingTotal_"+p5+".value"));
	      eval("document.quoteWizard.grandTotal_"+p5+".value = '"+formatCurrency(ttl5)+"'");
		  displayMessage(frm,p5,ttl5);
		  var ttl6 = parseFloat(eval("document.quoteWizard.prodTotal_"+p6+".value")) + 
	             parseFloat(eval("document.quoteWizard.padTotal_"+p6+".value")) + 
				 parseFloat(eval("document.quoteWizard.mouldingTotal_"+p6+".value")) +
				 parseFloat(eval("document.quoteWizard.accTotal_"+p1+".value")) +
				 parseFloat(eval("document.quoteWizard.taxTotal_"+p6+".value")) + 
				 parseFloat(eval("document.quoteWizard.shippingTotal_"+p6+".value"));
	      eval("document.quoteWizard.grandTotal_"+p6+".value = '"+formatCurrency(ttl6)+"'");
		  displayMessage(frm,p6,ttl6);
	  }
   }
   
   /**
    * Displays the square foot message to the customer!
	*/
	function displayMessage(frm,prod,total) {
		var msg,field,field2;
		msg = formatCurrency(total/parseFloat(frm.totSqft.value));
		field = 'msg_'+prod;
		field2 = 'disclaimer_'+prod;
		if(frm.totSqft.value != '' && frm.totSqft.value != '0') {
			if(total > 0.00) {
				document.getElementById(field).innerHTML = '<font color="blue"><i>* That is only <b>$'+msg+'</b> per square foot delivered!</i></font>';
				document.getElementById(field2).innerHTML = '<font color="blue">* Calculated value is based on total number of boxes ordered which, in most cases, covers more than the square footage entered.</font>';
			} else {
				document.getElementById(field).innerHTML = '';
				document.getElementById(field2).innerHTML = '';
			}
		} else {
			document.getElementById(field).innerHTML = '';
			document.getElementById(field2).innerHTML = '';
		}
	}
  
  /**
   * Sets the product boxes and board prices
   * CLEAN THIS UP WITH AN ARRAY OF THE QUOTE PRODUCTS
   */
  function setProductBoxes(frm,sqFt) {
	  var strFBoxes = "boxTotal_";
	  var strFBoardPrice = "prodTotal_";
	  var boxes1 = getCoverageForItem(sqFt,p1);
	  var boxes2 = getCoverageForItem(sqFt,p2);
	  var boxes3 = getCoverageForItem(sqFt,p3);
	  var boxes4 = getCoverageForItem(sqFt,p4);
	  var boxes5 = getCoverageForItem(sqFt,p5);
	  var boxes6 = getCoverageForItem(sqFt,p6);
	  var cost1 = getQuoteCostByPid(boxes1,p1);
	  var cost2 = getQuoteCostByPid(boxes2,p2);
	  var cost3 = getQuoteCostByPid(boxes3,p3);
	  var cost4 = getQuoteCostByPid(boxes4,p4);
	  var cost5 = getQuoteCostByPid(boxes5,p5);
	  var cost6 = getQuoteCostByPid(boxes6,p6);
	  var ttl1 = parseFloat(boxes1 * cost1);
	  var ttl2 = parseFloat(boxes2 * cost2);
	  var ttl3 = parseFloat(boxes3 * cost3);
	  var ttl4 = parseFloat(boxes4 * cost4);
	  var ttl5 = parseFloat(boxes5 * cost5);
	  var ttl6 = parseFloat(boxes6 * cost6);
	  eval("document.quoteWizard.boxTotal_"+p1+".value = "+boxes1);
	  if(target != 'order' && target != 'quote') {
		  eval("document.quoteWizard.boxTotal_"+p2+".value = "+boxes2);
		  eval("document.quoteWizard.boxTotal_"+p3+".value = "+boxes3);
		  eval("document.quoteWizard.boxTotal_"+p4+".value = "+boxes4);
		  eval("document.quoteWizard.boxTotal_"+p5+".value = "+boxes5);
		  eval("document.quoteWizard.boxTotal_"+p6+".value = "+boxes6);
	  }
	  eval("document.quoteWizard.prodTotal_"+p1+".value = '"+formatCurrency(ttl1)+"'");
	  if(target != 'order' && target != 'quote') {
		  eval("document.quoteWizard.prodTotal_"+p2+".value = '"+formatCurrency(ttl2)+"'");
		  eval("document.quoteWizard.prodTotal_"+p3+".value = '"+formatCurrency(ttl3)+"'");
		  eval("document.quoteWizard.prodTotal_"+p4+".value = '"+formatCurrency(ttl4)+"'");
		  eval("document.quoteWizard.prodTotal_"+p5+".value = '"+formatCurrency(ttl5)+"'");
		  eval("document.quoteWizard.prodTotal_"+p6+".value = '"+formatCurrency(ttl6)+"'");
	  }
  }
 
 /**
  * Returns the cost by box number
  */
 function getQuoteCostByPid(boxNum,pid) {
	 for(var i=0;i<quotePriceArray.length;i++) {
		 obj = quotePriceArray[i];
		 if(obj.pid == pid && boxNum >= obj.fromQty && boxNum <= obj.toQty) {
		    return obj.boxPrice; 
		 }
	 }
	 return 0;
	 
 }
 
 /**
  * Returns the total number of boxes needed per item
  */
  function getCoverageForItem(sqFt,pid) {
	  for(var i=0;i<coverageArray.length;i++) {
		  obj = coverageArray[i];
		  if(obj.pid == pid) {
				return Math.ceil(sqFt/obj.coverage);  
		  }
	  }
	  return 0;
  }
 
 /**
  * Builds a price object for the quick quote
  */
 function buildQuotePriceObject(fromQty,toQty,boxPrice,sqftPrice,pid) {
	objPrice = new Object();
	objPrice.pid = pid;
	objPrice.fromQty = fromQty;
	objPrice.toQty = toQty;
	objPrice.boxPrice = boxPrice;
	objPrice.sqftPrice = sqftPrice;
	curr = quotePriceArray.length;
	quotePriceArray[curr++] = objPrice;
 }
 
 /**
  * Builds the coverage objects
  */
  function buildCoverageObject(pid,coverage) {
	  objCoverage = new Object();
	  objCoverage.pid = pid;
	  objCoverage.coverage = coverage;
	  curr = coverageArray.length;
	  coverageArray[curr++] = objCoverage;
  }
  
  /**
   * Builds the pad Array
   */
  function buildPadArray(pid) {
	  curr = padArray.length;
	  padArray[curr++] = pid;
  }
  
  /**
   * Builds the moulding Array
   */
  function buildMouldingArray(pid) {
	  curr = mouldingArray.length;
	  mouldingArray[curr++] = pid;
  }
  
  /*
   * Builds the accessory Array
   */
  function buildAccessoryArray(pid) {
	  curr = accessoryArray.length;
	  accessoryArray[curr++] = pid;
  }
  
  /**
   * Return raw coverage for a given pid
   */
   function getRawCoverage(pid) {
	   for(var i=0;i<coverageArray.length;i++) {
		  obj = coverageArray[i];
		  if(obj.pid == pid) {
				return obj.coverage;  
		  }
	  }
	  return 0;
   }

