function setFocus() {
  document.dix.search.focus();
  document.dix.search.select();
  refreshPrivate();
}
function clearForm() {
  document.dix.search.defaultValue = '';
  document.dix.search.value = '';
  setFocus();
}
function printpage() {
    if (window.print) window.print();
    else alert("Bitte benutzen Sie die Druckfunktion Ihres Webbrowsers.\n\nPor favor utilice la función de imprimir de su navegador.\n\nPlease use the print function in your browser.");
}
function changeText(msg) { document.getElementById("divMessage").firstChild.data = msg }
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}
function readCookie(name) {
	var nameEQ = name + "=";
	var ca = document.cookie.split(';');
	for(var i=0;i < ca.length;i++) {
		var c = ca[i];
		while (c.charAt(0)==' ') c = c.substring(1,c.length);
		if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
	}
	return null;
}
function eraseCookie(name) {	createCookie(name,"",-1); }
function updateOpenClose(tablename, val){
	var oc = readCookie('dix_openclose');
	if(oc==null) {	
		createCookie('dix_openclose', tablename+'='+val+'-', 365);
		return;
	}
	var current = new Array();
	var i = oc.indexOf(tablename);
	if(i!=-1){
		var e = oc.indexOf('-', i);
		if(e!=-1) {
			createCookie('dix_openclose', oc.substring(0,i)+tablename+'='+val + oc.substring(e), 365);
			return;
		}
	}
	createCookie('dix_openclose', oc+tablename+'='+val+'-', 365);
}
function collapse(tablename){
	var l = tablename + '_icon';
	t = document.getElementById(l);
	t.innerHTML = '<img src="./pics/p.gif" alt="expand" style="cursor:pointer;" onClick="expand(\''+tablename+'\');" onmouseover="this.src=\'./pics/p'+cscheme+'.gif\'" onmouseout="this.src=\'./pics/p.gif\'"/>';
	var l = tablename + '_title';
	t = document.getElementById(l);
	t.onclick = function(){ expand(tablename); }
	t = document.getElementById(tablename);
	for(i=1; i<t.rows.length; i++){
		t.rows[i].style.display="none";
	}
	var date = new Date();
	updateOpenClose('dix'+tablename, 'c:'+(date.getTime()/1000+(date.getTimezoneOffset()+60)*60));
}
function expand(tablename){
	t = document.getElementById(tablename);
	for(i=1; i<t.rows.length; i++){
		t.rows[i].style.display="";
	}
	var l = tablename + '_icon';
	t = document.getElementById(l);
	t.innerHTML = '<img src="./pics/m.gif" alt="collapse" style="cursor:pointer;" onClick="collapse(\''+tablename+'\');" onmouseover="this.src=\'./pics/m'+cscheme+'.gif\'" onmouseout="this.src=\'./pics/m.gif\'"/>';
	var l = tablename + '_title';
	t = document.getElementById(l);
	t.onclick = function(){ collapse(tablename); }
	l = tablename + '_new';
	t = document.getElementById(l);
	if(t!=null) t.innerHTML = '';
	updateOpenClose('dix'+tablename, 'e');
}
var activeMyDIX = '';
var activeMyDIXLabel = '';
function getActiveMyDIX(){
	var mydix = readCookie('mydix');
	if(mydix==null){
		mydix = '1==myDIX===';
		createCookie('mydix', mydix, 365);
	}
	var temp = new Array(); 
	temp = mydix.split('===');
	var t = new Array();
	t = temp[0].split('==');
	activeMyDIX = t[0];
	activeMyDIXLabel = t[1];
}
function changeLabel(infotext, defaultlabel){
	var ret =  window.prompt(infotext, defaultlabel);
	if(ret==null) return;
	ret = ret.replace(/\'/g, '');
	ret = ret.replace(/==/g, '');
	if(ret.length<1) return;
	
	var mydix = readCookie('mydix');
	var i1 = mydix.indexOf('==');
	var i2 = mydix.indexOf('===');
	mydix = mydix.substr(0,i1+2)+ret+mydix.substr(i2);
	createCookie('mydix', mydix, 365);
	activeMyDIXLabel = ret;
	createCookie('myDixHasChanges', '1', 365);
	refreshPrivate();
}
function addToPrivate(rowid){
	createCookie('myDixHasChanges', '1', 365);
	getActiveMyDIX();
	var r = readCookie('my_'+activeMyDIX+'_'+dix);
	if(r!=null) {
		if(r.length>4000) alert("myDIX uses cookies to store your data.\nTherefore the capacity is limited to approximately 200 translations on most browsers.\nYou have reached this limit - it is not guaranteed that additional translations can be stored correctly.\nYou can create up to 10 private dictionaries, each with up to 200 translations.\nThank you for your understanding.");
		if(r.indexOf(rowid)==-1) r = r+rowid+'-';
	}
	else r = rowid+'-';
	createCookie('my_'+activeMyDIX+'_'+dix, r, 365);
	refreshPrivate();
}
function removeFromPrivate(rowid){	
	createCookie('myDixHasChanges', '1', 365);
	getActiveMyDIX();
	var r = readCookie('my_'+activeMyDIX+'_'+dix, 365);
	if(r!=null) {
		var i = r.indexOf(rowid);
		if(i!=-1){
			var e = r.indexOf('-', i);
			r = r.substring(0,i) + r.substring(e+1);
			if(r.length>1)	createCookie('my_'+activeMyDIX+'_'+dix, r, 365);
			else 		eraseCookie('my_'+activeMyDIX+'_'+dix);
		}
	}
	refreshPrivate();
}
function getHeaderMyDIX(){
	var u = readCookie('phorum_cookieauth');
	var c = readCookie('myDixHasChanges');
	if(u!=null && u.length>5 && c=='1') tmptxt = ' | <a href="./mydix.php'+urlsettings+'updatemydix=true&search='+search+'">'+strpermasave+'</a>';
	else if(u==null) tmptxt = ' | <a href="./forum/login.php'+urlsettings+'target='+target+'">'+strlogin+'</a>';
	else tmptxt = '';
	label = activeMyDIXLabel;
	tmptxt = ' <a href="javascript:onClick=changeLabel(\''+strchangelabel+'\',\''+activeMyDIXLabel+'\');">'+strchangelabel+'</a>' + tmptxt;	
	return '<a href="./mydix.php'+urlsettings+'" id="mydixlabel">'+label+'</a><br><font>'+tmptxt+'</font>';
}
function hasmyDIXElements(array){
	for (var j=0;j<array.length-1;j++){
		if(array[j].length>10){
			var t = new Array();
			t = array[j].split('=');
			var origRow = document.getElementById('row_'+t[0]);
			if(origRow!=null) return true;
		}
	}
	return false;
}
function refreshPrivate(){
	getActiveMyDIX();
	var r = readCookie('my_'+activeMyDIX+'_'+dix);
	var th= document.getElementById('mydixheader');
	var t = document.getElementById('results');
	if(t==null) return;
	//alert(r);
	if(r!=null) {
		var temp = new Array(); 
		temp = r.split('-');
		if(!hasmyDIXElements(temp)) return;
		
		var newCell;
		if(th==null){      
			var r0 = t.insertRow(2);
			newCell = r0.insertCell(0); 
			newCell.colSpan = 4; 
			r0.id = 'mydixheader';
			r0.className = 'contentheadcenter';
			
			r0 = t.insertRow(3);
			newCell = r0.insertCell(0); 
			newCell.colSpan = 4; 
			r0.id = 'mydixfooter';			
		}
		t.rows[2].cells[0].innerHTML = getHeaderMyDIX();
		var minindex = document.getElementById('mydixheader').rowIndex;
		var maxindex = document.getElementById('mydixfooter').rowIndex;
		// collect visible ids
		var visibleRows = new Object();
		for (var j=minindex+1;j<maxindex;j++){
			visibleRows[t.rows[j].id] = false;
		}
		
		// append new inserted rows
		for (var j=0;j<temp.length-1;j++){
			if(temp[j].length>10){
				var t2 = new Array();
				t2 = temp[j].split('=');
				var origRow = document.getElementById('row_'+t2[0]);
				if(origRow!=null && origRow.rowIndex>maxindex){ // add recently added to mydix
					var newRow = origRow.cloneNode(true);
					t.tBodies[0].insertBefore(newRow, document.getElementById('mydixfooter'));
					t.tBodies[0].deleteRow(origRow.rowIndex);
					
					var con = newRow.cells[0].innerHTML;
					var pos = con.indexOf('>');
					newRow.cells[0].innerHTML = '<img src="./pics/pm.gif" width="14px" height="12px" alt="'+strremlabel+'" style="cursor:pointer;" onmouseover="this.src=\'./pics/pm'+cscheme+'.gif\'" onmouseout="this.src=\'./pics/pm.gif\'" onclick="removeFromPrivate(\''+temp[j]+'\');">'+con.substr(pos+1, con.length);
				}
				visibleRows['row_'+t2[0]] = true;
			}
		}
		// iterate to delete what belongs back to original data
		for (var j in visibleRows){
			if(visibleRows[j]==false){ 
				deleteRow(j, maxindex, t);
			}
		}
	}
	else if(th!=null){
		var minindex = document.getElementById('mydixheader').rowIndex;
		var maxindex = document.getElementById('mydixfooter').rowIndex;
		// collect visible ids
		for (var j=minindex+1;j<maxindex;j++){
			deleteRow(t.rows[j].id, maxindex, t);
		}
	}
	for(var i=0; i<t.rows.length; i++){
		if(t.rows[i].className=="contentbg0" || t.rows[i].className=="contentbg1"){
			t.rows[i].className = "contentbg"+(i%2);
		}
	}
}
function deleteRow(id, offset, t){
	var origRow = document.getElementById(id);
	var newRow  = origRow.cloneNode(true);
	var origPos = offset+1;
	t.tBodies[0].rows[offset].cells[0].innerHTML = strremoved;
	t.tBodies[0].rows[offset].className = 'contentheadcenter';
	
	t.tBodies[0].insertBefore(newRow, t.rows[origPos]);
	t.tBodies[0].deleteRow(origRow.rowIndex);
				
	var con = newRow.cells[0].innerHTML;
	var pos = con.indexOf('>');
	newRow.cells[0].innerHTML = '<img src="./pics/my.gif" width="14px" height="12px" alt="'+straddlabel+'" style="cursor:pointer;" onmouseover="this.src=\'./pics/my'+cscheme+'.gif\'" onmouseout="this.src=\'./pics/my.gif\'" onclick="addToPrivate(\''+id.replace('row_','')+'\');">'+con.substr(pos+1, con.length);
}
function addEngine(name,ext,cat) {
	if ((typeof window.sidebar == "object") & (typeof window.sidebar.addSearchEngine == "function"))   {
		window.sidebar.addSearchEngine("http://dix.osola.com/plugin/"+name+".src", "http://dix.osola.com/plugin/"+name+"."+ext, name, cat );
	}
	else {  alert("Netscape 6 or Mozilla is needed to install a sherlock plugin");  }
}
function findPos(obj){
	var curleft = curtop = 0;
	if (obj.offsetParent) {
		curleft = obj.offsetLeft
				curtop = obj.offsetTop
				while (obj = obj.offsetParent) {
			curleft += obj.offsetLeft
					curtop += obj.offsetTop
				}
	}
	return [curleft,curtop];
}

/* mark word and lookup tranlsation */
var ie5=document.all && !window.opera
var ns6=document.getElementById
document.onmouseup = evaluateSelection;
if (ie5||ns6) {   document.write('<div id="dynmenu" onMouseover="clearhidemenu();" onMouseout="dynamichide(event);"></div>'); }

function iecompattest() {   	 return (document.compatMode && document.compatMode.indexOf("CSS")!=-1)? document.documentElement : document.body }
function addScript(selection,coordX,coordY) {
	var t = document.getElementById('results');
	if(t!=null) return;
  if(typeof dix_page_language == "undefined") {    dix_page_language='de';  }
  if(typeof dix_url == "undefined") { dixurl='http://dix.osola.com'; }
  var obj = new JSONscriptRequest(dix_url + '/dix.php?search=' + selection + '&X=' + coordX + '&Y=' + coordY + '&lang=' + dix_page_language);
  obj.buildScriptTag();
  obj.addScriptTag();
}
function containsDix(a){
  while(a.parentNode){
    if(a.id=='dix' || a.tagName=='TEXTAREA' || a.tagName=='INPUT') return true;
    a = a.parentNode;
  }
  return false;
}

String.prototype.stripTags = function () {return this.replace(/<([^>]+)>/g,'');}
String.prototype.trim = function()       { return this.replace(/^\s+|\s+$/g, ""); };
function evaluateSelection (ev) {
	if (!ev)    ev = window.event;
	var t;
	if(ev.target) t = ev.target;
	else if(ev.srcElement) t = ev.srcElement;
	if (t.nodeType == 3)   t = t.parentNode; // defeat Safari bug
	if(containsDix(t)) return;
	if (window.getSelection) {       sel = window.getSelection();   } 
	else if (document.getSelection) {sel = document.getSelection(); } 
	else if (document.selection) {   sel = document.selection.createRange().text;   }
	if (sel != '') {// increase the probability that we find an answer: limit length, remove tags ...
		var s = sel+'';
		s = s.replace(/"/g, ' ');
		s = s.replace(/&nbsp;/g, ' ').stripTags().trim();
		s = s.replace(/(der |die |das |el |la |los |las |the |to |a )/gi,' ');
		s = s.trim();
		if( s.length<30 )
		addScript(s,ev.clientX,ev.clientY);   
	}
}

function showmenu(data) {
   if (!document.all && !document.getElementById) {  return   }
   clearhidemenu()

   content = '<table style="border:1px solid #'+cb+';background-color:#'+cbg+';" >'
   content += '<tr><td colspan="2" style="text-align:center;">' + data.head + '</td></tr><tr><td colspan="2"><table style="background-color:#FFFFF0;" width="100%" >';
   if (data.trans.length<1) {      content += '<tr><td style="text-align:center;">' + data.error + '</td></tr></tr>'   } 
   else {  for (i=0;i< data.trans.length;i++) {     content += '<tr><td width="50%"><a href="' +data.dixurl+ '?search=' +data.trans[i].l1w+ '">' +data.trans[i].l1+ '</a>&nbsp;</td><td>&nbsp;<a href="' +data.dixurl+ '?search=' +data.trans[i].l2w+ '">' +data.trans[i].l2+ '</a></td></tr>'     }   }
   content += '</table></td></tr><tr><td>' + data.more + '</td><td style="text-align:right;">&copy; <a href="http://www.osola.com/" target="_blank">DIX</a></td></tr></table>';
  
   X = data.coordX-10;
   Y = data.coordY-10;

   dynmenuobj = ie5? document.all.dynmenu : document.getElementById("dynmenu")
   dynmenuobj.innerHTML=content
   dynmenuobj.contentwidth=dynmenuobj.offsetWidth
   dynmenuobj.contentheight=dynmenuobj.offsetHeight

   var right=ie5? iecompattest().clientWidth-X : window.innerWidth-X
   var bottom=ie5? iecompattest().clientHeight-Y : window.innerHeight-Y
   if (right<dynmenuobj.contentwidth) {     dynmenuobj.style.left=ie5? iecompattest().scrollLeft+X-dynmenuobj.contentwidth+"px" : window.pageXOffset+X-dynmenuobj.contentwidth+"px"   } 
   else {     dynmenuobj.style.left=ie5? iecompattest().scrollLeft+X+"px" : window.pageXOffset+X+"px"   }
   if (bottom<dynmenuobj.contentheight) {     dynmenuobj.style.top=ie5? iecompattest().scrollTop+Y-dynmenuobj.contentheight+"px" : window.pageYOffset+Y-dynmenuobj.contentheight+"px"   } 
   else {     dynmenuobj.style.top=ie5? iecompattest().scrollTop+Y+"px" : window.pageYOffset+Y+"px"   }

   dynmenuobj.style.visibility="visible";
   return false
}

function contains_ns6(a, b) { while (b.parentNode)   if ((b = b.parentNode) == a) {     return true;   }   return false;}
function hidemenu(){   if (window.dynmenuobj) {     dynmenuobj.style.visibility="hidden"   } }
function dynamichide(e){  
	if 	(ie5&&!dynmenuobj.contains(e.toElement)) {    hidemenu()  } 
	else {    if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget)) {       hidemenu()    }  }
}
function delayhidemenu() {  delayhide=setTimeout("hidemenu()",500)}
function clearhidemenu() {  if (window.delayhide) {      clearTimeout(delayhide)  }}

function showinfomenu(right, lang, dix, obj, rowid, tracker, vote, lword, lwtype, rword, rwtype, canoo, dwds, conj, rae, hm){
   if (!document.all && !document.getElementById) {  return   }
   clearhidemenu()
   var offset = 0;
   addclass = '';
   if(right){
	   word = rword;
	   wtype = rwtype;
	   offset = -112;
	   addclass = 'infomenuleft';
   }
   else {
	   word = lword;
	   wtype = lwtype;
   }
   content = '<table class="infomenu '+addclass+' ">'
   if(vote==1){	 content += '<tr><td><div class="dropdownlink"><a href="vote.php' + urlsettings + 'v=r&amp;id=' + rowid + '" title="' +strr+ '" target="_top">' +labelr+ '</a></div></td></tr>'
	   	 content += '<tr><td><div class="dropdownlink"><a href="vote.php' + urlsettings + 'v=w&amp;id=' + rowid + '" title="' +strw+ '" target="_top">' +labelw+ '</a></div></td></tr>'
   }
   if(tracker>0)content += '<tr><td><div class="dropdownlink"><a href="tracker.php' + urlsettings + 'transid=' + rowid + '" title="' +strtracker+ '" target="_top">' +labeltracker+ '</a></div></td></tr>'
   if(lang=='DE'){
   if(canoo==1)  content += '<tr><td><div class="dropdownlink"><a href="l.php?v=' + word + '&amp;cat=' + wtype + '" title="' +strcanoo+ '" target="_blank">Canoo</a></div></td></tr>'
   if(dwds==1)   content += '<tr><td><div class="dropdownlink"><a href="l.php?v=' + word + '&amp;dwds=1" title="' +strdwds+ '" target="_blank">DWDS</a></div></td></tr>'
   if(dix=='de_es') {otherdix = 'http://www.woerterbuch-englisch.info/index.php'; ltrans = stren; }
   else             {otherdix = 'http://dix.osola.com/index.php'; ltrans = stres; }
   }
   else if(lang=='ES'){
   if(conj==1)   content += '<tr><td><div class="dropdownlink"><a href="v.php' + urlsettings + 'search=' + word + '" title="' +strconj+ '" target="_top">' +labelconj+ '</a></div></td></tr>'
   if(rae==1)    content += '<tr><td><div class="dropdownlink"><a href="r.php' + urlsettings + 'search=' + word + '" title="' +strrae+ '" target="_top">RAE</a></div></td></tr>'
   if(dix=='de_es') {otherdix = 'http://www.diccionario-ingles.info/index.php'; ltrans = stren; }
   else             {otherdix = 'http://dix.osola.com/index.php'; ltrans = strde; }
   }
   else if(lang=='EN'){
   if(hm==1)     content += '<tr><td><div class="dropdownlink"><a href="l.php?v=' + word + '&amp;hm=1" title="' +strhm+ '" target="_blank">' +labelhm+ '</a></div></td></tr>'
   if(dix=='en_de') {otherdix = 'http://www.dictionary-spanish.info/index.php'; ltrans = stres; }
   else             {otherdix = 'http://www.dictionary-german.info/index.php'; ltrans = strde; }
   }
   content += '<tr><td><div class="dropdownlink"><a href="search.php' + urlsettings + 'q=' + word + '&sa=Google+Search&client=pub-9996093703546080&forid=1&ie=ISO-8859-1&oe=ISO-8859-1&cof=GALT%3A%23'+ca+'%3BGL%3A1%3BDIV%3A%23'+cbg+'%3BVLC%3A'+cah+'%3BAH%3Acenter%3BBGC%3A'+cbg+'%3BLBGC%3A'+cbg+'%3BALC%3A000000%3BLC%3A000000%3BT%3A'+ct+'%3BGFNT%3A'+cah+'%3BGIMP%3A'+cah+'%3BFORID%3A11&hl='+lang+'" title="' +strgoogle+ '" target="_top">Google</a></div></td></tr>'
   content += '<tr><td><div class="dropdownlink"><a href="http://'+lang+'.wikipedia.org/wiki/Special:Search?search='+word+'&amp;go=Go" title="' +strwikipedia+ '" target="_blank">Wikipedia</a></div></td></tr>'		   
   content += '<tr><td><div class="dropdownlink"><a href="' + otherdix + urlsettings + 'search=' + word + '" title="' +labeltrans+' '+ltrans+'" target="_top">' +strto+' '+ltrans+ '</a></div></td></tr>'
   content += '</table>';
 
   var coors = findPos(obj);
   X = coors[0]+12+offset;
   Y = coors[1];
   
   dynmenuobj = ie5? document.all.dynmenu : document.getElementById("dynmenu")
   dynmenuobj.innerHTML=content
   dynmenuobj.style.left= X+"px"
   dynmenuobj.style.top= Y+"px"
   dynmenuobj.style.visibility="visible";
   return false	
}

// JSONscriptRequest -- a simple class for accessing Yahoo! Web Services
// using dynamically generated script tags and JSON
// Author: Jason Levitt
// Date: December 7th, 2005
// A SECURITY WARNING FROM DOUGLAS CROCKFORD:
// "The dynamic <script> tag hack suffers from a problem. It allows a page 
// to access data from any server in the web, which is really useful. 
// Unfortunately, the data is returned in the form of a script. That script 
// can deliver the data, but it runs with the same authority as scripts on 
// the base page, so it is able to steal cookies or misuse the authorization 
// of the user with the server. A rogue script can do destructive things to 
// the relationship between the user and the base server."
// So, be extremely cautious in your use of this script.

// Constructor -- pass a REST request URL to the constructor
function JSONscriptRequest(fullUrl) {
    // REST request path
    this.fullUrl = fullUrl; 
    // Keep IE from caching requests
    this.noCacheIE = '&noCacheIE=' + (new Date()).getTime();
    // Get the DOM location to put the script tag
    this.headLoc = document.getElementsByTagName("head").item(0);
    // Generate a unique script tag id
    this.scriptId = 'YJscriptId' + JSONscriptRequest.scriptCounter++;
}

// Static script ID counter
JSONscriptRequest.scriptCounter = 1;

// buildScriptTag method
JSONscriptRequest.prototype.buildScriptTag = function () {
    // Create the script tag
    this.scriptObj = document.createElement("script");
    // Add script object attributes
    this.scriptObj.setAttribute("type", "text/javascript");
    this.scriptObj.setAttribute("src", this.fullUrl + this.noCacheIE);
    this.scriptObj.setAttribute("id", this.scriptId);
}
 
// removeScriptTag method
JSONscriptRequest.prototype.removeScriptTag = function () {
    // Destroy the script tag
    this.headLoc.removeChild(this.scriptObj);  
}

// addScriptTag method
JSONscriptRequest.prototype.addScriptTag = function () {
    // Create the script tag
    this.headLoc.appendChild(this.scriptObj);
}

