// JavaScript Document
function buildeaddresses () {
        buildeaddresses2("amail1","Enquiries","info","chocolatsbelges",".com");
	buildeaddresses2("amail2","Returns","returns","chocolatsbelges",".com");
        buildeaddresses2("amaildc1","The Datacontroller","datacontroller","chocolatsbelges",".com");
        buildeaddresses2("amaildc2","The Datacontroller","datacontroller","chocolatsbelges",".com");
        buildeaddresses2("amaildc3","The Datacontroller","datacontroller","chocolatsbelges",".com");
}
function buildeaddresses2 (id,alias,who,whereat1,whereat2) {
	// if alias is omitted, it is assign the full email address
	// all other values are mandatory
	// the html bit should look like this <a href="" id="amail1"></a>
	if (document.getElementById(id)) {
		eaddress = who + "@" + whereat1 + whereat2;
		elink = "mailto:" + eaddress;

		node1 = document.getElementById(id);
		node1.setAttribute("href",elink);

		if (alias == "") {
			alias = eaddress;
		}
		node2 = document.createTextNode(alias);
		node1.appendChild(node2);
	}
}
function checkcartquantity () {
	totalitems=0;
	for (i=0;i<document.forms.namedItem("cart_quantity").elements.length;i++) {
		if (document.forms.namedItem("cart_quantity").elements[i].name.search('cart_quantity') != -1) { //store the element number for later
			totalitemselement=i;
		}
		if ((document.forms.namedItem("cart_quantity").elements[i].name.search('id') != -1) //if the input name has id in it
		&& (document.forms.namedItem("cart_quantity").elements[i].type == "text")) {
			if (document.forms.namedItem("cart_quantity").elements[i].value != "") {
				totalitems+=parseInt(document.forms.namedItem("cart_quantity").elements[i].value);
			}
		}
	}
	if (totalitems == 0) {
		alert("Please fill in the boxes with how many of each type you would like");
		return false;
	}
	if (((totalitems/3)-(Math.floor(totalitems/3))) != 0) { //not a multiple of 3
		alert("The total number of items is "+totalitems+".\nPlease make it a multiple of 3.");
		return false;
	} else {
		document.forms.namedItem("cart_quantity").elements[totalitemselement].value=totalitems/3;
		return true;
	}
}
