window.onload = jsFnOnLoad;

function jsFnOnLoad()
{
	if (document.getElementById)
	{
		aProductContent = document.getElementById('content_bottom');
		if (aProductContent != null)
		{
			var aDiv = document.getElementsByTagName("div");
			var aFirst = true;
			if (aDiv != null) 
			{
				for(aDivIndex=0; aDivIndex < aDiv.length; aDivIndex++)
				{
					if(aDiv[aDivIndex].className=='tab')
					{
						if(aFirst) aFirst = false;
						else aDiv[aDivIndex].style.display = 'none';
					}
				}
			}
		}
		
		
		var aContactForm = document.getElementById('contactform');
		if (aContactForm != null) aContactForm.onsubmit = JSFnValidateContactForm;
		
		var aClientRegisterForm = document.getElementById('ClientRegisterForm');
		if (aClientRegisterForm != null) aClientRegisterForm.onsubmit = JSFnValidateClientRegisterForm;
		
		var aClientRegisterForm_2 = document.getElementById('ClientRegisterForm_2');
		if (aClientRegisterForm_2 != null) aClientRegisterForm_2.onsubmit = JSFnValidateClientRegisterForm2;
		
		var aRegisterForm = document.getElementById('RegisterForm');
		if (aRegisterForm != null) aRegisterForm.onsubmit = JSFnValidateRegisterForm;
		
		var aRegisterForm_2 = document.getElementById('RegisterForm_2');
		if (aRegisterForm_2 != null) aRegisterForm_2.onsubmit = JSFnValidateRegisterForm2;
		
		var aRegisterForm_3 = document.getElementById('RegisterForm_3');
		if (aRegisterForm_3 != null) aRegisterForm_3.onsubmit = JSFnValidateRegisterForm3;

		//*** Remove confirm ***********************************************************************************************
		var remove = document.getElementsByTagName("a");
 		if (remove != null) 
		{
			for(aremindex=0;aremindex<remove.length;aremindex++)
			{
				if(remove[aremindex].className=='rem') remove[aremindex].onclick = JSFnRemoveClick;
			}
		}				
		//******************************************************************************************************************

		//*** View HTML doc new window *************************************************************************************
		var viewhtml = document.getElementsByTagName("a");
 		if (viewhtml != null) 
		{
			for(adocindex=0;adocindex<viewhtml.length;adocindex++)
			{
				if(viewhtml[adocindex].className=='viewhtml') viewhtml[adocindex].onclick = JSFnNewWindow;
			}
		}				
	}
}


/* Register Form */
var aRegisterRequiredFields = new Array ("FirstName","Please enter your first name to continue",
	 									 "Surname","Please enter a surname to continue",
									 	 "EmailAddress","Please enter your email address to continue",
									 	 "EmailAddressConfirm","Please confirm your email address to continue",
										 "PasswordField","Please enter a password to continue",
										 "ConfirmPassword","Please confirm your password to continue",
										 "Terms", "Please confirm you agree to the terms");

function JSFnValidateRegisterForm()
{
	var aResult = JSFnValidateForm(aRegisterRequiredFields);
	//alert(aResult);
	if(aResult == true)
	{
		// check if both password fields are the same
		if (this.EmailAddress.value != this.EmailAddressConfirm.value)
		{
			alert("The two email addresses are not the same.");
			this.EmailAddress.focus();
			return false;
		}
	}

	if(aResult == true)
	{
		if (this.PasswordField.value.length < 6)
		{
			alert("Please enter at least 6 characters in the \"Password\" field.");
			return false;
		}
	}

	if(aResult == true)
	{
		// check if both password fields are the same
		if (this.PasswordField.value != this.ConfirmPassword.value)
		{
			alert("The two passwords are not the same.");
			this.ConfirmPassword.focus();
			return false;
		}
	} 
	
	return aResult;
}

/* Register Form */
var aRegister2RequiredFields = new Array ("TelephoneNo","Please enter your telephone no to continue",
	 									 "DayDOB","Please enter your date of birth to continue",
									 	 "MonthDOB","Please enter your date of birth to continue",
									 	 "YearDOB","Please confirm your date of birth to continue",
									 	 "Address1","Please enter address 1 to continue",
									 	// "Address2","Please address 2 to continue",
									 	 "Town","Please enter a town to continue",
									 	 "Postcode","Please enter a postcode to continue");

function JSFnValidateRegisterForm2()
{
	return JSFnValidateForm(aRegister2RequiredFields);
}

/* Register Form */
var aRegister3RequiredFields = new Array ("NationalityID","Please select your nationaility to continue",
										  "IDTypeID","Please select which document can you provide",
										  "Eligible", "Please confirm you are eligible to work in the UK & can provide the above documentation"
										  );

function JSFnValidateRegisterForm3()
{
	return JSFnValidateForm(aRegister3RequiredFields);
}


/* Client Register Form */
var aRegisterRequiredFields = new Array ("ClientName","Please enter your business name to continue",
										 "FirstName","Please enter your first name to continue",
	 									 "Surname","Please enter a surname to continue",
									 	 "EmailAddress","Please enter your email address to continue",
									 	 "EmailAddressConfirm","Please confirm your email address to continue",
										 "PasswordField","Please enter a password to continue",
										 "ConfirmPassword","Please confirm your password to continue",
										 "Terms", "Please confirm you agree to the terms");

function JSFnValidateClientRegisterForm()
{
	var aResult = JSFnValidateForm(aRegisterRequiredFields);
	
	if(aResult == true)
	{
		// check if both password fields are the same
		if (this.EmailAddress.value != this.EmailAddressConfirm.value)
		{
			alert("The two email addresses are not the same.");
			this.EmailAddress.focus();
			return false;
		}
	}

	if(aResult == true)
	{
		if (this.PasswordField.value.length < 6)
		{
			alert("Please enter at least 6 characters in the \"Password\" field.");
			return false;
		}
	}

	if(aResult == true)
	{
		// check if both password fields are the same
		if (this.PasswordField.value != this.ConfirmPassword.value)
		{
			alert("The two passwords are not the same.");
			this.ConfirmPassword.focus();
			return false;
		}
	} 
	
	return aResult;
}

/* Register Form */
var aClientRegister2RequiredFields = new Array ("Name","Please enter a business address name to continue",
	 									  "Address1","Please enter address line 1 to continue",
									 	  "Postcode","Please enter a postcode to continue",
									 	  "TelephoneNo","Please enter a telephone no. to continue");

function JSFnValidateClientRegisterForm2()
{
	return JSFnValidateForm(aClientRegister2RequiredFields);
}

/* Contact Form */
var aContactRequiredFields = 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",
									 	"Subject","Please enter a subject to continue",
									 	"Message","Please enter a message to continue");

function JSFnValidateContactForm()
{
	return JSFnValidateForm(aContactRequiredFields);
}


/*** Pop Up Window ***/
function JSFnNewWindow()
{
	var aWindow = window.open(this.href, 'VIewHTML', 'scrollbars=yes, menubar=no, resizeable=yes, toolbar=no, width=800px, height=800px')
	aWindow.focus();
	return false;
}
//********************************************************************************************************************************

/*** Validate Form ***/
function JSFnValidateForm(aRequiredFields)
{
	for (aIndex = 0; aIndex < aRequiredFields.length; aIndex = aIndex + 2)
	{
		currElement = document.getElementById(aRequiredFields[aIndex]);

		
		if (currElement != null && currElement.parentNode.style.display!="none")
		{
			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;

}
//********************************************************************************************************************************

/*** Remove Link ***/
function JSFnRemoveClick()
{
	var removed = confirm("Are you sure you want to remove this item?");
	return removed;
}
//********************************************************************************************************************************
