// JavaScript Document

function toPoundsPence(n) {
	var s = "" + Math.round(n * 100) / 100
	var i = s.indexOf('.')
	if (i < 0) return s + ".00"
	var t = s.substring(0, i + 1) + s.substring(i + 1, i + 3)
	if (i + 2 == s.length) t += "0"
	return t
}

function updateTotal() {
	
	var qty2
	qty2 = document.getElementById("txtquantity").value;
	if (basePrice.indexOf(",") > -1) {
		basePrice = parseFloat(basePrice.replace(",",""));
	}
	optionCost = parseFloat(optionCost);
	colourCost = parseFloat(colourCost);
	qty = qty2;
	qty = parseInt(qty);

	var bitch
	bitch = ((parseFloat(basePrice)+parseFloat(colourCost)+parseFloat(optionCost))*qty);
	bitch = '£' + bitch;
	//document.getElementById("totalPrice").innerHTML = "£" + toPoundsPence((basePrice+optionCost+colourCost)*qty);
	document.getElementById("totalPrice").innerHTML = "£" + ((parseFloat(basePrice)+parseFloat(colourCost)+parseFloat(optionCost))*qty);
}

function changeTotal(frmObject) {
	qty = frmObject[frmObject.selectedIndex].value;
	updateTotal();
}

function optionCostFunc(obj) {
	optionCost = obj.options[obj.selectedIndex].title;
	optionCost = optionCost.replace("£","");
	optionCost = optionCost.replace(" extra","");
	updateTotal();
}

function colourCostFunc(obj) {  
	colourCost = obj.title;
	colourCost = colourCost.replace("£","");
	colourCost = colourCost.replace(" extra","");
	updateTotal();
} 

function showTerms(location, strTitle){
	newWindow = window.open(location,'newWin','scrollbars=yes,width=630,height=400') 
	//newWindow.document.write("<HTML><HEAD><TITLE>" + strTitle + "</TITLE></HEAD><BODY bgcolor='#FFFFFF' text='#000000'><DIV ALIGN='center'><IMG SRC=" + imgLocation + "></DIV></BODY></HTML> ") 
	newWindow.document.close 
} 
function newPopupWindow(imgLocation, strTitle){
	newWindow = window.open('','newWin','scrollbars=yes,width=630,height=400') 
	newWindow.document.write("<HTML><HEAD><TITLE>" + strTitle + "</TITLE></HEAD><BODY bgcolor='#FFFFFF' text='#000000'><DIV ALIGN='center'><IMG SRC=" + imgLocation + "></DIV></BODY></HTML> ") 
	newWindow.document.close 
} 
function termsc() {
  if (document.form2.terms.checked) {
    //window.open('','checkout','resizable=no,status=yes,height=400,width=600,toolbar=no,scrollbars=yes,copyhistory=no').focus();
    //location='thankyou.asp';
  } else {
    alert('Please read and accept our terms & conditions');
  }
  return document.form2.terms.checked;
}

function showDelivery(whichLayer)
{
	if (document.getElementById) {
		var style = document.getElementById(whichLayer).style;
		style.display = style.display? "":"none";
	} else if (document.all) {
		var style = document.all[whichLayer].style;
		style.display = style.display? "":"none";
	} else if (document.layers) {
		var style = document.layers[whichLayer].style;
		style.display = style.display? "":"none";
	}
}

