var showingShipAddr = false;
var emailMe = false;

function toggleShipAddr(id)
{
	var elem = document.getElementById(id)
	if (!elem)
	{
		alert(id+" not found");
		return;
	}
	
	if (elem.innerHTML == "")
		showShipAddr(elem);
	else
		hideShipAddr(elem);
}

function showShipAddr(elem)
{
	var shippingAddr = "";
	
	shippingAddr += '<table border="0" style="text-align: right;">';
	shippingAddr += '\n<tbody><tr bgcolor="#ffffff"><td align="left" nowrap="nowrap"><label style="margin: 2px;">Ship to Name</label></td>';
	shippingAddr += '<td align="left"><input style="font-size: 9pt;color:#000000;" name="xxxShippingName" size="15" type="text" /></td></tr>';
	shippingAddr += '\n<tr bgcolor="#ffffff"><td align="left" nowrap="nowrap"><label style="margin: 2px;">Ship to Address<br />(include Country)</label></td>';
	shippingAddr += '<td align="left"><textarea style="font-size: 9pt;color:#000000;" rows="5" cols="20" name="xxxShippingAddress"></textarea></td></tr>';
	shippingAddr += '\n</tbody></table>';
	
	shippingAddr += '<p>You will be asked for your billing address in the next step -- please ensure you have correctly entered the address you would like the items shipped.</p>';
	
	var submitButton = document.getElementById('submit');
	if (submitButton)
		submitButton.onclick = verifyShipAddr;
	
	elem.innerHTML = shippingAddr;
	elem.style.display = "block";
	
	showingShipAddr = true;
}

function hideShipAddr(elem)
{
	var submitButton = document.getElementById('submit');
	if (submitButton)
		submitButton.onclick = null;
	
	elem.innerHTML = "";
	elem.style.display = "none";

	showingShipAddr = false;
}

function verifyShipAddr(e)
{
	if (showingShipAddr)
	{
		return confirm("Please confirm you have entered the Ship To information correctly?");
	}
	else if (emailMe)
	{
		return confirm("Please confirm you are happy for us to contact you occasionally with our email newsletter");
	}
}

function toggleEmailMe()
{
	var ty = document.getElementById('thankyou');
	var x2 = document.getElementById('xxxVar2');
	emailMe = (emailMe?false:true);

	if (ty)
	{
		ty.style.display = (emailMe?"inline":"none");
	}
	if (x2)
	{
		if (emailMe)
			x2.value = "Please sign me up for your email newsletter";
		else
			x2.value = "";
	}
}

