function check_nakup()
{
	var company_ok;
	
	if (document.pokladna.frm_ico.value.length)
		company_ok = document.pokladna.frm_company.value.length;
	else
		company_ok = true;


	var errors = new Array();
	
	with (document.pokladna)
	{
		if (!frm_name.value.length)			errors.push("jméno");
		if (!frm_surname.value.length)		errors.push("příjmení");
		if (!frm_phone.value)				errors.push("telefon");
		if (!is_mail_ok(frm_email.value))	errors.push("e-mail");
		if (!frm_street.value.length)		errors.push("ulice");
		if (!frm_city.value.length)			errors.push("město");
		if (!frm_zip.value.length)			errors.push("PSČ");
		if (!radioValue(document.pokladna.platby))	errors.push("způsob platby");
		if (!radioValue(document.pokladna.doprava))	errors.push("způsob dopravy");
		if (!company_ok)					errors.push("firma");
	}

	with (document.pokladna)
		if (
			frm_name.value.length &&
			frm_surname.value.length &&
			frm_phone.value.length &&
/*			frm_email.value.length &&*/
			is_mail_ok(frm_email.value) &&
			frm_street.value.length &&
			frm_city.value.length &&
			frm_zip.value.length &&
			radioValue(document.pokladna.platby) &&
			radioValue(document.pokladna.doprava) &&
			company_ok
		)
			return true;
		else
			alert("Vyplňte korektně tyto položky: \n" + errors.join(", "));
		
	return false;
}

function check_dotaznik()
{
	var company_ok;
	var errors = new Array();
	
	with (document.dotaznik)
	{
		if (!frm_name.value.length)			errors.push("jméno");
		if (!frm_surname.value.length)		errors.push("příjmení");
		if (!frm_phone.value)				errors.push("telefon");
		if (!is_mail_ok(frm_email.value))	errors.push("e-mail");
		
		if (!boxValue(document.dotaznik, "profese").length)	errors.push("obor podnikání");
	}

	with (document.dotaznik)
		if (
			frm_name.value.length &&
			frm_surname.value.length &&
			frm_phone.value.length &&
			is_mail_ok(frm_email.value) &&
			
			boxValue(document.dotaznik, "profese").length
		)
			return true;
		else
			alert("Vyplňte korektně tyto položky: \n" + errors.join(", "));
		
	return false;
}

function boxValue(formObj, boxName)
{
	var values = new Array();
	
	eval("var pattern = /" + boxName + "/g;");
	
	for (var i = 0; i < formObj.elements.length; i++)
		if (formObj.elements[i].name.search(pattern) >= 0)
			if (formObj.elements[i].checked)
				values.push(formObj.elements[i].value);
	
	return values;
}

function radioValue(radioObj)
{
	if (!radioObj)
		return "";
	
	var radioLength = radioObj.length;
	
	if (radioLength == undefined)
		if (radioObj.checked)
			return radioObj.value;
		else
			return "";
	
	for (var i = 0; i < radioLength; i++)
	{
		if (radioObj[i].checked)
			return radioObj[i].value;
	}
	
	return "";
}


function is_mail_ok(mail)
{
	return (mail.match(/[A-Za-z0-9\._\-]+@[A-Za-z0-9\._\-]+\.[A-Za-z]{2,}/g) != null);
}

function is_phone_ok(phone)
{
	return (
		phone.match(/(00|\+)( )?[0-9]{3}( )?[0-9]{3}( )?[0-9]{3}( )?[0-9]{3}/g) != null &&
		phone.length <= 14	// 17 ?
	);
}


function setRadioHandler()
{
	document.pokladna.platby[0].onclick = function()
	{
		document.pokladna.platby[1].disabled = false;
		document.pokladna.platby[2].disabled = false;
		
		document.pokladna.doprava[1].disabled = true;
		document.pokladna.doprava[1].checked = false;
		
		document.pokladna.doprava[0].disabled = false;
	}
	
	document.pokladna.platby[1].onclick = function()
	{
		document.pokladna.platby[0].disabled = false;
		document.pokladna.platby[2].disabled = false;
		
		document.pokladna.doprava[0].disabled = true;
		document.pokladna.doprava[0].checked = false;
		
		document.pokladna.doprava[1].disabled = false;
	}
	
	document.pokladna.platby[2].onclick = function()
	{
		document.pokladna.platby[0].disabled = false;
		document.pokladna.platby[1].disabled = false;
		
		document.pokladna.doprava[0].disabled = false;
		
		document.pokladna.doprava[1].disabled = false;
	}
	
	
	document.pokladna.doprava[0].onclick = function()
	{
		document.pokladna.doprava[1].disabled = false;
		
		document.pokladna.platby[0].disabled = false;
		
		document.pokladna.platby[1].disabled = true;
		document.pokladna.platby[1].checked = false;

		document.pokladna.platby[2].disabled = false;
	}
	
	document.pokladna.doprava[1].onclick = function()
	{
		document.pokladna.doprava[0].disabled = false;
		
		document.pokladna.platby[0].disabled = true;
		document.pokladna.platby[0].checked = false;
		
		document.pokladna.platby[1].disabled = false;

		document.pokladna.platby[2].disabled = false;
	}
}





























