function showUpdateButtonAndOverlays()
{
	// show "UPDATE"-Button
	showElementById("updateSchedulebuttonId");
	// show gray overlay on schedule
	showElementById("scheduleOverlayId");
	// show Info-Text on gray overlay
	showElementById("scheduleOverlayInfoTextId");
	// show gray overlay on resourse
	showElementById("scheduleResourceOverlayId");
}
function hideUpdateButtonAndOverlays()
{
	// hide "UPDATE"-Button
	hideElementById("updateSchedulebuttonId");
	// hide overlay on schedule
	hideElementById("scheduleOverlayId");
	// hide Info-Text on gray overlay
	hideElementById("scheduleOverlayInfoTextId");
	// hide overlay on resourse
	hideElementById("scheduleResourceOverlayId");
}

function showElementById(elementName)
{
	if (document.getElementById(elementName))
		document.getElementById(elementName).style.display='';
}
function hideElementById(elementName)
{
	if (document.getElementById(elementName))
		document.getElementById(elementName).style.display='none';
}

function submitScheduleForm(useUpdateButtonToSubmit)
{
	if (useUpdateButtonToSubmit)
	{
		showUpdateButtonAndOverlays();
	}
	else
	{
		// submit form
		document.getElementById("scheduleNavigationFormId").submit();	
		
		hideUpdateButtonAndOverlays();
	}	
}

function resetFilterOverlay(){
	
		// reset form
		document.getElementById("scheduleNavigationFormId").reset();			

		hideUpdateButtonAndOverlays();
}	


function showFilterBox()
{
	resetFilterOverlay();
	elem = document.getElementById("filterBox");
	if (elem.style.display=='')
	{		
		//<![CDATA[
     Effect.Fade('filterBoxControls', { afterFinish : function(effect) {elem.style.display='none';}});
    // ]]>    
	}
	else
	{
		elem.style.display='';	
		//<![CDATA[
      Effect.Appear('filterBoxControls');
    // ]]>	    
	}
}


function showTimeZoneBox()
{
	elem = document.getElementById("timeZoneBox");
	elem1 = document.getElementById("timeZoneBoxIcon");
	if (elem.style.display=='')
	{		
		//<![CDATA[
     Effect.Fade('timeZoneBoxControls', { afterFinish : function(effect) {elem.style.display='none';elem1.src='images/timezone.gif';}});
    // ]]>    
	}
	else
	{
		elem.style.display='';	
		elem1.src='images/timezone_hide.gif';
		//<![CDATA[
      Effect.Appear('timeZoneBoxControls');
    // ]]>	    
	}
}

function showResourceSelectBox()
{
	elem = document.getElementById("resourceSelectBox");
	if (elem.style.display=='')
	{
		//<![CDATA[
      Effect.Fade('resourceSelectBoxControls', { afterFinish : function(effect) {elem.style.display='none';}});
    // ]]>
	}
	else
	{
		elem.style.display='';	
		//<![CDATA[
      Effect.Appear('resourceSelectBoxControls');
    // ]]>	
	}
}
/** 
 * Für TRs soll das Include so aufgebaut sein:
 * <table><tbody><tr>....</tr></tbody></table>
 * also eine Tabelle mit genau einer Zeile
 * Das TargetElement ist dabei das TR selbst und nicht noch ein Wrapper wie sonst bei AJAX Updates üblich
 */
function loadResourcesViaAJAX(resourceType, resourceId, targetId, pars)
{
	var url1	= 'schedule_resourceinfo.ajax.jsp';
	pars 	= pars+'&ajaxResourceId='+resourceId+'&ajaxResourceType='+resourceType+'&rnd='+Math.random();
	url1 = url1+'?'+pars;
	
	
alert(url1);	
	
	var tempId = 'tempDiv';
	var tempDiv = document.getElementById(tempId);
	// TempKnoten erzeugen und ans Body-Tag hängen, damit das Update auch mit "TR" funktioniert!
	if(!tempDiv)
	{
		tempDiv = document.createElement("DIV");
		tempDiv.id = tempId;
		tempDiv.style.display = 'none';
		document.getElementsByTagName('body')[0].appendChild(tempDiv);
	}
	tempDiv.innerHTML='HALLO!';
	var ajax 	= new Ajax.Updater(
								{success: tempId},
								url1, 
								{
									method: 'get', 									
									onFailure: reportError,
									onComplete: timeOut(tempId, targetId)
								}); 	
}

function timeOut(tempId, targetId)
{
	setTimeout("copyAJAXRessource('"+tempId+"', '"+targetId+"')", 5000);
}

function copyAJAXRessource(tempId, targetId)
{
	var targetElement = document.getElementById(targetId);
	var tempDiv = document.getElementById(tempId);
	var bodyNode = targetElement.parentNode;
	//alert(tempDiv.innerHTML);
	if ("TR" == targetElement.nodeName)
		bodyNode.replaceChild(tempDiv.firstChild.firstChild.firstChild, targetElement);
	else
		bodyNode.replaceChild(tempDiv.firstChild, targetElement);
}
function unloadAJAXResources(elementId)
{
	elem = document.getElementById(elementId);
	elem.style.display = 'none';
}


function reportError()	
{
	alert("ERROR");
}

function getSelectedTimeZoneCode()
{
	elem = document.getElementById('timeZoneSelectBox');
	return elem.options[elem.selectedIndex].value;
}


