// generic validation functions
function validateString(str, warning, min, max) {
	if (!min) {
		min = 1;
	}
	if (!max) {
		max = 65535;
	}

	if (!str.value || str.value.length < min || str.value.length > max) {
		alert(unescape(warning));
		str.focus();
		str.select();
		return false;
	}

	return true;
}


//----------------------------------
function validateEmail(email) {
	if (!email.value) {
		return true;
	}

	var re_mail = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z])+$/;
	if ( !re_mail.test(email.value) ) {
		alert('Nesprávný formát email adresy');
		email.focus();
		email.select();
		return false;
	}

	return true;
}

//----------------------------------
function validateRc(rc) {
	if (!rc.value) {
		return true;
	}

	var re_rc = /^[0-9]{6}\/[0-9]{4}$/;
	if ( !re_rc.test(rc.value) ) {
		alert('Nesprávný formát rodého čísla (správně:  XXXXXX/XXXX)');
		rc.focus();
		rc.select();
		return false;
	}

	return true;
}

//----------------------------------
function validateNum(var1, min, max) {
	if (!var1.value) {
		return true;
	}

	var re_num = /^([0-9])/;
	if ( !re_num.test(var1.value) ) {
		alert('Nespravny format cisla'.min.value);
		var1.focus();
		var1.select();
		return false;
	}

	if ( var1.value < min.value ) {
		alert('Cislo je mensi nez je povoleno');
		var1.focus();
		var1.select();
		return false;
	}

	if ( var1.value > max.value ) {
		alert('Cislo je vetsi nez je povoleno');
		var1.focus();
		var1.select();
		return false;
	}
        
	return true;
}

//----------------------------------
function validateDate(var1) {
	if (!var1.value) {
		return true;
	}

	var re_date = /^([0-9]){4}[-.]{1}([0-9]){2}[-.]{1}([0-9]){2}$/;
	if ( !re_date.test(var1.value) ) {
		alert('Nespravny format datumu');
		var1.focus();
		var1.select();
		return false;
	}

	return true;
}

//----------------------------------
function validateMatch(var1, var2, msg) {
	if (var1.value != var2.value) {
		alert(unescape(msg));
		var1.focus();
		var1.select();
		return false;
	}

	return true;
}


// site specific validation functions
//----------------------------------
function OpenEmptyWin(url,width,height) {
        var setting="toolbar=no,location=no,directories=no,"+
                 "status=no,menubar=no,scrollbars=yes,"+
                 "resizable=yes,width="+width+",height="+height+","+
                 "left=150,top=150";

        b= window.open(url,"new",setting); 
        b.focus();
}

var objItem;
//----------------------------------
function ShowDate(strItem) {
	objItem = strItem
	var objWnd = window.open("SelectDate.html","Datum","scrollbars=yes,resizable=yes,height=280,width=330");
	objWnd.focus();
}
//----------------------------------
function ShowPicture(strItem) {
	objItem = strItem
	var objWnd = window.open("SelectPic.php","Obrázek","scrollbars=yes,resizable=yes,height=620,width=440");
	objWnd.focus();
}
//----------------------------------
function ShowZaci(strItem) {
	objItem = strItem
	var objWnd = window.open("vyber_zaka.php?GRP="+document.form1.urceno_grp.value,"Výběr_žáka","scrollbars=yes,resizable=yes,height=620,width=440");
	objWnd.focus();
}
//----------------------------------
function ShowFile(strItem) {
	objItem = strItem
	var objWnd = window.open("SelectFile.php","Soubory","scrollbars=yes,resizable=yes,height=620,width=380");
	objWnd.focus();
}
//----------------------------------
function ImageZoom(file) {
	file="../obrazky/"+file
	window.open(file,"Detail","scrollbars=yes,resizable=yes,height=420,width=590");
}
//----------------------------------
function goBack() {
	window.history.back()
}
//----------------------------------
function clearValues(theTextField) {
	eval("document.form1."+theTextField+".value=''");
}

//----------------------------------
function ShowHelp(file) {
	window.open(file,"Datum","scrollbars=yes,resizable=yes,height=330,width=430");
}
