/**
 * FormSignup
 */
var FormSignup = Class.create({
  /**
   * Init FormSignup
   */
  initialize: function() {
	this.options = Object.extend({
	  elemContent : null
	}, arguments[0] || { });		
	
	this.strDialog = "emailsignup";

    this.elemErr = this.options.elemContent.select('.err')[0];
	this.elemMsgField = this.options.elemContent.down('.msg');
	this.elemForm = this.options.elemContent.down('form');
	
	this.strServerURL = "server/index.php?contenttype=sendemail";
	
    // add field validation
    var email = new Spry.Widget.ValidationTextField("formemail", "none", {validateOn:["change"], additionalError: 'Callback_additionalErrorZone_complete'});
  },
  
  sendEmail: function(strFrom) {
    var strURL = this.strServerURL + "&content=" + this.strDialog;
    new Ajax.Request(strURL, {
      parameters: $(strFrom).serialize(true),
      method:'post',
      onSuccess: function(response) {
      }.bind(this),
      onFailure: function(response) {
      }.bind(this)
    });
  },
  
  submit: function() {
    var strForm = this.elemForm.getAttribute('id');
	  
    var ret = Spry.Widget.Form.validate($(strForm));	
    if (ret) {
      this.elemErr.style.visibility = "hidden";
      this.sendEmail(strForm);
      
   	  this.elemMsgField.style.visibility = "visible";
      this.elemMsgField.style.display = "inline";
	}
	else {
	  this.elemErr.style.visibility = "visible";
	}	 
  }

});

