//allgemeine variable


function MM_openBrWindow(theURL,winName,features) { 
window.open(theURL,winName,features);
}
function MM_openBrWindow1(theURL,winName,features) { 
fenster=window.open(theURL,winName,features);
fenster.focus();
}
function checkRadio(entry,meldung){

sch=0;
for (var i = 0; i < entry.length; i++) {
    if(entry[i].checked == true){sch++;}
  }
if(sch<1){
	entry[0].focus();
	alert("Bitte bei " +meldung+ " eine Auswahl treffen!");
	return false;}

return true;
}

function checkDatum(entry){
var val = entry.value + "";
if(val.length < 10 || val.length > 10){
	entry.focus();
     
      alert("Ungültiges Datum!");
      return false;}
if(val.substr(4,1) != "-" || val.substr(7,1) != "-"){
	entry.focus();
     
      alert("Ungültiges Datum!");
      return false;}
jj=val.substr(0,4);
mm=val.substr(5,2);
tt=val.substr(8,2);
 if (!validDate(tt, mm, jj)) {
	entry.focus();
     
      alert("Ungültiges Datum!");
      return false;}
return true;
}

function checkZeit(entry){
var val = entry.value + "";
if(val.length < 5 || val.length > 5){
	entry.focus();
     
      alert("Ungültige Eingabe!");
      return false;}
if(val.substr(2,1) != ":"){
	entry.focus();
     
      alert("Ungültige Eingabe!");
      return false;}
hh=val.substr(0,2);
mm=val.substr(3,2);


 if ((hh < "00")  || (hh > "24") || (hh == "NaN")) { 
	entry.focus();
     
      alert("Ungültige Eingabe!");
      return false;}
 if ((mm < "00")  || (mm > "59") || (mm == "NaN")) {entry.focus();
     
      alert("Ungültige Eingabe!");
      return false;}

return true;
}
function validDate(day, mon, year)   {

 // mon = mon + "";
  //year = year + "";
  //mon = mon.toUpperCase();


 

 if ((day < "01")  || (day > "31") || (day == "NaN")) { return 0;  }
 if ((mon < "01")  || (mon > "12") || (mon == "NaN")) { return 0;  }
  if ((year < 0)  || (year > 9999) || (year == "NaN") || (year == "---")) { return 0;  }
  if ((mon != "01") && (mon != "02") && (mon != "03") && (mon != "04") && (mon != "05") && (mon != "06") && (mon != "07") && (mon != "08") && (mon != "09") && (mon != "10") && (mon != "11") && (mon != "12"))  { return 0; }
  if ((mon== "01") || (mon== "03") || (mon== "05") || (mon== "07") || (mon== "08") || (mon== "10") || (mon== "12")) { return 1;
  } else {
    if ((mon== "04") || (mon== "06") ||   (mon== "09") || (mon== "11")) {
      if (day <= 30)  {   return 1; }    }
    else {
      if (mon == "02")   {
        if (((year % 4) == 0) && ((year % 100) != 0))  {
          if (day <= 29) {  return 1;  }
        }
        if ((year % 400) == 0) {
          if (day <= 29)   {  return 1;    }
        }
        if (day <= 28) {  return 1;    }
      } else {
        return 0;
      }
    }
  }
  return 0;
}



function checkAnzahl(entry) {
  var val = entry.value + "";         
  var maxDecimalPlaces; 
  if (entry.form[entry.name+"_decimalPlaces"] == null) { 
    maxDecimalPlaces = 0; 
  } else { 
    maxDecimalPlaces = parseInt(eval(entry.form[entry.name+"_decimalPlaces"].value));
  }
  var newVal = ""; 
  var decimalPoint=false;
  var decimalPlaces=0;
  var thousandFoundIndex = -1;
  var dotFoundIndex = -1;
  var invalidNumber = false;
  if (val.length == 1 && val.substring(0,1) =="-") {      
    invalidNumber = true;
  }
  for (var i=0;i<val.length;i++)   {      
    letter=val.substring(i,i+1);          
    if ( ((letter<"0" || "9"<letter)&&(letter!=",")&&(letter!="-") && (letter!="."))
         || ((letter==",")&&(decimalPoint==true)) ) {
      entry.focus();
      entry.select();
      alert("Bitte nur Zahlen eingeben!");
      return false;
    }
    if ((decimalPoint==true)&&(letter!="-")) { decimalPlaces++; }
    if (decimalPlaces>maxDecimalPlaces && letter!="0") {
      entry.focus();
      entry.select();
      alert("Maximal erlaubte Dezimalstellen: " +maxDecimalPlaces);
      return false;
    }
    if ((letter=="-") && i!=0) {
      entry.focus();
      entry.select();
      alert("Ungültige Zahl");
      return false;
    }
    if (letter==",") { decimalPoint=true; }
    if (letter==".") {
      if (dotFoundIndex >= 0) {
        invalidNumber = true;
      } else {
        thousandFoundIndex = i;
      }
    }
    if (letter==",") {
      dotFoundIndex = i;
    }
    if (dotFoundIndex == i && i == (val.length - 1))  {
      invalidNumber = true;
    }
    if (thousandFoundIndex >= 0 && dotFoundIndex == i && ((dotFoundIndex - thousandFoundIndex) != 4))  {
      invalidNumber = true;
    }
    if (thousandFoundIndex >= 0 && dotFoundIndex < 0 && (i == val.length - 1) && (i - thousandFoundIndex != 3 )){
      invalidNumber = true;
    }
    newVal = newVal + letter;
  }
  entry.value = newVal;
  if (invalidNumber) {
    alert("Ungültige Zahl");
    entry.focus();
    entry.select();
    return false;
  }
  return true;
}

function checkText(entry) {
  var val = entry.value + "";
  val = val.replace(/ */, "");
  if (val.length > 0)  { return true; }
  entry.focus();
  entry.select();
  alert("Dieses Feld darf nicht leer sein.");
  return false;
}


function open_kalender(feld){
var breite = screen.width;
var hoehe = screen.height;
links = breite / 2;
oben =170;
 programm='kalender.php?feld='+feld;
F1 = window.open(programm,"kalender","scrollbars=no, resizable=yes, width=274,height=190,left="+links+",top="+oben);


}

function checkDatumVonBis() {
von=document.f.beginn.value;
bis=document.f.ende.value;
vjj=von.substr(6,4);
vmm=von.substr(3,2);
vtt=von.substr(0,2);
von=vjj+vmm+vtt;
bjj=bis.substr(6,4);
bmm=bis.substr(3,2);
btt=bis.substr(0,2);
bis=bjj+bmm+btt;


  if (bis < von) {

alert("Bitte wählen Sie ein Ende-Datum, dass nach dem Beginn-Datum liegt.");
  document.f.ende.focus();
    return false;
  }
  return true;
}


function beilage_zeigen(was) {
//alert(was);
x=document.getElementById(was).style.display;
if(x=="none"){
	document.getElementById(was).style.display="block";
	
}
else {
	document.getElementById(was).style.display="none";

}
}

function createXMLHttpRequest() {
var ua;
if(window.XMLHttpRequest) {
    try {
      ua = new XMLHttpRequest();
    } catch(e) {
      ua = false;
    }
  } else if(window.ActiveXObject) {
    try {
      ua = new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e) {
      ua = false;
    }
  }
  return ua;
}


function open_neu(programm){
dhtmlwindow.open("termin", "iframe", programm, "Neuer Termin", "width=280px,height=400px,resize=0,scrolling=0,center=0,left=500px,top=20px", "")
}
function open_iframe(programm){
breite=400;
hoehe=250;
bsposx=(screen.width / 2)  -  breite;
bsposy=(screen.height / 2) - hoehe;
dhtmlwindow.open("termine", "iframe", programm, "Neuer Termin", "width="+breite+"px,height="+hoehe+"px,resize=0,scrolling=0,left="+bsposx+"px,top="+bsposy+"px,center=1", "recal")
}
function open_iframea(programm){
breite=400;
hoehe=250;
bsposx=(screen.width / 2)  -  breite;
bsposy=(screen.height / 2) - hoehe;
dhtmlwindow.open("termine", "iframe", programm, "Termin ändern", "width="+breite+"px,height="+hoehe+"px,resize=0,scrolling=0,left="+bsposx+"px,top="+bsposy+"px,center=1", "recal")
}
function open_iframexxx(programm){
//alert(datumalt+'---'+fid);
//document.getElementById("termiframe").src = programm;
//MM_openBrWindow(programm,'termine','width=600,height=70,resizable=yes,scrollbars=yes')
//bsposx=window.event.clientX+165;
//bsposy=window.event.clientY;
bsposx=(screen.width -  400) / 2;
bsposy=(screen.height - 130) / 2;
termfenster = window.open(programm, "termine", "width=400,height=130,resizable=yes,scrollbars=yes,left="+bsposx+"px,top="+bsposy+"px,");
termfenster.focus();
}

function open_iframe_alt(programm){
//alert(datumalt+'---'+fid);
document.getElementById("termiframe").src = programm;
}
function open_ausfall(programm){
breite=400;
hoehe=100;
bsposx=(screen.width / 2)  -  breite;
bsposy=(screen.height / 2) - hoehe;
dhtmlwindow.open("termine", "iframe", programm, "Ausfall", "width="+breite+"px,height="+hoehe+"px,resize=0,scrolling=0,left="+bsposx+"px,top="+bsposy+"px,center=1", "recal")
}
function wartung(){
document.f2.action="wartung/berechtigung_pruefen.php";
document.f2.target="_wartung";
document.f2.submit();
}


function open_foto(pname,bild,titel,param){
dhtmlwindow.open(pname, 'inline', '<img src="'+bild+'">', titel, param, 'recal');
}	
function checksuchbegriff(){
if(!checkText(f1.suchbegriff)) { return false; }
x=document.f1.suchbegriff.value;
if(x.length<3){
	alert("Suchbegriff zu kurz");
	document.f1.suchbegriff.focus();
	return false;
}
return true;
}
