function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_findObj(n, d) { //v3.0
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function openrefwindow() {
   	var myurl = window.location.href;
   	var reffile = document.forms.RefFrm.REF_LINK.value;
   	if (myurl.indexOf("deutsch") != -1) {
   		var refwindow = window.open("/deutsch/html/references/"+reffile, "dialog", "height=390,width=600,scrollbars=1,resizable=1");
   	} else { 
   		var refwindow = window.open("/english/html/references/"+reffile, "dialog", "height=390,width=600,scrollbars=1,resizable=1");
	}
   	if (navigator.appName == "Netscape")    {
   	    refwindow.focus();
   	}
}

function btnback(){
	history.back();
}

 var isDHTML = 0;
 var isLayers = 0;
 var isAll = 0;
 var isID = 0;
 
 if (document.getElementById) 
 {
	isID = 1; 
	isDHTML = 1;
 }
 else 
 {
	if (document.all) 
	{
		isAll = 1; 
		isDHTML = 1;
	}
	else 
	{
		browserVersion = parseInt(navigator.appVersion);
		if ((navigator.appName.indexOf('Netscape') != -1) && (browserVersion == 4)) 
		{
			isLayers = 1; 
			isDHTML = 1;
		}
	}
 }
 
 function findDOM(objectID,withStyle) 
 {
	if (withStyle == 1) 
	{
		if (isID) 
		{ 
			return (document.getElementById(objectID).style) ; 
		}
		else 
		{ 
			if (isAll) 
			{ 
				return (document.all[objectID].style); 
			}
			else 
			{
				if (isLayers) 
				{ 
					return (document.layers[objectID]); 
				}
			};
		}
	}
	//without style
	else 
	{
		if (isID) 
		{ 
			return (document.getElementById(objectID)) ; 
		}
		else 
		{ 
			if (isAll) 
			{ 
				return (document.all[objectID]); 
			}
			else 
			{
				if (isLayers) 
				{ 
					return (document.layers[objectID]); 
				}
			};
		}
	}
 }

 
 function setVisibility(ObjectID, state)
 {
	var Obj = findDOM(ObjectID, 1);
	Obj.visibility = state;
 }


function toggleVisibility(ObjectID)
{
	var Obj = findDOM(ObjectID, 1);
	var currentState = Obj.visibility;
	if (currentState == "hidden")
	{
		setVisibility(ObjectID, "visible");
	}
	else
	{
		setVisibility(ObjectID, "hidden");
	}
}

function setDisplay(ObjectID, state)
{
	var Obj = findDOM(ObjectID, 1);
	Obj.display = state;
}
 

function toggleDisplay(ObjectID)
{
	var Obj = findDOM(ObjectID, 1);
	var currentState = Obj.display;
	if (currentState == "none")
	{
		setDisplay(ObjectID, "block");
		setVisibility(ObjectID, "visible");
	}
	else
	{
		setDisplay(ObjectID, "none");
		setVisibility(ObjectID, "hidden");
	}
}

function addScrollingDiv()
{
		
	//if we are not in netscape place textbody contents into a scrolling div
	var isNS = 0;
	var browVer = 0;
	if(navigator.appName.indexOf('Netscape') != -1)
	{
		isNS = 1;

		//give up on detecting which Netscape since it doesn't work properly in 7.0 anyway 
		//	alert (navigator.userAgent);
		//	var pos = navigator.userAgent.indexOf('Netscape') + 8;
		//	verString = navigator.userAgent.substr(pos);
		//	var browVer = verString.substr(1,3);
		//	alert(browVer);
	}
	if (isNS == 0)
	{
		if (document.getElementById('mytext'))
		{
			return;
		}
        	var newDiv = document.createElement('div');
        	newDiv.id = "mytext";
		var tableObj = document.getElementById('textbody');
		var divObj = document.getElementById('toolbar');
		divObj.parentNode.appendChild(newDiv);
		newDiv.appendChild(tableObj);
		tableObj.style.position = 'absolute'; 
		tableObj.style.left = '0px'; 
		tableObj.style.top = '0px'; 
		if (document.URL.indexOf('#Page') != -1)
		{
			document.URL = '#Page';
			divObj.scrollTop = divObj.scrollTop + 150;
		}
		
	}
}
function storeCaret (textEl) {
  if (textEl.createTextRange)
    textEl.caretPos = document.selection.createRange().duplicate();
}

function insertAtCaret (textEl, text) {
  if (textEl.createTextRange && textEl.caretPos) {
    var caretPos = textEl.caretPos;
    caretPos.text =
      caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?
        text + ' ' : text;
  }
  else
     textEl.value  = text;
}

function translateKey(evnt) {
var charcode;
var isNS = (navigator.appName.indexOf('Netscape') != -1);
var keyInput = 0;
if (isNS)
{
	keyInput = evnt.which;
}
else
{
	keyInput = event.keyCode;
}
switch(keyInput)
{
	case 65://A
	charcode = 0x3b1;
	break;
	case 66://B
	charcode = 0x3b2;
	break;
	case 67://C
	charcode = 0x3c7;
	break;
	case 68://D
	charcode = 0x3b4;
	break;
	case 69://E
	charcode = 0x3b5;
	break;
	case 70://F
	charcode = 0x3c6;
	break;
	case 71://G
	charcode = 0x3b3;
	break;
	case 72://H
	charcode = 0x3b7;
	break;
	case 73://I
	charcode = 0x3b9;
	break;
	case 74://J
	charcode = 0x3ba;
	break;
	case 75://K
	charcode = 0x3ba;
	break;
	case 76://L
	charcode = 0x3bb;
	break;
	case 77://M
	charcode = 0x3bc;
	break;
	case 78://N
	charcode = 0x3bd;
	break;
	case 79://O
	charcode = 0x3bf;
	break;
	case 80://P
	charcode = 0x3c0;
	break;
	case 81://Q
	charcode = 0x3b8;
	break;
	case 82://R
	charcode = 0x3c1;
	break;
	case 83://S
	charcode = 0x3c3;
	break;
	case 84://T
	charcode = 0x3c4;
	break;
	case 85://U
	charcode = 0x3c5;
	break;
	case 86://V
	charcode = 0x3c6;
	break;
	case 87://W
	charcode = 0x3c9;
	break;
	case 88://X
	charcode = 0x3be;
	break;
	case 89://Y
	charcode = 0x3c8;
	break;
	case 90://Z
	charcode = 0x3b6;
	break;
	case 97://a
	charcode = 0x3b1;
	break;
	case 98://b
	charcode = 0x3b2;
	break;
	case 99://c
	charcode = 0x3c7;
	break;
	case 100://d
	charcode = 0x3b4;
	break;
	case 101://e
	charcode = 0x3b5;
	break;
	case 102://f
	charcode = 0x3c6;
	break;
	case 103://g
	charcode = 0x3b3;
	break;
	case 104://h
	charcode = 0x3b7;
	break;
	case 105://i
	charcode = 0x3b9;
	break;
	case 106://j
	charcode = 0x3ba;
	break;
	case 107://k
	charcode = 0x3ba;
	break;
	case 108://l
	charcode = 0x3bb;
	break;
	case 109://m
	charcode = 0x3bc;
	break;
	case 110://n
	charcode = 0x3bd;
	break;
	case 111://o
	charcode = 0x3bf;
	break;
	case 112://p
	charcode = 0x3c0;
	break;
	case 113://q
	charcode = 0x3b8;
	break;
	case 114://r
	charcode = 0x3c1;
	break;
	case 115://s
	charcode = 0x3c3;
	break;
	case 116://t
	charcode = 0x3c4;
	break;
	case 117://u
	charcode = 0x3c5;
	break;
	case 118://v
	charcode = 0x3c6;
	break;
	case 119://w
	charcode = 0x3c9;
	break;
	case 120://x
	charcode = 0x3be;
	break;
	case 121://y
	charcode = 0x3c8;
	break;
	case 122://z
	charcode = 0x3b6;
	break;
	default:
	charcode = 0;
	break;
}
//alert(document.ACCFORM.Accelerator.value);
if (!isNS)
{
//	document.selection.clear();
}
if (charcode > 0)
{
	if (isNS)
	{
		sText = String.fromCharCode(charcode);
		document.forms['ACCFORM'].elements[0].value = document.forms['ACCFORM'].elements[0].value + sText;
		return false;
	}
	else
	{
		event.keyCode = charcode;
	}
}
else
{
	return true;
}
}

function context_toc()
{
	if (document && document.forms && document.forms.ContextFrm)
  	{
  		if (document.forms.ContextFrm.CONTEXT_TOC)
  		{
  			if (document.forms.ContextFrm.CONTEXT_TOC.value)
  			{
  				var urlstring = document.forms.ContextFrm.CONTEXT_TOC.value;
  				if (urlstring && (urlstring.length > 0) && (urlstring.indexOf('!--') <= 0))
  				{
  					var strlength = urlstring.length;
  					var tocref=urlstring.slice(9,strlength-2);
  					window.location=tocref;
  				}
  			}
  		}
  	}
}

function text_only()
{
	if (document && document.location.href)
  	{
  		var locn = document.location.href;
  		var loc1 = locn;
  		if (locn.indexOf('#') > 0)
  		{
  			loc1 = locn.replace(/\#(.*)$/, '');
  		}		
  		document.location=loc1 + '&PRINT=yes&ALL=Y&WARN=N';
  	}
}

function new_search()
{
	setCrossSearchCookieOff();
  	document.location='search';
}

function focusAccelField()
{
//document.forms[0].elements[0].focus(); 
}

function dummyErrorHandler()
{
	return true;
}

function do_cross_search(cs)
{
	//onerror = dummyErrorHandler;
	var crosssearching = false;
	
	//if we are initialising (cs = 0) then check the value of the cookie
	if (cs == 0)
	{
		crosssearching = isCrossSearchCookieTrue();
	}
	if ((cs == 1) || crosssearching)
	{
		//show the Cross Search form
		setDisplay('SearchFormDiv', 'none');	
		setDisplay('CrossSearchFormDiv', 'block');	
		document.forms['CrossSearchForm'].elements['CROSSSEARCH'].checked=true;
		if (document.forms['CrossSearchForm'].elements['KEY'].value == '')
		{
			document.forms['CrossSearchForm'].elements['KEY'].value = document.forms['SearchForm'].elements['KEY'].value;
		}
		if (document.forms['CrossSearchForm'].elements['GREEK'].value == '')
		{
			document.forms['CrossSearchForm'].elements['GREEK'].value = document.forms['SearchForm'].elements['GREEK'].value;
		}
		if (document.forms['CrossSearchForm'].elements['TITLE'].value == '')
		{
			document.forms['CrossSearchForm'].elements['TITLE'].value = document.forms['SearchForm'].elements['TITLE'].value;
		}
		document.forms['CrossSearchForm'].elements['KEY'].focus();
		setCrossSearchCookieOn();
	}
	else
	{
		//show the Search Form
		setDisplay('SearchFormDiv', 'block');	
		setDisplay('CrossSearchFormDiv', 'none');
		document.forms['SearchForm'].elements['CROSSSEARCH'].checked=false;
		if (document.forms['SearchForm'].elements['KEY'].value == '')
		{
			document.forms['SearchForm'].elements['KEY'].value = document.forms['CrossSearchForm'].elements['KEY'].value;
		}
		if (document.forms['SearchForm'].elements['GREEK'].value == '')
		{
			document.forms['SearchForm'].elements['GREEK'].value = document.forms['CrossSearchForm'].elements['GREEK'].value;
		}
		if (document.forms['SearchForm'].elements['TITLE'].value == '')
		{
			document.forms['SearchForm'].elements['TITLE'].value = document.forms['CrossSearchForm'].elements['TITLE'].value;
		}
		document.forms['SearchForm'].elements['KEY'].focus();
		setCrossSearchCookieOff();
	}
	//initialise the summary som
	do_summary_som(2);
}

function do_summary_som(ss)
{
	//onerror = dummyErrorHandler;
	//alert(ss);
	var summarysom = false;
	//if we are initialising (ss = 2) then check the value of the cookie
	if (ss == 2)
	{
		summarysom = isSummarySomCookieTrue();
	}
	//alert(summarysom);
	if ((ss == 1) || summarysom)
	{
		if (document.forms['CrossSearchForm'].elements['CROSSSEARCH'].checked)
		{
			//alert('Setting CrossSearch source to cross_search_summary');
			document.forms['CrossSearchForm'].elements['SOURCE'].value = "cross_search_summary.cfg";
			document.forms['CrossSearchForm'].elements['SIZE'].value = "100";
		}
		else
		{
			//alert('Setting Search source to summary');
			document.forms['SearchForm'].elements['SOURCE'].value = "summary.cfg";
			document.forms['SearchForm'].elements['SIZE'].value = "100";
		}
		
		setSummarySomCookieOn();
	}
	else
	{
		if (document.forms['CrossSearchForm'].elements['CROSSSEARCH'].checked)
		{
			document.forms['CrossSearchForm'].elements['SOURCE'].value = "cross_search.cfg";
			document.forms['CrossSearchForm'].elements['SIZE'].value = "10";
		}
		else
		{
			document.forms['SearchForm'].elements['SOURCE'].value = "config.cfg";
			document.forms['SearchForm'].elements['SIZE'].value = "10";
		}
		
		setSummarySomCookieOff();
	}
	
}

function isCrossSearchCookieTrue()
{
	var retVal = false;
	var allCookies = document.cookie;
	var pos = allCookies.indexOf("crosssearch=");
	if(pos != -1)
	{
		var start = pos + 12;
		var end = allCookies.indexOf(";", start);
		if (end == -1) end = allCookies.length;
		var value = allCookies.substring(start, end);
		if (value > 0)
			retVal = true;
	}
	return retVal;
}


function setCrossSearchCookieOn()
{
	document.cookie = "crosssearch=1";
}

function setCrossSearchCookieOff()
{
	document.cookie = "crosssearch=0";
}

function isSummarySomCookieTrue()
{
	var retVal = false;
	var allCookies = document.cookie;
	var pos = allCookies.indexOf("summarysom=");
	if(pos != -1)
	{
		var start = pos + 11;
		var end = allCookies.indexOf(";", start);
		if (end == -1) end = allCookies.length;
		var value = allCookies.substring(start, end);
		if (value > 0)
			retVal = true;
	}
	return retVal;
}


function setSummarySomCookieOn()
{
	document.cookie = "summarysom=1";
}

function setSummarySomCookieOff()
{
	document.cookie = "summarysom=0";
}

function keyDown(evnt)
{
	var keyInput = 0;
	if (isNS)
	{
		keyInput = evnt.which;
	}
	else
	{
		keyInput = event.keyCode;
	}
  if (keyInput == 13)
  {
    var newInput = document.createElement('input');
    newInput.id = "SEARCH";
    newInput.name = "SEARCH";
  	var formObj;
  	if (isCrossSearchCookieTrue())
  	{
		formObj = document.getElementById('CrossSearchForm');
		formObj.appendChild(newInput);
    	document.CrossSearchForm.DEFAULTACTION.onclick();
  		return false;
    }
    else
  	{
		formObj = document.getElementById('SearchForm');
		formObj.appendChild(newInput);
    	document.SearchForm.DEFAULTACTION.onclick();
  		return false;
    }
  }
}

var w1 = null, is_nav = 0, is_nav3 = 0, is_nav4 = 0, is_nav4up = 0, is_ie  = 0;       
var is_ie3 = 0, is_ie4 = 0, is_ie4up = 0, is_ie5 = 0, is_ie5up = 0;

function DetermineBrowserTypeVersion()
{
   	var agt=navigator.userAgent.toLowerCase(); 
		   
   	// Note: On IE5, these return 4, so use is_ie5up to detect IE5. 
   	var is_major = parseInt(navigator.appVersion); 
   	var is_minor = parseFloat(navigator.appVersion); 
	
   	// Navigator Checks
   	is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('compatible') == -1)); 
   	if( is_nav )
   	{
    	is_nav3 = (is_nav && (is_major == 3)); 
     	is_nav4 = (is_nav && (is_major == 4)); 
     	is_nav4up = (is_nav && (is_major >= 4)); 
    }
	
	// IE Checks
	is_ie   = (agt.indexOf("msie") != -1); 				
	if( is_ie )
	{
	  	is_ie3  = (is_ie && (is_major < 4)); 
      	is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) ); 
        is_ie4up  = (is_ie  && (is_major >= 4)); 
        is_ie5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) ); 
        is_ie5up  = (is_ie  && !is_ie3 && !is_ie4); 	
	}
}
						
function openSatellite(framename, attribs, newurl)
{
	Window.open(newurl, framename, attribs);
}
	
function CreateSatellite( theURL, name, width, height, center, options )
{
	DetermineBrowserTypeVersion()

	// Different Browsers have different ways to get the 
	// position and size of the browser window.
	if( is_nav4up && center )
	{
	 	var x = window.screenX;
      	var y = window.screenY;
	  	var w = window.outerWidth;
	  	var h = window.outerHeight;
	  	var midx = x + (w - width)/2; 
	  	var midy = y + (h - height)/2; 	
		w1 = window.open( theURL, name, "left=" + midx + ",top=" + midy + ",height="+ height + ",width=" +  width + options );
	}
	else if( is_ie5up && center ) 
	{
		var x = window.screenLeft;
       	var y = window.screenTop;
		var w = document.body.clientWidth;
	 	var h = document.body.clientHeight;
		var midx = x + (w - width)/2; 
		var midy = y + (h - height)/2; 	
    
    	// Next bit forces IE5 to give focus and display the window in the correct position
	  	if( w1 != null && !w1.closed )
	  	{
	  		w1.close(); w1 = null;
	  	}			    
   		w1 = window.open(theURL, name, "left=" + midx + ",top=" + midy + ",height="+ height + ",width=" +  width + options );
	}
	else
	{  
	   	// Older browsers can't determine browser window pos/size and IE4 has probs
		// closing and re-opening a window  	      
		w1 = window.open(theURL, name, "height="+ height + ",width=" +  width + options );
	}
	w1.focus();
}
		
function OpenLexicon()
{
	var options = ",location=no,menubar=no,resizable=no,status=no,toolbar=no,copyhistory=no,directories=no,scrollbars=yes";
	var w = 500, h = 550;

	CreateSatellite( "/lexicon/search", "SATELLITE", w, h, true, options );
				
} 

function HideHeadword()
{
	setDisplay('HeadwordDiv', 'none');	
	setDisplay('HeadwordDiv1', 'none');	
	setDisplay('HeadwordDiv2', 'none');	
}

function ShowHeadword()
{
	setDisplay('HeadwordDiv', 'block');	
	setDisplay('HeadwordDiv1', 'block');	
	setDisplay('HeadwordDiv2', 'block');	
}

function check_options()
{
	if (document.forms['DICTFORM'].elements['OPTIONS1'].value == 'O_IndexOnly')
	{
		HideHeadword();
		document.forms['DICTFORM'].elements['SOURCE'].value = 'index.cfg';
	}
	else
	{
		ShowHeadword();
		document.forms['DICTFORM'].elements['SOURCE'].value = 'config.cfg';
	}
}

function isOldBrowser()
{
	var isIE55 = 0;
	var isIE6 = 0;
	var isNS6 = 0;
	var isNS7 = 0;
	var userAgent = navigator.userAgent;
//	alert(userAgent);
	if (userAgent.indexOf('MSIE 5.5') > 0)
		isIE55 = 1;
	if (userAgent.indexOf('MSIE 6') > 0)
		isIE6 = 1;
	if (userAgent.indexOf('Netscape6') > 0)
		isNS6 = 1;
	if (userAgent.indexOf('Netscape/7') > 0)
		isNS7 = 1;
//	if (isIE55)
//		alert('IE 5.5');
//	if (isIE6)
//		alert('IE 6');
//	if (isNS6)
//		alert('NS 6');
//	if (isNS7)
//		alert('NS 7');
	return (!isIE55 && !isIE6 && !isNS6 && !isNS7)	
}

function warnOldBrowsers()
{
	if (isOldBrowser())	
		alert('Please note that this site uses dynamic HTML and browsers below IE 5.5 and Netscape 6 are not supported.');
}