﻿function Juice_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}


function addProducts(id) {
    location.href = '/Winkelmandje.aspx?productid=' + id;    
}

function aantallenAanpassen(aantalveld){
    if (aantalveld.value!='') {
		Juice_findObj('mode').value='aantallenaangepast';
		url = document.location;
		document.aspnetForm.action = url;
		setTimeout("document.aspnetForm.submit();",500);	     
	}
}

function CheckBestelForm() {    
    if (document.getElementById('verzendadres_ophaal_locatie_container_select').style.display == '') {
        Juice_validateForm('voorletters', '', 'R', 'achternaam', '', 'R', 'huidigadres', '', 'R', 'postcode', '', 'R', 'plaats', '', 'R', 'telefoon1', '', 'R', 'e-mailadres', '', 'RisEmail', 'checkbox', '', 'R', 'AfhaalLocatie', '', 'R');
    }
    else {
        Juice_validateForm('voorletters', '', 'R', 'achternaam', '', 'R', 'huidigadres', '', 'R', 'postcode', '', 'R', 'plaats', '', 'R', 'telefoon1', '', 'R', 'e-mailadres', '', 'RisEmail', 'checkbox', '', 'R');
    }    
    if (document.Juice_returnValue)
        submitform();
}

function Juice_validateForm() { //v4.0
  if (document.validatemessage==undefined) 
    document.validatemessage = 'Er zijn problemen gevonden, vult u de gekleurde velden a.u.b. correct in.';
  var kleur = 'FF0000';
  if (document.veldkleur!=undefined)
    kleur = document.veldkleur;
  var i,p,q,r,nm,test,num,min,max,errors='',args=Juice_validateForm.arguments;
  
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=Juice_findObj(args[i]);
    if (val) { 
        if (val.type=='checkbox') {
            if (val.checked==false) {
                document.validatemessage += "\nU heeft nog geen akkoord op de leveringsvoorwaarden gegeven.\n";
                errors+='- U heeft nog geen akkoord op de leveringsvoorwaarden gegeven.\n';
               }
        }
    nm=val.name; if ((val=val.value)!="") {
    if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        r=val.indexOf('.');
        if (r<1 || p<1 || p==(val.length-1)) {Juice_findObj(nm).style.backgroundColor=kleur; Juice_findObj(nm).value='geen geldig e-mail adres'; errors+='- '+nm+' bevat geen geldig e-mail adres.\n';}
      } else if (test!='R') { num = parseFloat(val);
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') {Juice_findObj(nm).style.backgroundColor=kleur; errors += '- '+nm+' is niet ingevuld.\n';} }
  } if (errors) {
    if (document.validatemessage!='niettonen')
       alert(document.validatemessage);
      }
  document.validatemessage = 'Er zijn problemen gevonden, vult u de gekleurde velden a.u.b. correct in.';
  document.Juice_returnValue = (errors == '');
}

function Juice_SelecteerVeld(veld) {
   veld.style.backgroundColor='FFFFFF';
}

function Juice_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=Juice_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function ChangeVerzendAdres(blok,val) {
if (blok == 'lever')
    {
    switch(val)
        {
            case 'leveringgelijk':
                document.getElementById('verzendadres_ophaal_locatie_container_select').style.display = 'none';
                document.getElementById('verzendadres_ander_adres_container').style.display = 'none';
                document.getElementById('verzendadres_gelijk_adres_container').style.display = '';
                if (document.getElementById('land').value != 'Nederland') {
                    document.getElementById('bezorgkosten1').innerHTML = 'Let op: Bezorgkosten zijn &euro; 75,-';
                }
                break;
            case 'leveringanders':
                document.getElementById('verzendadres_ophaal_locatie_container_select').style.display = 'none';
                document.getElementById('verzendadres_ander_adres_container').style.display = '';
                document.getElementById('verzendadres_gelijk_adres_container').style.display = 'none';
                if (document.getElementById('land2').value != 'Nederland') {
                    document.getElementById('bezorgkosten2').innerHTML = 'Let op: Bezorgkosten zijn &euro; 75,-';
                }
                break;
            case 'afhalen':
                document.getElementById('verzendadres_ophaal_locatie_container_select').style.display = '';
                document.getElementById('verzendadres_ander_adres_container').style.display = 'none';
                document.getElementById('verzendadres_gelijk_adres_container').style.display = 'none';
                break;
            case 'land': //Land veranderd
                if (document.getElementById('land').value == 'Nederland') {
                    document.getElementById('bezorgkosten1').innerHTML = 'Let op: Bezorgkosten zijn &euro; 15,-';
                }
                else {
                    document.getElementById('bezorgkosten1').innerHTML = 'Let op: Bezorgkosten zijn &euro; 75,-';
                }
            case 'land2': //Verzend land veranderd
                if (document.getElementById('land2').value == 'Nederland') {
                    document.getElementById('bezorgkosten2').innerHTML = 'Let op: Bezorgkosten zijn &euro; 15,-';
                }
                else {
                    document.getElementById('bezorgkosten2').innerHTML = 'Let op: Bezorgkosten zijn &euro; 75,-';
                }       
        }
    }
else
    {
    switch(val)
        {   
            case 'factuurgelijkhuidig':
                document.getElementById('factuuradres_verzend_adres_container').style.display = 'none';
                break;    
            case 'factuurgelijklevering':
                document.getElementById('factuuradres_verzend_adres_container').style.display = 'none';
                break;    
            case 'factuuranders':
                document.getElementById('factuuradres_verzend_adres_container').style.display = '';
                break;
        }
    }
}

function submitform()
{    
    var theForm = document.forms['aspnetForm'];
    if (!theForm) {
        theForm = document.aspnetForm;
    }
    theForm.submit();      
//  document.aspnetForm.submit();
}

function changeshowroominfo() {
    element = document.getElementById("AfhaalLocatie");
    for (i = 0; i < element.options.length; i++) {
        elmvalue = element.options[i].value;
        elm = document.getElementById(elmvalue);
        if (elm) {
            $("#" + elm.id).hide();
            if (elmvalue == document.getElementById("AfhaalLocatie").value) {
                $("#" + elm.id).show();
            }
        }
    }
}

function hideDefaultHidden() {
    $(".hideMe").each(function(i) {
        $(this).hide();
    });
}

$(function(){
		   initMenu();
});

// Menu
var $timeout = false;
function initMenu()
{    
    // Submenu hiden
    $(".subnav").hide();
    
    $(".subnav").hover(
                    function(){
                        clearTimeout($timeout);
                    },function(){
                        $timeout = setTimeout(menuHide, 500);
                    });
    
    // Hover instellen
    $(".sub").hover(
                    function(){
                        // Timeout clearen indien nodig
                        clearTimeout($timeout);
                        
                        // Remove selection
                        menuRemoveSelected();
                        
                        // Hide alle submenu's
                        $(".subnav").hide();
                        
                        // Make me hover!
                        menuSelect($(this));
						
                        $parentPos = $(this).position();
								
                        // Activate sub menu
						$("." + $(this).attr("rel"))
							.css({left : $parentPos.left})
								.show();
                    },
                    function(){
                        $timeout = setTimeout(menuHide, 500);
                    });  
}

function menuRemoveSelected()
{
    // Back to basic
    $(".sub").removeClass("hover");
}

function menuHide()
{
    // Remove selection
    menuRemoveSelected();
    
    // Submenu hiden
    $(".subnav").hide();
}
function menuSelect($obj)
{
   $($obj).addClass("hover");
}