function check_ptc_multi(question_id, exclusive_id, this_id)
{
	var elements = $$("#cnt_que_" + question_id + " input");
	var idpre = "que_" + question_id + "_";
	var elm = null;
	
	for (var i = 0; i < elements.length; i++)
	{
		elm = elements[i];
		
		if ((this_id == exclusive_id && elm.id != (idpre + exclusive_id)) ||
			(this_id != exclusive_id && elm.id == (idpre + exclusive_id)))
		{
			elm.checked = false;
		}
	}
}

/****************************************/

function load_homepage_box(what)
{
	new Ajax.Updater("inline_box", "/_boxes/inline/homepage.php?what=" + what, {
					 asynchronous: true,
					 evalScripts: true,
					 method: "get",
					 encoding: "iso-8859-1",
					 onComplete: function() {
						 new Effect.Highlight("inline_box_content");
						 moveFooter();
					 }});
	
	return false;
}

function load_elearning_selftest(education, chapter)
{
	load_elearning_question(education, chapter, 0);
}

function load_elearning_question(education, chapter, question)
{
	new Ajax.Updater("elearning_chapter", "/de/fortbildung/_selbsttest/", {
					 asynchronous: true,
					 evalScripts: true,
					 method: "post",
					 encoding: "iso-8859-1",
					 postBody: "education=" + education + "&chapter=" + chapter + "&question=" + question,
					 onComplete: function() {
						 $("elearning_chapter").className = "loaded";
						 new Effect.Highlight("elearning_chapter");
						 moveFooter();
					 }});
}

function send_elearning_selftest()
{
	new Ajax.Updater("elearning_chapter", "/de/fortbildung/_selbsttest/", {
					 asynchronous: true,
					 evalScripts: true,
					 method: "post",
					 encoding: "iso-8859-1",
					 postBody: Form.serialize("elearning_selftest_form"),
					 onComplete: function() {
						 new Effect.Highlight("elearning_chapter");
						 moveFooter();
					 }});
	
	return false;
}

/****************************************/

function load_generic_selftest(selftest)
{
	load_generic_question(selftest, 0);
}

function load_generic_question(selftest, question)
{
	new Ajax.Updater("generic_selftest", "/de/selbsttest/_selbsttest/", {
					 asynchronous: true,
					 evalScripts: true,
					 method: "post",
					 postBody: "selftest=" + selftest + "&question=" + question,
					 onComplete: function() {
						 $("generic_selftest").addClassName("loaded");
						 new Effect.Highlight("generic_selftest");
						 moveFooter();
					 }});
}

function send_generic_selftest()
{
	new Ajax.Updater("generic_selftest", "/de/selbsttest/_selbsttest/", {
					 asynchronous: true,
					 evalScripts: true,
					 method: "post",
					 postBody: Form.serialize("generic_selftest_form"),
					 onComplete: function() {
						 new Effect.Highlight("generic_selftest");
						 moveFooter();
					 }});
	
	return false;
}

/****************************************/

function moveFooter()
{
	if (navigator.userAgent.indexOf("MSIE") >= 0)
	{
		document.getElementById("footer").style.top = (document.body.scrollHeight - 45) + "px";
	}
}

function changeAllTableRows(tableid)
{
	var event_bodies = document.getElementById(tableid).childNodes;
	var i, j;
	
	for (i = 0; i < event_bodies.length; i++)
	{
		if (event_bodies[i].tagName && event_bodies[i].tagName.toLowerCase() == "tbody")
		{
			for (j = 0; j < event_bodies[i].childNodes.length; j++)
			{
				if (event_bodies[i].childNodes[j].tagName &&
					event_bodies[i].childNodes[j].tagName.toLowerCase() == "tr" &&
					event_bodies[i].childNodes[j].className.indexOf("active") < 0)
				{
					event_bodies[i].childNodes[j].className += " active";
				}
			}
		}
	}
	
	moveFooter();
}

function changeTableRow(link_element)
{
	if (!isNaN(link_element))
	{
		changeTableRow(document.getElementById("row" + link_element));
		changeTableRow(document.getElementById("info" + link_element));
		return;
	}
	
	var row = (link_element.tagName.toLowerCase() == "a" ? link_element.parentNode.parentNode : link_element);
	
	if (row && typeof row != "undefined" && row.tagName.toLowerCase() == "tr")
	{
		row.className = ((row.className.indexOf("active") >= 0) ? row.className.replace(/\s*active/, "") : row.className + " active");
	}
	
	moveFooter();
}

function hideTextfieldDummy(element)
{
	element.style.backgroundImage = 'none';
}

function specialCheckbox(element_key, source)
{
	var element = document.getElementById(element_key);
	
	if (!element || typeof element == "undefined")
	{
		return;
	}
	
	element.checked = !element.checked;
	source.className = "check_special" + (element.checked ? " active" : "");
}

function viewAndHidePreview(element_id, pclass)
{
	var pobject = document.getElementById("preview_" + element_id);
	
	if (!pobject || typeof pobject == "undefined")
	{
		return;
	}
	
	pobject.className = "preview " + pclass;
}

function gupct(evt) {
	var e = $(Event.element(evt));
	
	while (e) {
		if (e && e.href) break;
		e = e.parentNode;
	} 
	
	if (!e || !e.href) return true;
	
	var i = new Image();
	i.src = "/gupct.php?s=" + encodeURIComponent(window.location.href) + "&t=" + encodeURIComponent(e.href) + "&x=" + evt.pointerX() + "&y=" + evt.pointerY();
	
	return true;
}

/****************************************/

document.observe("dom:loaded", function() {
	/* Vergrößerungsbilder umwandeln */
	var magnpic;
	for (var e = 0; e < $$("a.picture[rel] img").length; e++) {
		magnpic = $$("a.picture[rel] img")[e];
		magnpic.insert({before: new Element("span", {"class": "magnify"}).update(" ").setStyle({marginTop: (magnpic.getHeight() - 25) + "px"}).setStyle({marginLeft: (magnpic.getWidth() - 25) + "px"})});
	}
	
	/* Klicktracking hinzufügen */
	$$("a").each(this.observe("click", gupct));
});

