// JavaScript Document

function SendForm(formname,actionGo,abfrage,block){
	var trigger = 1;
	if(abfrage){
	if(abfrage.value==""){
			alert("Bitte wählen Sie zunächst ein Spiel aus.");
			trigger = 2;
		}
	}
	if(actionGo=="buchung_stehplatz.php"){
		if(document.formAuswahl.blockstehplatz.value==""){
				alert("Bitte wählen Sie zunächst einen Block aus.");
				trigger = 2;		
		}
	}
	if(trigger==1){
		document.forms[formname].action = actionGo;
		document.forms[formname].block.value = block;
		//alert(block);
		document.forms[formname].submit();
	}
	
}
function insertGPK(KGesamtpreis){
	var AnzK = parseInt(document.formBuchung.KKarten.value)
	var PreisK = parseInt(document.formBuchung.KPreis.value)
	var EUR =",00 €";
	var GPK =(AnzK * PreisK) + EUR;
	document.formBuchung.KGesamtpreis.value=GPK;

}
function insertGPE(EGesamtpreis){
	var AnzE = parseInt(document.formBuchung.EKarten.value)
	var PreisE = parseInt(document.formBuchung.EPreis.value)
	var EUR =",00 €";
	var GPE =(AnzE * PreisE) + EUR;
	document.formBuchung.EGesamtpreis.value=GPE;

}
function openBuchung(url,ID,Event,Remark,Event_day,Event_time,KPreis,EPreis){
	var weite = screen.width;
	var hoehe = screen.height;
	var left = (weite-710)/2;
	var top = (hoehe-500)/2;
	var fehler1 = "Diese Veranstaltung ist bereits ausverkauft!";
	var fehler2 = "Diese Veranstaltung wurde abgesagt!";
	
	if(Remark=="Ausverkauft"){
			alert(fehler1);  
			var fehler1 = 1;			
		}
		if(fehler1!=1){
	bWindow = window.open(url+"?ID="+ID+"&Event="+Event+"&Remark="+Remark+"&Event_day="+Event_day+"&Event_time="+Event_time+"&KPreis="+KPreis+"&EPreis="+EPreis,"New","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=710,height=500,left="+left+",top="+top);
	bWindow.focus();
}
	if(Remark=="ABGESAGT"){
			alert(fehler2);  
			var fehler1 = 2;			
		}
		if(fehler1!=2){
	bWindow = window.open(url+"?ID="+ID+"&Event="+Event+"&Remark="+Remark+"&Event_day="+Event_day+"&Event_time="+Event_time+"&KPreis="+KPreis+"&EPreis="+EPreis,"New","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=710,height=500,left="+left+",top="+top);
	bWindow.focus();
}
}

function openWin(url,eventID){
	
	var weite = screen.width-150;
	var hoehe = screen.height-500;
	var left = (weite)/2;
	var top = (hoehe)/2;
	bWindow = window.open(url+"?eventID="+eventID,"New","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=150,height=500,left="+left+",top="+top);
	bWindow.focus();
}
function openAuswertung(url,datum_von,datum_bis,art,eventID,excel,def){
	
	var weite = screen.width;
	var hoehe = screen.height;
	var left = 0;
	var top = 0;
	var urlNew = url+"?datum_von="+datum_von+"&datum_bis="+datum_bis+"&art="+art+"&eventID="+eventID+"&excel="+excel;
	var fehler1 = "Bitte waehlen Sie einen Zeitraum aus.";
	var fehler2 = "Bitte waehlen Sie ein Spiel aus.";
	
	if(!excel || excel==""){
		if(def==1 && (datum_von=="" || datum_bis=="" || !datum_von || !datum_bis)){
			alert(fehler1);  
			var fehler1 = 1;
		}
		if(def==2 && eventID==""){
			alert(fehler2);  
			var fehler1 = 1;			
		}
		if(fehler1!=1){
			bWindow = window.open(urlNew,"New","toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width="+weite+",height="+hoehe+",left="+left+",top="+top);
			bWindow.focus();
		}
	}
	if(excel){
		if(def==2 && eventID==""){
			alert(fehler2);  
			var fehler2 = 1;			
		}
		if(def==1 && (datum_von=="" || datum_bis=="" || !datum_von || !datum_bis)){
			alert(fehler1);  
			var fehler2 = 1;
		}		
		if(fehler2!=1){
			location.href=urlNew;
			//bWindow = window.open(urlNew,"New","toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width="+weite+",height="+hoehe+",left="+left+",top="+top);
			//bWindow.focus();			
		}
	}
}

function openUbZeiten(url){
	var weite = screen.width;
	var hoehe = screen.height;
	var left = 0;
	var top = 0;	
	bWindow = window.open(url,"New","toolbar=no,location=no,directories=no,status=no,menubar=yes,scrollbars=yes,resizable=yes,width="+weite+",height="+hoehe+",left="+left+",top="+top);
	bWindow.focus();
}


function nextBuchung(block){
	document.getElementById('plaetzeDiv').className = "showDiv";
	document.getElementById('nextButt').className = "hideDiv";
	
}


function zahlen_string_runden(x)
{
   var ergebnis;
// der Eingabewert wird gerundet und in einen String umgewandelt:
  var k = (Math.round(x * 100) / 100).toString();


// bei glatten Werten wird .00 angehängt:
  k += (k.indexOf('.') == -1)? '.00' : '00';

// fehlende führende Nullen werden aufgespürt und ggf. eingesetzt,
// Punkte werden durch Komata ersetzt:
  var p = k.indexOf('.'), m = k.indexOf('-.');
  var f = (p == 0 || m == 0)? '0.' : '.';

// der Rückgabewert wird zusammengesetzt:
   ergebnis = k.substring(0, p) + f + k.substring(p+1, p+3);
   return ergebnis;
}

function insertFields(kart,preis,zuschlag,vgeb){
	document.formBuchung.kartenartTxt.value=kart;
	document.formBuchung.kartenart.value=kart;
	document.formBuchung.preisTxt.value=preis;
	document.formBuchung.preis.value=preis;	

	preis = parseFloat(preis);
	zuschlag = parseFloat(zuschlag);
	vgeb = parseFloat(vgeb);
	var summe = preis + zuschlag + vgeb;
	summe = zahlen_string_runden(summe);
	
	document.formBuchung.gesamtpreisTxt.value=summe;	
	document.formBuchung.gesamtpreis.value=summe;	
}


function EintragDifferenz(){
	var anzahl = document.formBuchung.anzahlTickets.value;
	var rest = document.formBuchung.anzahlRest.value;
	anzahl = parseFloat(anzahl);
	rest = parseFloat(rest);	
	var diff = rest - anzahl;
	document.formBuchung.anzahlDifferenz.value=diff;	
	
}


function GotoDS(zStart,knummer,storno){
	document.formAuswahl.z.value=zStart;
	document.formAuswahl.kontrollnummer1.value=knummer;
	document.formAuswahl.stornieren.value=storno;
	//alert(document.formAuswahl.stornieren.value);
	document.formAuswahl.submit();
}

function GotoTicket(zStart,knummer){
	document.formAuswahl.z.value=zStart;
	document.formAuswahl.kontrollnummer.value=knummer;
	document.formAuswahl.submit();
}

function DruckOK(gedruckt,knummer){
	document.formAuswahl.gedruckt.value=gedruckt;
	document.formAuswahl.kontrollnummer.value=knummer;
	document.formAuswahl.submit();
}

function DruckOKSerie(gedrucktSerie){
	document.formAuswahl.gedrucktSerie.value=gedrucktSerie;
	document.formAuswahl.submit();
}


function openDruck(url){
	var weite = 800;
	var hoehe = 600;
	var left = (weite-800)/2;
	var top = (hoehe-450)/2;
	dWindow = window.open(url,"New","toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=yes,width=800,height=450,left="+left+",top="+top);
	dWindow.focus();
}
//aus dem blättern / Suchen Script
function pageset(wert) 
{ 
    document.form_nav.page_no.value = wert; 
    document.form_nav.submit();         
} 
//aus dem blättern / Suchen Script
function pageset2() 
{ 
    document.form_nav.page_no.value = document.form_nav.page.value; 
    document.form_nav.submit();         
}  

var neuesFenster;
function erzeugeFenster() {
neuesFenster= open("","displayWindow",
"height=300,width=300,top=10,left=10,scrollbars=yes");
neuesFenster.focus();
neuesFenster.document.open();
with(neuesFenster.document) {
write("<html><head><title>WARNUNG</title></head>");
write("<body bgcolor='#FF0000' color='#FFFFFF'><h2>Datensatz l&ouml;schen!</h2>");
write("<hr>Wollen Sie diesen Datensatz und ");
write("zugeh&ouml;rige Datens&auml;tze in anderen ");
write("Tabellen wirklich l&ouml;schen?");
write("<body><h2>L&ouml;schung ist unwiderruflich!</h2>");
write("<hr></body></html>");
}

neuesFenster.document.close();
}

function dataUebernahme(){
    var auswahl = document.stada.befugnisse.value;
    var valueTextfeld = document.stada.bem_function.value;
    var valueAuswahl = "\n"+auswahl;
    eval(document.stada.bem_function.value = 
document.stada.bem_function.value + valueAuswahl);
}

/*DIV auf sichtbar stellen */
function divshow(div) {
document.getElementById(div).style.display = "block";
}
/*DIV auf unsichtbar stellen */
function divhide(div) {
document.getElementById(div).style.display = "none";
}

function formActualize(){
	document.formAuswahl.submit();
}

function chkFormular () {
  if (document.formBuchung.KKarten.value == "" && document.formBuchung.EKarten.value == "") {
    alert("Bitte Anzahl der Karten eingeben!");
    document.formBuchung.realname.focus();
    return false;
  }
  if (document.formBuchung.realname.value == "") {
    alert("Bitte Ihren Namen eingeben!");
    document.formBuchung.realname.focus();
    return false;
  }
  if (document.formBuchung.strassenr.value == "" || document.formBuchung.plz.value == ""
	  || document.formBuchung.ort.value == "") {
    alert("Bitte Ihre komplette Anschrift eingeben!");
    document.formBuchung.strassenr.focus();
    return false;
   }
  if (document.formBuchung.tel.value == "" && document.formBuchung.mobil.value == "") {
    alert("Bitte Ihre tel. Erreichbarkeit eingeben!");
    document.formBuchung.tel.focus();
    return false;
 }
}
