window.onload = JsFnOnLoad;

var FBasketOkToContinue = true;

function JsFnOnLoad()
{
	var aLinks = document.getElementsByTagName('a');
	for (aIndex = 0; aIndex < aLinks.length; aIndex++)
	{
		if (aLinks[aIndex].className == 'delitem') aLinks[aIndex].onclick = ConfirmDelete;
	}
	
	var aForm = document.getElementById('checkoutfrm1');
	if (aForm != null) aForm.onsubmit = CheckCheckoutForm1;
	
	var aForm = document.getElementById('checkoutfrm2');
	if (aForm != null) aForm.onsubmit = CheckCheckoutForm2;
	
	var aForm = document.getElementById('checkoutfrm3');
	if (aForm != null) setTimeout("GoToEpdq()", 2000);
	
	var aForm = document.getElementById('dldfrm');
	if (aForm != null) 
	{
		aForm.onsubmit = CheckDownloadForm;
		aItemToFocus = aForm.getElementById('email');
		aItemToFocus.focus();
	}
	
	var aBasketForm = document.getElementById('basketform');
	if (aBasketForm != null) 
	{			
		var aLinks = document.getElementsByTagName('a');
		for (aIndex = 0; aIndex < aLinks.length; aIndex++)
		{
			if (aLinks[aIndex].className == 'basketcontinue') aLinks[aIndex].onclick = CheckBasketForm;
		}
				
		var aInputs = aBasketForm.getElementsByTagName('input');
		for (aIndex = 0; aIndex < aInputs.length; aIndex++)
		{
			if (aInputs[aIndex].type == 'text') aInputs[aIndex].onchange = BasketChanged;
		}
	}
}

function BasketChanged()
{
	FBasketOkToContinue = false;
}

function CheckBasketForm()
{
	if (FBasketOkToContinue) return true;
	else return confirm('It appears that you have changed the quantities that you wish to order. If you continue without clicking the Update Basket button you will lose these changes. Press cancel below to return to the form and apply your changes.');
}

function GoToEpdq()
{
	var aForm = document.getElementById('checkoutfrm3');
	if (aForm != null) aForm.submit();
}

function ConfirmDelete()
{
	if (confirm("Delete this item?")) return true;
	else return false;
}

function CheckCheckoutForm1()
{
	var aName = document.getElementById('name');
	var aEst = document.getElementById('est');
	var aTown = document.getElementById('town');
	var aCounty = document.getElementById('county');
	var aEmail = document.getElementById('email');
	
	if(aName.value=='')
	{
		alert("Please enter your name");
		return false;
	}
	else if(aEst.value=='')
	{
		alert("Please enter your address");
		return false;
	}
	else if(aTown.value=='')
	{
		alert("Please enter your town or city");
		return false;
	}
	else if(aCounty.value=='')
	{
		alert("Please enter your county, state or region.");
		return false;
	}
	else if(aEmail.value=='')
	{
		alert("You need to enter a valid email address.");
		return false;
	}
	return true;
}

function CheckCheckoutForm2()
{
	var aName = document.getElementById('bname');
	var aEst = document.getElementById('best');
	var aTown = document.getElementById('btown');
	var aCounty = document.getElementById('bcounty');
	
	if(aName.value=='')
	{
		alert("Please enter your name");
		return false;
	}
	else if(aEst.value=='')
	{
		alert("Please enter your address");
		return false;
	}
	else if(aTown.value=='')
	{
		alert("Please enter your town or city");
		return false;
	}
	else if(aCounty.value=='')
	{
		alert("Please enter your county, state or region.");
		return false;
	}
	return true;
}

function CheckDownloadForm()
{
	var aEmail = document.getElementById('email');
	if(aEmail.value == '')
	{
		alert("You must identify yourself with your email address.");
		return false;
	}
	return true;
}