// --- debug console --- start --- //
var _console = null;

function debug_prop(msg) {
	debug_console("<h3>Vlastnosti: " + msg + "</h3>");
	for (i in msg)
		try {	debug_console("<b>" + i + "</b> : " + msg[i]); }
		catch(e) { debug_console("<i>Exception: " + i + "</i>"); }
}

function debug_console(msg) {
	if ((_console == null) || (_console.closed)) {
		_console = window.open("","console","width=600,height=300,resizable,scrollbars");
		_console.document.open("text/html");
	}
	_console.document.writeln("<br>" + msg);
}
// --- debug console --- end --- // 

var isDOM = (document.getElementById);
var isIE4 = (document.all && !isDOM);
var isNS4 = (document.layers);
var isDyn = (isDOM || isIE4 || isNS4);

function getRef(id) {
	if (isDOM) return document.getElementById(id);
	if (isIE4) return document.all[id];
	if (isNS4) return document.layers[id];
}

function getVP(x) {
	return document.forms[x ? x : 'vp'];
}

function r2(x, desMist) {
x = parseFloat(x);
return Math.round(x * Math.pow(10, desMist)) / Math.pow(10, desMist)
}

function nf(x) {
x = parseFloat(x.replace(/,/, "."));
return isNaN(x) ? 0 : x;
}

function showNum(x) {
return (x == Infinity || x == -Infinity || isNaN(x)) ? "-" : x;
}

function enAb(theObject) {
theObject.style.backgroundColor = '#FFFFFF';
theObject.readOnly = false;
}

function disAb(theObject) {
theObject.style.backgroundColor = '#CCCCCC';
theObject.readOnly = true;
}

function itemIndex(r) {
for (var i = 0; i < r.length; i++) { if (r[i].checked == true) {return i} }
return -1;
}

function createSelect(s, p, d) {
s.length = 0; 
for (var i = 0; i < p.length; i++) { s[i] = new Option(p[i]); } 
s.selectedIndex = d;
}

function info(url, imgName) {
	obr = new Image();
 	obr.src = "./images/cenik/"+imgName;
	if (!obr.height && !obr.width) {
		obr.src = "./images/cenik/empty.gif";
	}

	var maxY;
	var winX = 600;
	var winY = 470;

	if (screen.height <= 480) {
		maxY = 350;
		winX = 500;
	} else if (screen.height <= 600) {
		maxY = 500;
		winX = 600;
	} else {
		maxY = 500;
		winX = 800;
	}

 	if (obr.width && obr.height) {
		if (obr.width / 2 < winX / 2) {
			winY = (obr.height + 250 < maxY) ? obr.height + 250 : maxY;
		} else {
			winY = (obr.height + 500 < maxY) ? obr.height + 500 : maxY;
		}
	}

	var leftpos = (screen.availWidth - winX) / 2;
	var toppos = (screen.availHeight - winY) / 2;

	resiz = (navigator.appName=="Netscape") ? 0 : 1;
	windowHandle = window.open(url+"&amp;winX="+winX+"&amp;winY="+winY,"info","width="+winX+",height="+winY+",top="+toppos+",left="+leftpos+",directories=0,location=0,menubar=0,scrollbars=1,status=0,titlebar=0,toolbar=0,resizable="+resiz+"");
	windowHandle.focus();
	return false;
}

function nahled(imgName,browserTitle,type) {
	imgX = 640;
	imgY = 449;

	var leftpos = (screen.availWidth - (imgX + 20)) / 2;
	var toppos = (screen.availHeight - (imgY + 20)) / 2;

	resiz = (navigator.appName=="Netscape") ? 0 : 1;
	italie02 = window.open('./show.php4?browserTitle='+browserTitle+'&img='+imgName+"&imgX="+imgX+"&imgY="+imgY+"&type="+type,"italie02","width=660,height=474,top="+toppos+",left="+leftpos+",directories=0,location=0,menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0,resizable="+resiz+"");
	italie02.focus();
	return false;
}

function nahled_medovina(imgName) {
	imgX = 162;
	imgY = 373;

	var leftpos = (screen.availWidth - (imgX + 20)) / 2;
	var toppos = (screen.availHeight - (imgY + 20)) / 2;
	resiz = (navigator.appName=="Netscape") ? 0 : 1;

	jhmedovina = window.open("./show.php4?browserTitle=Medovina Jan Halada&img="+imgName+"&imgX="+imgX+"&imgY="+imgY+"&type=0","jhmedovina","width=660,height=474,top="+toppos+",left="+leftpos+",directories=0,location=0,menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0,resizable="+resiz+"");
	jhmedovina.focus();
	return false;
}

function showPruceli() {
	var leftpos = (screen.availWidth - 515) / 2;
	var toppos = (screen.availHeight - 375) / 2;

	resiz = (navigator.appName=="Netscape") ? 0 : 1;
	winPruceli = window.open("./pruceli.php4","info","width=515,height=374,top="+toppos+",left="+leftpos+",directories=0,location=0,menubar=0,scrollbars=0,status=0,titlebar=0,toolbar=0,resizable="+resiz+"");
	winPruceli.focus();
	return false;
}

function pWin(url,i_width,i_height) {
	var swidth=screen.width, sheight=screen.height;
	//doplnit testovani (0, None ?) spravne nacteni jinak nastavit swidth=590 a sheight=410 (pro 800x600)
	var min_x=100, min_y=100, max_x=swidth-50, max_y=sheight-190;
	var owidth=i_width>max_x?max_x:i_width<min_x?min_x:i_width, oheight=i_height>max_y?max_y:i_height<min_y?min_y:i_height;
	if ((owidth!=i_width) || (oheight!=i_height)) pageWin = window.open(url,"","width="+owidth+",height="+oheight+",menubar=0,scrollbars=1,resizable=1,screenX=20,screenY=40,left=20,top=40");
	else pageWin = window.open(url,"","width="+owidth+",height="+oheight+",scrollbars=1,resizable=1,screenX=20,screenY=40,left=20,top=40");
	pageWin.focus();
	return false;
}
