window.onload = function() 
{
	var aRefineButton = document.getElementById('RefineButton');
	if (aRefineButton != null) aRefineButton.style.display = 'none';

	if (document.getElementById)
	{
		/* Associate logo's onclick event with home page */
		var logo = document.getElementById("logo");
		if (logo != null)
		{
			logo.onclick = function() 
			{
				window.location = 'index.php';
				return false;
			}
		}

		
		aLinks = document.getElementsByTagName("a");
		for (aIndex = 0; aIndex < aLinks.length; aIndex++)
		{
//			if ((aLinks[aIndex].href.indexOf('http://www.e-shopfair.co.uk') == -1) && (aLinks[aIndex].href.indexOf('http://www.eshopfair.co.uk') == -1) && (aLinks[aIndex].href.indexOf('http://www.eshopfair.com') == -1) && (aLinks[aIndex].href.indexOf('http://www.e-shopfair.com') == -1) && (aLinks[aIndex].href.indexOf('http://www.fashionbrand.co.uk') == -1))
			if (aLinks[aIndex].href.indexOf('http://www.fashionbrand.co.uk') == -1)
			{
				aLinks[aIndex].target = '_blank';
			}
		}		

		var aRefineCategorySelect = document.getElementById('SubCategoryID');
		if (aRefineCategorySelect != null) 
		{
			aRefineCategorySelect.onchange = JSFnRefreshCategoryList;
		}

		var aContactForm = document.getElementById('ContactForm');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;

		var aRatingForm = document.getElementById('RatingForm');
		if (aRatingForm != null) aRatingForm.onsubmit = JSFnValidateRatingForm;

		var aCommentsForm = document.getElementById('CommentsForm');
		if (aCommentsForm != null) aCommentsForm.onsubmit = JSFnValidateCommentsForm;

		var aCommentsForm2 = document.getElementById('CommentsForm2');
		if (aCommentsForm2 != null) aCommentsForm2.onsubmit = JSFnValidateCommentsForm2;

		var aLoginForm = document.getElementById('LoginForm');
		if (aLoginForm != null) aLoginForm.onsubmit = JSFnValidateLoginForm;

		var aUserLoginForm = document.getElementById('UserLoginForm');
		if (aUserLoginForm != null) aUserLoginForm.onsubmit = JSFnValidateUserLoginForm;

		var aPasswordForm = document.getElementById('PasswordForm');
		if (aPasswordForm != null) aPasswordForm.onsubmit = JSFnValidatePasswordForm;

		var aRegisterForm = document.getElementById('RegisterForm');
		if (aRegisterForm != null) aRegisterForm.onsubmit = JSFnValidateRegisterForm;

		var aMailingListForm = document.getElementById('MailingListForm');
		if (aMailingListForm != null) aMailingListForm.onsubmit = JSFnValidateMailingListForm;

		var aMailingListForm2 = document.getElementById('MailingListForm2');
		if (aMailingListForm2 != null) aMailingListForm2.onsubmit = JSFnValidateMailingListForm2;
	}	
}

function addbookmark()
{
	bookmarkurl="http://www.e-shopfair.co.uk/index.php"
	bookmarktitle="E-Shop Fair"
	if (document.all)
	window.external.AddFavorite(bookmarkurl,bookmarktitle)
}

function JSFnRefreshCategoryList()
{
	var aRefineCategory = document.getElementById('refinecategory');
	if (aRefineCategory != null) aRefineCategory.submit();

}
/* Validate the Contact Form: Fields */
var aContactRequiredFields = new Array ("Name","Please enter your name to continue",
									 	 "EmailAddress","Please enter your email address to continue");
/* Validate the Contact Form: Function */
function JSFnValidateContactForm()
{
	var aContactForm = JSFnValidateForm(aContactRequiredFields);
	
	if(aContactForm == true)
	{
		if (this.Code.value != 'JJ67FES')
		{
			alert("Please enter the correct code");
			aContactForm = false;
		}
	}

	return aContactForm;
}

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

/* Validate the Comments Form: Fields */
var aCommentsRequiredFields = new Array ("Details","Please enter a review to continue",
									 	 "Name","Please enter your name to continue");
/* Validate the Comments Form: Function */
function JSFnValidateCommentsForm()
{
	return JSFnValidateForm(aCommentsRequiredFields);
}

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

/* Validate the Comments2 Form: Fields */
var aComments2RequiredFields = new Array ("Details","Please enter a review to continue");
/* Validate the Comments Form: Function */
function JSFnValidateCommentsForm2()
{
	return JSFnValidateForm(aComments2RequiredFields);
}

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

/* Validate the Rating Form: Fields */
var aRatingRequiredFields = new Array ("SiteDesign","Please rate the site design to continue",
									   "SiteContent","Please rate the site content to continue",
									   "CustomerService","Please rate the customer service to continue",
									   "Delivery","Please rate the delivery to continue")
/* Validate the Rating Form: Function */
function JSFnValidateRatingForm()
{
//	return JSFnValidateRadioForm(aRatingRequiredFields);
}

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

/* Validate the Login Form: Fields */
var aLoginRequiredFields = new Array ("username","Please enter a username to continue",
									  "pss","Please enter a password to continue");
/* Validate the Login Form: Function */
function JSFnValidateLoginForm()
{
	return JSFnValidateForm(aLoginRequiredFields);
}

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

/* Validate the User Login Form: Fields */
var aUserLoginRequiredFields = new Array ("username2","Please enter a username to continue",
									      "pss2","Please enter a password to continue");
/* Validate the User Login Form: Function */
function JSFnValidateUserLoginForm()
{
	return JSFnValidateForm(aUserLoginRequiredFields);
}

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

/* Validate the Password Form: Fields */
var aPasswordRequiredFields = new Array ("FullName","Please enter your full name to continue",
									  "MerchantName","Please enter your merchant name to continue");
/* Validate the Login Form: Function */
function JSFnValidatePasswordForm()
{
	return JSFnValidateForm(aPasswordRequiredFields);
}

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

/* Validate the Register Form: Fields */
var aRegisterRequiredFields = new Array ("FirstName","Please enter your first name to continue",
										 "Surname","Please enter your surname to continue",
										 "CompanyName","Please enter company name to continue",
										 "AddressLine1","Please enter address line 1 to continue",
										 "AddressLine2","Please enter address line 2 to continue",
										 "Postcode","Please enter a postcode to continue",
										 "TelephoneNo","Please enter a telephone number to continue",
										 "Email","Please enter an email address to continue",
										 "WebAddress","Please enter a web address to continue",
										 "Terms","Please tick to confirm you have read and understood the terms and conditions");
/* Validate the Register Form: Function */
function JSFnValidateRegisterForm()
{
	var aRegisterForm = JSFnValidateForm(aRegisterRequiredFields);
	
	if(aRegisterForm == true)
	{
		if (this.Code.value != 'JJ67FES')
		{
			alert("Please enter the correct code");
			aRegisterForm = false;
		}
	}

	return aRegisterForm;
}

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


/* Validate the Mailing List Form: Fields */
var aMailingList2RequiredFields = new Array ("FirstName","Please enter your first name to continue",
											"Surname","Please enter your surname to continue",
											"EmailAddress","Please enter an email address to continue",
											"terms","Please tick this box to confirm you have read the privacy policy");

/* Validate the Mailing List Form: Function */
function JSFnValidateMailingListForm2()
{
	var aMailingListForm = JSFnValidateForm(aMailingList2RequiredFields);
	
	if(aMailingListForm == true)
	{
		if (this.Code.value != '8')
		{
			alert("Please enter the result for 1+1+4+2");
			aMailingListForm = false;
		}
	}

	return aMailingListForm;
}

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


/* Validate the Mailing List Form2: Fields */
var aMailingListRequiredFields = new Array ("FullName","Please enter your name to continue",
											"EmailAddress","Please enter an email address to continue");

/* Validate the Mailing List Form2: Function */
function JSFnValidateMailingListForm()
{
	return JSFnValidateForm(aMailingList2RequiredFields);
}

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


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;
}

function JSFnValidateRadioForm(aRequiredFields)
{
	for (aIndex = 0; aIndex < aRequiredFields.length; aIndex = aIndex + 4)
	{
		currElement = document.getElementById(aRequiredFields[aIndex]);
		if (currElement != null)
		{
			if (currElement.type == 'radio')
			{
				aIndex = aIndex + 4;
				if (!currElement.checked)
				{
					currElement = document.getElementById(aRequiredFields[aIndex]);
					if ((currElement.type == 'radio') && (!currElement.checked))
					{
						alert(aRequiredFields[aIndex + 1]);
						return false;
					}
				}
			}
		}
	}
	return true;
}
