/**
 * zkontroluje vyplnena pole formulare,
 * pokud je pole povinne, ma class = required
 */

function validate(id){
	var send = true;
	var focus = false;
	var form = document.getElementById(id);
	//pole typu input
	var inputs = form.getElementsByTagName("input");
	var pocetInputs = inputs.length;
	//pole typu textarea
	var textareas = form.getElementsByTagName("textarea");
	var pocetTextareas = textareas.length;
	for (i=0;i<pocetInputs;i++){
		if (inputs[i].type == "hidden" || inputs[i].type == "button" || inputs[i].type == "submit" || inputs[i].type == "reset")
			continue;
		if(inputs[i].className.indexOf("required") == 0 && inputs[i].value == ''){
			if(!focus){
				focus = inputs[i];
			}
			send = false;
		}
	}
	for (i=0;i<pocetTextareas;i++){
		if(textareas[i].className.indexOf("required") == 0 && textareas[i].value == ''){
			send = false;
		}
	}

	if(!send){
		self.alert('Je potřeba vyplnit povinná pole!');
		if(focus){
			focus.focus();
		}
		return false;
	}
	return true;
}


function getWindowFeatures(width, height) {
	width = width > screen.availWidth ? screen.availWidth : width;
	height = height > screen.availHeight ? screen.availHeight : height;
	// umisteni okna doprostřed obrazovky
	var left = (screen.availWidth - width) / 2;
	var top = (screen.availHeight - height) / 2;
	// vlastnosti nového okna
	var features = "left=" + left + ",top=" + top + ",width=" + width + ",height=" + height
	    + ",resizable=yes,scrollbars=yes,status=no,toolbar=no,menubar=no,location=no";
	return features;
}

// Otevře hlavní okno aplikace
function openMainWindow(a_url) {
	// defaultní velikost hlavního okna (1024x768)
	var width = 1024;
	var height = 768;
	var url = a_url;
	// zajištění možnosti otevřít různá okna z různých profilů (target je vždy jiný)
	//var target = "mainWindow" + getUniqueId();
	var target = "issenew";
	// otevření okna
	var winObj=window.open(url, target, getWindowFeatures(width, height));
	// nastavení focusu na otevřené okno
	winObj.focus();
}