 // copyright 1999 Idocs, Inc. http://www.idocs.com
// Distribute this script freely but keep this notice in place
function numbersonly(myfield, e, dec)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);

// control keys
if ((key==null) || (key==0) || (key==8) ||
	(key==9) || (key==13) || (key==27) )
   return true;

// numbers
else if ((("0123456789").indexOf(keychar) > -1)){
   return true;
}
// decimal point jump
else if (dec && (keychar == "."))
   {
   myfield.form.elements[dec].focus();
   return false;
   }
else
   return false;
};


function updateTotalPrice (tf) {
	var searchStr = "product_quantity";
	var id = Number(tf.name.slice(searchStr.length));
	var t = document.getElementById("product_total"+id);
	var itemsInCart = Number(tf.value);
	var priceZAR = products[id].priceZAR;
	t.innerHTML = (priceZAR * itemsInCart).toFixed(2);
	tally();
};

function tally () {
	var st = document.getElementById("product_subtotal");
	var t = document.getElementById("product_total");
	var v = document.getElementById("vat");
	
	var subTotal = 0;
	var total = 0;
	var vat = 0;
	for (var i=0;i<products.length;i++) {
		var qty = Number(myForm["product_quantity"+i].value);
		subTotal += Number(document.getElementById("product_total"+i).innerHTML);
	};
	st.innerHTML = subTotal.toFixed(2);					// set subtotal
	vat = (subTotal * 0.14);							// set VAT
	v.innerHTML = vat.toFixed(2);
	t.innerHTML = (vat + subTotal).toFixed(2);			// set total
};



products = [
			/*
{itemNum: "20078", name: "8 Colour Set MR.SKETCH MARKER (per box)", priceZAR: 70.00},
{itemNum: "20072",name: "12 Colour Set MR.SKETCH MARKER (per box)", priceZAR: 96.00},
{itemNum: "P0001",name: "FastPLAN&trade; Project Planning Starter Toolkit", priceZAR: 1550.00},
{itemNum: "P0002",name: "White Self Adhesive Sheets (700mm x 1000mm) (each)", priceZAR: 16.00},
{itemNum: "P0003",name: "Large Arrows (Pad of 50)", priceZAR: 16.50},
{itemNum: "P0004",name: "Small Arrows (Pad of 50)", priceZAR: 12.50},
{itemNum: "P0005",name: "Deliverable Pads (Pad of 50)", priceZAR: 19.00},
{itemNum: "P0006",name: "Task Pads (Pad of 50)", priceZAR: 19.00},
{itemNum: "P0007",name: "Title Pads (Pad of 50)", priceZAR: 21.50},
{itemNum: "P0010",name: "Large Clouds (Pad of 50)", priceZAR: 90.00},
{itemNum: "P0011",name: "Small Clouds (Pad of 50)", priceZAR: 50.00},
{itemNum: "P0012",name: "Question Cards (Pad of 50)", priceZAR: 45.00},
{itemNum: "P0013",name: "Circle Cards (Pad of 50)", priceZAR: 23.50},
{itemNum: "P0014",name: "Responsibility Cards (Pad of 50)", priceZAR: 40.00},
{itemNum: "P0015",name: "Idea Cards (Pad of 50)", priceZAR: 22.50}, 
{itemNum: "P0016",name: "Cluster Cards (Pad of 50)", priceZAR: 32.00},
{itemNum: "P0017",name: "Topic Cards (Pad of 50)", priceZAR: 24.50},
{itemNum: "M0001",name: "Pritt Sticky Stuff (Per Pack)", priceZAR: 10.50},
{itemNum: "M0002",name: "Artline30 Kokis (Per Box of 12) (Red, Black, Blue)", priceZAR: 96.00},
{itemNum: "P0008",name: "FastPLAN&trade; Project Planning Agenda Model and Facilitation Guide;", priceZAR: 650.00},
{itemNum: "P0009",name: "FaciliteIT!&trade; Travel Bag", priceZAR: 500.00}
*/
{itemNum: "10001",name: "Title Cards (Pad of 50) - Blue", priceZAR: 30.50},
{itemNum: "10002",name: "Task Cards (Pad of 50) - Yellow", priceZAR: 29.50},
{itemNum: "10003",name: "Deliverable Cards (Pad of 50) - Orange", priceZAR: 29.50},
{itemNum: "10004",name: "Self Adhesive Sheets (700mm x 1000mm) (each) - White ", priceZAR: 25.00},
{itemNum: "10005",name: "Large Dependency Arrows (Pad of 50)", priceZAR: 26.50},
{itemNum: "10006",name: "Small Dependency Arrows (Pad of 50)", priceZAR: 20.50},
{itemNum: "10007",name: "Topic Cards (Pad of 50) - Red", priceZAR: 34.50},
{itemNum: "10008",name: "Circle Cards (Pad of 50) - Green (Large)", priceZAR: 52.50},
{itemNum: "10009",name: "Cluster Cards (Pad of 50 - Red", priceZAR: 53.50},
{itemNum: "10010",name: "Idea Cards (Pad of 50) - Green - <b>OUT OF STOCK</b>", priceZAR: 34.50},
{itemNum: "10011",name: "Large Clouds (50 Cards per Set) - <b>OUT OF STOCK</b>", priceZAR: 86.00},
{itemNum: "10012",name: "Small Clouds (50 Cards per Set)", priceZAR: 65.50},
{itemNum: "10013",name: "Question Bubbles (50 Cards per Set)", priceZAR: 49.50},
{itemNum: "10014",name: "Responsibility (People) Cards (Pad of 50)", priceZAR: 57.50},
{itemNum: "10015",name: "Process Cards (Pad of 50) - Yellow - <b>NOW IN STOCK</b>", priceZAR: 34.50},
{itemNum: "10016",name: "Decision Cards (Pad of 50) - Orange - <b>NOW IN STOCK</b>", priceZAR: 32.50},
{itemNum: "10017",name: "Document Cards (Pad of 50) - Blue - <b>OUT OF STOCK</b>", priceZAR: 39.50},
{itemNum: "10018",name: "A4 Printable Sheets - <b>NOW IN STOCK</b>", priceZAR: 40.50},
{itemNum: "20001",name: "Pritt Sticky Stuff (Per Pack)", priceZAR: 17.50},
{itemNum: "20002",name: "Artline30 Kokis (Per Box of 12) (Red, Black, Blue)", priceZAR: 135.00},
{itemNum: "20004",name: "FacilitateIT!&trade; Travel Bag", priceZAR: 670.00},
{itemNum: "20078", name: "8 Colour Set MR.SKETCH MARKER (per box)", priceZAR: 125.00},
{itemNum: "20072",name: "12 Colour Set MR.SKETCH MARKER (per box)", priceZAR: 145.00},
{itemNum: "30001",name: "FastPLAN&trade; Project Planning Starter Toolkit", priceZAR: 2395.00},
{itemNum: "30002",name: "The IT Sessions Toolkit", priceZAR: 3495.00},
{itemNum: "30003",name: "The Process Mapping & Flow Charting Toolkit", priceZAR: 3995.00},
{itemNum: "30004",name: "The MINDSTORMING Group Techniques Toolkit", priceZAR: 2550.00},
{itemNum: "30005",name: "Stressballs (each)", priceZAR: 17.50},
{itemNum: "30006",name: "VisualiseIT!&trade; full colour large wall chart (each) - <b>not laminated</b>", priceZAR: 895.00} ,
{itemNum: "30007",name: "VisualiseIT!&trade; black & white large wall chart (each) - <b>not laminated</b>", priceZAR: 590.00} ,
{itemNum: "30008",name: "VisualiseIT!&trade; full colour A1 wall chart (each) - <b>not laminated</b>", priceZAR: 290.00} ,
{itemNum: "30009",name: "VisualiseIT!&trade; black & white A1 wall chart (each) - <b>not laminated</b>", priceZAR: 250.00} 

/*{itemNum: "P0008",name: "FastPLAN&trade; Project Planning Agenda Model and Facilitation Guide;", priceZAR: 650.00},*/
];
			  
function initProducts (isPrintMode) {
	qtyDefaultValue = isPrintMode ? "" : 0;
	var p = document.getElementById("divProducts");
	var html = "";
	html += '<table width="480" border="1" cellpadding="2" cellspacing="0" bordercolor="#DBDBDB">';
	html += '  <tr>';
	html += '    <td width="30" bgcolor="#666666" style="color: #ffffff;"><strong>Item</strong></td>';
	html += '    <td width="50" bgcolor="#666666" style="color: #ffffff;"><strong>Image</strong></td>';
	html += '    <td width="250" bgcolor="#666666" style="color: #ffffff;"><strong>Item Name</strong></td>';
	html += '    <td width="20" bgcolor="#666666" style="color: #ffffff;"><strong>Qty</strong></td>';
	html += '    <td width="60" align="right" bgcolor="#666666" style="color: #ffffff;"><strong>Price</strong></td>';
	html += '    <td width="70" align="right" bgcolor="#666666" style="color: #ffffff;"><strong>Total</strong></td>';
	html += '  </tr>';
	for (var i=0;i<products.length;i++) {
		var name = products[i].name;
		var itemNum = products[i].itemNum;
		var priceZAR = products[i].priceZAR.toFixed(2);
		var infoLink = products[i].infoLink;
		i % 2 == 0 ? html += '  <tr style="background-color: #efefef;">' : html += '  <tr style="background-color: #ffffff;">';;
		html += '    <td style="font-size: 10px;">'+itemNum+'</td>';
		html += '    <td style="font-size: 10px;"><a href="product_images/'+itemNum+'_lg.jpg'+'" target="_blank"><img src="product_images/'+itemNum+'.jpg" border="0" alt="View larger image" width="70" height="50"></a></td>';
		html += '    <td style="font-size: 10px;">'+name+'</td>';
		
		//if (isPrintMode) {
			//html += '    <td align="center"><input type="text" name="product_quantity'+i+'" value="'+qtyDefaultValue+'" style="width: 30px;" maxlength="3" style="font-size: 9px;"></td>';
		//} else {
			html += '    <td align="center"><input type="text" name="product_quantity'+i+'" value="'+qtyDefaultValue+'" style="width: 30px;" maxlength="3" onKeyPress="return numbersonly(this, event);" onKeyUp="updateTotalPrice(this);" style="font-size: 9px;"></td>';
		//};
	
		html += '    <td align="right">R '+priceZAR+'</td>';
		html += '    <td align="right">';
		html += '   	 <table border="0" cellspacing="0" cellpadding="0">';
		html += '     		 <tr>';
		html += '				<td>R&nbsp;</td>';
		html += '   			<td><div id="product_total'+i+'">0.00</div></td>';
		html += '     		 </tr>';
		html += '    	</table>';
		html += '    </td>';
		html += '  </tr>';
	};
	
	// Sub total row ______________ START
	html += '  <tr style="background-color: #ffffff;" align="right">';
	html += '    <td colspan="5">Sub Total</td>';
	html += '    <td>';
	html += '   	 <table border="0" cellspacing="0" cellpadding="0">';
	html += '     		 <tr>';
	html += '				<td>R&nbsp;</td>';
	html += '   			<td><div id="product_subtotal">0.00</div></td>';
	html += '     		 </tr>';
	html += '    	</table>';
	html += '    </td>';
	html += '  </tr>';
	// Sub total row ______________ END
	
	// VAT row ______________ START
	html += '  <tr style="background-color: #ffffff;" align="right">';
	html += '    <td colspan="5">VAT</td>';
	html += '    <td>';
	html += '   	 <table border="0" cellspacing="0" cellpadding="0">';
	html += '     		 <tr>';
	html += '				<td>R&nbsp;</td>';
	html += '   			<td><div id="vat">0.00</div></td>';
	html += '     		 </tr>';
	html += '    	</table>';
	html += '    </td>';
	html += '  </tr>';
	// VAT row ______________ END
	
	// total row ______________ START
	html += '  <tr align="right" bgcolor="#AD4B12">';
	html += '    <td colspan="5" style="color: #ffffff;"><strong>TOTAL (incl. VAT)</strong></td>';
	html += '    <td>';
	html += '   	 <table border="0" cellspacing="0" cellpadding="0">';
	html += '     		 <tr>';
	html += '				<td style="color: #ffffff;"><strong>R&nbsp;</strong></td>';
	html += '   			<td style="color: #ffffff;"><div id="product_total" style="font-weight: bold;">0.00</div></td>';
	html += '     		 </tr>';
	html += '    	</table>';
	html += '    </td>';
	html += '  </tr>';
	// total row ______________ END
	
	html += '</table>';
	p.innerHTML = html;
}
