<!--
function help(obj)
{
  if (document.getElementById(obj).style.display == "none" || document.getElementById(obj).style.display == "")
  {
		document.getElementById("a"+obj).firstChild.data = "<<";
    document.getElementById(obj).style.display = "block";
  }
  else
  {
		document.getElementById("a"+obj).firstChild.data = ">>";
    document.getElementById(obj).style.display = "none";
  }
}
function setFocus()
{
  // die FORM heisst 'dict', der INPUT 'search' (wie praktisch)
  document.dict.search.focus();
  document.dict.search.select();
}
function clearForm()
{
  document.dict.search.defaultValue = '';
  document.dict.search.value = '';
  setFocus();
}
function addPanel() {
  if ((typeof window.sidebar == "object") &&
    (typeof window.sidebar.addPanel == "function")){
    window.sidebar.addPanel ("LEO","http://www.leo.org/dict/sidebar.html","");
  }
}
var clear = true;
function onLoad()
{
    if (!document.all)
  {
    if (clear)
      setFocus();
  }
}
function setClear()
{
    clear = false;
}
function init()
{
  //document.getElementById("h2").style.display = "none";
}
function switchVisibility(obj)
{
  if (document.getElementById(obj).style.display == "none" || document.getElementById(obj).style.display == "")
  {
		document.getElementById("a"+obj).firstChild.data = "<<";
    document.getElementById(obj).style.display = "block";
  }
  else
  {
		document.getElementById("a"+obj).firstChild.data = ">>";
    document.getElementById(obj).style.display = "none";
  }
}
function changeselection()
{
	voclength = document.getElementsByName("vocable[]").length
	inbox = document.getElementById("chgselection")
	if(inbox.checked==true)
	{
		for(i=0;i < voclength;i++)
		{
			document.getElementsByName("vocable[]")[i].checked=true;
		}
	}
	else
	{
		for(i=0;i < voclength;i++)
		{
			document.getElementsByName("vocable[]")[i].checked=false;
		}
	}
}

var url="http://dict.leo.org/mydict/ajax.php";

function AjaxRequest()
{
	var xmlHttpReq = false;
	/*@cc_on @*/
	/*@if (@_jscript_version >= 5)
	try
	{
		xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
	}
	catch (e)
	{
		try
		{
			xmlHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch (e2)
		{
			xmlHttpReq = false;
		}
	}
	@end @*/

	if (!xmlHttpReq && typeof XMLHttpRequest != 'undefined')
	{
		xmlHttpReq = new XMLHttpRequest();
	}

	info = null;
	// Ajax-Request kann durchgeführt werden
	this.getMoreInfo =  function (e, idWord)
	{
		if (xmlHttpReq)
		{
			if (idWord.search(/_b/) != -1)
			{
				// Forumseintrag wird angezeigt
				if (e.target)
				{
					var trNode = e.target.parentNode.parentNode;
				}
				else
				{
					var trNode = e.srcElement.parentNode.parentNode;
				}

				info = document.getElementById('divForumInfo');
				var newRow = document.createElement("tr");
				newRow.setAttribute("id","forumTableRow");
				var newCell = document.createElement("td");
				// Der IE achtet hier auf gross/klein schreibung!
				newCell.setAttribute("colSpan","5");
				newCell.appendChild(info);
				newRow.appendChild(newCell);

				if (trNode.nextSibling)
				{
					trNode.parentNode.insertBefore(newRow,trNode.nextSibling);
				}
				else
				{
					trNode.parentNode.appendChild(newRow);
				}
				info.style.visibility = 'visible';
				info.style.display = 'block';
				info = document.getElementById('divForumInfoContent');
			}
			else
			{
				info = document.getElementById('divMoreInfo');
			}

			document.body.style.cursor='wait';
			xmlHttpReq.open("GET", url+"?idWord="+idWord+"&lang="+document.dict.lang.value+"&lp="+document.dict.lp.value, true);
			xmlHttpReq.onreadystatechange = this.updateInfo;
			xmlHttpReq.send(null);

			if (idWord.search(/_en/) != -1)
			{
				// Contextmenue wird links plaziert
				this.positionLeft(e);
			}
			if (idWord.search(/_de/) != -1)
			{
				// Contextmenue wird rechts plaziert
				this.positionRight(e);
			}
		}
		else
		{
			// Browser unterstützt keine AJAX-Requests, Pop-Up  wird stadt dessen geöffnet bzw. neue Seite angezeigt
			if (idWord.search(/_b/) != -1)
			{
				// Forumseintrag wird in neuer Seite geöffnet
				document.open("http://83.220.155.5/mydict/ajax.php?idWord="+idWord+"&lang="+document.dict.lang.value+"&lp="+document.dict.lp.value+"&ajax=false","PopUpInfo","width=500,height=400,left=0,top=0, menubar=yes,resizable=yes,scrollbars=yes,location=yes,toolbar=yes,status=yes");
			}
			else
			{
				// Pop-Up wird geöffnet
				var popUpInfo = document.open("http://83.220.155.5/mydict/ajax.php?idWord="+idWord+"&lang="+document.dict.lang.value+"&lp="+document.dict.lp.value+"&ajax=false","PopUpInfo","width=300,height=400,left=200,top=200");
			}
		}
	}

	this.getSelectedVocables = function (post)
	{
		url = "http://dict.leo.org/mydict/trainer/selectVocables.php?ajax=true";
		xmlHttpReq.open("POST", url);
		xmlHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		xmlHttpReq.onreadystatechange = this.updateVocables;
		xmlHttpReq.send(post);
	}

	this.sendTrainerResults = function (post)
	{
		url = "http://dict.leo.org/mydict/trainer/writeVocable.php?ajax=true";
		xmlHttpReq.open("POST", url);
		xmlHttpReq.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
		//xmlHttpReq.onreadystatechange = this.updateVocables;
		xmlHttpReq.send(post);
	}

	this.updateVocables = function()
	{
		if(xmlHttpReq.readyState == 4)
		{
			// UTF8 Dateianfang wird weggeparst
			document.getElementById('contentDisplayVocvables').innerHTML = xmlHttpReq.responseText.substr(3);
			document.body.style.cursor='default';
		}
	}

	this.updateInfo = function()
	{
		if(xmlHttpReq.readyState == 4)
		{
			// Contextmenue wird aktualisiert
			info.innerHTML = xmlHttpReq.responseText;
			// Contextmenue wird angezeigt
			info.style.visibility = 'visible';
			info.style.display = 'block';
			document.body.style.cursor='default';
		}
	}

	this.positionLeft = function(e)
	{
		var y;
		if (self.pageYOffset) // all except Explorer
		{
			y = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
		{
			y = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			y = document.body.scrollTop;
		}

		if (e.pageX)

		{
			var pageX = e.pageX;
			var pageY = e.pageY;
		}
		else
		{
			var pageX = e.clientX;
			var pageY = e.clientY + y;
		}

		info.style.right = "";
		info.style.left = (pageX - 10)+ "px";
		info.style.top = (pageY - 10) + "px";
	}

	this.positionRight = function(e)
	{
		info.style.left = "";

		var innerWidth, offSetY, pageX, pageY;

		/**
		* Die X/Y-Position "pageX, pageY" des Events wird bestimmt
		* Fuer den IE muss dazu der Scroll-Offset "offSetY"  bestimmt werden
		*/
		if (self.pageYOffset) // all except Explorer
		{
			offSetY = self.pageYOffset;
		}
		else if (document.documentElement && document.documentElement.scrollTop)
		// Explorer 6 Strict
		{
			offSetY = document.documentElement.scrollTop;
		}
		else if (document.body) // all other Explorers
		{
			offSetY = document.body.scrollTop;
		}
		if (e.pageX)
		{
			pageX = e.pageX;
			pageY = e.pageY;
		}
		else
		{
			pageX = e.clientX;
			pageY = e.clientY + offSetY;
		}

		/**
		* Fensterbreite "innerWidth" wird bestimmt.
		*/
		if (self.innerHeight)
		{
			// alle Browser auser IE
			innerWidth = self.innerWidth;
		}
		else if (document.documentElement && document.documentElement.clientHeight)
		{
			// IE 6 Strict Mode
			innerWidth = document.documentElement.clientWidth;
		}
		else if (document.body)
		{
			// andere IEs
			innerWidth = document.body.clientWidth;
		}

		info.style.right = (innerWidth - pageX - 30)+ "px";
		info.style.top = (pageY - 10) + "px";
	}
}

var ajax = new AjaxRequest();
function getMoreInfo(e, idWord)
{
	ajax.getMoreInfo(e, idWord);
}

function displaySelectedVocables(event, formName)
{
	ajax.getSelectedVocables(postBackString(event, formName));
}

function postBackString(event, formName)
{
	if (event.target)
	{
		var value = event.target.value;
	}
	else
	{
		var value = event.srcElement.value;
	}
	var fields = new Array();
	if(formName)
	{
		//loop through form elements and retrieve field NAMEs and Values
		for (var x = 0; x < eval("document."+formName+".elements.length"); x++)
		{
			// join them into a string.
			var type = eval("document."+formName+".elements[x].type");
			if (type == 'submit' || type == "button")
			{
				if (eval("document."+formName+".elements[x].value") == value)
				{
					eval("fields.push(document."+formName+	".elements[x].name+'='+document."+formName+".elements[x].value)");
				}
			}
			else
			{
				if (type == "checkbox")
				{
					if (document.forms[formName].elements[x].checked == true)
					{
						eval("fields.push(document."+formName+  ".elements[x].name+'='+document."+formName+".elements[x].value)");
					}
				}
				else if (type == "radio")
				{
					if (document.forms[formName].elements[x].checked == true)
					{
						eval("fields.push(document."+formName+  ".elements[x].name+'='+document."+formName+".elements[x].value)");
					}
				}
				else
				{
					eval("fields.push(document."+formName+	".elements[x].name+'='+document."+formName+".elements[x].value)");
				}
			}
		}
	}
	return "ajax=true&"+fields.join('&');
}


/*
* Encodet die entities in UFT8 Chars
*/
function decodeEntities(str)
{
	var matches = str.match(/&#x(\w)+;/g);

	if (matches)
	{
		for(var i = 0; i < matches.length; i++)
		{
			// line wraps here -- be careful copy/pasting
			var charCode = "0" + matches[i].replace(/\W+/g,"");
			var replacement = String.fromCharCode(charCode);

			str = str.replace(/&#(\w)+;/,replacement);
		}
	}
	return str;
}

/*
* Fügt den Buchstaben dem aktivierten Feld hinzu
*/
function addToField(letter)
{
	try
	{
		if (field)
		{
			field.value += letter;
			field.focus();
		}
	}
	catch(e)
	{
	}
}
//-->

