function TableHandled ()
{
	this.objTable			= Object();

	document.selectedColColor	= "";
	document.overColColor		= "";
	document.defaultColColor	= "";

	this.init = function (idTable)
	{
		this.objTable			= document.getElementById(idTable);
		document.selectedColColor	= this.objTable.getAttribute("allowselectcol");
		document.multipleSelectedCell	= this.objTable.getAttribute("allowmultipleselectedcell");
		document.selectedCellColor	= this.objTable.getAttribute("allowselectcell");
		document.overColColor		= this.objTable.getAttribute("allowovercol");
		document.defaultColColor	= this.objTable.getAttribute("defaultcolor");
		document.overHeadColor		= this.objTable.getAttribute("allowoverheadcol");
		document.overFixColor		= this.objTable.getAttribute("allowoverfixcol");

		eval(this.objTable.onselectstart = function () {return false});
		eval(this.objTable.onmousedown = function () {return false});

		if (document.selectedColColor != "")
		{
			eval(this.objTable.onclick = function(e)
			{
				e = e || window.event;
				coords = getPointerPos(e);
				col = -1;
				for (var i = 0; i < this.rows.length; i++)
				{
					for (j = 0; j < this.rows[i].cells.length; j++)
					{
						cell	= this.rows[i].cells[j];
						pos	= findPos(cell);
						dim	= getDim(cell);
						if ( isIn(coords, pos, dim) )
							col = j;
						if (col != -1) break;
					}
					if (col != -1) break;
				}

				if (col > 0)
				{
					hiddenInput = document.getElementById(this.getAttribute("hiddeninput")+"["+col+"]");
					colSelected = this.rows[0].cells[col].getAttribute("selected");
					if ( (colSelected == "false") || (colSelected == '') || (!colSelected) )
					{
						this.rows[0].cells[col].setAttribute("selected","true");
						hiddenInput.value	= this.rows[0].cells[col].getAttribute("value");
						for (var i = 0; i < this.rows.length; i++)
							this.rows[i].cells[col].className += " " + document.selectedColColor;
					}
					else
					{
						this.rows[0].cells[col].setAttribute("selected","false");
						hiddenInput.value = "";
						for (var i = 0; i < this.rows.length; i++)
						{
							string = this.rows[i].cells[col].className;
							indexStr = string.indexOf(document.selectedColColor);
							if (indexStr > -1)
								string = string.substring(0, indexStr - 1);
							this.rows[i].cells[col].className = string;
						}
					}
				}
			});
		}

		if ( (document.multipleSelectedCell == "true") && (document.selectedCellColor != "") )
		{
			eval(this.objTable.onmouseup = function(e)
			{
				e = e || window.event;
				coords = getPointerPos(e);
				row = -1;
				col = -1;
				for (var i = 0; i < this.rows.length; i++)
				{
					for (j = 0; j < this.rows[i].cells.length; j++)
					{
						cell	= this.rows[i].cells[j];
						pos	= findPos(cell);
						dim	= getDim(cell);
						if ( isIn(coords, pos, dim) )
						{
							col = j;
							row = i;
							j = this.rows[i].cells.length;
						}
					}
					if (row > 0)
						i = this.rows.length;
				}

				if ( (row > -1) && (col > -1) )
				{
					selectedDay		= this.rows[row].cells[col].getAttribute("selected");
					hiddenInputIndex	= this.rows[row].cells[col].getAttribute("index");
					if ( (selectedDay == "false") || (selectedDay == "true") )
					{
						hiddenInput = document.getElementById(this.getAttribute("hiddeninput"));
						if ( (selectedDay == "false") )
						{
							this.rows[row].cells[col].setAttribute("selected","true");
							temp = hiddenInput.value.split(":");
							val = this.rows[row].cells[col].getAttribute("value");
							indexArray = isInArray(val, temp);
							if (indexArray == -1)
							{
								if(temp != "") { temp.push(val); } else { temp[0] = val; }
								hiddenInput.value = arrayToString(temp,":");
								this.rows[row].cells[col].className += " " + document.selectedCellColor;
							}
						}
						else
						{
							this.rows[row].cells[col].setAttribute("selected","false");
							temp = hiddenInput.value.split(":");
							val = this.rows[row].cells[col].getAttribute("value");
							indexArray = isInArray(val, temp);
							if (indexArray > -1)
								temp.splice(indexArray,1);
							hiddenInput.value = arrayToString(temp,":");
							string = this.rows[row].cells[col].className;
							indexStr = string.indexOf(document.selectedCellColor);
							if (indexStr > -1)
								string = string.substring(0, indexStr - 1);
							this.rows[row].cells[col].className = string;
						}
					}
				}
			});
		}

		if ( (document.multipleSelectedCell == "false") && (document.selectedCellColor != "") )
		{
			eval(this.objTable.onmouseup = function(e)
			{
				e = e || window.event;
				coords = getPointerPos(e);
				row = -1;
				col = -1;
				for (var i = 0; i < this.rows.length; i++)
				{
					for (j = 0; j < this.rows[i].cells.length; j++)
					{
						cell	= this.rows[i].cells[j];
						pos	= findPos(cell);
						dim	= getDim(cell);
						if ( isIn(coords, pos, dim) )
						{
							col = j;
							row = i;
							j = this.rows[i].cells.length;
						}
					}
					if (row > 0)
						i = this.rows.length;
				}

				if ( (row > -1) && (col > -1) )
				{
					msg = this.rows[row].cells[col].getAttribute("msg");
					if (msg != "")
						alert(msg);

					selectedDay		= this.rows[row].cells[col].getAttribute("selected");
					if ( (selectedDay == "false") || (selectedDay == "true") )
					{
						hiddenInput = document.getElementById(this.getAttribute("hiddeninput"));
						//find selected day to clean
						for (var i = 0; i < this.rows.length; i++)
						{
							for (j = 0; j < this.rows[i].cells.length; j++)
							{
								hiddenInput.value = "";
								string = this.rows[i].cells[j].className;
								indexStr = string.indexOf(document.selectedCellColor);
								if (indexStr > -1)
									string = string.substring(0, indexStr - 1);
								this.rows[i].cells[j].className = string;
								this.rows[i].cells[j].setAttribute("selected","false");
							}
						}

						if ( (selectedDay == "false") )
						{
							this.rows[row].cells[col].setAttribute("selected","true");
							hiddenInput.value = this.rows[row].cells[col].getAttribute("value");
							this.rows[row].cells[col].className += " " + document.selectedCellColor;
							
						}
						makeSubmit(hiddenInput.form.name);
					}
				}
			});
		}

		if ( (document.overColColor != "") && (document.overHeadColor == "") )
		{
			eval(this.objTable.onmouseover = function (e)
			{
				e = e || window.event;
				coords = getPointerPos(e);
				col = -1;
				for (var i = 0; i < this.rows.length; i++)
				{
					for (j = 0; j < this.rows[i].cells.length; j++)
					{
						cell = this.rows[i].cells[j];
						pos	= findPos(cell);
						dim	= getDim(cell);
						if ( isIn(coords, pos, dim) )
							col = j;
						if (this.rows[0].cells[j].getAttribute("selected") != "true")
						{
							string = this.rows[i].cells[j].className;
							indexStr = string.indexOf(document.overColColor);
							if (indexStr > -1)
								string = string.substring(0, indexStr - 1);
							this.rows[i].cells[j].className = string;
						}
					}
				}
	
				if (col > 0)
					for (var i = 0; i < this.rows.length; i++)
						if (this.rows[0].cells[col].getAttribute("selected") != "true")
							this.rows[i].cells[col].className += " " + document.overColColor;
	
			});
		}

		if ( (document.overHeadColor != "") && (document.overFixColor != "") )
		{
			eval(this.objTable.onmouseover = function (e)
			{
				e = e || window.event;
				coords = getPointerPos(e);
				col = -1;
				for (j = 0; j < this.rows[0].cells.length; j++)
				{
					cell = this.rows[0].cells[j];
					pos	= findPos(cell);
					dim	= getDim(cell);
					if ( isIn(coords, pos, dim) )
						col = j;

					for (i = 0; i < this.rows.length; i++)
					{
						if (this.rows[i].cells[j].getAttribute('selected') != 'true')
						{
							string = this.rows[i].cells[j].className;
							string = string.substring(0, string.indexOf(document.overHeadColor) - 1);
							this.rows[i].cells[j].className = string;
						}
					}
				}

				if (col > 0)
					for (i = 0; i < this.rows.length; i++)
						this.rows[i].cells[col].className += " " + document.overHeadColor;

				row = -1;
				for (i = 0; i < this.rows.length; i++)
				{
					cell = this.rows[i].cells[0];
					pos	= findPos(cell);
					dim	= getDim(cell);
					if ( isIn(coords, pos, dim) )
						row = i;

					
					string = this.rows[i].className;
					indexStr = string.indexOf(document.overFixColor);
					if (indexStr > -1)
						string = string.substring(0, indexStr - 1);
					this.rows[i].className = string;
				}
				if (row > 0)
					if ( (this.rows[row].cells[0].innerHTML != "&nbsp;") )
					{
						for (j = 0; j < this.rows[0].cells.length; j++)
							this.rows[row].cells[j].className += " " + document.overFixColor;
					}
	
			});
		}

	};

	this.selectAll = function (idTable)
	{
		this.objTable	= document.getElementById(idTable);
		for (j = 1; j < this.objTable.rows[0].cells.length; j++)
		{
			hiddenInput = document.getElementById(this.objTable.getAttribute("hiddeninput")+"["+j+"]");
			colSelected = this.objTable.rows[0].cells[j].getAttribute("selected");
			this.objTable.rows[0].cells[j].setAttribute("selected","true");
			hiddenInput.value = this.objTable.rows[0].cells[j].getAttribute("value");
			for (var i = 0; i < this.objTable.rows.length; i++)
				this.objTable.rows[i].cells[j].className += " " + document.selectedColColor;
		}
	};

	this.unselectAll = function (idTable)
	{
		this.objTable	= document.getElementById(idTable);
		for (j = 1; j < this.objTable.rows[0].cells.length; j++)
		{
			hiddenInput = document.getElementById(this.objTable.getAttribute("hiddeninput")+"["+j+"]");
			this.objTable.rows[0].cells[j].setAttribute("selected","false");
			hiddenInput.value = "";
			for (var i = 0; i < this.objTable.rows.length; i++)
			{
				string = this.objTable.rows[i].cells[j].className;
				indexStr = string.indexOf(document.selectedColColor);
				if (indexStr > -1)
					string = string.substring(0, indexStr - 1);
				this.objTable.rows[i].cells[j].className = string;
			}
		}

	};

	this.toggle = function (idTable)
	{
		this.objTable	= document.getElementById(idTable);
		numberOfSelected = 0;
		numberOfDays = this.objTable.rows[0].cells.length-1;
		for (j = 0; j < numberOfDays; j++)
		{
			if (this.objTable.rows[0].cells[j].getAttribute("selected") == "true")
				numberOfSelected++;
		}

		switch (numberOfSelected/(numberOfDays-1))
		{
			case 0:
			{
				this.selectAll(idTable);
			}
			break;
			case 1:
			{
				this.unselectAll(idTable);
			}
			break;
			default:
			{
				switch (Math.round(numberOfSelected/(numberOfDays-1)))
				{
					case 1:
					{
						this.selectAll(idTable);
					}
					break;
					case 0:
					{
						this.unselectAll(idTable);
					}
					break;
				}
			}
			break;
		}
	};

	this.selectAllRow = function (idTable, row)
	{
		this.objTable	= document.getElementById(idTable);
		for (j = 1; j < this.objTable.rows[row].cells.length; j++)
		{
			selectedDay		= this.objTable.rows[row].cells[j].getAttribute("selected");
			hiddenInputIndex	= this.objTable.rows[row].cells[j].getAttribute("index");
			if ( (selectedDay == "false") || (selectedDay == "true") )
			{
				hiddenInput = document.getElementById(this.objTable.getAttribute("hiddeninput"));
				this.objTable.rows[row].cells[j].setAttribute("selected","true");
				temp = hiddenInput.value.split(":");
				val = this.objTable.rows[row].cells[j].getAttribute("value");
				indexArray = isInArray(val, temp);
				if (indexArray == -1)
				{
					if(temp != "") temp.push(val);
					else temp[0] = val;
					hiddenInput.value = arrayToString(temp,":");
					this.objTable.rows[row].cells[j].className += " " + document.selectedCellColor;
				}
			}
// 			this.objTable.rows[row].cells[j].setStyle('background',document.selectedCellColor);
		}
	};

	this.unselectAllRow = function (idTable, row)
	{
		this.objTable	= document.getElementById(idTable);
		for (j = 1; j < this.objTable.rows[row].cells.length; j++)
		{
			selectedDay		= this.objTable.rows[row].cells[j].getAttribute("selected");
			hiddenInputIndex	= this.objTable.rows[row].cells[j].getAttribute("index");
			if ( (selectedDay == "false") || (selectedDay == "true") )
			{
				hiddenInput = document.getElementById(this.objTable.getAttribute("hiddeninput"));
				this.objTable.rows[row].cells[j].setAttribute("selected","false");
				temp = hiddenInput.value.split(":");
				val = this.objTable.rows[row].cells[j].getAttribute("value");
				indexArray = isInArray(val, temp);
				if (indexArray > -1)
					temp.splice(indexArray,1);
				hiddenInput.value = arrayToString(temp,":");

				string = this.objTable.rows[row].cells[j].className;
				indexStr = string.indexOf(document.selectedCellColor);
				if (indexStr > -1)
					string = string.substring(0, indexStr - 1);
				this.objTable.rows[row].cells[j].className = string;
			}
// 			this.objTable.rows[row].cells[j].setStyle('background','');
		}

	};

	this.toggleRow = function (idTable)
	{
		this.objTable	= document.getElementById(idTable);

		row = -1;
		for (var i = 0; i < this.objTable.rows.length; i++)
		{
			cell	= this.objTable.rows[i].cells[0];
			pos	= findPos(cell);
			dim	= getDim(cell);
			if ( isIn(coords, pos, dim) )
				row = i;
		}
	
		if (row > 0)
		{
			numberOfAllowSelect	= 0;
			numberOfSelected	= 0;
			numberOfcols		= this.objTable.rows[row].cells.length - 1;
			for (j = 0; j < numberOfcols; j++)
			{
				selectedCol = this.objTable.rows[row].cells[j].getAttribute("selected");
				if ( (selectedCol == "true") || (selectedCol == "false") )
					numberOfAllowSelect++;

				if (this.objTable.rows[row].cells[j].getAttribute("selected") == "true")
					numberOfSelected++;
			}

			switch (numberOfSelected/(numberOfAllowSelect))
			{
				case 0:
				{
					this.selectAllRow(idTable, row);
				}
				break;
				case 1:
				{
					this.unselectAllRow(idTable, row);
				}
				break;
				default:
				{
					switch (Math.round(numberOfSelected/(numberOfAllowSelect)))
					{
						case 1:
						{
							this.unselectAllRow(idTable, row);
						}
						break;
						case 0:
						{
							this.selectAllRow(idTable, row);
						}
						break;
					}
				}
				break;
			}
		}

	};

	this.selectAllCol = function (idTable, col)
	{
		this.objTable	= document.getElementById(idTable);
		for (i = 1; i < this.objTable.rows.length; i++)
		{
			selectedDay		= this.objTable.rows[i].cells[col].getAttribute("selected");
			if ( (selectedDay == "false") || (selectedDay == "true") )
			{
				hiddenInput = document.getElementById(this.objTable.getAttribute("hiddeninput"));
				this.objTable.rows[i].cells[col].setAttribute("selected","true");
				temp = hiddenInput.value.split(":");
				val = this.objTable.rows[i].cells[col].getAttribute("value");
				indexArray = isInArray(val, temp);
				if (indexArray == -1)
				{
					if(temp != "") temp.push(val);
					else temp[0] = val;
					hiddenInput.value = arrayToString(temp,":");
					this.objTable.rows[i].cells[col].className += " " + document.selectedCellColor;
				}
			}
// 			this.objTable.rows[i].cells[col].setStyle('background',document.selectedCellColor);
		}
	};

	this.unselectAllCol = function (idTable, col)
	{
		this.objTable	= document.getElementById(idTable);
		for (i = 1; i < this.objTable.rows.length; i++)
		{
			selectedDay		= this.objTable.rows[i].cells[col].getAttribute("selected");
			if ( (selectedDay == "false") || (selectedDay == "true") )
			{
				hiddenInput = document.getElementById(this.objTable.getAttribute("hiddeninput"));
				this.objTable.rows[i].cells[col].setAttribute("selected","false");
				temp = hiddenInput.value.split(":");
				val = this.objTable.rows[i].cells[col].getAttribute("value");
				indexArray = isInArray(val, temp);
				if (indexArray > -1)
					temp.splice(indexArray,1);
				hiddenInput.value = arrayToString(temp,":");

				string = this.objTable.rows[i].cells[col].className;
				indexStr = string.indexOf(document.selectedCellColor);
				if (indexStr > -1)
					string = string.substring(0, indexStr - 1);
				this.objTable.rows[i].cells[col].className = string;
			}
// 			this.objTable.rows[i].cells[col].setStyle('background','');
		}

	};

	this.toggleCol = function (idTable)
	{
		this.objTable	= document.getElementById(idTable);

		col = -1;
		for (var j = 0; j < this.objTable.rows[0].cells.length; j++)
		{
			cell	= this.objTable.rows[0].cells[j];
			pos	= findPos(cell);
			dim	= getDim(cell);
			if ( isIn(coords, pos, dim) )
			{
				col = j;
				j = this.objTable.rows[0].cells.length;
			}
		}
	
		if (col > 0)
		{
			numberOfAllowSelect	= 0;
			numberOfSelected	= 0;
			numberOfrows		= this.objTable.rows.length - 1;
			for (i = 0; i < numberOfrows; i++)
			{
				selectedCol = this.objTable.rows[i].cells[col].getAttribute("selected");
				if ( (selectedCol == "true") || (selectedCol == "false") )
					numberOfAllowSelect++;

				if (this.objTable.rows[i].cells[col].getAttribute("selected") == "true")
					numberOfSelected++;
			}

			switch (numberOfSelected/numberOfAllowSelect)
			{
				case 0:
				{
					this.selectAllCol(idTable, col);
				}
				break;
				case 1:
				{
					this.unselectAllCol(idTable, col);
				}
				break;
				default:
				{
					switch (Math.round(numberOfSelected/(numberOfAllowSelect)))
					{
						case 1:
						{
							this.unselectAllCol(idTable, col);
						}
						break;
						case 0:
						{
							this.selectAllCol(idTable, col);
						}
						break;
					}
				}
				break;
			}

		}

	};

}

tableHandled = new TableHandled();
