EVENT_HANDLING['TIMETABLE'] = true;
var DIV_MAIN_TIMETABLE = null;
var imw_tim_dat = null;
var imw_tim_int = null;
var imw_tim_locked = null;

function imw_tim_init_static(p_time, d_time, d_container, intervall)
{
	document.getElementById(p_time).value = "12:00";
	document.getElementById(d_time).value = "12:00";
	
	imw_tim_init(d_container, intervall);
}

function imw_tim_init(d_container, intervall)
{
	if (!document.getElementById(d_container))
		return false;
	
	imw_tim_int = intervall;
	
	DIV_MAIN_TIMETABLE = document.getElementById(d_container);
	DIV_MAIN_TIMETABLE.scrollTop = 0;
}

function imw_tim_open(d_time, e_container, px, py)
{
	if (DIV_MAIN_TIMETABLE)
	{
		imw_tim_close();
	}
	
	imw_tim_init(e_container, 30);
	
	if (!imw_tim_int)
		return false;
	
	if (document.getElementById(d_time) != imw_tim_dat)
	{
		imw_tim_dat = document.getElementById(d_time);
		
		var str_timetable = "";
		
		var k = 0;
		
		for (i = 0; i < 24; i++)
		{
			j = 0;
			while (j < 60)
			{
				var row = (i < 10 ? "0" + i : i) + ":" + (j < 10 ? "0" + j : j);
				str_timetable += "<a href=\"\" id=\"" + d_time + "imw_tim_" + k + "\" onClick=\"imw_tim_set('" + row + "'); return false;\">" + row + "</a>";
				j += imw_tim_int;
				k++;
			}
		}
		
		DIV_MAIN_TIMETABLE.innerHTML = str_timetable;
		
		DIV_MAIN_TIMETABLE.style.visibility = 'visible';
		DIV_MAIN_TIMETABLE.style.display 	= 'block';
		
		if (!BROWSER_CURRENT['msie'])
		{
			if (imw_div_pg_type == 'R')
			{
				if (BROWSER_CURRENT['firefox'])
				{
					py = parseInt(py) + 1;
				}
			} else {
				if (!BROWSER_CURRENT['opera'])
				{
					px -= 2;
				}
				py -= 3;
			}
		}
		
		// DIV_MAIN_TIMETABLE.style.left = ( parseInt(px) + parseInt(imw_div_offset_x) ) + "px";
		// DIV_MAIN_TIMETABLE.style.top  = ( parseInt(py) + parseInt(imw_div_offset_y) ) + "px";
		
		temp_a = imw_tim_dat.value.split(':');
		
		t_hour = temp_a[0];
		
		if (t_hour.length == 2 && t_hour.substr(0,1) == "0")
		{
			t_hour = t_hour.substr(1,1);
		}
		
		temp_v = parseInt(t_hour) * (60 / imw_tim_int) + parseInt(temp_a[1]) / imw_tim_int; // 30 , 15 
		
		// alert(imw_tim_dat.value);
		
		/* Ausgewähltes Element markieren */
		if (document.getElementById(d_time + 'imw_tim_'+temp_v))
		{
			document.getElementById(d_time + 'imw_tim_'+temp_v).style.border = '1px solid #b70909';
			/* IE will das zweimal haben!? Ansonsten klappt es nicht!! */
			DIV_MAIN_TIMETABLE.scrollTop = DIV_MAIN_TIMETABLE.scrollTop = temp_v * 18 - 1;
		} else {
			DIV_MAIN_TIMETABLE.scrollTop = 0;
		}
		
	}
}

function imw_tim_lock()
{
	imw_tim_locked = true;
}

function imw_tim_unlock()
{
	imw_tim_locked = false;
}

function imw_tim_close()
{
	if (imw_tim_dat != null)
	{
		DIV_MAIN_TIMETABLE.style.visibility = 'hidden';
		DIV_MAIN_TIMETABLE.style.display 	= 'none';
		
		if (imw_tim_dat.value.length > 0)
		{
			/* Uhrzeit evtl formatieren */
			temp = imw_tim_dat.value.split(":");
			
			if (temp.length == 1 && temp[0].length < 3)
			{	
				imw_tim_dat.value = (temp[0].length == 1 ? "0"+temp[0] : temp[0])+":00";
			} else
			if (temp.length == 2 && temp[0].length < 3 && temp[1].length < 3)
			{
				t_hour = (temp[0].length == 1 ? "0"+temp[0] : temp[0]);
				t_min  = (temp[1].length == 1 ? temp[1]+"0" : temp[1]);
				
				if (t_hour.length == 0)
					t_hour = "00";
				if (t_min.length == 0)
					t_min  = "00";
				
				imw_tim_dat.value = t_hour+":"+t_min;
			} else {
				imw_tim_dat.value = "12:00";
			}
		}
		
		imw_tim_dat = null;
		
		DIV_MAIN_TIMETABLE = null;
	}
}

function imw_tim_set(s_time)
{
	if (imw_tim_dat)
	{
		imw_tim_dat.value = s_time;
		
		imw_tim_close();
	}
}

function imw_tim_EventOnClick()
{
	if (imw_tim_dat && !imw_tim_locked)
	{
		imw_tim_close();
	}
}