// JavaScript Document
// Verify New User Application Form
// File: validateSignUp.js
// Version: V1.0
// Last Updated: 22 January 2003
// Author: Bozidar Jovanovic - boz@neolateral.com.au
// Company: Neolateral
// ABN: 31 554 615 680

	function validateForm( signUp )
	{
		/*if (signUp.titleMenu[].option == "") // Check 'Title' field
		{ 
			alert ("Please enter your name")
			signUp.titleMenu.focus();
        	return false ;
			
		}*/
				
				if( signUp.formUserName.value =="" )
		{
			alert("Please choose a Username") ;
			signUp.formUserName.focus();
			return false ;
		}
		

		if( signUp.formPassword.value == "" )
		{
			alert("Please choose a Password") ;
			signUp.formPassword.focus();
			return false ;
		}
		
		if( signUp.formPassword.value != signUp.formPassword2.value )
		{
			alert("There is a mis-match between your password, and the one you re-typed.\n\nThese two passwords must be the same to ensure that you\n have typed the password you have chosen correctly.") ;
			signUp.formPassword.focus();
			return false ;
		}

		if (signUp.firstName.value == "") // Check 'firstName' field
		{ 
			alert ("Please enter your first name")
			signUp.firstName.focus();
        	return false ;
			
		}
		if (signUp.lastName.value == "") // Check 'lastName' field
		{ 
			alert ("Please enter your last name")
			signUp.lastName.focus();
        	return false ;
			
		}
	
	
		if (signUp.ReMoMenu.value =="") // Check 'isBusiness' field
		{ 
			alert ("Please choose member attribute.")
			signUp.ReMoMenu.focus();			
        	return false ;
			
		}
		
		if (signUp.ReMoMenu.value =="2"&&signUp.SubEMMenu.value =="") // Check 'isBusiness' field
		{ 
			alert ("Please choose the managing mode of your business.")
			signUp.SubEMMenu.focus();			
        	return false ;
			
		}		
		
		if (signUp.ReMoMenu.value == "2" && ( signUp.businessname.value == "" || signUp.ABNACN.value == "" || !signUp.isAuthorised.checked) ) // Check 'isBusiness' field
		{ 
			alert ("You have stated that you are a business entity, and therefore\nmust:\n   -Supply Your Business Name and ABN/ACN\n   -Tick 'Yes' to say that you are an authorised\n    representative of your Business/Company.\nThank you.")
        	
			if( signUp.businessname.value == "" )
			{signUp.businessname.focus();}
			else if( signUp.ABNACN.value == "" )
			{signUp.ABNACN.focus();}
			else if( !signUp.isAuthorised.checked )
			{signUp.isAuthorised.focus();}
						
			return false ;	
		}
		
		
		if (!validEmail( signUp.emailAddress ) )
		{
			alert("Please enter a valid email address") ;
			signUp.emailAddress.focus();
			return false ;
		}


		if (getAgreedAndUnderstoodTerms() == "no" || getAgreedAndUnderstoodTerms() == -1)
		{
			alert("The services that Aus-Bizlist provides are subject to the terms and conditions\noutlined in the guidelines section in the main menu at the top of this page.\n\nAcceptance of these terms and conditions is compulsory if you wish to use\nany services provided by Aus-Bizlist.\n\nThank you.") ;
			signUp.terms.focus();
			return false ;
		}
		

		function validEmail( emailAddress )
		{
			var valid = false ;

			if (emailAddress.value.length < 7) //a@bc.de check for minimum length
			{
				return false ;
			}

			var hasAt = -1;
			for (i = 0; i < emailAddress.value.length ; i++)
			{
				
				if (emailAddress.value.charAt(i) == "@")
				{
					//valid = true ;
					hasAt = i;
					//return true ;
				}
				
				//Check to see if we have at least 'a@bc.de'
				if ( ( i >= hasAt + 2) && ( emailAddress.value.length >= (hasAt + (i-hasAt) + 3) ) && (emailAddress.value.charAt(i) == ".") )
				{
					valid = true ;
					//return true ;
				}
			}
			if ( !valid )
			{
				return false ;
			}else
			{
				return true ;
			}
		}
		
		function getSelectedIsBusiness()
		{
			var i;

			for( i=0; i<signUp.isBusiness.length; ++i)
				if( signUp.isBusiness[i].checked)
					return signUp.isBusiness[i].value;

			// default (non selected)
			return -1;
		}
	
		function getAgreedAndUnderstoodTerms()
		{
			var i;

			for( i=0; i<signUp.terms.length; ++i)
				if( signUp.terms[i].checked)
					return signUp.terms[i].value;

			// default (non selected)
			return -1;
		}
		
	}
	
