﻿$(document).ready(function() {
    $("#SelectAll").click(function() {
        $("input:checkbox").attr("checked", $("#SelectAll").attr("checked"));
//        $("#SelectAllPages").removeAttr("style").attr("checked", false);
    });
});

function submitChecked(form, msg, max) {
    if (typeof max != 'undefined') {
        if ($(":checkbox:checked").length > max) {
            alert("Please select only " + max + " row!");
            return;
        } 
    } 

    if ($(":checkbox:checked").length > 0) {
        if (msg.length > 0) {
            if (confirm(msg)) form.submit();
        } else form.submit();
    } else alert("Please select at least 1 row first!");
}

function submitTextBox(form, textbox, minlength) {
    if (trim(textbox.value).length < minlength) {
        alert("Please enter at least " + minlength + " letters before clicking search!");
        return;
    }
    form.submit();
}

function submitConfirm(form, msg) {
    if (confirm(msg)) form.submit();
}

function updatePickMany(fromname, toname) {
    from = fromname;
    to = toname;

    var options = new Object();
    for (var i = 0; i < to.options.length; i++) {
        options[to.options[i].value] = to.options[i].text;
    }
    for (var i = 0; i < from.options.length; i++) {
        var o = from.options[i];
        if (o.selected) {
            if (options[o.value] == null || options[o.value] == "undefined" || options[o.value] != o.text) {
                to.options[to.options.length] = new Option(o.text, o.value);
            }
        }
    }
    for (var i = (from.options.length - 1); i >= 0; i--) {
        var o = from.options[i];
        if (o.selected) { from.options[i] = null; }
    }
}

function trim(str, chars) {
    return ltrim(rtrim(str, chars), chars);
}

function ltrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("^[" + chars + "]+", "g"), "");
}

function rtrim(str, chars) {
    chars = chars || "\\s";
    return str.replace(new RegExp("[" + chars + "]+$", "g"), "");
}