﻿String.prototype.trim = function() {
    return this.replace(/^\s+|\s+$/g, "");
}
String.prototype.ltrim = function() {
    return this.replace(/^\s+/, "");
}
String.prototype.rtrim = function() {
    return this.replace(/\s+$/, "");
}

String.prototype.regxmatch = function(regxstr) {
    var re = new RegExp(regxstr);
    if (this.match(re)) {
        return true;
    }
    else {
        return false;
    }
}
function setiframsrc(frameid, srcpath) {
    var _Iframe = document.getElementById(frameid);

    if (_Iframe!=null && typeof(_Iframe) != "undefined") {
        _Iframe.src = srcpath;
    }
}
//===================================================================
function listbox_move(sourceid, destid, hiddenid, sourcehiddenflg, sourcesortflg, dessortflg) {
    $(sourceid + ' :selected').each(function(i, selected) {

        $(selected).attr('selected', false);
        $(selected).appendTo(destid);
    });

    if (sourcesortflg)
        listbox_sort(sourceid);
    if (dessortflg)
        listbox_sort(destid);

    if (sourcehiddenflg)
        listbox_valuestr(sourceid, hiddenid);
    else
        listbox_valuestr(destid, hiddenid);
}
//===================================================================
function listbox_sort(listid) {
    var $r = $(listid + " option");
    $r.sort(function(a, b) {
        if (a.text < b.text) return -1;
        if (a.text == b.text) return 0;
        return 1;
    });
    $($r).remove();
    $(listid).append($($r));
}
//===================================================================
function listbox_valuestr(listid, hiddenid) {
    $(hiddenid).val("");
    $(listid + ' >option').each(function(i, opt) {
        if ($(hiddenid).val() == '')
            $(hiddenid).val($(opt).val());
        else
            $(hiddenid).val($(hiddenid).val() + '|' + $(opt).val());
    });
}
//===================================================================
function callwebmethod(type, url, contenttype, datatype, params, onsucc) {
    $.ajax({
        type: type,
        url: url,
        data: params,
        contentType: contenttype,
        dataType: datatype,
        success: function(data) {
            eval(onsucc);
        }
    });
}
//===================================================================
function combo_reqval1(id, alarmid) {
    if ($("#" + id + " option:selected").val() > 0) {
        $("#" + alarmid).css("display", "none");
        return true;
    }
    else {
        $("#" + alarmid).css("display", "inline");
        return false;
    }
}
//===================================================================
function combo_reqval(source, clientside_arguments) {
    if (clientside_arguments.Value.length <= 0) {
        clientside_arguments.IsValid = false;
        return;
    }
    if (clientside_arguments.Value > 0) {
        clientside_arguments.IsValid = true;
    }
    else {clientside_arguments.IsValid = false; };
}
//===================================================================
function chk_reqval(source, clientside_arguments) {
    clientside_arguments.IsValid = false;
}
//===================================================================
function rb_reqval(source, clientside_arguments) {
    if (clientside_arguments.Value.length <= 0) {
        clientside_arguments.IsValid = false;
        return;
    }
    if (clientside_arguments.Value > 0) {
        clientside_arguments.IsValid = true;
    }
    else {clientside_arguments.IsValid = false; };
}
//===================================================================
function ClientSqlCheck(source, clientside_arguments) {
    if (clientside_arguments.Value.indexOf(';') >= 0 ||
          clientside_arguments.Value.indexOf('\'') >= 0 ||
          clientside_arguments.Value.indexOf('.') >= 0 ||
          clientside_arguments.Value.indexOf('-') >= 0 ||
          clientside_arguments.Value.indexOf('<') >= 0 ||
          clientside_arguments.Value.indexOf('>') >= 0 ||
          clientside_arguments.Value.indexOf('%') >= 0 ||
          clientside_arguments.Value.indexOf(',') >= 0 ||
          clientside_arguments.Value.indexOf('/*') >= 0 ||
          clientside_arguments.Value.indexOf('*/') >= 0 ||
          clientside_arguments.Value.indexOf('|') >= 0 ||
          clientside_arguments.Value.indexOf('+') >= 0 ||
          clientside_arguments.Value.indexOf('0x') >= 0 ||
          clientside_arguments.Value.indexOf('0X') >= 0) {
        clientside_arguments.IsValid = false;
    }
    else { clientside_arguments.IsValid = true };
}
