// JavaScript Document
function validEmail(email)
{
   invalidChars = " /:,;"

   if (email == "")
      return false

   for (i=0; i<invalidChars.length; i++)
   {
      badChar = invalidChars.charAt(i)

      if (email.indexOf(badChar,0)>-1)
         return false
   }

   atPos = email.indexOf("@",1)

   if (atPos == -1)
      return false

   if (email.indexOf("@",atPos+1) != -1)
      return false

   periodPos = email.indexOf(".",atPos)

   if (periodPos == -1)
      return false

   if (periodPos+3 > email.length)
      return false

   return true
}

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        //if (((c < "0") || (c > "9"))) return false;
        if ((c < "0") || (c > "9") || (c != "+")) return false;
    }
    // All characters are numbers.
    return true;
}

function validUsername(username)
{
   invalidChars = ":,;='!#$%^&<>"

   if (username == "")
      return false

   for (i=0; i<invalidChars.length; i++)
   {
      badChar = invalidChars.charAt(i)

      if (username.indexOf(badChar,0)>-1)
         return false
   }

   return true
}


function submitIt (joinForm)
{
   if (joinForm.username.value == "")
   {
      alert("Please enter a username.")
	  return false
   }

   if (!validUsername(joinForm.username.value))
   {
      alert("Invalid character. Please enter your username again.")
      return false
   }

   titleChoice = joinForm.title.selectedIndex
   if (joinForm.title.options[titleChoice].value == "")
   {
      alert ("You must select a title.")
	  return false
   }

   if (joinForm.fName.value == "")
   {
      alert("Please enter your first name.")
	  return false
   }

   if (joinForm.sName.value == "")
   {
      alert("Please enter your surname.")
	  return false
   }

   if (joinForm.company.value == "")
   {
      alert("Please enter a company.")
	  return false
   }

   if (joinForm.industry.value == "")
   {
      alert("Please enter an industry.")
	  return false
   }

   if (joinForm.position.value == "")
   {
      alert("Please enter your position.")
	  return false
   }

   //if (joinForm.intCode.value == "" || isInteger(joinForm.intCode.value) == false)
   if (joinForm.intCode.value == "" )
   {
      alert("Please enter a valid international access code.")
      joinForm.intCode.value=""
      joinForm.intCode.focus()
      return false
   }

   //if (joinForm.areaCode.value == "" || isInteger(joinForm.areaCode.value) == false)
   if (joinForm.areaCode.value == "" )
   {
      alert("Please enter a valid area code.")
	  joinForm.areaCode.value=""
	  joinForm.areaCode.focus()
      return false
   }
	  
   //if (joinForm.phone.value == "" || isInteger(joinForm.phone.value) == false)
   if (joinForm.phone.value == "" )
   {
      alert("Please enter a valid phone number.")
	  joinForm.phone.value=""
      joinForm.phone.focus()
      return false
   }

/*
   if (joinForm.intCode2.value == "")
   {
      alert("Please enter a valid international access code of fax.")
      joinForm.intCode2.value=""
      joinForm.intCode2.focus()
      return false
   }

   if (joinForm.areaCode2.value != "")
   {
      if (isInteger(joinForm.areaCode2.value) == false)
      {
         alert("Please enter a valid area code of fax.")
	     joinForm.areaCode2.value=""
	     joinForm.areaCode2.focus()
         return false
      }
   }
	  
   if (joinForm.fax.value != "")
   {
      if (isInteger(joinForm.fax.value) == false)
      {
         alert("Please enter a valid fax number.")
	     joinForm.fax.value=""
         joinForm.fax.focus()
         return false
      }
   }
*/

   if (!validEmail(joinForm.email.value))
   {
      alert("Invalid format. Please enter your email address again.")
      return false
   }

   if (joinForm.address.value == "")
   {
      alert ("Please enter an address.")
      return false
   }

   if (joinForm.suburb.value == "")
   {
      alert ("Please enter a suburb or city.")
      return false
   }

   if (joinForm.strState.value == "")
   {
      alert ("Please enter a state or province.")
      return false
   }

   //if (joinForm.postcode.value == "" || isInteger(joinForm.postcode.value) == false)
   if (joinForm.postcode.value == "")
   {
      alert ("Please enter a valid postcode or zip.")
      return false
   }
    
   if (joinForm.country.value == "")
   {
      alert ("Please type in a country.")
      return false
   }
/*
   ind_opChoice = joinForm.ind_op.selectedIndex
   if (joinForm.ind_op.options[ind_opChoice].value == "")
   {
      alert ("You must select a industry you operate in.")
	  return false
   }

   if (joinForm.ind_op.options[ind_opChoice].value == "Other")
   {
      if (joinForm.ind_op1.value == "")
      {
         alert ("You must enter a industry you operate in.")
	     return false
      }
   }
*/
/*
   if (joinForm.water.checked==false && joinForm.waste.checked==false && joinForm.electricity.checked==false && joinForm.mining.checked==false && joinForm.oilngas.checked==false && joinForm.irrigation.checked==false && joinForm.security.checked==false && joinForm.transport.checked==false && joinForm.other.checked==false)
   {
      alert ("Sorry. You have not told us which industries you operate in. Please select one or more answers for the question labelled 'Which industry do you operate in?'")
      return false
   }
*/  
   if (joinForm.broadcast.checked==false && joinForm.communications.checked==false && joinForm.electricity.checked==false && joinForm.environmental.checked==false && joinForm.mining.checked==false && joinForm.oilngas.checked==false && joinForm.publicsafety.checked==false && joinForm.SCADAsecurity.checked==false && joinForm.transport.checked==false && joinForm.water.checked==false && joinForm.waste.checked==false && joinForm.other.checked==false)
   {
      alert ("Sorry. You have not told us which industries you operate in. Please select one or more answers for the question labelled 'Which industry do you operate in?'")
      return false
   }

   if (joinForm.other.checked==true)
   {
      if (joinForm.ind_op1.value == "")
      {
         alert ("Sorry. You have not told us which industries you operate in. Please answers for the question labelled 'Which industry do you operate in?'")
         return false
      }
   }

   subscribeOption = -1
   for (i = 0; i < joinForm.subscribe.length; i++)
   {
      if (joinForm.subscribe[i].checked)
      {
         subscribeOption = i
      }
   }

   if (subscribeOption == -1)
   {
      alert ("You must choose you like to receive updates of new products and software / firmware from us or not.")
      return false
   }

   softwareOption = -1
   for (i = 0; i < joinForm.software.length; i++)
   {
      if (joinForm.software[i].checked)
      {
         softwareOption = i
      }
   }

   if (softwareOption == -1)
   {
      alert ("You must choose you require access to our Software Download Section or not.")
      return false
   }
     
   return true
}


