var global = window.document
var MENU_BORDER_COLOR = '#999999'
var MENU_CURRENTPAGE_COLOR = '#ffffff'
var MENU_MOUSEOVER_COLOR = '#cccccc'
var MENU_MOUSEDOWN_COLOR = '#999999'

function paletteFieldUpdate(fieldName) {
	paletteField = fieldName;
}

function colorFieldFill(color) {
	var colorObject = eval('document.all.frmParamters.'+paletteField+';');
	colorObject.value = color;
}		

function normalized_href(href)
{
	href = href.toLowerCase();
	var slash = href.lastIndexOf("/");
	if (-1 != slash) 
	{
		var filename = href.substr(slash + 1);
		if ("index.htm" == filename || "index.asp" == filename)
			href = href.substr(0, slash + 1);
	}
	return href;
}

function event_onload()
{
	if (!global.all) return
	
	var items = global.all.tags("TD")
	var i	
	var lhref = normalized_href(location.href)

	for (i=0; i<items.length; i++)
	{
		var item = items[i]
		if (item.className == "flyoutLink")
		{
			var disabled = false
			var anchors = item.all.tags("A")			
			if (anchors.length > 0)
			{
				var anchor = anchors.item(0)
				var ahref = normalized_href(anchor.href)				
				if (ahref == lhref)
				{
					anchor.outerHTML = anchor.innerHTML
					item.style.borderColor = MENU_BORDER_COLOR
					item.style.backgroundColor = MENU_CURRENTPAGE_COLOR
					item.style.cursor = 'default'
					disabled = true					
				}				
			}
			item.defaultBorder = item.style.borderColor
			item.defaultBackground = item.style.backgroundColor
			item.attachEvent("onmouseover", item_onmouseover)
			item.attachEvent("onmouseout", item_onmouseout)
			if (!disabled)
			{
				item.attachEvent("onmousedown", item_onmousedown)
				item.attachEvent("onmouseup", item_onmouseup)
			}			
		}
	}	
}



function item_onmouseover()
{	
	var e = whichItem()
	if (e.contains(window.event.fromElement))
		return
	if (e.style.backgroundColor != MENU_CURRENTPAGE_COLOR)
	{		
		e.style.borderColor = MENU_BORDER_COLOR
		e.style.backgroundColor = MENU_MOUSEOVER_COLOR
	}	
	var a = e.all.tags("A")
	if (a.length > 0)
		window.status = a[0].href
}

function item_onmouseout()
{	
	var e = whichItem()
	var te = window.event.toElement
	if (te)
		if (e.contains(te))
			return
	e.style.borderColor = e.defaultBorder
	e.style.backgroundColor = e.defaultBackground	
	window.status = ""
}

function whichItem()
{
	var e = event.srcElement
	while (e.tagName != "TD")
		e = e.parentElement
	return e
}

function item_onmousedown()
{	
	if ((event.button & 1) == 0)
		return;
	var e = whichItem()
	e.style.backgroundColor = MENU_MOUSEDOWN_COLOR
	e.mouseIsDown = 1
}

function item_onmouseup()
{	
	if ((event.button & 1) == 0)
		return;
	var e = whichItem()
	if (e.mouseIsDown != 1)
		return
	e.mouseIsDown = false
	e.style.backgroundColor = MENU_MOUSEOVER_COLOR
	var a = e.all.tags("A")
	if (a.length > 0)
		location.href = a[0].href
}

var message="Copyright 2005: aranes.org";
function click(e) {
if (document.all) {
if (event.button == 2) {
alert(message);
return false;
}
}
if (document.layers) {
if (e.which == 3) {
alert(message);
return false;
}
}
}
if (document.layers) {
document.captureEvents(Event.MOUSEDOWN);
}
document.onmousedown=click;


function disableselect(e){
//return false
}
function reEnable(){
return true
}
document.onselectstart=new Function ("return false")
if (window.sidebar){
document.onmousedown=disableselect
document.onclick=reEnable
}

var win = null;

function OpenAbreviacions()
{ 
	win=window.open('abreviacions.asp', 'abreviacions', 'resizable=no,scrollbars,height=200,width=200')
}

function OpenDiccionari(param1,param2,param3,param4)
{ 
if (param2.checked) psearchtype=""
if (param3.checked) psearchtype="AND"
if (param4.checked) psearchtype="OR"
if (param1.length>1)
{
	win=window.open('diccio2.asp?psearch=' + param1 + '&psearchtype=' + psearchtype + '&', 'diccionari', 'resizable=no,scrollbars,height=420,width=790')
}else{alert('Cau cercar un mínim de dues letres.')}
}

function ResetDiccionari()
{ 
	win=window.open('diccio.asp?cmd=reset', 'diccionari', 'resizable=no,scrollbars,height=420,width=790')
}

