var path = "pic/";

if (document.images) {
  novinky1= new Image ();
  novinky1.src= "pic/bt_novinky1.gif";


}

function PushOn(image_name) {
  if (document.images) {
  document.images[image_name].src = path+"bt_"+image_name+"1.gif";
 }
}
function PushOff(image_name) {
  if (document.images) {
  document.images[image_name].src = path+"bt_"+image_name+".gif";
 }
}

function kontrolasearch() {

	co=document.hledat.co.value;

	if (co == "" || co.length < 3){
		alert("Prosím, vložte minimálně 3 znaky");
		document.hledat.co.focus();
		document.hledat.co.select();
		return false;
	}

}

//	Vyměna barvy pozadí
function setBgColor (id, color) {

	if (document.layers)
		document[id].bgColor = color == 'transparent' ? null : color;
	else if (document.all)
		document.all[id].style.backgroundColor = color;
	else if (document.getElementById)
		document.getElementById(id).style.backgroundColor = color;

}

//	Vyměna obrázku pozadí
function setBgImage (id, imageURL) {

	if (document.layers)
		document[id].background.src = imageURL == 'none' ? null : imageURL;
	else if (document.all)
		document.all[id].style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';
	else if (document.getElementById)
		document.getElementById(id).style.backgroundImage = imageURL == 'none' ? 'none' : 'url(' + imageURL + ')';

}

function delpdf(id,item,file,sid) {

	if(file == "") {
		window.alert("U položky není asociován PDF soubor!");
	} else {
		dotaz = window.confirm("Chcete soubor \"" + file.toUpperCase() + "\" skutečně smazat?");
		if (dotaz == true) window.location='index.php?page=adm_detail&amp;akce=del_pdf&amp;id=' + id + '&amp;item=' + item + '&amp;file=' + file + '&amp;sid=' + sid;
	}

}

function check_email(adresa) {
//	re = /^[^.]+(\.[^.]+)*@([^.]+[.])+[a-z]{2,4}$/;
	re = /^([a-zA-Z0-9._-]+)@([a-zA-Z0-9._-]+)\.([a-zA-Z]{2,5})$/;
	return adresa.search(re) == 0;
}

//	Zobrazování polí pro vyplnění údaje o firmě
function ukaz_firmu(forma) {
    if(forma == "osoba") {
	document.getElementById('f1').style.display='none';
    document.getElementById('f2').style.display='none';
    document.getElementById('f3').style.display='none';
    document.getElementById('space').style.display='';
    } else {
	document.getElementById('f1').style.display='';
    document.getElementById('f2').style.display='';
    document.getElementById('f3').style.display='';
    document.getElementById('space').style.display='none';
	}
}

function reg_form() {

	mail = /^([a-zA-Z0-9._-]+)@([a-zA-Z0-9._-]+)\.([a-zA-Z]{2,5})$/;
	tel = /^[\+][0-9]{3}[ ][0-9]{9}$/;

//	Kontrola e-mailu
	if ( document.registrace.email.value == "" ) {
		alert("Vyplňte prosím Vaši e-mailovou adresu");
		document.registrace.email.focus();
		return false;
	}

	if (mail.test(document.registrace.email.value) == 0) {
		alert ("E-mailová adresa není platná");
		document.registrace.email.focus();
		document.registrace.email.select();
		return false;
	}

//	Kontrola hesla
	if (document.registrace.heslo.value.length <= 5) {
		alert ("Heslo je příliš krátké");
		document.registrace.heslo.focus();
		document.registrace.heslo.select();
		return false;
	}

	if (document.registrace.heslo.value != document.registrace.heslo2.value) {
		alert ("Zadaná hesla nejsou totožná!");
		document.registrace.heslo2.focus();
		document.registrace.heslo2.select();
		return false;
	}

	if ( document.registrace.forma.value == "P" ) {

		if ( document.registrace.firma.value == "" ) {
			alert("Vyplňte prosím název Vaší firmy.");
			document.registrace.firma.focus();
			return false;

		}

		if ( document.registrace.ico.value == "" ) {
			alert("Vyplňte prosím Vaše IČ.");
			document.registrace.ico.focus();
			return false;

		}

		if ( document.registrace.dic.value == "" ) {
			alert("Vyplňte prosím Vaše DIČ.");
			document.registrace.dic.focus();
			return false;

		}

	}

	if ( document.registrace.jmeno.value == "" ) {
		alert("Vyplňte prosím Vaše jméno.");
		document.registrace.jmeno.focus();
		return false;

	}

	if ( document.registrace.prijmeni.value == "" ) {
		alert("Vyplňte prosím Vaše příjmení.");
		document.registrace.prijmeni.focus();
		return false;

	}

	if ( document.registrace.adresa.value == "" ) {
		alert("Vyplňte prosím Vaši adresu.");
		document.registrace.adresa.focus();
		return false;

	}

	if ( document.registrace.mesto.value == "" ) {
		alert("Vyplňte prosím Vaše město.");
		document.registrace.mesto.focus();
		return false;

	}

	if ( document.registrace.psc.value == "" ) {
		alert("Vyplňte prosím Vaše poštovní směrovací číslo.");
		document.registrace.psc.focus();
		return false;

	}

	if (document.registrace.telefon.value == "") {
		alert ("Vyplňte prosím telefonní číslo");
		document.registrace.telefon.focus();
		return false;
	}

	if (document.registrace.souhlas.checked) {
		dotaz = window.confirm("Jste si jistí, že všechny údaje jsou správně vyplněny?");
		if (dotaz == true) document.registrace.submit();
	} else {
		alert ("Musíte souhlasit se Obchodními podmínkami!");
		document.registrace.souhlas.focus();
		return false;
	}

}

function upd_form() {

	mail = /^([a-zA-Z0-9._-]+)@([a-zA-Z0-9._-]+)\.([a-zA-Z]{2,5})$/;
	tel = /^[\+][0-9]{3}[ ][0-9]{9}$/;

//	Kontrola e-mailu
	if ( document.registrace.email.value == "" ) {
		alert("Vyplňte prosím Vaši e-mailovou adresu");
		document.registrace.email.focus();
		return false;
	}

	if (mail.test(document.registrace.email.value) == 0) {
		alert ("E-mailová adresa není platná");
		document.registrace.email.focus();
		document.registrace.email.select();
		return false;
	}

	if ( document.registrace.firma.value == "" ) {
		alert("Vyplňte prosím název Vaší firmy.");
		document.registrace.firma.focus();
		return false;

	}

	if ( document.registrace.ico.value == "" ) {
		alert("Vyplňte prosím Vaše IČ.");
		document.registrace.ico.focus();
		return false;

	}

	if ( document.registrace.dic.value == "" ) {
		alert("Vyplňte prosím Vaše DIČ.");
		document.registrace.dic.focus();
		return false;

	}

	if ( document.registrace.jmeno.value == "" ) {
		alert("Vyplňte prosím Vaše jméno.");
		document.registrace.jmeno.focus();
		return false;

	}

	if ( document.registrace.prijmeni.value == "" ) {
		alert("Vyplňte prosím Vaše příjmení.");
		document.registrace.prijmeni.focus();
		return false;

	}

	if ( document.registrace.adresa.value == "" ) {
		alert("Vyplňte prosím Vaši adresu.");
		document.registrace.adresa.focus();
		return false;

	}

	if ( document.registrace.mesto.value == "" ) {
		alert("Vyplňte prosím Vaše město.");
		document.registrace.mesto.focus();
		return false;

	}

	if ( document.registrace.psc.value == "" ) {
		alert("Vyplňte prosím Vaše poštovní směrovací číslo.");
		document.registrace.psc.focus();
		return false;

	}

	if (document.registrace.telefon.value == "") {
		alert ("Vyplňte prosím telefonní číslo");
		document.registrace.telefon.focus();
		return false;
	}

	document.registrace.submit();

}

function change_pass() {

//	Kontrola existence původního hesla
	if ( document.zmenahesla.heslo.value == "" ) {
		alert("Vyplňte prosím Vaše původní heslo!");
		document.zmenahesla.heslo.focus();
		return false;
	}

//	Kontrola nového hesla
	if (document.zmenahesla.noveheslo.value.length <= 5) {
		alert ("Vaše nové heslo je příliš krátké");
		document.zmenahesla.noveheslo.focus();
		document.zmenahesla.noveheslo.select();
		return false;
	}

	if (document.zmenahesla.noveheslo.value != document.zmenahesla.noveheslo2.value) {
		alert ("Zadaná hesla nejsou totožná!");
		document.zmenahesla.noveheslo2.focus();
		document.zmenahesla.noveheslo2.select();
		return false;
	}

	document.zmenahesla.submit();

}

function into_cart() {

	if ( document.set_ku.typ.value == "jmeno" ) {

		if ( document.set_ku.subjekt.value == "" ) {
			alert("Vyplňte prosím jméno oprávněného subjeku.");
			document.set_ku.subjekt.focus();
			return false;

		}

	}

	if ( document.set_ku.typ.value == "parcela" ) {

		if ( document.set_ku.kmenove_cislo.value == "" ) {
			alert("Vyplňte prosím kmenové číslo.");
			document.set_ku.kmenove_cislo.focus();
			return false;

		}

	}

	if ( document.set_ku.typ.value == "dum" || document.set_ku.typ.value == "byt" ) {

		if ( document.set_ku.cast_obce.value == "" ) {
			alert("Vyplňte prosím část obce.");
			document.set_ku.cast_obce.focus();
			return false;

		}

		if ( document.set_ku.cislo_domu.value == "" ) {
			alert("Vyplňte prosím číslo domu.");
			document.set_ku.cislo_domu.focus();
			return false;

		}

		if ( document.set_ku.typ.value == "byt" ) {

			if ( document.set_ku.cislo_jednotky.value == "" ) {
				alert("Vyplňte prosím jméno číslo jednotky.");
				document.set_ku.cislo_jednotky.focus();
				return false;

			}

		}

	}

	document.set_ku.submit();

}

function updatepocet(polozka,sid) {
	id = polozka.name;
	pocet = polozka.value;
//	pocet = polozka.options[polozka.selectedIndex].text;
	document.location.href = 'index.php?page=kosik&amp;akce=zmenit&amp;id='+id+'&amp;pocet='+pocet+'&amp;sid='+sid;
}

function is_send() {

	if(document.send_addr.fak2send.checked) {
		document.send_addr.cont_firma.value = document.send_addr.fak_firma.value;
		document.send_addr.cont_jmeno.value = document.send_addr.fak_jmeno.value;
		document.send_addr.cont_prijmeni.value = document.send_addr.fak_prijmeni.value;
		document.send_addr.cont_adresa.value = document.send_addr.fak_adresa.value;
		document.send_addr.cont_mesto.value = document.send_addr.fak_mesto.value;
		document.send_addr.cont_psc.value = document.send_addr.fak_psc.value;
	} else {
		document.send_addr.cont_firma.value = "";
		document.send_addr.cont_jmeno.value = "";
		document.send_addr.cont_prijmeni.value = "";
		document.send_addr.cont_adresa.value = "";
		document.send_addr.cont_mesto.value = "";
		document.send_addr.cont_psc.value = "";
	}

}

function sendmail() {

	if(document.napiste.jmeno.value == "") {
		alert("Vyplňte, prosím, Vaše jméno a příjmení!");
		document.napiste.jmeno.focus();
		return false;
	}
	if(document.napiste.email.value == "") {
		alert("Vyplňte, prosím, Vaši emailovou adresu!");
		document.napiste.email.focus();
		return false;
	}
	if (!check_email(document.napiste.email.value) ) {
	   alert("Vaše emailová adresa není vyplněna správně!");
	   document.napiste.email.focus();
	   return false;
	}
	if(document.napiste.zprava.value == "") {
		alert("Teď už nám jen něco napište! :-)");
		document.napiste.zprava.focus();
		return false;
	}
	document.napiste.submit();

}

function change_status(id,sid) {

	stav = document.chng.change_stav.options.value;
	var stav_text = "";
	if (stav == "new") stav_text = "NOVÁ";
	if (stav == "solving") stav_text = "V ŘEŠENÍ";
	if (stav == "processed") stav_text = "ZPRACOVANÁ";
	if (stav == "storno") stav_text = "STORNOVANÁ";
	if (stav == "delete") stav_text = "SMAZAT";

	if (stav == "") {
		return false;
	} else {
		dotaz = window.confirm("Opravdu chcete změnit stav objednávky na \"" + stav_text + "\"?");
		if (dotaz == true) {
			location.href='index.php?page=adm_detail&amp;id=' + id + '&amp;akce=update2&amp;set=' + stav + '&amp;sid=' + sid;
		} else {
			alert ("Změna stavu objednávky nebyla provedena!");
			return false;
		}
	}

}

function change_vypisu(iI) {

	checkno = /^[0-9]{1,5}$/;
	
	if (checkno.test(document.forms['pocet'+iI].vypisu.value) == 0) {
		alert ("Zadané číslo není v platném rozsahu!");
		document.forms['pocet'+iI].vypisu.focus();
		document.forms['pocet'+iI].vypisu.select();
		return false;
	} else {
		dotaz = window.confirm("Opravdu chcete upravit počet výpisů vztahujících se k zadanému subjektu?");
		if (dotaz == true) {
			document.forms['pocet'+iI].submit();
//			location.href='index.php?page=adm_detail&amp;akce=update3&amp;id=' + id + '&amp;item=' + item + '&amp;set=' + document.pocet.vypisu.value + '&amp;sid=' + sid;
		} else {
			alert ("Akce zrušena uživatelem. Změna počtu výpisů nebyla provedena!");
			return false;
		}
	}


}

function sendappel(id,goback,sid,typ) {

	if(typ == "vyzva") {
		dotaz = window.confirm("Opravdu chcete odeslat e-mail s výzvou k úhradě?");
	} else {
		dotaz = window.confirm("Opravdu chcete odeslat e-mail s urgencí úhrady objednávky?");
	}

	if (dotaz == true) {
		location.href='index.php?page=adm_detail&amp;id=' + id + '&amp;akce=send&amp;typ=' + typ + '&amp;goback=' + goback + '&amp;sid=' + sid;
	} else {
		alert ("Akce zrušena uživatelem. E-mail nebyl odeslán!");
		return false;
	}

}


function vlozit_text() {

	if(document.texty.validfrom.value > document.texty.validto.value) {
		alert("Neplatný rozsah platnosti!");
		return false;
	} else {
		document.texty.submit();
	}

}


function smazat_text(id,sid) {

	dotaz = window.confirm("Opravdu chcete záznam s ID "+id+" smazat?");
	if (dotaz == true) {
		document.location.href = "index.php?page=adm_text&amp;akce=delete&amp;id="+id+"&amp;sid="+sid;
	} else {
		alert ("Záznam nebyl smazán");
		return false;
	}

}
