/**
 * This array is used to remember mark status of tdatas in btdatase mode
 */
var marked_row = new Array;

/**
 * enables highlight and marking of tdatas in data tables
 *
 */
function PMA_marktdatasInit() 
{
    //for every table td ...
    var tdatas=document.getElementsByTagName('td');
    for(var i=0; i < tdatas.length; i++) 
    {
    		//alert(tdatas[i].className);
    		// ... with the class 'odd' or 'even' ...
        if(tdatas[i].className != 'selector' && tdatas[i].className != 'selector_chk') 
        {
         	continue;
        }
        
        // ... add event listeners ...
        // ... to highlight the row on mouseover ...
        if(navigator.appName == 'Microsoft Internet Explorer' ) 
        {
            // but only for IE, other btdatasers are handled by :hover in css
            tdatas[i].onmouseover = function() 
            {
                //this.className += ' hover';
                switch(this.className)
                {
                	case 'selector'	:
                		{
                			this.style.backgroundColor='#781777';
                			this.style.color='#ffffff';
                		}
                		break;
                	case 'selector_small'	:
                		{
                			this.style.backgroundColor='#781777';
                			this.style.color='#ffffff';
                		}
                		break;
                	case 'selector_chk'	:
                		{
                			this.style.backgroundColor='none';
                			this.style.color='#781777';
                		}
                		break;
                }
            }
            tdatas[i].onmouseout = function() 
            {
                // this.className = this.className.replace( ' hover', '' );
                if(this.className.indexOf('marked') == -1) 
                {
                    switch(this.className)
                    {
                    	case 'selector'	:
                    		{
                    			this.style.backgroundColor='#faf7f4';
                					this.style.color='#781777';
                					nd();
                    		}
                    		break;
                    	case 'selector_small'	:
                    		{
//                    			this.style.backgroundColor='#c8c1ac';
                					this.style.color='#781777';
                					nd();
                    		}
                    		break;
                    	case 'selector_chk'	:
                    		{
                    			this.style.backgroundColor='none';
                					this.style.color='#ffffff';
                					nd();
                    		}
                    		break;
                    }
                } 
                else 
                {
//                    this.style.backgroundColor='#c8c1ac';
                }
            }
        }
        // Do not set click events if not wanted
        if(tdatas[i].className.search(/noclick/) != -1) 
        {
            continue;
        }
        // ... and to mark the row on click ...
        tdatas[i].onmousedown = function() {
            var unique_id;
            var checkbox;
            checkbox = this.getElementsByTagName( 'input' )[0];
            if ( checkbox && checkbox.type == 'checkbox' ) {
                unique_id = checkbox.name + checkbox.value;
            } else if ( this.id.length > 0 ) {
                unique_id = this.id;
            } else {
                return;
            }
            if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                marked_row[unique_id] = true;
            } else {
                marked_row[unique_id] = false;
            }
            if ( marked_row[unique_id] ) {
                this.className += ' marked';
            } else {
                this.className = this.className.replace(' marked', '');
            }
            if ( checkbox && checkbox.disabled == false ) {
                checkbox.checked = marked_row[unique_id];
            }
        }
        // ... and disable label ...
        var labeltag = tdatas[i].getElementsByTagName('label')[0];
        if ( labeltag ) {
            labeltag.onclick = function() {
                return false;
            }
        }
        // .. and checkbox clicks
        var checkbox = tdatas[i].getElementsByTagName('input')[0];
        if ( checkbox ) {
            checkbox.onclick = function() {
                // opera does not recognize return false;
                this.checked = ! this.checked;
            }
        }
    }
} 
