// JavaScript Document
// Script - pbcm.js

<!-- ***************************************************************************************************************** -->
// Licence Agreement Checkbox
<!-- ***************************************************************************************************************** -->
function checkTermsBox(ver) {
	var msg;

	if(ver == "pdf") {
		if(document.orderForm.termsCHK.checked) {
			return true;
		} else {
			msg = "Please check the box to confirm that you accept the e-book Terms of Purchase.";
			alert(msg);
			return false;
		}
	}
	
}

<!-- ***************************************************************************************************************** -->
// Open Licence Agreement Window
<!-- ***************************************************************************************************************** -->
function openEbookTermsWin() {
	//alert(action);
	var w = "780";
	var h = "660";
	var x = "200";
	var y = "200";
	var URL = "ebookTerms.html";
	var attribs;
	attribs = "width=" + w + ",height=" + h + ",";
	attribs += "channelmode=0,dependent=0,directories=0,fullscreen=0,";
	attribs += "location=0,menubar=0,resizable=1,scrollbars=1,status=0,toolbar=0";
	termsPopupWin = window.open( URL, "termsPopupWin", attribs);
	termsPopupWin.focus();
}

<!-- ***************************************************************************************************************** -->
// Submit Manual Code Entry
<!-- ***************************************************************************************************************** -->
function submitCode() {
	var URL;
	
	URL = 'PracticalBusinessContinuityManagementBookOnlineOrder.php?promoCode=' + document.getElementById("codeBox").value;
	URL = URL + "&qty=" + document.getElementById("quantity").value;
	URL = URL + "&post=" + document.getElementById("post").value;
	URL = URL + "&version=" + document.getElementById("ver").value;
	this.location.replace(URL);	
}
	
<!-- ***************************************************************************************************************** -->
// Handle a change in the required version
<!-- ***************************************************************************************************************** -->
function versionChange(v) {
	
	var URL;
	URL =  'PracticalBusinessContinuityManagementBookOnlineOrder.php?version=' + v;
	if(document.getElementById("codeBox").value) {
		URL = URL + '&promoCode=' + document.getElementById("codeBox").value;
	}
	this.location.replace(URL);	
}
	
<!-- ***************************************************************************************************************** -->
// Handle Changes to Shopping Basket
<!-- ***************************************************************************************************************** -->
function updateBasket() {
	
	var qty;
	var unitPrice = document.orderForm.unitPrice.value;
	var discount = document.orderForm.discount.value;
	var unitPostage;

	var plusQTY;
	var plusPostage;
	
	var totGoods;
	var totPostage;
	var total;
	
	var postCode;
	
	// Get Quantity
	qty = document.orderForm.quantity.value;
	qty = Math.round(qty);
	document.orderForm.quantity.value = qty;

	// Discount
	totDiscount = ( qty * discount );
	totDiscount = totDiscount.toFixed(2);

	// Goods
	totGoods = ( qty * unitPrice );
	totGoods = totGoods.toFixed(2);

	// Get Unit Postage Price
	for (var i=0; i < document.orderForm.postage.length; i++) {
		if (document.orderForm.postage[i].checked) {
			unitPostage = document.orderForm.postage[i].value;
			if (i == "0") postCode = "uk";
			if (i == "1") postCode = "over";
			document.getElementById("post").value = postCode;
		}
	}	
	
	// Postage
	totPostage = Number(unitPostage);
	if(qty > 1) {
		plusQTY = Number(qty - 1);
		plusPostage = Number(plusQTY) * Number(unitPostage / 2);
		totPostage = Number(totPostage) + Number(plusPostage);		
	}
	totPostage = totPostage.toFixed(2);
	
	// Total
	total = ( Number(totGoods) + Number(totPostage));
	total = total.toFixed(2);
	
	// Debug
	msg = "Recalculate Clicked\n"
	msg = msg + "Quantity = " + qty + "\n";
	msg = msg + "Unit Price = " + unitPrice + "\n";
	msg = msg + "Unit Postage = " + unitPostage + "\n";
	msg = msg + "Goods = " + totGoods + "\n";
	msg = msg + "Postage = " + totPostage + "\n";
	msg = msg + "Total = " + total + "\n";
		
//	alert(msg);

	// IE
	if(document.all) {
		document.getElementById("goodsValue").innerText = totGoods;

		if(discount = document.orderForm.discount.value != 0) {
			document.getElementById("discountValue").innerText = totDiscount;
		}

		document.getElementById("postageValue").innerText = totPostage;
		document.orderForm.shipping.value = totPostage;
		
		document.getElementById("totalValue").innerText = total;
	// Firefox
	} else {
		document.getElementById("goodsValue").textContent = totGoods;
	
		if(discount = document.orderForm.discount.value != 0) {
			document.getElementById("discountValue").textContent = totDiscount;
		}

		document.getElementById("postageValue").textContent = totPostage;
		document.orderForm.shipping.value = totPostage;
		
		document.getElementById("totalValue").textContent = total;
	}


	// Don't submit the form
	return false;

}


