/**
 * Solves the problem that IE has with button tags
 * Autor: Jano
 * Date: 03/04/2006
 * Use: Add the script to the page.
 */
(function() {
  var fixes={
    fixButtonTags:function(){
      var els= document.getElementsByTagName('button'), el, i;
      for(i=0;i<els.length;i++) {
        el= els[i];
        if(el.form==null) continue;
        el.onclick=this.wrap(el.onclick,this.fixb);
        if(!el.form._initiated) {
          el.form._initiated= true;
          el.form.onsubmit= this.wrap(el.form.onsubmit,this.fixf);
        }
      }
      els=el=i= null;
    },
    wrap:function(func,fix){
      if(func!=null) {
        return function() {
          var res= func.call(this);
          if(res!=false) fix.call(this);
          if(typeof(res)!='undefined') return res;
        };
      } else return fix;
    },
    fixb:function(){
      this.form._selected= this;
    },
    fixf:function(){
      var el= this._selected;
      if(el!=null) {
        if(el.attributes['value']) el.value=el.attributes['value'].value;
        this._selected= null;
      }
      var els= document.getElementsByTagName('button'), i;
      for(i=0;i<els.length;i++) {
        if(el!=els[i] && els[i].form==this) els[i].disabled= true;
      }
      el=els=i= null;
    }
  }
  // Check if fix is needed
  if(/MSIE/.test(navigator.userAgent) && !window.opera) {
    var doc= document;
    doc.attachEvent("onreadystatechange",function(){
      if(doc.readyState == "complete") fixes.fixButtonTags();
    });
  }
})();

