// JavaScript Bibliothek
//(C) Diomira.de 2006-2010
// All rights reserved


IE = document.all&&!window.opera;
DOM = document.getElementById&&!IE;
TippText= new Array();
function PopUp(callerID,t,a) {
ClosePopUp();
var relatedElement = document.getElementById(callerID);
var OuterFrame = document.getElementById('PopUP');
var WriteTag = document.createElement("DIV");
var WriteExtraTag = document.createElement("DIV");
var StyleClass = document.createAttribute("class");
var ElementStyle = document.createAttribute("style");
var ExtraStyleClass = document.createAttribute("class");

StyleClass.nodeValue = a;
ExtraStyleClass.nodeValue = "TipBoxExtra";
if(!TippText[callerID.slice(0,5)+'_Extra']) TippText[callerID.slice(0,5)+'_Extra'] = '';


WriteTag.setAttributeNode(StyleClass);
WriteTag.setAttributeNode(ElementStyle);
WriteExtraTag.setAttributeNode(ExtraStyleClass);

var NewTextToParagraph = document.createTextNode(TippText[t]);
var ExtraTextToParagraph = document.createTextNode(TippText[callerID.slice(0,5)+'_Extra']);
var xposparent=findPosX(relatedElement);
var yposparent=findPosY(relatedElement);
WriteTag.appendChild(NewTextToParagraph);
WriteExtraTag.appendChild(ExtraTextToParagraph);
WriteTag.appendChild(WriteExtraTag, WriteTag.lastChild);
OuterFrame.appendChild(WriteTag, OuterFrame.lastChild);

document.getElementById('PopUP').style.top=(yposparent-(OuterFrame.offsetHeight+10)) + 'px';
document.getElementById('PopUP').style.left=(xposparent-(OuterFrame.offsetWidth/2)+20) + 'px';

}

function ClosePopUp(callerID) {
var relatedElement = document.getElementById('PopUP');
	if(relatedElement) {
	l=relatedElement.childNodes.length;
	for(x=0;x<l;x++) {
		var ThisTipBox=relatedElement.childNodes[0];
		relatedElement.removeChild(ThisTipBox);
		}
	}

}


function findPosX(obj) {
   var curleft = 0;
   if(obj.offsetParent) {
      while(obj.offsetParent) {
         curleft += obj.offsetLeft
         obj = obj.offsetParent;
      }
   }
   else if(obj.x)
     curleft = obj.x;
   return curleft;
}

function findPosY(obj) {
   var curtop = 0;
   if(obj.offsetParent) {
      while(obj.offsetParent) {
         curtop += obj.offsetTop
         obj = obj.offsetParent;
      }
   }
   else if(obj.y)
      curtop = obj.y;
   return curtop;
}



function karte(ID,PLZ,formname)
{if(ID && PLZ) {
document.forms[formname].SubmitByMap.value=ID+'_'+PLZ;
document.forms[formname].submit();
}}


function addUmlaut(type)
{
var relatedElement = document.getElementById('suchort');
l=relatedElement.value.length-1;
switch (type) {
case 'a':
if(relatedElement.value.substr(l,1) == ' ' || relatedElement.value.substr(l,1) == '') relatedElement.value+='Ä'; else relatedElement.value+='ä';
break;
case 'u':
if(relatedElement.value.substr(l,1) == ' ' || relatedElement.value.substr(l,1) == '') relatedElement.value+='Ü'; else relatedElement.value+='ü';
break;
case 'o':
if(relatedElement.value.substr(l,1) == ' ' || relatedElement.value.substr(l,1) == '') relatedElement.value+='Ö'; else relatedElement.value+='ö';
break;
case 's':
relatedElement.value+='ß';
break;
}
}



// Browserweiche
IE = document.all&&!window.opera;
DOM = document.getElementById&&!IE;

// Variablen für die Mausposition
var mouseX = 0; // x-Koordinate
var mouseY = 0; // y-Koordinate


/* Body-Objekt des IE ermitteln (abhängig, ob IE im Quirks- oder Standardmode*/
function getBody(){
  // Entsprechendes Bodyobjekt zurückgeben (CSS1Compat = Standardmode
  return (window.document.compatMode == "CSS1Compat") ?
          window.document.documentElement : window.document.body || null;
}

var ieBody = null;

// Funktion zum Initialisierung, die in onload aufgerufen wird
function initMousePos(){
  document.onmousemove = getMousePos; // Mausposition ermitteln

  // Falls es sich um einen IE handelt
  if(IE)
    ieBody = getBody(); // Bodyobjekt für IE ermitteln
}

// Funktion zum Ermitteln der Mausposition
function getMousePos(ereignis){
  // Aktuelle Mauskoordinaten bei Mausbewegung ermitteln
  mouseX = (IE) ? window.event.clientX : ereignis.pageX;
  // Mauskoordinate im Body auch nach Scrollen (Wert ist evtl. höher im IE)
  mouseY = (IE) ? (window.event.clientY + ieBody.scrollTop) : ereignis.pageY;
  // Mauskoordinate im Fenser (ohne Scrollen im IE)
  //mouseY = (IE) ? window.event.clientY : ereignis.pageY;

if((document.getElementById('KirchenPopUp') && (mouseX<700 || mouseY < document.getElementById('KirchenPopUp').style.top.slice(0,-2)-10) && currentChurchId>0)) closeChurchInfo();

  //window.status = "Mauskoordinaten (x, y): (" + mouseX + ", " + mouseY +" "+document.getElementById('KirchenPopUp').style.top.slice(0,-2)+")";
}


var currentChurchId=-1;
function getCurchInfo(ChurchID,top)
{
var xmlhttp;
top +=200;

if(currentChurchId != ChurchID && ChurchID>0) {

if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Ihr Browser unterstützt diese Funktion leider nicht.");
  }
xmlhttp.onreadystatechange=function()
{
  var KirchenPopUp = document.getElementById('KirchenPopUp');

    	  //Hack für IE6 z-index Problem
    	  var html='';
          var is_ie6 =
           document.all &&
           (navigator.userAgent.toLowerCase().indexOf("msie 6.") != -1);
 		if (is_ie6)
        {  html = "<iframe style='position:absolute;display:none;display:block;z-index:-1; width:3000px; height:3000px; top:0; left:0; filter:mask();'></iframe>";
           KirchenPopUp.innerHTML = html;
        }


  KirchenPopUp.style.top=top + 'px';

if(xmlhttp.readyState==4)
  { KirchenPopUp.innerHTML='';
	KirchenPopUp.innerHTML=html+xmlhttp.responseText;
  } else {
  KirchenPopUp.innerHTML='';
  KirchenPopUp.innerHTML=html+"<div style='width:200px;height:200px;background:url(./grafik/timebar.gif) center center no-repeat;background-color:FFFFFF;'></div>";
  }
}
xmlhttp.open("GET","./diomiraapi?SID=" + SessionID + "&ChurchID="+ChurchID+"&ident={" + authentication + "}",true);
xmlhttp.send(null);
if(currentChurchId!=ChurchID && currentChurchId>-1)ClosePopUp();
currentChurchId=ChurchID;
}
}

function closeChurchInfo()
{
  var KirchenPopUp = document.getElementById('KirchenPopUp');
  KirchenPopUp.innerHTML='';
  currentChurchId=-1;
  //ClosePopUp();
}



function checkAddForm()
{
check=0;
fehler=false;
if(document.patch.WahlStunden.value=='' || document.patch.WahlMinuten.value=='')
	{fehler='Bitte geben Sie die Uhrzeit ein!';}
 else
 	{if(document.patch.WahlStunden.value>23 || document.patch.WahlMinuten.value>59 || document.patch.WahlStunden.value.match(/[^0-9]/) || document.patch.WahlMinuten.value.match(/[^0-9]/)) {fehler='Bitte geben Sie eine gültige Uhrzeit ein!';}
		else {
		if(document.patch.WahlMinuten.value.match(/^[0-9]$|[0-5][1-46-9]/)) fehler='Bitte geben Sie eine seriöse Uhrzeit ein';
		}
	}
if(document.patch.WahlWoTag.value=='_') fehler='Bitte geben Sie den Wochentag an!';
if(document.patch.WahlAngebot.value=='_') fehler='Bitte geben Sie die Art des Termins an!';
if(document.patch.WahlRegel.value=='_') fehler='Bitte geben Sie an, ob der Termin regelmäßig stattfindet!';
if(document.patch.WahlSprache.value=='_') fehler='Bitte geben Sie an, in welcher Sprache der Termin stattfindet!';
if(!fehler) check=1; else alert(fehler);
return check;
}


function checkAddForm7(Stunden, Minuten)
{
alert(Stunden);
check=0;
fehler=false;
if(Stunden=='' || Minuten=='')
	{fehler='Bitte geben Sie die Uhrzeit ein!';}
 else
 	{if(Stunden>23 || Minuten>59 || Stunden.match(/[^0-9]/) || Minuten.match(/[^0-9]/)) {fehler='Bitte geben Sie eine gültige Uhrzeit ein!';}
		else {
		if(Minuten.match(/^[0-9]$|[0-5][1-46-9]/)) fehler='Bitte geben Sie eine seriöse Uhrzeit ein';
		}
	}
if(!fehler) check=1; else alert(fehler);
return check;
}





function clipBoard(x)
{
	t=0;
	inlay='Block_0';
	while(document.getElementById(inlay)) {
		if(t==x)document.getElementById(inlay).style.display='block'; else document.getElementById(inlay).style.display='none';
		t++;
		inlay='Block_'+t;
	}
}


var IsExtended, YesDoExtend;
function selectCheck(a){
if(a==1) {
if(document.search.typ0.checked==true)
for(c=1;c<=12;c++) document.search.elements['typ'+c].checked=false; else document.search.typ0.checked=true;
if(IsExtended==true && document.search.searchText.value=='') SrincDropDown();
} else {
YesDoExtend=false;
for(c=1;c<=12;c++) if(document.search.elements['typ'+c].checked==true) YesDoExtend=true;
if(YesDoExtend==true)document.search.typ0.checked=false;else document.search.typ0.checked=true;
var textsearch= document.search.searchText.value;
var textsearch=textsearch.replace(/  | |[%&/$?!]/g, '');
if(textsearch.length>3) YesDoExtend=true;
if(YesDoExtend==true) ExtendDropDown();
else if(IsExtended==true) SrincDropDown();
}
}

function ExtendDropDown() {
if(!IsExtended) {
var relatedElement = document.getElementById('UKrS');
var KMStep = new Array(50,75,100,200);

for(c=0;c<=3;c++) {
var km = KMStep[c];
relatedElement.options[relatedElement.options.length] = new Option("Umkreis bis " + km + "km", km);
}
IsExtended = true;
}
}

function SrincDropDown() {
var relatedElement = document.getElementById('UKrS');
relatedElement.options.length = 3;
IsExtended = false;
}




var showMsgLocationIsOpen = 0;
var pid;
var latitude = Array();
var longitude = Array();

function showMsgLocation() {
html="<iframe style='position:absolute;display:none;display:block;z-index:-1; width:3000px; height:3000px; top:0; left:0; filter:mask();border:0px;'></iframe><div class='schattenboxRechts' style='border:0px;position:relative;padding:0px 10px 0px 0px; width:250px;'>";
html+="<div style='background-color:#FFFFFF;border:1px solid;padding:10px 10px 10px 10px;'>Um die Kirche auf der Landkarte richtig zu positionieren, ziehen Sie einfach die Markierung an die richtige Stelle und klicken Sie auf speichern.<p style='padding-top:10px;'><input type='button' class='button3' id='NewPosCancel' value='abbrechen' onclick='closeMsgLocation()'>&nbsp;<input type='button' class='button1' id='NewPosSave' value='speichern' onclick='saveMsgLocation(pid)'> </div></div><div class='schattenboxUnten'></p></div>";
  var msglocation = document.getElementById('msglocation');
  msglocation.innerHTML=html;
  showMsgLocationIsOpen=1;
}

function closeMsgLocation(){
  var msglocation = document.getElementById('msglocation');
  msglocation.innerHTML='';
  showMsgLocationIsOpen=0;
}

function saveMsgLocation(ChurchID){

  var msglocation = document.getElementById('msglocation');
  msglocation.innerHTML='';

var xmlhttp;

if(ChurchID && ChurchID>0) {

if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Ihr Browser unterstützt diese Funktion leider nicht.");
  }
xmlhttp.onreadystatechange=function()
{

if(xmlhttp.readyState==4)
  {
  msglocation.innerHTML=xmlhttp.responseText;
    latitude[pid]=marker.getPoint().lat();
    longitude[pid]=marker.getPoint().lng();
    window.setTimeout("msglocation.innerHTML=''", 3000);

  } else {
  msglocation.innerHTML='';
  html="<iframe style='position:absolute;display:none;display:block;z-index:-1; width:3000px; height:3000px; top:0; left:0; filter:mask();border:0px;'></iframe><div class='schattenboxRechts' style='border:0px;position:relative;padding:0px 10px 0px 0px; width:250px;'>";
  msglocation.innerHTML=html+="<div style='background:url(./grafik/timebar.gif) center center no-repeat;background-color:#FFFFFF;border:1px solid;padding:10px 10px 10px 10px;'> </div></div><div class='schattenboxUnten'></p></div>";
  showMsgLocationIsOpen=0;
  }
}


xmlhttp.open("GET","./diomiraapi?SID=" + SessionID + "&ChurchID="+ChurchID+"&newGeo="+marker.getPoint()+"&ident={" + authentication + "}&action=setgeopos",true);
xmlhttp.send(null);
}


}




function doChurchLog(ChurchID,roodID) {
openlayer(roodID);
getAjax(ChurchID,'startLog');
}

function openlayer(roodID) {

x= findPosX(document.getElementById(roodID));
y= findPosY(document.getElementById(roodID));

	if(IE) {
	WindowWidth =document.body.clientWidth;
	WindowHeight =document.body.clientHeight;
	} else {
	WindowWidth=window.innerWidth;
	WindowHeight=window.innerHeight;
	}

//Bildschirm sperren
document.getElementById('Layer').style.top='0px';
document.getElementById('Layer').style.left='0px';
document.getElementById('Layer').style.width=WindowWidth+'px';
document.getElementById('Layer').style.height=WindowHeight+50+'px';
document.getElementById('Layer').className='transparenz';

document.getElementById('PopUP').style.top=y+'px';
document.getElementById('PopUP').style.left=x+'px';
document.getElementById('PopUP').className='LayerBox';

document.getElementById('PopUP').innerHTML="<div onclick='closelayer();' style='background:url(./grafik/fensterschliessen.gif) top right no-repeat; width:100%; margin-right:10px; height:20px;'></div><div ID='LayerContainer'></div>";

}

function closelayer() {
document.getElementById('Layer').style.top='0px';
document.getElementById('Layer').style.left='0px';
document.getElementById('Layer').style.width='0px';
document.getElementById('Layer').style.height='0px';
document.getElementById('Layer').className='';
document.getElementById('PopUP').style.top='0px';
document.getElementById('PopUP').style.left='0px';
document.getElementById('PopUP').style.width='0px';
document.getElementById('PopUP').style.height='0px';
document.getElementById('PopUP').className='';
document.getElementById('PopUP').innerHTML='';
}

function getAjax(ChurchID,LayerAction) {
var container = document.getElementById('LayerContainer');
var xmlhttp;
if (window.XMLHttpRequest)
  {
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else if (window.ActiveXObject)
  {
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
else
  {
  alert("Ihr Browser unterstützt diese Funktion leider nicht.");
  }
xmlhttp.onreadystatechange=function()
{

if(xmlhttp.readyState==4)
  {
	container.innerHTML=xmlhttp.responseText;
  } else {
  container.innerHTML='';
  html="<iframe style='position:absolute;display:none;display:block;z-index:-1; width:3000px; height:3000px; top:0; left:0; filter:mask();border:0px;'></iframe>";
  container.innerHTML=html+="<div style='background:url(./grafik/timebar.gif) center center no-repeat;background-color:#FFFFFF;border:1px solid;padding:10px 10px 10px 10px;'> </div>";
  }
}
xmlhttp.open("GET","./diomiraapi?SID=" + SessionID + "&ChurchID="+ChurchID+"&ident={" + authentication + "}&action="+LayerAction,true);
xmlhttp.send(null);
}

