var mygetrequest = new ajax_request();
var target_id = '';

function popup_zoomin(popup_id,target_id)
{
	var popup = document.getElementById(popup_id);
	var target = document.getElementById(target_id);
	if (popup!=false&&target!=false)
	{
		popup.style.opacity = 0.0;
		target_x = getElementPosition(target_id).left;
		target_y = getElementPosition(target_id).top;
		target_w = 284;
		target_h = 350;
		popup.style.position = 'absolute';
		popup.style.display = 'block';
		popup.style.top = target_y+(87)+'px';
		popup.style.left = target_x+(570)+'px';
		popup.style.height = target_h+'px';
		popup.style.width = target_w+'px';

		popup_blendin(popup_id,0.0);
	}
}
function popup_hide(popup_id)
{
	var popup = document.getElementById(popup_id);
	if (popup!=false)
	{
		popup.style.display = 'none';
	}
}
function popup_blendin(popup_id,this_opacity)
{
	if (this_opacity<1.0)
	{
		this_opacity+=0.1;
		popup = document.getElementById(popup_id);
		popup.style.opacity = this_opacity;
		window.setTimeout('popup_blendin("'+popup_id+'",'+this_opacity+')',50);
	}
}

function ajax_request() 
{
  try {return new XMLHttpRequest();}
  catch (error) {}
  try {return new ActiveXObject("Msxml2.XMLHTTP");}
  catch (error) {}
  try {return new ActiveXObject("Microsoft.XMLHTTP");}
  catch (error) {}
  throw new Error("Kein HTTP Request möglich.");
}

mygetrequest.onreadystatechange=function()
{ 
	if (mygetrequest.readyState==4)
	{
		if (mygetrequest.status==200 || window.location.href.indexOf("http")==-1)
		{
//			alert(mygetrequest.responseText);
			var str_onload = '';
			var output_html = mygetrequest.responseText;
			var onload_pos = output_html.indexOf('<!--#@#onload-');
			if (onload_pos>0)
			{
				str_onload = output_onload(output_html);
				output_html = output_html.substr(0,onload_pos); 
			}
			document.getElementById(target_id).innerHTML=output_html;
			eval(str_onload);
		}
	}
}

function output_onload(str)
{
	/* <!--#@#onload-STRING-@#@--> */
	str_pos = str.indexOf('<!--#@#onload-');
	end_pos = str.indexOf('-@#@-->');
	if (str_pos!=-1&&end_pos!=-1)
	{
		onload_js = str.substr(str_pos,end_pos);
		onload_js = onload_js.replace('<!--#@#onload-','');
		onload_js = onload_js.replace('-@#@-->','');
		return onload_js;
	}
	return false;
}

function update_bereich(container_id,bereich_id,seite_id)
{
	target_id = container_id;
	document.getElementById(target_id).innerHTML = '<div class="ajax_loader"></div>';
	if (mygetrequest!=false)
	{
		target = "http://www.fugu-nydegg.ch/web_bereich.php?b="+bereich_id+"&p="+seite_id;
		mygetrequest.open("GET", target, true);
		window.setTimeout('mygetrequest.send(null)',200);
		return false;
	}
	else return true;
}

function init_keysearch(item_id) 
{
	suchfeld = document.getElementById(item_id);
	if ((suchfeld.value=='durchsuchen')&&(suchfeld.className=='keyword_input_init'))
	{
		suchfeld.setAttribute('class','keyword_input');
		suchfeld.value='';
	}
}
function reset_keysearch(item_id)
{
	suchfeld = document.getElementById(item_id);
	if (suchfeld.value=='')
	{ 
		suchfeld.setAttribute('class','keyword_input_init');
		suchfeld.value = 'durchsuchen';
	}
}
function filter_keys(wrapper_id,search_value)
{
	keys_liste = document.getElementById(wrapper_id);
	keys_children = keys_liste.getElementsByTagName('div');

	if (search_value!='')
	{ search_value = search_value.toLowerCase(); }

	for (var i=0; i<keys_children.length; i++)
	{
		keys_div = keys_children[i];
		if (keys_div.className=='keyword')
		{
			if (search_value=='')
			{ 
				keys_div.style.display='block'; 
			}
			else
			{
				key_text = keys_div.innerHTML.toLowerCase();
				if (key_text.indexOf(search_value)==-1)
				{ keys_div.style.display='none'; }
				else
				{ keys_div.style.display='block'; }
			}
		}
	}
}


var fontSize = 1;
var lineHeight = 1.3;
function zoom_in()
{
	fontSize += 0.1;
	document.body.style.fontSize = fontSize + "em";
	document.body.style.lineHeight = lineHeight + "em";
	changecss('.main','font-size',fontSize);
}
function zoom_out()
{
	fontSize -= 0.1;
	document.body.style.fontSize = fontSize + "em";
	document.body.style.lineHeight = lineHeight + "em";
	changecss('.main','font-size',fontSize);
}
function zoom_normal()
{
	fontSize = 1;
	document.body.style.fontSize = fontSize + "em";
	document.body.style.lineHeight = lineHeight + "em";
	changecss('.main','font-size',fontSize);
}

function getElementPosition(elemID){
var offsetTrail = document.getElementById(elemID);
var offsetLeft = 0;
var offsetTop = 0;
while (offsetTrail){
offsetLeft += offsetTrail.offsetLeft;
offsetTop += offsetTrail.offsetTop;
offsetTrail = offsetTrail.offsetParent;
}
if (navigator.userAgent.indexOf('Mac') != -1 && typeof document.body.leftMargin != 'undefined'){
offsetLeft += document.body.leftMargin;
offsetTop += document.body.topMargin;
}
return {left:offsetLeft,top:offsetTop};
}
function getElementHeight(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetHeight;
	return xPos;
}
function getElementWidth(Elem) {
	if(document.getElementById) {
		var elem = document.getElementById(Elem);
	} else if (document.all){
		var elem = document.all[Elem];
	}
	xPos = elem.offsetWidth;
}

function changecss(theClass,element,value) 
{
 var cssRules;
 var added = false;
 for (var S = 0; S < document.styleSheets.length; S++){

if (document.styleSheets[S]['rules']) {
  cssRules = 'rules';<!---->
 } else if (document.styleSheets[S]['cssRules']) {
  cssRules = 'cssRules';
 } else {
  //no rules found... browser unknown
 }

  for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
   if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
	if(document.styleSheets[S][cssRules][R].style[element]){
	document.styleSheets[S][cssRules][R].style[element] = value;
	added=true;
	break;
	}
   }
  }
  if(!added){
  if(document.styleSheets[S].insertRule){
	  document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
	} else if (document.styleSheets[S].addRule) {
		document.styleSheets[S].addRule(theClass,element+': '+value+';');
	}
  }
 }
}






