/* hafas_utilities.js */
/* built: 16.05.2006 by CAG */
/* added: 21.02.2007 by MHEI */
/*        Date object enhancmends */


// Get absolute x-positon of any element
function getPosX(element){
  var curleft = 0;
  if (element.offsetParent){
     while (element.offsetParent){
        curleft += element.offsetLeft
        element = element.offsetParent;
     }
  }
  else if (element.x)	curleft += element.x;
  return curleft;
}

// Get absolute y-position of any element
function getPosY(element){
  var curtop = 0;
  if (element.offsetParent)	{
     while (element.offsetParent){
        curtop += element.offsetTop
        element = element.offsetParent;
     }
  }
  else if (element.y)	curtop += element.y;
  return curtop;
}

// IE6 FIX : only focus an element which is not hidden or in a hidden container
function safeFocus(element) {
	var parent = element.parentNode;
	var bFocus = true;
	// while parent node exists and isn't body or html tag
	while (parent) {
		if ((parent.tagName == "BODY") || (parent.tagName == "HTML")) {
			break;
		}
		// The parent node is hiddden this so this element is no good.
		if ((parent.style.display == "none") || (parent.style.visibility == "hidden")) {
			bFocus = false;
			break;
		}
		// climb up DOM tree
		parent = parent.parentNode;
	}
	if (bFocus) {
		element.focus();
	}
}


// Date object enhancements:
Date.prototype.getDaysInMonth = function() {
   return new Date(this.getFullYear(),this.getMonth()+1,1,-1).getDate();
}

Date.prototype.getWeek = function() {
   var d = new Date(this);
	var DoW = d.getDay();
	d.setDate(d.getDate() - (DoW + 6) % 7 + 3); // Nearest Thu
	var ms = d.valueOf(); // GMT
	d.setMonth(0);
	d.setDate(4); // Thu in Week 1
	return Math.round((ms - d.valueOf()) / (7 * 864e5)) + 1;
}

function insertAfter(parent, node, referenceNode){
	if(referenceNode.nextSibling){
    parent.insertBefore(node, referenceNode.nextSibling);
  } else {
    parent.appendChild(node);
  }
}

/* built 2007-01-05  mib A&F           */
/* Show Mouseover in 'Teilsuche' links */

/* Tooltip for partsearch arrows including mouse over for ps icon */
var hafasTTip = {
   i:null,
   t:null,

   show: function (id, name){
        a=document.getElementById(id);
        if(a == null)
           return;
        i=document.getElementById('i'+id);
        if(i == null)
           return;
        t=document.getElementById('HFSTooltip');
        if(t == null)
           return;
        x=a.offsetLeft;
        y=a.offsetTop;
        while((a = a.offsetParent) != null){
           x += a.offsetLeft;
           y += a.offsetTop;
           }
        t.innerHTML = name ;
        t.style.top = y+28+"px";
        t.style.left = x+5+"px";
        t.style.display = 'block';
        if(i)hafasTTip.cImg(1);
        },

   hide: function (id){
        t.style.display = 'none';
        if(i)hafasTTip.cImg(0);
        },

   cImg: function (stat){/* image mouse over */
        if(stat == 1)
           i.src = i.src.substring(0,i.src.indexOf('.png'))+'_o.png';
        else
           i.src = i.src.substring(0,i.src.indexOf('_o.png'))+'.png';
        }
   }


