function toggleStock(){
	var StickerStock = document.getElementById("StickerStock");
	var SignStock = document.getElementById("SignStock");
	var finishingRow = document.getElementById("finsihingRow");
				
	if(document.getElementById("Sticker/label").checked){
		StickerStock.style.display = '';
		SignStock.style.display = 'none';
		finishingRow.display = 'none';
	}else if(document.getElementById("Sign").checked){
		StickerStock.style.display = 'none';
		SignStock.style.display = '';
		finishingRow.display = 'none';
	}else {
		StickerStock.style.display = 'none';
		SignStock.style.display = 'none';
		finishingRow.display = '';
	}
}

function updateQuoteDetails(){
	updateQuoteQty();
	updateQuoteDescription();
	updateQuoteCosts();
	showHideCheckoutButton();
}

function showHideCheckoutButton(){
	var minOrderValue = 40;
	var checkoutButton = document.getElementById("Checkout");
	var quoteTotal = parseFloat(document.getElementById("quotetotal").value );
	var minOrder = document.getElementById("minOrder");
	
	if(quoteTotal <= minOrderValue){
		checkoutButton.style.display = 'none';
		minOrder.innerHTML = "<div align='right'>We have a minimum order value of $40.00.<br />You may like to adjust the quantity to meet the minimum value.</div>";		
	}else{
		checkoutButton.style.display = '';
		minOrder.innerHTML = "";
	}
}

function updateQuoteCosts(){
	var finishingCost = 40;
	var itemCost = 0;
	var subtotalCost = 0;
	var GSTCost = 0;
	var GSTRate = 0.1;
	var grandTotalCost = 0;
		
	//identify type of quote to get calculation
	for( i = 0; i < document.InstantQuote.Type.length; i++ )
	{
		if( document.InstantQuote.Type[i].checked == true ){
			type = document.InstantQuote.Type[i].value;
		}
	}
	
	if(type == "Sticker/label" ){
		itemCost = calcStickerPrice();
		//alert("sticker = 0");
		finishingCost = 0;
	}else if (type == "Sign"){
		itemCost = calcSignPrice();
		//alert("sign = 0");
		finishingCost = 0;
	}else{
		finishingCost = 40;
		itemCost = calcBannerPrice();
	}
	
	//add finishing from value above.
	var finishing = document.getElementById("finishingCost");
	finishing.innerHTML = "$"+finishingCost.toFixed(2);
		
	//add subtotal
	subtotalCost = parseFloat(itemCost) + finishingCost;
	var subtotal = document.getElementById("subTotal");
	subtotal.innerHTML = "$"+subtotalCost.toFixed(2);
	//grandTotal, subTotal, GST
	
	//calculate GST
	GSTCost = parseFloat(subtotalCost)*GSTRate;
	var gst = document.getElementById("GST");
	gst.innerHTML = "$"+GSTCost.toFixed(2);
	
	//grand total
	grandTotalCost = GSTCost + subtotalCost;
	var grandTotal = document.getElementById("grandTotal");
	grandTotal.innerHTML = "$"+grandTotalCost.toFixed(2);
	
	//set hidden feilds to send for processing
	var hiddenTotal =  document.getElementById("quotetotal");
	hiddenTotal.value = grandTotalCost.toFixed(2);
	
}

function calcStickerPrice(){
	
	var rate, height, width, individualTotal, total, heightInMetres, widthInMetres, qty;
	rate = height = width = individualTotal = total = heightInMetres = widthInMetres = qty = 0;
	
	var select_list_field = document.getElementById("Type of stock");
	var select_list_selected_index = select_list_field.selectedIndex;
	rate = parseFloat(document.getElementById("Type of stock").value);	
	height = parseFloat(document.getElementById("Height").value);
	width = parseFloat(document.getElementById("Width").value);
	qty = parseInt(document.getElementById("Quantity").value);
	heightInMetres = ((height)+ 5  ) / 1000; //add 5mm then convert to Metres
	widthInMetres = (width +5) / 1000; //add 5mm then convert to metres

	individualTotal = rate * heightInMetres * widthInMetres;
	
	var individaulCost = document.getElementById("individaulCost");
	individaulCost.innerHTML = "$"+individualTotal.toFixed(3);
	
	total = qty * individualTotal;
	var itemCost = document.getElementById("itemCost");
	itemCost.innerHTML = "$"+total.toFixed(2);
	return total;
	
}

function calcSignPrice(){
	var rate, height, width, individualTotal, total, heightInMetres, widthInMetres, qty;
	rate = height = width = individualTotal = total = heightInMetres = widthInMetres = qty = 0;
	
	var select_list_field = document.getElementById("Type of stock2");
	var select_list_selected_index = select_list_field.selectedIndex;
	rate = parseFloat(document.getElementById("Type of stock2").value);	
	height = parseFloat(document.getElementById("Height").value);
	width = parseFloat(document.getElementById("Width").value);
	qty = parseInt(document.getElementById("Quantity").value);
	heightInMetres = height / 1000; //convert to Metres
	widthInMetres = width  / 1000; //convert to metres

	individualTotal = rate * heightInMetres * widthInMetres;
	
	var individaulCost = document.getElementById("individaulCost");
	individaulCost.innerHTML = "$"+individualTotal.toFixed(3);
	
	total = qty * individualTotal;
	var itemCost = document.getElementById("itemCost");
	itemCost.innerHTML = "$"+total.toFixed(2);
	return total;
}

function calcBannerPrice(){
	var rate, height, width, individualTotal, total, heightInMetres, widthInMetres, qty;
	rate = height = width = individualTotal = total = heightInMetres = widthInMetres = qty = 0;

	rate = parseFloat(document.getElementById("bannerRATE").value);	
	height = parseFloat(document.getElementById("Height").value);
	width = parseFloat(document.getElementById("Width").value);
	qty = parseInt(document.getElementById("Quantity").value);
	heightInMetres = height / 1000; //convert to Metres
	widthInMetres = width  / 1000; //convert to metres

	individualTotal = rate * heightInMetres * widthInMetres;
	
	var individaulCost = document.getElementById("individaulCost");
	individaulCost.innerHTML = "$"+individualTotal.toFixed(3);
	
	total = qty * individualTotal;
	var itemCost = document.getElementById("itemCost");
	itemCost.innerHTML = "$"+total.toFixed(2);
	return total;
}

function updateQuoteQty(){
	var qty = document.getElementById("quoteQty");
	qty.innerHTML=document.getElementById("Quantity").value;
	
	//set hidden feilds to send for processing
	var hiddenQty = document.getElementById("quoteQuantity");
	hiddenQty.value = document.getElementById("Quantity").value;
}

function updateQuoteDescription(){
	var description = document.getElementById("quoteDescription");
	//find the currently selected type radio button
	var type, width, height, stock, descriptionText;
	type = width = height = stock = descriptionText = "";

	for( i = 0; i < document.InstantQuote.Type.length; i++ )
	{
		if( document.InstantQuote.Type[i].checked == true )
		type = document.InstantQuote.Type[i].value;
	}
	//Stickers @ 100mm W x 150mm L on Promotional Gloss with UV Laminate Protection.
	descriptionText = type;
	descriptionText +=  " @ ";
	descriptionText += document.getElementById("Width").value;
	descriptionText +=  "mm W ";
	descriptionText += document.getElementById("Height").value;
	descriptionText +=  "mm L";
	//check if stock is required.
	if(document.getElementById("SignStock").style.display != 'none'){
		var select_list_field = document.getElementById("Type of stock2");
		var select_list_selected_index = select_list_field.selectedIndex;

		descriptionText +=  " on ";
		descriptionText += select_list_field.options[select_list_selected_index].text;
		//descriptionText += document.getElementById("Type of stock2").value;		
	} else if(document.getElementById("StickerStock").style.display != 'none'){
		var select_list_field = document.getElementById("Type of stock");
		var select_list_selected_index = select_list_field.selectedIndex;

		descriptionText +=  " on ";
		descriptionText += select_list_field.options[select_list_selected_index].text;
		//descriptionText +=  " on ";
		//descriptionText += document.getElementById("Type of stock").value;		
	}
	
	description.innerHTML=descriptionText;
		
	//set hidden feilds to send for processing
	var hiddenDescription = document.getElementById("quoteItem");
	hiddenDescription.value = descriptionText;


}