$(document).ready(function(){
  $("input._email").removeAttr("disabled");

	$("input._email").focus(function() {
		if(this.value == "e-mail") {
			this.value = "";
		}
    if (this.value != $(this).attr("alt")) {
      $(this).css("color","#000");
    }else{
      $(this).css("color","#ccc");
    }
	})
  
  $("input._email").blur(function() {
		if(!this.value.length) {
			this.value = $(this).attr("alt");
		}
    if (this.value != $(this).attr("alt")) {
      $(this).css("color","#000");
    }else{
      $(this).css("color","#ccc");
    }
	})
  
  $("input._email").change(function(){
    if (this.value != $(this).attr("alt")) {
      $(this).css("color","#000");
    }else{
      $(this).css("color","#ccc");
    }
  });
  
  
  //on email submit
  $("#dailyphrase").submit(function(){
    homePagePodSignup();
    return false;
  });
  
})



/**
 * 
 */
function homePagePodSignup(event){

  //event.preventDefault();
  hp_onEmailSignup();
  

  var email_address = $("input#email-pod").val();
  var pattern = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}$/;
  var not_valid = false;
        
  if(pattern.test(email_address) == false)
  {
    $("input#email-pod").css('borderColor', 'red');
    $("div#emailErrIE").show();
    not_valid = true;
  }
  else
  {
    $("div#emailErrIE").hide();
    $("input#email-pod").css('borderColor', 'black');
  }
	
  if ($("#edit-policy-check").attr('checked') == false)
  {
    $("#policyErr").show();
    not_valid = true; 
  }
  else
  {
    $("#policyErr").hide();
  }
        
  if(not_valid == true)
  {
    return false;
  }


  $.ajax({
    dataType: 'json',
    type: "POST",
    url: '/podsub',
    data: {
      email: email_address,
      agree: 'true'
    },
    success: function(data)
    {
      if (data.success) {
//        showLightBox("podthankyou_overlay",720,100);
        showLightBox("podfeedback",662,480,true);
        $("#edit-policy-check").removeAttr('checked');
        $("input#email-pod").val('')
      }else{
        alert(data.message);
      }
    },
    error: function()
    {
      alert("An error occurred. Please try again");
    }
  });
  return true
}

