function getsometext(con,num,isdotyes1no0) {
    con = clearhtml(con);
    if (isEmpty(con)) {
        return "";
    }
    if (con.length > num) {
        return con.substring(0, num) + (isdotyes1no0==1?"...":"");
    } return con;
}


function alertnullsyselecons() {
    var mstmsg = "";
    var hastips = 0;
    var mstlen = $(".opmst1").length;
    if (mstlen > 0) {
        var mstid = "";
        for (var m = 0; m < mstlen; m++) {
            hastips = 0;
            mstid = $(".opmst1").eq(m).attr("id");
            mstmsg = $("#" + mstid + " .optip").html().replace("：", "");
            if ($("#" + mstid + " .opselect").length > 0) {
                if (isEmpty($("#" + mstid + " .opselect").val())) {
                    hastips = 1;
                    mstmsg = "请选择" + mstmsg;
                    break;
                }
            } else if ($("#" + mstid + " .optext").length > 0) {
                if (isEmpty($("#" + mstid + " .optext").val())) {
                    hastips = 1;
                    mstmsg = mstmsg.indexOf("请填写") == -1 ? "请填写" + mstmsg : mstmsg;
                    break;
                }
            } else if ($("#" + mstid + " .picbox").length > 0) {
                if ($("#" + mstid + " .opimg").length == 0) {
                    hastips = 1;
                    mstmsg = mstmsg.indexOf("请上传") == -1 ? "请上传" + mstmsg : mstmsg;
                    break;
                }
            } else if ($("#" + mstid + " .opvdo").length > 0) {
                if (isEmpty($("#" + mstid + " .opvdo").val())) {
                    hastips = 1;
                    mstmsg = mstmsg.indexOf("请上传") == -1 ? "请上传" + mstmsg : mstmsg;
                    break;
                }
            } else if ($("#" + mstid + " .advopt").length > 0) {
                if ($("#" + mstid + " .otpimg").length == 0) {
                    hastips = 1;
                    mstmsg = mstmsg.indexOf("请上传") == -1 ? "请上传" + mstmsg : mstmsg;
                    break;
                }
            } else if ($("#" + mstid + " .twopt").length > 0) {
                if ($("#" + mstid + " .otpimg").length == 0) {
                    if ($("#" + mstid + " .otptext").length > 0) {
                        $("#" + mstid + " .otptext").each(function () {
                            if (hastips != 2) {
                                if (!isEmpty($("#" + mstid + " .otptext").val())) {
                                    hastips = 2;
                                }
                            }
                        });
                        if (hastips == 0) {
                            hastips = 1;
                            mstmsg = mstmsg.indexOf("请编辑") == -1 ? "请编辑" + mstmsg : mstmsg;
                            break;
                        }
                    } else {
                        hastips = 1;
                        mstmsg = mstmsg.indexOf("请编辑") == -1 ? "请编辑" + mstmsg : mstmsg;
                        break;
                    }
                }
            }
        }
    }
    if (mstmsg != "" && hastips == 1) {
        return mstmsg;
    } else {
        return "";
    }
}
function getsyselecons() {
    var sels = "";
    var seln = $(".opselect").length;
    if (seln > 0) {
        var i = 0;
        $(".opselect").each(function () {
            sels += "&seli" + i + "=" + $(this).attr("id") + "&selv" + i + "=" + encodeURIComponent($(this).val());
            i++;
        });
    }
    var texts = "";
    var textn = $(".optext").length;
    if (textn > 0) {
        var i = 0;
        $(".optext").each(function () {
            texts += "&texti" + i + "=" + $(this).attr("id") + "&textv" + i + "=" + encodeURIComponent($(this).val());
            i++;
        });
    }
    var pics = "";
    var picn = $(".opimg").length;
    if (picn > 0) {
        var i = 0;
        $(".opimg").each(function () {
            pics += "&pici" + i + "=" + $(this).attr("id") + "&picv" + i + "=" + encodeURIComponent($(this).attr("src"));
            i++;
        });
    }
    var vdos = "";
    var vdon = $(".opvdo").length;
    if (vdon > 0) {
        var i = 0;
        $(".opvdo").each(function () {
            vdos += "&vdoi" + i + "=" + $(this).attr("id") + "&vdov" + i + "=" + encodeURIComponent($(this).val());
            i++;
        });
    }
    var otps = "";
    var otpn = $(".otpbox").length;
    if (otpn > 0) {
        otps += "&otpn=" + otpn;
        var i = 0;
        $(".otpbox").each(function () {
            otps += "&otpi" + i + "=" + $(this).attr("data-id");
            var sn = $(this).attr("data-sn");
            var olen = $(".otpi" + sn).length;
            if (olen > 0) {
                otps += "&olen" + i + "=" + olen;
                for (var n = 0; n < olen; n++) {
                    var oid = $(".otpi" + sn).eq(n).attr("id");
                    var omode = $(".otpi" + sn).eq(n).attr("data-mode");
                    if (omode == "text") {
                        var val = $("#" + oid + " .otptext").val();
                        if (!isEmpty(val)) {
                            otps += "&otptext" + i + "_" + n + "=" + encodeURIComponent(val);
                        }
                    } else if (omode == "pic") {
                        var val = $("#" + oid + " .otpimg").attr("src");
                        if (!isEmpty(val)) {
                            otps += "&otpimg" + i + "_" + n + "=" + encodeURIComponent(val) + "&otpimgttl" + i + "_" + n + "=" + encodeURIComponent($("#" + oid + " .ittlobj").val()) + "&otpimglink" + i + "_" + n + "=" + encodeURIComponent($("#" + oid + " .ihrefobj").val());
                        }
                    } else if (omode == "adv") {
                        var val = $("#" + oid + " .otpimg").attr("src");
                        if (!isEmpty(val)) {
                            otps += "&otpadv" + i + "_" + n + "=" + encodeURIComponent(val) + "&otpiname" + i + "_" + n + "=" + encodeURIComponent($("#" + oid + " .isettt").val()) + "&otpilink" + i + "_" + n + "=" + encodeURIComponent($("#" + oid + " .isethf").val());
                        }
                    }
                }
            }
            i++;
        });
    }
    return "seln=" + seln + "&textn=" + textn + "&vdon=" + vdon + "&picn=" + picn + sels + texts + pics + vdos + otps;
}


function addorupdate(callback, e, paras, class_btn, isalert) {
    $(".loader").remove();
    if (class_btn == "" || class_btn == null || class_btn == undefined) { class_btn = "actbtn"; }
    var k0v = $("#k0").length > 0 ? $("#k0").val() : "";
    var k1v = $("#k1").length > 0 ? $("#k1").val() : "";
    var k2v = $("#k2").length > 0 ? $("#k2").val() : "";
    var k3v = $("#k3").length > 0 ? $("#k3").val() : "";
    $("." + class_btn).hide();
    if (isalert) {
        $("." + class_btn).after("<span class='loader'>提交中...</span>");
    }
    goAjax("/evtw", "e=" + e + "&k0=" + k0v + "&k1=" + k1v + "&k2=" + k2v + "&k3=" + k3v + "&" + paras, function (result) {
        $(".loader").html("");
        var data = (result != "") ? $.parseJSON(result) : null;
        if (data != undefined && data != null && data.code != undefined) {
            if (data.code == 2000) {
                if (callback != "" && callback != null && callback != undefined) {
                    callback(data); return;
                } else {
                    if (isalert) {
                        $(".loader").addClass("domsg").html(data.msg);
                        overdo();
                    }
                }
            } else {
                if (isalert) {
                    pageAlert(data.msg, 0, 2500);
                }
            }
        } else {
            data = null;
            if (isalert) {
                pageAlert("操作失败", 0, 2500);
            }
        }
        if (isalert) {
            setTimeout(function () { $(".loader").remove(); $("." + class_btn).show(); }, 1500);
        }
    });
}
function overdo(reload) {
    setTimeout(function () {
        var pageloadwinsnv = $("#pageloadwinsn").length > 0 ? $("#pageloadwinsn").val() : "0";
        if (pageloadwinsnv == "0") {
            var reurl = window.location.href;
            window.location.href = reurl.indexOf("?") == -1 ? reurl + "?" : reurl + "&0";
        } else {
            parent.closepagewin(pageloadwinsnv, reload);
        }
    }, 1500);
}
function loadpage(title, url, close_yes1_no0_refresh, cusclosebtn_css, cusclosebtn_text, callback) {
    var sn = 9999 + $(".pageloadwin").length + 1;
    var winH = $(window).height() - 65;
    $("body").css("overflow", "hidden");
    $("body").append("<div class='pageloadwinbg pageloadwinbg" + sn + "' style='z-index:" + sn + "'></div><div class='pageloadwin pageloadwin" + sn + "' style='z-index:" + sn + "1'><div class='pageloadwint'><div class='pgwtitle'>" + getsometext(title, 40, 1) + "<a href='javascript:void(0);' class='erri " + ((cusclosebtn_css != null && cusclosebtn_css != undefined) ? cusclosebtn_css : "") + "' onclick='closepagewin(" + sn + "," + close_yes1_no0_refresh + "," + ((callback != null && callback != undefined) ? callback : null) + ");'>" + ((cusclosebtn_text != null && cusclosebtn_text != undefined) ? cusclosebtn_text : "") + "</a></div></div><div class='pageloadwinbody'><iframe id='inwin" + sn + "' src='" + url + (url.indexOf("?") == -1 ? "?pageloadwinsn=" + sn : "&pageloadwinsn=" + sn) + "' frameborder='0' style='height:" + winH + "px;width:100%' scrolling='auto'></iframe></div></div>");
    stopUrlLoader();
    $("body").append("<div class=\"urlloader\">正在加载中...</div>");
    $(".urlloader").css("z-index", sn + "2");
    $("#inwin" + sn).load(function () {
        $(".urlloader").html("加载完成");
        setTimeout(function () { stopUrlLoader(); }, 100);
    });
} function stopUrlLoader() {
    if ($(".urlloader").length > 0) {
        $(".urlloader").remove();
    }
}
function closepagewin(sn, close_yes1_no0_refresh, callback) {
    $("body").css("overflow", "auto");
    if (callback != null && callback != undefined) {
        callback();
    }
    if (close_yes1_no0_refresh == 1) {
        var reurl = window.location.href;
        window.location.href = reurl.indexOf("?") == -1 ? reurl + "?" : reurl + "&?";
    }
    if ($(".pageloadwinbg" + sn).length > 0) {
        $(".pageloadwinbg" + sn).remove();
        $(".pageloadwin" + sn).remove();
    }
}
function clearhtml(con) {
    if (isEmpty(con)) {
        return "";
    }
    var regex = /(<([^>]+)>)/ig;
    return con.replace(regex, "");    
}
function isEmpty(val) { if (val == "" || val == undefined || val == null) { return true; } if (val.replace(/^\s+|\s+$/igm, '') == "") { return true; } else { return false; } } 
function focusEle(id) { document.getElementById(id).focus(); } 
function isEmail(val) { var rege = /^([a-zA-Z0-9\._-])+@([a-zA-Z0-9_-])+((\.[a-zA-Z0-9_-]{2,3}){1,2})$/; if (!rege.test(val)) { return false; } else { return true; } }
function isMobile(val) { var rege = /^1[1-9]{1}[0-9]{9}$/; if (!rege.test(val)) { return false; } else { return true; } } 
function gopos(stop) {
    $('html,body').animate({ scrollTop: stop }, "fast"); 
}

function goAjax(action_url, data, callback, datatype, method) { $.ajax({ type: method || 'POST', datatype: datatype || 'text', url: action_url, contentType: 'application/x-www-form-urlencoded; charset=utf-8', data: data, cache: false, beforeSend: function () { }, complete: function () { }, success: function (result) { callback(result); }, error: function () { } }); } function goJson(action_url, data, callback) { $.getJSON(action_url, data, function (result) { callback(result); }); }

//  pageAlert("xxx！", 0, 1500);
function pageAlert(msg, ok1fail0, minseconds_hide) {
    var winH = $(window).height();
    var winW = $(window).width();
    var mtop = (winH / 2) + 50;
    if ($(".webalter_obj").length > 0) {
        $(".webalter_obj").remove();
    }
    $("body").append("<div class='webalter_obj' style='position:fixed;top:-200px;left:0;z-index:999999;right:0;bottom:0;width:100%;transition:top 0.5s;-moz-transition:top 0.5s; -webkit-transition:top 0.5s;-o-transition:top 0.5s;text-align:center;'><div class='webalertinfo' style='background:#fff url(/res/i/msg_alert.gif) 5px 6px no-repeat;border:solid 1px #d0d0d0;border-radius:5px;line-height:22px;padding:20px 10px 20px 60px;font-size:15px;display:inline-block;margin:0 auto;'></div></div");
    setTimeout(function () {
        $(".webalter_obj").css("top", mtop);
    }, 100);
    if (ok1fail0 == 1) { $(".webalter_obj .webalertinfo").css("background", "#fff url(/res/i/msg_yes.gif) 10px center no-repeat"); }
    $(".webalter_obj .webalertinfo").html(msg);
   setTimeout(function () { $(".webalter_obj").remove(); }, minseconds_hide);
}
