﻿function E() {
    var elements = new Array();
    for (var i = 0; i < arguments.length; i++) {
        var element = arguments[i];
        var element1;
        if (typeof arguments[i] == "string") {
            element1 = document.getElementById("ContentPlaceHolder1_" + element);
            if (element1 == null) {
                element1 = document.getElementById("ctl00_ContentPlaceHolder1_" + element);
                if (element1 == null) {
                    element1 = document.getElementById("ctl00$ContentPlaceHolder1$" + element);
                    if (element1 == null)
                        element1 = document.getElementById(element);
                }
            }
        }
        if (arguments.length == 1) {
            return element1;
        }
        elements.push(element1);
    }
    return elements;
}



var EncodeURI = function (unzipStr, isCusEncode) {
    if (isCusEncode) {
        var zipArray = new Array();
        var zipstr = "";
        var lens = new Array();
        for (var i = 0; i < unzipStr.length; i++) {
            var ac = unzipStr.charCodeAt(i);
            zipstr += ac;
            lens = lens.concat(ac.toString().length);
        }
        zipArray = zipArray.concat(zipstr);
        zipArray = zipArray.concat(lens.join("O"));
        return zipArray.join("N");
    } else {
        //return encodeURI(unzipStr);
        var zipstr = "";
        var strSpecial = "!\"#$%&'()*+,/:;<=>?[]^`{|}~%";
        var tt = "";

        for (var i = 0; i < unzipStr.length; i++) {
            var chr = unzipStr.charAt(i);
            var c = StringToAscii(chr);
            tt += chr + ":" + c + "n";
            if (parseInt("0x" + c) > 0x7f) {
                zipstr += encodeURI(unzipStr.substr(i, 1));
            } else {
                if (chr == " ")
                    zipstr += "+";
                else if (strSpecial.indexOf(chr) != -1)
                    zipstr += "%" + c.toString(16);
                else
                    zipstr += chr;
            }
        }
        return zipstr;
    }
}

var DecodeURI = function (zipStr, isCusEncode) {
    if (isCusEncode) {
        var zipArray = zipStr.split("N");
        var zipSrcStr = zipArray[0];
        var zipLens;
        if (zipArray[1]) {
            zipLens = zipArray[1].split("O");
        } else {
            zipLens.length = 0;
        }
        var uzipStr = "";
        for (var j = 0; j < zipLens.length; j++) {
            var charLen = parseInt(zipLens[j]);
            uzipStr += String.fromCharCode(zipSrcStr.substr(0, charLen));
            zipSrcStr = zipSrcStr.slice(charLen, zipSrcStr.length);
        }
        return uzipStr;
    } else {
        //return decodeURI(zipStr);
        var uzipStr = "";
        for (var i = 0; i < zipStr.length; i++) {
            var chr = zipStr.charAt(i);
            if (chr == "+") {
                uzipStr += " ";
            } else if (chr == "%") {
                var asc = zipStr.substring(i + 1, i + 3);
                if (parseInt("0x" + asc) > 0x7f) {
                    uzipStr += decodeURI("%" + asc.toString() + zipStr.substring(i + 3, i + 9).toString()); ;
                    i += 8;
                } else {
                    uzipStr += AsciiToString(parseInt("0x" + asc));
                    i += 2;
                }
            } else {
                uzipStr += chr;
            }
        }
        return uzipStr;
    }
}

var StringToAscii = function (str) {
    return str.charCodeAt(0).toString(16);
}

var AsciiToString = function (asccode) {
    return String.fromCharCode(asccode);
}


function HTAjaxws(servericeUrl, method, data, callback, isasync) {
    $.ajax({
        type: "POST",
        async: isasync == false ? false : true,
        contentType: "application/json; charset=utf-8",
        url: servericeUrl + "/" + method,
        data: "{" + data + "}",
        dataType: "json",
        success: callback
    });
    return;
}

function AllCheck(box, obj) {

    if ($("#" + obj + "").is(":checked")) {
        $("#" + box + " input[type=checkbox]").attr("checked", true);
    }
    else {
        $("#" + box + " input[type=checkbox]").attr("checked", false);
    }
}

function ltrim(s) {
    if (s != null) {
        return s.replace(/^\s*/, "");
    }
    return "";
}

function rtrim(s) {
    if (s != null) {
        return s.replace(/\s*$/, "");
    }
    return "";
}

function trim(s) {
    return rtrim(ltrim(s));
}

function loginPlease() {
    dialog('用户登陆', 'iframe:/UserLogin.aspx', 300, 'auto', '');
}

function HTAlert(info) {
     dialog('友情提示', 'text:'+info, 300, 'auto', '');
}

function HTShowDialog(title,msg,width ) {   
    dialog(title, 'text:' + msg, width, 'auto', '');  
}

function ChangeDiv(divId, divName, zDivCount) {
    for (i = 0; i <= zDivCount; i++) {
        E(divName + i).style.display = "none";
    }
    document.getElementById(divName + divId).style.display = "block";
    if (divId == "0") {
        E("personal_publish").className = "personal_bg_color";
        E("personal_graffiti").className = "";
    }
    else {
        E("personal_publish").className = "";
        E("personal_graffiti").className = "personal_bg_color";
    }
}

function dialog(title, content, width, height, cssName) {
   
    if (typeof ($("#floatBoxBg")[0]) == "undefined") {
        $("body").append("<div id='floatBoxBg'>&nbsp;</div>");
    }
    $("#floatBoxBg").css('filter', 'alpha(opacity=0)');
    $("#floatBoxBg").css('opacity', '0');


    if (typeof ($("#floatBox")[0]) != "undefined") {
        $("#floatBox").remove();
    }
    $("body").append("<div id='floatBox'></div>");
    $("#floatBox").append(' <div class="title"><h4></h4><span>关闭</span></div>  <div class="content">  </div>');


    $("#floatBox .title span").click(function () {
        $("#floatBox").remove();
        $("#floatBoxBg").remove();
    });

    $("#floatBox .title h4").html(title);
    contentType = content.substring(0, content.indexOf(":"));
    content = content.substring(content.indexOf(":") + 1, content.length);
    var topmargin = 250;
    switch (contentType) {
        case "url":
            var content_array = content.split("?");
            $("#floatBox .content").ajaxStart(function () {
                $(this).html("loading...");
            });
            $.ajax({
                type: content_array[0],
                url: content_array[1],
                data: content_array[2],
                error: function () {
                    $("#floatBox .content").html("error...");
                },
                success: function (html) {
                    $("#floatBox .content").html(html);
                }
            });
            break;
        case "text":
            $("#floatBox .content").html(content);
            break;
        case "id":
            $("#floatBox .content").html($("#" + content + "").html());
            break;
        case "iframe":
            {
                $("#floatBox .content").html("<iframe name=\"myiframe\" src=\"" + content + "\" width=\"100%\" height=\"" + (parseInt(height) - 30) + "px" + "\" scrolling=\"auto\" frameborder=\"0\" marginheight=\"0\" marginwidth=\"0\"  ></iframe>");
                topmargin = 70;
            }

    }
    $("#floatBoxBg").css({ height: document.body.clientHeight > document.documentElement.clientHeight ? document.body.clientHeight : document.documentElement.clientHeight }, "normal");
    $("#floatBoxBg").show();
    $("#floatBoxBg").animate({ opacity: "0.5" }, "normal");
    $("#floatBox").attr("class", "floatBox " + cssName);
    $("#floatBox").css({ display: "block", left: (($(document).width()) / 2 - (parseInt(width) / 2)) + "px", top: ($(document).scrollTop() - (height == "auto" ? 300 : parseInt(height))) + "px", width: width, height: height });
    $("#floatBox").animate({ top: ($(document).scrollTop() + topmargin) + "px" }, "normal");
}



  function clear_it() {
        inps = document.getElementsByTagName("input");
        for (i = 0; i < inps.length; i++) {
            if (inps[i].type != "button" && inps[i].type != "submit" && inps[i].type != "reset" && inps[i].type != "hidden")
                inps[i].value = "";
        }

        sels = document.getElementsByTagName("select");
        for (i = 0; i < sels.length; i++) {
            sels[i].options[0].selected = true;
        }

    }

    function TextValidate() {
        var code;
        var character;
        var err_msg = "Text can not contain SPACES or any of these special characters  other than underscore (_) and hyphen (-).";
        if (document.all) //判断是否是IE浏览器 
        {
            code = window.event.keyCode;
        }
        else {
            code = arguments.callee.caller.arguments[0].which;
        }
        var character = String.fromCharCode(code);

        var txt = new RegExp("[\\/\\<\\>]");
        //特殊字符正则表达式 

        if (txt.test(character)) {
            HTAlert("请注意，不能输入以下字符:\n \t   /  < > \" ");
            if (document.all) {
                window.event.returnValue = false;
            }
            else {
                arguments.callee.caller.arguments[0].preventDefault();
            }
        }
    }





