﻿$(document).ready(function() {
    $("a[rel^='prettyPhoto']").prettyPhoto({
        theme: 'facebook',
        show_title: false,
        autoplay_slideshow: false,
        deeplinking: false,
        social_tools: false
    });

    var main = $('#ctl00_cphMain_ucSearchResults_ddlMainGroup');
    var sub = $('#ctl00_cphMain_ucSearchResults_ddlSubGroup');

    main.change(function() {

        var firstLineVal = $("#ctl00_cphMain_ucSearchResults_ddlSubGroup option:first").val();
        var firstLineTxt = $("#ctl00_cphMain_ucSearchResults_ddlSubGroup option:first").text();
        sub.removeOption(/./);
        sub.addOption(firstLineVal, firstLineTxt);
        if (main.val() != -1) {
            sub.ajaxAddOption("/xt_ProcessJSon.aspx?id=" + main.val(), {}, false);
            sub.removeAttr("disabled");
        }
        else {
            sub.attr("disabled", "disabled");
        }
    });
});

function PostSearchBox(controlClientID, title){ 
    var val = $("#searchbox-input input[type=text]").val();
    if (val.length == 0 || val == 'Zoeken' || val == 'Search' || val == '') { 
        return false; 
    } else { 
        return true; 
    }
}

function PostSubscribeBox(title){ 
    var val = $(".mailbox-input input[type=text]").val();
    if (val.length == 0 || val == title || val == '') { 
        return false; 
    } else { 
       __doPostBack("ctl00$ucSidebarSubscription$ibSubscribe", "");
    }
}

function PostSearchBoxExt(title){
    var val = $("#uitgebreid-zoeken input[type=text]").val();
    if (val.length == 0 || val == title) {
        alert("U heeft geen omschrijving ingevuld.");
        return false; 
    } else { 
        __doPostBack("ctl00$cphMain$ucSearchResults$lbSearchExt", "");
    }
}

function LoginBox(uniqueID){ 

    var email = $("[id$=_txtEmail]").val();
    var password = $("[id$=_txtPassword]").val();

    if (email.length == 0 && password.length == 0) { 
        return false; 
    } else { 
        __doPostBack(uniqueID, '');
    }
}

function PostLogin(){ 
    var valEmail = $(".spLogin input").val();
    var valPassWord = $(".spPassWord input").val();
    
    if (valEmail.length == 0 && valPassWord.length == 0) { 
        return false; 
    } else { 
        __doPostBack('ctl00$cphMain$ucRegisterLogin$lbLogin','');
    }
}

function PostPasswordRecover(){ 
    var email = $("[id$=_txtEmailAddress]").attr("id");
    var button = $("[id$=_lbRecover]").attr("id");
    var value = $("#" + id).val();
    
    if (value.length == 0) { 
        return false; 
    } else { 
        __doPostBack(button,'');
    }
}

function AutoFill(selector, text) {
    $(selector).attr({ value: text }).focus(function() { 
		if($(this).val()==text){ $(this).val(""); }}).blur(function(){
		if($(this).val()==""){ $(this).val(text); }
	});
}

function ShippingEqualsInvoice(val) {
    var inv = $("#addresses .invoice");
    var ship = $("#addresses input:text");
    for(var i = 0; i < inv.length; i++) {
        var invoiceValue = inv.eq(i);
        var shipValue = ship.eq(i);
        if (val) {
            shipValue.val(invoiceValue.html());
        } else {
            shipValue.val("");
        }
    }
}

function PasswordChange(change) {
    var id = $("[id$=_divPasswordChange]").attr("id");
    $("#" + id + " input").val("");
    if (change) {
        $("#" + id).show();
        $("#" + id + " input:first").focus();
    } else {
        $("#" + id).hide();
    }
}

function ChangeShippingCosts(id) {
    var oCellShipping = $("#ctl00_cphMain_ucCart_trVerzendKosten > td:nth-child(3) > strong");
    var oTotal = $("#sTotal");
    var oRowCOD = $("#ctl00_cphMain_ucCart_trRembours");
    var oRowShippingCost = $("#ctl00_cphMain_ucCart_trVerzendKosten");

    var totCollect = $("#ctl00_cphMain_ucCart_hdTotCollect").val();
    var priceShipping = $("#ctl00_cphMain_ucCart_hdPriceShipping").val();
    var totShipping = $("#ctl00_cphMain_ucCart_hdTotShipping").val();
    var totCod = $("#ctl00_cphMain_ucCart_hdTotCOD").val();
    var totZero = $("#ctl00_cphMain_ucCart_hdTotZero").val();

    switch (id) {
        case 1: // afhalen
            var dTotal = totCollect;
            oCellShipping.html("&euro; " + totZero);
            oRowCOD.hide();
            oRowShippingCost.hide();
            break;
        case 2: // verzenden
            var dTotal = totShipping;
            oCellShipping.html("&euro; " + priceShipping);
            oRowCOD.hide();
            oRowShippingCost.show();
            break;
        case 3: // rembours
            var dTotal = totCod;
            oCellShipping.html("&euro; " + priceShipping);
            oRowCOD.show();
            oRowShippingCost.show();
            break;
    }
    
    oTotal.html("&euro; " + dTotal);
}

function OpenTerms(o) {
    window.open(o.href, 'terms', 'width=780,height=500,scrollbars=1,resizable=1');
}
