/**
 * Objet javascript permettant de gérer les données d'affichage
 * du "bloc" newsLetter.
 */
var NewsLetter = {

  // liste des elements HTML utilises
  elm_form:null,
  elm_forminput:null,
  email:null,

  getBeans: function() {
    return "ProfileViewBean;";
  },

  initJSON: function() {
  },

	init: function() {
		if (!this.initialized) {
      this.elm_form = $("news_form");
      this.elm_forminput = $("news_email");
      this.elm_formSubmit = $("news_submit");

      if (!!this.elm_form) {
        Event.observe(this.elm_forminput, "focus", this.onEmailChanged.bind(this));
        Event.observe(this.elm_form, "submit", this.onSubmit.bind(this));
      }
      
      }
    },
        
  rewrite: function() {

    this.init();

    var profileBean = viewBeans["ProfileViewBean"];
  
    if (!!this.elm_form) {
      if (profileBean && profileBean.email != "")
        this.elm_forminput.value = profileBean.email;
    }
    
  },
  
  onEmailChanged: function() {
   if (!!this.elm_form)
      this.elm_forminput.value = "";
  },
  
  onSubmit: function() {
    if (!!this.elm_form && this.email!=this.elm_forminput.value)
      this.elm_form.action = "/mailing_list.svlt?action=SUBSCRIBE&site=MEE|BUS;PMO,AEC&origine=WEB";
  }
  
}

core.push(NewsLetter);
