﻿function winopen(node) { //node is either an <a> element, or an href
	var w = window.open((node.href ? node.href : node), '_blank', 'width=400,height=200,scrollbars=yes,resizable=yes') //,location=yes')
	w.focus()
}
function getElementClassAttribute(element) {
	return (element.getAttribute("class") ? element.getAttribute("class") /*firefox*/ 
		:  element.getAttribute("className") /*ie*/)
}
function movepopup(element, event) {
	function getElementClassAttribute(element) {
		return (element.getAttribute("class") ? element.getAttribute("class") /*firefox*/ 
			:  element.getAttribute("className") /*ie*/)
	}
	var posx = event.clientX
	var posy = event.clientY
	for (element = element.firstChild; element; element = element.nextSibling) {
		if ((element.nodeType != 3) && (getElementClassAttribute(element) == "shadow")) {
			element.setAttribute("style", "position:fixed; left:" + (posx + 20) + "px; top:" + (posy + 20) + "px;") //this works for firefox and opera
			element.style["position"] = "fixed"; element.style["left"] = (posx + 20); element.style["top"] = (posy + 20) //this works for ie and opera	
			break
		}
	}
}
/*function wordclick(element) {
	element = element.getElementsByTagName("SUB")[0];
	if (element.getAttribute("style")) element.setAttribute("style", null);
	else element.setAttribute("style", "display:inline");
}*/
function worddefn(lexicon_subdomain) {
	//note: laparola.net requires fully-accented word, so won't find word if accents and breathings have been removed

	//if (textprefsenabled && ! spaced) return //selection is bigger than than word
	if (window.getSelection) {
		var selection = window.getSelection()
		var word = selection.toString()
		var node= selection.anchorNode
		//var node= selection.focusNode
//alert(selection + "\nWORD:" + word + "\nANCHOR:" + node.nodeValue + "\nFOCUS:" + selection.focusNode.nodeValue)
	} else {
		var range = document.selection.createRange()
		var word = range.text
		var node = range.parentElement()
	}
	for (; true; node = node.parentNode) { //make sure selected word is in the "greek" column
		if (! node) return
//alert(node  +"\n" + node.nodeName + "\n" + node.nodeValue + "\n" + node.data + "\n" + node.lang)
		if (node.nodeName == 'TABLE') return
		if (node.nodeName == 'SUB') return //this only works in Opera
		if (node.nodeName == 'TD') if (getElementClassAttribute(node).match(/orig/) && (node.lang == 'grc' || node.lang.substr(0,2) == 'el')) break
		//if (node.nodeName == 'TD') if (getElementClassAttribute(node) == 'greek') break
	}
	if (word.indexOf(' ') > -1) word = word.substring(0, word.indexOf(' '))
	window.open(lexicon_subdomain + "index.php?search=" + word.replace(/[¶·«»]/, '')) //Ench 6:1 has all the punctuation marks
}
function enableStylesheet(id, flag) {
	var linkelement = document.getElementById(id)
	linkelement.rel = "stylesheet" /*ie6*/
	linkelement.disabled = ! flag //link element must have title attr set for this to work in Opera
}
function selectAll(ancestor, checked)
{
	inputelements = ancestor.getElementsByTagName('input');
	for (i = 0; i < inputelements.length; i++) if (inputelements.type = "checkbox") inputelements[i].checked = checked
}
