var defColor;
var blokujMenu;
function setPointer(theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
    var theCells = null;

    // 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;
    }
    alert("ok"); 
    // 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;
    }
    // 3.2 ... with other browsers
    else {
        currentColor = theCells[0].style.backgroundColor;
        domDetect    = false;
    } // end 3

    // 4. Defines the new color
    // 4.1 Current color is the default one
    if (currentColor == ''
        || currentColor.toLowerCase() == theDefaultColor.toLowerCase()) {
        if (theAction == 'over' && thePointerColor != '') {
            newColor = thePointerColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.2 Current color is the pointer one
    else if (currentColor.toLowerCase() == thePointerColor.toLowerCase()) {
        if (theAction == 'out') {
            newColor = theDefaultColor;
        }
        else if (theAction == 'click' && theMarkColor != '') {
            newColor = theMarkColor;
        }
    }
    // 4.1.3 Current color is the marker one
    else if (currentColor.toLowerCase() == theMarkColor.toLowerCase()) {
        if (theAction == 'click') {
            newColor = (thePointerColor != '')
                     ? thePointerColor
                     : theDefaultColor;
        }
    } // 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

function clearMarkedPionter(tableName, theRow, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
  var ts;
  var tabela = null;
  var c = null;
  var r = null;
  var i = null;
	var idWiersz = null;
    if (typeof(document.getElementsByTagName) != 'undefined') {
      ts = document.getElementsByTagName('table');
    }
    else {
        return false;
    }
    for (i = 0; i < ts.length; i++) {
		  if (tableName == ts[i].name){
			  tabela = ts[i];
			} 
		}
    if (tabela == null) {
        return false;
    }
    for (i = 0; i < tabela.rows.length; i++) {
		  if (theRow == tabela.rows[i]){
			  idWiersz = i;
			} 
		}
    if (idWiersz == null) {
        return false;
    }
    if (theAction == 'out') {
			for (c = 0; c < tabela.rows[idWiersz].cells.length; c++) {
        if (tabela.rows[idWiersz].cells[c].style.backgroundColor.toLowerCase() != theMarkColor.toLowerCase()){
  				tabela.rows[idWiersz].cells[c].style.backgroundColor = theDefaultColor;
				}
      } // end for
		  return true;
		} else if (theAction == 'over') {
      for (c = 0; c < tabela.rows[idWiersz].cells.length; c++) {
        if (tabela.rows[idWiersz].cells[c].style.backgroundColor.toLowerCase() != theMarkColor.toLowerCase()){
          tabela.rows[idWiersz].cells[c].style.backgroundColor = thePointerColor;
				}
      } // end for
		  return true;
		} else if (theAction == 'click') {
      for (r = 0; r < tabela.rows.length; r++) {
        for (c = 0; c < tabela.rows[r].cells.length; c++) {
          tabela.rows[r].cells[c].style.backgroundColor = theDefaultColor;
        } // end for
      } // end for
      for (c = 0; c < tabela.rows[idWiersz].cells.length; c++) {
        tabela.rows[idWiersz].cells[c].style.backgroundColor = theMarkColor;
      } // end for
		  return true;
		};
	return false;
}


function setRowColor(tableName, idWiersz, theDefaultColor)
{
  var ts;
  var tabela = null;
  var c = null;
  var i = null;
    if (typeof(document.getElementsByTagName) != 'undefined') {
      ts = document.getElementsByTagName('table');
    }
    else {
        return false;
    }
    for (i = 0; i < ts.length; i++) {
		  if (tableName == ts[i].name){
			  tabela = ts[i];
			} 
		}
    if (tabela == null) {
        return false;
    }
//		alert(idWiersz);
    if (idWiersz == null) {
        return false;
    }
		for (c = 0; c < tabela.rows[idWiersz].cells.length; c++) {
 				tabela.rows[idWiersz].cells[c].style.backgroundColor = theDefaultColor;
    } // end for
	  return true;
}

function clearMarkedPionterCell(tableName, idWiersz, idKolumna, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
  var ts;
  var tabela = null;
  var c = null;
  var r = null;
  var i = null;
 // alert(document.getElementById(tableName) + "," + document.getElementsByTagName('table')); 
  if (blokujMenu) {return false;}
  if (theDefaultColor == '') {
    theDefaultColor = defColor;
  } 
  	if (document.getElementById(tableName))  {
      tabela = document.getElementById(tableName);
    } else {
	  if (typeof(document.getElementsByTagName) != 'undefined') {
        ts = document.getElementsByTagName('table');
       // alert(tabela + "," + idWiersz);
        for (i = 0; i < ts.length; i++) {
	      if (tableName == ts[i].name)  tabela = ts[i];
		} 
	  }
    }
    if (tabela == null) {
        return false;
    }
    if (idWiersz == null) {
        return false;
    }

    if (theAction == 'out') {
      if (tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor.toLowerCase() != theMarkColor.toLowerCase()){
		tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor = theDefaultColor;
        tabela.rows[idWiersz].cells[idKolumna].style.borderStyle = "none none none none";
  	  }
	  return true;
	}else if (theAction == 'over') {
      if (tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor.toLowerCase() != theMarkColor.toLowerCase()){
        for (r = 0; r < tabela.rows.length; r++) {
          for (c = 0; c < tabela.rows[r].cells.length; c++) {
            tabela.rows[r].cells[c].style.backgroundColor = theDefaultColor;
            tabela.rows[r].cells[c].style.borderStyle = "none none none none";
          } // end for
        } // end for
        tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor = thePointerColor;
        tabela.rows[idWiersz].cells[idKolumna].style.borderColor = "black black black black";
        tabela.rows[idWiersz].cells[idKolumna].style.borderStyle = "solid solid solid solid";
        tabela.rows[idWiersz].cells[idKolumna].style.borderWidth = "1px 1px 1px 1px";
	  }
	  return true;
	}else if (theAction == 'click') {
      for (r = 0; r < tabela.rows.length; r++) {
        for (c = 0; c < tabela.rows[r].cells.length; c++) {
          tabela.rows[r].cells[c].style.backgroundColor = theDefaultColor;
          tabela.rows[r].cells[c].style.borderStyle = "none none none none";
        } // end for
      } // end for
      tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor = theMarkColor;
      tabela.rows[idWiersz].cells[idKolumna].style.borderColor = "black black black black";
      tabela.rows[idWiersz].cells[idKolumna].style.borderStyle = "solid solid solid solid";
      tabela.rows[idWiersz].cells[idKolumna].style.borderWidth = "1px 1px 1px 1px";
	  return true;
	};
	return false;
}
function clearMarkedPionterRow(tableName, idWiersz, idKolumna, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
  var ts;
  var tabela = null;
  var c = null;
  var r = null;
  var i = null;
 // alert(document.getElementById(tableName) + "," + document.getElementsByTagName('table')); 
  if (blokujMenu) {return false;}
  if (theDefaultColor == '') {
    theDefaultColor = defColor;
  } 
  	if (document.getElementById(tableName))  {
      tabela = document.getElementById(tableName);
    } else {
	  if (typeof(document.getElementsByTagName) != 'undefined') {
        ts = document.getElementsByTagName('table');
        //alert(tabela + "," + idWiersz);
        for (i = 0; i < ts.length; i++) {
	      if (tableName == ts[i].name)  tabela = ts[i];
		} 
	  }
    }
    if (tabela == null) {
        return false;
    }
    if (idWiersz == null) {
        return false;
    }

    if (theAction == 'out') {
//      if (tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor.toLowerCase() != theMarkColor.toLowerCase()){
        for (c = 0; c < tabela.rows[idWiersz].cells.length; c++) {
          tabela.rows[idWiersz].cells[c].style.backgroundColor = theDefaultColor;
          tabela.rows[idWiersz].cells[c].style.borderStyle = "none none none none";
        } // end for
//  	  }
	  return true;
	}else if (theAction == 'over') {
//      if (tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor.toLowerCase() != theMarkColor.toLowerCase()){
        for (r = 0; r < tabela.rows.length; r++) {
          for (c = 0; c < tabela.rows[r].cells.length; c++) {
            tabela.rows[r].cells[c].style.backgroundColor = theDefaultColor;
            tabela.rows[r].cells[c].style.borderStyle = "none none none none";
//            tabela.rows[r].cells[c].style.borderTopColor = theDefaultColor;
//            tabela.rows[r].cells[c].style.borderRightColor = theDefaultColor;
//            tabela.rows[r].cells[c].style.borderBottomColor = theDefaultColor;
//            tabela.rows[r].cells[c].style.borderLeftColor = theDefaultColor;
          } // end for
        } // end for
		
        for (c = 0; c < tabela.rows[idWiersz].cells.length; c++) {
          tabela.rows[idWiersz].cells[c].style.backgroundColor = thePointerColor;
          tabela.rows[idWiersz].cells[c].style.borderColor = "black black black black";
          tabela.rows[idWiersz].cells[c].style.borderStyle = "solid none solid none";
          tabela.rows[idWiersz].cells[c].style.borderWidth = "1px 1px 1px 1px";
        } // end for
        tabela.rows[idWiersz].cells[0].style.borderLeftStyle = "solid";
        tabela.rows[idWiersz].cells[c - 1].style.borderRightStyle = "solid";
      return true;
	}else if (theAction == 'click') {
      for (r = 0; r < tabela.rows.length; r++) {
        for (c = 0; c < tabela.rows[r].cells.length; c++) {
          tabela.rows[r].cells[c].style.backgroundColor = theDefaultColor;
          tabela.rows[r].cells[c].style.borderStyle = "none none none none";
        } // end for
      } // end for
      for (c = 0; c < tabela.rows[idWiersz].cells.length; c++) {
        tabela.rows[idWiersz].cells[c].style.backgroundColor = theMarkColor;
        tabela.rows[idWiersz].cells[c].style.borderColor = "black black black black";
        tabela.rows[idWiersz].cells[c].style.borderStyle = "solid none solid none";
        tabela.rows[idWiersz].cells[c].style.borderWidth = "1px 1px 1px 1px";
      } // end for
      tabela.rows[idWiersz].cells[0].style.borderLeftStyle = "solid";
      tabela.rows[idWiersz].cells[c - 1].style.borderRightStyle = "solid";
	  return true;
	};
	return false;
}
function clearMarkedPionterCellSingel(tableName, idWiersz, idKolumna, theAction, theDefaultColor, thePointerColor, theMarkColor)
{
  var ts;
  var tabela = null;
  var c = null;
  var r = null;
  var i = null;
  if (blokujMenu) {return false;}
  if (theDefaultColor == '') {
    theDefaultColor = defColor;
  }
  	if (document.getElementById(tableName))  {
      tabela = document.getElementById(tableName);
    } else {
	  if (typeof(document.getElementsByTagName) != 'undefined') {
        ts = document.getElementsByTagName('table');
        //alert(tabela + "," + idWiersz);
        for (i = 0; i < ts.length; i++) {
	      if (tableName == ts[i].name)  tabela = ts[i];
		} 
	  }
    }
    if (tabela == null) {
        return false;
    }
    if (idWiersz == null) {
        return false;
    }

    if (theAction == 'out') {
  	tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor = theDefaultColor;
	  return true;
		}else if (theAction == 'over') {
      tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor = thePointerColor;
		  return true;
		}else if (theAction == 'click') {
      for (r = 0; r < tabela.rows.length; r++) {
        for (c = 0; c < tabela.rows[r].cells.length; c++) {
          tabela.rows[r].cells[c].style.backgroundColor = theDefaultColor;
        } // end for
      } // end for
        tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor = theMarkColor;
		  return true;
		};
	return false;
}

function getDefColor(tableName, idWiersz, idKolumna)
{
  var ts;
  var tabela = null;
  var c = null;
  var r = null;
  var i = null;
  	if (document.getElementById(tableName))  {
      tabela = document.getElementById(tableName);
    } else {
	  if (typeof(document.getElementsByTagName) != 'undefined') {
        ts = document.getElementsByTagName('table');
        //alert(tabela + "," + idWiersz);
        for (i = 0; i < ts.length; i++) {
	      if (tableName == ts[i].name)  tabela = ts[i];
		} 
	  }
    }
    if (tabela == null) {
        return false;
    }
    if (idWiersz == null) {
        return false;
    }
	defColor = tabela.rows[idWiersz].cells[idKolumna].style.backgroundColor;
	return true;
}

