﻿
var timeout = 500;
var closetimer = 0;
var ddmenuitem = 0;
var parentli = 0
var menuitem = 0;

function jsddm_open() {
    jsddm_canceltimer();
    jsddm_close();
    ddmenuitem = $(this).find('ul').css('visibility', 'visible');
    parentli = $(this).find('a.scalafont').css('color', 'white');
    menuitem = $(this).addClass('MenuItemHover');
    //Cufon.replace('.scalafont', { hover: true });

}

function SetSlectedLanguage() {
    var opt = document.submitUserData.EcomOrderCustomerCountry.options;
    for (var i = 1; i < opt.length; i++) {
        if (opt[i].value == "<!--@Ecom:Order.Customer.Country-->") {
            opt[i].selected = true;
        }
    }

    opt = document.submitUserData.EcomOrderDeliveryCountry.options;
    for (var i = 1; i < opt.length; i++) {
        if (opt[i].value == "<!--@Ecom:Order.Delivery.Country-->") {
            opt[i].selected = true;
        }
    }
}

function jsddm_close() {
    if (ddmenuitem) ddmenuitem.css('visibility', 'hidden');
    if (parentli) parentli.css('color', 'black');
    if (menuitem) menuitem.removeClass('MenuItemHover');
    //Cufon.replace('.scalafont', { hover: true });
}

function jsddm_timer() {
    closetimer = window.setTimeout(jsddm_close, timeout); 
}

function jsddm_canceltimer() {
    if (closetimer) {
        window.clearTimeout(closetimer);
        closetimer = null;
    }
}

$(document).ready(function () {
    $('.UlMenu > li').bind('mouseover', jsddm_open)
    $('.UlMenu > li').bind('mouseout', jsddm_timer)

    jQuery('#mycarousel').jcarousel({
        "scroll": 1
        // Configuration goes here
    });

    //    $(".ProductOverzicht a").hover(function () {
    //        $(this).next("div").stop(true, true).animate({ opacity: "show", top: "0" }, "slow");
    //    }, function () {
    //        $(this).next("div").animate({ opacity: "hide", top: "0" }, "fast");
    //    });
    //    $(".ProductOverzicht a")( function () {
    //        $(this).next("div").stop().fadeTo('slow', 0);
    //    });

    //    $(".ProductOverzicht a").hover(
    //function () {
    //    $(this).next("div").css('display', 'inline');
    //    $(this).next("div").stop().fadeTo('slow', 1);
    //},
    //function () {
    //    $(this).next("div").stop().fadeTo('slow', 0);
    //});


//    $('.ProductOverzicht a')
//    .mouseenter(function () {
//            $(this).next("div").css('display', 'inline');
//            $(this).next("div").stop().fadeTo('slow', 1);
//    })
//    .mouseleave(function () {
//        //$(this).next("div").css('display', 'none');
//        $(this).next("div").stop().fadeTo('slow', 0);
//    });

//    var isHovering = $(this).next("div").is(fadeTo('slow', 0));

    //    alert("is hovering over div?: " + isHovering); 

    $('.productslider').mouseenter(function (e) {
            //$(this).children('a').children('img').animate({ height: '299', left: '0', top: '0', width: '450' }, 100);
        $(this).children('a').children('span').fadeTo('slow', 1);
        }).mouseleave(function (e) {
            //$(this).children('a').children('img').animate({ height: '332', left: '-20', top: '-20', width: '500' }, 100);
            $(this).children('a').children('span').fadeTo('slow', 0);
        });

    $('.Variants').selectbox();    

});


function MarkupPrice(ele) {
    var Price = document.getElementById(ele).innerHTML;
    var arrPrice = Price.split(',');
    if (arrPrice.length > 1) {
        document.getElementById(ele).innerHTML = "<span class='ProductPopupPriceLeft'>" + arrPrice[0] + ",</span><span class='ProductPopupPriceRight'>" + arrPrice[1] + "</span>";
    }
}

function MarkupDefaultPrice(ele) {
    var Price = document.getElementById(ele).innerHTML;
    var arrPrice = Price.split(',');
    if (arrPrice.length > 1) {
        document.getElementById(ele).innerHTML = "<span class='ProductDefaultPriceLeft'>" + arrPrice[0] + ",</span><span class='ProductDefaultPriceRight'>" + arrPrice[1] + "</span>";
    }
}


function LoadDropdown(ddl, AvailableCombinations, index) {
    if (parseInt(index) > 1) {
        $('#' + ddl).attr("disabled", true);
        $('#' + ddl).val("");
    }

    // alle items van dropdownlist doorlopen
    var sAvaibleCombinations = document.getElementById(AvailableCombinations).innerHTML;
    var items = parseInt($('option', $('#' + ddl)))
    var ItemsToRemove = new Array();

    var y = 0
    $('#' + ddl + ' option').each(function() {
//    for (var x = 0; x <= (items - 1); x++) {
        var ItemValue = $(this).val()
//        if ($('#' + ddl).get(0).options(x) != null) {
//            ItemValue = $('#' + ddl).get(0).options(x).value
//        } else {
//        }

        if (ItemValue != '') {
            if (sAvaibleCombinations.indexOf(ItemValue) >= 0) {
            }
            else {
                //var ValueToRemove = $('#' + ddl).get(0).options(x).value;
                // items toevoegen aan array om te verwijderen
                ItemsToRemove[y] = ItemValue;
                y++
            }
        }
    });
//    }

    for (i = 0; i < ItemsToRemove.length; i++) {
        $("option[value=" + ItemsToRemove[i] + "]").remove();
    }


}

function ChangeDropDown(ddl, AvailableCombinations, index) {
    var NextIndex = parseInt(parseInt(index) + 1);
    var NextDll = ddl.replace(index, NextIndex);
    var NextDllSmooth = ddl.replace(index, NextIndex) + "_input"
    //alert(NextDllSmooth + ' ' + index);
    if ($('#' + NextDll).length > 0) {

        //controleren of aangepaste dropdownlist wel een gekozen waarde heeft 
        var SelectedVal = $("#" + ddl).val();
        
        var ItemsToRemove = new Array();
        if (SelectedVal.indexOf('V') >= 0) { //aanhef dropdownlist heeft lege value, variant heeft altijd een value met V       

            // volgende dropdownlist beschikbaar maken
            $('#' + NextDll).removeAttr("disabled");
            $('#' + NextDllSmooth).removeAttr("disabled");

            var sAvailableCombinations = document.getElementById(AvailableCombinations).innerHTML;
            var Combinations = sAvailableCombinations.split(",");
            //alert(sAvailableCombinations);

            var foo = [];
            $('#' + NextDll + ' option').each(function() {
                //alert($(this).val());
            });
            //alert(foo);
            var options = $('option', $('#' + NextDll));
//            $('#' + NextDll + 'option').each(function (i) {
//                alert($(i).text());
//            });
            // alle items van dropdownlist doorlopen 
                       
//            var items = options.length
            var y = 0
//            for (var x = 0; x <= (items - 1); x++) {

            $('#' + NextDll + ' option').each(function () {
                var ItemValue = $(this).val()
                if (ItemValue != '') {
                    var Available = 'false'
                    for (var z = 0; z <= (Combinations.length - 2); z++) {
                        // controleren of combinatie van gekozen dropdownlist en huige item in variantcombinatie aanwezig zijn
                        if (Combinations[z].indexOf(ItemValue) >= 0 && Combinations[z].indexOf(SelectedVal) >= 0) {
                            // controleren of er voorraad is
                            var SplitCombi = Combinations[z].split("|");
                            var Stock = parseInt(SplitCombi[1]);
                            $(this).val(SplitCombi[0]);
                            if (parseInt(Stock) > 0) {
                                Available = 'true'
                            }

                        }
                    }
                    if (Available == 'false') {
                        var ValueToRemove = ItemValue;
                        ItemsToRemove[y] = ValueToRemove;
                        y++
                        //$("#" + NextDll)[0].remove(x);
                    }



                }

            });
//            }
            for (i = 0; i < ItemsToRemove.length; i++) {
                $("option[value=" + ItemsToRemove[i] + "]").remove();
            }
//            $("#" + ddl).selectbox();
        }

        else {
            $('#' + NextDll).attr("disabled", true);
            $('#' + NextDll).val("");
            $('#' + NextDllSmooth).attr("disabled", true);
            $('#ProdQuantity').attr("disabled", true);
            $('#ProdQuantity_input').attr("disabled", true);
            $('#ProdQuantity').val("");

            //$('#BtnToevoegen').attr("disabled", true);
            $('#BtnToevoegen').removeAttr("style");
            $('#BtnToevoegen').css("display", "none");
            $('#BtnToevoegenPassive').removeAttr("style");
            $('#BtnToevoegenPassive').css("display", "block");


        } // selected = V 
    } else {
        // bij wijzigen laatste dropdown mag aantal gekozen worden
        var SelectedVal = $("#" + ddl).val();       
        if (SelectedVal.indexOf('V') >= 0) {     
            $('#ProdQuantity').removeAttr("disabled");
            $('#ProdQuantity_input').removeAttr("disabled");
           
            document.getElementById("VariantID").value = SelectedVal.slice(1, SelectedVal.length - 1);            
        } else {
            $('#ProdQuantity').attr("disabled", true);
            $('#ProdQuantity_input').attr("disabled", true);
            $('#ProdQuantity').val("");
            //$('#BtnToevoegen').attr("disabled", true);
            $('#BtnToevoegen').removeAttr("style");
            $('#BtnToevoegen').css("display", "none");
            $('#BtnToevoegenPassive').removeAttr("style");
            $('#BtnToevoegenPassive').css("display", "block");
        }
    } // not next is null


} //end function


function AddToCart(ProductID) {
  document.getElementById(ProductID).submit()
}

function ChangeQuantity() {
    var Quantity = parseInt($('#ProdQuantity').val());   
    if (Quantity > 0) {
        //$('#BtnToevoegen').removeAttr("disabled");
        $('#BtnToevoegen').removeAttr("style");
        $('#BtnToevoegen').css("display", "block");
        $('#BtnToevoegen').css('cursor', 'pointer');
        $('#BtnToevoegen').css('cursor', 'hand');
        $('#BtnToevoegenPassive').removeAttr("style");
        $('#BtnToevoegenPassive').css("display", "none");
        document.getElementById("quantity").value = Quantity;
        document.getElementById("VariantID").value = $('#ProdSize').val();
    } else {
        //$('#BtnToevoegen').attr("disabled", true);
        $('#BtnToevoegen').removeAttr("style");
        $('#BtnToevoegen').css("display", "none");
        $('#BtnToevoegen').css('cursor', 'none');
        $('#BtnToevoegenPassive').removeAttr("style");
        $('#BtnToevoegenPassive').css("display", "block");
    }
}

function AddNewsLetterFunctions(ParagraphID, PageID) {
    $('#AccessUserName_' + ParagraphID).addClass('nieuwsbrief_naam');
    if ($('#AccessUserName_' + ParagraphID).val() == '') {
        $('#AccessUserName_' + ParagraphID).val("Achternaam");
    }
    $('#AccessUserName_' + ParagraphID).click(function(){ 
        RemoveText(this, 'Achternaam');
    }) 
    $('#AccessUserName_' + ParagraphID).blur(function(){ 
        RefillBox(this, 'Achternaam');
    })
    $('#AccessUserEmail_' + ParagraphID).addClass('nieuwsbrief_email');
    if ($('#AccessUserEmail_' + ParagraphID).val() == '') {
        $('#AccessUserEmail_' + ParagraphID).val("E-mail adres");
    }
    $('#AccessUserEmail_' + ParagraphID).click(function () {
        RemoveText(this, 'E-mail adres');
    })
    $('#AccessUserEmail_' + ParagraphID).blur(function () {
        RefillBox(this, 'E-mail adres');
    })
}

function AddNewsLetterFunctionsDE(ParagraphID, PageID) {
    $('#AccessUserName_' + ParagraphID).addClass('nieuwsbrief_naam');
    if ($('#AccessUserName_' + ParagraphID).val() == '') {
        $('#AccessUserName_' + ParagraphID).val("Familienname");
    }
    $('#AccessUserName_' + ParagraphID).click(function () {
        RemoveText(this, 'Familienname');
    })
    $('#AccessUserName_' + ParagraphID).blur(function () {
        RefillBox(this, 'Familienname');
    })
    $('#AccessUserEmail_' + ParagraphID).addClass('nieuwsbrief_email');
    if ($('#AccessUserEmail_' + ParagraphID).val() == '') {
        $('#AccessUserEmail_' + ParagraphID).val("E-mailadresse");
    }
    $('#AccessUserEmail_' + ParagraphID).click(function () {
        RemoveText(this, 'E-mailadresse');
    })
    $('#AccessUserEmail_' + ParagraphID).blur(function () {
        RefillBox(this, 'E-mailadresse');
    })
}

function RemoveText(oTextbox, filltext) {
    if (oTextbox.value == filltext) {
        oTextbox.value = ""
    }
}
function RefillBox(oTextbox, filltext) {
    if (oTextbox.value == "") {
        oTextbox.value = filltext
    }
}

function FormatVariant(OrderlineVariant, Kleur, Maat) {
    var DivVariantTekst = document.getElementById(OrderlineVariant)
    var VariantTekst = DivVariantTekst.innerHTML;
     var arrVariantTekst = VariantTekst.split('-');
   DivVariantTekst.innerHTML = Kleur + ' ' + arrVariantTekst[0].toUpperCase().replace(/\s+$/,'')   + ', ' + Maat; 
   var RestTekst = VariantTekst.replace(arrVariantTekst[0], '');
   RestTekst = RestTekst.slice(1, RestTekst.length);
   DivVariantTekst.innerHTML = DivVariantTekst.innerHTML + RestTekst.toUpperCase();
}

/* GA tracking */
var trackPageviewPushed = false;
function TrackPageViewAction(trackPageview) {
    if (_gaq != undefined) {
        //alert('TEST INNOVADIS _trackPageview: ' + trackPageview);
        _gaq.push(['_trackPageview', trackPageview]);
        trackPageviewPushed = true;
    }
}

    $(document).ready(function() {
        var hide = false;
        $(".Logo_confidence").hover(function () {
            if (hide) clearTimeout(hide);
            $(".Logo_confidence_info").show();
            $(".Logo_Sanitized_info").hide();
        }, function() {
            hide = setTimeout(function () { $(".Logo_confidence_info").hide(); }, 1);
        });
        $(".Logo_confidence_info").hover(function () {
            if (hide) clearTimeout(hide);
        }, function() {
            hide = setTimeout(function () { $(".Logo_confidence_info").hide(); }, 1);
        });
        $(".Logo_Sanitized").hover(function () {
            if (hide) clearTimeout(hide);
            $(".Logo_Sanitized_info").show();
            $(".Logo_confidence_info").hide();
        }, function () {
            hide = setTimeout(function () { $(".Logo_Sanitized_info").hide(); }, 1);
        });
        $(".Logo_Sanitized_info").hover(function () {
            if (hide) clearTimeout(hide);
        }, function () {
            hide = setTimeout(function () { $(".Logo_Sanitized_info").hide(); }, 1);
        });

    });

