﻿// Created by Randell 04/23/2007

var hBColor;
var hFColor;

function findParentRow(e){
    var row=e;
    while(row.tagName!='TR'){
        if(row==null)break;
        row=row.parentElement;
    }
    return row;
}

function setHighLightColor(gridViewId,highlightBackgroundColor,highlightForeColor,selectedColor,pageSize,cursor,columnSelectorIndex,clickFunction){
    if(redf_getElementById(gridViewId)==null)return;

    var rowCollection=redf_getElementById(gridViewId).childNodes[0].childNodes;
    
    for(var i=1;i<rowCollection.length-(rowCollection.length<=pageSize||pageSize==-1?0:1);i++){
    
        /* condition "rowCollection[i].cells.length > 1" added by mike 06-29-2007 */
        if(rowCollection[i].cells.length > 1) {
        rowCollection[i].style.cursor=cursor;
        if(columnSelectorIndex!=-1){
            var chkObject=rowCollection[i].childNodes[columnSelectorIndex].childNodes[0];
            chkObject.onclick=
                function(){
                    var row=findParentRow(event.srcElement);
                    row.style.backgroundColor=(event.srcElement.checked?selectedColor:highlightBackgroundColor);
                }
        }
    
        rowCollection[i].onmouseover=
            function(){
                var row=findParentRow(event.srcElement);
                if(columnSelectorIndex!=-1&&row.childNodes[columnSelectorIndex].childNodes[0].checked)return;
                hBColor=row.style.backgroundColor;
                hFColor=row.style.color;
                row.style.backgroundColor=highlightBackgroundColor;
                row.style.color=highlightForeColor;
            };
            
        rowCollection[i].onmouseout=
            function(){
                var row=findParentRow(event.srcElement);
                if(columnSelectorIndex!=-1&&row.childNodes[columnSelectorIndex].childNodes[0].checked)return;
                row.style.backgroundColor=hBColor;
                row.style.color=hFColor;
            }
            
        rowCollection[i].onclick=clickFunction;
    }}
}

function getSelectedValuesPerColumn(gridViewId,columnSelectorIndex,columnValuesIndex,pageSize,delimeter){
    var rowCollection=redf_getElementById(gridViewId).childNodes[0].childNodes;
    var result = '';

    for(var i=1;i<rowCollection.length-(rowCollection.length - 1<=pageSize||pageSize==-1?0:1);i++){
        var chkObject=rowCollection[i].childNodes[columnSelectorIndex].childNodes[0];
        if(chkObject.checked){
            result+=(i!=1?delimeter:'')+rowCollection[i].childNodes[columnValuesIndex].innerText;
        }
    }

    return result;
}