var selrow;
var selrow2;
var rows = document.getElementsByTagName('tr');

/**
 * function checks if the popup window reference has opened correctly
 * In case the getElementById of the document is undefined an error message will be displayed
 */
function checkPopupBlocker(windowRef) {
	if( is_null(windowRef) || 
		!is_defined(windowRef.document) || 
		!is_defined(windowRef.document.getElementById)) {
		
		if( !is_null(windowRef) && is_defined(window.showModalDialog)){
			alert (_T('POPUP_ERROR_MESSAGE_IE'));
		} else {
			alert (_T('POPUP_ERROR_MESSAGE'));
		}
	} else {
		windowRef.focus();
	}
}

/**
 * handles highlighting stuff
 *
 * @param obj:HTMLElement, which fires the event
 * @param on:int [0,1] 0 means mouseout, 1 mouseover
 */
function rowhighlight( obj, action ) {
	var regEx = /^(\D.+\B)(\d)$/;
	var className = obj.className.trim();
	var classNames = [];
	if(className.indexOf(" ") != -1){
		classNames = className.split(" ");
		className = classNames[0];
		array_remove (classNames, 0);
	}
	var ret = regEx.exec(className);
	if(ret.length != 3){
		return;
	}
	obj.className = ret[1]+action + " " + classNames.join(" ");
}
/**
 * adds className highlight to given className
 * should be used on click for list-elments (tr, maybe it works on li)
 *
 * @param obj:HTMLElement, which fires the event
 */
function rowselect( obj ) {
	YDom.addClass (obj, "highlight");
	var rows = obj.parentNode.childNodes;
	for ( var i = 0; i < rows.length; ++i ) {
		if(obj == rows[i]){
			// active element
			continue;
		}
		YDom.removeClass (rows[i], "highlight");
	}
}

function removehighlight(id){
	var o = document.getElementById(id);
	if(!o){
		return;
	}
	YDom.removeClass (o, "highlight");
	var rows = o.childNodes;
	for ( var i = 0; i < rows.length; ++i ) {
		YDom.removeClass (rows[i], "highlight");
	}
}


// tooltip functions - START

var breite = 178;
var mausabstand = 15;
var ToolTippShow = false;
var ToolTipp = null;
var dir, b_Breite, b_Dir, b_VDir;

function setToolTipp (breite){
	document.onmousemove = cursorMove;
	if (breite && breite>20) {
		b_Breite = breite;
	}
	ToolTipp = crossGetObject('ToolTipp');
	ToolTippShow = false;

}

function showToolTipp(title,msg,rechtslinks,untenoben,breite,path){
    var b_Back;
	var relWidth, relHeight;
	if (ToolTipp === null) {
		return;
	}
	if (breite && breite>20) {b_Breite = breite;}
	else {b_Breite=178;}
    msg = '<table width="' + b_Breite + '" cellpadding="0" cellspacing="0" style="border:1px solid #485B7C; background-color:#FEEF92;"><tr><td style="vertical-align:top; width:20px;"><img src="/img/tooltipp_icon.gif" style="margin:3px 5px 0 4px;" alt=""></img></td><td style="padding:1px;"><table width="100%" border="0" cellpadding="0" cellspacing="0"><tr><th style="text-align:left;"><h3 style="margin:0 4px 0 0; font-family:Verdana,Helvetica,Arial,sans-serif; font-size:11px; font-weight:bold; color:#11435C; line-height:15px;"><b>'+title+'</b></h3></th></tr><tr><td><p style="margin:0 4px 0 0; font-family:Verdana,Helvetica,Arial,sans-serif; font-size:11px; font-weight:normal; color:#11435C; line-height:15px;">' + msg + '</span></td></tr></table></td></tr></table>';

	if (!dir) {b_Dir = rechtslinks;}
	else {b_Dir = dir;}
	relWidth = crossInnerWindowWidth() + crossGetScroll("x");
	relHeight = crossInnerWindowHeight() + crossGetScroll("y");
	if (crossMouseX + b_Breite + mausabstand > relWidth) {
		b_Dir = 1;
	}
	else if (crossMouseX < b_Breite + mausabstand) {
		b_Dir = 0;
	}
	b_VDir = untenoben;
	if (crossMouseY + 65 > relHeight) {
		b_VDir = 1;
	} else if (crossMouseY - 65 < 0)  {
		b_VDir = 0;
	}
	crossWrite(ToolTipp, msg);
	ToolTippShow = true;
	crossShowObject(ToolTipp);

}

function hideToolTipp(breite) {
	if (ToolTipp === null) {
		return;
	}
	crossHideObject(ToolTipp);
	ToolTippShow=false;
	crossMoveTo(ToolTipp, -178, 0);
}

function cursorMove(e) {
	var posX, posY;
	crossMousePosition(e);

	if(ToolTippShow){
		if(b_Dir===0){
			posX = crossMouseX + mausabstand;
			if (b_VDir===0) {posY = crossMouseY + mausabstand;}
			else {posY = crossMouseY - 65;}
		}else{
			posX = crossMouseX-b_Breite-mausabstand;
			if (b_VDir===0) {posY = crossMouseY + mausabstand;}
			else {posY = crossMouseY - 65;}
		}
		crossMoveTo(ToolTipp, posX, posY);
	}
}


var B_Type = new crossBrowserType();
function crossBrowserType() {
	this.IE = false;
	this.NS4 = false;
	this.NS6 = false;
	this.id = "";

	if (document.all) {this.IE = true; this.id = "IE";}
	else if (document.getElementById) {this.NS6 = true; this.id = "NS6";}
	else if (document.layers) {this.NS4 = true; this.id = "NS4";}
}

var crossMouseX, crossMouseY;
if (B_Type.NS4) {
	document.captureEvents(Event.MOUSEMOVE);
}

function crossMousePosition(e) {
	var evt = e || window.event;
	var pos = _getMouseXY(evt);
	crossMouseX=pos.x;
	crossMouseY=pos.y;
}

function _getMouseXY(ev) {
  var pos = {x:0, y:0};
  if(ev.pageX){
    pos.x = ev.pageX;
    pos.y = ev.pageY;
  } else if(window.event && window.event.clientX) {
    var isStrictMode = document.compatMode &&
		document.compatMode != 'BackCompat' ? true : false;
    var scrollX = isStrictMode ?
        document.documentElement.scrollLeft : document.body.scrollLeft;
    var scrollY	= isStrictMode ?
        document.documentElement.scrollTop : document.body.scrollTop;
    pos.x = window.event.clientX + scrollX;
    pos.y = window.event.clientY + scrollY;
  }
  return pos;
}

function crossGetObject(id) {
	var obj = null;
	if (B_Type.IE) {obj=document.all[id];}
	else if (B_Type.NS6) {obj=document.getElementById(id);}
	else if (B_Type.NS4) {obj=document.layers[id];}
	return obj;
}

function crossWrite(obj, text) {
	if (B_Type.IE) {obj.innerHTML = text;}
	else if (B_Type.NS6) {obj.innerHTML = text;}
}

function crossInnerWindowWidth() {
	var val;
	if (B_Type.IE) {val=document.body.clientWidth;}
	else if (B_Type.NS6) {val=window.innerWidth;}
	else if (B_Type.NS4) {val=window.innerWidth;}
	return val;
}

function crossOuterWindowWidth() {
	var val;
	if (B_Type.IE) {val=document.body.offsetWidth;}
	else if (B_Type.NS6) {val=window.outerWidth;}
	else if (B_Type.NS4) {val=window.outerWidth;}
	return val;
}

function crossInnerWindowHeight() {
	var val;
	if (B_Type.IE) {val=document.body.clientHeight;}
	else if (B_Type.NS6) {val=window.innerHeight;}
	else if (B_Type.NS4) {val=window.innerHeight;}
	return val;
}

function crossGetScroll(achse) {
	var val;
	if(!achse || achse == "y"){
		if (B_Type.IE) {val=document.body.scrollTop;}
		else if (B_Type.NS6) {val=window.pageYOffset;}
		else if (B_Type.NS4) {val=window.pageYOffset;}
	}else{
		if (B_Type.IE) {val=document.body.scrollLeft;}
		else if (B_Type.NS6) {val=window.pageXOffset;}
		else if (B_Type.NS4) {val=window.pageXOffset;}
	}
	return val;
}

function crossMoveTo(obj, x, y) {
	if (B_Type.IE) {obj.style.pixelLeft=x; obj.style.pixelTop=y;}
	else if (B_Type.NS4) {obj.left=x; obj.top=y;}
	else if (B_Type.NS6) {obj.style.left=x+"px"; obj.style.top=y+"px";}
}

function crossShowObject(obj) {
	if (B_Type.IE || B_Type.NS6) {obj.style.visibility="visible";}
	else if (B_Type.NS4) {obj.visibility="show";}
}

function crossHideObject(obj) {
	if (B_Type.IE || B_Type.NS6) {obj.style.visibility="hidden";}
	else if (B_Type.NS4) {obj.visibility="hide";}
}

// tooltip functions - END

function avoidNonNumerics(evt){
	var e = evt || window.event;
	var target = e.srcElement || e.target;

	target.value = target.value.replace(/\D/, '');
}

/**
 * Wrapper-Funktion für wt_sendinfo. Tracken von Klicks auf Links, bei denen die Seite
 * nicht verlassen wird.
 */
function ft_sendInfo(clickName, action){
  var wt = WEBTREKK_BEREICH ? WEBTREKK_BEREICH : "";
  clickName = wt + clickName;
  wt_sendinfo(clickName, action);
}

/**
 * Manipuliert das name-Attribut eines Links. Um den Namen dynamisch
 * zusammenzusetzen.
 */
function ft_setWtName(evt){
  var e = evt || window.event;
  var a = evt.target || evt.srcElement;
  var wt = WEBTREKK_BEREICH ? WEBTREKK_BEREICH : "";
  if(a.name.indexOf(WEBTREKK_BEREICH) !== 0){
	a.name = wt + a.name;
  }
}

function addBookmark(url, title){
	if(window.external && typeof window.external.AddFavorite != 'undefined'){
		window.external.AddFavorite(url, title);
	}
}

function bAbleToBookmark() {
	if (window.external && typeof window.external.AddFavorite != 'undefined') {
		return true;
	}
}

