﻿// JScript 文件

function TableRowHilighter(tbl,hasFooter,rowHeight, hilightColor) {
    this.currentRow = null;
    this.hilightColor = hilightColor ? hilightColor : '#ffffdf';
    this.RowHeight = rowHeight?rowHeight:20;
    var _this = this;
    
    ie5 = document.all && document.getElementById && navigator.userAgent.toLowerCase().indexOf('opera')==-1?1:0 ;    
    
    if(!tbl || tbl.rows.length==0)return;
    
    var rowlen = tbl.rows.length;
    var footercount = hasFooter?1:0;
    
    tbl.className='dg_table';
    
    tbl.rows[0].className = "dg_header";
    
    if(footercount>0)
    {
        tbl.rows[rowlen-1].className = "dg_page";
    }
    
    for(i=1;i<rowlen-footercount;i++)
    {
        if(i%2==0)
        tbl.rows[i].className = "dg_alter";
        else tbl.rows[i].className = "dg_item";
    }
        
    if(tbl.attachEvent){
        
        for(i=1;i<rowlen-footercount;i++)
        {
            tbl.rows[i].attachEvent("onmouseover", rowonmouseover);
            tbl.rows[i].attachEvent("onmouseout", rowonmouseout);
        }
    }
    else
    {        
        for(i=1;i<tbl.rows.length;i++)
        {
            //tbl.rows[i].addEventListener("mouseover", rowonmouseover);
            //tbl.rows[i].addEventListener("mouseout", alert(event));
        }
    }    
    
    function rowonmouseout() {   

         if(!event){
               event || window.event;
        }
        if(event.srcElement)
        {
            e = event.srcElement;
        }
        else{ e = event.target;}
        
                
        while(e.tagName!='TR' && e.parentElement)
        {
            e = e.parentElement;
        }
        
        if (e.tagName != 'TR'){ return;}

        if (_this.currentRow){
            _this.currentRow.runtimeStyle.backgroundColor = '';
        }
       
        //document.defaultView.getComputedStyle(e,null).backgroundColor = _this.hilightColor;
       
        _this.currentRow.runtimeStyle.backgroundColor ='';
        _this.currentRow.runtimeStyle.height=_this.RowHeight;
        _this.currentRow.runtimeStyle.fontWeight='';
    }

    function rowonmouseover() {
        if(!event){
               event || window.event;
        }
        if(event.srcElement)
        {
            e = event.srcElement;
        }
        else{ e = event.target;}
      
        while(e.tagName!='TR' && e.parentElement)
        {
            e = e.parentElement;
        }
        //if (_this.currentRow ==e){return;}
        if (e.tagName != 'TR'){ return;}

        if (_this.currentRow){
            _this.currentRow.runtimeStyle.backgroundColor = '';
        }

        e.runtimeStyle.backgroundColor = _this.hilightColor;
        e.runtimeStyle.height=_this.RowHeight+10;
        e.runtimeStyle.fontWeight='bold';
        _this.currentRow = e;
    }
}

function showPopupWindow(popupWindowClientID,w,h,srcElemnet,xplace,yplace,url,padding)
{
    if(!padding)padding=50;
    
    $('divPopupWindow'+popupWindowClientID).setStyle('display','block');
    
    var left=0;
    var top=0;
    
    if($chk(srcElemnet))
    {
        var scoor = $(srcElemnet).getCoordinates();
        var left=scoor.left;//+padding;
        var top=scoor.top;//+padding;
    }
    
    
   if(xplace=='centerofwin')
    {
        point = window.center({width:padding,height:padding});
        top = point.y ;
        left = point.x;
        
        
        $('divPopupWindow'+popupWindowClientID).setStyle('left',left-w/2);
        $('divPopupWindow'+popupWindowClientID).setStyle('top',top-h/2);
 
        if(url)   document.getElementById('frmPopupWindow'+popupWindowClientID).src=url;
        return;
    }
    
    if(yplace=='above')
    {
        top = scoor.top-h-padding;
    }
    if(yplace=='below')
    {
        top = scoor.top+padding;
    }
    
    if(xplace=='left')
    {
        left = scoor.left-w-padding;
    }
    
    if(xplace=='right')
    {
        left = scoor.left+padding;
    }
    
    while(w+left>window.rightbottom().x)
    {
        left=left-50;
    }
    
    if(w<window.rightbottom().x)
    while(w+left>window.rightbottom().x)
    {
        left=left-50;
    }

    if(left<=0)left=50;
    if(top<=0)top=50;
    
    $('divPopupWindow'+popupWindowClientID).setStyle('left',left);
    $('divPopupWindow'+popupWindowClientID).setStyle('top',top);
    
    if(url)   document.getElementById('frmPopupWindow'+popupWindowClientID).src=url;

}

