function kontrolaFormulare(data) {
	var chybejiciInputClassName = 'input-nevyplneno';
	var textelement = 'span';
	var chybejici = '';
	var focused = false;

	for(var i=0;i<data.length;i++) {
		var parametry = new Array();
		var tmpHodnoty = data[i].split(';');
		var chyba = false;

		for(var t=0;t<tmpHodnoty.length;t++) {
			parametry[tmpHodnoty[t].substring(0,tmpHodnoty[t].indexOf('='))] = tmpHodnoty[t].substring(tmpHodnoty[t].indexOf('=')+1, tmpHodnoty[t].length);
		}

		if(parametry['id'] && document.getElementById(parametry['id'])) {
			if(!document.getElementById(parametry['id']).value) {
				chyba = true;
				chybejici += parametry['name']+', ';
			} else if(parametry['format']) {
				//alert(parametry['format']);
				//if(!parametry['format'].test(document.getElementById(parametry['id']).value)) {
				if(!document.getElementById(parametry['id']).value.match(parametry['format'])) {
					chyba = true;
					chybejici += ' špatně vyplněno '+parametry['name']+', ';
				}
			} else {
				if(parametry['textelement'] || (textelement.length > 0)) {
					var tmp = parametry['textelement'] ? document.getElementById(parametry['id']).parentNode.getElementsByTagName(parametry['textelement']) : document.getElementById(parametry['id']).parentNode.getElementsByTagName(textelement);
					if(tmp[0]) {
						tmp[0].className = tmp[0].className.replace(' '+chybejiciInputClassName, '');
					}
				}
			}

			if(chyba) {
				if(parametry['textelement'] || (textelement.length > 0)) {
					var tmp = parametry['textelement'] ? document.getElementById(parametry['id']).parentNode.getElementsByTagName(parametry['textelement']) : document.getElementById(parametry['id']).parentNode.getElementsByTagName(textelement);
					if(tmp[0]) {
						if(tmp[0].className.indexOf(chybejiciInputClassName) == -1) tmp[0].className += ' '+chybejiciInputClassName;
					}
				}

				if(!focused) {
					document.getElementById(parametry['id']).focus();
					focused = true;
				}
			}
		}
	}

	if(chybejici.length > 0) {
		alert('Vyplňte všechny povinné položky - '+chybejici.substring(0, chybejici.length-2)+'.');
		return false;
	} else {
		return true;
	}
}

function _click(res) {
	odkazy = res.parentNode.getElementsByTagName('a');
	if(odkazy[0].href) {
		document.location = odkazy[0].href;
	}
}

function clickableRow(kde) {
	table = kde.getElementsByTagName('tbody');
	for(i=0;i<table.length;i++) {
		if(table[i].className == 'clickable') {
			table[i].style.cursor = 'pointer';
			radky = table[i].getElementsByTagName('tr');
			for(t=0;t<radky.length;t++) {
				//případný onclick = odkaz
				odkazy = radky[t].getElementsByTagName('a');
				if(odkazy[0]) {
					bunky = radky[t].getElementsByTagName('td');
					for(l=0;l<bunky.length;l++) {
						jeOdkaz = bunky[l].getElementsByTagName('a');
						if(!jeOdkaz[0]) bunky[l].onclick = function() {_click(this)};
					}
				}
			}
		}
	}
}


$(document).ready(function() {
	if(document.getElementById('produkt-foto')) {
		var el = document.getElementById('produkt-foto').getElementsByTagName('a');
		for(var i=0;i<el.length;i++) {
			var tmp = document.createElement('span');

			var obr = el[i].getElementsByTagName('img');
			if(obr[0]) {
				if((obr[0].width != 0) && (obr[0].height != 0)) {
					tmp.style.right = Math.round((190-obr[0].width)/2)+'px';
					//tmp.style.bottom = '20px';
				}
			}
			el[i].appendChild(tmp);
		}
	}
	clickableRow(document);
	
	$('a.fancybox').fancybox();
});


