var focus_changing = false;
var dont_check = false;

// Focus into field f, display message s and return false
function focus_alert(s, f) {
	f.focus();
	alert(s);
	return false;
}

// Check fields in the form
// s is warning message, f is pointer to <form>, next arguments are names of mandatory fields
// example of use: <form onSubmit="return form_correct('Fill-in all marked fields!', this, 'name', 'password');">
function form_correct(s, f) {
	// correctness of each field
	for (i=0; i < f.elements.length; i++) {
		if (f.elements[i].onblur != undefined && !f.elements[i].onblur()) {
			return false;
		}
	}
	
	// non-emptiness of selected fields
	for (i=2; i < arguments.length; i++) {
		if (f[arguments[i]].value == '') {
			return focus_alert(s, f[arguments[i]]);
		}
	}
	return true;
}

// Check if field matches ereg
// example of use: <input onBlur="return ereg_correct('Enter a date!', this, /^[0-9]{4}-[0-9]{2}-[0-9]{2}$/);">
function ereg_correct(s, f, regexp) {
	if (f.value == '' || regexp.test(f.value)) {
		return true;
	}
	if (!focus_changing) {
		focus_changing = true;
		focus_alert(s, f);
		focus_changing = false;
	}
	return false;
}

// Check if there is a number in the field
// s is warning message, f is input field, boolean negative allows negative values, d1 is number of digits before decimal point, optional d2 is maximum count of digits after decimal point (empty - none, d1 - unlimited)
// example of use: <input onBlur="return number_correct('Enter a possitive number!', this, false, 5);">
function number_correct(s, f, negative, d1, d2) {
	f.value = f.value.replace(',', '.');
	return ereg_correct(s, f, new RegExp('^'+ (negative ? '-?' : '') +'[0-9]{0,'+ (d1 ? d1 : '') +'}'+ (d2 ? '([.][0-9]{1,'+ d2 +'})?' : '') +'$'));
}

// Check if there is an e-mail in the field, simplified!
// example of use: <input onBlur="return email_correct('Enter an e-mail!', this);">
function email_correct(s, f) {
	return ereg_correct(s, f, /^[^ @]+@[^ @]+\.[^ @]+$/);
}

// Check if there is a URL in the field, simplified!
// example of use: <input onBlur="return email_correct('Enter a URL!', this);">
function url_correct(s, f) {
	return ereg_correct(s, f, /^https?:\/\/[^ \/]+\.[^ ]+/);
}

// Open image window
function img_open(filename, w, h, title) {
	with (window.open('', '', (w && h ? 'width=' + w + ', height=' + h : 'width=100, height=100'))) {
		document.write('<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">\n<html>\n');
		if (title) {
			document.write('<head>\n<title>' + title + '</title>\n</head>\n');
		}
		document.write('\n<body leftmargin="0" topmargin="0">\n\n');
		document.write('<a href="javascript:window.close();" title="Zavřít náhled">');
		document.write('<img src="' + filename + '"' + (w && h ? ' width="' + w + '" height="' + h + '"' : '') + ' border="0">');
		document.write('</a>\n');
		document.write('\n</body>\n</html>\n');
		return true;
	}
	return false;
}

//// JF
function menu_onoff(item) {
    with (document.getElementById(item).style) {
        display = (display == "none" ? "block" : "none");
        return true;
    }
    return false;
}

