﻿var condecta = condecta || {}

condecta.ui = {}; condecta.common = {};condecta.forms = {}; condecta.basePath = "";


condecta.init = function () {
    condecta.basePath = $dnn.hostUrl;
    condecta.common.init();
    condecta.ui.init();
    condecta.forms.init();

};

condecta.common.init = function () {
    condecta.common.search.init();
    condecta.common.search.getSuggestions("condecta");

};

condecta.ui.init = function () {
    condecta.ui.downloads.init();
    condecta.ui.print.init();

    /*condecta.ui.search.init();*/
    /*condecta.ui.menuFix.init();*/
};

condecta.forms.init = function () {
    condecta.forms.toilet.init();
};

condecta.forms.toilet = {
    init: function () {
        var imgs = { "Basic": "http://www.condecta.ch/contento/Portals/6/media/produkte_events/mobitoil_basic_120.jpg",
            "Comfort": "http://www.condecta.ch/contento/Portals/6/media/produkte_events/mobitoil_comfort_120.jpg", "Camping": "http://www.condecta.ch/contento/Portals/6/media/produkte_events/mobitoil_camping_100.jpg"
        };
        var $form = $("#dnn_ctr1191_Default_Form_divForm");
        $form.find("div.UDT_Field").addClass("clearfix");
        var $cabins = $form.find("select[id*='Kabinenmodell']").each(function (index) {
            var $sel = $(this);
            $sel.width(40);
            $sel.css('margin-right', '10px');
            var id = $(this).attr("id");
            $.each(imgs, function (img) {
                if (id.indexOf(img) != -1) {
                    $sel.closest(".UDT_Field").append("<img src='" + imgs[img] + "'/>");

                }


            });

        });
    }
}

condecta.ui.menuFix = {
    init: function () {
        $("li.selected").parents("li").addClass("selected");
    }

}

condecta.ui.print = {
    init: function () {
        $(".btn-print").click(function () {
            document.getElementById("dnn_SKINSELECT_cboSkins").selectedIndex = 1;
            __doPostBack('dnn$SKINSELECT$cboSkins', '1');
            return false;
        });


    }
}

condecta.ui.search = {

    init: function () {
        $("#search-box").autoSuggest(condecta.common.search.getSuggestionsUrl, { queryParam: "s", type: "POST", selectedItemProp: "Title", selectedValueProp: "Title", searchObjProps: "Title", selectionLimit: 1, selectionClick:
        function (elem) {
         
        } 
        });
    }
}

condecta.ui.downloads = {

    init: function () {
        $(".download-btn").click(function () {
            $(this).toggleClass("active");
            return false;
        });
        $(".downloads .filter").chosen();
        $(".downloads .filter").chosen().change(function () {
            var url = document.location.href;
            url = (url.indexOf("?") == -1) ? url : url.split("?")[0];

            document.location = encodeURI(url + "?" + $(this).val());
        }
        );
    },
    trigger: function (container_id) {
        var url = "http://www.condecta.ch/contento/DesktopModules/Contento/Downloads/Basket.ashx?portalid=0&tabid=705&id=";
        var checked = $("#" + container_id).find(".active").each(function () {
            //fill the array with the values
            url = url + jQuery(this).attr("data") + ";";

        }


    );
        document.location = url;

    }

};

condecta.common.search = {
    init: function () {
        condecta.common.search.searchServiceUrl = condecta.basePath + "DesktopModules/contento/Search/SearchService.asmx";
        condecta.common.search.getSuggestionsUrl = condecta.common.search.searchServiceUrl + "/GetSuggestions";
    },
    getSuggestions: function (s) {

       
        $.ajax({
            type: "POST",
            url: condecta.common.search.getSuggestionsUrl,
            async: false,
            contentType: "application/json; charset=utf-8",
            dataType: "json",
            data: '{"s":"' + s +  '"}',

            success: function (data) {
                return data ;
            }
                    , error: function (XMLHttpRequest, textStatus, errorThrown) {
                        alert("Error");
                    }
        });
        



    }

}

$(document).ready(function () {
    condecta.init();
    
});
