
			function get_total_price() {
				var tot_price = 0;
				for (var a = 1; a <= orders; a++) {
					var it = "product_" + a;
					if (document.getElementById(it)) {
						//add up total price
						var cs = "price_" + a;
						tot_price += parseFloat(document.getElementById(cs).value);
					}
				}
				document.getElementById("pre_discount").value = tot_price;
				
				get_discount();
			}
			
			function get_discount() {
				var d = document.getElementById("discount_perc").value;
				var tc = document.getElementById("pre_discount").value;
				var gv = document.getElementById("gift_voucher_price").value;
				var disc = Math.round(d*tc/100);
				var total = tc - disc - gv;
				
				if (isNaN(total)) { total = 0; }
				if (total < 0) { total = 0; }
				
				document.getElementById("initial_price").innerHTML = "R " + tc;
				document.getElementById("discount").innerHTML = "R " + disc;
				document.getElementById("total_price").innerHTML = "R " + total;
				
				document.getElementById("total_cost").value = total;
			}

			function pricer(it) {
				var size = document.getElementById("size_" + it).value;
				var product = document.getElementById("product_" + it).value;
				var copies = document.getElementById("copies_" + it).value;
				var price = document.getElementById("price_" + it).value;
				
				var wid = parseInt(document.getElementById("size_w_" + it).value);
				var hgt = parseInt(document.getElementById("size_h_" + it).value);
				
				var nice_price = get_price(product, wid, hgt, copies);
				
				document.getElementById("price_" + it).value = nice_price;
				document.getElementById("price" + it).innerHTML = "R " + nice_price;
				get_total_price();
			}

			function get_price(product, wid, hgt, copies) {
				var area = wid * hgt / 1000000;
				var perim = (wid + hgt)*2;

				var print_price = 0;
				var mount_price = 0;
				
				if (product == "Canvas stretched frame") { 
					print_price = (area * canvas_paper) + base_canvas;
					mount_price = base_frame + (perim * frame_mm);
				}
				if (product == "Acrylic print") {
					print_price = area * gloss_paper;
					mount_price = acrylic_m2 * area;
					mount_price = mount_price + acrylic_labour;
				}
				if (product == "Mounted gloss print") {
					print_price = area * gloss_paper;
					mount_price = mount_6mm * area;
					mount_price = mount_price + mount_labour;
					
					// updated 8 june 09 - we now double-laminate these prints, which adds 42% to the total cost
					print_price = 1.42 * print_price;
					mount_price = 1.42 * mount_price;
				}
				if (product == "Box frames") {
					print_price = area * gloss_paper;
					mount_price = perim * box_frame_mm;
					mount_price = mount_price + box_frame_labour;
				}
				if (product == "Loose glossy print") {
					print_price = area * gloss_paper;
				}
				if (product == "Loose canvas print") {
					print_price = (area * canvas_paper) + base_canvas;
				}
				
				var total_price = (print_price + mount_price)*copies*1.14;
				var nice_price = Math.round(total_price);	

				return nice_price;			
			}


			function rounder(num){
				num = num.toString();
				var split = num.split(".");
				var dec = split[1].substr(0,3);
				var dec1 = dec.match(/\d{2,2}/);
				var dec2 = dec.match(/(\d$)/);
				var rounded = (dec1 + "." + dec2[0]);
				return split[0] + "." + Math.round(rounded);
			} 




			function findPosn(obj) {
				var curleft = curtop = 0;
				obj = document.getElementById(obj);
				if (obj.offsetParent) {	
					do {
						curleft += obj.offsetLeft;
						curtop += obj.offsetTop;
					} while (obj = obj.offsetParent);
				}
				return [curleft,curtop];
			}
	


			// "select size" functions ---------------------------------------------------------------------------------------------
			
			var cur_size_el = '';
			var cur_cust_size_el = '';
			
			function choose_size(el) {
				if (cur_product_el != '') { cur_product_el = el; choose_product(el); }
				if (cur_copies_el != '') { cur_copies_el = el; choose_copies(el); }
				
				var eln = 'size' + el;
				var posn = findPosn(eln);
				var t = posn[1] + 101;
				if (cur_size_el == el) { 
					opacity('choose_size', 100, 0, 300);
					window.setTimeout('document.getElementById("choose_size").style.display = "none"', 305);
					cur_size_el = ''; 
				} else {
					document.getElementById('choose_size').style.left = posn[0] + "px";
					document.getElementById('choose_size').style.top = t + "px";
					setOpacity(0, "choose_size");
					opacity('choose_size', 0, 100, 200); 
					cur_size_el = el; cur_cust_size_el = el;
				}
			}
			
			function select_size(sz) {
				if (sz == "a0") { 	wid = 1189; 	hgt = 841; }
				if (sz == "a1") { 	wid = 841; 		hgt = 594; }
				if (sz == "a2") { 	wid = 594; 		hgt = 420; }
				if (sz == "a3") { 	wid = 420; 		hgt = 297; }
				if (sz == "a4") { 	wid = 297; 		hgt = 210; }
				if (sz == "a5") { 	wid = 210; 		hgt = 149; }
				if (sz == "a6") { 	wid = 149; 		hgt = 105; }
				if (sz == "custom") { 	wid = document.getElementById("size_w_"+cur_size_el).value;	hgt = document.getElementById("size_h_"+cur_size_el).value; }
			
				var eln = 'size_' + cur_size_el;
					document.getElementById(eln).value = sz;
				var eln = 'size_w_' + cur_size_el;
					document.getElementById(eln).value = wid;
				var eln = 'size_h_' + cur_size_el;
					document.getElementById(eln).value = hgt;
				
				var eln2 = 'pic_size' + cur_size_el;
				document.getElementById(eln2).src = 'images/size_big_' + sz + '.gif';
				
				//opacity('choose_size', 100, 0, 300); 
				pricer(cur_size_el);
				choose_size(cur_size_el);
				//cur_size_el = '';

				if (sz == "custom") { get_custom_size(); }
			}
			





			function get_custom_size() {
				document.getElementById("grn").style.display = "";
				var sz = getPageSize();
				var posn = findPosn("footer");
				var t = posn[1] + 377;
				document.getElementById("grn").style.height = t + "px";
				changeOpac(50, 'grn');
				
				var eln = 'size' + cur_cust_size_el;
				var posn = findPosn(eln);
				var t = posn[1] + 101;

				document.getElementById('cs').style.left = posn[0] + "px";
				document.getElementById('cs').style.top = t + "px";
				
				document.getElementById('cs_w').value = document.getElementById('size_w_'+cur_cust_size_el).value;
				document.getElementById('cs_h').value = document.getElementById('size_h_'+cur_cust_size_el).value;

				document.getElementById("cs").style.display = "";
			}
			
			function go_custom() {
				var fail=false;
				var x = document.getElementById("cs_w").value;
				var anum=/(^\d+$)|(^\d+\.\d+$)/
				if (!anum.test(x)) { fail=true; }
				var x = document.getElementById("cs_h").value;
				if (!anum.test(x)) { fail=true; }
				
				if (fail) {
					alert("only numbers, please");
				} else {
					if (document.getElementById("cs_w").value > 1100 && document.getElementById("cs_h").value > 1100) {
						alert("PrintWild can print your image any length, as long as the width is 1.1m or smaller.\nPlease ensure one of your dimensions is smaller than 1100mm");
					} else {
						var eln = 'size_w_' + cur_cust_size_el;
						document.getElementById(eln).value = document.getElementById("cs_w").value;
						var eln = 'size_h_' + cur_cust_size_el;
						document.getElementById(eln).value = document.getElementById("cs_h").value;
						pricer(cur_cust_size_el);
						document.getElementById("grn").style.display = "none";
						document.getElementById("cs").style.display = "none";
					}
				}
				
			}


			function getPageSize(){
				
				var xScroll, yScroll;
				
				if (window.innerHeight && window.scrollMaxY) {	
					xScroll = document.body.scrollWidth;
					yScroll = window.innerHeight + window.scrollMaxY;
				} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
					xScroll = document.body.scrollWidth;
					yScroll = document.body.scrollHeight;
				} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
					xScroll = document.body.offsetWidth;
					yScroll = document.body.offsetHeight;
				}
				
				var windowWidth, windowHeight;
				if (self.innerHeight) {	// all except Explorer
					windowWidth = self.innerWidth;
					windowHeight = self.innerHeight;
				} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
					windowWidth = document.documentElement.clientWidth;
					windowHeight = document.documentElement.clientHeight;
				} else if (document.body) { // other Explorers
					windowWidth = document.body.clientWidth;
					windowHeight = document.body.clientHeight;
				}	
				
				// for small pages with total height less then height of the viewport
				if(yScroll < windowHeight){
					pageHeight = windowHeight;
				} else { 
					pageHeight = yScroll;
				}
			
				// for small pages with total width less then width of the viewport
				if(xScroll < windowWidth){	
					pageWidth = windowWidth;
				} else {
					pageWidth = xScroll;
				}
			
			
				arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
				return arrayPageSize;
			}





			
			
			// "select product" functions ---------------------------------------------------------------------------------------------
			
			var cur_product_el = '';
			
			function choose_product(el) {
				if (cur_size_el != '') { cur_size_el = el; choose_size(el); }
				if (cur_copies_el != '') { cur_copies_el = el; choose_copies(el); }

				var eln = 'product' + el;
				var posn = findPosn(eln);
				var t = posn[1] + 101;
				if (cur_product_el == el) { 
					opacity('choose_product', 100, 0, 300); 
					window.setTimeout('document.getElementById("choose_product").style.display = "none"', 305);
					cur_product_el = ''; 
				} else {
					var l = posn[0] - 30;
					document.getElementById('choose_product').style.left = l + "px";
					document.getElementById('choose_product').style.top = t + "px";
					setOpacity(0, "choose_product");
					opacity('choose_product', 0, 100, 200); 
					cur_product_el = el; 
				}
			}
			
			function select_product(sz) {
				var eln = 'product_' + cur_product_el;
				document.getElementById(eln).value = sz;
				var eln2 = 'pic_product' + cur_product_el;
				document.getElementById(eln2).src = 'images/prod_' + sz + '.jpg';
				
				//opacity('choose_product', 100, 0, 300); 
				pricer(cur_product_el);
				choose_product(cur_product_el);
				//cur_product_el = ''; 
			}



			// "select copies" functions ---------------------------------------------------------------------------------------------
			
			var cur_copies_el = '';
			
			function choose_copies(el) {
				if (cur_product_el != '') { cur_product_el = el; choose_product(el); }
				if (cur_size_el != '') { cur_size_el = el; choose_size(el); }
				
				var eln = 'copies' + el;
				var posn = findPosn(eln);
				var t = posn[1] + 101;
				if (cur_copies_el == el) { 
					opacity('choose_copies', 100, 0, 300); 
					window.setTimeout('document.getElementById("choose_copies").style.display = "none"', 305);
					cur_copies_el = ''; 
				} else {
					document.getElementById('choose_copies').style.left = posn[0] + "px";
					document.getElementById('choose_copies').style.top = t + "px";
					setOpacity(0, "choose_copies");
					opacity('choose_copies', 0, 100, 200); 
					cur_copies_el = el; 
				}
			}
			
			function select_copies(sz) {
				var eln = 'copies_' + cur_copies_el;
				document.getElementById(eln).value = sz;
				var eln2 = 'pic_copies' + cur_copies_el;
				document.getElementById(eln2).src = 'images/copies_' + sz + '.gif';
				
				//opacity('choose_copies', 100, 0, 300); 
				pricer(cur_copies_el);
				choose_copies(cur_copies_el);
				//cur_copies_el = ''; 
			}
			
			
			

			
			
			
			
			