﻿//获取上传input的value
function getUploadValue(obj) {
    if (navigator.userAgent.indexOf("Firefox") > 0) {
        return obj.files.item(0).getAsDataURL();
    }
    else if (navigator.userAgent.indexOf("MSIE") > 0 && parseInt(navigator.appVersion) >= 4) {
        return obj.value;
    }
    return "";
}

//可遍历某DOM下的所有DOM,包括子元素的子元素...
/*
@parentDom:要遍历的DOM引用
@func:遍历的操作函数,第一个参数:遍历到的DOM(单个)
*/
function traversalDom(parentDom, func) {
    if (parentDom.childNodes != undefined) {
        for (var i = 0; i < parentDom.childNodes.length; i++) {
            func(parentDom.childNodes[i]);
            if (parentDom.childNodes[i] != undefined && parentDom.childNodes[i].childNodes.length > 0) traversalDom(parentDom.childNodes[i], func);
        }
    }
}

//某输入框,只能输入数字,在输入框的onkeydown中调用
/*
同时禁用输入法
style="ime-mode:disabled" onkeydown="return InputInteger(event)"
*/
function InputInteger(event) {
    var e = event || window.event;
    var k = e.keyCode;
    //启用删除,复制,粘贴,剪切,方向键左右
    if ((k >= 48 && k <= 57) || (k >= 96 && k <= 105) || k == 8 || k == 46 || k == 37 || k == 39 || (e.ctrlKey && (k == 67 || k == 86 || k == 88))) return true;
    else return false;
}

//把选中的项移动位置,toIndex:移动到的索引,超出范围则没任何效果
function SelectedIndexMoveTo(id, toIndex) {
    var s = $(id)[0];
    if (toIndex >= 0 && toIndex < s.options.length && s != undefined && s != null) {
        var tValue = s.options[s.selectedIndex].value;
        var tText = s.options[s.selectedIndex].innerHTML;
        s.options[s.selectedIndex].value = s.options[toIndex].value;
        s.options[s.selectedIndex].innerHTML = s.options[toIndex].innerHTML;
        s.options[toIndex].value = tValue;
        s.options[toIndex].innerHTML = tText;
        s.selectedIndex = toIndex;
    }
}

//获取滚动条的位置
function getScrollTop() {
    var scTop, scLeft;
    if (typeof window.pageYOffset != 'undefined') {
        scTop = window.pageYOffset;
        scLeft = window.pageXOffset;
    }
    else if (typeof document.compatMode != 'undefined' && document.compatMode != 'BackCompat') {
        scTop = document.documentElement.scrollTop;
        scLeft = document.documentElement.scrollLeft;
    }
    else if (typeof document.body != 'undefined') {
        scTop = document.body.scrollTop;
        scLeft = document.body.scrollLeft;
    }
    return { top: scTop, left: scLeft };
}
//获取元素绝对位置
function getAbsoluteLocation(element) {
    if (arguments.length != 1 || element == null) {
        return null;
    }
    var offsetTop = element.offsetTop;
    var offsetLeft = element.offsetLeft;
    var offsetWidth = element.offsetWidth;
    var offsetHeight = element.offsetHeight;
    while (element = element.offsetParent) {
        offsetTop += element.offsetTop - element.scrollTop;
        offsetLeft += element.offsetLeft - element.scrollLeft;
    }
    return { left: offsetLeft, top: offsetTop };
}


//获取鼠标位置****************************************
//调用mouseCoords(event),返回{x,y}
function mouseCoords(ev) {
    if (ev.pageX || ev.pageY) {
        return { x: ev.pageX, y: ev.pageY };
    }
    return {
        x: ev.clientX + document.body.scrollLeft - document.body.clientLeft,
        y: ev.clientY + document.body.scrollTop - document.body.clientTop
    };
}
//获取鼠标位置结束***********************************


//全选
function CheckboxAll() {
    $(":checkbox").each(function() {
        $(this).attr("checked", true);
    });

}

//取消全选
function UnCheckboxAll() {
    $(":checkbox").each(function() {
        $(this).attr("checked", false);
    });

}

//反选
function InverseCheckboxAll() {
    $(":checkbox").each(function() {
        if ($(this).attr("checked")) {
            $(this).attr("checked", false);
        } else {
            $(this).attr("checked", true);
        }
    });
}
//取值
function getCheckboxListValues() {
    var s = '';
    $(":checkbox").each(function() {
        if ($(this).attr("checked")) {
            s = s + ($(this)).attr("value") + ',';
        }
    });
    return s;
}

//全选
function CheckboxAllByName(checkName) {
    $(":checkbox[name='" + checkName + "']").attr('checked', true);
}
//取消
function UnCheckboxAllByName(checkName) {
    $(":checkbox[name='" + checkName + "']").attr('checked', false);
}
//反选
function InverseCheckboxAllByName(checkName) {
    $(":checkbox[name='" + checkName + "']").each(function() {
        if ($(this).attr("checked")) {
            $(this).attr("checked", false);
        } else {
            $(this).attr("checked", true);
        }
    });

}

//取值
function getCheckboxListValuesByName(checkName) {
    var s = '';
    $(":checkbox[name='" + checkName + "']").each(function() {
        if ($(this).attr("checked")) {
            s = s + ($(this)).attr("value") + ',';
        }
    });
    return s;

//    $.each($("input[name='CheckboxIds']"), function(i, n) {
//        if (n.checked) {
//            idsArr.push(n.value);
//        }
//    });
//    if (idsArr == null || idsArr == "") {
//        return;
//    }
//    var ids = idsArr.join(",");
}

//设置选中复选框项
function setCheckboxListValuesByName(checkName, s) {
    var thisarray = s.split(",");
    $(":checkbox[name='" + checkName + "']").each(function() {
        for (thisval in thisarray) {
            if ($(this).attr("value") == thisarray[thisval]) {                         
                $(this).attr("checked", true); //打勾                
            }
        }
    });    
}
//格式化浮点数
function formatFloat(src, pos) {
    return Math.round(src * Math.pow(10, pos)) / Math.pow(10, pos);
} //alert(formatFloat("1212.2323", 2)); 

//读取Cookie
//valueName可为空
//对应Request.Cookies[cookieName].Values[valueName]
//valueName为空则对应Request.Cookies[cookieName].Value
function GetCookie(cookieName, valueName) {
    var cookie = document.cookie, dIndex, tempList, n, m;
    cookie = $.trim(cookie);
    var cookies = cookie.split(";");
    for (var i = 0; i < cookies.length; i++) {
        n = $.trim(cookies[i]);
        dIndex = n.indexOf("=");
        if (dIndex != -1 && n.substr(0, dIndex) == cookieName) {
            if (!valueName) return decodeURI($.trim(n.substr(dIndex + 1, n.length - dIndex - 1)));
            tempList = n.substr(dIndex + 1, n.length - dIndex - 1).split("&");
            for (var j = 0; j < tempList.length; j++) {
                m = $.trim(tempList[j]);
                var d2Index = m.indexOf("=");
                if (d2Index != -1 && m.substr(0, d2Index) == valueName) {
                    return decodeURI($.trim(m.substr(d2Index + 1, m.length - d2Index - 1)));
                }
            }
        }
    }
    return "";
}

//通用,在查询的时候选择全部,把所有text清空,select选择第一项
function selectAllBySearch(inDivID) {
    $(inDivID + " :text").val("");
    var selectList = $(inDivID + " select");
    for (var i = 0; i < selectList.length; i++) {
        if (selectList[i].options.length > 0) {
            selectList[i].selectedIndex = 0;
        }
    }
}


//显示创建框
function showCreate() {
    $("#CreateDiv").show();
    $("#CreateButton").hide();
}

//隐藏AjaxDiv
function hideAjaxDiv() {
    $("#AjaxDiv").html("");
    $("#AjaxDiv").hide();
}

//显示创建按钮
function showButton() {
    $("#ErrorInfo").html("");
    $("#CreateDiv").hide();
    $("#CreateButton").show();
}

//编辑的时候显示隐藏编辑
//显示隐藏编辑
function showEdit(id) {
    $(".Detail" + id).hide();
    $(".Edit" + id).show();
//    var l = $(".Edit" + id),eHtml;
//    for (var i = 0; i < l.length; i++) {
//        eHtml = l[i].editHtml;
//        if (eHtml != undefined && eHtml != "") {
//            l[i].innerHTML = eHtml;
//        }
//        else {
//            l[i].editHtml = l[i].innerHTML;
//        }
//    }
}

function showDetail(id) {
    if (confirm("当前处于编辑状态,是否强制退出编辑?")) {
        $(".Edit" + id).hide();
        $(".Detail" + id).show();
    }
}

//设置对象的值为空
function setObjNull(obj) {
    $("#" + obj).val("");
}

//显示固定DIV
function showObjById(obj) {
    $("#" + obj).show();
}

//隐藏固定DIV
function hideObjById(obj) {
    $("#" + obj).hide();
}

//显示隐藏类
function showClassObj(classObj){
    $("." + classObj).show();
}

function hideClassObj(classObj) {
    $("." + classObj).hide();
}

//操作之后的提示信息
function configHide(div,callBack) {
    $(div).fadeOut("slow", callBack);
}
function configShow(div, callBack) {
    $(div).fadeIn("slow", callBack);
}
//参数:
//hodHideDiv:等待一个DIV显示,就隐藏
function configAlert(s, div, hodHideDiv,isno) {
    $(div).html("<div class=\"info\">" + s + "</div>");
    clearTimeout($(div).attr("ShowSetTimeout"));
    if(!isno) window.location.href = "#";   
    configShow(div, function() {
        if (hodHideDiv) {
            $(hodHideDiv).attr("hideDiv", div);
        }
        else {
            var hideDiv = $(div).attr("hideDiv");
            $(hodHideDiv).attr("hideDiv", "");
            if (hideDiv) {
                configHide(hideDiv);
            }
            $(div).attr("ShowSetTimeout", setTimeout("configHide('" + div + "')", 5000));
        }
    });
}



//设置某ID的隐藏和显示,用于根据某值同步某对象的隐藏和显示,如:
//把一个DIV的隐藏和显示绑定在一个checkbox上
/*
<input type="checkbox" onchange="setObjShowOrHidden('#test',$(this).attr('checked'))" /><div id="test"></div>
*/
//或控制当某个下拉菜单选项改变到指定项时,隐藏某层..等
function setObjShowOrHidden(objId, isShow) {
    if (isShow + "" == "true") {
        $(objId).show();
    }
    else {
        $(objId).hide();
    }
}

//无限联级下拉菜单
//存放所有菜单项
var laMenuData = new Array();
//注册/设置菜单
function RegeditMenu(menuName, parentID, value, text) {
    var i = laMenuData.length;
    laMenuData[i] = new Array();
    laMenuData[i]["menuName"] = menuName;
    laMenuData[i]["parentID"] = parentID;
    laMenuData[i]["text"] = text;
    laMenuData[i]["value"] = value;
}

//清除
function ClearMenuByName(name) {
    for (var i = 0; i < laMenuData.length; i++) {
        if (name == laMenuData[i]["menuName"]) {
            laMenuData.splice(i, 1);
            i--;
        }
    }
}

//根据父ID获取所有子项,并把子项组成下拉菜单(HTML格式),并可以有默认选中项
function GetMenuChildsHtml(menuName, parentID, selectId, selectedValue, attr, isno, selectedText) {    
    var reHtml = "<select name='" + (selectId ? selectId : "") + "' id='" + (selectId ? selectId : "") + "' " + (attr ? attr : "") + ">";
    if (isno) {
        reHtml += "<option value='-1'>" + "=请选择=" + "</option>";
    }
    for (var i = 0; i < laMenuData.length; i++) {
        if (laMenuData[i]["menuName"] == menuName && laMenuData[i]["parentID"] == parentID) {
            reHtml += "<option value='" + laMenuData[i]["value"] + "'" + (selectedValue == laMenuData[i]["value"] ? " selected='true'" : (selectedText == laMenuData[i]["text"] ? " selected='true'" : "")) + ">" + laMenuData[i]["text"] + "</option>";
        }
       
    }
    return reHtml;
}

//获取页面正文的尺寸
function getPageSize() {
    if (document.documentElement) {
        return { width: parseInt(document.documentElement.scrollWidth), height: parseInt(document.documentElement.scrollHeight) };
    }
    else {
        return { width: parseInt(document.body.scrollWidth), height: parseInt(document.body.scrollHeight) };
    }
}
//获取浏览器窗口的尺寸
function winDimensions() {
    var winHeight = 0, winWidth = 0;
    //获取窗口宽度
    if (window.innerWidth && window.innerHeight) {
        winWidth = window.innerWidth;
        winHeight = window.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight && document.documentElement.clientWidth) {
        winHeight = document.documentElement.clientHeight;
        winWidth = document.documentElement.clientWidth;
    }
    else if ((document.body) && (document.body.clientWidth)) {
        winWidth = document.body.clientWidth;
        winHeight = document.body.clientHeight;
    }
    return { winWidth: winWidth, winHeight: winHeight };
}


//通用--用DIV模拟拟态窗口
//使用说明:
/*
使用场景:
要将一HTML对象里的HTML展现
将该HTML对象里的HTML显示在一个最顶层的定位DIV中,并同时用一个DIV遮盖住后方的页面,实现禁用页面
可在同一个页面使用多个拟态窗口(即:可同时展示不同的HTML对象)
调用:
showNiWindow(要展现的HTML对象ID(不加前缀),该对象出现的拟态窗口的样式(为""或为null则使用默认样式),拟态窗口的标题(可为HTML代码,默认为空))

生成的代码:
<div class="NiWindow_hiPanelDiv NiWindow_hiPanelDiv"+特定的ClassName(默认为空) ></div>
<div class="NiWindow_body"+特定的ClassName(默认为空)>
    <div class="NiWindow_title"+特定的ClassName(默认为空)>
        <div class="NiWindow_titleLeft"+特定的ClassName(默认为空)></div>
        <div class="NiWindow_titleRight"+特定的ClassName(默认为空)></div>
    </div>
    <div class="NiWindow_content"+特定的ClassName(默认为空)></div>
</div>

默认的,只要设置以下几个样式
.NiWindow_hiPanelDiv{}//用来遮盖的层
.NiWindow_body{}//整个窗体层
.NiWindow_title{}//窗体的标题层
.NiWindow_titleLeft{}//标题里的第一个层
.NiWindow_titleRight{}//标题里的第二个层(里面放置一个"×"连接,用于关闭拟态窗体)
.NiWindow_content{}//放置需要展示的HTML对象里的HTML

如果需要对某个展示设置新的样式
只需调用的时候:showNiWindow(要展示的HTML对象的ID,新的样式名,标题)
那么需要特别设置的样式名为:相应部位+新的样式名(如:showNiWindow("id","New","测试标题");  遮盖层的样式名:NiWindow_hiPanelDiv NiWindow_hiPanelDivNew)
*/
var thisMoveDiv = null;
var thisMoveDivExcX = 0;
var thisMoveDivExcY = 0;
function documentMouseMove(event) {
    if (thisMoveDiv) {
        var mouse = mouseCoords(event);
        thisMoveDiv.css({ "left": mouse.x - thisMoveDivExcX, "top": mouse.y - thisMoveDivExcY });
        return false;
    }
}
function showNiWindow(objId, className, titleHtml) {
    if (!className) className = "";
    if (!title) title = "";
    var hiPanelDiv, body, title, content, titleLeft, titleRight;
    if ($("#NiWindow_hiPanelDiv" + objId + "_" + className).length > 0) {
        hiPanelDiv = $("#NiWindow_hiPanelDiv" + objId + "_" + className)[0];
        body = $("#NiWindow_body" + objId + "_" + className)[0];
        title = $("#NiWindow_title" + objId + "_" + className)[0];
        titleLeft = $("#NiWindow_titleLeft" + objId + "_" + className)[0];
        titleRight = $("#NiWindow_titleRight" + objId + "_" + className)[0];
        content = $("#NiWindow_content" + objId + "_" + className)[0];
    }
    else {
        hiPanelDiv = document.createElement("DIV");
        body = document.createElement("DIV");
        title = document.createElement("DIV");
        titleLeft = document.createElement("DIV");
        titleRight = document.createElement("DIV");
        content = document.createElement("DIV");

        $(title).css({cursor:"move"});

        $(hiPanelDiv).attr("class", "NiWindow_hiPanelDiv " + (className ? "NiWindow_hiPanelDiv" + className : ""));
        $(body).attr("class","NiWindow_body " + (className ? "NiWindow_body" + className : ""));
        $(title).attr("class", "NiWindow_title " + (className ? "NiWindow_title" + className : "")) ;
        $(titleLeft).attr("class", "NiWindow_titleLeft " + (className ? "NiWindow_titleLeft" + className : "")) ;
        $(titleRight).attr("class","NiWindow_titleRight " + (className ? "NiWindow_titleRight" + className : "")) ;
        $(content).attr("class", "NiWindow_content " + (className ? "NiWindow_content" + className : ""));

        hiPanelDiv.id = "NiWindow_hiPanelDiv" + objId + "_" + className;
        body.id = "NiWindow_body" + objId + "_" + className;
        title.id = "NiWindow_title" + objId + "_" + className;
        titleLeft.id = "NiWindow_titleLeft" + objId + "_" + className;
        titleRight.id = "NiWindow_titleRight" + objId + "_" + className;
        content.id = "NiWindow_content" + objId + "_" + className;
        
        title.appendChild(titleLeft);
        title.appendChild(titleRight);
        document.body.appendChild(body);
        document.body.appendChild(hiPanelDiv);

        var bodyC = $("<div style='position:relative;width:100%;height:100%;z-index:2;top:0;left:0;'></div>");
        bodyC.append(title).append(content);
        
        //用于IE防止被下拉菜单(select)遮盖
        var hiPanelIfr = $('<iframe src="javascript:{void(0);}" style="width:10000px;height:10000px;position:absolute;z-index:1;top:0;left:0;border:none;filter:alpha(opacity=1);-moz-opacity: 0.01;opacity: 0.01;" frameborder="0"></iframe>');
        $(body).append(bodyC);
        $(hiPanelDiv).append(hiPanelIfr);
        var hiPanelIfrDoc = hiPanelIfr[0].contentWindow.document;
        hiPanelIfrDoc.write("&nbsp;");
        hiPanelIfrDoc.close();

        $(title).mousedown(function(even) {
            var mouse = mouseCoords(even);
            var ofs = $(body).offset();
            thisMoveDiv = $(body);
            thisMoveDivExcX = mouse.x - ofs.left;
            thisMoveDivExcY = mouse.y - ofs.top;
            var moveEndFunc = function() {
                $(document).unbind("mousemove", documentMouseMove);
                thisMoveDiv = null;
                resetNiHiPanel(objId, className);
            };
            $(document).mousemove(documentMouseMove).one("mouseup", moveEndFunc);
        }).css({ "-moz-user-select": "-moz-none" });
        title.onselectstart = function() { return false; };

        $(titleRight).html("<a href=\"javascript:void(0);\" title=\"关闭\" onclick=\"closeNiWindow('" + objId + "','" + className + "');return false;\">×</a>");

        $(window).resize(function() {
            resetNiWindow(objId, className);
        });
    }

    var tempHtml = $("#" + objId).html();
    $("#" + objId).html("");
    $(content).html("<div class=\"ErrorInfo\"></div><div class=\"ConfigInfo\"></div>" + tempHtml+"<div class=\"clear\"></div>"); //增加错误显示DIV,增加了耦合度,如果移植,将该DIV去除

    
    content.style.cssText = $("#" + objId)[0].style.cssText;
    $(content).show();
    
    $(titleLeft).html(titleHtml);
    $(hiPanelDiv).show();
    $(body).show();

    resetNiWindow(objId, className);
}
var setTimeoutResetHiWinHandle = {};
function resetNiWindow(objId, className) {
    if (!className) className = "";

    var body = $("#NiWindow_body" + objId + "_" + className);
    
    var bodyTop = (winDimensions().winHeight - $(body)[0].offsetHeight) / 2;
    var bodyLeft = (winDimensions().winWidth - $(body)[0].offsetWidth) / 2;
    if (bodyTop < 0) bodyTop = 0;
    if (bodyLeft < 0) bodyLeft = 0;
    bodyTop += getScrollTop().top;
    bodyLeft += getScrollTop().left;
    
    body.css({ "left": bodyLeft + "px", "top": bodyTop + "px", "z-index": "2", "position": "absolute" });
    resetNiHiPanel(objId, className);

}
function resetNiHiPanel(objId, className) {
    var hiPanelDiv = $("#NiWindow_hiPanelDiv" + objId + "_" + className);
    if (hiPanelDiv.is(":visible")) {
        if (!className) className = "";
        hiPanelDiv
        .hide()
        .css({ "width": (getPageSize().width - 1) + "px", "height": getPageSize().height + "px", "position": "absolute", "top": "0", "left": "0", "z-index": "1" })
        .show();

        if (!setTimeoutResetHiWinHandle[objId + "_" + className]) {
            setTimeoutResetHiWinHandle[objId + "_" + className] = setTimeout(function() { resetNiHiPanel(objId, className); }, 500);
        }
    }
}
function closeNiWindow(objId, className) {
    if (!className) className = "";
    clearTimeout(setTimeoutResetHiWinHandle[objId + "_" + className]);
    $("#NiWindow_hiPanelDiv" + objId + "_" + className).hide().html("");
    $("#NiWindow_body" + objId + "_" + className).fadeOut(300);
    var content = $("#NiWindow_content" + objId + "_" + className);
    tempHtml = content.html();
    content.html("");
    $("#" + objId).html(tempHtml);
}




//POST获取下拉菜单(缓存获取)****************************************************
/*
说明:
使用场景:在多个地方使用同一个列表(列表里的项相同(每个的Value和Text),项的个数相同,但ID可以不同)
为了不用重新获取数据,和减少HTML代码冗余,使用本方法,对同一个列表,进行获取
说明参数:
sendData:获取列表的POST参数
url:列表的获取地址
rebackExec:载入完后执行的回调
getSelectFunc:获取到菜单时,显示前,执行该函数,并将下拉菜单对象作为参数传入
,isnocache:是否需要缓存
selectListStr:直接取得的data数据
本功能的下拉菜单缓存,是使用url+sendData进行标识每个菜单
只要url+sendData都一致,那么将从缓存中读取,否则POST读取
*/
var cacheData = new Array();
//载入中的列队,如果在同时请求同一个数据,那么后面一个请求等待前一个请求完毕,然后 后一个请求直接从缓存中读取数据,从而减少一个请求的数据
var cachePostList = new Array();
function getObjectSelectList(sendData, url, showObjID, selectID, value, attrs, parentValue, rebackExec, getSelectFunc, isnocache, selectListStr) {
    var key = "key" + encodeURIComponent(url).replace(/\%/gi, "").replace(/^\d/, ""), kl;
    for (var k in sendData) {
        kl = k.toLocaleLowerCase();
        if (kl != "selectname" && kl != "selectid" && kl != "attr" && kl != "selectvalue" && kl != "value" && kl != "attrs") key += encodeURIComponent(sendData[k]).replace(/\%/gi, "");
    }
    var loading = "<select id=\"" + selectID + "\"><option value=\"\">载入中...</option></select>";
    if (selectListStr != undefined && selectListStr != "" && selectListStr != null) {
        cacheData[key] = new SelectList(selectListStr, selectID, attrs);
    }
    //判断同样的请求是否在POST中,如果是的话,继续等待,如果已经请求完毕,则取数据
    if (cachePostList[key]) {//有同样的数据在请求
        if (cacheData[key]) {//已经取得数据
            cachePostList[key] = null;
        }
        else {
            $(showObjID).html(loading);
            setTimeout(function() {
                getObjectSelectList(sendData, url, showObjID, selectID, value, attrs, parentValue, rebackExec, getSelectFunc, selectListStr);
            }, 500);
            return "loading";
        }
    }
    else {
        cachePostList[key] = "load";
    }
    if ((cacheData[key] && isnocache != true) || selectListStr != undefined) {
        cacheData[key].id = selectID;
        cacheData[key].attr = attrs;
        var exObj = cacheData[key];
        if (getSelectFunc) {
            exObj = new SelectList(exObj.toString(value, parentValue, selectID, attrs), cacheData[key].id, cacheData[key].attr);
            getSelectFunc(exObj);
            $(showObjID).html(exObj.toString(value, false, selectID, attrs));
        }
        else {
            $(showObjID).html(exObj.toString(value, parentValue, selectID, attrs));
        }
        if (rebackExec) eval(rebackExec);
    }
    else {
        $(showObjID).html(loading);
        $.post(url, sendData, function(data) {
            cacheData[key] = new SelectList(data, selectID, attrs);
            var exObj = cacheData[key];
            if (getSelectFunc) {
                exObj = new SelectList(exObj.toString(value, parentValue, selectID, attrs), cacheData[key].id, cacheData[key].attr);
                getSelectFunc(exObj);
                $(showObjID).html(exObj.toString(value, false, selectID, attrs));
            }
            else {
                $(showObjID).html(exObj.toString(value, parentValue, selectID, attrs));
            }
            /*临时替换,没对比是否一致,先注释,对比一致后删除该段
            if (getSelectFunc) {
            exObj = new SelectList(cacheData[key].items, cacheData[key].id, cacheData[key].attr);
            getSelectFunc(exObj);
            }
            $(showObjID).html(exObj.toString(value, parentValue, selectID, attrs));
            */
            if (rebackExec) eval(rebackExec);
        });
    }
    return true;
}
//selectParent object
/*
var list=new Array();
list[0]=new SelectItem(1900,1900,{});
list[1]=new SelectItem(1900,1900,{});
var selectList=new SelectList(list,"year");
cacheData["year"]=selectList;
$("#spanY").html(selectList.toString("1900",null,"onchange=''"));

*/
//可自定义属性,Value的Option
function SelectItem(value, text, attr) {
    this.value = value ? value + "" : "";
    this.text = text ? text + "" : "";
    this.attr = attr ? (typeof (attr).toLocaleString() == "object" ? attr : {}) : {};

    this.init = function(optionObj) {
        this.text = optionObj.text;
        var list = optionObj.attributes;
        var name, tempStr;
        for (var i = 0; i < list.length; i++) {
            if (list[i].nodeValue != undefined && list[i].nodeValue + "" != "") {
                name = list[i].name.toLowerCase();

                if (name != undefined && name != null && name != false && name != "" && list[i].nodeValue != undefined && list[i].nodeValue + "" != "") {
                    switch (name) {
                        case "value":
                            this.value = list[i].nodeValue;
                            break;
                        case "selected":
                            break;
                        case "disabled":
                            break;
                        default:
                            this.attr[name] = list[i].nodeValue;
                            break;
                    }
                }
            }
        }
    };

    this.attrToString = function() {
        var s = "";
        for (var r in this.attr) {
            s += " " + r + "=\"" + this.attr[r] + "\"";
        }
        return s;
    };

    this.toString = function(isSelected) {
        return "<option" + this.attrToString() + " value=\"" + this.value.replace("\"", "&#34;") + "\"" + (isSelected ? " selected=\"true\"" : "") + ">" + this.text.replace("<", "&lt;").replace(">", "&gt;") + "</option>";
    };
}
//selectList object
//带有父节点的下拉菜单
function SelectList(selectList, selectID, attrs) {
    if (!selectList) {
        alert("Error:selectList为必须参数!");
        return null;
    }
    this.items = new Array();

    this.id = selectID ? selectID + "" : "";
    this.attr = attrs ? attrs + "" : "";
    
    if (typeof (selectList) == "string") {
        var t = document.createElement("DIV");
        t.innerHTML = selectList;
        var list = t.childNodes[0];
        if (this.id == "") {
            this.id = list.id;
        }
        if (this.attr == "") {
            this.attr = $(list).attr("onchange") ? $(list).attr("onchange") : "";
        }
        list = list.options;
        if (list) {
            var tempSelectItem;
            for (var i = 0; i < list.length; i++) {
                tempSelectItem = new SelectItem();
                tempSelectItem.init(list[i]);
                this.items.push(tempSelectItem);
            }
        }
    }
    else if (selectList.length) {
        var item;
        for (var i = 0; i < selectList.length; i++) {
            item = selectList[i];
            this.items.push(new SelectItem(item.value, item.text, item.attr));
        }
    }
    else {
        alert("Error:selectList不能转换");
        return null;
    }


    this.toString = function(defaultValue, parentValue, selectID, attr) {
        parentValue += "";
        var reStr = "<select id=\"" + (selectID ? selectID : this.id.replace("\"", "&#34;")) + "\" name=\"" + (selectID ? selectID : this.id.replace("\"", "&#34;")) + "\" " + (attr ? attr : this.attr) + ">";
        if (parentValue != "undefined" && parentValue != "false" && parentValue != "null") {//parentValue != undefined && parentValue != false
            var valueList;
            for (var i = 0; i < this.items.length; i++) {
                if (this.items[i].attr.parentvalue != undefined) {
                    valueList = new Array();
                    valueList = this.items[i].attr.parentvalue.split(",");
                    for (var j = 0; j < valueList.length; j++) {
                        if (valueList[j] == parentValue) {
                            reStr += this.items[i].toString(this.items[i].value == defaultValue);
                            break;
                        }
                    }
                }
            }
        }
        else {
            for (var i = 0; i < this.items.length; i++) {
                reStr += this.items[i].toString(this.items[i].value == defaultValue);
            }
        }
        reStr += "</select>";
        return reStr;
    };
}
//POST获取下拉菜单(缓存获取)  END ****************************************************



/*
对下拉菜单的搜索(按拼音和按字符匹配)
前提:一个已经存在的下拉菜单(取ID),一个已经存在的文本框(取ID),包含拼音转换程序PinYin.go
使用:SearchByPinYin.Init("下拉菜单ID名","文本框ID名")
在文本框输入,匹配到的结果将出现在文本框的下方,点击结果,将在下拉菜单中选中该结果
*/
var SearchByPinYin = {
    /*
    *初始化
    *@selectID:数据来源下拉菜单ID
    *@inputPinYID:用来输入的input的ID
    *@listClassName:设置显示结果的层的class,结果的结构:
                                                <div class="样式设置在这,默认样式:SearchByPinYinSearchList">
                                                <ul>
                                                <li><a href="javascript:void(0);">姓名</a></li>
                                                </ul>
                                                </div>
    *@skipIndex:初始化时,转换下拉菜单的text拼音时,跳过几个字符
    */
    Init: function(selectID, inputPinYID, listClassName, skipIndex) {
        if(!skipIndex)skipIndex=0;
        var s = $("#" + selectID), input = $("#" + inputPinYID);
        var searchDiv = document.createElement("div");
        searchDiv.id = selectID + "_selectList";
        if (listClassName != undefined) searchDiv.className = listClassName;
        else { searchDiv.className = "SearchByPinYinSearchList"; }
        searchDiv.style.cssText = "position:absolute;top:0;left:0;height:auto;display:none;";
        document.body.appendChild(searchDiv);
        var showFunc = function() {
            if($.trim(input.val())!="")SearchByPinYin.searchSelect(input[0], selectID);
        };
        input.keyup(showFunc).focus(showFunc).click(function(){return false;});
        $(document).click(function() {
            SearchByPinYin.hide(selectID);
        });
        for (var i = 0; i < s[0].options.length; i++) {
            var sTemp = s[0].options[i].text.split("").slice(skipIndex);
            for (var j = 0; j < sTemp.length; j++) {
                sTemp[j] = pinyin.go(sTemp[j]).substr(0, 1).toLocaleLowerCase();
            }
            $(s[0].options[i]).attr("pinyinSZM", sTemp.join(""));
        }
    },
    /*
    *内置函数,用于响应输入,开始搜索
    *@obj:输入框的引用
    *@selectID:用来输入的input的ID
    */
    searchSelect: function(obj, selectID) {
        var str = "";
        var s = $("#" + selectID);
        for (var i = 0; i < s[0].options.length; i++) {
            if ($(s[0].options[i]).attr("pinyinSZM").indexOf(obj.value.toLocaleLowerCase()) == 0 || s[0].options[i].text.toLocaleLowerCase().indexOf(obj.value.toLocaleLowerCase()) == 0) {
                str += "<li><a href=\"javascript:void(0);\" onclick=\"SearchByPinYin.select('#" + selectID + "'," + i + ")\">" + s[0].options[i].text + "</a></li>";
            }
        }
        var o = getAbsoluteLocation(obj), scrollO = getScrollTop();
        var left = o.left, top = o.top + obj.offsetHeight;
        $("#" + selectID + "_selectList").css({ left: left + "px", top: top + "px", "display": "block" }).html("<ul>" + str + "</ul>");
    },
    select: function(id, selectedIndex) {
        $(id)[0].selectedIndex = selectedIndex;
    },
    hide: function(selectID) {
        $("#" + selectID + "_selectList").hide();
    }
};




//根据表格里的表头自动排序
/*
关键函数(排序函数):sortTable
参数:要排序的表格ID名,排序的列索引(从零开始),排序类型[int|float|date](可空,空默认按字符串的排序方式)
*/
function convert(sValue, sDataType) {
    switch (sDataType) {
        case "int":
            return parseInt(sValue);
            break;
        case "float":
            return parseFloat(sValue);
            break;
        case "date":
            return new Date(Date.parse(sValue));
            break;
        default:
            return sValue.toString();
    }
}

function generateCompareTrs(iCol, sDataType) {
    return function compareTrs(oTr1, oTr2) {
        var vValue1 = convert(oTr1.cells[iCol].firstChild.nodeValue, sDataType);
        var vValue2 = convert(oTr2.cells[iCol].firstChild.nodeValue, sDataType);
        if (vValue1 < vValue2) {
            return -1;
        }
        else if (vValue1 > vValue2) {
            return 1;
        }
        else {
            return 0;
        }
    }
}
function sortTable(sTableId, iCol, sDataType) {
    var oTable = document.getElementById(sTableId);
    var oTBody = oTable.tBodies[0];
    var colDataRows = oTBody.rows;
    var aTrs = new Array();
    for (var i = 0; i < colDataRows.length; i++) {
        aTrs.push(colDataRows[i]);
    }
    if (oTable.sortCol == iCol) {
        aTrs.reverse();
    }
    else {
        aTrs.sort(generateCompareTrs(iCol, sDataType));
    }
    var oFragment = document.createDocumentFragment();
    for (var i = 0; i < aTrs.length; i++) {
        oFragment.appendChild(aTrs[i]);
    }
    oTBody.appendChild(oFragment);
    oTable.sortCol = iCol;
}



//我要地图
//****************************************************************************************************************************************************
//移动

var drag_=false;
var D = new Function('obj', 'return document.getElementById(obj);');
var oevent = new Function('e', 'if (!e) e = window.event;return e');
function Move_obj(obj) {
    var x, y;
    D(obj).onmousedown = function(e) {
        drag_ = true;
        with (this) {
            style.position = "absolute"; var temp1 = offsetLeft; var temp2 = offsetTop;
            x = oevent(e).clientX; y = oevent(e).clientY;
            document.onmousemove = function(e) {
                if (!drag_) return false;
                with (this) {
                    style.left = temp1 + oevent(e).clientX - x + "px";
                    style.top = temp2 + oevent(e).clientY - y + "px";
                }
            }
        }
        document.onmouseup = new Function("drag_=false");
    };
}
//移动结束
//****************************************************************************************************************************************************

