/* shows pointer by eric */
function pointer(element) {
	if (navigator.platform == "Win32" && navigator.appName == "Microsoft Internet Explorer") element.style.cursor = 'hand';
	else element.style.cursor = 'pointer';
}

function addEventListenerForObj(obj,evt,func,evtModel) {
	if(obj.addEventListener)
		obj.addEventListener(evt,func,evtModel);
	else
		eval('obj.on'+evt+'=func');
}

/* display status message by eric */
function dm(msgStr) {
window.status = msgStr;
}

/* display status message by eric, .type does not work with ie5win */
function linkMsg(theEvent) {
/*	if(theEvent.type == 'mouseover')
	{
		window.status = theEvent.target.title;
		return true;
	}
	else
	{
		window.status = '';
		return true;
	}*/
}

function setBg(theEvent) {
	if(theEvent.eventPhase == theEvent.AT_TARGET)
	{
		var theme,point;
		theElement = getEventElement(theEvent);
	
	/*find different element types*/
		if(theElement.type == 'button')
		{
			theBg = 'rgb(255,255,255)';
			theme = 'btn';
			point = true;
		}
		else if (theElement.className.search(/(^divSubContainerHead$|^divSubContainerHead )/) != -1)
		{
			theBg = 'rgb(230,230,230)';
			theme = 'head';
			point = true;
		}
		else if (theElement.className.search(/(^link$|^link )/) != -1)
		{
			theBg = 'rgb(230,230,230)';
			theme = 'link';
			point = true;
		}
		else if (theElement.className.search(/(^project$|^project )/) != -1)
		{
			theBg = 'rgb(240,240,240)';
			theme = 'project';
			point = true;
		}

	
	/*	theBg = theElement.style.backgroundColor;*/
		
		r = theBg.substring(theBg.indexOf('(')+1,theBg.indexOf('(')+4);
		g = theBg.substring(theBg.indexOf(',')+1,theBg.indexOf(',')+4);
		b = theBg.substring(theBg.lastIndexOf(')')-3,theBg.lastIndexOf(')'));
	
		theBgList = new Array(r,g,b);
		if (theme == 'head')
		{
			overAmount = 25;
			overDir = 1;
			downAmount = 100;
			downDir = 1;
		}
		else if (theme == 'btn')
		{
			overAmount = 100;
			overDir = 1;
			downAmount = 100;
			downDir = 0;
		}
		else if (theme == 'link')
		{
			overAmount = 100;
			overDir = 1;
			downAmount = 100;
			downDir = 0;
		}
		else if (theme == 'project')
		{
			overAmount = 10;
			overDir = 1;
			downAmount = 10;
			downDir = 0;
		}
		if (theEvent.type == 'mouseover')
		{
			if(point)
				pointer(theElement);
			
			for (i = 0; i <= 2; i++)
			{
				if (overDir==0)
					theBgList[i] = parseInt(theBgList[i])+overAmount;
				else
					theBgList[i] = parseInt(theBgList[i])-overAmount;
			}
		}
		else if (theEvent.type == 'mouseout' || theEvent.type == 'click')
		{
			for (i = 0; i <= 2; i++)
			{
				if (overDir==0)
					theBgList[i] = parseInt(theBgList[i])-overAmount;
				else
					theBgList[i] = parseInt(theBgList[i])+overAmount;
			}
		}
		else if(theEvent.type == 'mouseup')
		{
			for (i = 0; i <= 2; i++)
			{
				if (overDir==0)
					theBgList[i] = parseInt(theBgList[i])-downAmount;
				else
					theBgList[i] = parseInt(theBgList[i])+downAmount;
			}
		}
		else if (theEvent.type == 'mousedown')
		{	
			for (i = 0; i <= 2; i++)
			{
				if (overDir==0)
					theBgList[i] = parseInt(theBgList[i])+downAmount;
				else
					theBgList[i] = parseInt(theBgList[i])-downAmount;
			}
		}
		theElement.style.background = "rgb("+theBgList[0]+","+theBgList[1]+","+theBgList[2]+")";
	}
/*	else
		alert(theEvent.eventPhase);*/
}

/*gets the event-connected element (for ie and dom)*/
function getEventElement(theEvent) {
	if(isIE4)
	{
		var theEvent = window.event;
		var theElement = theEvent.srcElement;
	}
	else
	{
		var theElement = findOwner(theEvent);
//		var theElement = theEvent.target;
	}
	return theElement;
}

/*find the next parent node for an element.*/
function findOwner( evt )
{
    var node;
    if (isNav6)
    {
        node = evt.target;
        while (node)
        {
            if ( node.nodeType == Node.ELEMENT_NODE)
            {
                return node;
            }
            node = node.parentNode;
        }
    }
    else if (isIE4)
    {
        node = window.event.srcElement;
        while (node)
        {
            if (node.tagName == "div")
            {
                return node;
            }
            node = node.parentElement;
        }
    }
    return null;
}

function setDisplay(elementID,state)
{
	if(state == "hide")
	{
		document.getElementById(elementID).style.display = 'none';
	}
	else
	{
		document.getElementById(elementID).style.display = 'block';
	}
}

function autoSetDisplay(elementID)
{
	var theElement = document.getElementById(elementID);
	if(theElement.style.display != 'none')
	{
		theElement.style.display = 'none';
	}
	else
	{
		/*here the class of the tag should be parsed and hidden should be found*/
		theElement.style.display = 'block';
	}
}
