window.onload = jsFnOnload;

function jsFnOnload()
{
	if (document.getElementById)
	{	
		var aReceipt = document.getElementById('shoppingcart');
		var aShowReceiptBtn = document.getElementById('showcart');
		var aHideReceiptBtn = document.getElementById('closecart');
		var aCloseReceiptImg = document.getElementById('closereceipt');
		if ((aReceipt != null) && (aShowReceiptBtn != null) && (aHideReceiptBtn != null) && (aCloseReceiptImg != null))
		{
			aShowReceiptBtn.onclick = jsFnShowReceipt;
			aHideReceiptBtn.onclick = jsFnHideReceipt;
			aCloseReceiptImg.onclick = jsFnHideReceipt;
			aCloseReceiptImg.style.cursor = 'pointer';
		}
		
		if ((typeof aShowCart != "undefined") && (aShowCart == true)) aReceipt.style.display = 'block';

		var aImageZoom = document.getElementById('productlink');
		if (aImageZoom != null) aImageZoom.onclick = JSFnImageZoom;


		var aPrint = document.getElementById('Print');
		if (aPrint != null) aPrint.onclick = JSFnPrint;

		var aConfirmForm = document.getElementById('customerdetails');
		if (aConfirmForm != null) aConfirmForm.onsubmit = JSFnValidateConfirmForm;

		var aCheckoutForm = document.getElementById('checkoutform');
		if (aCheckoutForm != null) aCheckoutForm.onsubmit = JSFnValidateCheckout;
		
		var aMailingListForm = document.getElementById('MailingList');
		if (aMailingListForm != null) aMailingListForm.onsubmit = JSFnValidateMailingList;
		
		var aSamplesForm = document.getElementById('SamplesForm');
		if (aSamplesForm != null) aSamplesForm.onsubmit = JSFnValidateSamples;
		
		var aQuoteForm = document.getElementById('QuoteForm');
		if (aQuoteForm != null) aQuoteForm.onsubmit = JSFnValidateQuotes;
		
		var aHangersForm = document.getElementById('HangerForm');
		if (aHangersForm != null) aHangersForm.onsubmit = JSFnValidateHangers;
		
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContact;
		
		var leftcolumn = document.getElementById("content");
		if (leftcolumn != null)
		{
			var aBoxedProducts = leftcolumn.getElementsByTagName("ul");
			for (aBoxIndex = 0; aBoxIndex < aBoxedProducts.length; aBoxIndex++)
			{
				if (aBoxedProducts[aBoxIndex].className == 'boxedproducts')
				{
					var aLIs = aBoxedProducts[aBoxIndex].getElementsByTagName("li");
					for (aLIIndex = 0; aLIIndex < aLIs.length; aLIIndex++)
					{
						var aProductLinks = aLIs[aLIIndex].getElementsByTagName("a");
						for (aProductIndex = 0; aProductIndex < aProductLinks.length; aProductIndex++)
						{
							aAltText = aProductLinks[aProductIndex].innerHTML;
							aLIs[aLIIndex].onclick = JSFnIndexProductLink;
							aLIs[aLIIndex].onmouseover = JSFnIndexProductHover;
							aLIs[aLIIndex].onmouseout = JSFnIndexProductExit;
						}
					}
				}
			}
		}
	}
}
/******************************************************************************************************************************************/
function JSFnImageZoom()
{
	var aWindow = window.open(this.href, 'productbig', 'scrollbars=yes, menubar=no, resizeable=no, toolbar=no, width=600px, height=800px')
	aWindow.focus();
	return false;
}


function JSFnPrint()
{
	window.print();
	return false;
}
/******************************************************************************************************************************************/

function jsFnShowReceipt()
{
	var aReceipt = document.getElementById('shoppingcart');
	aReceipt.style.display = 'block';
	return false;
}

function jsFnHideReceipt()
{
	var aReceipt = document.getElementById('shoppingcart');
	aReceipt.style.display = 'none';
	return false;
}


function JSFnIndexProductLink()
{
	var aProductLinks = this.getElementsByTagName("a");
	for (aProductIndex = 0; aProductIndex < aProductLinks.length; aProductIndex++)
	{
		window.location = aProductLinks[aProductIndex].href; 
	}
	return false;
}

function JSFnIndexProductHover()
{
	this.style.backgroundColor = '#FFF';
	this.style.cursor = 'pointer';
}

function JSFnIndexProductExit()
{
	this.style.backgroundColor = '#eee';
}

var aConfirmRequiredFields = new Array ("CustomerName","Please enter your name to continue",
										"DeliveryAddress", "Please enter a delivery address to continue",
										"DeliveryPostCode","Please enter a delivery postcode to continue",
										"SpecialDelivery","Please select a location to continue",
										"HowToPay","Please select how you wish to pay to continue");
function JSFnValidateConfirmForm()
{
	return JSFnValidateForm(aConfirmRequiredFields);
}

	/********************************/

/* Validate the Mailing List Form: Fields */
var aMailingListRequiredFields = new Array ("Name","Please enter your name to continue",
										    "Email","Please an email address to continue");
/* Validate the Mailing List Form: Function */
function JSFnValidateMailingList()
{
	return JSFnValidateForm(aMailingListRequiredFields);
}

	/********************************/

/* Validate the Samples Form: Fields */
var aSamplesRequiredFields = new Array ("Name","Please enter your name to continue",
									   "Address","Please an address to continue",
									   "SamplesRequired","Please enter details of samples required to continue");
/* Validate the Samples Form: Function */
function JSFnValidateSamples()
{
	var aEmail = document.getElementById('Email');
	var aTelephone = document.getElementById('Telephone');
	
	if ((aEmail != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your email or telephone.');
			return false;
		}
	}

	return JSFnValidateForm(aSamplesRequiredFields);
}

	/********************************/

/* Validate the Quotes Form: Fields */
var aQuotesRequiredFields = new Array ("Name","Please enter your name to continue",
									   "Address","Please an address to continue",
									   "DetailsOfOrder","Please enter details of your order to continue");
/* Validate the Quotes Form: Function */
function JSFnValidateQuotes()
{
	var aEmail = document.getElementById('Email');
	var aTelephone = document.getElementById('Telephone');
	
	if ((aEmail != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your email or telephone.');
			return false;
		}
	}

	return JSFnValidateForm(aQuotesRequiredFields);
}

	/********************************/

/* Validate the Hangers Form: Fields */
var aHangersRequiredFields = new Array ("Name","Please enter your name to continue",
									    "Requirements","Please enter details of your requirements to continue");
/* Validate the Hangers Form: Function */
function JSFnValidateHangers()
{
	var aEmail = document.getElementById('Email');
	var aTelephone = document.getElementById('Telephone');
	
	if ((aEmail != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your email or telephone.');
			return false;
		}
	}

	return JSFnValidateForm(aHangersRequiredFields);
}

	/********************************/

/* Validate the Contact Form: Fields */
var aContactRequiredFields = new Array ("Name","Please enter your name to continue",
									    "Address","Please an address to continue");
/* Validate the Contact Form: Function */
function JSFnValidateContact()
{
	var aEmail = document.getElementById('Email');
	var aTelephone = document.getElementById('Telephone');
	
	if ((aEmail != null) && (aTelephone != null))
	{
		if ((aEmail.value == '') && (aTelephone.value == ''))
		{
			alert('You must provide either your email or telephone.');
			return false;
		}
	}

	var aContactForm = JSFnValidateForm(aContactRequiredFields);

	
	if(aContactForm == true)
	{
		if (this.Code.value != 'TRE457B')
		{
			alert("Please enter the correct code");
			aContactForm = false;
		}
	}

	return aContactForm;
}

	/********************************/



CheckoutRequiredFields = new Array ("terms","You must tick to say that you agree to Euro Office Supplies terms and conditions in order to checkout.");
function JSFnValidateCheckout()
{
	return JSFnValidateForm(CheckoutRequiredFields);
}

function JSFnValidateForm(aRequiredFields)
{
	for (aIndex = 0; aIndex < aRequiredFields.length; aIndex = aIndex + 2)
	{
		currElement = document.getElementById(aRequiredFields[aIndex]);
		if (currElement != null)
		{
			if  (   (   (currElement.type == 'text')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'password')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'checkbox')
				     && (currElement.checked == false))
				 || (   (currElement.type == 'file')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'textarea')
				     && (currElement.value == ''))
				 || (   (currElement.type == 'select-one')
				     && (currElement.value == '')))
			{
				alert(aRequiredFields[aIndex + 1]);
				return false;
			}
			else if (currElement.type == 'radio')
			{
				aIndex = aIndex + 2;
				if (!currElement.checked)
				{
					currElement = document.getElementById(aRequiredFields[aIndex]);
					if ((currElement.type == 'radio') && (!currElement.checked))
					{
						alert(aRequiredFields[aIndex + 1]);
						return false;
					}
				}
			}
		}
	}
	return true;
}

