if(document.all) {
  document.nativeGetElementById = document.getElementById;
  document.getElementById = function(id) {
    var e = document.nativeGetElementById(id);
    if(e) {
      if(e.attributes['id'] && e.attributes['id'].value == id) return e;
      else for(var i=1; i<document.all[id].length; i++) if(document.all[id][i].id == id) return document.all[id][i];
    }
    return null;
  };
}

var $ = function(id) {
  return document.getElementById(id);
};



var utils = {
  get_xhttp_rq: function() {
    var o = false;
    try {
      o = new ActiveXObject('Msxml2.XMLHTTP');
    } catch(e) {
      try {
        o = new ActiveXObject('Microsoft.XMLHTTP');
      } catch(e) {
        o = new XMLHttpRequest();
    } }
    if(!o) alert("Unsupported Browser:/nBrowser does not support HTTP Request");
    return o;
  },
  
  basehref: function(){
    var bt = document.getElementsByTagName("base");
    return bt[0].href;
  },

  dlhref: function(b) {
    var u = document.location.href.split('/'), a = b == undefined ? 0 : b, e = document.location.href.substr(document.location.href.length-1,1);
    if(e == '/') u.pop();
    for(var i=0; i<b; i++) u.pop();
    return e == '/' || b > 0 ? u.join('/') + '/' : u.join('/');
  },
  
  remclass: function(classname, node) {
    if (!node) node = document.getElementsByTagName("body")[0];
    else if (typeof node == 'string') node = $(node);
    var e = node.getElementsByTagName("*");
    for (var i = 0; i < e.length; i++) {
      if (e[i].className.indexOf(classname) != -1) {
        var ca = e[i].className.split(' ');
        for (var j = 0; j < ca.length; j++) if (ca[j] == classname) ca[j] = "";
        nc = ca.join(' ');
        nc = nc.replace(/  /g, ' ');
        if (nc.substring(nc.length - 1, nc.length)) nc = nc.substring(0, nc.length - 1);
        e[i].className = nc;
    } }
  },
  
  qform: function(a, v, m, t) {
    var f = document.createElement('form');
    f.action = a.substr(0,1) != '/' ? a.substr(0,1) == '.' ? a.substr(1,1) == '.' ? utils.dlhref((a.split('../').length)-1) : utils.dlhref()+a.substr(2) : a : utils.basehref()+a.substr(1,a.length);
    f.method = m == undefined ? 'post' : m;
    f.style.margin = '0px';
    f.style.padding = '0px';
    for (var k in v) {
      var i = document.createElement('input');
      i.type  = 'hidden';
      i.name  = k
      i.value = v[k];
      f.appendChild(i);
    }
    if(t != undefined) {
      if(typeof(t) == 'object') {
        var w = window.open('','qform_popup','location=0,status=0,toolbar=0,resizable=0,width='+t.w+',height='+t.h);
        f.target = 'qform_popup';
      } else f.target = t;
    }
    document.body.appendChild(f);
    f.submit();
    if(w != undefined) w.focus();
  }
};



var shopcart = {
  added: {
    node:     'shopcart_added',
    timeout:  5000,
    interval: 65,
    step:     12,
    ft:       null,
    oh:       null,
    ie:       (/msie/i.test(navigator.userAgent) && !/opera/i.test(navigator.userAgent)),
    check: function() {
      if($(shopcart.added.node) !== null) {
        t = $(shopcart.added.node);
        if(shopcart.added.ie) {
          var b = t.currentStyle.backgroundImage.replace(/^url..(.+)..$/, '$1');
          if(/.+\.png$/i.test(b)) {
            var x = utils.get_xhttp_rq();
            x.open("HEAD", b.replace(/(.+)\.png$/i, '$1.jpg'), false);
            x.send();
            if(x.status != 200) {
              x.open("HEAD", b.replace(/(.+)\.png$/i, '$1.gif'), false);
              x.send();
              if(x.status == 200)  t.style.backgroundImage = "url('"+b.replace(/(.+)\.png$/i, '$1.gif')+"')";
            } else t.style.backgroundImage = "url('"+b.replace(/(.+)\.png$/i, '$1.jpg')+"')";
          }
          shopcart.added.oh = t.parentNode.innerHTML;
          t.style.filter = 'alpha(opacity=0)';
        } else t.style.opacity = '0.0';
        t.style.display = 'block';
        t.sc_fo = 0;
        shopcart.added.ft = setInterval('shopcart.added.fade('+shopcart.added.step+')', 50);
      }
    },
    fade: function(a) {
      var t = $(shopcart.added.node), v = t.sc_fo;
      if(v + a >= 100 || v + a <= 0) {
        if(a > 0) {
          if(shopcart.added.ie) {
            t.parentNode.innerHTML = shopcart.added.oh;
            t = $(shopcart.added.node);
            t.style.display = 'block';
          } else t.style.opacity = '1.0';
          t.sc_fo = 100;
          setTimeout(function(){shopcart.added.ft = setInterval('shopcart.added.fade(-'+a+')', 50);}, shopcart.added.timeout);
        } else t.style.display = 'none';
        clearInterval(shopcart.added.ft);
      } else {
        var n = v + a;
        t.sc_fo = n;
        if(shopcart.added.ie) t.style.filter = 'alpha(opacity='+n+')';
        else t.style.opacity = n > 10 ? '0.'+n : '0.0'+n;
  } } }
};

var form = {
  validate: function (f, p, t, n) {
    utils.remclass('form_err', f);
    var m = '',
        e1 = f.getElementsByTagName('input'),
        e2 = f.getElementsByTagName('select'),
        e3 = f.getElementsByTagName('textarea'),
        e = [];
    n = typeof(n) == "undefined" ? "Formerror:" : n;
    e = form._validate_sub(e1, p, t);
    e.merge(form._validate_sub(e2, p, t));
    e.merge(form._validate_sub(e3, p, t));
    for (i in p) if ( !! e[i]) m += typeof(t[i]) == "undefined" ? "\n- " + i : "\n- " + t[i];
    if (m !== '') {
      alert(n + m);
      return false;
    } else return true;
  },
  
  _validate_sub: function (e, p, t) {
    var m = {
          "merge": function (o) {
            for (i in o) this[i] = o[i];
        } },
        b = {};
    for (var i = 0; i < e.length; i++) if (typeof(e[i].name) != "undefined") {
      for (var j in p) if (j == e[i].name) {
        var r = new RegExp(p[j], 'm');
        if (e[i].type == "radio") {
          if (typeof(b[j]) == "undefined") b[j] = false;
          if (e[i].checked && r.test(e[i].value)) b[j] = true;
        } else if (!r.test(e[i].value)) {
          m[j] = true;
          e[i].className += ' form_err';
    } } }
    for (j in b) if (!b[j]) m[j] = true;
    return m;
  }
};

var spimg = function(e) {
  var e = !e ? window.event : e, s = e.srcElement ? e.srcElement : e.target;
  var t = $('pf_mimg');
  t.src = t.src.replace(/^(.+\/[0-9]+\/[0-9]+\/).+$/, "$1"+s.src.replace(/^.+\/[0-9]+\/[0-9]+\/(.+)$/, "$1"));
};

var toggle_slide = {
  attach: function(id) {
    var e = $(id), n = e.name, s = $(n);
    e.onclick = toggle_slide._toggle;
    if (!e.checked) s.style.display = 'none';
    else if(s.style.display == 'none') toggle_slide._slide(s, false);;
  },

  _toggle: function (e) {
    var e = !e ? window.event : e,
        t = e.srcElement ? e.srcElement : e.target,
        s = $(t.name);
    if (typeof s.intrv != 'undefined') clearInterval(s.intrv);
    t.blur();
    if (t.checked) toggle_slide._slide(s, false);
    else toggle_slide._slide(s, true);
  },

  _in: function (id) {
    var t = $(id);
    if (t.initheight - t.offsetHeight < 2) {
      t.style.height = t.initheight + 'px';
      clearInterval(t.intrv);
    } else t.style.height = Math.ceil(t.offsetHeight + ((t.initheight - t.offsetHeight) / 3)) + 'px';
  },

  _out: function (id) {
    var t = $(id);
    if (t.offsetHeight < 2) {
      t.style.display = 'none';
      clearInterval(t.intrv);
    } else t.style.height = Math.floor(t.offsetHeight - (t.offsetHeight / 3)) + 'px';
  },

  _slide: function (t, o) {
    if (typeof t.intrv != 'undefined') clearInterval(t.intrv);
    if (!o) t.style.visibility = 'hidden';
    t.style.display = 'block';
    if (typeof t.initheight == 'undefined') {
      t.initheight = t.offsetHeight;
      if (!o) t.style.height = '1px';
      t.style.overflow = 'hidden';
    }
    t.style.visibility = 'visible';
    if (!o) t.intrv = window.setInterval("toggle_slide._in('" + t.id + "')", 40);
    else t.intrv = window.setInterval("toggle_slide._out('" + t.id + "')", 40);
  }
}

var co_address_submit = function() {
  var f = $('co_address');
  if(typeof f.delivery != "undefined" && f.delivery.checked) {
    if(form.validate(f, {
      'contact[email]'      : "^[_a-z0-9-]+(?:\\.[_a-z0-9-]+)*@[a-z0-9-]+(?:\\.[a-z0-9-]+)*\\.[a-z]{2,4}$",
      'contact[company]'    : "[^'\"\\\\]{0,255}",
      'contact[gender]'     : "(0|1)",
      'contact[surname]'    : "[^'\"\\\\]{1,255}",
      'contact[first_name]' : "[^'\"\\\\]{1,255}",
      'contact[phone]'      : "^[/()+ 0-9-]{6,20}$",
      'contact[street]'     : "[^'\"\\\\]{1,255}",
      'contact[house_no]'   : "(?:[^'\"\\\\]*[0-9][^'\"\\\\]*){1,15}",
      'contact[addition]'   : "[^'\"\\\\]{0,255}",
      'contact[zip]'        : "(?:[0-9a-zA-Z ]*[0-9][0-9a-zA-Z ]*){4,15}",
      'contact[city]'       : "[^'\"\\\\]{1,255}",
      'contact[country_id]' : "[0-9]{1,3}",
      'gender'              : "(0|1)",
      'surname'             : "[^'\"\\\\]{1,255}",
      'first_name'          : "[^'\"\\\\]{1,255}",
      'phone'               : "^[/()+ 0-9-]{6,20}$",
      'street'              : "[^'\"\\\\]{1,255}",
      'house_no'            : "(?:[^'\"\\\\]*[0-9][^'\"\\\\]*){1,15}",
      'addition'            : "[^'\"\\\\]{0,255}",
      'zip'                 : "(?:[0-9a-zA-Z ]*[0-9][0-9a-zA-Z ]*){4,15}",
      'city'                : "[^'\"\\\\]{1,255}",
      'country_id'          : "[0-9]{1,3}"
    }, {
      'contact[email]'      : "E-Mail-Adres",
      'contact[company]'    : "Bedrijfsnaam",
      'contact[gender]'     : "Aanhef",
      'contact[surname]'    : "Achternaam",
      'contact[first_name]' : "Voornaam",
      'contact[phone]'      : "Telefoonnnummer",
      'contact[street]'     : "Straat",
      'contact[house_no]'   : "Huisnr",
      'contact[addition]'   : "Toevoegsel",
      'contact[zip]'        : "Postcode",
      'contact[city]'       : "Plaats",
      'contact[country_id]' : "Land",
      'gender'              : "Leveradres: Aanhef",
      'surname'             : "Leveradres: Achternaam",
      'first_name'          : "Leveradres: Voornaam",
      'phone'               : "Leveradres: Telefoonnnummer",
      'street'              : "Leveradres: Straat",
      'house_no'            : "Leveradres: Huisnr",
      'addition'            : "Leveradres: Toevoegsel",
      'zip'                 : "Leveradres: Postcode",
      'city'                : "Leveradres: Plaats",
      'country_id'          : "Leveradres: Land"
    }, "De volgende velden zijn niet volledig of incorrect ingevuld:")) f.submit();
  } else {
    if(form.validate(f, {
      'contact[email]'      : "^[_a-z0-9-]+(?:\\.[_a-z0-9-]+)*@[a-z0-9-]+(?:\\.[a-z0-9-]+)*\\.[a-z]{2,4}$",
      'contact[gender]'     : "(0|1)",
      'contact[surname]'    : "[^'\"\\\\]{1,255}",
      'contact[first_name]' : "[^'\"\\\\]{1,255}",
      'contact[phone]'      : "^[/()+ 0-9-]{6,20}$",
      'contact[street]'     : "[^'\"\\\\]{1,255}",
      'contact[house_no]'   : "(?:[^'\"\\\\]*[0-9][^'\"\\\\]*){1,15}",
      'contact[addition]'   : "[^'\"\\\\]{0,255}",
      'contact[zip]'        : "(?:[0-9a-zA-Z ]*[0-9][0-9a-zA-Z ]*){4,15}",
      'contact[city]'       : "[^'\"\\\\]{1,255}",
      'contact[country_id]' : "[0-9]{1,3}"
    }, {
      'contact[email]'      : "E-Mail-Adres",
      'contact[gender]'     : "Aanhef",
      'contact[surname]'    : "Achternaam",
      'contact[first_name]' : "Voornaam",
      'contact[phone]'      : "Telefoonnnummer",
      'contact[street]'     : "Straat",
      'contact[house_no]'   : "Huisnr",
      'contact[addition]'   : "Toevoegsel",
      'contact[zip]'        : "Postcode",
      'contact[city]'       : "Plaats",
      'contact[country_id]' : "Land"
    }, "De volgende velden zijn niet volledig of incorrect ingevuld:")) f.submit();
  }
  return false;
};

var fmss = function(f){
  return form.validate(f, {
    'first_name' : ".{1,255}",
    'surname'    : ".{1,255}",
    'email'      : "^[_a-z0-9-]+(?:\\.[_a-z0-9-]+)*@[a-z0-9-]+(?:\\.[a-z0-9-]+)*\\.[a-z]{2,4}$"
  }, {
    'first_name' : "Voornaam",
    'surname'    : "Achternaam",
    'email'      : "E-mail-Adres"
  }, "De volgende velden zijn niet, involledig of incorrect ingevuld:");
};

var co_confirm_submit = function(f) {
  var n = f.getElementsByTagName('input'), ok = true;
  for(i in n) if(typeof(n[i].name) != 'undefined') if(/confirm\[agree\].*/.test(n[i].name)) if(!n[i].checked) ok = false;
  if(ok) f.submit();
  else alert("Gaat u akkoord met de algemene voorwaarden?");
};

if (window.addEventListener) window.addEventListener('load', shopcart.added.check, false)
else window.attachEvent('onload', shopcart.added.check);
