//globalni promenne
var dopredu = 2;	//kolik dni dopredu pri inicializaci datumu ve formulari

//*******************************************************************
//	Pri kliknuti v Programu na odkaz REZERVOVAT se v URL za ? vraci titul predstaveni
//	 => to se vypise ve formulari.
// ?predstaveni=&den=&mesic=&rok=&cas=
function rezervaceURL(f) {

	if (location.search) 
	{	// na konci URL je ? s textem
		var obj = location.search;				//nacist retezec
		var fokus = 1;							//v URL byly informace o rezervaci
		obj = obj.substring(1, obj.length);		//odriznuti otazniku (1. znak)
		pole = obj.split("&");					//rozdeleni na polozky podel &
		var obj1 = "";
		for (var i=0; i < pole.length && fokus; i++) {
			parametr = pole[i].split("=");		//parametr - pole s 2 polozkami:
												//1. - index 0 = nazev parametru v URL
												//2. - index 1 = hodnota parametru v URL
			switch (parametr[0]) 
			{
				case "predstaveni":
					f.predstaveni.value = unescape(parametr[1]); 	//dekodovani escape sekvenci v URL					
				break;
				case "den":
					f.Den.value = parseInt(parametr[1]);					
				break;
				case "mesic":
					f.Mesic.value = parseInt(parametr[1]);					
				break;
				case "rok":
					f.Rok.value = parseInt(parametr[1]);					
				break;
				case "cas":
					f.hodina.value = unescape(parametr[1]); 	//dekodovani escape sekvenci v URL					
				break;
				default: fokus = 0;
			} //switch			
		} //for
//		location.hash = "rezervace";			//rolovani stranky na pozici "rezevace"		
		if (fokus) f.pocet.focus();
	}	//if
} //function rezervaceURL

//*******************************************************************
//	Pri kliknuti ve Workshopech na odkaz Prihlasit se v URL za ? vraci titul predstaveni
//	 => to se vypise ve formulari.
// ?workshop=&den=&mesic=&rok=&cas=
function workshopURL(f) {

	if (location.search) 
	{	// na konci URL je ? s textem
		var obj = location.search;				//nacist retezec
		var fokus = 1;							//v URL byly informace o workshopech
		obj = obj.substring(1, obj.length);		//odriznuti otazniku (1. znak)
		pole = obj.split("&");					//rozdeleni na polozky podel &
		var obj1 = "";
		for (var i=0; i < pole.length && fokus; i++) {
			parametr = pole[i].split("=");		//parametr - pole s 2 polozkami:
												//1. - index 0 = nazev parametru v URL
												//2. - index 1 = hodnota parametru v URL
			switch (parametr[0]) 
			{
				case "workshop":
					f.workshop.value = unescape(parametr[1]); 	//dekodovani escape sekvenci v URL
				break;
				case "den":
					f.Den.value = parseInt(parametr[1]);					
				break;
				case "mesic":
					f.Mesic.value = parseInt(parametr[1]);					
				break;
				case "rok":
					f.Rok.value = parseInt(parametr[1]);					
				break;
				case "cas":
					f.hodina.value = unescape(parametr[1]); 	//dekodovani escape sekvenci v URL					
				break;
				default: fokus = 0;
			} //switch			
		} //for
//		location.hash = "workshopy";			//rolovani stranky na pozici "workshopy"		
		if (fokus) f.pocet.focus();
	}	//if
} //function workshopURL

//*******************************************************************
//nastavi ve formulari datum o dva dny pozdeji
function datumInit(f) {
        var datum1 = new Date();        //dnesni datum
        var datum = new Date(datum1.getYear(),datum1.getMonth(),datum1.getDate() + dopredu); //dnesni datum + pocet dni dopredu

        f.Den.value = datum.getDate();
        f.Mesic.value = datum.getMonth() + 1;
        f.Rok.value = datum.getYear();

} //function datumInit

//*******************************************************************
//inicializuje formular REZERVACE
function rezervaceInit(f) {        
        datumInit(f);
} //function rezervaceInit

//*******************************************************************
//inicializuje formular WORKSHOPY
function workshopInit(f) {        
        datumInit(f);
} //function workshopInit


//*******************************************************************
//zjisti hodnotu vybraneho prepinaciho tlacitka
function radioValue(radio) {
	var hodnota = null;
	for (var i=0; i<radio.length; i++) {
 		if (radio[i].checked) {
			hodnota = radio[i].value;
			return hodnota;
		} //if
	} //for
   return hodnota; 
} // function radioValue

//*******************************************************************
//kontroluje polozky formulare REZERVACE pred odeslanim
function rezervaceSubmit(f) {
var pocetVstupenek = 500;
var chyby = "", upozorneni = "";
var alertTxt = "", confirmTxt = "";

		//predstaveni
        if (f.predstaveni.value == "") chyby += "   --> It is necessary to fill out the item \"Performance\"    \n";

        //datum
        var datum = new Date();
        if (Date.UTC(f.Rok.value,f.Mesic.value-1,f.Den.value) < Date.UTC(datum.getYear(),datum.getMonth(),datum.getDate())) chyby += "   --> Old date - cannot make a reservation for past performances    \n";
		var frmDatum = new Date(f.Rok.value,f.Mesic.value-1,f.Den.value);
		if (frmDatum.getDate() != f.Den.value) chyby += "   -->  Bad date - please fill in a valid date    \n";
		
        //pocet vstupenek
       if (f.pocet.value == "" ) {
               chyby += "   --> It is necessary to fill out the item \"Number of tickets\"    \n";
       } else {
               	if ( f.pocet.value <= 0)
               		chyby += "   --> Number of persons must be a positive intereger.    \n";
					
				// osetreni kapacity	   
/*				if (f.pocet.value > pocetVstupenek)
	                	chyby += "   --> The number of tickets must not exceed the capacity "+pocetVstupenek+" for reservation    \n";
*/
		} //else
		
		//na jmeno
        if (f.jmeno.value == "") chyby += "   --> It is necessary to fill out the item \"Name, Surname\"    \n";

		
        //kontakt
        if (f.potvrzeni.value == "")
                upozorneni += " Should you require us to confirm your order, please fill out the item \"Contact for confirmation of the order (e-mail)\".    \nWithout a confirmation your order cannot be guaranteed.";

        if (chyby != "")
                alertTxt += " The form cannot be sent for the following reasons:    \n\n"+chyby+"\n\nPlease, correct the relevant data. Thank you.";

        if ( upozorneni != "")
                confirmTxt += " Warning:\n\n"+upozorneni+"\n\n\nDo you really want to send the form?";


        if ( Date.UTC(datum.getYear(),datum.getMonth(),datum.getDate()) <= (Date.UTC(f.Rok.value,f.Mesic.value-1,f.Den.value)) && (Date.UTC(f.Rok.value,f.Mesic.value-1,f.Den.value) < Date.UTC(datum.getYear(),datum.getMonth(),datum.getDate()+2)) ) {
                                //drive nez za 2 dny pouze telefonicky
                alert("notice:\n\nIf you want to book tickets for a performance to be held earlier than two days from now,   \n please, use our booking line +420-2-24817886 or +420-2-24813899!\nThank you.");
        } else {         //jinak zkontrolovat a odeslat formular
                if ( alertTxt != "") {
                        alert(alertTxt);
                 } else {
                        var odesli = confirmTxt != "" ? confirm(confirmTxt) : 1;
                 		if (odesli) f.submit(); else f.potvrzeni.focus();
				}
        } //if
} //function rezervaceSubmit

//kontroluje polozky formulare workshopy pred odeslanim
function workshopySubmit(f) {
var pocetVstupenek = 500;
var chyby = "", upozorneni = "";
var alertTxt = "", confirmTxt = "";

		//predstaveni
        if (f.workshop.value == "") chyby += "   --> It is necessary to fill out the item \"Workshop\"    \n";

        //datum
        var datum = new Date();
        if (Date.UTC(f.Rok.value,f.Mesic.value-1,f.Den.value) < Date.UTC(datum.getYear(),datum.getMonth(),datum.getDate())) chyby += "   --> Old date - cannot make a reservation for past performances!    \n";
		var frmDatum = new Date(f.Rok.value,f.Mesic.value-1,f.Den.value);
		if (frmDatum.getDate() != f.Den.value) chyby += "   --> Bad date - please fill in a valid date    \n";
		
        //pocet vstupenek
       if (f.pocet.value == "" ) {
               chyby += "   --> It is necessary to fill out the item \"Number of tickets\"    \n";
       } else {
               	if ( f.pocet.value <= 0)
               		chyby += "   --> Number of persons must be a positive intereger.    \n";
					
				// osetreni kapacity	   
/*				if (f.pocet.value > pocetVstupenek)
	                	chyby += "   --> počet vstupenek nesmí převyšovat kapacitu "+pocetVstupenek+" míst k rezervaci    \n";
*/
		} //else
		
		//na jmeno
        if (f.jmeno.value == "") chyby += "   --> It is necessary to fill out the item \"Name, Surname\"    \n";

		//e-mail
//        if (f.email.value == "") chyby += "   --> je nutno vyplnit položku \"E-mail\"    \n";

		
        //kontakt
        if (f.email.value == "")
                upozorneni += "Should you require us to confirm your order, please fill out the item \"E-mail\".    \nWithout a confirmation your order cannot be guaranteed.";

        if (chyby != "")
                alertTxt += "The form cannot be sent for the following reasons:    \n\n"+chyby+"\n\nPlease, correct the relevant data. Thank you.";

        if ( upozorneni != "")
                confirmTxt += "Warning:\n\n"+upozorneni+"\n\n\nDo you really want to send the form?";


        if ( Date.UTC(datum.getYear(),datum.getMonth(),datum.getDate()) <= (Date.UTC(f.Rok.value,f.Mesic.value-1,f.Den.value)) && (Date.UTC(f.Rok.value,f.Mesic.value-1,f.Den.value) < Date.UTC(datum.getYear(),datum.getMonth(),datum.getDate()+2)) ) {
                                //drive nez za 2 dny pouze telefonicky
                alert("notice:\n\nIf you want to apply for a workshop to be held earlier than two days from now,   \n please, use our booking line +420-2-24817886 or +420-2-24813899!\nThank you.");
        } else {         //jinak zkontrolovat a odeslat formular
                if ( alertTxt != "") {
                        alert(alertTxt);
                 } else {
                        var odesli = confirmTxt != "" ? confirm(confirmTxt) : 1;
                 		if (odesli) f.submit(); else f.email.focus();
				}
        } //if
} //function workshopySubmit

//*******************************************************************
//kontroluje polozky formulare NABIDKA ZARAZENI DO ADRESARE pred odeslanim
function nabidkaSubmit(f) {
var chyby = "", upozorneni = "";
var alertTxt = "", confirmTxt = "";
	
		//jmeno
        if (f.jmeno1.value == "") chyby += "   --> It is necessary to fill out the item \"Name\"    \n";
			
		//email
       	if (f.email.value == "") chyby += "   --> It is necessary to fill out the item \"E-mail\"    \n";			
	
	if (chyby != "")  alertTxt += " The form cannot be sent for the following reasons:    \n\n"+chyby+"\n\n Please, correct the relevant data. Thank you.";
	if ( alertTxt != "") {
    	alert(alertTxt);
    } else {
    	var odesli = confirmTxt != "" ? confirm(confirmTxt) : 1;
    	if (odesli) f.submit(); else f.potvrzeni.focus();
	}

} //function nabidkaSubmit
