﻿/// <reference path="E:\Source\Intermex@WEB\Intermex.Web\Scripts\jquery-1.3.2-vsdoc.js"/>

function initExternalLinks() {
    $("#menu ul").hide();
    $("#menu li a").click(function() {
        $(this).next().slideToggle("normal");
    });
}

function LoadURL(url) {
    window.open(url, "_blank", "", "");
}

function AddBookmark() {
    var BookmarkURL = 'http://www.propisionline.com'
    var BookmarkTitle = 'Propisi Online'
    // If the browser is Internet Explorer
    if (document.all) {
        // Add to Favorites (Internet Explorer)
        window.external.AddFavorite(BookmarkURL, BookmarkTitle);
    }
    else {
        // Add to Bookmarks (Mozilla Firefox)
        window.sidebar.addPanel(BookmarkTitle, BookmarkURL, '');
    }
}


$(document).ready(function() {
    initExternalLinks();
});


function IndOkShowAdvancedSearch() {
    $("#Search").hide();
    $("#Application").hide();
    $("#AdvancedSearch").show();
    $.cookie("searchtype", "advanced");
}

function IndOkShowStandardSearch() {
    $("#AdvancedSearch").hide();
    $("#Application").show();
    $("#Search").show();
    $.cookie("searchtype", "standard");
}


function UpdateIndexList() {
    var book = $.cookie("book");
    $.ajax(
{
    type: "GET",
    contentType: "application/json; charset=utf=8",
    url: "/Practice/GetBookIndex/" + book,
    data: "",
    dataType: "json",
    success: function(data) {
        if (data.length > 0) {
            var options = '';
            for (s in data) {
                var state = data[s];
                options += "<option value='" + state.Value + "'>" + state.Text + "</option>";
            }
            $("#index").html(options);
            var index = $.cookie("index");
            if (index == null)
                index = 0;
            $("#index").val(index);

        }
    }
});
};

function PracticeSetup() {

    var book = $.cookie("book");
    if (book != null)
        UpdateIndexList();

    $("select#book").change(function() {
        $.cookie("book", $(this).attr("value"));
        $.cookie("index", null);
        UpdateIndexList();
    });

    $("select#index").change(function() {
        $.cookie("index", $(this).attr("value"));
    });

};

function UpdateSectionGroupList() {
    var group = $.cookie("section");
    $.ajax(
{
    type: "GET",
    contentType: "application/json; charset=utf=8",
    url: "/IndOk/GetSectionList/?group=" + group,
    data: "",
    dataType: "json",
    success: function(data) {
        if (data.length > 0) {
            var options = '';
            for (s in data) {
                var state = data[s];
                options += "<option value='" + state.Value + "'>" + state.Text + "</option>";
            }
            $("#sectionGroup").html(options);
            var sectionGroup = $.cookie("sectionGroup");
            if (sectionGroup == null)
                sectionGroup = 0;
            $("#sectionGroup").val(sectionGroup);
        }
    }
});
};

function UpdateSectionSubGroupList() {
    var group = $.cookie("sectionGroup");
    $.ajax(
{
    type: "GET",
    contentType: "application/json; charset=utf=8",
    url: "/IndOk/GetSectionList/?group=" + group,
    data: "",
    dataType: "json",
    success: function(data) {
        if (data.length > 0) {
            var options = '';
            for (s in data) {
                var state = data[s];
                options += "<option value='" + state.Value + "'>" + state.Text + "</option>";
            }
            $("#sectionSubGroup").html(options);
            var sectionSubGroup = $.cookie("sectionSubGroup");
            if (sectionSubGroup == null)
                sectionSubGroup = 0;
            $("#sectionSubGroup").val(sectionSubGroup);

        }
    }
});
};


function UpdateYearList() {
    var journal = $.cookie("journal");
    $.ajax(
{
    type: "GET",
    contentType: "application/json; charset=utf=8",
    url: "/IndOk/GetYearList/?journal=" + journal,
    data: "",
    dataType: "json",
    success: function(data) {
        if (data.length > 0) {
            var options = '';
            for (s in data) {
                var state = data[s];
                options += "<option value='" + state.Value + "'>" + state.Text + "</option>";
            }
            $("#year").html(options);
            var year = $.cookie("year");
            if (year == null)
                year = 0;
            $("#year").val(year);
        }
    }
});
};

function UpdateNumberList() {
    var journal = $.cookie("journal");
    var year = $.cookie("year");
    $.ajax(
{
    type: "GET",
    contentType: "application/json; charset=utf=8",
    url: "/IndOk/GetNumberList/?journal=" + journal + "&year=" + year,
    data: "",
    dataType: "json",
    success: function(data) {
        if (data.length > 0) {
            var options = '';
            for (s in data) {
                var state = data[s];
                options += "<option value='" + state.Value + "'>" + state.Text + "</option>";
            }
            $("#number").html(options);
            var number = $.cookie("number");
            if (number == null)
                number = 0;
            $("#number").val(number);

        }
    }
});
};

function IndOkAdvancedSearchSetup() {
    var searchtype = $.cookie("searchtype");
    if ((searchtype == null) | (searchtype == "standard"))
        IndOkShowStandardSearch();
    if (searchtype == "advanced")
        IndOkShowAdvancedSearch();

    var opcija = $.cookie("option");
    if (opcija == "Keyword") {
        $("#Sections").hide();
        $("#Keywords").show();
        $('input[name="option"]')[0].checked = true;
    }
    else if (opcija == "Section") {
        $("#Keywords").hide();
        $("#Sections").show();
        $('input[name="option"]')[1].checked = true;
    };


    $("#rbKeyword").click(function() {
        var opcija = $(this).attr("value");
        $.cookie("option", opcija);
        if (opcija == "Keyword") {
            $("#Sections").hide();
            $("#Keywords").show();
        }
        else if (opcija == "Section") {
            $("#Keywords").hide();
            $("#Sections").show();
        };
    });


    $("#rbSection").click(function() {
        var opcija = $(this).attr("value");
        $.cookie("option", opcija);
        if (opcija == "Keyword") {
            $("#Sections").hide();
            $("#Keywords").show();
        }
        else if (opcija == "Section") {
            $("#Keywords").hide();
            $("#Sections").show();
        };
    });

    var journal = $.cookie("journal");
    if (journal != null)
        UpdateYearList();
    var year = $.cookie("year");
    if (year != null)
        UpdateNumberList();

    $("select#journal").change(function() {
        $.cookie("journal", $(this).attr("value"));
        $.cookie("year", null);
        $.cookie("number", null);
        $("#year").val(0);
        $("#number").val(0);
        UpdateYearList();
        UpdateNumberList();
    });

    $("select#year").change(function() {
        $.cookie("year", $(this).attr("value"));
        $.cookie("number", null);
        $("#number").val(0);
        UpdateNumberList();
    });

    $("select#number").change(function() {
        $.cookie("number", $(this).attr("value"));
    });


    var section = $.cookie("section");
    if (section != null)
        UpdateSectionGroupList();
    var sectionSubGroup = $.cookie("sectionSubGroup");
    if (sectionSubGroup != null)
        UpdateSectionSubGroupList();


    $("select#section").change(function() {
        if ($("#section > option:selected").attr("value") == 0) {
            $("#sectionGroup").html("<option value='0'>Sve</option>");
            $("#sectionSubGroup").html("<option value='0'>Sve</option>");
            $.cookie("section", null);
            $.cookie("sectionGroup", null);
            $.cookie("sectionSubGroup", null);
        }
        else {
            $.cookie("section", $(this).attr("value"));
            $.cookie("sectionGroup", null);
            $.cookie("sectionSubGroup", null);
            $("#sectionGroup").val(0);
            $("#sectionSubGroup").val(0);
            UpdateSectionGroupList();
            UpdateSectionSubGroupList();
        }
    });

    $("select#sectionGroup").change(function() {
        if ($("#sectionGroup > option:selected").attr("value") == 0) {
            $.cookie("sectionGroup", null);
            $.cookie("sectionSubGroup", null);
            $("#sectionSubGroup").html("<option value='0'>Sve</option>");
        }
        else {
            $.cookie("sectionGroup", $(this).attr("value"));
            $.cookie("sectionSubGroup", null);
            $("#sectionSubGroup").val(0);
            UpdateSectionSubGroupList();
        }
    });

    $("select#sectionSubGroup").change(function() {
        $.cookie("sectionSubGroup", $(this).attr("value"));
    });

};




(function($) {
    var printAreaCount = 0;

    $.fn.printArea = function() {
        var ele = $(this);

        var idPrefix = "printArea_";

        removePrintArea(idPrefix + printAreaCount);

        printAreaCount++;

        var iframeId = idPrefix + printAreaCount;
        var iframeStyle = 'position:absolute;width:0px;height:0px;left:-500px;top:-500px;';

        iframe = document.createElement('IFRAME');

        $(iframe).attr({ style: iframeStyle,
            id: iframeId
        });

        document.body.appendChild(iframe);

        var doc = iframe.contentWindow.document;

        $(document).find("link")
                .filter(function() {
                    return $(this).attr("rel").toLowerCase() == "stylesheet";
                })
                .each(function() {
                    doc.write('<link type="text/css" rel="stylesheet" href="' + $(this).attr("href") + '" >');
                });

        doc.write('<div class="' + $(ele).attr("class") + '">' + $(ele).html() + '</div>');
        doc.close();

        var frameWindow = iframe.contentWindow;
        frameWindow.close();
        frameWindow.focus();
        frameWindow.print();
    }

    var removePrintArea = function(id) {
        $("iframe#" + id).remove();
    };

})(jQuery);



///////////////////////////////////////
// Stapanje propisa
//
function LegislationPrint() {
    $('div#Legislation').printArea();
    return false;
}


///////////////////////////////////////
// Stapanje Ugovora
//
function ContractPrint() {
    $('div#Contract').printArea();
    return false;
}


///////////////////////////////////////
// Stapanje Misljenja
//
function OpinionPrint() {
    $('div#Opinion').printArea();
    return false;
}

///////////////////////////////////////
// Stapanje Misljenja
//
function DecisionPrint() {
    $('div#Decision').printArea();
    return false;
}
