// JavaScript Document

var gb_Array = {price:38.00, currency:"GBP", tax:" inc VAT + ", format:"PAL", language:"English", postage:2.00};
var us_Array = {price:49.00, currency:"USD", tax:" + ", format:"NTSC", language:"English", postage:6.00};
var ie_Array = {price:35.00, currency:"GBP", tax:" + ", format:"PAL", language:"English", postage:4.00};
var nz_Array = {price:49.00, currency:"USD", tax:" + ", format:"PAL", language:"English", postage:9.00};
var au_Array = {price:49.00, currency:"USD", tax:" + ", format:"PAL", language:"English", postage:9.00};
var eu_Array = {price:35.00, currency:"EUR", tax:" + ", format:"PAL", language:"English", postage:5.00};
var other_Array = {price:39.50, currency:"GBP", tax:" + ", format:"PAL", language:"English", postage:10.00};

function getSymbol(currency){
	switch (currency)
		{
			case "GBP" :
				//return "&pound;";
				return "£"
				break
			case "USD" :
				//return "&#8364;";
				return "US$"
				break
			case "EUR" :
				//return "&#8364;";
				return "€"
				break
			default :
				return null;
				break;
		}
}
//returns the full description made out of the description language and format vars
function getDVDdescription(formObj)
{
	formObj.desc.value = formObj.item_name.value + " Lang:" + formObj.language.value + " Format:" + formObj.format.value;
	//formObj.desc.value = formObj.item_name.value
}


//same as isNAN but works in js1
function myIsNaN(what) 
{
	return (what != ((what - 0) + '')); 
}
//returns a number in currency format
function roundOff(value, precision)
{
	return places(value,1,precision);
}
function places(X, M, N) 
{
	var T, S=new String(Math.round(X*Number("1e"+N)))

	while (S.length<M+N) S='0'+S
	var y = S.substr(0, T=(S.length-N));
	if(N>0) 
	{
		y += '.' + S.substr(T, N);
	}

	return y;
}

<!-- This function addeds the postage and packaging to the total price of the products. Add new postage rates here, and also edit further down the page to add them to the table. -->
function calculateDVDtotals(formObj)
{
	var currentDetails
	
	switch (formObj.country.value)
	{
		case "gb" :
			currentDetails = gb_Array;
			break;
		case "us" :
			currentDetails = us_Array;
			break;
		case "ie" :
			currentDetails = ie_Array;
			break
		case "au" :
			currentDetails = au_Array;
			break
		case "nz" :
			currentDetails = nz_Array;
			break
		case "eu" :
			currentDetails = eu_Array;
			break
		case "other" :
		default :
			currentDetails = other_Array;
			break;
	}
	if(myIsNaN(Number(formObj.quantity.value))) formObj.quantity.value = "1";
	
	formObj.quantity.value = Math.floor(formObj.quantity.value)
	
	if(Number(formObj.quantity.value) < 1) formObj.quantity.value = "1";
	if(Number(formObj.quantity.value) > 5) 
	{
		alert("If you would like to order more than 5 copies, please contact us.");
		formObj.quantity.value = "5";
	}
	formObj.price.value = Number(currentDetails.price)

	formObj.subtotal.value = (Number(currentDetails.price) * Number(formObj.quantity.value)) ;
	
	formObj.postage.value = Number(currentDetails.postage);
	formObj.postageTotal.value = (Number(formObj.postage.value) * Number(formObj.quantity.value)) ;
	
	formObj.total.value = (Number(formObj.subtotal.value) + Number(formObj.postageTotal.value));
	
	formObj.amount.value = roundOff(formObj.total.value,2);
	formObj.taxStr.value = currentDetails.tax;
	formObj.postage.value = getSymbol(currentDetails.currency) + roundOff(formObj.postage.value,2) + " p&p.";
	formObj.postageTotal.value = getSymbol(currentDetails.currency) + roundOff(formObj.postageTotal.value,2);
	formObj.subtotal.value = getSymbol(currentDetails.currency) + roundOff(formObj.subtotal.value,2);
	formObj.total.value = getSymbol(currentDetails.currency) + roundOff(formObj.total.value,2);
	formObj.price.value = getSymbol(currentDetails.currency) + roundOff(formObj.price.value,2);
	
	formObj.currency.value = currentDetails.currency;
	formObj.format.value = currentDetails.format;
	formObj.language.value = currentDetails.language;

	getDVDdescription(formObj);
}

function MM_openBrWindow(theURL,winName,features) { //v2.0
  window.open(theURL,winName,features);
}
