/*
copyright by
F.H.U. Slawomir Kaniecki
e-mail: kontakt (at) www-editor (dot) net
/**/
var mouse_special = 0;
var js_debug = 0;

document.onclick			= m_klik;
document.onmouseover	= m_klik;
document.onmouseout		= m_klik;
//	document.onmousemove	= m_klik;
function m_klik(e) {
	if (e) { targ = e.target; type = e.type; } // FF
	else if (window.event) { targ = window.event.srcElement; type = window.event.type; } // IE
	if (targ) {
		//	alert(type);
		//	if (debug2) debug2.innerHTML += 'type l: ' + (++l) + ', type: ' + type + ', t: ' + targ.tagName + ' ' + targ.className + '<BR>';

		if (type == 'click') {
			if (mouse_special == 1) img01_click(targ);

			if (targ.slovek == 'listindex') {
				custom_usun_el(targ);
			}
			if (targ.slovek == 'photos_grp') {
				custom_photos_grp_click(targ);
			}
			if (targ.slovek == 'photos_grp1') {
				custom_photos_grp1_click(targ);
			}
			if (targ.slovek == 'xxx') {
				// code here
			}
		}
		if (type == 'mouseover') {
			if (mouse_special == 1) img01_over(targ);

			if (targ.slovek == 'listindex') {
				custom_show_del(targ);
			}
			if (targ.slovek == 'photos_grp') {
				custom_photos_grp_over(targ);
			}
			if (targ.slovek == 'photos_grp1') {
				custom_photos_grp1_over(targ);
			}
		}
		if (type == 'mouseout') {
			if (mouse_special == 1) img01_out(targ);

			if (targ.slovek == 'listindex') {
				custom_hide_del(targ);
			}
			if (targ.slovek == 'photos_grp') {
				custom_photos_grp_out(targ);
			}
			if (targ.slovek == 'photos_grp1') {
				custom_photos_grp1_out(targ);
			}
		}
	}
}

document.onmousemove = myszka;
var mouseX = -1;
var mouseY = -1;
function myszka(e) {
	if (e) {
		mouseX = e.pageX;
		mouseY = e.pageY;
	}
	else if (window.event) {
		mouseX = window.event.x + document.body.scrollLeft;
		mouseY = window.event.y + document.body.scrollTop;
	}
}

function find_po(t) {
	var o = t;
	do {
		alert(o.tagName);
	//	} while (o = o.parentElement)
	//	} while (o = o.offsetParent)
	} while (o = o.parentNode)
	//	return false;
}

function find_o(targ, class_name) {
	if (class_name == '') return null;
	var o = targ;
	do {
		if (o.className == class_name) {
			return o;
		}
	//	} while (o = o.offsetParent)
	} while (o = o.parentNode)
	return null;
}

function el_pos(el) {
	var ret = new Object();
	ret.left = 0;
	ret.top  = 0;
	ret.width  = 0;
	ret.height = 0;
	var o = el;
	ret.left = o.offsetLeft;
	ret.top  = o.offsetTop;
	//	while (o = o.parentNode) {
	while (o = o.offsetParent) {
		ret.left = ret.left + o.offsetLeft;
		ret.top  = ret.top  + o.offsetTop;
		ret.width  = el.offsetWidth;
		ret.height = el.offsetHeight;
	}
	return ret;
}

function set_opacity(o, value) {
	o.style.opacity = value/100;
	o.style.filter = 'alpha(opacity=' + value + ')';
}

function switch_class(id, st1, st2) {
	var o = document.getElementById(id);
	if (o) {
		if (o.className == st2) o.className = st1;
		else o.className = st2;
	}
}

function show(id, state) {
	var o = document.getElementById(id);
	if (o) {
		if (state == undefined || state == 1)
			o.style.visibility = 'visible';
		if (state == 0)
			o.style.visibility = 'hidden';
		if (state == 2)
			//	alert(o.style.visibility)
			if (o.style.visibility == 'hidden') {
				o.style.visibility = 'visible';
				//	o.style.position = 'relative';
			}
			else {
				o.style.visibility = 'hidden';
				//	o.style.position = 'absolute';
			}
	}
}

//	document.onmousemove = window.status = '';
var winow = 0;
var winoh = 0;
function wino(id, target, typ) {
	var tmp;
  var i = new Object();
	i.width  = (winow) ? winow : 720;
	i.height = (winoh) ? winoh : 600;
	var l = Math.round( (screen.width  - i.width -50) / 2 );
	var t = Math.round( (screen.height - i.height -80) / 2 );
	//	alert(i.width + ' : ' + i.height)
	typ = (typ != undefined) ? '&typ=' + typ : '';

	script = '/open.php';
	if (target == 'print') script = '/print.php';
	else target = 'open';

	tmp = window.open(script + '?id=' + id + typ, target, 'location=yes,toolbar=no,scrollbars,resizable,left=' + l + ',top=' + t + ',screenX=0,screenY=0, width=' + i.width + ', height=' + i.height + '');
	tmp.focus();
}
function winp(id, typ) {
	wino(id, 'print', typ);
}

function wino2(tresc) {
	var tmp;
  var i = new Object();
	i.width  = (winow) ? winow : 720;
	i.height = (winoh) ? winoh : 600;
	var l = Math.round( (screen.width  - i.width -50) / 2 );
	var t = Math.round( (screen.height - i.height -80) / 2 );

	script = '';
	target = '_blank';

	tmp = window.open(script, target, 'location=yes,toolbar=no,scrollbars,resizable,left=' + l + ',top=' + t + ',screenX=0,screenY=0, width=' + i.width + ', height=' + i.height + '');
	tmp.document.writeln(tresc + '<P STYLE="margin: 20px; text-align: center; "><a HREF="#" OnClick="self.close(); return false; ">close</A></P>');
	tmp.focus();
	tmp.document.close();
}



if (!lnv) {
  var lnv = new Object();
  lnv.pytdel = 'delete';
  lnv.pytsav = 'save';
  lnv.pytchange = 'change';
}

function ttip(o, t) {
	var obj = document.getElementById(o);
	if (obj) {
		//	window.status = mouseX + ' : ' + mouseY + ' : ' + obj.offsetWidth + ' a:' + obj.style.backgroundColor;
		obj.style.left = mouseX - obj.offsetWidth  - 10;
		obj.style.top  = mouseY - obj.offsetHeight - 10;
		obj.style.visibility = (t == 1) ? 'visible' : 'hidden';
	}
}

function offset(id, job) {
	if (document.daria.ourlist1) document.daria.ourlist.value = document.daria.ourlist1.value;
	document.daria.offset.value = id;
	document.daria.job.value = (job) ? job : 'search';
	document.daria.submit();
}


function setjob(id) {
	window.status = id.substring(id.length-3);
	sbmt(document.daria.job, (id.substring(id.length-3)=='del')?1:0, id);
}
function sbmt(id, code, property) {
	var ok = true;
	if (code) {
		var txt = '';
		switch (code) {
		case 1:  txt = lnv.pytdel + ' ?'; break;
		case 2:  txt = lnv.pytsav + ' ?'; break;
		case 3:  txt = lnv.pytchange + ' ?'; break;
		default: txt = 'pytanie ?'; break;
		}
		ok = confirm(txt);
	}
	if (ok) {
		if (property) {
			id.value = property;
			id.form.submit(); 
		}
		else {
			if (id.form.todo) id.form.todo.value = id.name;
			id.form.submit(); 
		}
	}
}

function show_img(x, type) {
	var tmp;
	type = (type) ? 'type=' + type + '&' : '';
	tmp = window.open('/img.php?' + type + 'x=' + x, 'img', 'toolbar=no,scrollbars,resizable,left=0,top=0,screenX=0,screenY=0,width=1,height=1');
	tmp.focus();
}

function switch_img(id) {
	var o = document.getElementById(id);
	if (o) {
		o.src = o.tab[++o.l % o.tab.length];
		setTimeout("switch_img('" + id + "')", 5000);
	}
}

function fitwin() {
	var i = document.getElementById('img');
	var l = Math.round( (screen.width  - i.width -50) / 2 );
	var t = Math.round( (screen.height - i.height -80) / 2 );
	//alert(i.width);
	this.window.moveTo(l, t);
	this.window.resizeTo(i.width + 50, i.height + 80);
}

function clk(el, r) {
//	alert()
	el.form.job.value = el.name; el.form.submit();
}

//*
function radio_sel(r) {
	if (r) {
		if (r.length) { for (var i=0; i<r.length; i++) if (r[i].type == 'radio' && r[i].checked) return i; return -1; }
		else return (r.type == 'radio' && r.checked)?0:-1;
	}
	else return -2;
}

function radio_val(r, id) {
	if (r) {
		if (r.length) return r[id].value;
		else return r.value;
	}
	else return false;
}

function radio_sel_val(r) {
	var id = radio_sel(r);
	if (id > -1) return radio_val(r, id)
	return '';
}
/**/

var msel      = null;
var offsleft  = 0;
var offsleft1 = 0;
var offstop   = 0;
function on(x) {
	var msg = '';
	var offs = 0;
	if (!x && msel) { x = msel; }
	if (!offsleft) offsleft = 0;

	var o = document.getElementById('main');
	if (o) {
		offs = parseInt((document.body.clientWidth - o.offsetWidth));
		//	offs = (offs > 0  && o.offsetLeft > 0) ? o.offsetLeft : parseInt(offs / 2);
		offs = parseInt(offs / 2);
		if (offs < 0) offs = 0;
		szerokosc = o.offsetWidth;
		//	alert(offs + ' - ' + szerokosc);
	}
	else { alert('blad'); }
	var o = document.getElementById(x);
	if (o) {
		var oo = document.getElementById('m' + x);
		if (oo) {
			o1 = el_pos(o);
			if (menu_type == 'v') {
				//	if (debug) debug.innerHTML = 'l: ' + (++l) + ', po.id: ' + po.id + ', o.top: ' + o.top + ' o.left: ' + o.left + ' o.width: ' + o.width + ' o.height: ' + o.height;

				//	alert( 'o.id: ' + o.id + ', o.top: ' + o1.top + ' o.left: ' + o1.left + ' o.width: ' + o1.width + ' o.height: ' + o1.height )
					oo.style.top  = o1.top + offstop;
					oo.style.left = o1.left + o1.width;
			}
			else {
				//	if (debug) debug.innerHTML = 'l: ' + (++l) + ', po.id: ' + po.id + ', o.top: ' + o.top + ' o.left: ' + o.left + ' o.width: ' + o.width + ' o.height: ' + o.height;
				//	oo.style.top = 65;
				//	oo.style.width = o.offsetWidth;
				if (offstop)	oo.style.top = o1.top + offstop;
	
				var ot = document.getElementById('m' + x + 't');
				if (ot) { ot.style.width = (o.offsetWidth > ot.offsetWidth) ? o.offsetWidth : ot.offsetWidth; }
	
				oo.style.left = o.offsetLeft + offs + offsleft;
				if (o.offsetLeft + parseInt(ot.style.width) > szerokosc - offsleft) {
					msg += 'szerokosc: ' + szerokosc + "\n";
					msg += 'ot.style.width: ' + ot.style.width + "\n";
					msg += 'offs: ' + offs + "\n";
					msg += 'offsleft1: ' + offsleft1 + "\n";
					oo.style.left = szerokosc - parseInt(ot.style.width) + offs - offsleft1;
					// + offsleft
					//	alert('test');
				}
			}
			msg += 'oo.style.left: ' + oo.style.left + "\n";

			if (js_debug) alert(msg)
			oo.style.visibility = 'visible';
			oo.show = true;
			if (msel && msel != x) hide(msel);
			msel = x;
		}
	}
}

function off(x) {
	if (!x && msel) { x = msel; }
	var o = document.getElementById(x);
	if (o) {
		var oo = document.getElementById('m' + x);
		if (oo) {
			oo.tout = setTimeout('hide(\'' + x + '\')', 700);
			oo.show = false;
		}
	}
}

function hide(x) {
	var o = document.getElementById('m' + x);
	if (o && !o.show) {
		o.style.visibility = 'hidden';
	}
}

function drukuj() {
	if (window.print) { window.print(); }
}

