function addEvent(obj, evType, fn, useCapture) {
	if(obj.addEventListener) {
		obj.addEventListener(evType, fn, useCapture);
		return true;
	}else if(obj.attachEvent) {
		var r = obj.attachEvent('on'+evType, fn);
		return r;
	}else{
		alert('Handler could not be attached');
	}
}
var sweetTitles = { 
	xCord : 0,
	yCord : 0,
	tipElements : ['a','abbr','acronym','label','input'],
	obj : Object,
	tip : Object,
	active : 0,
	init : function() {
		if ( !document.getElementById ||
			!document.createElement ||
			!document.getElementsByTagName ) {
			return;
		}
		var i,j;
		this.tip = document.createElement('div');
		this.tip.id = 'toolTip';
		this.tip.style.top = '0px';
		this.tip.style.visibility = 'hidden';
		document.getElementsByTagName('body')[0].appendChild(this.tip);
		var i = this.tipElements.length;
		while (i--) {
			var current = document.getElementsByTagName(this.tipElements[i]);
			var j = current.length;
			while (j--) {
				addEvent(current[j],'mouseover',this.tipOver,false);
				addEvent(current[j],'mouseout',this.tipOut,false);
				current[j].setAttribute('tip',current[j].title);
				current[j].removeAttribute('title');
			}
		}
	},
	updateXY : function(e) {
		if ( document.captureEvents ) {
			sweetTitles.xCord = e.pageX;
			sweetTitles.yCord = e.pageY;
		} else if ( window.event.clientX ) {
			sweetTitles.xCord = window.event.clientX+document.documentElement.scrollLeft;
			sweetTitles.yCord = window.event.clientY+document.documentElement.scrollTop;
		}
	},
	tipOut: function() {
		if ( window.tID ) {
			clearTimeout(tID);
		}
		if ( window.opacityID ) {
			clearTimeout(opacityID);
		}
		sweetTitles.tip.style.visibility = 'hidden';
	},
	checkNode : function() {
		var trueObj = this.obj;
		if ( this.tipElements.inArray(trueObj.nodeName.toLowerCase()) ) {
			return trueObj;
		} else {
			return trueObj.parentNode;
		}
	},
	tipOver : function(e) {
		sweetTitles.obj = this;
		tID = window.setTimeout("sweetTitles.tipShow()",800);
		sweetTitles.updateXY(e);
	},
	tipShow : function() {		
		var scrX = Number(this.xCord);
		var scrY = Number(this.yCord);
		var tp = parseInt(scrY+15);
		var lt = parseInt(scrX+10);
		var anch = this.checkNode();
		var addy = '';
		var access = '';
		if ( anch.nodeName.toLowerCase() == 'a' ) {
			var host = location.hostname.toString();
			var pattern = new RegExp("(http://?)"+host,"gi");
			var fullPath = anch.href.toString();
			var path = fullPath.replace(pattern,'');
			addy = (path.length > 25 ? path.toString().substring(0,25)+"..." : path);
			var access = ( anch.accessKey ? " ["+anch.accessKey+"]" : "" );
		} else if ( anch.nodeName.toLowerCase() == 'label' ) {
			addy = "";
		} else  if ( anch.nodeName.toLowerCase() == 'input' ) {
			addy = "";
		} else {
			addy = anch.firstChild.nodeValue;
		}
		if(addy == '/') addy = 'antiquariat-henke.de/'; 
		this.tip.innerHTML = (anch.getAttribute('tip') != "" || ((anch.nodeName.toLowerCase() == 'label' || anch.nodeName.toLowerCase() == 'input') && anch.getAttribute('tip') != "") ? "<p>"+anch.getAttribute('tip')+ (addy != "" && addy.indexOf('javascript:') < 0 && addy.length > 3 ? "<em>"+access+addy+"</em>" : "") + "</p>" : "");
		if ( parseInt(document.documentElement.clientWidth+document.documentElement.scrollLeft) < parseInt(this.tip.offsetWidth+lt) ) {
			this.tip.style.left = parseInt(lt-(this.tip.offsetWidth+10))+'px';
		} else {
			this.tip.style.left = lt+'px';
		}
		if ( parseInt(document.documentElement.clientHeight+document.documentElement.scrollTop) < parseInt(this.tip.offsetHeight+tp) ) {
			this.tip.style.top = parseInt(tp-(this.tip.offsetHeight+10))+'px';
		} else {
			this.tip.style.top = tp+'px';
		}
		if(this.tip.innerHTML != '')
		{
			this.tip.style.visibility = 'visible';
			this.tip.style.opacity = '.1';
			this.tipFade(10);
		}
	},
	tipFade: function(opac) {
		var passed = parseInt(opac);
		var newOpac = parseInt(passed+10);
		if ( newOpac < 80 ) {
			this.tip.style.opacity = '.'+newOpac;
			this.tip.style.filter = "alpha(opacity:"+newOpac+")";
			opacityID = window.setTimeout("sweetTitles.tipFade('"+newOpac+"')",20);
		}
		else { 
			this.tip.style.opacity = '.90';
			this.tip.style.filter = "alpha(opacity:90)";
		}
	}
};
Array.prototype.inArray = function (value) {
	var i = this.length;
	while(i--) {
		if (this[i] === value) {
			return true;
		}
	}
	return false;
};
function confirmDelete() {
	return confirm(unescape('Wollen Sie diesen Titel wirklich entfernen ?%0A%0ADiese Aktion kann nicht r%FCckg%E4ngig gemacht werden.%0A'));
}
function confirmExit() {
	return confirm(unescape('Wollen Sie Ihre Bestellung wirklich l%F6schen ?%0A%0ADiese Aktion kann nicht r%FCckg%E4ngig gemacht werden.%0A'));
}
function setFocus() {
	var theCurrentUrl = location.href;
	if (theCurrentUrl == 'http://antiquariat-henke.de/kontaktformular/' ) document.getElementById('from').focus();
	if (theCurrentUrl == 'http://antiquariat-henke.de/bestellung/absenden/' ) document.getElementById('name').focus();
	if (theCurrentUrl == 'http://antiquariat-henke.de/bestellung/' || theCurrentUrl == 'http://antiquariat-henke.de/bestellung/absenden/') {
		var allLinks = document.getElementsByTagName('a');
		for(i = 0; i < allLinks.length; i++)
		{
			if(allLinks[i].className)
			{
				if(allLinks[i].className == 'noprint red') allLinks[i].onclick = confirmDelete;
				if(allLinks[i].className == 'doconfirm') allLinks[i].onclick = confirmExit;
			}
		}
	}
}
function pageLoader() {
	sweetTitles.init();
	setFocus();
}

addEvent(window, 'load', pageLoader, false);
