function open_search()
{
	document.getElementById('search_link').style.display='none';
	document.getElementById('search_f').style.display='block';
}
function close_search()
{
	document.getElementById('search_link').style.display='block';
	document.getElementById('search_f').style.display='none';
}

function show_oeffn_set_form()
{ document.getElementById("oeffn_set_form").style.display="block"; }

function hide_oeffn_set_form()
{ document.getElementById("oeffn_set_form").style.display="none"; }

function cnfrm(msg,url)
{ if (confirm(msg)) { top.location.href = url; } }

function navigiere(url)
{ top.location.href=url; }

function change_anwesend(id,nbr,url)
{
	box = document.getElementById(id);
	if (box.checked)
	{ navigiere(url+"&anwesend="+nbr) }
	else
	{ navigiere(url+"&abwesend="+nbr) }
}

function show_raeume_form()
{
	document.getElementById('raeume_form').style.display='block';
	document.getElementById('tische_hinzu_link').style.display='none';
}

function show_raum_tab(raum_id)
{
	for(i=0;i<100;i++)
	{
		if (document.getElementById('raum'+i))
		{
			if (raum_id==i)
			{ document.getElementById('raum'+i).style.display ='block'; }
			else
			{ document.getElementById('raum'+i).style.display='none'; }
		}
	}
}

function notiz_form(notiz_id)
{
	if (document.getElementById('notiz'+notiz_id).style.display=='none')
	{
		document.getElementById('notiz'+notiz_id).style.display = 'block';
		document.getElementById('notiz_edit'+notiz_id).style.display = 'none';
	}
	else
	{
		document.getElementById('notiz'+notiz_id).style.display = 'none';
		document.getElementById('notiz_edit'+notiz_id).style.display = 'block';
	}
}

function res_status(id,sid,rid,status)
{
	if (status==0)
	{
		var annulliert_msg = prompt('grund (obligatorisch):','');
		if (annulliert_msg!='') 
		{ top.location.href='http://www.mahlhopper.ch/index.php?sid='+sid+'&p=reservationen&i='+id+'&r='+rid+'&status='+status+'&msg='+annulliert_msg; }
	}
	else
	{ top.location.href='http://www.mahlhopper.ch/index.php?sid='+sid+'&p=reservationen&i='+id+'&status='+status; }
}

function newnotiz_show()
{
	document.getElementById('newnotiz_form').style.display='block';
	document.getElementById('newnotiz_link').style.display='none';
}
function newnotiz_hide()
{
	document.getElementById('newnotiz_form').style.display='none';
	document.getElementById('newnotiz_link').style.display='block';
}

function kalender_refresh(datum,r,sid)
{  
	var mygetrequest=new ajaxRequest();
	var adresse = "../code/pages/kalender.php?self=self&r="+r+"&d="+datum+"&sid="+sid;

	mygetrequest.onreadystatechange=function(){
	 if (mygetrequest.readyState==4) {
	  if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1) {
	   document.getElementById("kalender_f").innerHTML=mygetrequest.responseText;
	  }
	 }
	}
	mygetrequest.open("GET", adresse, true)
	mygetrequest.send(null)
}

function ajaxRequest()
{
 var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] //activeX versions to check for in IE
 if (window.ActiveXObject){ //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
  for (var i=0; i<activexmodes.length; i++){
   try{
    return new ActiveXObject(activexmodes[i])
   }
   catch(e){
    //suppress error
   }
  }
 }
 else if (window.XMLHttpRequest) // if Mozilla, Safari etc
  return new XMLHttpRequest()
 else
  return false
}

function addroom()
{
	document.getElementById('hinzufuegen_link').style.display="none";
	document.getElementById('hinzufuegen_form').style.display="block";
}

function addroom_hide()
{
	document.getElementById('hinzufuegen_link').style.display="block";
	document.getElementById('hinzufuegen_form').style.display="none";
}

function addtable()
{
	document.getElementById('hinzufuegen_link_t').style.display="none";
	document.getElementById('hinzufuegen_form_t').style.display="block";
}

function addtable_hide()
{
	document.getElementById('hinzufuegen_link_t').style.display="block";
	document.getElementById('hinzufuegen_form_t').style.display="none";
}




// drag&drop handler
// thanks to webtoolkit.info
var drag_handler = {
	_oElem : null,
	attach : function(oElem) {
		oElem.onmousedown = drag_handler._dragBegin;
		oElem.dragBegin = new Function();
		oElem.drag = new Function();
		oElem.dragEnd = new Function();
		return oElem;
	},
	_dragBegin : function(e) {
		var oElem = drag_handler._oElem = this;
		if (isNaN(parseInt(oElem.style.left))) { oElem.style.left = '250px'; }
		if (isNaN(parseInt(oElem.style.top))) { oElem.style.top = '110px'; }
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
		e = e ? e : window.event;
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
		oElem.dragBegin(oElem, x, y);
		document.onmousemove = drag_handler._drag;
		document.onmouseup = drag_handler._dragEnd;
		return false;
	},
	_drag : function(e) {
		var oElem = drag_handler._oElem;
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
		e = e ? e : window.event;
		oElem.style.left = x + (e.clientX - oElem.mouseX) + 'px';
		oElem.style.top = y + (e.clientY - oElem.mouseY) + 'px';
		oElem.mouseX = e.clientX;
		oElem.mouseY = e.clientY;
		oElem.drag(oElem, x, y);
		return false;
	},
	_dragEnd : function() {
		var oElem = drag_handler._oElem;
		var x = parseInt(oElem.style.left);
		var y = parseInt(oElem.style.top);
		oElem.dragEnd(oElem, x, y);
		document.onmousemove = null;
		document.onmouseup = null;
		drag_handler._oElem = null;
	}
}

function drag_an()
{ var dragable1 = drag_handler.attach(id('drag_elem')); }

function drag_show(url)
{
	if (arguments.length>2)
	{ // breite und höhe des fensters
		id('drag_frame').style.width = arguments[1]+'px';
		id('drag_elem').style.width = arguments[1]+'px';
		id('drag_frame').style.height = arguments[2]+'px';
		id('drag_elem').style.height = arguments[2]+30+'px';
	}
	id('drag_frame').src = url;
	id('drag_elem').style.display = 'block';
	if ((arguments.length>3)&&(arguments[3]=='fade'))
	{
		id('drag_bg').style.opacity = 0;
		id('drag_bg').style.filter = 'alpha(opacity=0)';
		id('drag_bg').style.display = 'block';
		drag_bg_fade_in(0);
	}
	if (id('slide_main'))
	{ id('slide_main').style.display = 'none'; }
}

function drag_hide()
{
	id('drag_elem').style.display = 'none';
	id('drag_bg').style.display = 'none';
	id('drag_frame').href = 'about:blank;';
	if (id('slide_main'))
	{ id('slide_main').style.display = 'block'; }
	window.location.reload();
}

function drag_bg_fade_in(count)
{
	fade_level = count;
	if (fade_level<9)
	{
		id('drag_bg').style.opacity = fade_level/10;
		id('drag_bg').style.filter = 'alpha(opacity='+(fade_level*10)+')';
		window.setTimeout('drag_bg_fade_in('+(fade_level+1)+')',75);
	}
}

function id(this_id)
{
	return document.getElementById(this_id);
}


