/* (c) Scientec Internet Applications + Media GmbH - www.scientec.de */

portalpfad='';
var PLZ2=[["01","02","03","04","06","07","08","09"],["10","12","13","14","15","16","17","18","19"],["20","21","22","23","24","25","26","27","28","29"],["30","31","32","33","34","35","36","37","38","39"],["40","41","42","44","45","46","47","48","49"],["50","51","52","53","54","55","56","57","58","59"],["60","61","63","64","65","66","67","68","69"],["70","71","72","73","74","75","76","77","78","79"],["80","81","82","83","84","85","86","87","88","89"],["90","91","92","93","94","95","96","97","98","99"]];

init();
function init()
{
  if(document.referrer.indexOf(self.location.host) == -1)
  {
    dummyImg = new Image();
    var ref=encodeURI(document.referrer).replace(/\&/,"__");
    dummyImg.src = "http://www.onwatch.de/referrer.php?referrer="+ref+"&location="+location.href+"&pid="+pid;
  }
  addFunctions();
  mail();
  LINKS = document.getElementsByTagName("A");
  for(var i = 0; i < LINKS.length; i++)
  {
    var thisLink= LINKS[i];
    if(thisLink.href.indexOf(self.location.host) == -1){thisLink.onmousedown = function(){onwatch(this,location);this.removeAttribute('onmousedown')};}
    var thisParentTag=thisLink.parentNode.tagName.toLowerCase();
    if(thisParentTag=="cite"){thisLink.title="Zur externen Homepage"; thisLink.target="_blank"}
    else if(thisParentTag=="span"){thisLink.childNodes[0].title="Informationen zum Ranking"}
    else if(thisParentTag=="h2"){thisLink.title="Details anzeigen"}
  }
  if(document.getElementsByName("anmelden")[0]){document.getElementsByName("anmelden")[0].action="http://www.lokal.ws/cgi-bin/eintragen.pl";}
  if(document.getElementsByName("testen")[0]){document.getElementsByName("testen")[0].action="http://www.lokal.ws/cgi-bin/testen.pl";}
  buttonNormal('link-regionen');
  buttonNormal('link-postleitzahlen');
  Flyoutnavigation();
	addNewScript("extra.js")

}

function addNewScript(filename){
	newScript = document.createElement("script");
	newScript.type = "text/javascript";
	newScript.src = "http://www.lokal.ws/_scripts/"+filename;
  document.body.appendChild(newScript);	
}

function onwatch(link,location)
{
  dummyImg = new Image();
  dummyImg.src = "http://www.onwatch.de/onclick.php?url="+link.href+"&location="+location.href+"&pid="+pid;
}
function plz()
{
  _plz = document.getElementById("plzsuche").value;
  if(_plz.length < 5)
  {
    alert("Bitte geben Sie eine korrekte 5-stellige PLZ ein.");
  }
  else
  {
    dummy = _plz.split("");
    url = portalpfad+"/postleitzahlen/"+dummy[0]+dummy[1]+"/"+_plz+".html";
    window.location.href = url;
  }
  return false
}

function toggleEmpty(disnone,obj)
{
  li = document.getElementById("regionen").getElementsByTagName("li");
  for(var i = 0; i < li.length; i++)
  {
    if(li[i].className.indexOf("empty") != -1)
    {
      if(disnone)
      {
        li[i].style.display = "none";
      }
      else
      {
        li[i].style.display = "";
      }
    }
  }
  if(disnone)
  {
    document.getElementById("togglelink").title = "Leere Ordner anzeigen";
    document.getElementById("togglelink").href = "javascript:toggleEmpty(0,this)";
  }
  else
  {
    document.getElementById("togglelink").title = "Leere Ordner ausblenden";
    document.getElementById("togglelink").href = "javascript:toggleEmpty(1,this)";
  }
}

function addFunctions(){
  if(window.empty)document.getElementById("funktionen").innerHTML='<a href="javascript:toggleEmpty(0,this)" id="togglelink" id="f_ordner" title="Leere Ordner anzeigen"><img src="'+portalpfad+'/_grafik/ordner.png"></a>';
  if (document.all)document.getElementById('funktionen').innerHTML+='<a href="javascript:window.external.AddFavorite(location.href,document.title)" title="Diese Seite den eigenen Favoriten hinzuf&uuml;gen" id="f_favoriten"><img src="'+portalpfad+'/_grafik/favoriten.png"></a>';
  document.getElementById('funktionen').innerHTML+='<a href="http://www.mister-wong.de/index.php?action=addurl&amp;bm_url='+encodeURIComponent(location.href)+'&amp;bm_description='+encodeURIComponent(document.title)+'" title="Diese Seite zu Mister Wong hinzuf&uuml;gen" target="_blank" rel="nofollow" id="f_wong"><img src="'+portalpfad+'/_grafik/wong.png"></a>';
  document.getElementById('funktionen').innerHTML+='<a href="javascript:self.print()" title="Diese Seite drucken" id="f_drucken"><img src="'+portalpfad+'/_grafik/drucken.png"></a>';
}

function map(o,typ){
  if (typ=="lageplan" && o.className=="aus"){
   document.getElementById("r_map").className="an";
   document.getElementById("map").className="an";
   document.getElementById("r_route").className="aus";
   document.getElementById("route").className="aus";
  }
  else if (typ=="route" && o.className=="aus"){
   document.getElementById("r_map").className="aus";
   document.getElementById("map").className="aus";
   document.getElementById("r_route").className="an";
   document.getElementById("route").className="an";
  }
}
function suche(){
  if(document.getElementById("qs").value.length<3)return false
  else return true
}
function mail(){
  var EMs=document.getElementById("inhalt").getElementsByTagName("em");
  if(EMs.length>0){
    for(var i=0;i<EMs.length;i++){
      var thisEM=EMs[i];
      if (thisEM.firstChild.tagName=="A"){
        var thisA=thisEM.firstChild;
        thisA.title=thisA.title.replace(/~AT~/,"@");
        thisA.href="mai"+"lto:"+String(thisA.title);
        thisA.title="E-Mail senden";
        thisA.innerHTML=thisA.innerHTML.replace(/~AT~/,"@");
      }
    }
  }
}

if(typeof(hid)!="undefined")
{
  if(hid)
  {
    document.getElementById("hlink").innerHTML = '<a href="http://www.hotel.de/Booking.aspx?lng=DE&han=1158134&h_hmid='+hid+'" target="_blank" onmousedown="onwatch(this,location);this.removeAttribute(\'onmousedown\')" ><img src="../_grafik/buchen.gif" alt="Info & buchen" title="Info & buchen" border=0></a>';
  }
}

function isUrl(url)
{
  if(url.match(/https{0,1}:\/\//))
  {
    return true;
  }
  else
  {
    alert("Verwenden Sie bitte die komplette URL, z.B. 'http://www.domainname.de'");
    return false;
  }
}
/*******navigation*******/
var timer;

function getPositionNav(element)
{
  var elem=element,tagname="",x=0,y=0;
  
while ((typeof(elem)=="object")&&(typeof(elem.tagName)!="undefined"))
  {
    y+=elem.offsetTop;     
    x+=elem.offsetLeft;    
    tagname=elem.tagName.toUpperCase();

   if (tagname=="BODY")
      elem=0;
	  
   if (typeof(elem)=="object")
   if (typeof(elem.offsetParent)=="object")
        elem=elem.offsetParent;
  }
  
  position=new Object();
  position.x=x;
  position.y=y;
  position.y=y-document.getElementById('navigation').scrollTop;
  return position;
}
function setPosition(element,x,y){
	document.getElementById(element).style.left=x+"px";
	document.getElementById(element).style.top=y+"px";
}
function showElement(element){
	   if(window.XMLHttpRequest){
         document.getElementById(element).style.display='block';
         clearTimeout(timer);
}
}
function hideElement(element){
	document.getElementById(element).style.display='none';
}
function hideElementTime(element, caller){
	timer = setTimeout("hideElement('"+element+"');buttonNormal('"+caller+"');",500);	
}
function buttonBlau(element){
	if(window.XMLHttpRequest){
	document.getElementById(element).style.cssText="display:block; margin-left:-3px; color:#FFFFFF; width:170px; text-decoration:none;  padding-left:10px; background:#5b85c2 url(/_grafik/blauerpfeil_hover.png); background-position: right -1px; background-repeat:no-repeat; cursor:pointer;";
}
}
function buttonNormal(element){
	if(window.XMLHttpRequest){
	  if(document.getElementById(element))
	  {
	    document.getElementById(element).style.cssText="display:block; margin-left:-3px;  color:#000000; width:170px; text-decoration:none; padding-left:10px; background-image:url(/_grafik/blauerpfeil.png); background-position:right -1px; background-repeat:no-repeat; cursor:pointer;";
	  }
}
}
function Flyoutnavigation(){
       if(document.getElementsByName("ref")[0]){document.getElementsByName("ref")[0].value="jsok";}
       if(document.getElementById('link-postleitzahlen') && PLZ2)
       {
       writeHTML="<div id='subnavi' onMouseOver=\"showElement('subnavi'); buttonBlau('link-regionen')\" onMouseOut=\"hideElementTime('subnavi','link-regionen')\">"
                                                        +"  <div id='schatten-ecke-o'>&nbsp;</div>"
      								  +"    <div id='schatten-r'>&nbsp;</div>"
      								  +"      <div id='borderTop'>&nbsp;</div>"
      								  +"        <ul id='flyout'>";      
       var BL=["Baden-Wuerttemberg","Bayern","Berlin","Brandenburg","Bremen","Hamburg","Hessen","Mecklenburg-Vorpommern","Niedersachsen","Nordrhein-Westfalen","Rheinland-Pfalz","Saarland","Sachsen","Sachsen-Anhalt","Schleswig-Holstein","Thueringen"];
       var BLU=["Baden-W&uuml;rttemberg","Bayern","Berlin","Brandenburg","Bremen","Hamburg","Hessen","Mecklenburg-Vorpommern","Niedersachsen","Nordrhein-Westfalen","Rheinland-Pfalz","Saarland","Sachsen","Sachsen-Anhalt","Schleswig-Holstein","Th&uuml;ringen"];
       for(var i=0;i<BL.length;i++){
	   writeHTML+="<li><a href=\"/regionen/"+BL[i]+".html\" onMouseOver=\"showElement('subnavi')\">"+BLU[i]+"</a></li>"
	 }
       writeHTML+="</ul>"
								        +"      <div id='borderbottom'>&nbsp;</div>"
      								  +"    <div id='schatten-u'>&nbsp;</div>"
      								  +"  <div id='schatten-ecke-u'>&nbsp;</div>"
      								  +"</div>";
      
          							        writeHTML+="<div id='subnavi2' onMouseOver=\"showElement('subnavi2'); buttonBlau('link-postleitzahlen'); hideElement('subnavi')\" onMouseOut=\"hideElementTime('subnavi2','link-postleitzahlen'); buttonNormal('link-regionen')\">"
     									  +"      <div id='schatten-ecke-o2'>&nbsp;</div>"
     									  +"    <div id='schatten-r2'>&nbsp;</div>"
     									  +"  <div id='borderTop2'>&nbsp;</div>"
      								  +"<ul class='postleizahlen'>";
	 for(var k=0;k<PLZ2.length;k++){
       	 writeHTML+="<li>"
             for(var j=0;j<PLZ2[k].length;j++){
                writeHTML+="<a href=\"/postleitzahlen/"+PLZ2[k][j]+"/\">"+PLZ2[k][j]+"</a>";
      	 }
	  	 writeHTML+="</li>"
  	 }
  	 writeHTML
  	 								  +="</ul>"
 									  +"    <div id='borderbottom2'>&nbsp;</div>"
  									  +"    <div id='schatten-u2'>&nbsp;</div>"
  									  +"  <div id='schatten-ecke-u2'>&nbsp;</div>"
  									  +"</div>";
      
       document.getElementById('subnavigation').innerHTML = writeHTML;
       }
}

/**** Karl ****/
window.addEvent('domready', function(){
  var test = new layer($$('.screen1'),{});
});
/*
var test = new layer($$('.itemcont'),{
    initialize:function(){
        this.fx1 = new Fx.Style(this.toolTip, 'opacity', {duration: 0, wait: false}).set(0);
        this.fx2 = new Fx.Style(this.toolTip, 'opacity', {duration: 0, wait: false}).set(0);
      },
      onShow: function(toolTip) {
        this.fx1.start(1);
      },
      onHide: function(toolTip) {
        this.fx2.start(0);
      }
});
*/

var navUA = navigator.userAgent;
var navAN = navigator.appName;
var navAV = navigator.appVersion;
var dom=(document.getElementById)?1:0;
function FV_appName(){
 if (navAN.indexOf("Microsoft") != -1){return "IE";}
 else if(navAN.indexOf("Netscape") != -1){ return "NS";}
 else { return "Other";}
}
function FV_appVersion(){
  if (FV_appName()=="IE" && navAV.substring(0,1)==4 && navUA.indexOf("MSIE 5")!=-1){return 5;}//IE5 bug
  else if (FV_appName()=="IE" && navAV.substring(0,1)==4 && navUA.indexOf("MSIE 6")!=-1){return 6;}
  else if (FV_appName()=="IE" && navAV.substring(0,1)==4 && navUA.indexOf("MSIE 7")!=-1){return 7;}
  else {return navAV.substring(0,1);}
}
function FV_appNameVersion(){
  {return FV_appName()+FV_appVersion()}
}
var IE6 = (FV_appNameVersion() == "IE6")? true:false;

var layer = new Class({
	options: {
		onShow: function(tip){
			tip.setStyle('visibility', 'visible');
		},
		onHide: function(tip){
			tip.setStyle('visibility', 'hidden');
		},
		showDelay: 100,
		hideDelay: 100,
		className: 'tool',
		offsets: {'x': 5, 'y': 5},
		fixed: false,
		box: window
	},

	initialize: function(elements, options){
		this.setOptions(options);
		this.toolTip = new Element('div', {
			'class': this.options.className + '-tip',
			'styles': {
				'position': 'absolute',
				'top': '0',
				'left': '0',
				'visibility': 'hidden'
			}
		}).inject(document.body);
		this.wrapper = new Element('div').inject(this.toolTip);
		$$(elements).each(this.build, this);
		if (this.options.initialize) this.options.initialize.call(this);
	},

	build: function(el){
		if(el.tagName == "DIV")
		{
		  imgDummy = el.style.backgroundImage.replace("screenshots060","screenshots200");
		  el.store('myImage', imgDummy);
		  el.store('myText', '');
		}
		el.addEvent('mouseenter', function(event){
			this.start(el);
			if (!this.options.fixed) this.locate(event);
			else this.position(el);
		}.bind(this));
		if (!this.options.fixed) el.addEvent('mousemove', this.locate.bindWithEvent(this));
		var end = this.end.bind(this);
		el.addEvent('mouseleave', end);
		el.addEvent('trash', end);
	},

	start: function(el){
		this.wrapper.empty();
			this.title = new Element('div', {'class': 'imagecont1'}).inject(this.wrapper);
			this.title.setStyle('background-image', el.retrieve('myImage'));
			this.text = new Element('div', {'class': 'text1'}).inject(this.wrapper);
			this.text.innerHTML = el.retrieve('myText');
		$clear(this.timer);
		this.timer = this.show.delay(this.options.showDelay, this);
	},

	end: function(event){
		$clear(this.timer);
		this.timer = this.hide.delay(this.options.hideDelay, this);
	},

	position: function(element){
		var pos = element.getPosition();
		this.toolTip.setStyles({
			'left': pos.x + this.options.offsets.x,
			'top': pos.y + this.options.offsets.y
		});
	},

	locate: function(event){
		if(this.options.box == window)
		{
			var win = {'x': window.getWidth(), 'y': window.getHeight()};
			if(window.innerWidth)
			{
			  win = {'x': window.innerWidth, 'y': window.innerHeight};
			}
			if(document.body.clientWidth)
			{
			  win = {'x': document.body.clientWidth, 'y': document.body.clientHeight};
			}
		}
		else
		{
			var win = {'x': this.options.box.offsetWidth, 'y': this.options.box.offsetHeight};
		}

		var scroll = {'x': window.getScrollLeft(), 'y': window.getScrollTop()};
		var tip = {'x': this.toolTip.offsetWidth, 'y': this.toolTip.offsetHeight};
		var prop = {'x': 'left', 'y': 'top'};
		for (var z in prop){
			var pos = event.page[z] + this.options.offsets[z];
  			if ((pos + tip[z] - scroll[z]) > (win[z]-4))
  			{
  			  pos = event.page[z] + this.options.offsets[z] - tip[z];
  			  if(!IE6)
  			  {
  			    this.toolTip.style.backgroundImage = "url('http://www.lokal.ws/_grafik/viewer-oben.png')";
  			    this.toolTip.style.paddingTop = "13px";
  			    this.toolTip.style.paddingLeft = "39px";
  			  }
  			}
  			else if(!IE6)
  			{
  			  this.toolTip.style.backgroundImage = "url('http://www.lokal.ws/_grafik/viewer-unten.png')";
  			  this.toolTip.style.paddingTop = "18px";
  			  this.toolTip.style.paddingLeft = "40px";
  			}
    			this.toolTip.setStyle(prop[z], pos);
		};
	},

	show: function(){
		if (this.options.timeout) this.timer = this.hide.delay(this.options.timeout, this);
		this.fireEvent('onShow', [this.toolTip]);
	},

	hide: function(){
		this.fireEvent('onHide', [this.toolTip]);
	}

});

layer.implement(new Events, new Options);
