//******************************************
//lib.js
//
//zakladni js includ
//rezijni fce, zakladni definice, atp.
//
//by mirek@multimedia.cz
//******************************************


//******************************************
//pop-up
//******************************************
function popup(url)
///{{{
{
	var w = 500;
	var h = 400;
	if (arguments.length > 1)  w = arguments[1];
	if (arguments.length > 2)  h = arguments[2];
	o = window.open(url,'popup','status=no,width='+w+',height='+h+',resizable=yes,menubar=yes,scrollbars=yes,toolbar=no,left=50,top=50');
	o.focus();
}
//}}}

function isEmail(s)
///{{{
{
	s += "";
	var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)");
	var r2 = new RegExp("^[a-zA-Z0-9\\-\\.]+\\@[a-zA-Z0-9\\-\\.]+\\.[a-zA-Z]{2,4}$");
	if (r1.test(s) || !r2.test(s))
		return false;
	return true;
}
///}}}

function checkOrderForm(frm)
///{{{
{
	//checked = false;
	//for (i = 0; i < frm.vazba.length; ++i) {
	//	if (frm.vazba[i].checked) {
	//		checked = true;
	//		break;
	//	}
	//}
	//if (!checked) {
	//	window.alert('Vyberte prosím druh vazby.');
	//	return false;
	//}

	//checked = false;
	//for (i = 0; i < frm.jazyk.length; ++i) {
	//	if (frm.jazyk[i].checked) {
	//		checked = true;
	//		break;
	//	}
	//}
	//if (!checked) {
	//	window.alert('Vyberte prosím jazyk publikace.');
	//	return false;
	//}


	if (frm.jmeno.value == "") {
		window.alert('Prosím vyplňte Vaše jméno.');
		frm.jmeno.focus();
		return false;
	}
	if (frm.prijmeni.value == "") {
		window.alert('Prosím vyplňte Vaše příjmení.');
		frm.prijmeni.focus();
		return false;
	}
	if (frm.ulice.value == "") {
		window.alert('Prosím vyplňte název ulice.');
		frm.ulice.focus();
		return false;
	}
	if (frm.mesto.value == "") {
		window.alert('Prosím vyplňte město.');
		frm.mesto.focus();
		return false;
	}

	if (frm.psc.value == "") {
		window.alert('Prosím vyplňte PSČ.');
		frm.psc.focus();
		return false;
	}

	if (frm.krajina.selectedIndex == 0) {
		window.alert('Prosím zvolte stát.');
		frm.krajina.focus();
		return false;
	}

	if (frm.telefon.value == "") {
		window.alert('Prosím vyplňte telefonní číslo.');
		frm.telefon.focus();
		return false;
	}

	if (!isEmail(frm.email.value)) {
		window.alert('Prosím vyplňte platnou emailovou adresu.');
		frm.email.focus();
		return false;
	}

	return true;
}
///}}}

function checkOrderForm_en(frm)
///{{{
{
	//checked = false;
	//for (i = 0; i < frm.vazba.length; ++i) {
	//	if (frm.vazba[i].checked) {
	//		checked = true;
	//		break;
	//	}
	//}
	//if (!checked) {
	//	window.alert('Please select a type of cover.');
	//	return false;
	//}
        //
	//checked = false;
	//for (i = 0; i < frm.jazyk.length; ++i) {
	//	if (frm.jazyk[i].checked) {
	//		checked = true;
	//		break;
	//	}
	//}
	//if (!checked) {
	//	window.alert('Please select a language of publication.');
	//	return false;
	//}


	if (frm.jmeno.value == "") {
		window.alert('Please fill in your name.');
		frm.jmeno.focus();
		return false;
	}
	if (frm.prijmeni.value == "") {
		window.alert('Please fill in your surname.');
		frm.prijmeni.focus();
		return false;
	}
	if (frm.ulice.value == "") {
		window.alert('Please fill in the name of street.');
		frm.ulice.focus();
		return false;
	}
	if (frm.mesto.value == "") {
		window.alert('Please fill in the name of town.');
		frm.mesto.focus();
		return false;
	}

	if (frm.psc.value == "") {
		window.alert('Please fill in the ZIP code.');
		frm.psc.focus();
		return false;
	}

	if (frm.krajina.selectedIndex == 0) {
		window.alert('Please select your country.');
		frm.krajina.focus();
		return false;
	}

	if (frm.telefon.value == "") {
		window.alert('Please fill in the telephone number.');
		frm.telefon.focus();
		return false;
	}

	if (!isEmail(frm.email.value)) {
		window.alert('Please fill in the valid e-mail adress.');
		frm.email.focus();
		return false;
	}

	return true;
}
///}}}

function checkSouhlas(frm)
///{{{
{
	var b = false;
	for (i = 0; i < frm.doprava.length; ++i) {
		b = frm.doprava[i].checked;
		if (b) break;
	}

	if (!b) {
		window.alert('Zvolte preferovaný druh dopravy.');
		return false;
	}

/* 	if (!frm.souhlas.checked) {
		window.alert('Je nám líto, ale bez souhlasu se spracováním údajů není možné vyřídit Vaši objednávku.');
		return false;
	}
 */	return true;
}
///}}}

function checkSouhlas_en(frm)
{
	var b = false;
	for (i = 0; i < frm.doprava.length; ++i) {
		b = frm.doprava[i].checked;
		if (b) break;
	}

	if (!b) {
		window.alert('Choose kind of transportation.');
		return false;
	}
	return true;
}

function prepniProdukt(elementID, num)
///{{{
{
	var deco;
	if (element = document.getElementById(elementID+"-deco")) {

		deco = document.getElementById("deco");
		if (!deco) {
			deco = document.getElementById("deco-300px");
		}
		deco.style.backgroundImage = "url(" + element.src + ")";
	}

	setActive(num);
}
///}}}

function setActive(elementOrder)
///{{{
{
	//window.alert('volam setActive ' + elementOrder);

	isIE = ((navigator.userAgent.toLowerCase().indexOf("msie") != -1) && (navigator.userAgent.toLowerCase().indexOf("opera") == -1));

	//window.alert(isIE);

	div = document.getElementById('kolekce-alternativni-obrazky');
	j = 0;

	for (i = 0; i < div.childNodes.length; ++i) {
		//window.alert(div.childNodes[i].nodeType + ": " +  );
		if (div.childNodes[i].nodeType == 1 && div.childNodes[i].href) {
			if (j == elementOrder) {
				//if (isIE)
					div.childNodes[i].setAttribute('className', 'active');
				//else
					div.childNodes[i].setAttribute('class'    , 'active');
				//div.childNodes[i].className = 'active';
			} else {
				//if (isIE)
					div.childNodes[i].setAttribute('className', '');
				//else
					div.childNodes[i].setAttribute('class'    , '');
				//div.childNodes[i].className = '';
			}
			++j;
		}
	}
}
///}}}

function setDecoBg(imgSrc)
///{{{
{
	if (document.getElementById("deco")) {
		document.getElementById("deco").style.backgroundImage = "url("+imgSrc+")";
	} else	if (document.getElementById("deco-300px")) {
		document.getElementById("deco-300px").style.backgroundImage = "url("+imgSrc+")";
	} else {
		window.alert('CHYBA: nemam deco div!!');
	}
}
///}}}

function displayBox(boxId, display)
///{{{
{
	box = document.getElementById(boxId);

	if (box) {
		if (display) box.style.display = "block";
		else box.style.display = "none";
	}

	return false;
}
///}}}
