/*
Copyright 2010, 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.htext.value == "") { alert("Není zadán hledaný text!"); return false;
	} else { if (f.htext.value.length < 3) { alert("Minimální délka hledaného textu jsou 3 znaky!"); return false; } else { return true; }
	}
}


// Kontrola prihlasovaciho formulare
function loginCheck(f) {
	if ((f.prihlaseni_jmeno.value != "") && (f.prihlaseni_heslo.value != "")) { return true;
	} else { alert("Není zadáno uživatelské jméno nebo heslo!"); return false;
	}
}


// 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 = "/?kosik_vlozeni=" + 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;
	}
}


// Dokonceni (odeslani) objednavky
function completeOrder() {
	window.opener.location.href = '/objednavka-potvrzeni/';
	window.opener.focus(); window.close();
}


// Reload captcha obrazku
function reloadCaptcha() {
	document.getElementById("captcha").src = '/spamkod.asp?' + Date();
	document.getElementById("spamkod").focus();
}


// Otevreni okna pro zaslani hesla
function openPasswordWindow() {
	iMyWidth = (window.screen.width / 2) - (200 + 10); iMyHeight = (window.screen.height / 2) - (75 + 25);
	Okno = window.open("/heslo.asp", "PasswordWindow", "width=400, height=150, left=" + iMyWidth + ", top=" + iMyHeight + ", screenX=" + iMyWidth + ", screenY=" + iMyHeight + ", resizable=0, status=1, toolbar=0, location=0, scrollbars=0");
	Okno.focus()
}


// Otevreni okna pro dotaz k produktu
function openQuestionWindow(pid) {
	iMyWidth = (window.screen.width / 2) - (250 + 10); iMyHeight = (window.screen.height / 2) - (152 + 25);
	Okno = window.open("/page_window.asp?typ=produkt-dotaz&pid=" + pid, "QuestionWindow", "width=500, height=304, left=" + iMyWidth + ", top=" + iMyHeight + ", screenX=" + iMyWidth + ", screenY=" + iMyHeight + ", resizable=0, status=1, toolbar=0, location=0, scrollbars=1");
	Okno.focus()
}


// Otevreni okna pro zobrazeni objednavky
function openOrderWindow(uid) {
	iMyWidth = (window.screen.width / 2) - (395 + 10); iMyHeight = (window.screen.height / 2) - (260 + 20);
	Okno = window.open("/objednavka_tisk.asp?uid=" + uid, "OrderWindow", "width=790, height=520, left=" + iMyWidth + ", top=" + iMyHeight + ", screenX=" + iMyWidth + ", screenY=" + iMyHeight + ", resizable=1, status=1, toolbar=0, location=0, scrollbars=1");
	Okno.focus()
}


// Otevreni okna pro provedeni on-line platby
function openPaymentWindow(url) {
	iMyWidth = (window.screen.width / 2) - (425 + 10); iMyHeight = (window.screen.height / 2) - (325 + 20);
	Okno = window.open(url, "PaymentWindow", "width=850, height=650, left=" + iMyWidth + ", top=" + iMyHeight + ", screenX=" + iMyWidth + ", screenY=" + iMyHeight + ", resizable=1, status=1, toolbar=0, location=0, scrollbars=1");
	Okno.focus()
}
