  // Basic checks for valid formed email address
  function echeck(str)
  {
    var at="@"
    var dot="."
    var lat=str.indexOf(at)
    var lstr=str.length
    var ldot=str.indexOf(dot)
    if (str.indexOf(at)==-1)
    {
      alert("You have entered an invalid email address.  Please try again.")
      return false
    }
    if (str.indexOf(at)==-1 || str.indexOf(at)==0 || str.indexOf(at)==lstr)
    {
      alert("You have entered an invalid email address.  Please try again.")
      return false
    }
    if (str.indexOf(dot)==-1 || str.indexOf(dot)==0 || str.indexOf(dot)==lstr)
    {
      alert("You have entered an invalid email address.  Please try again.")
      return false
    }
    if (str.indexOf(at,(lat+1))!=-1)
    {
      alert("You have entered an invalid email address.  Please try again.")
      return false
    }
    if (str.substring(lat-1,lat)==dot || str.substring(lat+1,lat+2)==dot)
    {
      alert("You have entered an invalid email address.  Please try again.")
      return false
    }
    if (str.indexOf(dot,(lat+2))==-1)
    {
      alert("You have entered an invalid email address.  Please try again.")
      return false
    }
    if (str.indexOf(" ")!=-1)
    {
      alert("You have entered an invalid email address.  Please try again.")
      return false
    }
    return true          
  }
  // Main function to Validate the whole form
  function validateForm()
  {
    var emailID=document.getElementById('EmailAddress')
    if ((emailID.value==null)||(emailID.value==""))
    {
      alert("You have entered an invalid email address.  Please try again.")
      emailID.focus()
      // poorly formed email address try again.
      return false
    }
    if (echeck(emailID.value)==false)
    {
      emailID.value=""
      emailID.focus()
      // form will not submit because nothing was entered
      return false
    }
    // we have a good email address at this point
    // put the valid email address in the ETSubscriberKey.
    document.getElementById('ETSubscriberKey').value=emailID.value
    // This is the site where the thank you page will live.  This is the main
    // domain where all your pages live.
    var site="http://www.popularwoodworking.com/"
    // This is the thank you page, in wordpress this would be the page title,
    // This can be any url passed the site domain part of the url from above
    var thanksPage="/daily-updates-signup"
    // This defines the user email to be sent to the thank you page,
    // This should not be changed
    var userDirect="?user="
    // This is the final url with the users email address added in.
    // This variable should not be changed.  The final will look like below
    // http://dev1.fwmedia.com/newsletter-registration?user=shane.stout%40.com
    var redirecturl=site+thanksPage+userDirect+encodeURIComponent(emailID.value)
    // This sets the thank you page element in the html, this should not be
    // changed.
    document.getElementById('thx').value=redirecturl
    // This returns true so the form will be submitted.
    return true
  }

