﻿// JScript File

function GetWindowWidth()
{
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        return window.innerWidth;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
       //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientWidth;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        return document.body.clientWidth;
    }
    return 0;
}

function GetWindowHeight()
{
    if( typeof( window.innerWidth ) == 'number' ) {
        //Non-IE
        return window.innerHeight;
    } else if( document.documentElement && ( document.documentElement.clientWidth || document.documentElement.clientHeight ) ) {
       //IE 6+ in 'standards compliant mode'
        return document.documentElement.clientHeight;
    } else if( document.body && ( document.body.clientWidth || document.body.clientHeight ) ) {
        //IE 4 compatible
        return document.body.clientHeight;
    }
    return 0;
}

function GetPositionTop(obj)
{
    var iTop = obj.offsetTop - obj.scrollTop;
    while (obj = obj.offsetParent)
        iTop = iTop + obj.offsetTop - obj.scrollTop;
    return iTop;
}

function GetPositionLeft(obj)
{
    var iLeft = obj.offsetLeft - obj.scrollLeft;
    while (obj = obj.offsetParent)
        iLeft = iLeft + obj.offsetLeft - obj.scrollLeft;
    return iLeft;
}

// 使用ActiveX控件，把HTML转换成XML格式
// 调用方法： var strXml;
//            strXml = Html2XmlByActiveX(tdLogin);
function Html2XmlByActiveX(node, xmlDoc, level)
{
    if (xmlDoc == null)
        xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
    if (level == null)
        level = 0;
    if (node == null)
    {
        if (level == 0)
        {
            if (xmlDoc != null)
            {
                return xmlDoc.xml;
            }
            else
            {
                return "";
            }
        }
        else
        {
            return null;
        }
    }
    var newXmlNode;
    if (node.nodeType == 3)
        newXmlNode = xmlDoc.createTextNode(node.nodeValue);
    else
    {
        newXmlNode = xmlDoc.createElement(node.nodeName);
        for (var j = 0; j < node.attributes.length; j++)
        {
            if (node.attributes[j].specified || node.attributes[j].name == "value")
            {
                if (node.attributes[j].name == 'style')
                    newXmlNode.setAttribute(node.attributes[j].name, node.getAttribute(node.attributes[j].name).cssText);
                else if (node.nodeName.toLowerCase() == 'img' && node.attributes[j].name == 'src')
                {
                    var re = new RegExp("http://.+?" + GetAbsoluteUrl("/"), "i");
                    newXmlNode.setAttribute(node.attributes[j].name, node.attributes[j].value.replace(re, "../"));
                }
                else
                    newXmlNode.setAttribute(node.attributes[j].name, node.attributes[j].value);
            }
        }
        for (var i = 0; i < node.childNodes.length; i++)
        {
            var newXmlChildNode = Html2XmlByActiveX(node.childNodes[i], xmlDoc, level + 1);
            if (newXmlChildNode != null)
                newXmlNode.appendChild(newXmlChildNode);
        }
        if (node.text != null)
            newXmlNode.text = node.text;
    }
    if (level == 0)
    {
        if (xmlDoc != null)
        {
            xmlDoc.appendChild(newXmlNode);
            return xmlDoc.xml;
        }
        else
        {
            return "";
        }
    }
    return newXmlNode;
}


// 将检测报告的HTML格式转换成XML格式并且保存在strInputID指定的输入控件中 
function SaveReportPage2InputValue(strDivMainName, strSaveInputID)
{
    var xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0");
    var xmlRootNode = xmlDoc.createElement("pages");
    xmlDoc.appendChild(xmlRootNode);
	var node = document.getElementById(strDivMainName);
	if (node != null)
        GetReportPage(node, xmlDoc, xmlRootNode);
    document.all(strSaveInputID).value = xmlDoc.xml;
}

function GetReportPage(node, xmlDoc, xmlRootNode)
{
    if (node.nodeName.toLowerCase() == "div" && node.getAttribute("ispage") == "true")
    {
        ReportPage2Xml(node, xmlDoc, xmlRootNode);
        return;
    }
    for (var i = 0; i < node.childNodes.length; i++)
        GetReportPage(node.childNodes[i], xmlDoc, xmlRootNode);
    return;
}

function ReportPage2Xml(node, xmlDoc, parentNode)
{
    var newXmlNode;

    if (node == null)
        return;

    if (node.nodeName.toLowerCase() == "colgroup")
        return;

    if (node.nodeType == 3)
    {
        parentNode.appendChild(xmlDoc.createTextNode(node.nodeValue.replace(/\u00A0/g, " ")));   // &nbsp;对应的unicode编码是00A0(160), 需要转换成普通空格0020(32)
        return;
    }

    if (node.attributes.getNamedItem("ts_remove") == null)
    {
        newXmlNode = xmlDoc.createElement(node.nodeName.toLowerCase());
        for (var j = 0; j < node.attributes.length; j++)
        {
            if (node.attributes[j].specified || node.attributes[j].name == "value")
            {
                if (node.attributes[j].name == 'style')
                    newXmlNode.setAttribute(node.attributes[j].name, node.getAttribute(node.attributes[j].name).cssText.toLowerCase());
                else
                    newXmlNode.setAttribute(node.attributes[j].name.toLowerCase(), node.attributes[j].value);//.toLowerCase() 属性值不能全部转为小写
            }
        }
        if (node.nodeName.toLowerCase() == "table")
        {
            // newXmlNode.setAttribute("ts_clientheight", 0);	
            newXmlNode.setAttribute("ts_clientwidth", node.offsetWidth);
        }
        else if (node.nodeName.toLowerCase() == "td")
        {
            if (node.attributes.getNamedItem("minheight") != null)
                newXmlNode.setAttribute("ts_clientheight", node.attributes.getNamedItem("minheight").value);
            else if (node.childNodes.length > 0)
            {
                if (node.childNodes[0].nodeName.toLowerCase() == "img")
                    newXmlNode.setAttribute("ts_clientheight", node.offsetHeight);
            }
            newXmlNode.setAttribute("ts_clientwidth", node.offsetWidth);
        }
        else if (node.nodeName.toLowerCase() == "img")
        {
            newXmlNode.setAttribute("ts_clientheight", node.offsetHeight);	
            newXmlNode.setAttribute("ts_clientwidth", node.offsetWidth);
        }
        parentNode.appendChild(newXmlNode);
    }
    else
    {
        newXmlNode = parentNode;
    }
    if (node.nodeName.toLowerCase() != "div" || node.attributes.getNamedItem("ts_usercontrol") == null)
    {
        // 特殊控件的内容是不需要的 wh 2008.12.8
        for (var i = 0; i < node.childNodes.length; i++)
            ReportPage2Xml(node.childNodes[i], xmlDoc, newXmlNode);
    }
    return;
}

function XmlData(nodeRoot, sKey)
{
    var listValue = nodeRoot.getElementsByTagName(sKey);
    if (listValue.length > 0)
        return listValue[0].firstChild.nodeValue.replace(/\\>/g, ">").replace(/\\\\/g, "\\");
    return null;
}

function ShowWait()
{
    if (giPostEvent > 0)
    {
        if (document.all.divShowWait == null)
        {
            var oDiv = document.createElement("div");
            oDiv.id = "divShowWait";
            oDiv.style.position = "absolute";
            oDiv.style.zIndex = "999";
            oDiv.style.display = "none";
            oDiv.style.left = (GetWindowWidth() - 293) / 2;
            oDiv.style.top = (GetWindowHeight() - 70) / 2;
            var oImg = document.createElement("img");
            oImg.src = GetAbsoluteUrl("/Outside/Images/Wait.gif");
            oImg.width = 293;
            oImg.height = 70;
            oDiv.appendChild(oImg);
            document.forms[0].appendChild(oDiv);
        }
        if (document.all.divShowWait.style.display == "none")
            document.all.divShowWait.style.display = "";
        window.setTimeout(ShowWait, 100);
    }
    else
    {
        if (document.all.divShowWait != null)
            document.all.divShowWait.style.display = 'none';
    }
}

var giPostEvent = 0;
var gArrUCName = new Array();
var gArrFatherID = new Array();
var gArrEvent = new Array();
var gArrData = new Array();
var gArrCmdBefore = new Array();
var gArrCmdAfter = new Array();
var gbJumpQueue = false;    // 是否插入到PostEvent队列的前面
var gArrPostInput = new Array();
var giPostTimer = null;
var gPostUrl=null;

function StartPostEvent()
{
    giPostTimer = null;
    if (giPostEvent > 0 || gbInitValue == true)
    {
        giPostTimer = window.setTimeout(StartPostEvent, 10);
        return;
    }
    giPostEvent++;
    if (giPostEvent > 1)
    {
        giPostEvent--;
        giPostTimer = window.setTimeout(StartPostEvent, 10);
        return;
    }
    if (giPostEvent != 1)
    {
        alert("严重错误: 不能执行PostEvent!");
        giPostEvent = 0;
        giPostTimer = window.setTimeout(StartPostEvent, 10);
        return;
    }
    PostEventFun(gArrUCName.shift(), gArrFatherID.shift(), gArrEvent.shift(), gArrData.shift(), gArrCmdBefore.shift(), gArrCmdAfter.shift(), gArrPostInput.shift());
}

function PostEvent(sUCName, sFatherID, sEvent, sData, cmdBefore, cmdAfter, sPostInput,sUrl)
{
    gPostUrl=typeof(sUrl)=="undefined" ?  GetAbsoluteUrl("/Outside/Comm.aspx") : sUrl;
    if (gbJumpQueue)
    {
        gArrUCName.unshift(sUCName);
        gArrFatherID.unshift(sFatherID);
        gArrEvent.unshift(sEvent);
        gArrData.unshift(sData);
        gArrCmdBefore.unshift(cmdBefore);
        gArrCmdAfter.unshift(cmdAfter);
        
        if (typeof sPostInput != 'undefined')
            gArrPostInput.unshift(sPostInput);
        else
            gArrPostInput.unshift("!");
    }
    else
    {
        gArrUCName.push(sUCName);
        gArrFatherID.push(sFatherID);
        gArrEvent.push(sEvent);
        gArrData.push(sData);
        gArrCmdBefore.push(cmdBefore);
        gArrCmdAfter.push(cmdAfter);
        if (typeof sPostInput != 'undefined')
            gArrPostInput.push(sPostInput);
        else
            gArrPostInput.push("!");
    }
//    if (typeof giPostTimer != 'undefined')
//        window.clearTimeout(giPostTimer);
    giPostTimer = window.setTimeout(StartPostEvent, 0);
}

function PostEventFun(sUCName, sFatherID, sEvent, sData, cmdBefore, cmdAfter, sPostInput)
{
    if (sData == null)
        sData = "";
    if (cmdBefore == null)
        cmdBefore = "";
    if (cmdAfter == null)
        cmdAfter = "";

	var sUrl = gPostUrl + (document.location.search == "" ? "?UCName=" : document.location.search + "&UCName=") + sUCName + "&FatherID=" + sFatherID + "&Event=" + sEvent + "&t=" + new Date().getTime();

    var i = 0;
    var arr = new Array;
    var arrIndex = 0;
    var bPostAll = false;
    var arrPostInput = new Array();
    arrPostInput = sPostInput.split("&"); 
    
    if((arrPostInput[0] == "!"))
        bPostAll = true;        

    if(bPostAll)
    {
        for ( ; i < document.forms.length; i++)
        {
            var listInput = document.forms[i].getElementsByTagName("input");
            if (listInput != null)
            {
                //var j = 0;
                var iInputLength = listInput.length;
                for (j = 0 ; j < iInputLength; j++)
                {
                    var objInput = listInput[j];
                    var strInputID = objInput.id;
                    if (strInputID != "__VIEWSTATE") // 如果发送__VIEWSTATE会引起错误：500 Internal Server Error 服务器遇到了意料不到的情况，不能完成客户的请求
                    {
                        if (arrIndex != 0)
                            arr[arrIndex++] = "&";
                            
                        if (objInput.type == "checkbox")
                            arr[arrIndex++] = strInputID + "=" + encodeURIComponent(objInput.checked);
                        else
                            arr[arrIndex++] = strInputID + "=" + encodeURIComponent(objInput.value);
                    }
                }
                
            }
            
            var listSelect =document.forms[i].getElementsByTagName("select");
            if(listSelect !=null)
            {
                var j=0;
                for(;j<listSelect.length;j++)
                {
                   if(arrIndex !=0)
                      arr[arrIndex++] = "&";
                      arr[arrIndex++] = listSelect[j].id + "=" + encodeURIComponent(listSelect[j].value);
                }
            }
           
            var listTextarea = document.forms[i].getElementsByTagName("textarea");
            if (listTextarea != null)
            {
                var j = 0;
                for ( ; j < listTextarea.length; j++)
                {
                    if (arrIndex != 0)
                        arr[arrIndex++] = "&";
                    if(listTextarea[j].type&&listTextarea[j].type=="ckeditor"){
                       arr[arrIndex++] = listTextarea[j].id + "=" + encodeURIComponent(CKEDITOR.instances[listTextarea[j].id].getData());
                    }else{
                       arr[arrIndex++] = listTextarea[j].id + "=" + encodeURIComponent(listTextarea[j].value);
                    }
                }
            }
        }
    }
    else
    {
        var iInputLength = arrPostInput.length;
        
        for (j = 0 ; j < iInputLength; j++)
        {
            var objInput = document.getElementById(arrPostInput[j]);
            
            if(objInput != null)
            {
                var strInputID = objInput.id;
                if (strInputID != "__VIEWSTATE") // 如果发送__VIEWSTATE会引起错误：500 Internal Server Error 服务器遇到了意料不到的情况，不能完成客户的请求
                {
                    if (arrIndex != 0)
                        arr[arrIndex++] = "&";
                        
                    if (objInput.type == "checkbox")
                        arr[arrIndex++] = strInputID + "=" + encodeURIComponent(objInput.checked);
                    else
                        arr[arrIndex++] = strInputID + "=" + encodeURIComponent(objInput.value);
                }
            }
        }
    }   

    if(sData != "")
        sData += "&" + arr.join("");
     else
        sData += arr.join("");   
    
    $.ajax({
      type:"post",
      url:sUrl,
      success:function(data, textStatus){
        var i;
        if (data == null)
        {
            alert("PostEvent " + sUCName + " failed: data == null");
            delete xmlHttp;
            giPostEvent = 0;
            return;
        }
        nodeRoot = data.childNodes[0];
        if (nodeRoot == null)
        {
            alert("PostEvent " + sUCName + " failed: nodeRoot == null");
            delete xmlHttp;
            giPostEvent = 0;
            return;
        }
        if (nodeRoot.tagName != "ansyanswer")
        {
            alert("PostEvent " + sUCName + " failed: nodeRoot has wrong tag '" + nodeRoot.tagName + "'");
            delete xmlHttp;
            giPostEvent = 0;
            return;
        }
        var sExceiption = XmlData(nodeRoot, "Exception")
        if (sExceiption != null)
        {
            alert(sUCName + ".EventHandler 异常: " + sExceiption);
        }
        else
        {
            var listHtml = nodeRoot.getElementsByTagName("Html");
            for (var i = 0; i < listHtml.length; i++)
            {
                var sFatherID = listHtml[i].attributes[0].value;
                var oTag =document.getElementById(sFatherID);
                if (oTag != null)
                {
                    oTag.innerHTML = listHtml[i].firstChild.nodeValue.replace(/\\>/g, ">").replace(/\\\\/g, "\\");
                }
            }

            var listInput = nodeRoot.getElementsByTagName("Input");
            for (var i = 0; i < listInput.length; i++)
            {
                var sID = listInput[i].attributes[0].value;
                var oInput = document.getElementById(sID);
                if (oInput != null)
                {
                    if (oInput.type == "checkbox")
                    {
                        if (listInput[i].firstChild.nodeValue == "true")
                            oInput.checked = true;
                        else
                            oInput.checked = false;
                    }
                    else
                    {
                        var s = listInput[i].firstChild.nodeValue;
                        oInput.value = s.replace(/\\>/g, ">").replace(/\\\\/g, "\\");
                    }
                }
            }
                 
            var listTextArea = nodeRoot.getElementsByTagName("TextArea");
            for (var i = 0; i < listTextArea.length; i++)
            {
                var sID = listTextArea[i].attributes[0].value;
                var oTextArea = document.getElementById(sID);
                if (oTextArea != null)
                {
                    var s = listTextArea[i].firstChild.nodeValue;
                    oTextArea.value = s.replace(/\\>/g, ">").replace(/\\\\/g, "\\");
                }
            }

            var sTitle = XmlData(nodeRoot, "Title")
            if (sTitle != null)
                document.title = sTitle;

            var sPrompt = XmlData(nodeRoot, "Prompt");
            if (sPrompt != null)
                alert(sPrompt);

            var sScript = XmlData(nodeRoot, "Script");
            if (sScript != null)
                setTimeout("gbJumpQueue = true;" + sScript + "gbJumpQueue = false;", 0);
        }

        if (cmdAfter != "")
        {
            gbJumpQueue = true;
            eval(cmdAfter);
            gbJumpQueue = false;
        }
        delete xmlHttp;
        giPostEvent = 0;
        return;
      },
      beforeSend:function(){
        gbJumpQueue = true;
        eval(cmdBefore);
        gbJumpQueue = false;
      },
      error:function(){
        if (cmdAfter != "")
        {
            gbJumpQueue = true;
            eval(cmdAfter);
            gbJumpQueue = false;
        }
        delete xmlHttp;
        giPostEvent = 0;
        return;
      },
      data:sData
    });
        
	window.setTimeout(ShowWait, 1000);
}


// bChecked, true 不勾, false 勾
// bGray, true 灰色, false 正常色
// bCanClick, 是否可以点击是执行的代码
// strText, 文字
// strStyle, 样式
function SetCheckBox(oCheckbox, bChecked, bGray, bCanClick, strText, strStyleColor, strFontWeight)
{
	var strImg; 
	if (bGray) {
		if (bChecked)
			strImg = "checkbox_C_N.jpg";
		else
			strImg = "checkbox_U_N.jpg";
	} else {
		if (bChecked)
			strImg = "checkbox_C.jpg";
		else
			strImg = "checkbox_U.jpg";
	}
	eval("document.all." + oCheckbox.id + "canclick").value = (bCanClick ? "1" : "0");
	if (strStyleColor !=null)
	    oCheckbox.children(1).children(0).style.color= strStyleColor;
	if (strFontWeight != null)    
	    oCheckbox.children(1).children(0).style.fontWeight= strFontWeight;
   	if (strText != null)
	    oCheckbox.children(1).children(0).children(0).innerText = strText;
	oCheckbox.children(0).children(0).src = GetAbsoluteUrl("~/Outside/Images/" + strImg);
}

function overContextMenu(obj)
{
    obj.style.backgroundColor="highlight";
    obj.style.color="white";
    obj.style.cursor="hand";
}

function outContextMenu(obj)
{
     obj.style.backgroundColor = "#D4D0C8";
     obj.style.color="black";
}

function ShowContextMenu(objMenu, arry)
{    
    var listmenudiv=document.getElementsByName("uccontextmenudivmaininput");
    for (i=0;i<listmenudiv.length;i++)
    {
        if(listmenudiv[i].parentNode)
        {
            listmenudiv[i].parentNode.style.display="none";
        }
    }
    var arrylength=new Array();
    arrylength=arry.split(",");
    var row= objMenu.getElementsByTagName("tr");
    var maxclientWidth=4;

    if (row.length < 1)
        return ;
    if (arrylength.length < 1)
        return ;
    objMenu.style.posLeft=event.clientX - GetPositionLeft(objMenu.offsetParent);
    objMenu.style.posTop=event.clientY - GetPositionTop(objMenu.offsetParent);
    if (event.clientY + arrylength.length * 20 + 6 >= document.body.clientHeight)
        objMenu.style.posTop -= arrylength.length * 20 + 6;
    
    objMenu.style.display="";
     
    for (var i = 0;i<row.length;i++)
    {
        row[i].style.display="none";  
    }
       
    for (var i = 0 ;i<arrylength.length;i++)
    {
        row[arrylength[i]].style.display=""; 
        if (row[arrylength[i]].clientWidth>maxclientWidth)
            maxclientWidth=row[arrylength[i]].clientWidth
    } 

    if (maxclientWidth > 4)
	    maxclientWidth += 4;

    if (event.clientX + maxclientWidth >= document.body.clientWidth)
        objMenu.style.posLeft= event.clientX - maxclientWidth;
}

function TreeSwapPic(obj)
{
     if (obj.getAttribute("expand")=="false")
       { 
            if (obj.getAttribute("childnode")==0) 
                 obj.src=GetAbsoluteUrl("~/Outside/Images/spTreeSub2.gif");
            else if (obj.getAttribute("childnode")==1) 
                obj.src=GetAbsoluteUrl("~/Outside/Images/spTreeSub1.gif");
            else
                obj.src=GetAbsoluteUrl("~/Outside/Images/spTreeRootSub.gif");
           obj.setAttribute("expand","true");
         }
         else
         { 
            if (obj.getAttribute("childnode")==0)
                obj.src=GetAbsoluteUrl("~/Outside/Images/spTreeAdd2.gif");
            else if (obj.getAttribute("childnode")==1)
                obj.src=GetAbsoluteUrl("~/Outside/Images/spTreeAdd1.gif");
            else
                obj.src=GetAbsoluteUrl("~/Outside/Images/spTreeRootAdd.gif");
           obj.setAttribute("expand","false");
         }
}

function HiddenTreeChildNode(objimg,objtr,ichildnode)
{
    var bexpand = false;
    if (objimg.getAttribute("expand")=="true")
          bexpand=true;           

    if (ichildnode > 0) 
     {
         for (i =0 ;i<ichildnode;i++)
          {
                objtr=objtr.nextSibling;
                var icounter=0;
                
                icounter=parseInt(objtr.getAttribute("counter"));
                if (bexpand) 
                    objtr.setAttribute("counter",icounter - 1);
                else
                    objtr.setAttribute("counter",icounter + 1);
          
                if (objtr.getAttribute("counter")==0)
                    objtr.style.display="";
                else
                     objtr.style.display="none";
          }
     }
}

function SelectTreeNode(obj,objhiddenflag)
{
    if (objhiddenflag.value == "")
     {
         objhiddenflag.value =obj.id;
         obj.style.backgroundColor="highlight";
         obj.style.color="white";
     }
     else if(objhiddenflag.value != obj.id)
     {
         var objold=document.getElementById(objhiddenflag.value);
         objold.style.backgroundColor = "#FFFFFF";
         objold.style.color="black";
         objhiddenflag.value =obj.id;
         obj.style.backgroundColor="highlight";
         obj.style.color="white";
     }
}
//根据传入的iMaxLine判断Textarea是否需要动态增加行
function ChangeLine(objArea,iMaxLine)
{
    if (iMaxLine==null)
        iMaxLine=26;
    if (window.event.keyCode == 13 && objArea.rows < iMaxLine) 
        objArea.rows +=1;
};

//将传入的input值自动加上千位分隔符和人民币符号
function FormatToMoney(objInput)
{
    var value_input = objInput.value.replace(/,/g,'').replace(/￥/g,'');
    
    if (isFinite(value_input))
        objInput.value = '￥' + AddCommaFormat(value_input);
    else
        alert("请输入规范的数值！")     
};

//加千位分隔符
function AddCommaFormat(num){ 
//sScript &= "    alert(num);"
    num = num+'';
	var re=/(-?\d+)(\d{3})/;
	while(re.test(num)){
        num = num.replace(re, '$1,$2')
    }
    dot = num.indexOf('.'); //有没小数点
    if(dot>0){
        strnum = num.split('.');
        behinddot = strnum[1];
        if (strnum[1].length>1){
            try
                {
                    tema = strnum[1].replace(/,/g,'').substr(2,1); //取小数点后的第三位
                    if(parseInt(tema) > 4){
                        behinddot=strnum[1].replace(/,/g,'').substr(0,1) + (parseInt(strnum[1].replace(/,/g,'').substr(1,1)) + 1).toString();}
                     else{
                        behinddot=strnum[1].replace(/,/g,'').substr(0,2);}
                 }
            catch(e)
                {
                    behinddot = strnum[1].replace(/,/g,'').substr(0,2);
                }
        }
        else
            behinddot = strnum[1] + '0';
        num = strnum[0]+'.'+ behinddot;
    }
    else
         num = num + '.00';// '小数点没有的话后面加.00
         
if(num=='.00')
  {num='0.00'};         
return num;
};

function ImgAutoSize(ImgD,MaxWidth,MaxHeight)
{
    if (typeof ImgD == 'undefined')
        return;
    if (ImgD == null)
        return;
	//alert(': ' + MaxWidth + ',' + MaxHeight);
    var image=new Image();
    image.src=ImgD.src;
	// alert(': ' + ImgD.src + ',' + image.width);
    if (MaxWidth <= 0)
        MaxWidth = image.width;
    if (MaxHeight <= 0)
        MaxHeight = image.height;
    if(image.width>0 && image.height>0)
    {
        if(image.width/image.height>= MaxWidth/MaxHeight)
        {
            if(image.width>MaxWidth)
            { 
                ImgD.width=MaxWidth;
                ImgD.height=(image.height*MaxWidth)/image.width;
            }
            else
            {
                ImgD.width=image.width; 
                ImgD.height=image.height;
            }
            ImgD.alt="原始尺寸:宽" + image.width+",高"+image.height;
        }
        else
        {
            if(image.height>MaxHeight)
            { 
                ImgD.height=MaxHeight;
                ImgD.width=(image.width*MaxHeight)/image.height;     
            }
            else
            {
                ImgD.width=image.width; 
                ImgD.height=image.height;
            }
            ImgD.alt="原始尺寸:宽" + image.width+",高"+image.height;
        }
    }
    image = null;
}; 

//Start TextBox 专用
var gInput;
var gWorkRange;
function TextHandleEvent(oEvent,obj)
{
   gInput=obj
  // alert(oEvent.keyCode);
   if (oEvent.ctrlKey == true && oEvent.keyCode == 17 && oEvent.shiftKey == false )
     {
     
       ShowInputDiv(obj);
       return 
     }
     
 if (oEvent.ctrlKey == true && oEvent.keyCode == 7 && oEvent.shiftKey == false )
  {
       gWorkRange = getInputPos(obj);
       ShowCommonCodeDiv();
       return 
  }
         
 if (oEvent.ctrlKey == true && oEvent.keyCode == 4 && oEvent.shiftKey == false ) //快捷键 ctrl+d 英文字典
  {
       ShowDictionaryDiv();
       return 
  }
  
  if (oEvent.ctrlKey==true && oEvent.keyCode==21 && oEvent.shiftKey==false )
   {
    
     if (obj.ctrlU==0)
         {
              obj.value += '<sub>';
              obj.ctrlU=1;
              return;
         }
     
     if (obj.ctrlU==1)
         {
              obj.value += '</sub>';
              obj.ctrlU=0;
              return ;
         }
     
   }
    if (oEvent.keyCode==21 && oEvent.ctrlKey==true && oEvent.shiftKey==true )
   {
      if (obj.ctrlU==0)
         {
              obj.value += '<sup>';
              obj.ctrlU=1;
              return;
         }
     
     if (obj.ctrlU==1)
         {
              obj.value += '</sup>';
              obj.ctrlU=0;
              return ;
         }
   }
};

function ShowInputDiv(objInput)
{    
    var sHtml = "";
    
    sHtml = sHtml + "<table  id='tableInput' border='0' cellpadding='0' cellspacing='5' width='500'>";
    sHtml = sHtml + "    <tr>";
    sHtml = sHtml + "        <td width='100%' colspan='2'>";
    sHtml = sHtml + "           <textarea id='textAreaInput' rows='5' style='color: #396043; width: 100%; border: 1px solid #DCDED3; font-family: 宋体; font-size: 12px;' cols='1' onfocus='InputFocus();'>" + objInput.value + "</textarea></td>";
    sHtml = sHtml + "    </tr>";
    sHtml = sHtml + "    <tr>";
    sHtml = sHtml + "        <td  align ='right' style='width: 90%;'>";
    sHtml = sHtml + "           <input type='button' value='确 定' style='height: 20px; width: 60px; border: 1px solid lightgray;' onclick='gInput.value = document.all.textAreaInput.innerText; CloseDiv(\"divInput\"); '/></td>";
    sHtml = sHtml + "        <td  align ='right' style='width: 65px;'>";
    sHtml = sHtml + "           <input type='button' value='取 消' style='height: 20px; width: 60px; border: 1px solid lightgray;' onclick='CloseDiv(\"divInput\");'/></td>";
    sHtml = sHtml + "    </tr>";
    sHtml = sHtml + "</table>";
    
    OpenDiv("divInput", sHtml, "");
    arryESC.unshift("CloseDiv('divInput');");
    AdjustTopPosition("divInput");  
    
    document.getElementById('textAreaInput').focus();
}
function InputFocus() 
{
    var e = event.srcElement;   
    var r = e.createTextRange();  
    r.moveStart('character', e.value.length);   
    r.collapse(true);   
    r.select(); 
}

function getInputPos(){ 
    return document.selection.createRange();
} 


function SetInputValue(str){
    gWorkRange.select();
    gWorkRange.text = str.replace("&lt;","<").replace("&gt;",">").replace("　"," ");
}

//End TextBox 专用

//Start DropDownList专用
var bDivOnfocus;
var bImgClick = false;

function SetDiv(sFatherID)
{
    var sTItem = sFatherID + '_tItem';
    var sDiv = sFatherID + '_div';
    var sInput = sFatherID + '_input';
    var iLine = document.getElementById(sTItem).children(0).children.length;
    if (iLine == 0)
        return;

    document.getElementById(sDiv).style.top='auto';
	if (iLine > 10) 
    {
        document.getElementById(sTItem).style.width = document.getElementById(sInput).offsetWidth - 29;
        document.getElementById(sDiv).style.width = document.getElementById(sInput).offsetWidth - 12;
        document.getElementById(sDiv).style.overflowY = 'scroll';
        document.getElementById(sDiv).style.height = 20 * 10;
    } 
    else
    {
        document.getElementById(sTItem).style.width = document.getElementById(sInput).offsetWidth - 12;
        document.getElementById(sDiv).style.overflowY = 'visible';
        document.getElementById(sDiv).style.width = document.getElementById(sInput).offsetWidth - 12;
        document.getElementById(sDiv).style.height = 20 * iLine;
    }
			//以下代码有问题 暂时注释掉
//    var divoffsetTop= document.getElementById(sDiv).offsetTop;
//    var divoffsetHeight = document.getElementById(sDiv).offsetHeight;
//    var inputoffsetHeight = document.getElementById(sInput).offsetHeight;
//    if (divoffsetTop + divoffsetHeight + 6 > document.body.clientHeight )
//    {
//        if (divoffsetTop-divoffsetHeight-inputoffsetHeight>0)
//            document.getElementById(sDiv).style.top=divoffsetTop-divoffsetHeight-inputoffsetHeight;
//    }
}

function ShowDiv(iAdd, sFatherID)
{
    alert("过期的函数调用ShowDiv");
    return;   
}

function ShowDivNew(sFatherID,sShowPosition)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    SetDiv(sFatherID);
    var sTItem = sFatherID + '_tItem';
    var iLine = document.getElementById(sTItem).children(0).children.length;
    if (iLine > 0)
    {
        if(sShowPosition == 'up')
            oDiv.style.marginTop=-parseInt(oDiv.style.height)-33;    
        oDiv.style.display='';
    }
    else
        oDiv.style.display='none';
}

function HiddenDivNew(sFatherID)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    oDiv.style.display='none';
    oDiv.style.top='auto';
}

function ShowDivNew1(sFatherID)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    var oDropDownListData = document.getElementById(sFatherID +"_DropDownListData").value;
    var oDropDownListColor = document.getElementById(sFatherID +"_DropDownListColor").value;
    var obj = eval('(' + oDropDownListData + ')');
    var strHtml= "<table id='" + sFatherID + "_tItem' style='width: 100%;' class='tableNull'>";
    for (var i = 0;i<obj.length;i++)
    {
        strHtml +="<tr>";
        strHtml +="<td class='DivListTD' textonselected='" + obj[i][2] + "' style='padding-left:0px;border: 0px none #FFFFFF;width:100%;color:" + oDropDownListColor + ";' onmouseenter='TableOnmouseEnter(this);' onmouseleave='TableOnmouseLeave(this, &quot;" + oDropDownListColor + "&quot;);' onmousedown='TableOnmouseDown(this,&quot;" + sFatherID + "&quot;,&quot;" + obj[i][0] + "&quot;); " + sFatherID + "_funOnSelectChanged();'>" + obj[i][1] + "</td>";
        strHtml +="</tr>";
    }
    strHtml +="<table>";
    oDiv.innerHTML=strHtml;
    
    SetDiv(sFatherID);
    var sTItem = sFatherID + '_tItem';
    var iLine = document.getElementById(sTItem).children(0).children.length;
    if (iLine > 0)
        oDiv.style.display='';
    else
        oDiv.style.display='none';
}

function HiddenDivNew1(sFatherID)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    oDiv.innerHTML='';
    oDiv.style.display='none';
    oDiv.style.top='auto';
}

function SwitchDivNew(sFatherID,sShowPosition)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    if (oDiv.style.display == 'none')
        ShowDivNew(sFatherID,sShowPosition);
    else
        HiddenDivNew(sFatherID);
}

function SwitchDivNew1(sFatherID)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    if (oDiv.style.display == 'none')
        ShowDivNew1(sFatherID);
    else
        HiddenDivNew1(sFatherID);
}

function IsDropdownListClick(sFatherID)
{
    if (window.event.srcElement == document.getElementById(sFatherID + '_input'))
        return true;
    if (window.event.srcElement == document.getElementById(sFatherID + '_img'))
        return true;
    var oSrc = window.event.srcElement;
    var oDiv = document.getElementById(sFatherID + '_div');
    while (oSrc)
    {
        if (oSrc == oDiv)
            return true;
        oSrc = oSrc.parentElement;
    }
    return false;
}

function TableOnmouseEnter(obj)
{
    obj.style.backgroundColor='#32563E'; 
    obj.style.color='#FFFFFF';
}

function TableOnmouseLeave(obj, strColor)
{
    obj.style.backgroundColor = '#FFFFFF'; 
    obj.style.color = strColor;
}

function TableOnmouseDown(thisObj, sFatherID, sValue)
{
    var sInputID = sFatherID + '_input';
    var sValueID = sFatherID + '_Value';
    
    document.getElementById(sInputID).value = thisObj.textonselected;
    document.getElementById(sValueID).value = sValue; 
    HiddenDivNew(sFatherID);
}

//End DropDownList专用

//Start UCPersonList专用
function SetDivPersonList(sFatherID)
{
    var sTItem = sFatherID + '_tItem';
    var sDiv = sFatherID + '_div';
    var sInput = sFatherID + '_input';
    var iLine = document.getElementById(sTItem).children(0).children.length;
    if (iLine == 0)
        return;

    document.getElementById(sDiv).style.top='auto';
	if (iLine > 10) 
    {
        document.getElementById(sTItem).style.width = document.getElementById(sInput).offsetWidth - 29;
        document.getElementById(sDiv).style.width = document.getElementById(sInput).offsetWidth - 12;
        document.getElementById(sDiv).style.overflowY = 'scroll';
        document.getElementById(sDiv).style.height = 20 * 10;
    } 
    else
    {
        document.getElementById(sTItem).style.width = document.getElementById(sInput).offsetWidth - 12;
        document.getElementById(sDiv).style.overflowY = 'visible';
        document.getElementById(sDiv).style.width = document.getElementById(sInput).offsetWidth - 12;
        document.getElementById(sDiv).style.height = 20 * iLine;
    }
}

function ShowDivPersonList(sFatherID,sSelectType,iRowHeight,iColums,bOneDataSource)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    var sInput = sFatherID + '_input';
    var oInput = document.getElementById(sInput);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    
    if(bOneDataSource.toLowerCase() =='true')
        var oDropDownListData = document.getElementById("DropDownListDataSource").value;
    else
        var oDropDownListData = document.getElementById(sFatherID +"_DropDownListData").value; 

    var listDep = eval('(' + oDropDownListData + ')');
    var strHtml= "<table id='" + sFatherID + "_tItem' style='width: 100%;' class='tableNull'>";
    var iTempHeight=0;
    for (var i = 0;i<listDep.length;i++)
    {
        var sDepID = listDep[i][0];
        var sDepName = listDep[i][1];
        var listPerson = listDep[i][2];
        
        if(listPerson.length > 0)
        {
            var iRow = parseInt(listPerson.length / iColums);
            if(listPerson.Count % iColums != 0)iRow += 1;
  
            if (i==0)
                iTempHeight = 0;
            else
                iTempHeight = 7;
                
            if(sSelectType == '人员单选')
            {
                var strImgGup = '';
            }
            else
            {
                var strImgGup = "<img style='cursor: hand; padding-left:10px;padding-right:10px;' height='12' id='" + sFatherID + "depimg_" + sDepID + "' seltype='部门' src='" + GetImageUrl(oInput.value, sDepName) + "' depid='" + sDepID + "' onclick='TableOnmouseDownPersonList(document.all." + sFatherID + "depimg_" + sDepID + ",&quot;" + sFatherID + "&quot;,&quot;" + sDepName + "&quot;,&quot;" + sSelectType + "&quot;);' />";
            }
            
            strHtml +="<tr>";
            strHtml +="<td align='left' class='DivListTD'  colspan='" + listPerson.length + "' style='height:" + iRowHeight + "px;padding-top:" + iTempHeight + "px;'>" + strImgGup + sDepName +  "</td>";
            strHtml +="</tr>";
            
            for (var x = 0;x<iRow;x++)
            {
                strHtml += "<tr>";
                var iStarItem = x * iColums;
                for (var j = 0;j<iColums;j++)
                {
                    if(iStarItem + j < listPerson.length)
                    {
                        var strImg = "<img style='cursor: hand; padding-left:10px;padding-right:10px;' height='12' id='" + sFatherID + "img_" + listPerson[iStarItem + j][0] + "' seltype='人员' pname='" + listPerson[iStarItem + j][1] +  "' src='" + GetImageUrl(oInput.value, listPerson[iStarItem + j][1]) + "' name='depid_" + sDepID + "' onclick='TableOnmouseDownPersonList(document.all." + sFatherID + "img_" + listPerson[iStarItem + j][0] + ",&quot;" + sFatherID + "&quot;,&quot;" + listPerson[iStarItem + j][1] + "&quot;,&quot;" + sSelectType + "&quot;);' />";
                        strHtml += "<td align='left' class='DivListTD' style='height:" + iRowHeight + "px;'>";
                        strHtml += strImg;
                        strHtml += "<span style='cursor: hand;' id='" + sFatherID + "span_" + listPerson[iStarItem + j][0] + "' pname='" + listPerson[iStarItem + j][1] +  "' seltype='人员' onclick='TableOnmouseDownPersonList(document.all." + sFatherID + "img_" + listPerson[iStarItem + j][0] + ",&quot;" + sFatherID + "&quot;,&quot;" + listPerson[iStarItem + j][1] + "&quot;,&quot;" + sSelectType + "&quot;);'>" + listPerson[iStarItem + j][1] + "</span>";
                    }
                    else
                    {
                        strHtml += "<td>";
                    }
                    strHtml += "</td>";
                }
                strHtml += "</tr>";
            }
        }
    }
    strHtml +="<table>";
    oDiv.innerHTML=strHtml;
    
    SetDivPersonList(sFatherID);
    var sTItem = sFatherID + '_tItem';
    var iLine = document.getElementById(sTItem).children(0).children.length;
    if (iLine > 0)
        oDiv.style.display='';
    else
        oDiv.style.display='none';
}

function GetImageUrl(sValue,sUserName)
{
    sValue += sValue + ",";
    if(sValue.indexOf(sUserName + ",") > -1)
    {
        return "../outside/images/checkbox_C.jpg";
    }
    return "../outside/images/checkbox_U.jpg";
}

function HiddenDivPersonList(sFatherID)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    oDiv.innerHTML='';
    oDiv.style.display='none';
    oDiv.style.top='auto';
}

function SwitchDivPersonList(sFatherID,sSelectType,iRowHeight,iColums,bOneDataSource)
{
    var sDiv = sFatherID + '_div';
    var oDiv = document.getElementById(sDiv);
    if (oDiv == null)
    {
        document.detachEvent("onclick", eval(sFatherID + "_funOnDocumentClick"));
        return;
    }
    if (oDiv.style.display == 'none')
        ShowDivPersonList(sFatherID,sSelectType,iRowHeight,iColums,bOneDataSource);
    else
        HiddenDivPersonList(sFatherID);
}

function IsPersonListClick(sFatherID)
{
    if (window.event.srcElement == document.getElementById(sFatherID + '_input'))
        return true;
    var oSrc = window.event.srcElement;
    var oDiv = document.getElementById(sFatherID + '_div');
    while (oSrc)
    {
        if (oSrc == oDiv)
            return true;
        oSrc = oSrc.parentElement;
    }
    return false;
}

function TableOnmouseDownPersonList(thisObj, sFatherID, sValue,sSelectType)
{
    var sInputID = sFatherID + '_input';
    var sSelType = sFatherID + '_seltype';
    
    if(sSelectType == '人员单选' || sSelectType == '人员或部门单选')
    {
        ClearChecked(sFatherID,thisObj.id);
        if (thisObj.nameProp=='checkbox_U.jpg')
        {
            thisObj.src='../outside/images/checkbox_C.jpg';
            document.getElementById(sInputID).value = sValue;
            document.getElementById(sSelType).value = thisObj.seltype;
        }
        else
        {
            thisObj.src='../outside/images/checkbox_U.jpg';
            document.getElementById(sInputID).value = '';
            document.getElementById(sSelType).value = '';
        }
    }
    else if(sSelectType == '人员多选')
    {
        if (thisObj.nameProp=='checkbox_U.jpg')
        {
            thisObj.src='../outside/images/checkbox_C.jpg';
            document.getElementById(sSelType).value = '人员';
            if(thisObj.seltype == '部门')
            {
                var listperson = document.getElementsByName('depid_' + thisObj.depid);
                for(var i=0;i<listperson.length;i++) 
                {
                    listperson[i].src='../outside/images/checkbox_C.jpg';
                    if(document.getElementById(sInputID).value.indexOf(listperson[i].pname)<0)
                    {
                        if(document.getElementById(sInputID).value !='')
                            document.getElementById(sInputID).value = document.getElementById(sInputID).value + ',' + listperson[i].pname;
                        else
                            document.getElementById(sInputID).value = listperson[i].pname;
                    }
                }
            }
            else
            {
                if(document.getElementById(sInputID).value.indexOf(sValue)<0)
                {
                    if(document.getElementById(sInputID).value !='')
                        document.getElementById(sInputID).value = document.getElementById(sInputID).value + ',' + sValue;
                    else
                        document.getElementById(sInputID).value = sValue;
                }
            }
        }
        else
        {
            thisObj.src='../outside/images/checkbox_U.jpg';
            document.getElementById(sSelType).value = '人员';
             if(thisObj.seltype == '部门')
            {
                var listperson = document.getElementsByName('depid_' + thisObj.depid);
                for(var i=0;i<listperson.length;i++) 
                {
                    listperson[i].src='../outside/images/checkbox_U.jpg';
                    document.getElementById(sInputID).value = document.getElementById(sInputID).value.replace(',' + listperson[i].pname,'');
                    document.getElementById(sInputID).value = document.getElementById(sInputID).value.replace(listperson[i].pname + ',','');
                    document.getElementById(sInputID).value = document.getElementById(sInputID).value.replace(listperson[i].pname,'');
                }
            }
            else
            {
                document.getElementById(sInputID).value = document.getElementById(sInputID).value.replace(',' + sValue,'');
                document.getElementById(sInputID).value = document.getElementById(sInputID).value.replace(sValue + ',','');
                document.getElementById(sInputID).value = document.getElementById(sInputID).value.replace(sValue,'');
            }
        }
    }
}

function ClearChecked(sFatherID,id)
{
    var sItems = sFatherID + '_tItem';
    var oItems = document.getElementById(sItems);
    var rows=oItems.rows;
    for(var i=0;i<rows.length;i++) 
    {
        var cells=rows[i].cells;
        for(var j=0;j<cells.length;j++)
        {
            var objcell = cells[j];
            for(var x=0;x<objcell.childNodes.length;x++)
            {
                if (objcell.childNodes[x].id !=undefined)
                {
                    if (objcell.childNodes[x].id.indexOf(sFatherID + 'img_')>=0 && objcell.childNodes[x].id !=id)
                    {
                        if (objcell.childNodes[x].nameProp=='checkbox_C.jpg')
                        {
                            objcell.childNodes[x].src='../outside/images/checkbox_U.jpg';
                        }
                    }
                    else if (objcell.childNodes[x].id.indexOf(sFatherID + 'depimg_')>=0 && objcell.childNodes[x].id !=id)
                    {
                        if (objcell.childNodes[x].nameProp=='checkbox_C.jpg')
                        {
                            objcell.childNodes[x].src='../outside/images/checkbox_U.jpg';
                        }
                    }
                }
            }
        }
    }
}

//End UCPersonList专用

//Start CheckBox专用
function SingleSelect(obj, groupName)
{
	var strSplit = '';
	strSplit = document.getElementById('split_' + groupName).value;
	var listCheckBox = document.getElementsByName(groupName);				
	var i = 0;
	for	(; i < listCheckBox.length; i++)
	{			
		if (obj.id !=   listCheckBox[i].id )
		{
			listCheckBox[i].src = "../outside/images/checkbox_U.jpg";
			listCheckBox[i].selected = '0';
		}
	}		
	if( obj.selected == '1')
	{					 			
		obj.src = "../outside/images/checkbox_U.jpg";
		obj.selected = '0';
		document.getElementById('text_' + groupName).value = '';
		document.getElementById('value_' + groupName).value = '';
	}
	else
	{
		obj.src = "../outside/images/checkbox_C.jpg";
		obj.selected = '1';
		document.getElementById('text_' + groupName).value = strSplit + obj.text;
		document.getElementById('value_' + groupName).value = strSplit + obj.value;
	}	
}

function SetSingleSelected(groupName)
{
	var strSplit = document.getElementById('split_' + groupName).value;
	var listCheckBox = document.getElementsByName(groupName);				
	var i = 0;
	var bHaveSelected = false;
	
	for	(; i < listCheckBox.length; i++)
	{			
		if(obj.selected == '1')
		{	
			if(bHaveSelected)
			{
				obj.src = "../outside/images/checkbox_U.jpg";
				obj.selected = '0';
			}
			else
			{
				document.getElementById('text_' + groupName).value = strSplit + obj.text;
				document.getElementById('value_' + groupName).value = strSplit + obj.value;
				bHaveSelected = true;
			} 			
		}
	}
	
	if(!bHaveSelected)
	{
		document.getElementById('text_' + groupName).value = '';
		document.getElementById('value_' + groupName).value = '';
	}
}

function SetMultiSelected(groupName)
{
	var listCheckBox = document.getElementsByName(groupName);
	var txtSelected = '';
	var valueSelected = '';
	var strSplit = document.getElementById('split_' + groupName).value;
	var bHaveSelected = false;
	
	for	(var i = 0; i < listCheckBox.length; i++)
	{			
		if (listCheckBox[i].selected == '1')
		{
			txtSelected = txtSelected + strSplit + listCheckBox[i].text;
			valueSelected = valueSelected + strSplit + listCheckBox[i].value;
			bHaveSelected = true;
		}
	}	
	
	document.getElementById('text_' + groupName).value = txtSelected;	
	document.getElementById('value_' + groupName).value = valueSelected;
	
	if(!bHaveSelected)
	{
		document.getElementById('text_' + groupName).value = '';
		document.getElementById('value_' + groupName).value = '';
	}
}

function MultiSelect(obj, groupName)
{
//	var txtSelected = document.getElementById('text_' + groupName).value;
//	var valueSelected = document.getElementById('value_' + groupName).value;
//	var strSplit = document.getElementById('split_' + groupName).value;
//	
//	for	(var i = 0; i < listCheckBox.length; i++)
//	{			
//		if (listCheckBox[i].selected == '1')
//		{
//			txtSelected = txtSelected + strSplit + listCheckBox[i].text;
//			valueSelected = valueSelected + strSplit + listCheckBox[i].value;
//		}
//	}	
//	
//	document.getElementById('text_' + groupName).value = txtSelected;	
//	document.getElementById('value_' + groupName).value = valueSelected;
	
	if( obj.selected == '1')
	{					 			
		obj.src = "../outside/images/checkbox_U.jpg";
		obj.selected = '0';
	}
	else
	{
		obj.src = "../outside/images/checkbox_C.jpg";
		obj.selected = '1';
	}
	
	var listCheckBox = document.getElementsByName(groupName);
	var txtSelected = '';
	var valueSelected = '';
	var strSplit = document.getElementById('split_' + groupName).value;
	
	for	(var i = 0; i < listCheckBox.length; i++)
	{			
		if (listCheckBox[i].selected == '1')
		{
			txtSelected = txtSelected + strSplit + listCheckBox[i].text;
			valueSelected = valueSelected + strSplit + listCheckBox[i].value;
		}
	}	
	
	document.getElementById('text_' + groupName).value = txtSelected;	
	document.getElementById('value_' + groupName).value = valueSelected;
}
		
function MultiCheckBox(strSelected, groupName)
{
	if (strSelected.length == 0)
		return ;
		
	var strSplit = strSelected.substring(0, 1);
	var strReplace = "\\\\" + strSplit;
	var reg1 = new RegExp(strReplace,"gm");
	var reg2 = new RegExp("\\\\&","gm");
	var arrSelected = strSelected.replace(reg1, "\\&").split(strSplit);

	var listCheckBox = document.getElementsByName(groupName);
	var txtSelected = '';
	var valueSelected = '';	
			  
	for	(var i = 0; i < listCheckBox.length; i++)
	{
		var bChecked = false;
		
		for (var j = 0; j < arrSelected.length ; j++)
		{
			if (listCheckBox[i].value == arrSelected[j].replace(reg2, strSplit))
			{				  				
				bChecked = true; 
				break;				
			}
		}
		
		if (bChecked)
		{
			listCheckBox[i].src = "../outside/images/checkbox_C.jpg";
			listCheckBox[i].selected = '1';
			
			txtSelected = txtSelected + strSplit + listCheckBox[i].text;
			valueSelected = valueSelected + strSplit + listCheckBox[i].value;
		}
		else
		{
			listCheckBox[i].src = "../outside/images/checkbox_U.jpg";
			listCheckBox[i].selected = '0';	
		}
 		
		document.getElementById('text_' + groupName).value = txtSelected;	
		document.getElementById('value_' + groupName).value = valueSelected;
	}
}

function SelectedAll(groupName)
{
    if (!document.getElementById('split_' + groupName))
		return;
	var strSplit = document.getElementById('split_' + groupName).value;
		
	var listCheckBox = document.getElementsByName(groupName);
	var txtSelected = '';
	var valueSelected = '';	
			  
	for	(var i = 0; i < listCheckBox.length; i++)
	{
		listCheckBox[i].src = "../outside/images/checkbox_C.jpg";
		listCheckBox[i].selected = '1';
		
		txtSelected = txtSelected + strSplit + listCheckBox[i].text;
		valueSelected = valueSelected + strSplit + listCheckBox[i].value;
	}
	
	document.getElementById('text_' + groupName).value = txtSelected;	
	document.getElementById('value_' + groupName).value = valueSelected;
}

function MultiSelectAddValue(arrAdd, groupName)
{
    if (!document.getElementById('split_' + groupName))
		return;
	var strSplit = document.getElementById('split_' + groupName).value;			
	var valueSelected = document.getElementById('value_' + groupName).value;		
	var arrValueSelected = valueSelected.split(strSplit);
			  
	for	(var i = 0; i < arrAdd.length; i++)
	{
		var bAdd = true;
		for(var j = 0; j < arrValueSelected.length; j++)
		{
			if(arrAdd[i] == arrValueSelected[j])
			{
				bAdd = false;  
				break;				
			} 			
		}
		if(bAdd)
		{
			valueSelected = valueSelected + strSplit + arrAdd[i];
		}
	}
		
	document.getElementById('value_' + groupName).value = valueSelected;
	MultiCheckBox(valueSelected,groupName);
}

function MultiSelectRemoveValue(arrRemove, groupName)
{
    if (!document.getElementById('split_' + groupName))
		return;
	var strSplit = document.getElementById('split_' + groupName).value;			
	var valueSelected = document.getElementById('value_' + groupName).value;		
	var arrValueSelected = valueSelected.split(strSplit);			  
	var valueNewSelected = '';
	
	for	(var i = 0; i < arrValueSelected.length; i++)
	{
		var bDelete = false;
		for(var j = 0; j < arrRemove.length; j++)
		{
			if(arrValueSelected[i] == arrRemove[j])
			{
				bDelete = true;  
				break;				
			} 			
		}
		if(!bDelete)
		{
			valueNewSelected = valueNewSelected + strSplit + arrValueSelected[i];
		}
	}
		
	document.getElementById('value_' + groupName).value = valueNewSelected;
	MultiCheckBox(valueNewSelected,groupName);
}

function UnSelectedAll(groupName)
{		
    if (!document.getElementById('split_' + groupName))
		return;
	var listCheckBox = document.getElementsByName(groupName);
			  
	for	(var i = 0; i < listCheckBox.length; i++)
	{
		listCheckBox[i].src = "../outside/images/checkbox_U.jpg";
		listCheckBox[i].selected = '0';
	}
	
	document.getElementById('text_' + groupName).value = '';	
	document.getElementById('value_' + groupName).value = '';
}

function SingleCheckBox(strSelected, groupName)
{	
	var tempSelected = '';
	if (strSelected.length > 0)
		tempSelected = strSelected.substring(1, strSelected.length);
		
	var listCheckBox = document.getElementsByName(groupName);	
	var bChecked = false;			
			  
	for	(var i = 0; i < listCheckBox.length; i++)
	{
		if (!bChecked && listCheckBox[i].value == tempSelected)
		{
			listCheckBox[i].src = "../outside/images/checkbox_C.jpg";
			listCheckBox[i].selected = '1';
			document.getElementById('value_' + groupName).value = strSelected;
			bChecked = true;
		}
		else
		{
			listCheckBox[i].src = "../outside/images/checkbox_U.jpg";
			listCheckBox[i].selected = '0';
		}
	}
	
}
//zcj 2008-09-27
function SelectCheck (id)
   {
//        if (document.getElementById(id + 'canclick').value == '0')
//              return false;
        document.getElementById(id + 'checked').value = '1';
           if (document.getElementById(id + 'gray').value== '0')
               document.getElementById(id).children(0).children(0).src = "../outside/images/checkbox_C.jpg";
           else
               document.getElementById(id).children(0).children(0).src = "../outside/images/checkbox_C_N.jpg";
           
    }
function SelectNotCheck(id)
  {
     document.getElementById(id + 'checked').value = '0';
     if (document.getElementById(id + 'gray').value == '0')
        document.getElementById(id).children(0).children(0).src = " ../outside/images/checkbox_U.jpg";
     else
        document.getElementById(id).children(0).children(0).src = " ../outside/images/checkbox_U_N.jpg";
  }
    
        
//End CheckBox专用
//Start 自动刷新
function AutoRefresh(refreshCMD, millisecond)
{
	if (document.getElementById('AutoIntervalID')) 
	{
		var iIntervalID = document.getElementById('AutoIntervalID').value;
		window.clearInterval(iIntervalID);
		document.getElementById('AutoIntervalID').value = window.setInterval(refreshCMD, millisecond);
	}
	else
	{
		var input = document.createElement('input');
		input.id = 'AutoIntervalID';
		input.type = "hidden";
		input.value = window.setInterval(refreshCMD, millisecond);
		document.forms[0].appendChild(input);
	}
}
//End 自动刷新
//Start弹出层专用
function getBodySize()
{
	var bodySize = [];
	with(document.body) {
			bodySize[0] = (scrollWidth > clientWidth)?scrollWidth : clientWidth ;
			bodySize[1] = (scrollHeight > clientHeight)?scrollHeight : clientHeight ;
//			bodySize[1] = scrollHeight;
	}   
	return bodySize;
}
function isIE()
{
	return (document.all && window.ActiveXObject && !window.opera) ? true : false;
}
var gDivIndex = 900;
function OpenDiv(divID, sHtml, sScript,bHidden)
{
   var _bHidden=typeof(bHidden)=="undefined" ? false : bHidden;
//	d1 = new Date();
	if (document.getElementById(divID + '_HideAllElements')) 
	{   
	   if(!_bHidden){
		  document.getElementById(divID + '_HideAllElements').style.display = '';
		  ResetHideDiv(divID);
		}
	} 
	else 
	{
		var coverDiv = document.createElement('div');
		document.forms[0].appendChild(coverDiv);
		coverDiv.id = divID + '_HideAllElements';
		with(coverDiv.style) 
		{
			position = 'absolute';
			background = '#000000';
			left = '0px';
			top = '0px';
			var bodySize = getBodySize();
			width = "100%";//bodySize[0] + 'px'
			height = bodySize[1] + 'px';
			gDivIndex += 1;
			zIndex = gDivIndex;
			if (isIE()) 
			{
				filter = "Alpha(Opacity=50)";
			} else {
				opacity = 0.5;
			}
		}
	}	
	
	if (document.getElementById(divID + '_OpenClose'))	
	{
	  if(!_bHidden){
		var showDiv = document.createElement('div');
		showDiv.style.display = '';
	  }	
	}
	else
	{
		var showDiv = document.createElement('div');
		
		showDiv.id = divID + '_OpenClose';
		showDiv.className = 'DivOpenClose';
		showDiv.style.position = "absolute";
		if ((GetWindowWidth() - showDiv.clientWidth) > 0)  		
			showDiv.left = (GetWindowWidth() - showDiv.clientWidth) / 2;
		else
			showDiv.left = 0;
		if ((GetWindowHeight() - showDiv.clientHeight) > 0)
			showDiv.top = (GetWindowHeight() - showDiv.clientHeight) / 2;
		else
			showDiv.top = 0;
		gDivIndex += 1;
		showDiv.style.zIndex = gDivIndex;
		
		document.forms[0].appendChild(showDiv);
	}
	if(!_bHidden){
	  document.getElementById(divID + '_OpenClose').style.display = '';
	}else{
	  document.getElementById(divID + '_OpenClose').style.display = 'none';
	  document.getElementById(divID + '_HideAllElements').style.display = 'none';
	}  
	if (sHtml != null && sHtml != '')
	{
		document.getElementById(divID + '_OpenClose').innerHTML = sHtml;
//        BeginInitValue("document.all." + divID + '_OpenClose');
	}
	if (sScript != null && sScript != '')
		eval(sScript);
//	document.body.style.overflow = "hidden";
//	alert(document.getElementById(divID + '_HideAllElements').clientHeight);  	
//	d2 = new Date();
//  alert(d2.getTime() - d1.getTime());
}

function CloseDiv(divID)
{	
	document.getElementById(divID + '_OpenClose').style.display = 'none';
	document.getElementById(divID + '_HideAllElements').style.display = 'none';
	var ifrs=document.getElementById(divID + '_OpenClose').getElementsByTagName('iframe');
	for(var i=ifrs.length-1;i>=0;i--){
	   ifrs[i].parentNode.removeChild(ifrs[i]);   
	}
	document.getElementById(divID + '_OpenClose').innerHTML = "";
}
function ResetHideDiv(divID)
{
	if(document.getElementById(divID + '_HideAllElements'))
	{
		var bodySize = getBodySize();
		document.getElementById(divID + '_HideAllElements').style.width = "100%";//bodySize[0] + 'px';
		document.getElementById(divID + '_HideAllElements').style.height = bodySize[1] + 'px';
//		alert(bodySize[1]); 		
	}
}
var moveDiv = false; 
function StartDragDiv(obj) 
{
	if(event.button == 1)		 // && event.srcElement.tagName.toUpperCase() == "DIV"
	{
		obj.setCapture();
		moveDiv = true;
		GetDivPosition(obj);
	}  	
}
var yDiv = 0;
var xDiv = 0; 
function GetDivPosition(obj)
{
	var iTop = obj.offsetTop;
	var iLeft = obj.offsetLeft;
		
	while (obj = obj.offsetParent)
	{
		iTop = iTop + obj.offsetTop;			
		iLeft = iLeft + obj.offsetLeft;
	}
	yDiv = event.clientY - iTop;
	xDiv = event.clientX - iLeft;
}		 
function DragDiv(divID) 
{
	if(moveDiv)
	{	 
		var oldwin = document.getElementById(divID + '_OpenClose');
		if (oldwin)
		{
			oldwin.style.left = event.clientX - xDiv;
			oldwin.style.top = event.clientY - yDiv;
		}
	}
}
function StopDragDiv(obj)
{
	obj.releaseCapture();
	moveDiv = false;
} 
function AdjustTopPosition(divID)
{
	var oldwin = document.getElementById(divID + '_OpenClose');
	if (oldwin)
	{
		var left = 0;
		var top = 0;
		
		left = oldwin.offsetParent.clientWidth / 2 - oldwin.clientWidth / 2 + oldwin.offsetParent.scrollLeft;
		top = oldwin.offsetParent.clientHeight / 2 - oldwin.clientHeight / 2 + oldwin.offsetParent.scrollTop;
		if (left < 0)
		{
			left = 0;
		}
		if (top < 0)
		{
			top = 0;
		}
		
		oldwin.style.left = left;
		oldwin.style.top = top;
	}
}
//End弹出层专用

//
// 文件上传/下载
//
function ShowFileTransferDiv(sTransferType, sFileName, iOffset, iTotalSize)
{
    var oDiv = document.all.divFileTransfer;
    if (oDiv == null)
    {
        oDiv = document.createElement("div");
        oDiv.id = "divFileTransfer";
        oDiv.style.position = "absolute";
        oDiv.style.zIndex = "999";
        oDiv.style.display = "none";
        oDiv.style.backgroundColor = "#FEFFBD";
        oDiv.style.fontFamily = "宋体";
        oDiv.style.fontSize = "12px";
        oDiv.style.border = "solid 1px black";
        oDiv.style.width = "330px";
        oDiv.style.height = "130px";
        oDiv.style.left = (GetWindowWidth() - 330) / 2;
        oDiv.style.top = (GetWindowHeight() - 130) / 2;

        var sHtml = new Array();
        var iIndex = 0;

        sHtml[iIndex++] = "<table border='0' cellpadding='0' cellspacing='5' width='100%'>"
        sHtml[iIndex++] = "    <tr height='22'>"
        sHtml[iIndex++] = "        <td width='10%'>"
        sHtml[iIndex++] = "            &nbsp;</td>"
        sHtml[iIndex++] = "        <td width='80%'>"
        sHtml[iIndex++] = "            &nbsp;</td>"
        sHtml[iIndex++] = "        <td width='10%'>"
        sHtml[iIndex++] = "            &nbsp;</td>"
        sHtml[iIndex++] = "    </tr>"
        sHtml[iIndex++] = "    <tr>"
        sHtml[iIndex++] = "        <td>"
        sHtml[iIndex++] = "        </td>"
        sHtml[iIndex++] = "        <td nowrap onclick='alert(this.clientWidth);'>"
        sHtml[iIndex++] = "            <div style='overflow: hidden; text-overflow: ellipsis; width: 246'><font id='fontTransferFileName' style='color: DarkBlue; font-size: 12px;'><b>上传: </b>" + GetFileName(sFileName) + "</font></div></td>"
        sHtml[iIndex++] = "        <td>"
        sHtml[iIndex++] = "        </td>"
        sHtml[iIndex++] = "    </tr>"
        sHtml[iIndex++] = "    <tr>"
        sHtml[iIndex++] = "        <td>"
        sHtml[iIndex++] = "        </td>"
        sHtml[iIndex++] = "        <td>"
        sHtml[iIndex++] = "            <table border='0' cellpadding='0' cellspacing='0' width='100%'>"
        sHtml[iIndex++] = "                <tr>"
        sHtml[iIndex++] = "                    <td width='100%' style='border: solid 1px gray; padding: 2px;'>"
        sHtml[iIndex++] = "                        <img id='imgFileTransfer' src='" + GetAbsoluteUrl("/Outside/Images/FileTransfer.gif") + "' height='10' width='0%' /></td>"
        sHtml[iIndex++] = "                </tr>"
        sHtml[iIndex++] = "            </table>"
        sHtml[iIndex++] = "        </td>"
        sHtml[iIndex++] = "        <td>"
        sHtml[iIndex++] = "        </td>"
        sHtml[iIndex++] = "    </tr>"
        sHtml[iIndex++] = "    <tr>"
        sHtml[iIndex++] = "        <td>"
        sHtml[iIndex++] = "        </td>"
        sHtml[iIndex++] = "        <td id='tdFileTransfer' align='right' style='color: DarkBlue; font-size: 12px;'>"
        sHtml[iIndex++] = "            <table width='100%'><tr><td align='left'>已上传: 0.0%</td><td align='right'>0 /" + iTotalSize + "</td></tr></table></td>"
        sHtml[iIndex++] = "        <td>"
        sHtml[iIndex++] = "        </td>"
        sHtml[iIndex++] = "    </tr>"
        sHtml[iIndex++] = "    <tr>"
        sHtml[iIndex++] = "        <td id='tdFileTransferButton' colspan='3' align='center' style='padding-top: 10px;'>"
        sHtml[iIndex++] = "            </td>"
        sHtml[iIndex++] = "    </tr>"
        sHtml[iIndex++] = "</table>"
        
        oDiv.innerHTML = sHtml.join("");
        sHtml = null;
        document.forms[0].appendChild(oDiv);
    }

    document.all.fontTransferFileName.innerHTML = "<b>" + sTransferType + ": </b>" + GetFileName(sFileName);
    if (iTotalSize > 0)
    {
        document.all.imgFileTransfer.style.width = "" + (iOffset*100/iTotalSize).toFixed(1).toString() + "%";
        document.all.tdFileTransfer.innerHTML = "" + ToFileSize(iOffset) + " / " + ToFileSize(iTotalSize) + " 字节 (" + (iOffset*100/iTotalSize).toFixed(1) + "%)"
    }
    else
    {
        document.all.imgFileTransfer.style.width = "0%";
        document.all.tdFileTransfer.innerHTML = "0 / ? 字节 (0%)"
    }
    var gft_sTdFileTransferButtonHTML = "";
    if (gft_sFileTransferStatus == "")
        gft_sTdFileTransferButtonHTML = "<input type='button' value='取消' style='height: 20px; width: 60px;' onclick=\"gft_sFileTransferStatus='Pause'; if (confirm('取消文件传输?')) { gft_sFileTransferStatus='Off'; CloseFileTransferDiv(); } else gft_sFileTransferStatus='';\" />"
    else if (gft_sFileTransferStatus == "Pause" && sTransferType == "正在编辑")
        gft_sTdFileTransferButtonHTML = "<input type='button' value='取消' style='height: 20px; width: 60px;' onclick=\"if (confirm('您确定不需要将编辑后的文件保存回服务器吗?')) { gft_sFileTransferStatus='Off'; CloseFileTransferDiv(); }\" />"

    if (gsLastTdFileTransferButtonHTML != gft_sTdFileTransferButtonHTML)
    {
        gsLastTdFileTransferButtonHTML = gft_sTdFileTransferButtonHTML;
        document.all.tdFileTransferButton.innerHTML = gft_sTdFileTransferButtonHTML;
    }
    oDiv.style.display = "";
}

function ToFileSize(iSize)
{
    if (iSize >= 1000000)
        return (iSize / 1024 / 1024).toFixed(1).toString() + "M";
    else if (iSize >= 1000)
        return (iSize / 1024).toFixed(1).toString() + "K";
    return iSize.toString() + " 字节";
}

function GetFileName(sFilePath)
{
    var a = sFilePath.split("\\");
    return a[a.length - 1];
}

function GetFileNameExt(sFilePath)
{
    var a = sFilePath.split(".");
    return a[a.length - 1];
}

function CloseFileTransferDiv()
{
    if (document.all.divFileTransfer != null)
        document.all.divFileTransfer.style.display = "none";
}

function GetSelectOpenFileName(oWebX)
{
    var oFT = document.all.FT;
    if (oFT == null)
    {
        alert("文件传输控件不存在.");
        return "";
    }

    var v = oWebX.SelectOpenFile();
    oFT.value = v;
    if (oFT.value == "")
        return "";
    var r = oFT.value;
    oFT.value = "";
    return r;
}

function GetSelectSaveFileName(oWebX, sFileName)
{
    var oFT = document.all.FT;
    if (oFT == null)
    {
        alert("文件传输控件不存在.");
        return "";
    }

    var v = oWebX.SelectSaveFile(sFileName);
    oFT.value = v;
    if (oFT.value == "")
        return "";
    var r = oFT.value;
    oFT.value = "";
    return r;
}

function GetTmpPath(oWebX)
{
    var oFT = document.all.FT;
    if (oFT == null)
    {
        alert("文件传输控件不存在.");
        return "";
    }

    var v = oWebX.GetTempDirectoryName();
    oFT.value = v;
    if (oFT.value == "")
        return "";
    var r = oFT.value;
    oFT.value = "";
    return r;
}

function GetReadFileData(oWebX, sFileName, iOffset, iRead)
{
    var oFT = document.all.FT;
    if (oFT == null)
    {
        alert("文件传输控件不存在.");
        return "";
    }

    var v = oWebX.ReadFileData(sFileName, iOffset, iRead);
    oFT.value = v;
    if (oFT.value == "")
        return "";
    var r = oFT.value;
    oFT.value = "";
    return r;
}

function GetWriteFileData(oWebX, sFileName, iOffset, iSize, iTotalSize, sFileData)
{
    var oFT = document.all.FT;
    if (oFT == null)
    {
        alert("文件传输控件不存在.");
        return "";
    }
    var v = oWebX.WriteFileData(sFileName, iOffset, iSize, iTotalSize, sFileData);
    oFT.value = v;
    var r = oFT.value;
    oFT.value = "";
    return r;
}

function UploadFileByName(oWebX, sFileName, sFileType, sFileIdentifier, funOver)
{
    if (sFileName == "")
        return;
    var iTotalSize = oWebX.GetFileSize(sFileName);
    if (iTotalSize == 0)
    {
        alert("获取文件大小失败.");
        return;
    }

    gft_oWebX = oWebX;
    gft_sTransferType = "上传";
    gft_sFileType = sFileType;
    gft_sFileName = sFileName;
    gft_sFileIdentifier = sFileIdentifier;
    gft_iOffset = 0;
    gft_iTotalSize = iTotalSize;
    gft_sTmpFilePath = "";
    gft_funOver = funOver;

    gft_sFileTransferStatus = "";
    gsLastTdFileTransferButtonHTML = "";
    BeginFileTransfer();
}

function UploadFile(oWebX, sFileType, sFileIdentifier, funOver)
{
    var sFileName = GetSelectOpenFileName(oWebX);
    UploadFileByName(oWebX, sFileName, sFileType, sFileIdentifier, funOver);
}

function OpenFile(oWebX, sFileType, sFileIdentifier, sFileName, funOver)
{
    var sTmpPath = GetTmpPath(oWebX);
    if (sTmpPath == "")
        return;
    var sFileName = sTmpPath + sFileName;
    
    gft_oWebX = oWebX;
    gft_sTransferType = "浏览";
    gft_sFileType = sFileType;
    gft_sFileName = sFileName;
    gft_sFileIdentifier = sFileIdentifier;
    gft_iOffset = 0;
    gft_iTotalSize = 0;
    gft_sFilePath = "";
    gft_funOver = funOver;

    gft_sFileTransferStatus = "";
    gsLastTdFileTransferButtonHTML = "";
    BeginFileTransfer();
}

function EditFile(oWebX, sFileType, sFileIdentifier, sFileName, funOver)
{
    var sFileExt = GetFileNameExt(sFileName).toLowerCase();
    if (sFileExt != "doc" && sFileExt != "docx" && sFileExt != "xls")
    {
        alert("对不起, 目前只能对Word，Excel文件进行编辑.");
        return;
    }

    var sTmpPath = GetTmpPath(oWebX);
    if (sTmpPath == "")
        return;
    var sFileName = sTmpPath + sFileName;

    gft_oWebX = oWebX;
    gft_sTransferType = "编辑";
    gft_sFileType = sFileType;
    gft_sFileName = sFileName;
    gft_sFileIdentifier = sFileIdentifier;
    gft_iOffset = 0;
    gft_iTotalSize = 0;
    gft_sFilePath = "";
    gft_funOver = funOver;

    gft_sFileTransferStatus = "";
    gsLastTdFileTransferButtonHTML = "";
    BeginFileTransfer();
}

function DownloadFile(oWebX, sFileType, sFileIdentifier, sFileName, funOver, bDirectSave, bNoWarning)
{
    if (bDirectSave == null)
        sFileName = GetSelectSaveFileName(oWebX, sFileName);
    if (sFileName == "")
        return;

    gft_oWebX = oWebX;
    gft_sTransferType = "下载";
    gft_sFileType = sFileType;
    gft_sFileName = sFileName;
    gft_sFileIdentifier = sFileIdentifier;
    gft_iOffset = 0;
    gft_iTotalSize = 0;
    gft_sFilePath = "";
    gft_funOver = funOver;
    gft_bNoWarning = bNoWarning;

    gft_sFileTransferStatus = "";
    gsLastTdFileTransferButtonHTML = "";
    BeginFileTransfer();
}

function SaveBack()
{
    if (gft_oWebX.IsWordClosed(gft_sFileName, GetFileName(gft_sFileName)) == 0)
    {
        if (gft_sFileTransferStatus == "Pause")
            window.setTimeout(SaveBack, 1000);
        return;
    }
    if (!window.confirm("您确定将刚才编辑的文件保存回服务器吗？"))
    {
        EndFileTransfer();
        return;
    }
    var iTotalSize = gft_oWebX.GetFileSize(gft_sFileName);
    if (iTotalSize == 0)
    {
        alert("获取文件大小失败, 回传失败.");
        return;
    }
    gft_iTotalSize = iTotalSize;
    gft_sFileTransferStatus = "";
    gft_sTransferType = "回传";
    BeginFileTransfer();
}

var gft_sFileTransferStatus = "Off";
var gft_sTdFileTransferButtonHTML = "";
var gft_iFileSizePerSend = 1024 * 50;
var gft_oWebX;
var gft_sTransferType;
var gft_sFileType;
var gft_sFileName;
var gft_sFileIdentifier;
var gft_iOffset;
var gft_iTotalSize;
var gft_sTmpFilePath;
var gft_sFilePath;
var gft_oWebX;
var gft_funOver;
var gft_bNoWarning;

function BeginFileTransfer()
{
    ShowFileTransferDiv(gft_sTransferType, gft_sFileName, gft_iOffset, gft_iTotalSize);
    if (gft_sFileTransferStatus == "Off")
    {
        EndFileTransfer();
        return;
    }
    else if (gft_sFileTransferStatus == "Pause")
    {
        setTimeout(BeginFileTransfer, 500);
        return;
    }
    if (gft_sFileTransferStatus != "")
        return;
    if (gft_sTransferType == "上传" || gft_sTransferType == "回传")
        UploadFileTick(gft_oWebX, gft_sFileType, gft_sFileName, gft_sFileIdentifier, gft_sTmpFilePath, gft_iOffset, gft_iTotalSize);
    else if (gft_sTransferType == "下载" || gft_sTransferType == "编辑" || gft_sTransferType == "浏览")
        DownloadFileTick(gft_oWebX, gft_sFileType, gft_sFileName, gft_sFileIdentifier, gft_sFilePath, gft_iOffset, gft_bNoWarning);
    else
        EndFileTransfer();
}

function EndFileTransfer()
{
    gft_sFileTransferStatus = "Off";
    CloseFileTransferDiv();
}

function UploadFileTick(oWebX, sFileType, sFileName, sFileIdentifier, sTmpFilePath, iOffset, iTotalSize)
{
    //Start 调试用
    //var d1 = new Date();
    //var d2 = new Date();    
    //d1 = new Date();
    //End 调试用
    var iRead = iTotalSize - iOffset;
    if (iRead > gft_iFileSizePerSend)
        iRead = gft_iFileSizePerSend;
    var sData = GetReadFileData(oWebX, sFileName, iOffset, iRead);
    if (sData.length == 0)
    {
        alert("读取文件失败: " + iOffset + ", " + iTotalSize + ", " + sTmpFilePath + ", " + iRead);
        EndFileTransfer();
        return;
    }
    var arrPostData = new Array();
    var arrIndex = 0;
    arrPostData[arrIndex++] = "Data=" + encodeURIComponent(sData);
    sData = null;
 
    var xmlHttp;
    if (window.ActiveXObject)
	{
		xmlHttp=new ActiveXObject("MSXML2.XMLHTTP.3.0"); //("Microsoft.XMLHTTP") // ("MSXML2.XMLHTTP.3.0");
	}
	else if (window.XMLHttpRequest)
	{
		xmlHttp=new XMLHttpRequest;
	}
	var sUrl = GetAbsoluteUrl("/Outside/Comm.aspx") + (document.location.search == "" ? "?UCName=" : document.location.search + "&UCName=") + "UCEmpty&FatherID=&Event=UploadFile&t=" + new Date().getTime();

	xmlHttp.open("POST", sUrl, true);
	sUrl = null;
	xmlHttp.onreadystatechange = function()
	    {
            if (xmlHttp.readystate == 4)
            {
                if (xmlHttp.status == 200)
                {
                    xmlDoc = xmlHttp.responseXML;
                    var i;
                    
                    if (xmlDoc == null)
                    {
                        alert("UploadFile failed: xmlDoc == null");
                        return;
                    }
                    // alert(xmlDoc.xml);
                    nodeRoot = xmlDoc.childNodes[0];
                    if (nodeRoot == null)
                    {
                        alert("UploadFile failed: nodeRoot == null");
                        return;
                    }
                    if (nodeRoot.tagName != "ansyanswer")
                    {
                        alert("UploadFile failed: nodeRoot has wrong tag '" + nodeRoot.tagName + "'");
                        return;
                    }
                    var sExceiption = XmlData(nodeRoot, "Exception")
                    if (sExceiption != null)
                    {
                        alert("UploadFile 异常: " + sExceiption);
                        return;
                    }
                    var sPrompt = XmlData(nodeRoot, "Prompt");
                    if (sPrompt == "ok")
                    {
                        if (Number(iOffset) + Number(iRead) < iTotalSize)
                        {
                            if (iOffset == 0)
                                gft_sTmpFilePath = XmlData(nodeRoot, "TmpFilePath");
                            gft_iOffset = iOffset + iRead;
                            delete xmlHttp;
                            xmlHttp = null;
                            BeginFileTransfer();
                            return;
                        }                    
                        if (typeof gft_funOver == "function")
                            window.setTimeout('gft_funOver.call(null,XmlData(nodeRoot, "UploadFileRet"))', 1);
                    }
                    else
                        alert(sPrompt);
                }
                else
                {
                    alert("xmlHttp 状态异常");
                }
                EndFileTransfer();
                xmlHttp = null;
            }
            return;
        }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    arrPostData[arrIndex++] = "FileType=" + encodeURIComponent(sFileType);
    arrPostData[arrIndex++] = "FileName=" + encodeURIComponent(sFileName);
    arrPostData[arrIndex++] = "FileIdentifier=" + encodeURIComponent(sFileIdentifier);
    arrPostData[arrIndex++] = "TmpFilePath=" + encodeURIComponent(sTmpFilePath);
    arrPostData[arrIndex++] = "Offset=" + iOffset;
    arrPostData[arrIndex++] = "TotalSize=" + iTotalSize;
    var sPostData = arrPostData.join("&");
    arrPostData = null;
    arrIndex = null;
    xmlHttp.send(sPostData);
    sPostData = null;
}

function DownloadFileTick(oWebX, sFileType, sFileName, sFileIdentifier, sFilePath, iOffset, bNoWarning)
{
    //Start 调试用
    //var d1 = new Date();
    //var d2 = new Date();    
    //d1 = new Date();
    //End 调试用
 
    var xmlHttp;
    if (window.ActiveXObject)
	{
		xmlHttp=new ActiveXObject("MSXML2.XMLHTTP.3.0"); //("Microsoft.XMLHTTP") // ("MSXML2.XMLHTTP.3.0");
	}
	else if (window.XMLHttpRequest)
	{
		xmlHttp=new XMLHttpRequest;
	}
	var sUrl = GetAbsoluteUrl("/Outside/Comm.aspx") + (document.location.search == "" ? "?UCName=" : document.location.search + "&UCName=") + "UCEmpty&FatherID=&Event=DownloadFile&t=" + new Date().getTime();

	xmlHttp.open("POST", sUrl, true);
	sUrl = null;
	xmlHttp.onreadystatechange = function()
	    {
            if (xmlHttp.readystate == 4)
            {
                if (xmlHttp.status == 200)
                {
                    xmlDoc = xmlHttp.responseXML;
                    var i;
                    
                    if (xmlDoc == null)
                    {
                        alert("DownloadFile failed: xmlDoc == null");
                        delete xmlHttp;
                        xmlHttp = null;
                        return;
                    }
                    // alert(xmlDoc.xml);
                    nodeRoot = xmlDoc.childNodes[0];
                    if (nodeRoot == null)
                    {
                        alert("DownloadFile failed: nodeRoot == null");
                        delete xmlHttp;
                        xmlHttp = null;
                        return;
                    }
                    if (nodeRoot.tagName != "ansyanswer")
                    {
                        alert("DownloadFile failed: nodeRoot has wrong tag '" + nodeRoot.tagName + "'");
                        delete xmlHttp;
                        xmlHttp = null;
                        return;
                    }
                    var sExceiption = XmlData(nodeRoot, "Exception")
                    if (sExceiption != null)
                    {
                        alert("DownloadFile 异常: " + sExceiption);
                        delete xmlHttp;
                        xmlHttp = null;
                        return;
                    }
                    var sPrompt = XmlData(nodeRoot, "Prompt");
                    if (sPrompt == "ok")
                    {
                        var iTotalSize = parseInt(XmlData(nodeRoot, "TotalSize"));
                        var iDataSize = parseInt(XmlData(nodeRoot, "DataSize"));
                        var sFileData = XmlData(nodeRoot, "FileData");
                        var sRet = GetWriteFileData(oWebX, sFileName, iOffset, iDataSize, iTotalSize, sFileData);
                        if (sRet == "ok")
                        {
                            if (iOffset == 0)
                                gft_sFilePath = XmlData(nodeRoot, "FilePath");
                            gft_iOffset = iOffset + iDataSize;
                            if (gft_iOffset < iTotalSize)
                            {
                                gft_iTotalSize = iTotalSize;
                                delete xmlHttp;
                                xmlHttp = null;
                                BeginFileTransfer();
                                return;
                            }
                            if (gft_sTransferType == "下载")
                            {
                                EndFileTransfer();
                                if (typeof gft_funOver == "function")
                                    window.setTimeout(gft_funOver, 1);
                            } else if (gft_sTransferType == "浏览") {
                                EndFileTransfer();
                                if (oWebX.OpenFile(sFileName, GetFileName(sFileName)) == 0)
                                {
                                    alert("打开文件失败: " + sFileName);
                                    delete xmlHttp;
                                    xmlHttp = null;
                                    return;
                                }
                                if (typeof gft_funOver == "function")
                                    window.setTimeout(gft_funOver, 1);
                            } else if (gft_sTransferType == "编辑") {
                                if (oWebX.EditWordFile(sFileName, GetFileName(sFileName)) == 0)
                                {
                                    alert("打开文件失败: " + sFileName);
                                    delete xmlHttp;
                                    xmlHttp = null;
                                    return;
                                }
                                gft_oWebX = oWebX;
                                gft_sTransferType = "正在编辑";
                                gft_sFileType = sFileType;
                                gft_sFileName = sFileName;
                                gft_sFileIdentifier = sFileIdentifier;
                                gft_iOffset = 0;
                                gft_iTotalSize = iTotalSize;
                                gft_sFileTransferStatus = "Pause";
                                gft_oWebX = oWebX;
                                window.setTimeout(SaveBack, 1000);
                                ShowFileTransferDiv(gft_sTransferType, gft_sFileName, gft_iOffset, gft_iTotalSize);
                                delete xmlHttp;
                                xmlHttp = null;
                                return;
                            }
                        }
                        else
                        {
                            if (!bNoWarning)
                                alert("保存下载文件失败");
                        }
                    }
                    else
                        alert(sPrompt);
                }
                else
                    alert("xmlHttp 状态异常");
                EndFileTransfer();
                delete xmlHttp;
                xmlHttp = null;
            }
            return;
        }
    xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");

    var arrPostData = new Array();
    var arrIndex = 0;
    arrPostData[arrIndex++] = "FileType=" + encodeURIComponent(sFileType);
    arrPostData[arrIndex++] = "FileIdentifier=" + encodeURIComponent(sFileIdentifier);
    arrPostData[arrIndex++] = "FilePath=" + sFilePath;
    arrPostData[arrIndex++] = "Offset=" + iOffset;
    arrPostData[arrIndex++] = "Size=" + gft_iFileSizePerSend;
    var sPostData = arrPostData.join("&");
    arrPostData = null;
    arrIndex = null;
    xmlHttp.send(sPostData);
    sPostData = null;
}
// 
// End of 文件上传/下载
//

var gbInitValue = false;
function SetInputInitValue(objBody)
{
     //var iCount = 0;
    var listInput = objBody.getElementsByTagName("input");
    if (listInput != null)
    {
        var j = 0;
        var iInputLength = listInput.length;
        for (j = 0 ; j < iInputLength; j++)
        {
            var objInput = listInput[j];
            var strInputID = objInput.id;
            if (objInput.initvalue != null)
            {
                objInput.value = objInput.initvalue;
                objInput.initvalue = null;
                //iCount++;
            }
        }
    }
    //alert(iCount);
    gbInitValue = false;
}

function BeginInitValue(sBodyName)
{
    gbInitValue = true;
    window.setTimeout("SetInputInitValue(" + sBodyName + ");", 1);
}

function getCookie(cookiename, objname)
{
	var arr = document.cookie.match(new RegExp("(^| )" + cookiename + objname + "=([^;]*)(;|$)"));
	if(arr != null) 
		document.getElementById(objname).value = decodeURI(arr[2]); 
}

function setCookie(cookiename, objname)
{
	var d = new Date();
	d.setTime(d.getTime()+1000*60*60*24*30);
	var cookievalue = document.getElementById(objname).value;
	document.cookie = cookiename + objname + "=" + encodeURI(cookievalue)
		+ "; path=" + "/"
		+ "; expires=" + d.toGMTString();
}	
function delCookie(cookiename, objname)
{
	document.cookie = cookiename + objname + "=nothing"
		+ "; path=" + "/"
		+ "; expires=Fri, 31 Dec 1999 23:59:59 GMT;" 
}

//To Excel
function TableToExcel()
{
    var list = document.getElementsByTagName("table");
    var iCount = 1;
    
    if (list.length == 0)
        return;

    var arryTable = new Array();
    
    for (j = 0 ; j < list.length; j++)
	{
	    if (list[j].ts_type != null && list[j].ts_type == "excel")
	    {
	        arryTable.unshift(list[j].outerHTML);
	    }
	}
	
	if (arryTable.length == 0)
        return;
	
    try
	{
		var excelApp = new ActiveXObject("Excel.Application");		
		var excelWorkBook = excelApp.workbooks.add();
		
		var iSheetsCount = excelWorkBook.worksheets.count;
		
        if(iSheetsCount > 1)
        {
            for (j = 2 ; j <= iSheetsCount; j++)
		    {
		        excelWorkBook.worksheets(2).Delete();
		    }
        }
		
		for (j = 0 ; j < arryTable.length; j++)
		{
		    if (iCount > 1)
		    {
		        excelWorkBook.worksheets.add(null, excelWorkBook.worksheets(iCount - 1));
		    }
		    
		    window.clipboardData.setData("Text", arryTable[j]);
		    var excelSheet = excelWorkBook.worksheets(iCount);
		    excelSheet.name = "报表" + iCount;
		    excelWorkBook.worksheets(iCount).Paste;	
		    
		    iCount += 1;
		}		
		
		excelApp.DisplayAlerts = false;
		excelApp.visible = true;
		excelApp.UserControl = true;
	}  
	catch(e)
	{
		alert("您的电脑可能没有安装Microsoft Excel软件或浏览器权限不够！");
		return false;
	}	
}
//End Of To Excel
//start of mouse position
function mousePos(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
		};
  }
//end of mouse position

//Array contains
 Array.prototype.in_array = function(e){     
   for(i=0;i<this.length && this[i]!=e;i++);     
   return !(i==this.length);     
 }  
//end

/*星级评分控件Start*/
  var $RateStarStack=new Array();
  var RateStar=function(id,n,count,fun,readOnly,hiddenClose,hiddenEventSrc){ // 'n 代表星级 'count 当前分数 'fun OnClick function 'hiddenClose 隐藏closeImg
	  this.id=id;
	  this.starCount= typeof(n)=="undefined" ? 5 : n;
	  this.count=typeof(count)=="undefined" ? 0 : count;
	  this.container=document.getElementById(id);
	  this.readOnly=typeof(readOnly)=="undefined" ? false : readOnly;
	  this.hiddenClose=typeof(hiddenClose)=="undefined" ? false : hiddenClose;
	  this.container.style.width=19 * this.starCount;
	  this.container.style.height=18;
	  this.hiddenEventSrc=(typeof(hiddenEventSrc)=="undefined"||hiddenEventSrc==null) ? this.container : hiddenEventSrc;
	  this.fun=typeof(fun)=="undefined" ? function(){} : fun;
	  this.openImg=GetAbsoluteUrl("~/OutSide/Images/")+"star_red.gif";
	  this.closeImg=GetAbsoluteUrl("~/OutSide/Images/")+"star_gray.gif";
	  this.Create();
	  this.addStack();
  };
  RateStar.prototype={
      Create : function(){
	  	 this.CreateInput();
	     this.CreateStar();
	     if(this.hiddenClose&&!this.readOnly) this.BindStar();
	  },
	  BindStar : function(){
	      this.hiddenEventSrc.starObj=this;
	      this.hiddenEventSrc.onmouseover=function(){
	      	  this.starObj.InitStar(true);
	      };
	      this.hiddenEventSrc.onmouseout=function(){
	          this.starObj.InitStar(false);
	      };
	  },
	  InitStar : function(_show){
	      var _imgs=this.container.getElementsByTagName("img");
	      for(var i=0;i<_imgs.length;i++){
	        if(_show){
	           _imgs[i].style.display='';
	        }else{
	           if(_imgs[i].src.indexOf(this.closeImg.substring(this.closeImg.indexOf("/")))!=-1)  _imgs[i].style.display='none';
	        }
	      }
	  },
	  CreateStar : function(){
	     this.LoadStar(this.count);
	  },
	  CreateInput : function(){
	       var _input=document.createElement("input");
		   _input.type="hidden";
		   _input.id=this.id+"_Value";
		   _input.value=this.count;
		   this.input=_input;
		   this.container.appendChild(_input);
	  },
	  LoadStar : function(count){
		 for(var i=0;i<this.starCount;i++){
		    var _img=document.createElement("img");
			_img.index=i+1;
			if(i<count){
			  _img.src=this.openImg; 
			}else{
			   if(this.hiddenClose) _img.style.display='none';
			   _img.src=this.closeImg;
			}
			_img.style.cursor="pointer";
			_img.style.marginLeft="2px";
			_img.context=this;
			if(!this.readOnly){
			    _img.onmouseover=function(){
			       this.context.ChangeStatus(this.index,false,true);
			    };
			    _img.onmouseout=function(){
			       this.context.ChangeStatus(this.context.count,false,true);
			    };
			    _img.onclick=function(){
			       this.context.ChangeStatus(this.index,true,true);
			       this.context.fun.call(this.context);
			    };
			}
        	this.container.appendChild(_img);
		 }
	  },
	  ChangeStatus : function(_n,_save,_show){
	     var _imgs=this.container.getElementsByTagName("img");
		 for(var i=0;i<_imgs.length;i++){
		    if(i<_n) {
		       _imgs[i].src=this.openImg; 
		       _imgs[i].style.display='';
		    }else {
		       _imgs[i].src=this.closeImg;
		    }
		 }
		 if(_save){
		   if(_n==this.input.value){
		      this.input.value=0;
			  this.count=0;
			}else{
		      this.input.value=_n;
		      this.count=_n;
			}
		 }
		 if(!_show){
		   this.InitStar(_show);
		 }
	  },
	  addStack : function(){
	     for(var i=0;i<$RateStarStack.length;i++){
		    if($RateStarStack[i].id==this.id){
			   $RateStarStack.splice(i,1);
			   break;
			}
		 }
	     $RateStarStack.push(this);
	  }	  
  };
/*星级评分控件End*/

/*单选框Start*/
   var $CheckBoxStack=new Array();
   var UICheckBox=function(id,bChecked,bGray,bCanClick,strText,clickFun,strStyle,bTextNowrap){
	  this.id=id;
	  this.container=document.getElementById(id);
	  this.checked=typeof(bChecked)=="undefined" ? false : bChecked;
	  this.Gray=typeof(bGray)=="undefined" ? false : bGray;
	  this.CanClick=typeof(bCanClick)=="undefined" ? true : bCanClick;
	  this.strText=typeof(strText)=="undefined" ? "" : strText;
	  this.clickFun=typeof(clickFun)=="undefined" ? function(){} : clickFun;
	  this.strStyle=typeof(strStyle)=="undefined" ? "" : strStyle;
	  this.TextNowrap=typeof(bTextNowrap)=="undefined" ? false : bTextNowrap;
	  this.CImg=GetAbsoluteUrl("~/OutSide/Images/")+"checkbox_C.jpg";
	  this.NCImg=GetAbsoluteUrl("~/OutSide/Images/")+"checkbox_C_N.jpg";
	  this.UImg=GetAbsoluteUrl("~/OutSide/Images/")+"checkbox_U.jpg";
	  this.NUImg=GetAbsoluteUrl("~/OutSide/Images/")+"checkbox_U_N.jpg";
	  this.Create();
	  this.addStack();
   };
   UICheckBox.prototype={
      Create : function(){
		 this.CreateBox();
         if(this.strText!="") this.CreateSpan();
		 if(this.CanClick) this.BindEvent();
		 this.container.context=this;
		 this.container.style.width=typeof(this.span)=="undefined" ? 14 : (14+this.span.offsetWidth);
		 this.CreateInput();
	  },
	  CreateInput : function(){
	     var _input=document.createElement("input");
		 _input.type="hidden";
		 _input.id=this.id+"_Value";
		 _input.value=this.checked;
		 this.input=_input;
		 this.container.appendChild(_input); 
	  },
	  CreateSpan : function(){
	     var _span=document.createElement("span");
		 if(this.strStyle!="")  _span.style.cssText=this.strStyle;
		 if(this.TextNowrap) _span.style.whiteSpace="nowrap";
		 _span.innerHTML=this.strText;
		 _span.style.paddingLeft="2px";
		 this.span=_span;
		 this.container.appendChild(_span);
	  },
	  CreateBox : function(){
	     var _img=document.createElement("img");
		 if(this.Gray){
		   if(this.checked) _img.src=this.NCImg; else _img.src=this.NUImg;
		 }else{
		   if(this.checked) _img.src=this.CImg; else _img.src=this.UImg;   
		 }
		 this.box=_img;
		 _img.style.verticalAlign="middle";
		 this.container.appendChild(_img);
	  },
	  BindEvent : function(){
	     this.container.onclick=function(){
		    this.context.ChangeStatus();
			this.context.clickFun.call(this.context);
		 };
	  },
	  ChangeStatus : function(){
	     if(this.Gray){
		   if(!this.checked) this.box.src=this.NCImg; else this.box.src=this.NUImg;
		 }else{
		   if(!this.checked) this.box.src=this.CImg; else this.box.src=this.UImg;   
		 }
		 this.checked=!this.checked;
		 this.input.value=this.checked;
	  },
	  addStack : function(){
	     for(var i=0;i<$CheckBoxStack.length;i++){
		    if($CheckBoxStack[i].id==this.id){
			   $CheckBoxStack.splice(i,1);
			   break;
			}
		 }
	     $CheckBoxStack.push(this);
	  }
   };
/*单选框End*/

/*复选框Start*/
 var $CheckBoxGroupStack=new Array();
 var UICheckBoxGroup=function(id,iRowCount,bMultiSelected,strSplit,strStyle,bTextNowrap,txtBack,cmdClick,cmdMenu){
    this.id=id;
    this.RowCount=typeof(iRowCount)=="undefined" ? 0 : iRowCount;
	this.MultiSelected=typeof(bMultiSelected)=="undefined" ? true : bMultiSelected;
	this.strSplit=typeof(strSplit)=="undefined" ? ","  : strSplit;
	this.strStyle=typeof(strStyle)=="undefined" ? "font-size:12px;" : strStyle;
	this.TextNowrap=typeof(bTextNowrap)=="undefined" ? false : bTextNowrap;
	this.txtBack=typeof(txtBack)=="undefined" ? true : txtBack;
	this.cmdClick=typeof(cmdClick)=="undefined" ? function(){} : cmdClick;
	this.cmdMenu=typeof(cmdMenu)=="undefined" ? null : cmdMenu;
	this.CImg=GetAbsoluteUrl("~/OutSide/Images/")+"checkbox_C.jpg";
	this.UImg=GetAbsoluteUrl("~/OutSide/Images/")+"checkbox_U.jpg";
	this.addStack();
	this.saveParams();
	this.group=new Array();
 };
 UICheckBoxGroup.prototype={
   LoadItems : function(map,values,num){
      var _c=this.getContainer(num);
	  if(_c!=null && map.length>0){
	    var _ul=this.createUL(_c);
		this.addItem(map,values,_ul);
		_c.appendChild(_ul);
	  }
   },
   addItem : function(map,values,_ul){
       for(var i=0;i<map.length;i++){
         var _li=document.createElement("li");
		 _li.index=this.group.length;
		 if(this.RowCount!=0){
		   _li.style.cssText="padding:0;margin:0;width:"+ (100/this.RowCount|0) +"%;float:left;height:1.3em;";
		 }
		 _li.style.cursor="default";
		 //span
		 var _span=document.createElement("span");
		 if(map[i].key!=""){
			_span.style.cssText=this.strStyle;
			if(this.TextNowrap) _span.style.whiteSpace="nowrap";
			_span.innerHTML=map[i].key;
			_li.span=_span;
		 }
		 //img
		 var _img=document.createElement("img");
		 _img.style.verticalAlign="middle";
		  if(values.in_array(map[i].value)){
		    _img.src=this.CImg;
			_li.checked=true;
		  }else{
		    _img.src=this.UImg;
			_li.checked=false;
		  }
		  _li.img=_img;
		  _li.text=map[i].key;
		  _li.data=map[i].value;
		  if(this.txtBack){
		     _li.appendChild(_img);
			 if(typeof(_li.span)!="undefined") {_li.appendChild(_span); _span.style.paddingLeft=5;}
		  }else{
		     if(typeof(_li.span)!="undefined") {_li.appendChild(_span); _span.style.paddingRight=5;}
             _li.appendChild(_img);
		  }
		  _ul.appendChild(_li);
		  _li.context=this;
		  //BindEvent
		  _li.onclick = function(){
		      this.img.src=this.checked ? this.context.UImg : this.context.CImg;
			  this.checked=!this.checked;
			  this.context.changeValue(this);
			  this.context.cmdClick.call(this);
		  };
		  if(this.cmdMenu!=null&&typeof(this.cmdMenu)=="function"){
			  _li.oncontextmenu=function(){
				 this.context.cmdMenu.call(this);
				 return false;
			  };
		  }
		  _ul.appendChild(_li);
		  this.group.push(_li);
	   }
	   this.initValue(values);
	   this.initText();
   },
   changeValue : function(obj){    
	   var _values="";
	   var _keys="";
	   for(var i=0;i<this.group.length;i++){
		 if(this.group[i].checked && this.MultiSelected){
		    _keys+=this.strSplit+this.group[i].text;
		    _values+=this.strSplit+this.group[i].data;
		 }
		 if(!this.MultiSelected && this.group[i]!=obj){
		    this.group[i].img.src=this.UImg;
			this.group[i].checked=false;
		 }
	   }
	   if(!this.MultiSelected && obj.checked) {
	      _keys=this.strSplit+obj.text;
	      _values=this.strSplit+obj.data;
	   }
	   document.getElementById(this.id+"_Value").value=_values;
	   document.getElementById(this.id+"_Text").value=_keys;
   },
   initValue : function(values){
	  var _value=document.getElementById(this.id+"_Value").value;
	  var arr_value=_value.split(this.strSplit);
	  for(var i=0;i<values.length;i++){
	     if(!arr_value.in_array(values[i])) {
		   _value+=this.strSplit+values[i];
	     }
	  }
	  document.getElementById(this.id+"_Value").value=_value;
   },
   initText : function(){
	  var arr_value=document.getElementById(this.id+"_Value").value.split(this.strSplit);
	  var _text="";
	  for(var i=0;i<this.group.length;i++){
	     if(arr_value.in_array(this.group[i].data)){
		    _text+=this.strSplit+this.group[i].text;
		 }
	  }
	  document.getElementById(this.id+"_Text").value=_text;	  
   },
   createUL : function(_c){
       var _ul=document.createElement("ul");
	   _ul.style.cssText="list-style:none;margin:0;padding:0;width:100%;";
	   _c.ul=_ul;
	   _c.appendChild(_ul); 
	   return _ul;
   },
   getContainer : function(num){
      var _containers = document.getElementsByTagName("div");
	  for(var i=0;i<_containers.length;i++){
	    if(_containers[i].index==num && _containers[i].name==this.id)  return _containers[i];
	  }
	  return null;
   },
   saveParams : function(){
      this.createInput("Text","");
	  this.createInput("Value","");
	  this.createInput("Split",this.strSplit);
   },
   createInput : function(sign,value){
     if(!document.getElementById(this.id+"_"+sign)){
          var _input=document.createElement("input");
	      _input.type="hidden";
	      _input.id=this.id+"_"+sign;
	      document.getElementsByTagName("form")[0].appendChild(_input);
     }
	 document.getElementById(this.id+"_"+sign).value=value;
   },
   ReSetValue : function(){
     var _text="";
	 var _value="";
      for(var i=0;i<this.group.length;i++){
	      if(this.group[i].checked){
		   _text+=this.strSplit+this.group[i].text;
		   _value+=this.strSplit+this.group[i].data;
		  }
	  }
	  document.getElementById(this.id+"_Value").value=_value;
	  document.getElementById(this.id+"_Text").value=_text;
   },
   SelectedAll : function(){
     var _text="";
	 var _value="";
      for(var i=0;i<this.group.length;i++){
	      this.group[i].checked=true;
		  this.group[i].img.src=this.CImg;
		  _text+=this.strSplit+this.group[i].text;
		  _value+=this.strSplit+this.group[i].data;
	  }
	  document.getElementById(this.id+"_Value").value=_value;
	  document.getElementById(this.id+"_Text").value=_text;
   },
   UnSelectedAll : function(){
      for(var i=0;i<this.group.length;i++){
	      this.group[i].checked=false;
		  this.group[i].img.src=this.UImg;
	  }
	  document.getElementById(this.id+"_Value").value="";
	  document.getElementById(this.id+"_Text").value="";
   },
   addStack : function(){
	  for(var i=0;i<$CheckBoxGroupStack.length;i++){
		if($CheckBoxGroupStack[i].id==this.id){
		   $CheckBoxGroupStack.splice(i,1);
		   break;
		}
	 }
	 $CheckBoxGroupStack.push(this);
   }
 };
/*复选框End*/
/*GetControlByIdAndName*/
GetControlByIdAndName=function(id,Name){
   var arr;
   switch(Name){
       case "RateStar":
               arr=$RateStarStack;
               break;
       case "CheckBox":
               arr=$CheckBoxStack;
               break;
       case "CheckBoxGroup": 
               arr=$CheckBoxGroupStack;
               break;
       default:
               arr=new Array();
   }
   for(var i=0;i<arr.length;i++){
      if(id==arr[i].id) return arr[i];
   }
   return null;
};

/*UCButton Start*/
 UCButtonAddEvent=function(id,path,strOnClick,index){
   btn1={"upL":"Blank.gif","upR":"Blank.gif","downL":"btnS01DownLeft.gif","downR":"btnS01DownRight.gif","overL":"btnS01OnLeft.gif","overR":"btnS01OnRight.gif"};
   btn2={"upL":"Blank.gif","upR":"Blank.gif","downL":"btnS02DownLeft.gif","downR":"btnS02DownRight.gif","overL":"btnS02OnLeft.gif","overR":"btnS02OnRight.gif"};
   btn3={"upL":"Blank.gif","upR":"Blank.gif","downL":"btnS03DownLeft.gif","downR":"btnS03DownRight.gif","overL":"btnS03OnLeft.gif","overR":"btnS03OnRight.gif"};
   btn4={"upL":"btnS04OnLeft.gif","upR":"btnS04OnRight.gif","downL":"btnS04DownLeft.gif","downR":"btnS04DownRight.gif","overL":"btnS04OnLeft.gif","overR":"btnS04OnRight.gif"};
   btn5={"upL":"btnS01OnLeft.gif","upR":"btnS01OnRight.gif","downL":"btnS01DownLeft.gif","downR":"btnS01DownRight.gif","overL":"btnS01OnLeft.gif","overR":"btnS01OnRight.gif"};
   btn6={"upL":"btnS05OnLeft.gif","upR":"btnS05OnRight.gif","downL":"btnS05DownLeft.gif","downR":"btnS05DownRight.gif","overL":"btnS05OnLeft.gif","overR":"btnS05OnRight.gif"};
   setbackgroundImg=function(obj,path,r,x,y){
	  if(typeof(obj)!="undefined"){
	    if(typeof(path)!="undefined") obj.style.backgroundImage="url("+GetAbsoluteUrl("~/Outside/Images/")+path+")";
		if(typeof(r)!="undefined") obj.style.backgroundRepeat=r;
		if(typeof(x)!="undefined") obj.style.backgroundPositionX=x;
		if(typeof(y)!="undefined") obj.style.backgroundPositionY=y;
	   }
	};
	
	var objImg=eval("btn"+index);
    var _b=document.getElementById(id);
	if(typeof(path)!="undefined"){
	  setbackgroundImg(_b.children(0).children(0),path,"no-repeat","left","bottom");
	  _b.children(0).children(0).style.fontSize="17px";
	  _b.children(0).children(0).style.paddingRight="2px";
	}else{
	  _b.children(0).style.paddingLeft="5px";
	  _b.children(0).style.lineHeight="23px";
	}
	_b.onmousedown=function(){
	  setbackgroundImg(this,objImg.downL);
	  setbackgroundImg(this.children(0),objImg.downR);
	};
	_b.onmouseover=function(){
	  setbackgroundImg(this,objImg.overL);
	  setbackgroundImg(this.children(0),objImg.overR);
	};
	_b.onmouseup=function(){
	  setbackgroundImg(this,objImg.overL);
	  setbackgroundImg(this.children(0),objImg.overR);
	};
	_b.onmouseleave=function(){
	  setbackgroundImg(this,objImg.upL);
	  setbackgroundImg(this.children(0),objImg.upR);
	};
	_b.onclick=function(){
	  strOnClick.call(this);
	};
	setbackgroundImg(_b,objImg.upL,"no-repeat","left","top");
	setbackgroundImg(_b.children(0),objImg.upR,"no-repeat","right","top");
 };
/*UCButton End*/

/*菜单Start*/
var clickOk = false;
var oTimeOut = null;
function fun_MenuEventFix(){
    var topMenu = document.getElementById("menuULBar");
    topMenu.onmouseout=function() {
        var evt = window.event ? window.event : null;
        var _self = evt.toElement;
        while(_self && _self.className != 'cMenuBar')
            _self = _self.parentNode;
        if(_self!=null) return;
        oTimeOut = setTimeout('fun_MenuHidden(false)',1000);
    }
        
    var subMenu = document.getElementById("menuULBar").childNodes;
    for (var i=0; i<subMenu.length; i++) {
        if(subMenu[i].className=="sp") continue;
        subMenu[i].onclick=function() {
            if(clickOk==false) {
                this.className="sfhover";
                clickOk = true;
            }
            else{
                this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"),"");
                clickOk = false;
            }
        }
        subMenu[i].onmouseover=function() {
            this.className=this.className + " hover";
            clearTimeout(oTimeOut);
            if(clickOk==true) {
                fun_MenuHidden(clickOk);
                this.className=this.className + " sfhover";
            }
        }
        
         subMenu[i].onmouseout=function() {
            this.className=this.className.replace(new RegExp("( ?|^)hover\\b"),"");
        }
        
        var subsubMenu = subMenu[i].getElementsByTagName('li');
        for (var x=0; x<subsubMenu.length; x++) {
            if(subsubMenu[x].ref=='subsubmenu'){
                subsubMenu[x].onmouseover=function() {
                    clearTimeout(oTimeOut);
                    this.className="sfhover";
                }
                
                subsubMenu[x].onmouseout=function() {
                    this.className=this.className.replace(new RegExp("( ?|^)sfhover\\b"),"");
                }
            }
        }
    }
} 

function fun_MenuHidden(hidden) {
    var subMenu = document.getElementById("menuULBar").childNodes;
    for (var x=0; x<subMenu.length; x++) {
        if(subMenu[x].className=="sp") continue;
        subMenu[x].className=subMenu[x].className.replace(new RegExp("( ?|^)sfhover\\b"),"");
    }
    clickOk = hidden;
}
/*菜单End*/
