function leeren(element) {
 if (element.className == 'mail3') {
  element.value = "";
  element.className = 'mail2';
 }
}

function loesch(id) { 
 check = confirm("Soll der Termin wirklich geloescht werden?");
 if (check == true ) { window.location.replace('auth.php?m=1&mod=l&id='+id); }
}

function loeschbild(id) { 
 check = confirm("Soll dieses Bild wirklich geloescht werden?");
 if (check == true ) { window.location.replace('auth.php?m=2&mod=l&id='+id); }
}

function presse(bild,b,h) {
 if (window.voll) { voll.close(); }
 voll = window.open('view.php?bild='+bild,'Vollbild','height='+h+',width='+b+',top=30,left=50,scrollbars=yes');
 voll.focus();
}


function impress(e) {
   fbreite = 400; fhoehe = 490;
   breite = screen.width; hoehe  = screen.height; links  = e.screenX; oben   = e.screenY;
   if (links + fbreite < breite) { versatzx = links + 3; } else { versatzx = links - fbreite + 3; }
   if (oben  + fhoehe < hoehe)  { versatzy = oben + 3; } else { versatzy = oben - fhoehe + 18; }

   press = window.open('i.php','Im','left='+versatzx+',top='+versatzy+',height='+fhoehe+',width='+fbreite+',scrollbars=auto');
   press.focus();

}

function checkmaus(e,bilddiv) {
 mausx = (document.all) ? e.clientX + document.body.scrollLeft : e.pageX;
 mausy = (document.all) ? e.clientY + document.body.scrollTop  : e.pageY;

 a=mausx-findeL(bilddiv);
 b=mausy-findeO(bilddiv);

 l=document.getElementById('loch');
 m=document.getElementById('maske');

 posx = a-m.clientWidth/2;
 posy = b-m.clientHeight/2;


if (a < parseInt(l.clientWidth/2)) { posx=parseInt(l.clientWidth/2-m.clientWidth/2); }
if (b < parseInt(l.clientHeight/2)) {posy=parseInt(l.clientHeight/2-m.clientHeight/2); }
if (a > parseInt(m.clientWidth/2-l.clientWidth/2)) { posx=-parseInt(l.clientWidth/2); }
if (b > parseInt(m.clientHeight/2-l.clientHeight/2)) { posy=-parseInt(l.clientHeight/2); }

 m.style.left=posx;
 m.style.top=posy;
}

function crop(id,w,h) {

lcrop = m.clientWidth/2+posx-l.clientWidth/2;
ocrop = m.clientHeight/2+posy-l.clientHeight/2;

window.location.href='?m=2&mod=crop&id='+id+'&l='+lcrop+'&o='+ocrop+'&w='+w+'&h='+h;

}


function findeL(obj) {
 var lPos = 0;
 if (obj.offsetParent) { while (obj.offsetParent){ lPos += obj.offsetLeft; obj = obj.offsetParent; }
 } else if (obj.x) { lPos += obj.x; }
 return lPos;
}

function findeO(obj) {
 var oPos = 0;
 if (obj.offsetParent) { while (obj.offsetParent){ oPos += obj.offsetTop; obj = obj.offsetParent; }
 } else if (obj.y) { oPos += obj.y; }
 return oPos;
}



function checkdat(elem) {
 wert = elem.value; if (!wert) { return false; }
 var regex = /^([0-3][0-9])\.([0-1][0-9])\.(\d{4})$/;
 erg = regex.exec(wert);
 if (!erg) {  alert("Geben Sie ein gueltiges Datum im Format 'TT.MM.JJJJ' an."); elem.focus(); return false; 
 } else { 

  tag = RegExp.$1; mon = RegExp.$2; jah = RegExp.$3; 
  tmp = new Date(jah,mon,0);
  if(tmp.getDate() < tag || mon > 12) {  alert('Datum hat richtiges Format, ist aber kein gueltiges Datum.'); elem.focus(); return false; 
  } else { return wert; }

 } 
}

function checktim(elem) {
 wert = elem.value; if (!wert) { return false; }
 var regex = /^([0-9][0-9])\:([0-5][0-9])$/;
 erg = regex.exec(wert);
 if (!erg) {  alert("Geben Sie eine gueltige Uhrzeit im Format 'HH:MM' an."); elem.focus(); return false; 
 } else { 

  stunde = RegExp.$1; minute = RegExp.$2;
  tmp = new Date(2000,1,0,stunde,minute,0);
  if(stunde > 23 || minute > 59) {  alert('Uhrzeit hat richtiges Format, ist aber keine gueltige Uhrzeit.'); elem.focus(); return false; 
  } else { return wert; }

 } 
}



function speichern() {

 if (!document.tourform.ort.value)     { alert('Bitte geben Sie einen Ort ein.');          document.tourform.ort.focus();     return false; } 
 if (!document.tourform.loc.value)     { alert('Bitte geben Sie eine Location ein.');      document.tourform.loc.focus();     return false; } 
 if (!document.tourform.veranst.value) { alert('Bitte geben Sie eine Veranstaltung ein.'); document.tourform.veranst.focus(); return false; } 

 if (!document.tourform.vdat.value) { 
	alert("Bitte geben Sie ein Datum bei 'Von' ein.");
	document.tourform.vdat.focus();
	return false; 
 } else { rvdat = checkdat(document.tourform.vdat); } 

 if (!document.tourform.vtim.value) { 
	alert("Bitte geben Sie eine Uhrzeit bei 'Von' ein.");
	document.tourform.vtim.focus();
	return false; 
 } else { rvtim = checktim(document.tourform.vtim); } 

 if (!document.tourform.bdat.value) { 
	alert("Bitte geben Sie ein Datum bei 'Bis' ein."); 
	document.tourform.bdat.focus(); 
	return false; 
 } else { rbdat = checkdat(document.tourform.bdat); } 

 if (!document.tourform.btim.value) { 
	alert("Bitte geben Sie eine Uhrzeit bei 'Bis' ein.");
	document.tourform.btim.focus();
	return false; 
 } else { rbtim = checktim(document.tourform.btim); } 


 if (rvdat && rbdat && rvtim && rbtim) { 
   dv = rvdat.split("."); tv = rvtim.split(":"); tmpvon = new Date(dv[2],dv[1],dv[0],tv[0],tv[1],0);
   db = rbdat.split("."); tb = rbtim.split(":"); tmpbis = new Date(db[2],db[1],db[0],tb[0],tb[1],0);
   if (tmpvon >= tmpbis) { alert("Datum 'Von' darf nicht nach Datum 'Bis' liegen oder gleich sein."); document.tourform.vdat.focus(); return false; 
   } else { document.tourform.subm.value='Speichern'; document.tourform.submit();  }
 }

}



