function addClickFunction(id) {{
    var b = document.getElementById(id);
    if (b && typeof(b.click) == 'undefined') b.click = function() {{
        var result = true; if (b.onclick) result = b.onclick();
        if (typeof(result) == 'undefined' || result) {{ eval(b.getAttribute('href')); }}
    }}} 
}
    
function trim(str) {
    return str.replace(/^\s+|\s+$/g, "");
}

$(document).ready(function() {
    // jGrowl
    $.jGrowl.defaults.position = 'center';


    $(".afrekenen img").hover(function() {
        $(this).attr("src", "/Images/Front/btn-afrekenen-overstate.gif");
    }, function() {
        $(this).attr("src", "/Images/Front/btn-afrekenen.gif");
    });

    $(".search .search-button").hover(function() {
        $(this).attr("src", "/Images/Front/btn-zoek-overstate.gif");
    }, function() {
        $(this).attr("src", "/Images/Front/btn-zoek.gif");
    });

    // Watermark
    // Set default value
    if ($("#ctl00_tbSearch").val().length == 0 ||
        $("#ctl00_tbSearch").val() == "Voer hier uw zoekterm in")
        $("#ctl00_tbSearch").val("Voer hier uw zoekterm in").addClass("watermark");
    // Define what happens when the textbox comes under focus
    // Remove the watermark class and clear the box
    $("#ctl00_tbSearch").focus(function() {
        $(this).filter(function() {
            // We only want this to apply if there's not 
            // something actually entered
            return $(this).val() == "" || $(this).val() == "Voer hier uw zoekterm in" || $(this).val() == "Voer een zoekterm in"
        }).removeClass("watermark").removeClass("invalid").val("");
    });

    // Define what happens when the textbox loses focus
    // Add the watermark class and default text
    $("#ctl00_tbSearch").blur(function() {
        $(this).filter(function() {
            // We only want this to apply if there's not
            // something actually entered
            return $(this).val() == ""
        }).addClass("watermark").val("Voer hier uw zoekterm in");
    });

});

function cvSearch_Validate(sender, e) {
    value = trim(e.Value);
    e.IsValid = (value.length > 0 && value != "Voer hier uw zoekterm in" && value != "Voer een zoekterm in");

    if (!e.IsValid) {
        $("#ctl00_tbSearch").val("Voer een zoekterm in")
                    .removeClass("watermark")
                    .addClass("invalid").blur();
    }
}

function displayMessage(control) {

    $(control).colorbox({
        inline: true,
        innerWidth: '400px',
        innerHeight: '120px',
        close: '',
        href: '#confirmation-message',
        onComplete: function () {
            $('#confirmation-message .submit').click(function () {
                var href = $(control).attr('href');
                window.location = href;
            });
        }
    });
}
