// --------------- kalendář - více stránek
    function otevri_kal(prvek, akce) { 
	window.open("../kalendar.php?prvek="+prvek+"&akce="+akce,"Kalendar","width=280,height=330"); 
    }
function zobraz_koment() {
    document.getElementById('komentare').style.display='block';
}

// --------------- form_akce_1.php 

    function vrat_den(datum) {
	var dat = new Array();
	var n = 0;
	var posl = 0;
	for (i=0; i<datum.length; i++) {
	    if (datum.substring(i,i+1)==".") {
		dat[n]=datum.substring(posl,i);
		n++;
		posl=i+1;
	    }
	}
	dat[2]=datum.substring(posl,datum.length);
	dat_akce = new Date(dat[2], dat[1]-1, dat[0]);
	return dat_akce.getDay();
    } // -------------konec vrat_den()
    

    function zkontroluj_datum_n(zast, den, mess) {
	hlaska = "Chybně zadaný datum "+mess+"!";
	if (den==5) { 
            /*
	if ((den==2) || (den==5)) { 
	    if ((zast == "n_br") && (den!=2)) {
		alert (hlaska+"\nDo stanice Breda jedeme pouze v úterý");
		document.form1.dat_tam.focus();
		return false;
	    }
	    if ((zast == "n_ro") && (den!=2)) {
		alert (hlaska+"\nDo stanice Rotterdam jedeme pouze v úterý");
		document.form1.dat_tam.focus();
		return false;
	    }
	    if ((zast == "n_ha") && (den!=2)) {
		alert (hlaska+"\nDo stanice Den Haag jedeme pouze v úterý");
		document.form1.dat_tam.focus();
		return false;
	    }
	    if ((zast == "n_ut") && (den!=5)) {
		alert (hlaska+"\nDo stanice Utrecht jedeme pouze v pátek");
		document.form1.dat_tam.focus();
		return false;
	    }
            */
	    return true;
	} else {
	    alert (hlaska+"\ndo Holandska jezdíme v pátek");
	    return false;
	}
    } // ----- konec zkontroluj_datum_n()
    
    function zkontroluj_datum_c(zast, den, mess) {
	hlaska = "Chybně zadaný datum "+mess+"!";
	if (den==0) { 
            /*
	if ((den==0) || (den==3)) { 
	    if ((zast == "n_br") && (den!=3)) {
		alert (hlaska+"\nZe stanice Breda jedeme pouze ve středu");
		document.form1.dat_tam.focus();
		return false;
	    }
	    if ((zast == "n_ro") && (den!=3)) {
		alert (hlaska+"\nZe stanice Rotterdam jedeme pouze ve středu");
		document.form1.dat_tam.focus();
		return false;
	    }
	    if ((zast == "n_ha") && (den!=3)) {
		alert (hlaska+"\nZe stanice Den Haag jedeme pouze ve středu");
		document.form1.dat_tam.focus();
		return false;
	    }
	    if ((zast == "n_ut") && (den!=0)) {
		alert (hlaska+"\nZe stanice Utrecht jedeme pouze v neděli");
		document.form1.dat_tam.focus();
		return false;
	    }
            */
	    return true;
	} else {
	    alert (hlaska+"\nZ Holandska jezdíme ve neděli");
	    return false;
	}
    } // ----- konec zkontroluj_datum_c()

    function zobraz_zpatecku() { 
	var vybrano = document.form1.tip.selectedIndex;
	if (i_tip[vybrano].substring(0,1)=="j") {
	    document.form1.dat_zpet.disabled=true;
	    document.form1.kalendar2.disabled=true;
	} else {
	    document.form1.dat_zpet.disabled=false;
	    document.form1.kalendar2.disabled=false;
	}
	zobraz_cenu();
    } // kon zobraz_zpatecku

    function zobraz_cenu() {
	ind_od = document.form1.odjezd.selectedIndex;
	ind_pr = document.form1.prijezd.selectedIndex;
	ind_pl = document.form1.platba.selectedIndex;
	ind_tip = document.form1.tip.selectedIndex;

        var celk_cena = "0";
	if ((stav_odjezd_1()) || (i_odjezd[ind_od]=='zero') || (i_prijezd[ind_pr]=='zero')) {
	    text = i_platba[ind_pl].substring(0,1) + "_" + i_tip[ind_tip];
	    celk_cena= cena[text]*(document.form1.pocet.selectedIndex+1);
	}
	document.form1.c_celk.value = celk_cena;
    } // kon zobraz_cenu

    function stav_odjezd_1() { // vyhodnoti jestli je příjezd/odjezd platný
	ind_od = document.form1.odjezd.selectedIndex;
	ind_pr = document.form1.prijezd.selectedIndex;
	if (((i_prijezd[ind_pr].substring(0,1)=='c') && (i_odjezd[ind_od].substring(0,1)=='c')) || ((i_prijezd[ind_pr].substring(0,1)=='n') && (i_odjezd[ind_od].substring(0,1)=='n'))) {
	    return false;
	} else {
	    return true;
	}
    } // kon stav_odjezd_1

    function vrat_datum(text) {
	var b = text.length;
	var x = 0;
	var znak = "";
	var dat = new Array("","","");

	for (var i=0; i<b; i++) {
	    
	    znak = text.substring(i,i+1);
	    if (znak == ".") {
		x++;
	    } else {
		dat[x] += znak;
	    }
	}
	var datum = new Date(dat[2],dat[1]-1,dat[0]);
	return datum;
    } // kon vrat_datum

    function init() {
	zobraz_zpatecku();
	document.form1.dat_zpet.selectedIndex=akce["open"];
    } // kon init()

// -------------- vypis_akce_1.php vypis_akce_2.php
    function tl_zpet() {
	this.history.go(-1)
    }

    function validate_1() {
	var odeslat=true;
	var index = 0;
	if (document.form1.jmeno.value=='') {   
	    alert("Nezadali jste jméno!");
	    document.form1.jmeno.focus();
	    odeslat=false;
	}
	if ((document.form1.jmeno.value.length<5) && (odeslat))	  {   
	    alert("Jméno a příjmení musí mít dohromady minimálně 5 znaků!");
	    document.form1.jmeno.focus();
	    odeslat=false;
	}
	if ((document.form1.email.value=='') && (odeslat)) {
	  alert("Nezadali jste e-mail!");
	  document.form1.email.focus();
	  odeslat=false;
	}	
	if ((document.form1.email.value.length != 0) && (odeslat)) {
	    if (window.RegExp) {
		re = new RegExp("^[^@'<> ]+[@][^@.<> ]+[.][^@.<> ]+([.][^@.<> ]+)*$");    
		if (!re.test(document.form1.email.value)) {
		    alert("E-mailová adresa nemá správný tvar!");
		    document.form1.email.focus();
		    odeslat=false;
		}
	    }
	}
	index = document.form1.odjezd.selectedIndex;
	if ((i_odjezd[index] == 'zero') && (odeslat)) {
	  alert("Není vybráno nástupní místo!");
	  document.form1.odjezd.focus();
	  odeslat=false;
	}	
	index = document.form1.prijezd.selectedIndex;
	if ((i_prijezd[index] == 'zero') && (odeslat)) {
	  alert("Není vybráno výstupní místo!");
	  document.form1.prijezd.focus();
	  odeslat=false;
	}	
	if ((!stav_odjezd_1()) && (odeslat)) {
	  alert("Vnitrostátní přeprava vyloučena!");
	  document.form1.prijezd.focus();
	  odeslat=false;
	}	
	// kontroly datumů..

	if (odeslat) {
	    var dat_odj = i_akce[document.form1.dat_tam.selectedIndex];	
	    var den = vrat_den(dat_odj);
	    if (i_prijezd[document.form1.prijezd.selectedIndex].substring(0,1) == "n") {	// když jedem do hol. akace1
		odeslat = zkontroluj_datum_n(i_prijezd[document.form1.prijezd.selectedIndex], den, "tam");
	    } else {
		odeslat = zkontroluj_datum_c(i_odjezd[document.form1.odjezd.selectedIndex], den, "tam");
	    }
	}
		    //datum zpět
	if ((i_tip[document.form1.tip.selectedIndex].substring(0,1)=="z") && (odeslat)) {
	    dat_odj = i_akce[document.form1.dat_zpet.selectedIndex];
	    if (dat_odj != "open") {
		den = vrat_den(dat_odj);
		if (i_odjezd[document.form1.odjezd.selectedIndex].substring(0,1) == "n") {	// když jedem z hol. akace1
		    odeslat = zkontroluj_datum_n(i_odjezd[document.form1.odjezd.selectedIndex], den, "zpět");
		} else {
		    odeslat = zkontroluj_datum_c(i_prijezd[document.form1.prijezd.selectedIndex], den, "zpět");
		}
	    }
	}

	return odeslat;
    } // kon validate_1()

// -------------- form_akce_2.php
    function validate_2() {
	var odeslat=true;
	var index = 0;
	if (document.form1.jmeno.value=='') {   
	    alert("Nezadali jste jméno!");
	    document.form1.jmeno.focus();
	    odeslat=false;
	}
	if ((document.form1.jmeno.value.length<5) && (odeslat))	  {   
	    alert("Jméno a příjmení musí mít dohromady minimálně 5 znaků!");
	    document.form1.jmeno.focus();
	    odeslat=false;
	}
	if ((document.form1.email.value=='') && (odeslat)) {
	  alert("Nezadali jste e-mail!");
	  document.form1.email.focus();
	  odeslat=false;
	}	
	if ((document.form1.email.value.length != 0) && (odeslat)) {
	    if (window.RegExp) {
		re = new RegExp("^[^@'<> ]+[@][^@.<> ]+[.][^@.<> ]+([.][^@.<> ]+)*$");    
		if (!re.test(document.form1.email.value)) {
		    alert("E-mailová adresa nemá správný tvar!");
		    document.form1.email.focus();
		    odeslat=false;
		}
	    }
	}
	index = document.form1.odjezd.selectedIndex;
	if ((i_odjezd[index] == 'zero') && (odeslat)) {
	  alert("Není vybráno nástupní místo!");
	  document.form1.odjezd.focus();
	  odeslat=false;
	}	
	index = document.form1.prijezd.selectedIndex;
	if ((i_prijezd[index] == 'zero') && (odeslat)) {
	  alert("Není vybráno výstupní místo!");
	  document.form1.prijezd.focus();
	  odeslat=false;
	}	
	if ((!stav_odjezd_2()) && (odeslat)) {
	  alert("Vnitrostátní přeprava vyloučena!");
	  document.form1.prijezd.focus();
	  odeslat=false;
	}	
	// kontroly datumů..
	if (odeslat) {
	    var dat_odj = i_akce[document.form1.dat_tam.selectedIndex];	
	    var den = vrat_den(dat_odj);
	    if (i_prijezd[document.form1.prijezd.selectedIndex].substring(0,1) == "n") {	// když jedem do hol. akace1
		odeslat = zkontroluj_datum_n(i_prijezd[document.form1.prijezd.selectedIndex], den, "");
	    } else {
		odeslat = zkontroluj_datum_c(i_odjezd[document.form1.odjezd.selectedIndex], den, "");
	    }
	}
	if ((document.form1.cislo.value=='') && (odeslat)) {   
	    alert("Nezadali jste číslo jízdenky!");
	    document.form1.cislo.focus();
	    odeslat=false;
	}

	return odeslat;
    } // kon validate_2()


    function stav_odjezd_2() { // vyhodnoti jestli je příjezd/odjezd platný
	ind_od = document.form1.odjezd.selectedIndex;
	ind_pr = document.form1.prijezd.selectedIndex;
	if (((i_prijezd[ind_pr].substring(0,1)=='c') && (i_odjezd[ind_od].substring(0,1)=='c')) || ((i_prijezd[ind_pr].substring(0,1)=='n') && (i_odjezd[ind_od].substring(0,1)=='n'))) {
	    return false;
	} else {
	    return true;
	}
    } // kon stav_odjezd_2

    function zobraz_den(text) {
	var b = text.length;
	var x = 0;
	var znak = "";
	var dat = new Array("","","");

	for (var i=0; i<b; i++) {
	    
	    znak = text.substring(i,i+1);
	    if (znak == ".") {
		x++;
	    } else {
		dat[x] += znak;
	    }
	}
	var datum = new Date(dat[2],dat[1]-1,dat[0]);
	return datum.getDay();
    } // kon zobraz_den

// -------------- form_akce_2.php
function smilies(text) {
    var t_pos=document.getElementById('pos').value;
    var start='';
    var konec=0;
    for (i=0;i<t_pos.length;i++) {
        if (t_pos.substring(i,i+1,t_pos)==":") {
            konec=t_pos.substring(i+1,t_pos.length,t_pos);
            break;
        } else {
            start+=t_pos.substring(i,i+1,t_pos);
        }
    }
    var zprava=document.getElementById('message').value;
    var n_zpr=zprava.substring(0,start,zprava)+' '+text+' '+zprava.substring(konec,zprava.length,zprava);
    document.getElementById('message').value=n_zpr;
    document.getElementById('message').focus;
} // konec smilies
function start (komentar) {
    if (komentar==0) {
        document.getElementById('komentare').style.display='none';
    }
}
