function checkIllegalChar(str)
{
	var checkOK = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
	var checkStr = str;
	var allValid = true;
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
			if (j == checkOK.length)
			{
				allValid = false;
				break;
			}
	}	
	return (allValid);
}

function checkemail() 
{ 
	strng = document.form1.email.value;
		
	if (strng != "")
	{	
		var emailFilter=/^.+@.+\..{2,3}$/; 
		if (!(emailFilter.test(strng))) 
		{ 
			alert("Please enter a valid email address."); 
			document.form1.email.select();
			return false;
		} 
	
		//test email for illegal characters 
		var illegalChars= /[\(\)\<\>\,\;\:\\\"\[\]]/ 
		if (strng.match(illegalChars)) 
		{ 
			alert("The email address contains illegal characters."); 
			document.form1.email.select();
			return false;
		} 
	}

	return true; 
} 

function checkPassword () 
{
	login_pwd = document.form1.login_pwd.value;  
	confirm_pwd = document.form1.confirm_pwd.value;  
	
	if (login_pwd.length <4){ 
		alert("Login password must be 4 to 12 characters or numbers."); 
		document.form1.login_pwd.select();
		return false;
	}
	
	if (!checkIllegalChar(login_pwd))
	{
		alert("Login password should be numbers and characters only. Spaces and symbols are not allowed.");
		document.form1.login_pwd.select();
		return (false);
	}	
	
	if (confirm_pwd.length <4){ 
		alert("The confirm password must be 4 to 12 characters or numbers."); 
		document.form1.confirm_pwd.select();
		return false;
	}	
	
	if (confirm_pwd != login_pwd){ 
		alert("Both passwords are different. Please re-enter the password again."); 
		document.form1.confirm_pwd.select();
		return false;
	}	
	return true;
}
 


function submitForm()
{ 

  advertiser=document.form1.advertiser.value;
  owner_name=document.form1.owner_name.value;
  
  contact_no_off=document.form1.contact_no_off.value;
  contact_no_hm=document.form1.contact_no_hm.value;
  contact_no_hp=document.form1.contact_no_hp.value;
  
  address=document.form1.address.value;
  postcode=document.form1.postcode.value;
  town=document.form1.town.value;  
  mystate=document.form1.state.value;
  
  email=document.form1.email.value;  
  owner_username=document.form1.owner_username.value;
 
  if (advertiser.length<1){
      alert("Please select an advertiser type.");
      document.form1.advertiser.focus();
      return(false);
  }

  if (owner_name.length<1){
      alert("The contact person field is required.");
      document.form1.owner_name.select();
      return(false);
  }

  if ((contact_no_off.length<1) && (contact_no_hm.length<1) && (contact_no_hp.length<1)){
      alert("At least one contact number is required.");
      document.form1.contact_no_off.select();
      return(false);
  }

  if (address.length<1){
      alert("Address field is required.");
      document.form1.address.select();
      return(false);
  }

  if (postcode.length != 5){
      alert("Postcode field must have 5 numbers.");
      document.form1.postcode.select();
      return(false);
  } 

  if (isNaN(postcode)){
     alert("Postcode must be numbers.");
     document.form1.postcode.select();
     return(false);
  }
  
  if (town.length<1){
      alert("Town field is required.");
      document.form1.town.select();
      return(false);
  }

  if (mystate.length<1){
      alert("Please select a state.");
      document.form1.state.focus();      
      return(false);
  } 
  
  if (email.length<1){
      alert("The email address field is required.");
      document.form1.email.select();
      return(false);
  }

  Validemail = checkemail();
  if (Validemail == false)
	return(false); 

  if (owner_username.length<4){
      alert("Username must be 4 to 12 characters.");
      document.form1.owner_username.select();
      return(false);
  }

  if (!checkIllegalChar(owner_username))
  {
	alert("Username should be numbers and characters only. Spaces and symbols are not allowed.");
	document.form1.owner_username.select();
	return (false);
  }  

  ValidPassword = checkPassword();
  if (ValidPassword == false)
		return(false); 
 
  document.form1.js_yn.value = "yes"; 
 
  return(true);

}