  // Function to take the users address out of the url
  function getValues(name)
  {
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]")
    var regexS = "[\\?&#038;]"+name+"=([^&#]*)"
    var regex = new RegExp( regexS )
    var results = regex.exec( window.location.href )
    if( results == null )
      return ""
    else
      return decodeURIComponent(results[1])
  }
  // sets the users email to the two defined keys
  function setValues()
  {
    var userKey=getValues('user')
    document.getElementById('ETSubscriberKeyThx').value=userKey
    document.getElementById('EmailAddressThx').value=userKey
  }
  function echeckThx(thx_str)
  {
    var thx_at="@"
    var thx_dot="."
    var thx_lat=thx_str.indexOf(thx_at)
    var thx_lstr=thx_str.length
    var thx_ldot=thx_str.indexOf(thx_dot)
    var thx_message_str="You have entered an invalid email address.  Please try again."
    if (thx_str.indexOf(thx_at)==-1)
    {
      alert(thx_message_str)
      return false
    }
    if (thx_str.indexOf(thx_at)==-1 || thx_str.indexOf(thx_at)==0 || thx_str.indexOf(thx_at)==thx_lstr)
    {
      alert(thx_message_str)
      return false
    }
    if (thx_str.indexOf(thx_dot)==-1 || thx_str.indexOf(thx_dot)==0 || thx_str.indexOf(thx_dot)==thx_lstr)
    {
      alert(thx_message_str)
      return false
    }
    if (thx_str.indexOf(thx_at,(thx_lat+1))!=-1)
    {
      alert(thx_message_str)
      return false
    }
    if (thx_str.substring(thx_lat-1,thx_lat)==thx_dot || thx_str.substring(thx_lat+1,thx_lat+2)==thx_dot)
    {
      alert(thx_message_str)
      return false
    }
    if (thx_str.indexOf(thx_dot,(thx_lat+2))==-1)
    {
      alert(thx_message_str)
      return false
    }
    if (thx_str.indexOf(" ")!=-1)
    {
      alert(thx_message_str)
      return false
    }
    return true          
  }
  
  function isBlank(str) {
	  if(str == null || str == "") {
		  return true;
	  }
	  return false;
  }
  
  function isRequired(element) {
	  if(element != null) {
		  str = element.getAttribute("validate");
		  if(str == "required:true") {
			  return true;
		  }
	  }
	  return false;
  }
  
  //Validates address was entered
  function formCheck() {
	  var firstName = document.getElementById('first_name');
	  var lastName = document.getElementById('last_name');
	  var address1 =document.getElementById('address_1');
	  var address2 =document.getElementById('address_2');
	  var city = document.getElementById('city');
	  var state = document.getElementById('state');
	  var country = document.getElementById('country');
	  var postalCode = document.getElementById('postal_code');
	  
	  if(isRequired(firstName) && isBlank(firstName.value)) {
		  alert('First Name is required. Please try again.');
		  firstName.focus();
		  return false;
	  } 
	  if(isRequired(lastName) && isBlank(lastName.value)) {
		  alert ('Last Name is required. Please try again.');
		  lastName.focus();
		  return false;
	  }
	  if(isRequired(address1) && isBlank(address1.value)) {
		  alert ('Address 1 is required. Please try again.');
		  address1.focus();
		  return false;
	  }
	  if(isRequired(address2) && isBlank(address2.value)) {
		  alert ('Address 2 is required. Please try again.');
		  address2.focus();
		  return false;
	  }
	  
	  if(isRequired(city) && isBlank(city.value)) {
		  alert ('City is required. Please try again.');
		  city.focus();
		  return false;
	  }
	  
	  if(isRequired(state) && state.value == "Select a state") {
        if((country.value == "US" || country.value == "CA")) {
		  alert('State is required for US and CA. Please try again.');
		  state.focus();
		  return false;
        }
	  }
	  
	  if(isRequired(postalCode) && isBlank(postalCode.value)) {
        if((country.value == 'US' || country.value == 'CA')) {
		  alert('Postal Code is required for US and CA. Please try again.');
		  postalCode.focus();
		  return false;
        }
	  }
	  return true;
  }
  
  function ET_LongFormSubmit()
  {
    var emailObj=document.getElementById('EmailAddressThx')
    if ((emailObj.value==null)||(emailObj.value==""))
    {
      alert("You have entered an invalid email address.  Please try again.")
      emailObj.focus()
      return false
    }
    if (echeckThx(emailObj.value)==false)
    {
      emailObj.value=""
      emailObj.focus()
      return false
    }
    if(formCheck() == false) {
    	return false;
    }
    document.getElementById('ETSubscriberKeyThx').value=emailObj.value
    return true
  }

