var pointer_row = -1;
var pointer_color = '';

function setPointer(theRow, theRowNum, theAction, theDefaultColor, thePointerColor, theMarkColor){
    var theCells = null;
    var box = null;
    
    //document.getElementById('divdiv').innerHTML += theAction+'<br />';
    //Pointer and mark feature are disabled or the browser can't get the
    //    row -> exits
    if ((thePointerColor == '' && theMarkColor == '')
        || typeof(theRow.style) == 'undefined') {
        return false;
    }

    //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;
    }

    //Gets the current color...
    var rowCellsCnt  = theCells.length;
    var domDetect    = null;
    var currentColor = null;
    var newColor     = null;
    //... 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;
    }
    //... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    }

	//... Opera changes colors set via HTML to rgb(r,g,b) format so fix it
    if (currentColor.indexOf("rgb") >= 0)
    {
        var rgbStr = currentColor.slice(currentColor.indexOf('(') + 1,
                                     currentColor.indexOf(')'));
        var rgbValues = rgbStr.split(",");
        currentColor = "#";
        var hexChars = "0123456789ABCDEF";
        for (var i = 0; i < 3; i++)
        {
            var v = rgbValues[i].valueOf();
            currentColor += hexChars.charAt(v/16) + hexChars.charAt(v%16);
        }
    }

    //Defines the new color
    //Current color is the default one
    if (currentColor == '' || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor              = thePointerColor;
        } else if (theAction == 'click' && theMarkColor != '') {
            setOldColor(domDetect);
            newColor              = theMarkColor;
            pointer_row = theRowNum;
			pointer_color = theDefaultColor;

            //document.grid.opt[theRowNum -1].checked = true;
        }
    }

    //Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor              = theDefaultColor;
        } else if (theAction == 'click' && theMarkColor != '') {
            setOldColor(domDetect);
            newColor              = theMarkColor;
            pointer_row = theRowNum;
			pointer_color = theDefaultColor;

        }
    }

    //Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
			newColor              = thePointerColor;
            pointer_row = -1;
			pointer_color = '';
			if (document.getElementById('adminbox')){
				box = document.getElementById('adminbox');
				box.style.visibility = "hidden";
			}
			
			if (document.getElementById('buttonAccept')){
				box = document.getElementById('buttonAccept');
				box.style.visibility = "hidden";
			}
        }
    }

    //Sets the new color...
    if (newColor) {
        var c = null;
        //... with DOM compatible browsers except Opera
        if (domDetect) {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].setAttribute('bgcolor', newColor, 0);
            } // end for
        }
        //... with other browsers
        else {
            for (c = 0; c < rowCellsCnt; c++) {
                theCells[c].style.backgroundColor = newColor;
            }
        }
    }
   	
    return true;
}


function setOldColor(domDetect){
    var theCells2 = null;

    if (pointer_row != -1){
       newColor2 = pointer_color;
       theRow2 = document.getElementById('row'+pointer_row);

	   //Gets the current row and exits if the browser can't get it
	   if (typeof(document.getElementsByTagName) != 'undefined') {
	   	  theCells2 = theRow2.getElementsByTagName('td');
	   } else if (typeof(theRow2.cells) != 'undefined') {
	      theCells2 = theRow2.cells;
	   } else { return false; }

	   //Sets the new color...
	   if (newColor2) {
	        var d = null;
	        //... with DOM compatible browsers except Opera
	        if (domDetect) {
	            for (d = 0; d < theCells2.length; d++) {
	                theCells2[d].setAttribute('bgcolor', newColor2, 0);
	            } // end for
	        }
	        //... with other browsers
	        else {
	            for (d = 0; d < theCells2.length; d++) {
	                theCells2[d].style.backgroundColor = newColor2;
	            }
	        }
	    }
     }
}
function setCheckboxesRange(the_form, do_check, basename){
    if (typeof(document.forms[the_form].elements[basename]) != 'undefined') {
    	for(var i = 0; i < document.forms[the_form].elements[basename].length; i++)
        document.forms[the_form].elements[basename][i].checked = do_check;
    }
    return true;
} 

