function init()
{
	var errorCode = 0;
	
	/* Get parameters (if any) */
	var params = window.location.search;
	
	if (params.length > 0)
	{
		errorCode = -1;
		
		/* Split parameters into string array */
		
		params = params.substring(1, params.length);
	
		var paramsArr = params.split('&');

		params = null;
		
		/* Get form object */

		var formObj = null;

		if (is_nav == true)
			formObj = document.subscribe;
		else
			formObj = document.forms['subscribe'];
  
		if (formObj != null)
		{
			errorCode = 0;
			
			var paramArr = null;
			var inputObj = null;
			
			if (errorCode == 0)
			{
				if (is_nav == true)
					inputObj = formObj.title;
				else
					inputObj = formObj.all['title'];

				if (inputObj != null)
				{
					paramArr = paramsArr[0].split('=');

					inputObj.value = paramArr[1];

					paramArr = null;
					inputObj = null;
				}
				else
					errorCode = -1;
			}
			
			if (errorCode == 0)
			{
				if (is_nav == true)
					inputObj = formObj.firstName;
				else
					inputObj = formObj.all['firstName'];

				if (inputObj != null)
				{
					paramArr = paramsArr[1].split('=');

					inputObj.value = paramArr[1];

					paramArr = null;
					inputObj = null;
				}
				else
					errorCode = -1;
			}
			
			if (errorCode == 0)
			{
				if (is_nav == true)
					inputObj = formObj.lastName;
				else
					inputObj = formObj.all['lastName'];

				if (inputObj != null)
				{
					paramArr = paramsArr[2].split('=');

					inputObj.value = paramArr[1];

					paramArr = null;
					inputObj = null;
				}
				else
					errorCode = -1;
			}
			
			inputObj = null;
			paramArr = null;
		}
		
		formObj = null;
		paramsArr = null;
		
		/* Display error message within document */
		
		var labelObj = null;
		
		if (is_nav == true)
			labelObj = document.errorMsg;
		else
			labelObj = document.all['errorMsg'];
		
		if (labelObj != null)
			labelObj.innerHTML = '<br>The Email field was not entered correctly! Please try again. <br><br>';
		else
			errorCode = -1;
			
		labelObj = null;
	}
	
	params = null;
	
	if (errorCode == -1)
		window.alert('Error! There is a problem with the subscription form. Please contact webmaster@noelchadwick.co.uk.');
}

function pokeRedirectURL()
{
	var errorCode = -1;
	
	/* Get form object */
	
	var formObj = null;
	
	if (is_nav == true)
		formObj = document.subscribe;
	else
		formObj = document.forms['subscribe'];
  
	if (formObj != null)
	{
		errorCode = 0;
		
		var url = 'http://localhost/noelchadwick/newsletter.html';
		var inputObj = null;
	   
		if (errorCode == 0)
		{
			/* Get missing fields redirect URL */

			if (is_nav == true)
				inputObj = formObj.title;
			else
				inputObj = formObj.all['title'];

			if (inputObj != null)
			{
				url = url + '?1=' + inputObj.value;
				inputObj = null;
			}
			else
				errorCode = -1;
		}

		if (errorCode == 0)
		{
			if (is_nav == true)
				inputObj = formObj.firstName;
			else
				inputObj = formObj.all['firstName'];

			if (inputObj != null)
			{
				url = url + '&2=' + inputObj.value;
				inputObj = null;
			}
			else
				errorCode = -1;
		}
		
		if (errorCode == 0)
		{
			if (is_nav == true)
				inputObj = formObj.lastName;
			else
				inputObj = formObj.all['lastName'];

			if (inputObj != null)
			{
				url = url + '&3=' + inputObj.value;
				inputObj = null;
			}
			else
				errorCode = -1;
		}
		
		if (errorCode == 0)
		{
			if (is_nav == true)
				inputObj = formObj.missing_fields_redirect;
			else
				inputObj = formObj.all['missing_fields_redirect'];

			if (inputObj != null)
			{
				inputObj.value = url;
				inputObj = null;
			}
		}
		
		inputObj = null;
	}
	
	formObj = null;
	
	if (errorCode == -1)
		window.alert('Error! There is a problem with the subscription form. Please contact webmaster@noelchadwick.co.uk.');
}

function validateForm()
{
	var errorCode = -1;
	
	/* Get form object */
	
	var formObj = null;
	
	if (is_nav == true)
		formObj = document.subscribe;
	else
		formObj = document.forms['subscribe'];
  
	if (formObj != null)
	{
		errorCode = 0;
		
		if (errorCode == 0)
		{
			errorCode = -1;
			
			/* Get email input object */

			var inputObj = null;

			if (is_nav == true)
				inputObj = formObj.email;
			else
				inputObj = formObj.all['email'];

			if (inputObj != null)
			{
				errorCode = -2;

				/* Get email value */
				var emailAddr = inputObj.value;

				if (emailAddr.length > 0)
				{
					errorCode = -3;

					emailAddr = emailAddr.toLowerCase();

					if (emailAddr.indexOf('noelchadwick') == -1)
					{
						var nameDomainArr = emailAddr.split('@');

						if (nameDomainArr.length == 2)
						{
							if ((nameDomainArr[0].length > 0) && (nameDomainArr[1].length > 0))
							{
								errorCode = 0;

								var index = 0;
								var index1 = 0;

								if (errorCode == 0)
								{
									var nameArr = nameDomainArr[0].split('.');

									if (nameArr != null)
									{
										index = 0;
										index1 = nameArr.length;

										while ((errorCode == 0) && (index < index1))
										{
											if (nameArr[index] != null)
											{
												if (nameArr[index].length < 1)
													errorCode = -3;
											}
											else
												errorCode = -3;

											if (errorCode == 0)
												++index;
										}
									}
									else
										errorCode = -3;

									nameArr = null;
								}

								if (errorCode == 0)
								{
									var domainArr = nameDomainArr[1].split('.');

									if (domainArr != null)
									{
										if (domainArr.length >= 2)
										{
											index = 0;
											index1 = domainArr.length;

											while ((errorCode == 0) && (index < index1))
											{
												if (domainArr[index] != null)
												{
													if (domainArr[index].length < 1)
														errorCode = -3;
												}
												else
													errorCode = -3;

												if (errorCode == 0)
													++index;
											}
										}
										else
											errorCode = -3;
									}
									else
										errorCode = -3;

									domainArr = null;
								}
							}
						}

						nameDomainArr = null;
					}
				}

				emailAddr = null;
			}
		}
		
		if (errorCode == 0)
		{
			errorCode = -1;
			
			/* Get code input object */

			var inputObj = null;

			if (is_nav == true)
				inputObj = formObj.code;
			else
				inputObj = formObj.all['code'];

			if (inputObj != null)
			{
				/* Get code value */
				var code = inputObj.value;

				if (code.length > 0)
					errorCode = 0;
				else
					errorCode = -4;
			}
		}
		
		inputObj = null;
	}
	
	formObj = null;
	
	/* Check error code */
	
	var valid = false;
	
	if (errorCode == -1)
		window.alert('Error! There is a problem with the subscription form. Please contact webmaster@noelchadwick.co.uk.');
	else if (errorCode == -2)
		window.alert('Please enter your Email address.');
	else if (errorCode == -3)
		window.alert('Invalid Email address! Please enter again.');
	else if (errorCode == -4)
		window.alert('Please enter your registration code.');
	else
		valid = true;
	
	return valid;
}
