// This mmCalcTotal Function calculates and shows tax/VAT for productpr
// values. mmCheckIfSelected Function checks if product is selected
// and alerts customer if no product is selected before adding to cart

var dbTaxValue = 0.175;
var strCurrency = "£";
var  strAlertCustomer = "Please select a quantity of this product from the dropdown box above before adding it to your shopping cart.";

function mmCalcTotal(that, thatProductPr){

	var strProductPr, strProductPrArray, intProductPrTotal
	var curPriceExVat, curPriceVat, curPriceTotal
	var curPriceExVatTemp, curPriceVatTemp, intMultiProductNumber
	
	var intUserID = "5177736";
	var intFormUserID = that.userid.value;
	
		// Checks userid valid
	if (intFormUserID != intUserID){
		alert("Please use correct User ID "+intUserID);
		return false;
	}
	
	intMultiProductNumber = thatProductPr.name;
	intMultiProductNumber = intMultiProductNumber.replace('productpr','')+'';

	strProductPr = thatProductPr.selectedIndex;
	strProductPr = thatProductPr.options[strProductPr].value;
	strProductPrArray = strProductPr.split(":");
	intProductPrTotal = strProductPrArray.length;

	// Price Ex Vat
	curPriceExVat = strProductPrArray[1]
	curPriceExVat = currency(curPriceExVat);
	
	// Vat
	curPriceVat = currency(curPriceExVat * dbTaxValue);
	
	// Total
	curPriceExVatTemp = curPriceExVat - 0;
	curPriceVatTemp = curPriceVat - 0;
	
	curPriceTotal = currency(curPriceExVatTemp + curPriceVatTemp);

	// Sets form values
	var txtCurPriceExVat = 'curPriceExVat'+intMultiProductNumber
	var txtCurPriceVat = 'curPriceVat'+intMultiProductNumber
	var txtCurPriceTotal = 'curPriceTotal'+intMultiProductNumber

	if (isNaN(curPriceExVat)){curPriceExVat=''};
	if (isNaN(curPriceVat)){curPriceVat=''};
	if (isNaN(curPriceTotal)){curPriceTotal=''};
	
	that.elements[txtCurPriceExVat].value = strCurrency+curPriceExVat;
	that.elements[txtCurPriceVat].value = strCurrency+curPriceVat;
	that.elements[txtCurPriceTotal].value = strCurrency+curPriceTotal;
	
}

function mmCheckIfSelected(that){
	
	if (that.productpr.value==''){
		alert(strAlertCustomer);
		return false;
	}
	return true;
}

function currency(dbAmount) { 
	// returns the amount in the .99 format 
	dbAmount -= 0; 
	dbAmount = (Math.round(dbAmount*100))/100; 
	return (dbAmount == Math.floor(dbAmount)) ? dbAmount + '.00' : ( (dbAmount*10 == Math.floor(dbAmount*10)) ? dbAmount + '0' : dbAmount); 
}