var runme=true;

			// Form Functions
			// Used to check that mandatory textbox have a value
			function check_textbox(ThisField)
				{
			   if(document.getElementById(ThisField).value == ''){
						do_error(ThisField);
					}
			   }

			function check_radio(ThisField) {
				var MyRadio = document.getElementsByName(ThisField)
				var RadioChecked = false
					for(var i = 0; i < MyRadio.length; i++){
							if(MyRadio[i].checked) { RadioChecked=true ; } // yes one was ticked
						}
					if (RadioChecked == false) { do_error(ThisField); }
			}

			function do_error(ThisField) {
					var Error_colour  = "#3366CC";
					var TheMessage = 'Please enter a value for ' + ThisField;
					if (ThisField == 'EMAIL') 
					{ 
					TheMessage = 'EMAIL address is not valid' ;
					Error_colour = '#FF0000';
					}
					alert(TheMessage);
					document.getElementById(ThisField).style.backgroundColor = Error_colour;
					document.getElementById(ThisField).focus();
					runme = false;
					}

			function check_Email(ThisField) { 
					
					if (document.forms.ThisForm.EMAIL.value == '' || document.forms.ThisForm.IsEmailValid.value == 'False')
					{
						do_error('EMAIL');
					}
					
				}

			function isValidDate(thisday,thismonth,thisyear, ThisField)
			{
			var dteDate;
			var year, month, day;
			
			year = document.getElementById(thisyear).value; 
			month = document.getElementById(thismonth).value; 
			day = document.getElementById(thisday).value

			dteDate=new Date(year,month,day);
			
			if (! ((day==dteDate.getDate()) && (month==dteDate.getMonth()) && (year==dteDate.getFullYear())))
			{
			alert("Please Enter Valid Value for : " + ThisField); 
			runme = false;
			}

			}

			function form_submit() { 
					 // alert('run submit ' + runme ); 
					if (runme == true) { 
					
					// Added this to stop double clicking...
					document.ThisForm.btnSubmit.disabled=true;	
					document.ThisForm.btnSubmit.value='Please wait...';
					document.ThisForm.submit();

					} //alert('do it'); 
					else {runme = true	} //reset the runme var; 
						}

	function UnSubscribeChecked(ThisElement,FormField) {
				if (document.forms.ThisForm.UnSubBox.checked == true) 
					{ 
						document.forms.ThisForm.UNSUBSCRIBED.value = 1;
					}
				else
					{
						document.forms.ThisForm.UNSUBSCRIBED.value = 0;
					}
			}
	
			function DontSendMarketingChecked(ThisElement,FormField) 
			{
				if (document.forms.ThisForm.DONT_SEND_MARKETINGBox.checked == true) 
					{ 
						document.forms.ThisForm.DONT_SEND_MARKETING.value = 1;
					}
				else
					{
						document.forms.ThisForm.DONT_SEND_MARKETING.value = 0;
					}
			}


	// Create a new instance of ajax
	var ajax = new sack();
	
	function checkEmail(RunThisScript, EmailToValidate)
	{
		if(EmailToValidate.length >= 5 ) {

			if(IsEmailSyntaxCorrect(EmailToValidate))
			{
				//alert(EmailToValidate);
				ajax.requestFile = RunThisScript + '?Email=' + EmailToValidate;			// Specifying which file to get
				ajax.onCompletion = populateEmail;	// Specify function that will be executed after file has been found
				ajax.runAJAX();						// Execute AJAX function			
			}
			else
			{
				//alert('Syntax Incorrect !');
				document.forms.ThisForm.IsEmailValid.value = 'False';
				// document.getElementById('EMAIL').style.backgroundColor = '#FF0000';
				document.getElementById('EmailIsValidNotification').innerHTML = '<img src="Community_App_images/cross.gif" border="0">';
			}
		}
		else
		{
			document.getElementById('EmailIsValidNotification').innerHTML = '';
		}
	}

	function populateEmail()
	{
		//alert('finished running');
		document.forms.ThisForm.IsEmailValid.value = ajax.response;
		if(document.forms.ThisForm.IsEmailValid.value == 'True')
		{
			document.getElementById('EMAIL').style.backgroundColor = '#FFFFFF';
			document.getElementById('EmailIsValidNotification').innerHTML = '<img src="Community_App_images/tick.gif" border="0">';
		}
		else
		{
			//document.getElementById('EMAIL').style.backgroundColor = '#FF0000';
			document.getElementById('EmailIsValidNotification').innerHTML = '<img src="Community_App_images/cross.gif" border="0">';
		}
	}
	
	function IsEmailSyntaxCorrect(ThisEmail)
	{
		//alert('Checking ' + ThisEmail);

		if(ThisEmail != '')
		{
			var emailfmt= /^\w+([.-]\w+)*@\w+([.-]\w+)*\.\w{2,8}$/;
			return emailfmt.test(ThisEmail);
		}
	}
	function showDiv(divId)
	{
		document.getElementById(divId).style.display = "";
	}

	/* Hide a div */
	function hideDiv(divId)
	{
		document.getElementById(divId).style.display = "none";
	}
