/**
 * default.js
 *
 * Version history (please keep backward compatible):
 * 1.0, 2009-07-30: Cornelius Hansjakob
 *
 * @author Cornelius Hansjakob <cha@massiveart.com>
 * @version 1.0
 */

Default = Class.create({

  initialize: function() {   
    this.reValue = false;
  },
  
  /**
   * toggleElement
   */
  toggleElement: function(elementId, dblDuration){
    if(typeof(dblDuration) == 'undefined'){
      dblDuration = 0.2;   
    }
    if($(elementId)){
      if($(elementId).style.display == 'none'){
        Effect.SlideDown(elementId, {duration: dblDuration});
      }else{
        Effect.SlideUp(elementId, {duration: dblDuration});
      }
    }
  },
  
  /**
   * submitForm
   */
  submitForm: function(formId){
    if($(formId)){
      
      /**
       * validation
       */
      this.retValue = true;
      
      this.validateInput('fname');
      this.validateInput('sname');
      this.validateInput('mail');
      this.validateInput('infos');
      
      if(this.retValue == true) {
	      if($('noticebox')) $('noticebox').hide();
	      //this.addBusyClass('divFormButton');
	      
	      /**
	       * serialize form
	       */
	      var serializedForm = $(formId).serialize();
	      
	      new Ajax.Request($(formId).readAttribute('action'), {
	        parameters: serializedForm,
	        evalScripts: true,
	        onComplete: function(transport) {         
	          //this.removeBusyClass('divFormButton');
	          this.toggleElement('divEventForm', 0.5);
	          if($('succesbox')){	            
	            $('succesbox').appear();;
	            setTimeout('$("succesbox").fade()', 1500);
	          }    
	        }.bind(this)
	      });
	    }else{
	      //this.removeBusyClass('divFormButton');
        if($('noticebox')) $('noticebox').show();
	  }
    }
  },
  
  /**
   * validateInput
   */
  validateInput: function(element, baseValue) {
    if(($(element) && $F(element).blank()) || $F(element) == baseValue){
      $(element).addClassName('missinginput');
      this.retValue = false;
    }else{
      $(element).removeClassName('missinginput');
    }
  },
  
  /**
   * changeTestMode
   */
  changeTestMode: function(status){
    new Ajax.Request('/zoolu-website/testmode/change', {
      parameters: { TestMode: status },
      evalScripts: true,
      onComplete: function(transport) {         
        window.location.href = window.location.href;
      }.bind(this)
    });
  },
  
  /**
   * addBusyClass
   */
  addBusyClass: function(busyElement, blnDisplay) {
    if($(busyElement)){
      $(busyElement).addClassName('busy');
      if(blnDisplay) $(busyElement).show();
    }
  },

  /**
   * removeBusyClass
   */
  removeBusyClass: function(busyElement, blnDisplay) {
    if($(busyElement)){
      $(busyElement).removeClassName('busy');
      if(blnDisplay) $(busyElement).hide();
    }
  }
  
});
