// -------------------------------------------------------------------------------------------------
// String-concatenation in IE is very slow if the concatenated variable is going to be quite long
// Instead of using : _variable += 'whatever text' + counter
//         now use  : _variable.append('whatever text' + counter);
// Has over 80% performance improvement in IE.
//
// www.steware.nl
// -------------------------------------------------------------------------------------------------

function StringBuffer() {
  this.buffer = [];
}

StringBuffer.prototype.append = function (str) {
  this.buffer.push(str);
  return this;
}

StringBuffer.prototype.toString = function () {
  return this.buffer.join("");
}

var bColorOver = "#bccdd2";
var tColorOver = "#ffffff";


var MKBmain = function() {
  var req = "";
  var glbOpacity = 0;
  var glbIntvalY = 0;

  var menuArray = [
    {itemSrt: "H" , itemTxt: "Over ons &#187;"                  , itemUrl: "over_ons.htm"                        },
    {itemSrt: "B"                                                                                                },
    {itemSrt: "H" , itemTxt: "Algemeen"                         , itemUrl: ""                                    },
    {itemSrt: "S" , itemTxt: "Algemene gegevens"                , itemUrl: "algemene_gegevens.htm"               },
    {itemSrt: "S" , itemTxt: "Adres gegevens"                   , itemUrl: "adres_gegevens.htm"                  },
    {itemSrt: "S" , itemTxt: "Leveringsvoorwaarden"             , itemUrl: "leverings_voorwaarden.htm"           },
    {itemSrt: "B"                                                                                                },
    {itemSrt: "H" , itemTxt: "Diensten / Produkten"             , itemUrl: ""                                    },
    {itemSrt: "S" , itemTxt: "Aanbod diensten"                  , itemUrl: "aanbod_diensten.htm"                 },
    {itemSrt: "S" , itemTxt: "Administratiepakket - Basis"      , itemUrl: "administratiepakket_basis.htm"       },
    {itemSrt: "S" , itemTxt: "Administratiepakket - Uitgebreid" , itemUrl: "administratiepakket_uitgebreid.htm"  },
    {itemSrt: "S" , itemTxt: "Maatwerk"                         , itemUrl: "maatwerk.htm"                        },
    {itemSrt: "S" , itemTxt: "Salarisadministratie"             , itemUrl: "salarisadministratie.htm"            },
    {itemSrt: "S" , itemTxt: "Snelstart Software"               , itemUrl: "snelstart_software.htm"              },
    {itemSrt: "B"                                                                                                },
    {itemSrt: "H" , itemTxt: "Contact  &#187;"                  , itemUrl: "contact.htm"                         }
  ];

  
  return {

	// ---------------------------------------------------------------------------------------------
    // Attach events
    // ---------------------------------------------------------------------------------------------
    attachAllEvents: function() {
      //document.getElementById("idLogin").onclick = MKBmain.login;
    },

    login: function() {
      //alert('Login');
	},

    loadContent: function(_url) {
      var _newurl = MKBmain.addRandomToURL(_url);
	  var _obj    = top.document.getElementById("content")
	  _obj.style.display = "none";
	  _obj.src = _newurl;

      if (document.all) {
        _obj.style.filter  = "alpha(opacity=0)";
      }
      else {
        _obj.style.opacity  = 0;
      }
    },

    // ---------------------------------------------------------------------------------------------
    // Create menu items
    // ---------------------------------------------------------------------------------------------
    createMenu: function() {
      var _str = new StringBuffer();
      for (var i=0; i < menuArray.length; i++) {
        if (menuArray[i].itemSrt == "B") {
          _str.append( '<div class="seperator">&nbsp;</div>');
		}
        else {
          _str.append( MKBmain.getMenuString(menuArray[i].itemSrt , menuArray[i].itemTxt , menuArray[i].itemUrl) );
        }
	  }
      document.getElementById("menu").innerHTML = _str;
      MKBmain.resizeObjects();
	},


	// ---------------------------------------------------------------------------------------------
    // Return per menuitem string
    // ---------------------------------------------------------------------------------------------
    getMenuString: function(itemSoort, itemText, _source) {
      var _str    = new StringBuffer();
      var _class  = (itemSoort == "H") ? "menuitem" : "submenuitem";
      var _cursor = (_source   != "" ) ? "pointer"  : "normal";

      _str.append('<div style="cursor:' + _cursor + ';" class = "' + _class + ' hliteoff" ');
      if (_source != '') {
        _str.append(' onmouseover = "this.className=\'' + _class + ' hliteon\'"  ');
        _str.append(' onmouseout  = "this.className=\'' + _class + ' hliteoff\'" ');
        _str.append(' onclick     = "MKBmain.loadContent(\'' + _source + '\', \'content\');"');
      }
      //alert(_str);
      _str.append('>' + itemText + '</div>');
      return _str;
    },


    // ---------------------------------------------------------------------------
    // Check if frame has been loaded ...
    // ---------------------------------------------------------------------------
    isFinishedLoading: function() {
      var _obj    = document.getElementById("content")
      MKBmain.changeOpacity();
      _obj.style.display = "inline";
    },


	// ------------------------------------------------------------------------------------------------
    // Show page slowly
    // ------------------------------------------------------------------------------------------------
    changeOpacity: function () {
      glbOpacity = 0;
      if (glbIntvalY != 0)  clearInterval(glbIntvalY);
      glbIntvalY = setInterval("MKBmain.changeOpacityContinue()", 24);
    },



    // ------------------------------------------------------------------------------------------------
    // Continue change opacity of 2 layers
    // ------------------------------------------------------------------------------------------------
    changeOpacityContinue: function() {
      var _obj  = top.document.getElementById("content");

      if (document.all) {
        _obj.style.filter = "alpha(opacity=" +  glbOpacity  + ")";
        glbOpacity = glbOpacity + 20;
      }
      else {
        _obj.style.opacity = glbOpacity / 100;
        glbOpacity = glbOpacity + 20;
      }
      
	  if (glbOpacity >= 110) {
        clearInterval(glbIntvalY);
        if (document.all) {
          _obj.style.removeAttribute("filter") ;    // Remove filter, otherwise clearType font is disrupted
          return;
        }
      }
    },

    // ---------------------------------------------------------------------------
    // Add random value to URL to make unique
    // ---------------------------------------------------------------------------
    addRandomToURL: function(_url) {
      var _split    = _url.split('?');
      var _random   = Math.random();
      if(_split.length > 1) return _url + "&RANDOMISER=" + _random;
      return _url + '?RANDOMISER=' + _random;
    },

    // ---------------------------------------------------------------------------
    // Resize objects
    // ---------------------------------------------------------------------------
    resizeObjects: function() {
      var _totalHeight = Number(document.body.clientHeight);
	  var _corrHeightIframe = (document.all) ? 153 : 143;
      var _corrHeightMenu   = (document.all) ? 52  : 76;


	  var _newHeight   = (_totalHeight - _corrHeightIframe < 0) ? 100 : (_totalHeight - _corrHeightIframe);
      document.getElementById("content").style.height = _newHeight;
      document.getElementById("menu").style.height    = _newHeight - _corrHeightMenu;
    }
  }

}();







// -------------------------------------------------------------------------------------------------
// Check and if OK submit form
// -------------------------------------------------------------------------------------------------
var _errorField = '';

function submitContact() {
  var bln1 = checkVerplichteVelden();

  if (typeof(getRadioValue('fld_geslacht')) == 'undefined') {
    document.getElementById('idGeslacht').style.backgroundColor = bColorOver;
    var bln2 = false;
  }
  else {
    document.getElementById('idGeslacht').style.backgroundColor = tColorOver ;
    var bln2 = true;
  }


  if (bln1 == false || bln2 == false) {
    var strMsg = "";
    strMsg += "Niet alle verplichte velden zijn ingevoerd \n\n";
    strMsg += "U kunt deze alsnog invullen / aanvullen\n\n\n";
    alert(strMsg);
  }
  else {
    document.frmContact.submit();
  }
}


// ---------------------------------------------------------------------------
// Check of verplichte velden een waarde hebben
// ---------------------------------------------------------------------------
function checkVerplichteVelden() {
  var tmpBln = true;
  allFlds = document.getElementsByTagName('input');
  for (var i=0; i < allFlds.length; i++) {
    if (allFlds[i].getAttribute('verplicht') != null) {
      if (allFlds[i].value == '') {
        allFlds[i].style.backgroundColor = bColorOver ;
        tmpBln = false;
      }
      else {
        allFlds[i].style.backgroundColor = "#ffffff" ;
      }
    }
  }
  return tmpBln;
}


// ---------------------------------------------------------------------------
// Return checked-value van radiobutton
// ---------------------------------------------------------------------------
function getRadioValue(radioName) {
   var collection;
   collection = document.all[radioName];
   for (i=0;i<collection.length;i++) {
     if (collection[i].checked)
     return(collection[i].value);
   }
}

