// JavaScript Document

var layer;
var style;
var browser;

var browserType=navigator.appName;
if(browserType=='Microsoft Internet Explorer') {
  browser='ie';
  layer='all';
  style='.style';
}
else
if(browserType=='Netscape') {
  browser='net';
  layer='layers';
  style='';
}

var isDHTML=0;
var idI=0;
var isAll=0;
var isLayers=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]);
  }
  else {
    if(isId) 
	  return (document.getElementById(objectId));
	else
	  if(isAll)
	    return (document.all[objectId]);
	  else
	    if(isLayers)
	      return (document.layers[objectId]); 
  }	  
}

function findDOM_frame(objectId, withStyle, frame, is_top) {
  if(is_top==-1) {
    if(withStyle==1) {
      if(isId) 
	    return (window.top.frames[frame].document.getElementById(objectId).style);
	  else
	    if(isAll)
	      return (window.top.frames[frame].document.all[objectId].style);
	    else
	      if(isLayers)
	        return (window.top.frames[frame].document.layers[objectId]);
    }
    else {
      if(isId) 
	    return (window.top.frames[frame].document.getElementById(objectId));
	  else
	    if(isAll)
	      return (window.top.frames[frame].document.all[objectId]);
	    else
	      if(isLayers)
	        return (window.top.frames[frame].document.layers[objectId]); 
    }	  
  }
  else {
    if(withStyle==1) {
      if(isId) 
	    return (window.parent.frames[frame].document.getElementById(objectId).style);
	  else
	    if(isAll)
	      return (window.parent.frames[frame].document.all[objectId].style);
	    else
	      if(isLayers)
	        return (window.parent.frames[frame].document.layers[objectId]);
    }
    else {
      if(isId) 
	    return (window.parent.frames[frame].document.getElementById(objectId));
	  else
	    if(isAll)
	      return (window.parent.frames[frame].document.all[objectId]);
	    else
	      if(isLayers)
	        return (window.parent.frames[frame].document.layers[objectId]); 
    }	  
  }
}

function findDOM_parent(objectId, withStyle) 
{
    if(withStyle==1) 
	{
      if(isId) 
	    return (window.parent.document.getElementById(objectId).style);
	  else if(isAll)
	      return (window.parent.document.all[objectId].style);
	  else if(isLayers)
	      return (window.parent.document.layers[objectId]);
    }
    else 
	{
      if(isId) 
	    return (window.parent.document.getElementById(objectId));
	  else if(isAll)
	    return (window.parent.document.all[objectId]);
	  else if(isLayers)
	    return (window.parent.document.layers[objectId]); 
    }	  
}

function applyStyle(obj, prop, value, type) {
	var temp = findDOM(obj, type);
	eval("temp." + prop + " = '" + value + "'");
}

function getStyle(obj, prop, type) {
	var temp = findDOM(obj, type);
	eval("var ret = temp." + prop);
	return ret;
}

function applyStyleParent(obj, prop, value, type) {
	var temp = findDOM_parent(obj, type);
	eval("temp." + prop + " = '" + value + "'");
}

function getStyleParent(obj, prop, type) {
	var temp = findDOM_parent(obj, type);
	eval("var ret = temp." + prop);
	return ret;
}

function resizeToHeight(offset) {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight>0) {
			var tmp = findDOM('content', 0);
			var contentHeight = tmp.offsetHeight;
			window.resizeBy(0, contentHeight + offset - getWindowHeight());
		}
	}
}

function getWindowHeight() {
	var myWidth = 0, myHeight = 0;
	if (typeof(window.innerWidth) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else 
		if (document.documentElement &&
			(document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} 
		else 
			if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
	
	return myHeight;
}

function getWindowWidth() {
	var myWidth = 0, myHeight = 0;
	if (typeof(window.innerWidth) == 'number' ) {
		//Non-IE
		myWidth = window.innerWidth;
		myHeight = window.innerHeight;
	} 
	else 
		if (document.documentElement &&
			(document.documentElement.clientWidth || document.documentElement.clientHeight)) {
			//IE 6+ in 'standards compliant mode'
			myWidth = document.documentElement.clientWidth;
			myHeight = document.documentElement.clientHeight;
		} 
		else 
			if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
				//IE 4 compatible
				myWidth = document.body.clientWidth;
				myHeight = document.body.clientHeight;
			}
	
	return myWidth;
}

function centerWindow() {
	var size = new Array(2);
	size[0] = getWindowWidth();
	size[1] = getWindowHeight();
	window.moveTo(Math.round(screen.width/2 - size[0]/2), Math.round(screen.height/2 - size[1]/2));
}

function stick(evnt) {
  	var toolTip = findDOM('tooltip', 1);
	if (browser == 'ie') {
		toolTip.left = parseInt(event.clientX + 9 + document.body.scrollLeft) + 'px';
		toolTip.top = parseInt(event.clientY + 17 + document.body.scrollTop) + 'px';
  	}
  	else {
		toolTip.left = parseInt(evnt.pageX + 9) + 'px';
		toolTip.top = parseInt(evnt.pageY + 17) + 'px';
  	}
  	return true;
}

function initToolTip() {
	document.write('<div id="tooltip" style="position:absolute; border: solid 1px; background-color:#ede6c5; color:black; width:0px; padding:3px; z-index:100; font-size:10px; filter: alpha(opacity=0); -moz-opacity:0%"></div>');
	setAlpha('tooltip', 0);
}

function setToolTip(id, text) {
	var elem = findDOM(id, 0);
	elem.onmouseover = function() {
		if(typeof(fadeInt) != 'undefined')
			clearInterval(fadeInt);
		setAlpha('tooltip', 0);
		curr_fade = 0;
		applyStyle('tooltip', 'width', 250 + 'px', 1);
		applyStyle('tooltip', 'innerHTML', text, 0);
		fadeInt = setInterval('doFade(0)', 1);
	}
	elem.onmouseout = function() {
		if(typeof(fadeInt) != 'undefined')
			clearInterval(fadeInt);
		fadeInt = setInterval('doFade(1)', 1);
	}
	elem.onmousemove = function(event) {
		stick(event);
	}
}

function setAlpha(id, opacity) {
	element = findDOM(id, 0);
	if (typeof(element.filters) == 'object')
	{
		element.filters.alpha.opacity = opacity;
	}
	else if (element.style.setProperty)
	{
		element.style.setProperty('-moz-opacity', opacity / 100, '');
	}
}

var curr_fade = 0;

function doFade(type) { // 0 fade in, 1 fade out
	if(type && curr_fade <= 0) {
		clearInterval(fadeInt);
		applyStyle('tooltip', 'innerHTML', '', 0);
		applyStyle('tooltip', 'width', 0 + 'px', 1);
		return 0;
	}
	if(!type && curr_fade >= 100) {
		clearInterval(fadeInt);
		return 0;
	}

	if(type)
		curr_fade -= 5;
	else
		curr_fade += 2;
	setAlpha('tooltip', curr_fade);
}

function returnEvent(evt) {
	e = (evt) ? evt : (window.event) ? event : null;

	if (e.keyCode) 
		code = e.keyCode;
	else
		if (e.which) 
			code = e.which;

	return code;
}

function isMouseLeaveOrEnter(e, handler) { 
	if (e.type != 'mouseout' && e.type != 'mouseover') 
		return false; 
	var reltg = e.relatedTarget ? e.relatedTarget : e.type == 'mouseout' ? e.toElement : e.fromElement; 
	while (reltg && reltg != handler) 
		reltg = reltg.parentNode; 
	return (reltg != handler); 
}