// JavaScript Document
function doDecimals(theNum){
var strNum=theNum.toString();
var lenNum=strNum.length;
var positDot=strNum.indexOf('.');
if (positDot<0){
	strNum=strNum+'.00';
}
if(positDot>0){
	positDot=lenNum-strNum.indexOf('.');
if(positDot==2){
	strNum=strNum+'0';
}
}
return strNum;

}

function doCalc(){
var firstPages=0;
var midPages=0;
var highPages=0;
var totalCost=0;
var tocCost=0;
var tocWords='';
var grandTotal='';
var pages=document.form.pageCount2.value;
var remaining=pages-24;//There are more than 24 pages
var totalStr='';
if(remaining>0){
		firstPages=24;
	}
	else{
		firstPages=pages;
	}
	remaining=remaining-76;
	if(remaining>0){
		midPages=76;
	}
	else{
		midPages=0;
	}
	if (pages>100){
		highPages=pages-100;
	}
	if(pages>3){
		totalCost=25.00 + (firstPages*1.00)+(midPages*0.50) + (highPages*0.25);
		if(document.form.toc.checked){
			tocCost=pages*0.25;
			grandTotal=doDecimals(tocCost+totalCost);
			tocWords=doDecimals(tocCost);
			tocWords=' + Cost of Table of Contents ('+ pages + 'pages @ '+String.fromCharCode(163)+ '0.25) = '+String.fromCharCode(163)+ '' + tocWords + String.fromCharCode(13) + ' =  Total '+String.fromCharCode(163)+ ''+grandTotal;
		}
		totalStr=doDecimals(totalCost);
		return 'Setup '+String.fromCharCode(163)+ '25.00 + ('+firstPages+'pages @ '+ String.fromCharCode(163)+ '1.00) + ('+midPages+'pages @ '+ String.fromCharCode(163)+ '0.50) + ('+highPages+'pages @ '+ String.fromCharCode(163)+ '0.25) = '+String.fromCharCode(163)+ ''+totalStr + String.fromCharCode(13) + tocWords + String.fromCharCode(13) + ' + VAT';
	}	
	else{
		alert("There are not enough pages to make a brochure");
		return '';
	}
	
}
