﻿function check_managelocations() {
	var dowhat = document.managelocations.dowhat.value; 
	var loc_name = document.managelocations.loc_name.value;
	var loc_stadt = document.managelocations.loc_stadt.value;
	var errortext="";
	var check = true;
	if(loc_name == "") {
		errortext +="Der Name der Location muss ausgefüllt werden!";
	}
	if (loc_stadt =="") {
		errortext +="Die Stadt der Location muss ausgefüllt werden!";
	}
	if (errortext !=""){
		errortext="Folgende Fehler sind aufgetreten:\n\n" + errortext;
		alert(errortext);
	} else {
		if (dowhat == "delete"){
			check = confirm("Soll diese Location wirklich gelöscht werden?");
		}
		if (check == true){
			document.managelocations.submit();
		}
	}
}

function check_managebands() {
	var dowhat;
	var bnd_name;
	dowhat = document.manageband.dowhat.value; 
	bnd_name = document.manageband.bnd_name.value;
	var check = true;
	if(bnd_name == "") {
		alert("Folgender Fehler ist aufgetreten:\n\nDer Bandname muss ausgefüllt werden!");
	}
	else {
		if (dowhat == "delete"){
			check = confirm("Soll diese Band wirklich gelöscht werden?");
		}
		if (check == true){
			document.manageband.submit();
		}
	}
}

function check_newscomm() {
	var dowhat = document.insertcomment.dowhat.value; 
	var nec_text = document.insertcomment.nec_text.value;
	var check = true;
	if(nec_text == "") {
		alert("Folgender Fehler ist aufgetreten:\n\nDas Kommentar muss ausgefüllt werden!");
	}
	else {
		if (dowhat == "delete"){
			check = confirm("Soll dieses Kommentar wirklich gelöscht werden?");
		}
		if (check == true){
			document.insertcomment.submit();
		}
	}
}

function check_managestage() {
	var dowhat = document.managestage.dowhat.value; 
	var check = true;
	if (dowhat == "delete"){
		check = confirm("Soll diese Bühne (und alle dazugehörigen Daten) wirklich gelöscht werden?");
	}
	if (check == true){
		document.managestage.submit();
	}
}

function check_manageslots() {
	var dowhat = document.manageslots.dowhat.value; 
	var check = true;
	var errortext="";
	var bnd_bandid= document.manageslots.bnd_bandid.value
	var bnd_name=document.manageslots.bnd_name.value
	var fsl_datum= document.manageslots.fsl_datum.value
	if (bnd_bandid=="") {
		if (bnd_name ==""){
			errortext +="Es muss eine Band eingegeben werden\n";
		}else {
			var check = confirm("Soll die Band " + bnd_name +" angelegt werden?");
			if (check == false){
				errortext +="Es muss eine Band eingegeben werden\n";
			} else{
				document.manageslots.add_band.value = 1;
			}
		}
	}
	if (fsl_datum=="") {
			errortext +="Es muss ein Datum eingegeben werden\n";
	}
	if (errortext !=""){
		errortext="Folgende Fehler sind aufgetreten:\n\n" + errortext;
		alert(errortext);
	} else {
		if (dowhat == "delete"){
			check = confirm("Soll dieser Slot wirklich gelöscht werden?");
		}
		if (check == true){
			document.manageslots.submit();
		}
	}
}

function check_managenews() {
	var dowhat=document.insertnews.dowhat.value;
	var check = true;
	var errortext = "";
	
	if (dowhat != "delete") {
		var oEditor = FCKeditorAPI.GetInstance('new_text') ;
		var new_text = oEditor.GetHTML();
		if (new_text=='<br type="_moz" />'){
			new_text="";
		}
		var new_headline = document.insertnews.new_headline.value;
		var new_refid=document.insertnews.new_refid.value;
		var new_reftypeid1=document.insertnews.new_reftypeid[0].checked;
		var new_reftypeid2=document.insertnews.new_reftypeid[1].checked;
		var new_datum=document.insertnews.new_datum.value;
		
		if (new_text=="") {
			errortext +="Es muss eine Newsmeldung eingegeben werden\n";
		}
		if (new_headline == "") {
			errortext += "Es muss eine Headline eingegeben werden\n";
		}
		if (new_datum == "") {
			errortext += "Es muss ein Datum eingegeben werden\n";
		}
		if (new_reftypeid1 == true && new_refid == "") {
			errortext += "Es muss ein Festival eingegeben werden\n";
		}
		if (new_reftypeid2 == true && new_refid == "") {
			errortext += "Es muss ein Event eingegeben werden\n";
		}
	}
	if (errortext != "") {
		errortext="Folgende Fehler sind aufgetreten:\n\n" + errortext;
		alert(errortext);
	} else {
		if (dowhat =="delete"){
			check = confirm("Soll diese News wirklich gelöscht werden?");
		}
		if (check == true){
			document.insertnews.submit();
		}
	}
}

function check_managefestivals() {
	var dowhat=document.managefestivals.dowhat.value;
	var check = true;
	var errortext = "";
	var fst_datum= "";
	
	if (dowhat != "delete") {
		var fst_name = document.managefestivals.fst_name.value;
		var fst_ort=document.managefestivals.fst_ort.value;
		if (dowhat=="insert"){
			fst_datum=document.managefestivals.fst_datum.value;
		} else {
			fst_datum=" ";
		}
			
		if (fst_name=="") {
			errortext +="Es muss ein Festivalname eingegeben werden\n";
		}
		if (fst_ort == "") {
			errortext += "Es muss eine Ort eingegeben werden\n";
		}
		if (fst_datum == "") {
			errortext += "Es muss ein Datum eingegeben werden\n";
		}
	}
	if (errortext != "") {
		errortext="Folgende Fehler sind aufgetreten:\n\n" + errortext;
		alert(errortext);
	} else {
		if (dowhat =="delete"){
			check = confirm("Soll dieses Festival (und alle dazugehörigen Daten) wirklich gelöscht werden?");
		}
		if (check == true){
			document.managefestivals.submit();
		}
	}
}

function check_manageinterviews() {
	var dowhat=document.manageinterviews.dowhat.value;
	var check = true;
	var errortext = "";
	var fst_datum= "";
	var iqa_cnt=document.manageinterviews.iqa_cnt.value
	var txt_value="";
	var order_value="";
	var txt_error="";
	var textcnt=0;
	if (dowhat != "delete") {
		if (document.manageinterviews.bnd_bandid.value == ""){
			errortext += "Es muss eine Band eingetragen werden\n";
		}
		if (document.manageinterviews.int_jahr.value == ""){
			errortext += "Es muss ein Jahr eingetragen werden\n";
		}
		for (var i =0; i< iqa_cnt;i++){
			eval('txt_value=document.manageinterviews.iqa_text'+i+'.value;');
			if (txt_value != ""){
				textcnt++;
				eval('order_value=document.manageinterviews.iqa_ordernr'+i+'.value;');
				if (order_value == ""){
					errortext += "Das Sortierfeld " + (i+1) + " muss ausgefüllt werden\n";
				}
			} 

		}
		if (textcnt==0){
			errortext += "Zumindest ein Textfeld muss ausgefüllt werden\n";
		}
	}
	if (errortext != "") {
		errortext="Folgende Fehler sind aufgetreten:\n\n" + errortext;
		alert(errortext);
	} else {
		if (dowhat =="delete"){
			check = confirm("Soll dieses Interview wirklich gelöscht werden?");
		}
		if (check == true){
			document.manageinterviews.submit();
		}
	}
}

function check_manageopenstage() {
	var dowhat=document.manageopenstage.dowhat.value;
	var check = true;
	var errortext = "";
	if (dowhat != "delete") {
		var oEditor = FCKeditorAPI.GetInstance('ost_text') ;
		var ost_text = oEditor.GetHTML();
		if (ost_text=='<br type="_moz" />'){
			ost_text="";
		}
		var ost_bandid = document.manageopenstage.bnd_bandid.value;
		var ost_fqid = document.manageopenstage.ost_fqid.value;
		if (ost_text=="") {
			errortext +="Es muss ein Text eingegeben werden\n";
		}
		if (ost_bandid == "") {
			errortext += "Es muss eine Band eingegeben werden\n";
		}
		if (ost_fqid == "") {
			errortext += "Es muss eine Frequency-ID eingegeben werden\n";
		}
	}
	if (errortext != "") {
		errortext="Folgende Fehler sind aufgetreten:\n\n" + errortext;
		alert(errortext);
	} else {
		if (dowhat =="delete"){
			check = confirm("Soll diese Open Stage Empfehlung wirklich gelöscht werden?");
		}
		if (check == true){
			document.manageopenstage.submit();
		}
	}
}

function check_manageevents() {
	var dowhat=document.manageevents.dowhat.value;
	var check = true;
	var errortext = "";
	if (dowhat != "delete") {
		var bnd_bandname = document.manageevents.bnd_name.value;
		if (bnd_bandname==""){
			document.manageevents.bnd_bandid.value="";
		}
		var bnd_bandid = document.manageevents.bnd_bandid.value;
		var loc_locationid = document.manageevents.loc_locationid.value;
		var evt_titel = document.manageevents.evt_titel.value;
		var evt_datum = document.manageevents.evt_datum.value;
		
		if (evt_datum=="") {
			errortext +="Es muss ein Datum eingegeben werden\n";
		}
		if (bnd_bandid == "" && evt_titel =="") {
			errortext += "Es muss entweder eine Band oder ein Titel eingegeben werden\n";
		}
		if (loc_locationid == "" ) {
			errortext += "Es muss eine Location eingegeben werden\n";
		}
	}
	if (errortext != "") {
		errortext="Folgende Fehler sind aufgetreten:\n\n" + errortext;
		alert(errortext);
	} else {
		if (dowhat =="delete"){
			check = confirm("Soll dieser Event wirklich gelöscht werden?");
		}
		if (check == true){
			document.manageevents.submit();
		}
	}
}

function check_fstcontact() {
	var dowhat = document.contact.dowhat.value; 
	var con_text = document.contact.con_text.value;
	var check = true;
	if(con_text == "") {
		alert("Folgender Fehler ist aufgetreten:\n\nDas Newsfeld muss ausgefüllt werden!");
	}
	else {
		if (dowhat=="fstcontact"){
			Modalbox.show('/manage/fstcontact.php',{title:'News abgesendet', params: Form.serialize('contact'), width:500, height:200 });
		}
	}
}


function check_gewinnspiel() {
	var antwort = document.gewinnspiel.antwort_text.value;
	var gspname=document.gewinnspiel.gsp_name.value;
	var check = true;
	var error="";
	if(antwort == "") {
		error="Die Antwort muss ausgefüllt werden!\n";
	}
	if(gspname==""){
		error+="Der Name muß ausgefüllt werden!\n";
	}
	if (error !=""){
		error="Folgende Fehler sind aufgetreten:\n\n"+error;
		alert(error);
	}
	else {
		Modalbox.show('/manage/gewinnspiel.php',{title:'An Gewinnspiel teilgenommen', params: Form.serialize('gewinnspiel'), width:500, height:200 });
	}
}

function check_contact() {
	var dowhat = document.contact.dowhat.value; 
	var con_text = document.contact.con_text.value;
	var check = true;
	if(con_text == "") {
		alert("Folgender Fehler ist aufgetreten:\n\nDas Kontaktfeld muss ausgefüllt werden!");
	}
	else {
		if (dowhat=="contact"){
			Modalbox.show('/manage/contact.php',{title:'Kontaktformular abgesendet', params: Form.serialize('contact'), width:500, height:500 });
		}else if (dowhat=="bewerbung"){
			Modalbox.show('/manage/contact.php',{title:'Bewerbung abgesendet', params: Form.serialize('contact'), width:500, height:500 });
		}
	}
}

function getNewsSelectionId(text, li) {
	document.insertnews.new_refid.value=li.id
}

function getSlotBandSelectionId(text, li) {
	document.manageslots.bnd_bandid.value=li.id
}

function emptySlotBandSelectionId(deft, query) {
	document.manageslots.bnd_bandid.value="";
	return query;
}

function getOSTBandSelectionId(text, li) {
	document.manageopenstage.bnd_bandid.value=li.id
}

function getEvtBandSelectionId(text, li) {
	document.manageevents.bnd_bandid.value=li.id
}

function getEvtLocSelectionId(text, li) {
	document.manageevents.loc_locationid.value=li.id
}

function getIntBandSelectionId(text, li) {
	document.manageinterviews.bnd_bandid.value=li.id
}

function checkIntTextChange(text) {
	
	if (text.value == "") {
		$('add').hide();
	}else {
		
		$('add').appear();
	}
}

function checkInfoChange() {
	
	if (document.manageslots.fsl_info_select.value == 5) {
		document.manageslots.fsl_info.value = '';
		$('zusatz').appear();
	}else {
		document.manageslots.fsl_info.value = document.manageslots.fsl_info_select.value;
		$('zusatz').hide();
	}
}

function checkSlotDateStageChange() {
	if (document.manageslots.fbn_buehnenid.value == document.manageslots.fbn_buehnenid_orig.value && document.manageslots.fsl_datum_orig.value == document.manageslots.fsl_datum.value) {
		$('sort').appear();
	}else {
		$('sort').hide();
	}
}