var uvolnit = false;
var animTxt = "";
var oknoSirka = 650;
var oknoVyska = window.screen.height - 100;
var infoSirka = 430;
var infoVyska = 200;
var checkForms = true;
if (inView) window.focus();

// datum Od, Do
var od_datum = "From ...  [dd.mm.rrrr]";
var do_datum = "To ...  [dd.mm.rrrr]";

////////////////////////////////////////////////////////////////////////////////

function dnes() {
var datum=new Date();
var mesic=datum.getMonth();
var navratova_hodnota=null;
var den=null;
var rok=datum.getYear();
if (rok < 1000) rok += 1900;
mesic++;
if (datum.getDay() == 0) {document.write("..Sunday&nbsp;")}
if (datum.getDay() == 1) {document.write("..Monday&nbsp;")}
if (datum.getDay() == 2) {document.write("..Tuesday&nbsp;")}
if (datum.getDay() == 3) {document.write("..Wednesday&nbsp;")}
if (datum.getDay() == 4) {document.write("..Thursday&nbsp;")}
if (datum.getDay() == 5) {document.write("..Friday&nbsp;")}
if (datum.getDay() == 6) {document.write("..Saturday&nbsp;")}
navratova_hodnota=den + datum.getDate() + ". " + mesic + ". " + rok;
return(navratova_hodnota);
}

function displayNovinka() {
    //var cesta = "http://www.ticket-art.EN/index.php?pg=titul&id=177";
    //novinkaOknoSirka = window.screen.width - 200;
    //novinkaOknoVyska = window.screen.height - 300;
    //window.open(cesta, "view", "top=" + getTop(novinkaOknoVyska) + ", left=" + getLeft(novinkaOknoSirka) + ", height=" + novinkaOknoVyska + ", width=" + novinkaOknoSirka + ", status=yes, toolbar=yes, menubar=yes, location=yes, scrollbars=yes, resizable=yes");
    var cesta = "html/gv.html";
    novinkaOknoSirka = 840;
    novinkaOknoVyska = 320;
    window.open(cesta, "view", "top=" + getTop(novinkaOknoVyska) + ", left=" + getLeft(novinkaOknoSirka) + ", height=" + novinkaOknoVyska + ", width=" + novinkaOknoSirka);
}



function getLeft(sirka) {
	sirka = Math.min(window.screen.width, sirka);
	return Math.round((window.screen.width - sirka) / 2);
}
function getTop(vyska) {
	vyska = Math.min(window.screen.height, vyska);
	return Math.round((window.screen.height - vyska) / 2);
}

function Nahled(pg, param) {
	var cesta = "view.php?pg=" + pg;
	if (param != '') cesta += "&" + param;
	cesta += "&" + SID;
	if (inView) window.location.href = cesta;
	else window.open(cesta, "view", "top=" + (getTop(oknoVyska)-30) + ", left=" + getLeft(oknoSirka) + ", height=" + oknoVyska + ", width=" + oknoSirka + ", status=no, toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes");
}

function NahledSalu(titul, sal) {
	Nahled("sal", "titul=" + titul + "&sal=" + sal);
}

function NahledFotky(pic, sizeX, sizeY) {
	var cesta = "nahled.php?pic=" + pic;
	sizeX = Math.min(sizeX + 30, window.screen.width - 100);
	sizeY = Math.min(sizeY + 30, window.screen.height - 100);
	if (sizeY + 30 > window.screen.height - 100) sizeX += 25;
	window.open(cesta, "fotografie", "top=" + (getTop(sizeY)-30) + ", left=" + getLeft(sizeX) + ", height=" + sizeY + ", width=" + sizeX + ", status=no, toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes");
}

function Info(sekce, typ) {
	var cesta = "info.php?sekce=" + sekce + "&id=" + typ + "&" + SID;
	window.open(cesta, "info", "top=" + getTop(infoVyska) + ", left=" + getLeft(infoSirka) + ", height=" + infoVyska + ", width=" + infoSirka + ", status=no, toolbar=no, menubar=no, location=no, scrollbars=yes, resizable=yes");
}

function ViewResize(presun) {
	var vyska = oknoVyska;
	if (document.getElementById("pozice") != null) vyska = document.getElementById("pozice").offsetTop;
	if (OTC) vyska += 130;
	vyska = Math.min(vyska + 40, window.screen.height - 80);
	window.resizeTo(oknoSirka, vyska);
	window.moveTo(getLeft(oknoSirka), getTop(oknoVyska) - 30);
}

function InfoResize() {
	window.moveTo(getLeft(infoSirka), getTop(infoVyska));
	window.resizeTo(infoSirka, infoVyska);
	window.resizeTo(document.body.offsetWidth + 8, document.getElementById('pozice').offsetTop + 45);
	window.focus();
}

function poENmena(klic, klic2) {
	try {
		var disable = false;
		var objednavka = document.formObjednavka;
		
		for (var j = 1; j <= 7; j++) {
			elem = objednavka["pocet[" + klic + "][" + j + "]"];
			if (elem != null && elem.value > 0) disable = true;
		}
		for (var i = 1; i <= 30; i++) {
			if (i == klic) continue;
			for (var j = 1; j <= 7; j++) {
				elem = objednavka["pocet[" + i + "][" + j + "]"];
				if (elem != null) elem.disabled = disable;
			}
		}
		try {
			objednavka.predani[0].focus();
		}
		catch (Exception) {
			try {
				objednavka.predani.focus();
			}
			catch (Exception) {}
		}
		window.focus();
	}
	catch (Exception) {	}
}

function isEmail(t) {
	if (t.indexOf("@") < 1 || t.indexOf("@") != t.lastIndexOf("@") || t.lastIndexOf(".") < t.lastIndexOf("@")+2  || t.lastIndexOf(".") > (t.length-3) || t.lastIndexOf(".") < (t.length-5)) return false;
	else return true;
}

function isNumber(cislo) {
    var err = false;
	for( var i = 0; i < cislo.length; i++ ) {
    	var c = cislo.charAt(i);
    	if( c!='0' && c!='1' && c!='2' && c!='3' && c!='4' && c!='5' && c!='6' && c!='7' && c!='8' && c!='9' && c!=' ') err = true;
		break;
    }
    return !err;
}

function animButton(poz) {
	var anim = "";
	var delka = 8;
	if (poz >= delka) poz = 1;
	for (var i = 1; i < delka; i++) {
		if (i == poz) anim += ">>";
		else anim += " ";
	}
	animElem.value = animTxt + anim;
	window.setTimeout("animButton(" + (poz + 1) + ")", 500);
}


function DruhPlatby(druh) {
	try {
                var pozice = 0;
		switch (druh) {
		case 10: karta_benefity = false; pozice = 0; break;
		case 11: karta_benefity = false; pozice = 1; break;
		case 12: karta_benefity = false; pozice = 2; break;
                case 13: karta_benefity = true; pozice = 3; break;
                case 14: karta_benefity = false; pozice = 4; break;
                case 15: karta_benefity = false; pozice = 5; break;
                case 16: karta_benefity = false; pozice = 6; break;
		}
		var elem = document.formPlatba;
                elem.kCisloUctu.disabled = elem.kPin.disabled = !karta_benefity;
	}
	catch (Exception) {
	}
}

function checkFormUzivatel(platba) {
	var aTxt = "";
	if (platba.uJmeno.value.length < 2) aTxt += "Fill out your Forename\n";
	if (platba.uPrijmeni.value.length < 2) aTxt += "Fill out your Surname\n";
	if (platba.uAdresa.value.length < 3) aTxt += "Fill out the correct Address\n";
	if (platba.uObec.value.length < 2) aTxt += "Fill out the correct City/Town\n";
//	if (platba.uPSC.value.length < 2 || !isNumber(platba.uPSC.value)) aTxt += "EN Zadejte PSČ\n";
	if (!isEmail(platba.uEmail.value)) aTxt += "Fill out the correct Email address\n";
	if (platba.uTelefon.value.length < 5) aTxt += "Fill out your phone number\n";
        if (platba.uEmail2.value.toLowerCase() != platba.uEmail.value.toLowerCase()) aTxt += "Both Email addresses must be the same\n";
	return aTxt;
}

function checkFormObjednavka() {
	if (!checkForms) return true;
	try {
		var elem;
		var celkem = 0;
		var vybrano = 0;
		var doruceno = false;
		var aTxt = "";
		var objednavka = document.formObjednavka;
		
		for (var i = 1; i <= 30; i++) {
			for (var j = 1; j <= 7; j++) {
				elem = objednavka["pocet[" + i + "][" + j + "]"];
				if (elem != null && elem.value != 0) {
					celkem += Math.round(elem.value);
				}
			}
		}
		if (celkem > maxPocVstupenek) {	// maxpocvstupenek
			aTxt += "The maximal number of Tickets per one Order is " + maxPocVstupenek + "\n";
		}
		if (celkem == 0) {
			aTxt += "It is necessary to choose at least one ticket\n";
		}
		try {
			for (var i = 0; i <= 6; i++) {
				elem = objednavka.predani[i];
				if (elem != null && elem.checked) doruceno = true;
			}
			elem = objednavka.predani;
			if (elem != null && elem.checked) doruceno = true;
		}
		catch (Exception) {
			doruceno = true;
		}
		
		if (!doruceno) {
			aTxt += "Please select the Delivery type";
		}
		if (aTxt != '') {
			alert(aTxt);
			return false;
		}
		else {
			objednavka.fSubmit.disabled = true;
			animTxt = "The Reservation is in progress  ";
			animElem = objednavka.fSubmit;
			animButton(1);
			return true;
		}
	}
	catch (Exception) {
		return true;
	}
}

function checkFormRegistrace() {
	if (!checkForms) return true;
	try {
		var aTxt = checkFormUzivatel(document.formRegistrace);
		if (aTxt.length > 0) {
			alert(aTxt);
			return false;
		}
		else {
			return true;
		}
		
	}
	catch (Exception) {
		return true;
	}
}

/*
function checkFormPlatba() {
	try {
		var aTxt = "";
		var cTxt = "";
		var platba = document.formPlatba;
		
		aTxt = checkFormUzivatel(platba);
		
		var kartaZvolena = false;
		var bankaZvolena = false;
		for (var i = 0; i <= 1; i++) {
			elem = platba.kKarta[i];
			if (elem != null && elem.checked) kartaZvolena = true;
		}
		elem = platba.kKarta[2];
		if (elem != null && elem.checked) bankaZvolena = true;
		if (!kartaZvolena && !bankaZvolena && !(platba.kKarta != null && platba.kKarta.checked)) aTxt += "Please select the payment method\n";
	
		if (platba.kCislo.value.length < 9 || !isNumber(platba.kCislo.value)) cTxt += "Please fill out your Credit Card number\n";
		if (platba.kKod.value.length > 0 && !isNumber(platba.kKod.value)) cTxt += "Please fill out your Credit Card Verification number or leave it blank (if your Credit Card does not contain it)\n";
		if (platba.kMesic.value == -1) cTxt += "Please select the expiration Month of your Credit Card\n";
		if (platba.kRok.value == -1) cTxt += "Please select the expiration Year of your Credit Card\n";
		
		if (aTxt.length > 0 || (kartaZvolena && cTxt.length > 0)) {
			var viewTxt = aTxt;
			if (kartaZvolena) viewTxt += cTxt;
			alert(viewTxt);
			return false;
		}
		else {
			neuvolnovat();
			if (kartaZvolena) animTxt = "The Payment verification is in the progress  ";
			else animTxt = "Contacting eBanka  ";
			platba.fSubmit.disabled = true;
			animElem = platba.fSubmit;
			animButton(1);
			return true;
		}
	}
	catch (Exception) {
		return true;
	}

}*/
function checkFormPlatba() {
    try {
        var aTxt = "";
        var cTxt = "";
        var platba = document.formPlatba;
        var druhPlatby = 0;
        
        aTxt = checkFormUzivatel(platba);

        for (var i = 0; i <= 3; i++) {
            elem = platba.kKarta[i];
            if (elem != null && elem.checked) druhPlatby = elem.value;
        }
        
        // kontroly pro jednotlive druhy plateb
        if(druhPlatby == 10 || druhPlatby == 11 || druhPlatby == 14 || druhPlatby == 15 || druhPlatby == 16) {      // Visa, MasterCard, CS, Visa Electron, MC Maestro
        }
        else if(druhPlatby == 12) ;                      // eBanka
        else if(druhPlatby == 13) {                      // Benefity
            if (!isNumber(platba.kCisloUctu.value)) cTxt += "Please fill out your Account number\n";
            if (platba.kPin.value.length < 4 || !isNumber(platba.kPin.value)) cTxt += "Please fill out your PIN\n";
        }
        else aTxt += "Please select the payment method\n";         // nebyla vybrana zadna platba
        
        if (aTxt.length > 0 || cTxt.length > 0) {
            var viewTxt = aTxt;
            if (druhPlatby == 10 || druhPlatby == 11 || druhPlatby == 13) viewTxt += cTxt;
            alert(viewTxt);
            return false;
        }
        else {
            neuvolnovat();
            if (druhPlatby == 10 || druhPlatby == 11 || druhPlatby == 13) animTxt = "The Payment verification is in the progress  ";
            else animTxt = "Contacting Raiffeisen Banka  ";
            platba.fSubmit.disabled = true;
            animElem = platba.fSubmit;
            animButton(1);
            return true;
        }
    }
    catch (Exception) {
        return true;
    }
}

/*function checkFormKategorie() {
	if (!checkForms) return true;
	try {
		var elem = document.formKategorie;
		if (elem.skat.selectedIndex == 0 && elem.sdate.selectedIndex == 0 && elem.sdiv.selectedIndex == 0) {
			alert("Please select at least one Search parameter");
			return false;
		}
		else {
			return true;
		}
	}
	catch (Exception) {
		return true;
	}
}*/



/////////////////////////////////
function checkDatum(e, popis) {
	if(e.disabled == false) {
		if(e.value != popis) {
			if(isdate( e, "Invalid date" ) == false) return false;
			//if(isnull( e, "Nesmi byt prazdny" ) == false) return false;
		} else e.value = "";
	}
    return true;
}

function isdate( e, errmsg )
{                   
	var separator;
	var p;

	if ( e.value.length == 0 ) return true; 
	separator = '.';
	p = e.value.indexOf( separator );
	if ( p == -1 ) { 
		separator = '/';
		p = e.value.indexOf( separator );
		if ( p == -1 ) {
			separator = "-1";
			day = e.value.substring( 0, 2 );
			month = e.value.substring( 2, 4 );
			year = e.value.substring( 4, e.value.length );

		}
	}
	
	if ( separator != "-1" ) {
		pos1 = e.value.indexOf( separator );
		day = e.value.substring( 0, pos1 );
		pos2 = e.value.indexOf(  separator , pos1+1 );
		month = e.value.substring( pos1+1 , pos2 );
		year = e.value.substring( pos2+1 , e.value.length );
	}

	var y = parseInt(year,10);
	var m = parseInt(month,10) - 1;
	var d = parseInt(day,10);
	
	if ( y < 100 ) y += 2000;
	
	var date = new Date(y,m,d);
	if( y == date.getFullYear() && m == date.getMonth() && d == date.getDate() ) {
		e.value = d+"."+(m+1)+"."+y;
		return true;
	} else {
		alert( errmsg );
		e.focus();
		e.select();
		return false;
	}

}

function isnull( e, errmsg )
{
    if ( e.value.length > 0 ) return true; 
    alert( errmsg );
    e.focus(); e.select(); return false;
}
/////////////

function do_obdobi(e) {
	var e_sdate = document.formKategorie.sdate;
	var e_od_datum = document.formKategorie.od_datum;
	var e_do_datum = document.formKategorie.do_datum;
	
	if(e.value == 1) {
		e_sdate.disabled = false;
		e_od_datum.disabled = true;
		e_do_datum.disabled = true;
	}
	else {
		e_sdate.disabled = true;
		e_od_datum.disabled = false;
		e_do_datum.disabled = false;
	}
}

// testuje vstupni parametry - left panel / vyhledat
function checkFormKategorie() {
	if (!checkForms) return true;
	try {
		var elem = document.formKategorie;
		if(!checkDatum(elem.od_datum, od_datum)) return false;	// kontrola datumu - Od
		if(!checkDatum(elem.do_datum, do_datum)) return false;	// kontrola datumu - Do
		if (elem.skat.selectedIndex == 0		 
			&& (elem.sdate.selectedIndex == 0 && elem.sdate.disabled == false)
			&& elem.sdiv.selectedIndex == 0
		) {
			alert("Please select at least one Search parameter");
			return false;
		}
		else {
			return true;
		}
	}
	catch (Exception) {
		return true;
	}
}
/////////////////////////////////











function checkFormZpetny(elem) {
	var txt = "";
	if (!isEmail(elem.fEmail.value)) txt += "Please fill out the correct email address\n";
	if (elem.fTyp.value < 0) txt += "Please fill out the Message type\n";
	if (elem.fObsah.value.length == 0) txt += "The message must not be empty";
	if (txt.length > 0) {
		alert(txt);
		return false;
	}
	return true;
}

function neuvolnovat() {
	uvolnit = false;
	return true;
}

function UvolnitListky() {
	var cesta = "view.php?pg=regiony&" + SID;
	if (uvolnit) window.open(cesta, "uvolnit", "top=" + Math.round(screen.height/3) + ", left=" + Math.round(screen.width/4) + ", height=120, width=350, status=no, toolbar=no, menubar=no, location=no, scrollbars=no, resizable=yes");
}

function writeNavigate(typ) {
	if (window.history.length == 0) return;
	if (typ) document.write('<A HREF="javascript:window.history.forward(1)">Forward&nbsp;&gt;&gt;</A>');
	else document.write('<A HREF="javascript:window.history.back(1)">&lt;&lt;&nbsp;Back</A>');
}

function clipPut(elem) {
	try {
		txt = elem.createTextRange();
		txt.execCommand("Copy");
	}
	catch(Exception) {}
}

function setOdkaz( cislo, text) {
	document.formIkony.odkaz.value = "<A HREF=\"" + httpPath + "vstupenky.php?titul=" + cislo + "\" TARGET=\"_blank\">" + text + "</A>";
}