function checkLoginForm()
{


		// Allow language swop, before validating
		if(document.frmMainLogin.prmLangLoaded.value != trimSpace(document.frmMainLogin.prmVapLang.options[document.frmMainLogin.prmVapLang.selectedIndex].value))
	     {	
		     // alert("About to change language");	
			 //document.frmMainLogin.sEmail.value="";
			 //document.frmMainLogin.sEmail.focus();
			 return true;
	     }



		// Check to make sure user entered their Email.
    	 if(document.frmMainLogin.sEmail == null && trimSpace(document.frmMainLogin.sEmail.value)=="" && document.frmMainLogin.sPassword == null && trimSpace(document.frmMainLogin.sPassword.value)=="")
	     {	
		     alert("Please enter your email address & password to gain access to the eCatalogue");	
			 document.frmMainLogin.sEmail.value="";
			 document.frmMainLogin.sEmail.focus();
			 return false;
	     }

		// Check to make sure user entered their Email.
    	 if(document.frmMainLogin.sEmail != null && trimSpace(document.frmMainLogin.sEmail.value)=="")
	     {	
		     alert("Please enter your email address");	
			 document.frmMainLogin.sEmail.value="";
			 document.frmMainLogin.sEmail.focus();
			 return false;
	     }

		// Check to make sure user entered their Email, not the example.
    	 if(trimSpace(document.frmMainLogin.sEmail.value) == "someone@youraddress.com")
	     {	
		     alert("Please enter your email address");	
				document.frmMainLogin.sEmail.focus();
				document.frmMainLogin.sEmail.select();
			 return false;
	     }



		if(document.frmMainLogin.sEmail != null && trimSpace(document.frmMainLogin.sEmail.value) != "")
		{
			if( !isEmail(document.frmMainLogin.sEmail.value) )
			{
				alert("Your E-mail should be in the form 'someone@address.com'.");
				document.frmMainLogin.sEmail.focus();
				document.frmMainLogin.sEmail.select();
				return false;
			}
		}


		// Check to make sure user entered a password.	
		if(trimSpace(document.frmMainLogin.sPassword.value)=="")
		{	 	
			alert("Please enter a password");	
			document.frmMainLogin.sPassword.value="";	
			document.frmMainLogin.sPassword.focus();
			return false;
		}
	
	
		// Check to make sure passwords have at least 8 characters and that they are the same.		
		if(document.frmMainLogin.sPassword.value.length < 6)
		{	 	
			alert("Please re-enter your password, it must have at least 6 characters");	
	 		document.frmMainLogin.sPassword.value="";
			document.frmMainLogin.sPasswordConfirm.value="";	
			document.frmMainLogin.sPassword.focus();	
			return false;	
		}
	
		return true;
} //End function checkForm()



function checkRegistrationForm()
{
					
		document.myForm.State = "w";
		if( document.myForm.State != null )

			var userName = "";	
			var PostcodeCode = "";
			var i = 0;  

		// Check to make sure user entered their Email.
    	 if(document.myForm.sEmail != null && trimSpace(document.myForm.sEmail.value)=="")
	     {	
		     alert("Please enter your email address");	
			 document.myForm.sEmail.value="";
			 document.myForm.sEmail.focus();
			 return false;
	     }

		// Check to make sure user entered their Email, not the example.
    	 if(trimSpace(document.myForm.sEmail.value) == "someone@youraddress.com")
	     {	
		     alert("Please enter your email address");	
				document.myForm.sEmail.focus();
				document.myForm.sEmail.select();
			 return false;
	     }



		if(document.myForm.sEmail != null && trimSpace(document.myForm.sEmail.value) != "")
		{
			if( !isEmail(document.myForm.sEmail.value) )
			{
				alert("Your E-mail should be in the form 'someone@address.com'.");
				document.myForm.sEmail.focus();
				document.myForm.sEmail.select();
				return false;
			}
		}


		// Check to make sure user entered a password.	
		if(trimSpace(document.myForm.sPassword.value)=="")
		{	 	
			alert("Please enter a password");	
			document.myForm.sPassword.value="";	
			document.myForm.sPassword.focus();
			return false;
		}
	
		// Check to make sure user entered a confirm password.
		if(trimSpace(document.myForm.sPasswordConfirm.value)=="")
		{	 	
			alert("Please confirm your password");	
			document.myForm.sPasswordConfirm.value="";
			document.myForm.sPasswordConfirm.focus();
			return false;	
		}
	
		// Check to make sure passwords have at least 8 characters and that they are the same.		
		if(document.myForm.sPassword.value.length < 6 || document.myForm.sPasswordConfirm.value.length < 6)
		{	 	
			alert("Please re-enter your password, it must have at least 6 characters");	
	 		document.myForm.sPassword.value="";
			document.myForm.sPasswordConfirm.value="";	
			document.myForm.sPassword.focus();	
			return false;	
		}
	
		if(trimSpace(document.myForm.sPassword.value) != trimSpace(document.myForm.sPasswordConfirm.value)) 
		{		
			alert("The New Password and Confirm Password do not match. Please re-enter the passwords");
			document.myForm.sPassword.value="";		
			document.myForm.sPasswordConfirm.value="";	
			document.myForm.sPassword.focus();	
			return false;	 
		}	 	 	


	
		 // Check to make sure user entered their name.		
		 if(document.myForm.sUserNameLast != null && trimSpace(document.myForm.sUserNameLast.value)=="")
		 {	 	
			alert("Please enter your First Name");	 
			document.myForm.sUserNameLast.value="";	 	
			document.myForm.sUserNameLast.focus();	 
			return false;	 
		}

		 // If UK, then Postcode is mandetory
		 if(trimSpace(document.myForm.sCountry.options[document.myForm.sCountry.selectedIndex].value)=="GB" && document.myForm.sPostCode.value.length<4)
		 {	 	
			alert("Please enter your postcode");	 
			document.myForm.sPostCode.value="";	 	
			document.myForm.sPostCode.focus();	 
			return false;	 
		}


		return true;
} //End function checkForm()

function isEmail(str)
 {
   // are regular expressions supported? 
    var supported = 0;  
	if (window.RegExp) 
	{
    	var tempStr = "a";
		var tempReg = new RegExp(tempStr);
		if (tempReg.test(tempStr)) supported = 1;  
	}

    if (!supported) return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
  	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  	var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z0-9]{2,20}|[0-9]{1,3})(\\]?)$");  
	return (!r1.test(str) && r2.test(str));
}


//function to verify that the Email address is valid
function EmailVerification(passedForm)
{
	var at1_flag = 0;
	var dot1_flag = 0;
	var elength_flag1 = 0;
	var at2_flag = 0;
	var dot2_flag = 0;
	var elength_flag2 = 0;
	for(a=0;a<passedForm.Email.value.length;a++)
	{
		if(passedForm.Email.value.charAt(a) == '@')	at1_flag = 1;
		else 
			if(passedForm.Email.value.charAt(a) == '.') dot1_flag = 1;	
	}			

	if(passedForm.Email.value.length > 2) elength_flag1 = 1;
	if((at1_flag != 1) || (dot1_flag != 1) || (elength_flag1 != 1))
	{
			 alert("Your E-mail should be in the form 'yourname@yourAddess.com'.");	 
			 passedForm.Email.focus();	 
			 passedForm.Email.select();	 
			 return false;	
 	}
	return true;
} //end function EmailVerification()



//function to trim leading and trailing white spaces
function trimSpace(str)
{     
	return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

function checkUserName(userName)
{
	document.myForm.UserName.value = trimSpace(userName);
}

function putFocus()
{
	document.myForm.sEmail.focus();
}

function keepAddress()
{  
	var password = '';
	document.myForm.Password.value = password;
	document.myForm.ConfirmPW.value = password; 
	var state = '';
	var stateCode = '';
	var customerType = '';
	var stateCodeObject = document.myForm.StateCode;
	if( stateCodeObject != null )
	{
	  var stateLength = stateCodeObject.options.length;
	  for(indexState = 0; indexState < stateLength; indexState++)
	  {
	    	if( stateCodeObject.options[indexState].value == stateCode )
	    	{  	
				stateCodeObject.options[indexState].selected=true; 
				break;
			}
		}
	}

	var customerTypeObject = document.myForm.customerType;
	if( customerTypeObject != null )
	{
		var customerTypeLength = customerTypeObject.options.length;
		for(indexcustomerType = 0; indexcustomerType < customerTypeLength; indexcustomerType++)
		{
		  	if( customerTypeObject.options[indexcustomerType].value == customerType )
		  	{  	
				customerTypeObject.options[indexcustomerType].selected=true;
				break;
			}
		}
	}
} // end function keepAddress()

function changeAddress()
{
      var addressline1 = '';
	  var addressline2 = '';
	  var city = '';
	  var state = '';
	  var stateCode = '';  
	  var Postcode = '';
	  var password = ''; 
	  var customerType = '';	 
	  document.myForm.AddressLine1.value = addressline1;
	  document.myForm.AddressLine2.value = addressline2;
	  document.myForm.City.value = city;
	  var stateCodeObject = document.myForm.StateCode;
	  if( stateCodeObject != null )
	  {
	  	var stateLength = stateCodeObject.options.length;
		for(indexState = 0; indexState < stateLength; indexState++)
		{
		 	if( stateCodeObject.options[indexState].value == stateCode )
		 	{
			  		stateCodeObject.options[indexState].selected=true;
					break;	
			}
		}
	  }
	  var customerTypeObject = document.myForm.customerType;
	  if( customerTypeObject != null )
	  {
		  	var customerTypeLength = customerTypeObject.options.length;

			for(indexcustomerType = 0; indexcustomerType < customerTypeLength; indexcustomerType++)
			{
			  	if( customerTypeObject.options[indexcustomerType].value == customerType )
			  	{
					customerTypeObject.options[indexcustomerType].selected=true;
					break;
				}
			}
		} 

		document.myForm.Postcode.value = Postcode;
		document.myForm.Password.value = password;
		document.myForm.ConfirmPW.value = password;
} //end function changeAddress()

function hideAddressCorrection()
{
	document.getElementById("addressCorrection").style.visibility="hidden";
} //end function hideAddressCorrection

function changeCountry(countryObject)
{
    document.myForm.userAction.value = "";
	document.myForm.EM_Country.value=countryObject.options[countryObject.selectedIndex].value;
	document.myForm.EM_SelectCountry.value=countryObject.options[countryObject.selectedIndex].value;  
	document.myForm.submit();
	return true;
} // end function changeCountry

