var DHTML   = false;
var DOM     = false;

var MSIE4   = false;
var NS4     = false;
var OP      = false;

var lastObj =  null;
var lastCol =  null;
var clckObj =  null;
var urlapp  =  null;

var tipaktiv  = false;
var infoaktiv = false;
var hideaktiv = false;
var tooltip   = false;
var infotip   = false;
var x = -1, y = -1;

if (document.getElementById) {
  DHTML = true;
  DOM = true;
} else {
  if (document.all) {
    DHTML = true;
    MSIE4 = true;
  } else {
    if (document.layers) {
      DHTML = true;
      NS4 = true;
    }
  }
}
if (window.opera) {
  OP = true;
}

function getElement (Mode, Identifier, ElementNumber) {
  var Element;
  if (DOM) {
    if (Mode.toLowerCase() == "id") {
      if (typeof document.getElementById(Identifier) == "object") {
        Element = document.getElementById(Identifier);
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") {
      var ElementList = document.getElementsByName(Identifier);
      if (typeof ElementList == "object" || (OP && typeof ElementList == "function")) {
        Element = ElementList[ElementNumber];
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      var ElementList = document.getElementsByTagName(Identifier);
      if (typeof ElementList == "object" || (OP && typeof ElementList == "function")) {
        Element = ElementList[ElementNumber];
      } else {
        Element = false;
      }
      return Element;
    }
    return null;
  }
  if (MSIE4) {
    if (Mode.toLowerCase() == "id") {
      if (typeof document.all[Identifier] == "object") {
        Element = document.all[Identifier];
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "tagname") {
      if (typeof document.all.tags(Identifier) == "object") {
        Element = document.all.tags(Identifier)[ElementNumber];
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "name") {
      if (typeof document[Identifier] == "object") {
        Element = document[Identifier];
      } else {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  if (NS4) {
    if (Mode.toLowerCase() == "id" || Mode.toLowerCase() == "name") {
      if (typeof document[Identifier] == "object") {
        Element = document[Identifier];
      } else {
        Element = false;
      }
      return Element;
    }
    if (Mode.toLowerCase() == "index") {
      if (typeof document.layers[Identifier] == "object") {
        Element = document.layers[Identifier];
      } else {
        Element = false;
      }
      return Element;
    }
    return false;
  }
  return false;
}

function getContent (Mode, Identifier, ElementNumber) {
  var Content;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    if (Element.firstChild.nodeType == 3) {
      Content = Element.firstChild.nodeValue;
    } else {
      Content = "";
    }
    return Content;
  }
  if (MSIE4) {
    Content = Element.innerText;
    return Content;
  }
  return false;
}

function getAttribute (Mode, Identifier, ElementNumber, AttributeName) {
  var Attribute;
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM || MSIE4) {
    Attribute = Element.getAttribute(AttributeName);
    return Attribute;
  }
  if (NS4) {
    if (typeof Element[ElementNumber] == "object") {
      Attribute = Element[ElementNumber][AttributeName];
    } else {
      Attribute = Element[AttributeName]
    }
    return Attribute;
  }
  return false;
}

function setContent (Mode, Identifier, ElementNumber, Text) {
  var Element = getElement(Mode, Identifier, ElementNumber);
  if (!Element) {
    return false;
  }
  if (DOM && Element.firstChild) {
    Element.firstChild.nodeValue = Text;
    return true;
  }
  if (MSIE4) {
    Element.innerText = Text;
    return true;
  }
  if (NS4) {
    Element.document.open();
    Element.document.write(Text);
    Element.document.close();
    return true;
  }
}

/**********************************
 * Hintergrund-Operationen
 **********************************/
function setPointClicked() {
	if(!OP || typeof obj.style.backgroundColor=="string") {
		lastObj.style.backgroundColor = '#FFBBBB';
		if(clckObj!=null &&  clckObj!=lastObj) {
			clckObj.style.backgroundColor = '#EEEEEE';
		}
	} else {
		lastObj.setAttribute('bgcolor', '#FFBBBB', 0);
		if(clckObj!=null &&  clckObj!=lastObj) {
			clckObj.setAttribute('bgcolor', '#EEEEEE', 0);
		}
	}
	clckObj = lastObj;
}
function destroyClicked() {
	if(urlapp!=null && clckObj!=null){
		if(!OP || typeof obj.style.backgroundColor=="string") {
			clckObj.style.backgroundColor = '#EEEEEE';
		} else {
			clckObj.setAttribute('bgcolor', '#EEEEEE', 0);
		}
		clckObj = null;
		window.focus();
	}
}
function setPoint(obj,bgc){
	if(lastObj) {
		if(!OP || typeof obj.style.backgroundColor=="string") {
			lastObj.style.backgroundColor = lastCol;
		} else {
			lastObj.setAttribute('bgcolor', lastCol, 0);
		}
	}
	lastObj = obj;
	if(clckObj==null || clckObj!=obj) {
		if(!OP || typeof obj.style.backgroundColor=="string") {
			lastCol = obj.style.backgroundColor;
			obj.style.backgroundColor = bgc;
		} else {
			lastCol = obj.getAttribute('bgcolor',0);
			obj.setAttribute('bgcolor', bgc, 0);
		}
	}
}
/**********************************
 * ToolTip - Informationen
 **********************************/
function updateToolTipPosition(e) {
	if(typeof window.event == "object") {
		x = window.event.x;
		y = window.event.y;
	} else {
		x = e.pageX;
		y = e.pageY;
	}
	setToolTipPosition();
}

function setToolTipPosition() {
	if (x!=-1 && y!=-1 && tooltip) {
		if(NS4) {
			tooltip.left = (x + 10) + "px";
			tooltip.top  = (y + 17) + "px";
		} else {
			tooltip.style.left = (x + 10) + "px";
			tooltip.style.top  = (y + 17) + "px";
		}
	}
}

function showToolTip(id) {
	tooltip  = getElement("id",id,null);
	tipaktiv = window.setTimeout("toolTip()", 500);
}

function toolTip() {
	if(tooltip) {
		setToolTipPosition();
		if(NS4) {
			tooltip.display = "block";
		} else {
			tooltip.style.display = "block";
		}
	}
}

function hideToolTip() {
	if(tipaktiv)
		window.clearTimeout(tipaktiv);
	if(tooltip) {
		if(NS4) {
			tooltip.display = "none";
		} else {
			tooltip.style.display = "none";
		}
		tooltip = false;
	}
}

function showInfo(id) {
	infotip = getElement("id",id,null); 
	infoaktiv = window.setTimeout("showInfoTip()", 500);
}

function showInfoTip() {
	if(infotip) {
		if(NS4) {
			infotip.display = "block";
		} else {
			infotip.style.display = "block";
		}
	}
}

function hideInfo(now) {
	if(infoaktiv) {
		window.clearTimeout(infoaktiv);
		infoaktiv = false;
	}
	hideInfoTip();
}

function hideInfoTip() {
	if(infotip) {
		if(NS4) {
			infotip.display = "none";
		} else {
			infotip.style.display = "none";
		}
		infotip = false;
	}
}

function creatToolTip(id,text) {
	document.writeln('<'+'div class="tooltip" id="'+id+'">');
	document.writeln('<'+'table cellspacing="0" cellpadding="0" border="0" class="tooltip_table"'+'>');
	document.writeln('<'+'tr'+'><'+'td class="tooltip_text" nowrap="nowrap"'+'>'+text+'<'+'/td'+'>'+'<'+'/tr'+'>');
	document.writeln('<'+'/table'+'><'+'/div'+'>');
}

document.onmousemove = updateToolTipPosition;
