
var marked_row = new Array;


/**
 * Sets/unsets the pointer and marker in browse mode
 *
 * @param   object    the table row
 * @param   interger  the row number
 * @param   string    the action calling this script (over, out or click)
 * @param   string    the default background color
 * @param   string    the color to use for mouseover
 * @param   string    the color to use for marking a row
 *
 * @return  boolean  whether pointer is set or not
 */
function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = new Array;

    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {

        theCells = theRow.getElementsByTagName('td');
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    // 3.1 ... with DOM compatible browsers except Opera that does not return
    //         valid values with "getAttribute"
    if (typeof(window.opera) == 'undefined'
        && typeof(theCells[0].getAttribute) != 'undefined') {
        currentColor = theCells[0].getAttribute('bgcolor');
        domDetect    = true;
    //    window.alert("aaa - "+typeof(currentColor));
    }
    // 3.2 ... with other browsers
    else {

        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3
    
    
    
    if ( typeof(currentColor) == 'string' ) {
    //window.alert("33");
    currentColor = currentColor.toLowerCase()
    }
    else {
    //window.alert("44");
    currentColor = '';
    }
    
    
    
    //window.alert(currentColor+', '+currentColor+', '+theDefaultColor);
    var is_chrome = /Chrome/.test( navigator.userAgent );
    //window.alert("aaa - "+typeof(currentColor));
    if ( is_chrome ) {
    //window.alert("11");
    if ( typeof(currentColor) == 'string' ) {
    //window.alert("33");
    currentColor = currentColor.toLowerCase()
    }
    else {
    //window.alert("44");
    currentColor = '';
    }

    if ( typeof(currentColor) == 'string' ) {
    theDefaultColor = theDefaultColor.toLowerCase()
    }
    else {
    currentColor = '';
    }
    if ( typeof(thePointerColor) == 'string' ) {
    thePointerColor = thePointerColor.toLowerCase()
    }
    else {
    thePointerColor = '';
    }
    if ( typeof(theMarkColor) == 'string' ) {
    theMarkColor = theMarkColor.toLowerCase()
    }
    else {
    theMarkColor = '';
    }
    }
    else {
    //window.alert("22");
    currentColor = currentColor.toLowerCase();
    theDefaultColor = theDefaultColor.toLowerCase();
    thePointerColor = thePointerColor.toLowerCase();
    theMarkColor = theMarkColor.toLowerCase();
    }
    
    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor == theDefaultColor) {
        //window.alert('1');
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor == thePointerColor
             && (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])) {
             //window.alert('2');
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor              = theMarkColor;
            marked_row[theRowNum] = true;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor == theMarkColor) {
    //window.alert('3');
        if (theAction == 'click') {
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
            marked_row[theRowNum] = (typeof(marked_row[theRowNum]) == 'undefined' || !marked_row[theRowNum])
                                  ? true
                                  : null;
        }
    } // end 4

    // 5. Sets the new color...
    if (newColor) {
        var c = null;
        // 5.1 ... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        // 5.2 ... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    } // end 5

    return true;
} // end of the 'setPointer()' function




var marked_cell = new Array;
function setPointerCal(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;
    var theCheck = null;
    //window.alert(thePointerColor);
    // 1. Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    // 2. Gets the current row and exits if the browser can't get it
    if (typeof(document.getElementsByTagName) != 'undefined') {
        //theCells = document.getElementById(theRowNum);
        theCells = document.getElementsByName(theRowNum);
        theCheck = theRow.getElementsByTagName('INPUT');
        //marked_cell[theRowNum] = theCheck[0].getAttribute('value');
        //window.alert(theCheck[0].getAttribute('value'));
        //window.alert(marked_cell[theRowNum]);
        
        //theRow.style.backgroundColor = 'yellow';
        //theRow.setAttribute('bgcolor', 'yellow', 0);
        //theCells[0].setAttribute('bgcolor', '#ffff00');
        //window.alert(theCells[0].getAttribute('bgcolor'));
    }
    else if (typeof(theRow.cells) != 'undefined') {
        theCells = theRow.cells;
    }
    else {
        return false;
    }

    // 3. Gets the current color...
    //var rowCellsCnt  = theCells.length;
    //var domDetect    = null;
    var currentColor = null;
    var newColor     = null;

        //window.alert("c - "+theCells.length);
        //currentColor = theCells.style.backgroundColor;
        //currentColor = theCells[0].getAttribute('bgcolor');
        currentColor = theCells[0].style.backgroundColor;
        //window.alert("theAction: "+theAction+", a - "+currentColor);
        if ( theCheck[0].getAttribute('value') == 'true' ) {
        //window.alert("aaaaaaa");
        currentColor = theMarkColor;
        marked_cell[theRowNum] = true;
        }
        //window.alert("theAction: "+theAction+", a - "+currentColor);
        //window.alert("b - "+currentColor);
     // end 3
     
     
     
    if ( typeof(currentColor) == 'string' ) {
    //window.alert("33");
    currentColor = currentColor.toLowerCase()
    }
    else {
    //window.alert("44");
    currentColor = '';
    }
     
     
     
    var is_chrome = /Chrome/.test( navigator.userAgent );
    var is_mozilla = false;
    if ( /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent ) ) {
        var is_mozilla = true;
    }

    //window.alert("aaa - "+typeof(currentColor));
    if ( is_chrome || is_mozilla ) {
    //window.alert("11");

    currentColor = RGBtoHEX(currentColor);
    //window.alert("hex "+currentColor);
    if ( currentColor=="00" ) {
     currentColor='';
    }
    //window.alert("aaa - "+typeof(currentColor));
    //window.alert("bbb - "+typeof(currentColor)+" -- "+currentColor);
    if ( typeof(currentColor) == 'string' ) {
    //window.alert("33");
    currentColor = currentColor.toLowerCase()
    }
    else {
    window.alert("44");
    currentColor = '';
    }

    if ( typeof(currentColor) == 'string' ) {
    theDefaultColor = theDefaultColor.toLowerCase()
    }
    else {
    theDefaultColor = '';
    }
    if ( typeof(thePointerColor) == 'string' ) {
    thePointerColor = thePointerColor.toLowerCase()
    }
    else {
    thePointerColor = '';
    }
    if ( typeof(theMarkColor) == 'string' ) {
    theMarkColor = theMarkColor.toLowerCase()
    }
    else {
    theMarkColor = '';
    }
    }
    else {
    //window.alert("22");
    currentColor = currentColor.toLowerCase();
    theDefaultColor = theDefaultColor.toLowerCase();
    thePointerColor = thePointerColor.toLowerCase();
    theMarkColor = theMarkColor.toLowerCase();
    }
    //window.alert("theAction: "+theAction+", currentColor: "+currentColor+", theDefaultColor: "+theDefaultColor+", thePointerColor: "+thePointerColor+", theMarkColor: "+theMarkColor);


    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor == theDefaultColor) {
        //window.alert("1");
        if (theAction == 'over' && thePointerColor != '') {
        //window.alert("1a");
            newColor              = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            //window.alert("1b");
            //window.alert(changeCheck);
            FormChange(changeCheck);
            newColor              = theMarkColor;
            marked_cell[theRowNum] = true;

            if ( theCheck[0].getAttribute('value') == 'true' ) {
                //window.alert("1c");
                theCheck[0].value = null;
            }
            else {
                //window.alert("1d");
                theCheck[0].value = true;
            }

        }

    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor == thePointerColor
             && (typeof(marked_cell[theRowNum]) == 'undefined' || !marked_cell[theRowNum] )) {
        //window.alert("2");
        //window.alert(theAction);
        if (theAction == 'out' || theAction == 'over') {
            //window.alert("2a");
            newColor              = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
        //window.alert("2c");
        //window.alert(changeCheck);
            FormChange(changeCheck);
            newColor              = theMarkColor;
            marked_cell[theRowNum] = true;
            if ( theCheck[0].getAttribute('value') == 'true' ) {
            //window.alert("2d");
                theCheck[0].value = null;
            }
            else {
            //window.alert("2e");
                theCheck[0].value = true;
            }
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor == theMarkColor) {
    //window.alert("3");
    //window.alert(theAction);
        if (theAction == 'click') {
        //window.alert("3a");

//window.alert(theCheck[0].getAttribute('value'));
            newColor              = (thePointerColor != '')
                                  ? thePointerColor
                                  : theDefaultColor;
        //window.alert("theAction: "+theAction+", currentColor: "+currentColor+", theDefaultColor: "+theDefaultColor+", thePointerColor: "+thePointerColor+", theMarkColor: "+theMarkColor+", newcolor: "+newColor);

            marked_cell[theRowNum] = (typeof(marked_cell[theRowNum]) == 'undefined' || !marked_cell[theRowNum])
                                  ? true
                                  : null;
            if ( theCheck[0].getAttribute('value') == 'true' ) {
            //window.alert("3b");
                theCheck[0].value = null;
                //window.alert(theCheck[0].getAttribute('value'));
            }
            else {
            //window.alert("3c");
                theCheck[0].value = true;

            }

        }
        //window.alert(newColor);
    } // end 4


    
    // 5. Sets the new color...
    if (newColor) {
    //window.alert("5 - "+newColor);
                //theCells.style.backgroundColor = newColor;
                //theCells[0].setAttribute('bgcolor', newColor, 0);
                theCells[0].style.backgroundColor = newColor;
    } // end 5

    return true;
} // end of the 'setPointer()' marked_cell


function FormChangeAllert(txtAlert)
{
//window.alert(formName);
    if ( formChanged ) {
    //window.alert('a2');
        okno=window.confirm(txtAlert);
        if (okno)
        {
        //window.alert('a3');
        theForm = document.getElementById(formName);
        theForm.submit();
            //document.mch_upravit.submit();
        }
    }
} // end of the 'FormChangeAllert()' function


function FormChange(num)
{
//window.alert(formName);
    if ( num==1 ) {
        //window.alert('a2');
        formChanged = false;
    }
    else
    {
        formChanged = true;
    }
} // end of the 'FormChange()' function

function RGBtoHEX(str)
{
if ( str!='' && str.length>7 ) {
 //window.alert(str);
 var arr = str.split(",");
 var r = arr[0].substring(4),
 g = arr[1],
 b = arr[2].substring(0,arr[2].length-1);
 r = parseInt(r);
 g = parseInt(g);
 b = parseInt(b);
 //window.alert(r +'---'+ g +'---'+ b);
        colstr = "#" + r.toString(16) + "0"
       colstr = colstr.substr(0,3)
       colstr += (g.toString(16) + "0" )
       colstr = colstr.substr(0,5)
       colstr += (b.toString(16) + "0")
       colstr = colstr.substr(0,7)
 //return "#"+r+g+b;
 return colstr;
}
else {
    return str;
//window.alert('null str');
}
}

function bublinka (bubel,showit )
{
    emel=bubel.getElementsByTagName('div');
    if ( showit==1 ) {
        emel[0].style.display='block';
    }
    else {
        emel[0].style.display='none';
    }
}
