﻿var theDefaultColor;   //默认颜色 
var theAlterColor;     //间隔颜色
var theOverColor;      //鼠标经过颜色
var theMarkColor;      //标记颜色
var dataTable;         //数据表格
var theBtn;            //全选按钮
function senfe(o, a, b, c, d, checkBox) {
    theDefaultColor = a;
    theAlterColor = b;
    theOverColor = c;
    theMarkColor = d;
    if (!GetObj(o)) return;
    dataTable = GetObj(o);
    theBtn = GetObj(checkBox);
    var t = dataTable.getElementsByTagName("tr");
    for (var i = 1; i < t.length; i++) {
        var myCheck;
        t[i].style.backgroundColor = (t[i].sectionRowIndex % 2 == 0) ? theDefaultColor : theAlterColor;
        t[i].onclick = function() {
            if (this.x != "1") {
                this.x = "1"; //本来打算直接用背景色判断，FF获取到的背景是RGB值，不好判断
                this.style.backgroundColor = theMarkColor;
            } else {
                this.x = "0";
                this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? theDefaultColor : theAlterColor;
            }
            if (checkBox) {
                myCheck = this.getElementsByTagName('input')[0];
                myCheck.checked = !myCheck.checked;
            }
        }
        if (checkBox) {
            t[i].getElementsByTagName('td')[0].getElementsByTagName('input')[0].onclick = function() {
                this.checked = !this.checked;
            }
        }   
        t[i].onmouseover = function() {
            if (this.x != "1") this.style.backgroundColor = theOverColor;
        }
        t[i].onmouseout = function() {
            if (this.x != "1") this.style.backgroundColor = (this.sectionRowIndex % 2 == 0) ? theDefaultColor : theAlterColor;            
        }        
    }
}
function setColor(rowId) {
    var t = dataTable.getElementsByTagName("tr");
    var list = new Array;
    if (rowId.indexOf("|") == -1) list[0] = rowId;
    else list = rowId.split("|");
    
    for (var i = 1; i < t.length; i++) {
        var myCheck = t[i].getElementsByTagName('input')[0];
        var checkId = myCheck.id.replace("Ch", "");
        if (JS_cruel_search(list, checkId) > -1) {
            if (document.all) {
                t[i].click();
            } else {
                var evt = document.createEvent("MouseEvents");
                evt.initEvent("click", true, true);
                t[i].dispatchEvent(evt);
            }
        }
    }
}
function JS_cruel_search(data, key)       /*JS暴虐查找*/
{
    re = new RegExp(key, [""])
    return (data.toString().replace(re, "|").replace(/[^,|]/g, "")).indexOf("|")
}

function selectAll(obj) {
    if (!dataTable) return false;
    var t = dataTable.getElementsByTagName("tr");
    for (var i = 1; i < t.length; i++) {       
        if(document.all){
            t[i].click();   
        }else{  
            var evt = document.createEvent("MouseEvents");  
            evt.initEvent("click",true,true);  
            t[i].dispatchEvent(evt);  
        }
    }
    if(obj==0) theBtn.checked = !theBtn.checked;
}
