
if ((typeof Range !== "undefined") && !Range.prototype.createContextualFragment) {
    Range.prototype.createContextualFragment = function(html) {
        var frag = document.createDocumentFragment(),
                div = document.createElement("div");
        frag.appendChild(div);
        div.outerHTML = html;
        return frag;
    };
}

function searchSend() {
    var search = Ext.get('searchField').getValue();
    if (search) {
        document.getElementById('searchForm').submit();
    }
}

String.prototype.endsWith = function(pattern) {
    var d = this.length - pattern.length;
    return d >= 0 && this.lastIndexOf(pattern) === d;
};


function compare(checked, id, reload) {
    if (compareUrl != '') {
        var box = Ext.MessageBox.wait('Please wait... Sending data...', 'Connecting');

        Ext.Ajax.request({
            url: compareUrl,
            method: 'POST',

            success: function ( result, request ) {
                box.hide();

                obj = Ext.util.JSON.decode(result.responseText);
                if (document.getElementById('compareCount')) {
                    document.getElementById('compareCount').innerHTML = obj.params.count;
                }

                window.location = window.location;
            },
            failure: function ( result, request ) {
                var jsonData = Ext.util.JSON.decode(result.responseText);
                var resultMessage = jsonData.errors.reason;
                Ext.MessageBox.alert(resultMessage);
                box.hide();
            },
            params: { productId: id, add: checked }
        });
    }

}
