﻿function GetBaseUrl() {
    return 'MenuPlanner2.0';
}

function StripResponse(response) {
    response = response.substring(0,response.indexOf('<html'));
    return response;
}

function AutoCompleteTextbox(textboxControlId, values) {
    $().ready(function() {
         var dataArray = values.split("||");

         $("#" + textboxControlId).flushCache();
         $("#" + textboxControlId).autocomplete(dataArray,
        {
            matchContains: true,
            minChars: 0,
            mustMatch: false
        });
     });
}


//http://net.tutsplus.com/tutorials/html-css-techniques/how-to-create-a-slick-tabbed-content-area/
function InitializeTabs() {
    // When the document loads do everything inside here ...
    $(document).ready(function() {

        // When a link is clicked
        $("a.tab").click(function() {


            // switch all tabs off
            $(".active").removeClass("active");

            // switch this tab on
            $(this).addClass("active");

            // slide all content up
            $(".content").slideUp();

            // slide this content up
            var content_show = $(this).attr("title");

            $("#" + content_show).slideDown();

        });

        var title = "maandag";

        $(".content").hide();
        $("#" + title).show();

        $("a.tab[title=" + title + "]").addClass("active");




    });
}

function ShowCluetip(linkid) {
    //http://plugins.learningjquery.com/cluetip/demo/
    $('#' + linkid).cluetip({
        splitTitle: '|',
        cluetipClass: 'jtip',
        sticky: 'true',
        arrows: true,
        dropShadow: true,
        dropShadowSteps: 5,
        closePosition: 'title'
    });

}

function AddShowHide(divname, linkname) {
    $(document).ready(function() {
        $("#" + divname).hide();
        $("#" + linkname).show();

        $("#" + linkname).click(function() {
            $("#" + divname).slideToggle();
        });
    });
}

function ShowSearchResult(ingredientTextBoxId, resultDivId, selectionTextboxId) {
    var currentDate = new Date();
    var dummy = currentDate.getTime();

    var ingredient = $("#" + ingredientTextBoxId).val()

    $("#" + resultDivId).html("<img class=\"smallLoadingImage\" src=\"images/loading.gif\" alt=\"...\" />").show();

    $.get("modules/SearchByIngredient.aspx?ingredient=" + ingredient + "&selectionTextboxId=" + selectionTextboxId, function(response) {
        $("#" + resultDivId).html(response).show();
    });
}

function SetValueToTextBox(value, textboxid) {
    $("#" + textboxid).val(value);

}

function AddWysiwigToTextArea(textareaId)
{
    $("#" + textareaId).htmlarea();
}

function AddSuggestionActionToLink(textBoxId, imageControlId, hiddenGerechtIdControlId, ingredientsElement, loadingElement)
{
    var suggestion;
    var items;
    $("#" + loadingElement).html("<img class=\"smallLoadingImage\" src=\"images/loading.gif\" alt=\"even geduld...\" />").show();
    $.get("modules/GetSuggestion.aspx", function(response) {
        suggestion = StripResponse(response);
        items = suggestion.split("|");
        $("#" + hiddenGerechtIdControlId).val(items[0]);
        $("#" + textBoxId).val(items[1]);
        var image = 'images/gerechten/' + items[2];
        changeImg(imageControlId, image );
        
        $.get("modules/GetIngredients.aspx?gerechtid=" + items[0], function(ingredientsResponse) {
            $("#" + ingredientsElement).html(ingredientsResponse).show();
        });
        $("#" + loadingElement).html("").show();
    
    });
    
    
    
    
}

function changeImg(imageControlId, image_full_path) {

    var src = image_full_path
    if (src != $('img#' + imageControlId).attr('src')) {
        $('img#' + imageControlId).stop().animate({opacity:'0'},function(){
                $(this).attr('src',src+'?'+Math.floor(Math.random()*(10*100)));
        }).load(function(){
                $(this).stop().animate({opacity:'1'});
        });
    }
    return false;

}


