/*
Copyright 2007, JT WebDesign Studio - http://www.jtwds.cz
*/


// Kontrola spravnosti - cislo
function isNumber(str) {
	var num = "0123456789", result
	for (var x=0; x<=str.length; x++) {
		if (-1 == num.indexOf(str.charAt(x))) {
			return(false)
		} else {
			result = true
		}
	}
	return(result)
}


// Kontrola spravnosti - email
function isEmail(str) {
	if (str == "") return true;
	var bRetval = !(str.indexOf(".") == -1 || str.indexOf(".") == 0 || str.indexOf(" ") > -1 || str.indexOf("..") > -1 || str.indexOf("@") == -1 || str.lastIndexOf(".") == (str.length - 1));
	return bRetval;
}


// Kontrola vyhledavaciho formulare
function searchCheck(f) {
	if (f.hledej_slovo.value == "") {
		alert("Není zadán hledaný text!");
		return false;
	} else {
		return true;
	}
}


// Kontrola prihlasovaciho formulare
function loginCheck(f) {
	if ((f.username.value != "") && (f.password.value != "")) {
		return true;
	} else {
		alert("Není zadáno uživatelské jméno nebo heslo!")
		return false;
	}
}


// Kontrola mailingoveho formulare
function mailingCheck(f) {
	if ((f.mailing_email.value != "") && (isEmail(f.mailing_email.value))) {
		return true;
	} else {
		alert("Chybně zadaná e-mailová adresa!")
		return false;
	}
}


// Zobrazeni vypisu sekci mailingu
function mailingDetail() {
	document.getElementById('mailing_type_a').style.display = 'none';
	document.getElementById('mailing_type_b').style.display = '';
}


// Vlozeni produktu do nakupniho kose
function addToCart(produkt, kusu, verify) {
	var pID = 0;
	if ((kusu.length == "") || (!isNumber(kusu))) {
		alert("Množství [chybné číslo]!");
	} else {
		if (verify == "1" && produkt > 0) {
			pID = produkt;
		}
		if (verify == "2") {
			if (produkt[0]) {
				for (i=0; i<produkt.length; i++) {
					if (produkt[i].checked == true) {
						pID = produkt[i].value; break;
					}
				}
			} else {
				if (produkt.checked) { pID = produkt.value; }
			}
		}
		if (pID > 0) { location.href="./?kos_pridej=" + pID + "&pocet=" + kusu
		} else { alert("Zvolte variantu produktu!")
		}
	}
}


// Zmena poctu kusu produktu v nakupnim kosi
function modifyCart(kusu) {
	if ((kusu.length == "") || (!isNumber(kusu))) {
		alert("Množství [chybné číslo]!");
		return false;
	} else {
		return(true);
	}
}


// Otevreni okna pro zaslani hesla
function openPasswordWindow() {
	iMyWidth = (window.screen.width / 2) - (200 + 10)
	iMyHeight = (window.screen.height / 2) - (75 + 25)
	Fokus = window.open("heslo.asp", "PasswordWindow", "width=400, height=150, resizable=no, left=" + iMyWidth + ", top=" + iMyHeight + ", screenX=" + iMyWidth + ", screenY=" + iMyHeight + ", toolbar=0, location=0, scrollbars=0");
	Fokus.focus()
}


// Otevreni okna pro dotaz k produktu
function openQuestionWindow(url, name) {
	iMyWidth = (window.screen.width / 2) - (250 + 10)
	iMyHeight = (window.screen.height / 2) - (143 + 25)
	Fokus = window.open("page_window.asp?typ=produktdotaz&adresa=" + url + "&nazev=" + name, "QuestionWindow", "width=500, height=286, resizable=no, left=" + iMyWidth + ", top=" + iMyHeight + ", screenX=" + iMyWidth + ", screenY=" + iMyHeight + ", toolbar=0, location=0, scrollbars=1");
	Fokus.focus()
}


// Otevreni okna pro zobrazeni objednavky
function displayOrder(oid, sid) {
	iMyWidth = (window.screen.width / 2) - (360 + 10)
	iMyHeight = (window.screen.height / 2) - (250 + 20)
	Fokus = window.open("objednavka_tisk.asp?oid=" + oid + "&sid=" + sid, "PrintOrder", "height=500, width=720, left=" + iMyWidth + ", top=" + iMyHeight + ", screenX=" + iMyWidth + ", screenY=" + iMyHeight + ", status=1, resizable=yes, toolbar=0, location=0, scrollbars=1");
	Fokus.focus()
}