
function quoteToggleCover() {

	if( document.PriceCalc.UseB.value == 0 ){
		//alert("--A--");
		document.getElementById("coverElem1").style.display = "none";
		document.getElementById("coverElem2").style.display = "none";
		document.getElementById("coverElem3").style.display = "none";
		document.getElementById("coverElem4").style.display = "none";
		document.getElementById("coverElem5").style.display = "none";
	}else{
		//alert("--B--");
		document.getElementById("coverElem1").style.display = "block";
		document.getElementById("coverElem2").style.display = "block";
		document.getElementById("coverElem3").style.display = "block";
		document.getElementById("coverElem4").style.display = "block";
		document.getElementById("coverElem5").style.display = "block";
	}
}

function actionQuote() {
	var BookQty
	var innerThick, coverThick, stockThick
	var bindThick

	// set variables related to binding limits
	bindThick = bindingThickness( document.PriceCalc.Extra2.value );

	if( document.PriceCalc.UseB.value == 1 ) {
		innerThick = sheetThickness( document.PriceCalc.StockA.value, (document.PriceCalc.PageQty.value-1) );
		coverThick = sheetThickness( document.PriceCalc.StockB.value, document.PriceCalc.PageQty.value );
	} else {
		innerThick = sheetThickness( document.PriceCalc.StockA.value, document.PriceCalc.PageQty.value );
		coverThick = 0;
	}
	stockThick = innerThick+coverThick;

	// only user-supplied data is book quantity, so validate it
	//  before we attempt to proceed
	BookQty = parseInt( document.PriceCalc.BookQty.value );

	if( isNaN( BookQty ) ){
		alert("Please enter the number of books required");
		document.PriceCalc.BookQty.focus();
	}else if( BookQty <= 0 ){
		alert("Please enter the number of books required");
		document.PriceCalc.BookQty.focus();
	}else if( document.PriceCalc.PageQty.value == 1 && document.PriceCalc.UseB.value == 1 ){
		alert("Cannot specify a different cover for a book only containing one sheet of stock.");
	}else if( bindThick > 0 && stockThick > bindThick ) {
		bindingMessage( stockThick );
	}else if( document.PriceCalc.JobName.value.length == 0 ){
		alert("Please enter a job name for your own reference\r\nthis will help you identify individual jobs later on.");
		document.PriceCalc.JobName.focus();
	}else if( document.PriceCalc.JobOrderRef.value == "" && document.PriceCalc.forcePO.value == "Y" ){
		alert("Please supply a purchase order reference, you\r\ncan change your PO reference later on if required.");
		document.PriceCalc.JobOrderRef.focus();
	}else{
		if( document.PriceCalc.loginPrice.value == "Y" ) {
			document.PriceCalc.submit();
		} else {
			document.PriceCalc.Username.focus();
			alert("Please login before building a full quote, dont worry -\r\nyour current quote will still be here when you get back.");
		}
	}
}

function actionLogin() {
	
	// check required fields
	if( document.PriceCalc.Username.value.length == 0 && document.PriceCalc.Password.value.length == 0 ){
		alert( "Please enter your username and password before logging in." );
		document.PriceCalc.Username.focus();
	}else if( document.PriceCalc.Username.value.length == 0 ){
		alert( "Please enter your username before logging in." );
		document.PriceCalc.Username.focus();
	}else if( document.PriceCalc.Password.value.length == 0 ){
		alert( "Please enter your password before logging in." );
		document.PriceCalc.Password.focus();
	}else{
		document.PriceCalc.mode.value = "login";
		document.PriceCalc.action = "core.asp";
		document.PriceCalc.submit();	
	}
}

function actionRegister() {
		document.PriceCalc.mode.value = "preregister";
		document.PriceCalc.submit();	
}

function actionUpload(){
	document.PriceCalc.mode.value = "upload";
	document.PriceCalc.submit();
}

function actionSearch(){
	document.location.href = "search.asp";
}

document.PriceCalc.JobName.focus();
