﻿$(document).ready(function() {
  /* Lightbox activeren */
  $(".lightbox").lightbox();

  /* Carousel op home activeren */
  var deinnerfade = $('#home_images').innerfade({
    speed: 'slow',
    timeout: 10000,
    type: 'sequence',
    containerheight: '242px'
  });
});

var previd = '';
function showpic(id, defaultid) {
  if (id == previd) {
    return;
  }
  document.getElementById(id).parentNode.className  = "lightbox eerste";
  //alert(id);
  document.getElementById(id).style.display = "block";
  document.getElementById(id).style.top = "0px";
  if (previd != '')
    document.getElementById(previd).parentNode.className  = "lightbox hidden";
  else if (defaultid && defaultid != '')
  {
    document.getElementById(defaultid).parentNode.className  = "lightbox hidden";
  }
  window.status = id;
  previd = id;
}

function zoek(){
  var inpZoek = document.getElementById('zoekstring');
  var strZoek = inpZoek.value;
  if(strZoek.length>0){
    strZoek = escape(strZoek);
    strZoek = strZoek.replace(/ /g,'+').replace(/\%20/g,'+');
    document.location.href = '/pages/pagina.aspx?zoek=' + strZoek;
  }
}

function textFieldFocus(object, defaultValue) {
  if (object.value == defaultValue) {
    object.value = "";
  }
}

function textFieldBlur(object, defaultValue) {
  if (object.value == "") {
    object.value = defaultValue;
  }
}

function openPopup(el)
{
  closePopups(el.parentNode)
  el.getElementsByClassName('uitgelicht')[0].style.display = 'block';
}

function closePopups(el)
{
  for(i=0;i<el.getElementsByClassName('uitgelicht');i++)
  {
    el.getElementsByClassName('uitgelicht')[i].style.display = 'none';
  }
}

function closePopup(el)
{
  el.getElementsByClassName('uitgelicht')[0].style.display = 'none';
}

function copydivinputs(from,to)
{
  var finputs = document.getElementById(from).getElementsByTagName('input');
  var tinputs = document.getElementById(to).getElementsByTagName('input');
  for(i=0;i<finputs.length;i++)
  {
    tinputs[i].value = finputs[i].value;
  }
}

function rndrWinkelwagenTotaal(totaal)
{
  if(document.getElementById("winkelwagentotaal") && totaalbedrag)
  {
    $("#winkelwagentotaal").html(totaal);
  }
}

function rndrCurrentProduct(el,xml)
{
  //$(el.parentNode).children("subtotaalprijs").html();
  $(el).parent().parent().find(".td_totalen").html($("shoppingbasket", xml).find("subtotaalprijsexclbtw").text());
 // document.getElementById("korting").innerHTML = $("shoppingbasket", xml).find("kortingexclbtw").text();
  $("#totaalprijs").html($("shoppingbasket", xml).find("totaalexclbtw").text());
}

function ajaxError(type)
{
  //alert('Error loading XML document');
}

function addProduct(productid) {
  $.ajax({
    url: '/pages/ajaxwinkelwagen.aspx?action=add&product='+productid,
    type: 'GET',
    dataType: 'xml',
    timeout: 9000,
    error: function(){
        ajaxError();
    },
    success: function(xml){
      //rndrWinkelwagenTotaal($("shoppingbasket", xml).find("totaalexcl").text());
      document.location.href="/pages/pagina.aspx?type=winkelwagen"
    }
  });
}

function removeProduct(el,productid)
{
    $.ajax({
    url: '/pages/ajaxwinkelwagen.aspx?action=remove&product='+productid,
    type: 'GET',
    dataType: 'xml',
    timeout: 9000,
    error: function(){
        ajaxError();
    },
    success: function(xml){
      //rndrWinkelwagenHeader($("shoppingbasket", xml).find("header").text(),$("shoppingbasket", xml).find("aantal").text());
      rndrWinkelwagenTotaal($("shoppingbasket", xml).find("totaalexcl").text());
      rndrCurrentProduct(el,xml);
      //el.parentNode.parentNode.style.display = 'none';
      //$("#winkelwagenmelding").html($("shoppingbasket", xml).find("melding").text());
      document.location.href = document.location.href;
    }
  });
}

function updateProduct(el,productid,aantal)
{
    if((aantal < 0) || (aantal > 99999))
    {
      return;
    }
    $.ajax({
    url: '/pages/ajaxwinkelwagen.aspx?action=update&aantal=' + aantal + '&product=' + productid,
    type: 'GET',
    dataType: 'xml',
    timeout: 9000,
    error: function(){
        ajaxError();
    },
    success: function(xml){
      //rndrWinkelwagenHeader($("shoppingbasket", xml).find("header").text(),$("shoppingbasket", xml).find("aantal").text());
      rndrWinkelwagenTotaal($("shoppingbasket", xml).find("totaalexcl").text());
      rndrCurrentProduct(el,xml);
    }
  });
}

function emptyShoppingbasket()
{
  $.ajax({
  url: '/pages/ajaxwinkelwagen.aspx?action=empty',
    type: 'GET',
    dataType: 'xml',
    timeout: 9000,
    error: function() {
      ajaxError();
    },
    success: function(xml) {
      //rndrWinkelwagenHeader($("shoppingbasket", xml).find("header").text(),$("shoppingbasket", xml).find("aantal").text());
      //rndrWinkelwagenTotaal($("shoppingbasket", xml).find("totaalexcl").text());
      document.location.href = document.location.href;
    }
  });
}


//functies Zoekpagina (aga)
// Standaardwaarde van tekstveld verbergen onFocus (en css-class aanpassen)
function textFieldFocus(object, defaultValue) {
  if (object.value == defaultValue) {
    object.value = "";    
  }
  object.className = "active";
  document.getElementById("txtZoekWoorden").style.color = "#000000";
}

// Standaardwaarde van tekstveld herstellen onBlur (en css-class aanpassen)
function textFieldBlur(object, defaultValue) {
  if (object.value == "") {
    object.value = defaultValue;    
  }
  object.className = "";
}

function zoek(zoekUrl, strNegeerwaarde) {
  if (document.getElementById("txtZoekWoorden").value.length > 0 && document.getElementById("txtZoekWoorden").value != strNegeerwaarde){
  //alert(zoekUrl + "&productzoek=" + document.getElementById("txtZoekWoorden").value);
    window.location = zoekUrl + "&productzoek=" + document.getElementById("txtZoekWoorden").value;
    return false;
  }
  else {
  document.getElementById("txtZoekWoorden").style.color = "#dd0000";
  return false;
  }
}