function selectCity(type) {
  showLoadingDialog();
  if(type=="bundesland") {
    if(document.getElementById('citySelect').value=="all") window.location.href="index.php?allcities=1";
    else xajax_getCities(document.getElementById('citySelect').value);
  } else if(type=="stadt") {
    if(document.getElementById('citySelect').value=="") window.location.href = "index.php";
    else if(document.getElementById('citySelect').value=="back") xajax_getBL();
    else if(document.getElementById('citySelect').value=="all") window.location.href="index.php?allcities=1";
    else window.location.href = "index_"+document.getElementById('citySelect').value+".html";
  }
}

function showLoadingDialog() {
  var div;
  // Prüfen, ob Hinweisfenster bereits existiert
  if(document.getElementById('loading_dialogue')) {
    div = document.getElementById('loading_dialogue');
  } else {
    // Wenn Fenster noch nicht existiert, neu erstellen
    div = document.createElement("DIV");
    div.innerHTML = "<div style='padding:25%;text-align:center;'><img src='bilder/loading.gif' /><br />Einen kleinen Moment bitte ...</div>";
    div.id = "loading_dialogue";
    // Element in HTML-Baum einfügen
    document.body.appendChild(div);
  }
  // Element anzeigen
  div.style.display = "block";
}

function hideLoadingDialog() {
  if(document.getElementById('loading_dialogue')) document.getElementById('loading_dialogue').style.display = "none";
}

function logHimOut() {
  xajax_logout();
}

function forgotPW() {
  var user = encodeURIComponent(document.getElementById('username').value);
  xajax_sendpw(user);
}

function doLogin() {
  var user = encodeURIComponent(document.getElementById('username').value);
  var pass = encodeURIComponent(document.getElementById('pass').value);
  xajax_einloggen(user,pass);
}

function showDiv(div) {
  document.getElementById(div).style.display = "block";
}

currentID = 0;
function loadIt() {
}

window.onload=function()
{
  loadIt();
}

function updateStadt(inputID,outputID) {
  if(document.getElementById(inputID).value!="" && (document.getElementById(outputID).value=="" || document.getElementById(outputID).value=="Stadt" || document.getElementById(outputID).value=="PLZ")) {
    if(inputID.indexOf("plz")>-1) {
      xajax_getCity(encodeURIComponent(document.getElementById(inputID).value),outputID);
    } else {
      xajax_getPLZ(encodeURIComponent(document.getElementById(inputID).value),outputID);
    }
  }
}

/* Tooltip Bereich */
var breite;
var mouse_X = 0;
var mouse_Y = 0;
var tip_active = 0;

function update_tip_pos() {
  var pos_top = 0;
  if (self.pageYOffset)
	{
	  pos_top = self.pageYOffset;
    //pos_top=0;
	}
	else if (document.documentElement && document.documentElement.scrollTop)
	{
	  pos_top = document.documentElement.scrollTop;
	}
	else if (document.body)
	{
	  pos_top = document.body.scrollTop;
	}
  
  var x=0;
  var y = 0;
  if (self.innerHeight) // all except Explorer
  {
  	x = self.innerWidth-20;
  	y = self.innerHeight;
  }
  else if (document.documentElement && document.documentElement.clientHeight)
  {
  	x = document.documentElement.clientWidth;
  	y = document.documentElement.clientHeight;
  }
  else if (document.body)
  {
  	x = document.body.clientWidth;
  	y = document.body.clientHeight;
  }
  
  x = parseInt(x);
  y = parseInt(y);
  var left = 0;
  var top = 0;
  left = (mouse_X + 15);
	if (self.innerHeight) {
    top = mouse_Y;
  } else {
    top  = (mouse_Y+pos_top);
    y+=pos_top;
  }
  
  /*var tipBreite = 0;
  if(breite.indexOf("%")!=-1) {
    tipBreite = parseInt(breite)*x/100;
  } else tipBreite = parseInt(breite);*/

  if(left+/*tipB*/breite>x-5) {
    left = Math.round(x-/*tipB*/breite-5);
    top = Math.round(top+5);
  }
  
  if(y<900) var divHoehe = 145;
  else var divHoehe = 100;
  if(y<900 && document.getElementById('ToolTip').innerHTML.indexOf("<IMG")!=-1) divHoehe = 170;
  
  if((self.innerHeight && top+divHoehe>y+ pos_top) || (!self.innerHeight && top+divHoehe>y)) {
    if (self.innerHeight) {
      top = mouse_Y - divHoehe;
    } else {
      top = mouse_Y + pos_top - divHoehe;
    }
  }
  
  with(document.getElementById('ToolTip')) {
    style.left = left +"px";
    style.top = top +"px";
  }
}

function getMouseXY(e) {
  try {
    if (ie) {
      mouse_X = event.clientX + document.body.scrollLeft;
      mouse_Y = event.clientY + document.body.scrollTop;
    } else {
      mouse_X = e.pageX;
      mouse_Y = e.pageY;
    }
  
    if (mouse_X < 0) mouse_X = 0;
    if (mouse_Y < 0) mouse_Y = 0;
    //if (mouse_X+breite+30 > document.body.clientWidth) mouse_X = document.body.clientWidth-breite-30;
    
    if(!tip_active) update_tip_pos();
  } catch(err) { }
}

function tip_it(which, TTitle, TContent,breit){
  if(breit==undefined) breite = "250"; else breite = breit;

  var x;
  if (self.innerHeight) x = self.innerWidth;
  else if (document.documentElement && document.documentElement.clientHeight) x = document.documentElement.clientWidth;
  else if (document.body) x = document.body.clientWidth;
  
  if(breite.indexOf("%")!=-1) {
    breite = (parseInt(breite)*x/100);
  } else breite = 300;

	if(which){
		tip_active = 1;
    update_tip_pos();
    with(document.getElementById('ToolTip')) {
  		style.display = "block";
  		innerHTML = '<div class="maincontent" style="width:'+breite+'px"><div style="background:#7B0202;color:#fff;width:100%">'+TTitle+'</div><div style="line-height:17px;">'+TContent+'<br class="clear" /></div></div>';
    }
    //new Effect.Opacity('ToolTip', {to:0.9});
	}else{
		tip_active = 0;
		document.getElementById('ToolTip').style.display = "none";
	}
}

var ie = document.all?true:false;
if (!ie) document.captureEvents(Event.MOUSEMOVE);
document.onmousemove = getMouseXY;
