

function radiovalue (form, name) {
  var setvalue = arguments[2]; 
  var elements = Form.getElements( $(form) ); 
  for (var i = 0; i < elements.length; i++) { 
    var e = elements[i]; 
    if( e.name == name ) { 
      if ( setvalue != null && (setvalue == e.value)) { 
        e.checked = true; 
      } 
      if ( e.checked ){ 
        return e.value; 
      } 
    } 
  } 
}

//declaring the class
var RadioWatcher = Class.create();

//defining the rest of the class implementation
RadioWatcher.prototype = {

  initialize: function(radioButton) {
    this.radioButton = $(radioButton);
    this.radioButton.onclick = this.showMessage.bindAsEventListener(this);
    if (radioButton == 'machtiging' || radioButton == 'overmaken') {
      this.display = radioButton + 'Info';
    } else {
      this.display = 'naw';
    }
  },

  showMessage: function(evt) {
     Element.hide('amountmessage');
     if (this.display == 'naw') {
       Element.hide('machtigingInfo','overmakenInfo');
       Effect.Appear($('naw'));
       if (this.radioButton.id == 'ideal') {
         Element.show('bankaccount');
         Element.hide('geefgratismessage');
         Element.hide('geefgratisbelasting');
       } else {
         Element.hide('bankaccount');
       }
       
       if (this.radioButton.id == 'creditcard') {
         Element.show('creditcardbrand');
         Element.show('geefgratismessage');
         new Effect.Highlight('geefgratismessage', {});
         Element.show('geefgratisbelasting');
         new Effect.Highlight('geefgratisbelasting', {});
       } else {
         Element.hide('creditcardbrand');
       }
       
       if (this.radioButton.id == 'telephone') {
         $('amount').value='1,30';
         $('amount').readOnly=true;
         Element.show('geefgratismessage');
         new Effect.Highlight('geefgratismessage', {});
         Element.show('geefgratisbelasting');
         new Effect.Highlight('geefgratisbelasting', {});
       } else {
         if ($('amount').readOnly) {
           $('amount').readOnly=false;
           $('amount').value='';
         }  
       }
       if (this.radioButton.id == 'creditcard') {
         Element.update('amountmessage','minimaal 20 euro en hele getallen');
         Element.show('amountmessage');
         new Effect.Highlight('amountmessage', {});
       }
       if (this.radioButton.id == 'wallie') {
         Element.update('amountmessage','minimaal 0,20 euro');
         Element.show('amountmessage');
         Element.show('geefgratismessage');
         Element.show('geefgratisbelasting');
         new Effect.Highlight('amountmessage', {});
         new Effect.Highlight('geefgratismessage', {});
         new Effect.Highlight('geefgratisbelasting', {});
       }
       if (this.radioButton.id == 'ideal') {
         Element.update('amountmessage','minimaal 5 euro en maximaal 15000 euro');
         Element.show('amountmessage');
         new Effect.Highlight('amountmessage', {});
       }
       
       
     } else if (this.display == 'machtigingInfo') {
       Element.hide('naw','overmakenInfo');
       Effect.Appear($(this.display));
       Element.hide('geefgratismessage');
       Element.hide('geefgratisbelasting');
     } else if (this.display == 'overmakenInfo') {
       Element.hide('naw','machtigingInfo');
       Effect.Appear($(this.display));
       Element.hide('geefgratismessage');
       Element.hide('geefgratisbelasting');
     }
  }
};


//declare class for anonymous checkbox watcher
var AnonWatcher = Class.create();

//defining the rest of the class implementation
AnonWatcher.prototype = {

  initialize: function() {
    this.anonCheckbox = $('anonymousButton');
    this.anonCheckbox.onclick = this.disableFields.bindAsEventListener(this);
  },

  disableFields: function(evt) {
    Element.hide($('nonAnonInfo'));
    Element.hide($('mailoptions'));
    Element.hide($('nawinfo'));
    //Element.toggle('anonText');
    //new Effect.Highlight('anonText', {})
  }
};

//declare class for mailtype checkbox watcher
var MailtypeWatcher = Class.create();

//defining the rest of the class implementation
MailtypeWatcher.prototype = {

  initialize: function(name) {
    this.mailtypeCheckbox = $(name);
    this.mailtypeCheckbox.onclick = this.disableFields.bindAsEventListener(this);
    if (name == 'mailtype') {
      this.display = 'mailoptions';
    } else {
      this.display = '';
    }
  },

  disableFields: function(evt) {
    if (this.display == 'mailoptions') {
      //Effect.Appear($('mailoptions'));
      Element.show('mailoptions')
    } else {
      Element.hide($('mailoptions'));
    }
    Effect.Appear($('nawinfo'));
    Effect.Appear($('nonAnonInfo'));
    
  }
};

Event.observe(window, 'load', init, false);

function init(){
  Try.these (
    function() {
      var watcher0 = new RadioWatcher('wallie');
      var watcher1 = new RadioWatcher('ideal');
      var watcher2 = new RadioWatcher('creditcard');
      var watcher3 = new RadioWatcher('telephone');
      var watcher4 = new RadioWatcher('machtiging');
      var watcher5 = new RadioWatcher('overmaken');
      var anonWatcher = new AnonWatcher();
      var mailtypeWatcher0 = new MailtypeWatcher('mailtype');
      var mailtypeWatcher1 = new MailtypeWatcher('mtypenone');

      var submittype = $('submittype');
      submittype.value = 'javascript';

    }
  )
}
