﻿function SubContent(str, len) {

}

function strlen(str) {
    return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}

function trim(str) {
    return (str + '').replace(/(\s+)$/g, '').replace(/^\s+/g, '');
}

function getQueryString(queryname) {
    var qKeys = {};
    var re = /[?&]([^=]+)(?:=([^&]*))?/g;
    var matchInfo;
    while (matchInfo = re.exec(location.search)) {
        qKeys[matchInfo[1]] = matchInfo[2];
    }
    return typeof (qKeys[queryname]) == 'undefined' ? '' : qKeys[queryname];
}

//此方法主要用于Json时间格式
function ChangeDateFormat(cellval) {
    var date = new Date(parseInt(cellval.replace("/Date(", "").replace(")/", ""), 10));
    var month = date.getMonth() + 1 < 10 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1;
    var currentDate = date.getDate() < 10 ? "0" + date.getDate() : date.getDate();
    var hour = date.getHours();
    var minute = date.getMinutes();
    var second = date.getSeconds();
    return date.getFullYear() + "-" + month + "-" + currentDate + ' ' + hour + ':' + minute + ':' + second;
}

//验证邮箱
function IsValidMail(sText) {
    var reMail = /^(?:[a-z\d]+[_\-\+\.]?)*[a-z\d]+@(?:([a-z\d]+\-?)*[a-z\d]+\.)+([a-z]{2,})+$/i;
    return reMail.test(sText)
}

function convertdate(strdate) {
    strdate = strdate.replace(/-/ig, '/');
    var d = new Date(strdate);
    var now = new Date();
    var result;

    if (d.getYear() == now.getYear() && d.getMonth() == now.getMonth()) {
        var xday = now.getDate() - d.getDate();

        switch (xday) {
            case 0:
                result = "今天 " + d.format("hh") + ":" + d.format("mm");
                break;
            case 1:
                result = "昨天 " + d.format("hh") + ":" + d.format("mm");
                break;
            case 2:
                result = "前天 " + d.format("hh") + ":" + d.format("mm");
                break;
            default:
                result = d.format("yyyy-MM-dd hh:mm");
                break;
        }
    } else {
        result = d.format("yyyy-MM-dd hh:mm");
    }

    return result;
}

//html替换
function HtmlEnCode(str) {
    var s = "";
    if (str.length == 0) return "";
    s = str.replace(/&/g, "&gt;");
    s = s.replace(/</g, "&lt;");
    s = s.replace(/>/g, "&gt;");
    s = s.replace(/    /g, "&nbsp;");
    s = s.replace(/\'/g, "&#39;");
    s = s.replace(/\"/g, "&quot;");
    s = s.replace(/\n/g, "<br>");
    return s;
}   
