﻿function getPropertyValueById(props, propId) {
    if (props == null || props.length == 0)
        return null;
    for (var i = 0; i < props.length; i++) {
        if (props[i].PropertyId === propId)
            return props[i].Value;
    }
}

function gridPaging(index, size) {
    this.pageIndex = index;
    this.pageSize = size;
};

function searchOptions(keepPager, zoomToView) {
    this.keepPager = keepPager;
    this.zoomToView = zoomToView === null ? false : zoomToView;
};

var comparison = {
    max: 5,
    url: "compare.aspx",
    ids: new Array(),
    add: function(newId) {
        var atIndex = this.ids.length;
        var warnTextCtrl = document.getElementById("toomanyitems");
        var warning = document.getElementById(warnTextCtrl.value);
        if (this.ids.length === this.max) {
            //     alert(warning);
            alert(warnTextCtrl.value);
            return false;
        }
        if ($telerik.$.inArray(newId, this.ids) >= 0) return;
        this.ids[atIndex] = newId;
        this.updateCounter();
    },
    remove: function(id) {
        var j = 0;
        while (j < this.ids.length) {
            if (this.ids[j] == id) {
                this.ids.splice(j, 1);
                break;
            } else { j++; }
        }
        this.updateCounter();
    },
    clear: function() {
        this.ids = new Array();
        this.updateCounter();
    },
    updateCounter: function() {
        var counter = $telerik.$(".compare-info strong");
        var link = $telerik.$(".link_porovnat");
        if (counter.length > 0)
            counter.text(this.ids.length);
        if (link.length > 0) {
            if (this.ids.length > 1) {
                var query = new String();
                $telerik.$.each(this.ids, function() { if (query.length > 0) query += ","; query += this; });
                link.attr("href", this.url + '&ids=' + query);
                link.removeAttr("disabled");
            }
            else {
                link.removeAttr("href");
                link.attr("disabled", "true");
            }
        }
    }
};