// JavaScript Document
function openWin(url, id, style)
{
	newWin = window.open(url, id, style);
	newWin.focus();
	return newWin;
}

function winBlank(anch)
{
	anch.target = "blank";
	openWin(anch.href, "blank", "");
}

function winMonitor(anch)
{
	anch.target = "monitor";
	openWin(anch.href, "monitor", "toolbar = no, location = no, directories = no, status = no, menuBar = no, scrollbars = auto, resizable = yes");
}

function winPhoto(anch, width)
{
	var height = 600;
	anch.target = "photo";
	switch (width)
	{
	case 800: break;
	case 1024: height = 768; break;
	default: width = 800;
	}
	if (winPhotoNav == true)
		height += 40;
	x = ((screen.width - width) / 2);
	y = ((screen.height - height) / 2);
	win = openWin(anch.href, "photo", "left = " + x + ", top = " + y + ", width = " + width + ", height = " + height + ", toolbar = no, location = no, directories = no, status = no, menuBar = no, scrollbars = no, resizable = yes");
}

function winRef(anch)
{
	anch.target = "ref";
	x = ((screen.width - 640) / 2);
	y = ((screen.height - 480) / 2);
	win = openWin(anch.href, "ref", "left = " + x + ", top = " + y + ", width = 640, height = 480, toolbar = no, location = no, directories = no, status = no, menuBar = no, scrollbars = no, resizable = yes");
}

function winEkoma(anch)
{
	anch.target = "ekoma";
	openWin(anch.href, "ekoma", "width = 800, height = 600, toolbar = no, location = no, directories = no, status = no, menuBar = no, scrollbars = yes, resizable = yes");
}

function formEkoma(anch)
{
	anch.target = "ekoma";
	openWin("", "ekoma", "width = 800, height = 600, toolbar = no, location = no, directories = no, status = no, menuBar = no, scrollbars = yes, resizable = yes");
}

function winWebmail(url)
{
	openWin(url, "ekoma", "width = auto, height = auto, toolbar = no, location = no, directories = no, status = no, menuBar = no, scrollbars = yes, resizable = yes");
}

function formWebmail(anch)
{
	anch.target = "webmail";
	webmailWin = window.open("", "webmail", "width = auto, height = auto, toolbar = no, location = no, directories = no, status = no, menuBar = no, scrollbars = yes, resizable = yes");
}

function formEkomaValidator(theForm)
{
	if (theForm.pc.value == "")
	{
		alert("Vyplňte, prosíme, položku \"Cena bez DPH\".");
		theForm.pc.focus();
		return false;
	}

	var checkOK = "0123456789";
	var checkStr = theForm.pc.value;
	var allValid = true;
	var decPoints = 0;
	var allNum = "";
	for (i = 0;  i < checkStr.length;  i++)
	{
		ch = checkStr.charAt(i);
		for (j = 0;  j < checkOK.length;  j++)
			if (ch == checkOK.charAt(j))
				break;
		if (j == checkOK.length)
		{
			allValid = false;
			break;
		}
		if (ch == ",")
		{
			allNum += ".";
			decPoints++;
		}
		else
			allNum += ch;
	}
	if (!allValid)
	{
		alert("Chybné zadání položky \"Cena bez DPH\". Položka je celočíselného typu bez desetinných míst. Zadejte ji správně.");
		theForm.pc.focus();
		return false;
	}

	if (decPoints > 1)
	{
		alert("Vyplňte, prosíme, položku \"Cena bez DPH\".");
		theForm.pc.focus();
		return false;
		}
  
	if (theForm.pc.value < 30000)
	{
		alert("Minimální hodnota položky \"Cena bez DPH\" v tomto kalkulátoru je 30000.");
		theForm.pc.focus();
		return false;
	}

	return true;
}

function prenumverb(num, form1, form2, form3)
{
	if (num == 1)
		return "je 1 " + form1;
	else
	if ((num > 1) && (num < 5))
		return "jsou " + num + " " + form2;
	else
	if (num >= 5)
		return "je " + num + " " + form3;
}

function invalid(element, type, accept, required, minlength, title)
{
	var error = "";
	if (type == "textbox")
	{
		checkStr = "";
		regExp = "";
		allowed = "";
		if (!element.value)
			element.value = "";
		switch (accept)
		{
		case "cztext":
			checkStr = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyzŠŚŤŽŹšśťžźŁĄŞŻłąşĽľżŔÁÂĂÄĹĆÇČÉĘËĚÍÎĎĐŃŇÓÔŐÖŘŮÚŰÜÝŢßŕáâăäĺćçčéęëěíîďđńňóôőöřůúűüýţ0123456789-.-_,:; ";
			allowed = " (povolena pouze písmena, číslice a interpunkční znaménka)"
			break;
		case "num":
			checkStr = "0123456789-: ";
			allowed = " (povoleny pouze číslice, pomlčky a prázdné mezery)";
			break;
		case "numhex":
			checkStr = "0123456789-: ABCDEFabcdef";
			allowed = " (povoleny pouze cifry hexadecimální soustavy (0-9 a A-F), pomlčky a prázdné mezery)";
			break;
		case "alphanum":
			checkStr = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789- /";
			allowed = " (povoleny pouze znaky anglické abecedy, číslice, pomlčky a prázdné mezery)";
			break;
		case "phone":
			checkStr = "+/0123456789 ";
			allowed = " (povoleny pouze znaky definující telefonní číslo v mezinárodním formátu)";
			break;
		case "email":
			regExp = "^([a-zA-Z0-9]+[\._\-]?[a-zA-Z0-9]*)+@[a-zA-Z0-9\.\-]+$";
			regExp2 = "^.{3,}@.{5,}$";
			break;
		case "emailleftpart":
			regExp = "^([a-zA-Z0-9]+[\._\-]?[a-zA-Z0-9]*)+";
			regExp2 = "^[^@]{3,}$";
			break;
		}
		if (checkStr.length > 0)
		{
			for (i = 0; i < element.value.length; i++)
			{
				ch = element.value.charAt(i);
				for (j = 0; j < checkStr.length; j++)
				{
					if (ch == checkStr.charAt(j))
						break;
				}
				if (j == checkStr.length)
				{
					error += "Položka \"" + title + "\" je chybně vyplněna !" + allowed + "\r\n";
					break;
				}
			}
		}
		if ((required) && (element.value.length == 0))
			error += "Položka \"" + title + "\" musí být vyplněna !";
		else
		if ((minlength) && (element.value.length > 0))
		{
			if (element.value.length < minlength)
				error += "Minimální délka položky \"" + title + "\" " + prenumverb(minlength, "znak", "znaky", "znaků") + " !";
		}
		else
		if ((regExp.length > 0) && (element.value.length > 0))
		{
			if ((accept == "email") || (accept == "emailleftpart"))
				if (!(element.value.search(regExp) == 0))
					error += "Položka \"" + title + "\" nemá platný formát e-mailu !";
				else
				if (regExp2.length > 0)
				{
					if (!(element.value.search(regExp2) == 0))
						error += "Položka \"" + title + "\" nemá platný formát e-mailu !";
				}
		}
	}
	
	if ((type == "listbox") && (required))
	{
		var selection = false;
		for (i = 0; i < element.length; i++)
			if ((element.options[i].selected) && (element.options[i].value.length > 0))
				selection = true;
		if (!selection)
			error += "U položky \"" + title + "\" není vybrána žádná volba !";
	}
	
	if ((type == "check") && (required))
	{
		var check = false;
		for (i = 0; i < element.length; i++)
			if ((element[i].checked) && (element[i].value.length > 0))
				check = true;
		if (!check)
			error += "U položky \"" + title + "\" není vybrána žádná volba !";
	}
	
	if (error.length > 0)
		return error;
	else
		return false;
}
