/*
CheckBeforeSubmit.JS
*/

function open_pick_author() {
	if(document.getElementById("pickAuthor").style.visibility == "visible") {
		document.getElementById("pickAuthor").style.visibility = "hidden";
	} else {
		document.getElementById("pickAuthor").style.visibility = "visible";
	}
}

function close_pick_author() {
	document.getElementById("pickAuthor").style.visibility = "hidden";
	var all_author = document.getElementById("autoren").value;
	var add_author = document.getElementById("pickAuthor").value;
//	alert(all_author + "; " + add_author);
	if (document.getElementById("autoren").value == "") {
		document.getElementById("autoren").value = add_author;
	} else {
		document.getElementById("autoren").value = all_author + "; " + add_author;
	}
}

function check_num(thevalue) {
  var onlythis ="0123456789";
  for (var i = 0; i < thevalue.length; i++)
   if (onlythis.indexOf(thevalue.charAt(i))<0 ) return false;
  return true;
}

function check_date(thedate) {
  if (!thedate) return false;
  thedate=thedate.toString();
  thedate=thedate.split(".");
  if (thedate.length!=3) return false;
  thedate[0]=parseInt(thedate[0],10);
  thedate[1]=parseInt(thedate[1],10)-1;
  if (thedate[2].length==2) thedate[2]="20"+thedate[2];
  var repeatcheck=new Date(thedate[2],thedate[1],thedate[0]);
  if (repeatcheck.getDate()==thedate[0] && repeatcheck.getMonth()==thedate[1] && repeatcheck.getFullYear()==thedate[2]) return true; else return false;
}

function check_time(thetime) {
  if (!thetime) return false;
  thetime=thetime.toString();
  thetime=thetime.split(":");
  if (thetime.length!=2) return false;
  if (check_num(thetime[0]) == false) { return false; }
  if (check_num(thetime[1]) == false) { return false; }
  thetime[0]=parseInt(thetime[0],10);
  thetime[1]=parseInt(thetime[1],10);
  if ((thetime[0] < 0) || (thetime[0] > 23)) { return false; }
  if ((thetime[1] < 0) || (thetime[1] > 59)) { return false; }
  return true;
}


function current_date() {
  var _now = new Date();
  var _day = _now.getDate();
  var _month = _now.getMonth();
  var _year = _now.getFullYear();
  curr_date = _day + "." + _month + "." +_year;
  return curr_date;
}

function current_time() {
  var _now = new Date();
  var _hours = _now.getHours();
  var _minutes = _now.getMinutes();
  curr_time = _hours + ":" + _minutes;
  return curr_time;
}

function open_upload_win(adresse,openerfield) {
  window.open(adresse+"?formfield="+openerfield,"Upload","width=300,height=200,scrollbars=yes,dependent=yes");
}

function checkSemAnmeldung() {

	document.getElementById("vorname").style.backgroundColor = "#ffffff";
	document.getElementById("nachname").style.backgroundColor = "#ffffff";	
	document.getElementById("strasse").style.backgroundColor = "#ffffff";
	document.getElementById("plz").style.backgroundColor = "#ffffff";
	document.getElementById("ort").style.backgroundColor = "#ffffff";
	document.getElementById("AGB_anerkannt").style.backgroundColor = "#ffffff";

	isOK = 1;
	myfocus = "";

	if(document.getElementById('AGB_anerkannt').checked == false ) {
		isOK = 0;
		myfocus = "AGB_anerkannt";
		document.getElementById("AGB_anerkannt").style.backgroundColor = "#EDF5E5";		
	}

	if(document.getElementById('ort').value == "" ) {
		isOK = 0;
		myfocus = "ort";
		document.getElementById("ort").style.backgroundColor = "#EDF5E5";		
	} 	
	
	if(document.getElementById('plz').value == "" ) {
		isOK = 0;
		myfocus = "plz";
		document.getElementById("plz").style.backgroundColor = "#EDF5E5";		
	}
	
	if(document.getElementById('strasse').value == "" ) {
		isOK = 0;
		myfocus = "strasse";		
		document.getElementById("strasse").style.backgroundColor = "#EDF5E5";
	}	
	
	if(document.getElementById('nachname').value == "" ) {
		isOK = 0;
		myfocus = "nachname";
		document.getElementById("nachname").style.backgroundColor = "#EDF5E5";		
	}	
	
	if(document.getElementById('vorname').value == "" ) {
		isOK = 0;
		myfocus = "vorname";
		document.getElementById("vorname").style.backgroundColor = "#EDF5E5";		
	} 
	
	if(isOK == 0) {
		alert("Es fehlen noch notwendige Angaben.");
		document.getElementById(myfocus).focus();
		return false;
	}

	document.forms[0].submit();
}

function checkZertAnmeldung() {

	document.getElementById("vorname").style.backgroundColor = "#ffffff";
	document.getElementById("nachname").style.backgroundColor = "#ffffff";	
	document.getElementById("strasse").style.backgroundColor = "#ffffff";
	document.getElementById("plz").style.backgroundColor = "#ffffff";
	document.getElementById("ort").style.backgroundColor = "#ffffff";
	document.getElementById("geburtsdatum").style.backgroundColor = "#ffffff";
	document.getElementById("geburtsort").style.backgroundColor = "#ffffff";

	isOK = 1;
	myfocus = "";

	if(document.getElementById('ort').value == "" ) {
		isOK = 0;
		myfocus = "ort";
		document.getElementById("ort").style.backgroundColor = "#EDF5E5";		
	} 	
	
	if(document.getElementById('plz').value == "" ) {
		isOK = 0;
		myfocus = "plz";
		document.getElementById("plz").style.backgroundColor = "#EDF5E5";		
	}
	
	if(document.getElementById('strasse').value == "" ) {
		isOK = 0;
		myfocus = "strasse";		
		document.getElementById("strasse").style.backgroundColor = "#EDF5E5";
	}	

	if(document.getElementById('AGB_anerkannt').checked == false ) {
		isOK = 0;
		myfocus = "AGB_anerkannt";
		document.getElementById("AGB_anerkannt").style.backgroundColor = "#EDF5E5";		
	}
	
	if(document.getElementById('erfahrung').checked == false ) {
		isOK = 0;
		myfocus = "erfahrung";
		document.getElementById("erfahrung").style.backgroundColor = "#EDF5E5";		
	}
	
	if(document.getElementById('geburtsort').value == "" ) {
		isOK = 0;
		myfocus = "geburtsort";
		document.getElementById("geburtsort").style.backgroundColor = "#EDF5E5";		
	}
	
	if(document.getElementById('geburtsdatum').value == "" ) {
		isOK = 0;
		myfocus = "geburtsdatum";
		document.getElementById("geburtsdatum").style.backgroundColor = "#EDF5E5";		
	}
	
	if(document.getElementById('nachname').value == "" ) {
		isOK = 0;
		myfocus = "nachname";
		document.getElementById("nachname").style.backgroundColor = "#EDF5E5";		
	}	
	
	if(document.getElementById('vorname').value == "" ) {
		isOK = 0;
		myfocus = "vorname";
		document.getElementById("vorname").style.backgroundColor = "#EDF5E5";		
	} 
	
	if(isOK == 0) {
		alert("Es fehlen noch notwendige Angaben.");
		document.getElementById(myfocus).focus();
		return false;
	}

	document.forms[0].submit();
}
