//cykl wywołania pliku dwiękowego alarmu
var delay_alarm_sound = 5000;
//plik dwiękowy alarmu
var alarm_sound_file = '/alarm_3.wav';

//wywołanie alarmu dwiękowego
function alarm_sound(){
	var s = document.getElementById('sound_div');
	if(s){
		s.innerHTML = '<object height="0" width="0" classid="clsid:22D6F312-B0F6-11D0-94AB-0080C74C7E95"><param name="AutoStart" value="1" /><param name="Loop" value="0" /><param name="FileName" value="'+alarm_sound_file+'" /></object>';
	}
}


function f_location(loc) {
	window.location=loc;
}

function fk(kat_id, max_kat) {
	var o=document.getElementById('kat_'+kat_id);
	if (o.style.display=='block') o.style.display='none'; else o.style.display='block';
	for (var n=1; n<=max_kat; n++) if (n!=kat_id) document.getElementById('kat_'+n).style.display='none';
	return false;
}

var page_is_loaded=0, is_reg=1, o_map=null, o_geocoder=null, popup_shift_x=0, popup_shift_y=0, show_div_timer=null;

function f_load() {
	page_is_loaded=1;
	if (document.getElementById('div_loader')) {
		document.getElementById('div_loader').style.display='none';
		document.getElementById('div_content').style.display='block';
	}
	tab_menu_set();
}

function f_check_alarms() {
	//tutaj będzie sprawdzanie alarmów
	//jeli wystšpi alarm, to zostanie wywołany alarm dwiękowy i wyskoczy popup
}

function f_href_onclick() {
	if (document.getElementById('ed_wrapper')!=undefined) {
		if ((ile_div==0) && (ile_img==0)) return true; else return confirm(zmiany_zostana_utracone_txt);
	} else {
		return confirm(zmiany_zostana_utracone_txt);
	}
}

var win=new Array(10);
function f_win(name, w, h, nr) {
	if (name.search('help')>0) { w=800; h=450; }
	var top_align = eval(screen.availHeight/2)-eval(h/2)-20;
	var left_align = eval(screen.availWidth/2)-eval(w/2);
	var src=name, scroll='no';
	if ((nr==1) || (nr==2) || (nr==3)) scroll='yes';
	if (nr==2) src='about:blank';
	win[nr]=window.open(src,'win'+nr,'width=' + w + ',height=' + h + ',left=' + left_align + ',top=' + top_align + 
		',resizable=no,scrollbars='+scroll+',toolbar=no,menubar=no,location=no,status=no');
	win[nr].focus();
}

var ns4=document.layers, ns6=document.getElementById&&!document.all, ie4=document.all, mm=document.onmousemove, img1;

function f_popup(width, txt, shift_x, shift_y) {
	popup_shift_x=shift_x;
	popup_shift_y=shift_y;
	document.onmousemove=getmouse;
	if (width>0) popup_obj.style.width=width+'px'; else popup_obj.style.width='';
	popup_obj.innerHTML=txt;
}

function f_popup_out() {
	document.onmousemove=mm;
	popup_obj.style.display='none';
}

function getmouse(e) {
	var x=0, y=0;
	if ((ns4) || (ns6)) {
		x=e.pageX;
		y=e.pageY;
	} else {
		x=event.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
		y=event.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
	}
	popup_obj.style.left=eval(x+popup_shift_x)+'px';
	popup_obj.style.top=eval(y+20+popup_shift_y)+'px';
	popup_obj.style.display='';
}

function f_check_characters(o_name, sw, znaki, err_txt) {
	var re=new RegExp(znaki, "gi");
	var o=document.getElementById(o_name);
	var t=o.value;
	if (t.length==0) {
		if (sw==1) { o.focus(); return '#'; } else return t;
	}
	var A=t.match(re), max1=t.length, n;
	for (n=0; n<max1; n++) {
		if (A[n]!=t.charAt(n)) { alert(err_txt+': '+t.charAt(n)); o.focus(); return '#'; }
	}
	return t;
}

function search_submit(field_name, reg_txt, err_txt) {
	var t=f_check_characters(field_name, 1, reg_txt, err_txt);
	if (t=='#') return;
	window.location=document.search_form.action+t;
	return false;
}

function show_div(type, w, h, title, uri, params, shift_top, shift_left, e, sw) {
	var x=0, y=0, winW=0, winH=0, o_div=document.getElementById('show_div'), t1='';
	if (show_div_timer!=null) clearTimeout(show_div_timer);
	if (e!=null) {
		if (e.clientX) {
			if ((ns4) || (ns6)) {
				x=e.pageX;
				y=e.pageY;
			} else {
				x=e.clientX + (document.documentElement.scrollLeft ? document.documentElement.scrollLeft : document.body.scrollLeft);
				y=e.clientY + (document.documentElement.scrollTop ? document.documentElement.scrollTop : document.body.scrollTop);
			}
		} else if (e.x) {
			x=e.x;
			y=e.y;
		} else {
			if (parseInt(navigator.appVersion)>3) {
				if (navigator.appName=="Netscape") { winW = window.innerWidth-16; winH = window.innerHeight-16; }
				if (navigator.appName.indexOf("Microsoft")!=-1) { winW = document.body.offsetWidth-20; winH = document.body.offsetHeight-20;}
				x=Math.round((winW-w)/2);
				y=Math.round((winH-h)/2);
			}else{ 
				x=Math.round((screen.availWidth-w)/2);
				y=Math.round((screen.availHeight-h)/2);
			}
		}
	} else {
		if (parseInt(navigator.appVersion)>3) {
			if (navigator.appName=="Netscape") { winW = window.innerWidth-16; winH = window.innerHeight-16; }
			if (navigator.appName.indexOf("Microsoft")!=-1) { winW = document.body.offsetWidth-20; winH = document.body.offsetHeight-20;}
			x=Math.round((winW-w)/2);
			y=Math.round((winH-h)/2);
		}else{ 
			x=Math.round((screen.availWidth-w)/2);
			y=Math.round((screen.availHeight-h)/2);
		}
	}
	if(x<0) x=0;
	if(y<0) y=0;
	if ((!o_div) || (sw==1)) {
		close_div();
		o_div=document.createElement('div');
		o_div.setAttribute('id', 'show_div');
		o_div.style.top=eval(y+shift_top)+'px';
		o_div.style.left=eval(x+shift_left)+'px';
		document.getElementById('wrapper').appendChild(o_div);
	}
	if (w>0) o_div.style.width=w+'px';
	if (h>0) o_div.style.height=h+'px'; else o_div.style.minHeight='75px';
	o_div.innerHTML='<div id="show_div_top">'+
		'<div style="float: left;">'+title+'</div>'+
		'<div style="float: right;"><a href="#" id="show_div_a" onclick="close_div(); return false;"><img src="/img/icon_close.gif" style="margin-top: 1px;" alt="" /></a></div></div>'+
		'<div id="show_div_main" style="padding: 10px; text-align: center;" onclick="close_div();">'+
		'<img src="/img/loader1.gif" id="img1" style="margin-top: '+eval(Math.round((Math.max(h, 75)-18)/2)-35)+'px;" />'+
		'</div>';
	if (type=='div') {
		document.getElementById('show_div_main').onclick=function () { };
		http_post('http://'+base_host+uri, params, 'show_div_result');
	} else if (type=='div_xsl') {
		document.getElementById('show_div_main').onclick=function () { };
		http_post_xsl('http://'+base_host+uri, params, sw, 'show_div_main');
	} else if (type=='div_txt') {
		document.getElementById('show_div_main').onclick=function () { };
		show_div_result(uri);
	} else {
		img1=new Image();
		img1.src='/'+uri;
	}
	tr_div(0, type);
}

function tr_div(n, type) {
	var max1=10, v=n/max1, o_div=document.getElementById('show_div');
	if (!o_div) return;
	o_div.style.opacity=v;
	o_div.style.MozOpacity=v;
	o_div.style.filter='alpha(opacity: '+eval(v*100)+')';
	if (n<max1) {
		setTimeout('tr_div('+eval(n+1)+', \''+type+'\')', 25);
	} else if (type=='img') {
		if (img1.complete) {
			var i=document.getElementById('img1');
			i.src=img1.src;
			i.style.marginTop='';
		} else {
			setTimeout('tr_div('+eval(n)+', \''+type+'\')', 25);
		}
	}
}

function close_div() {
	var o_div=document.getElementById('show_div');
	if (o_div) o_div.parentNode.removeChild(o_div);
}

function show_div_result(txt) {
	var o_div_main=document.getElementById('show_div_main');
	o_div_main.style.textAlign='';
	o_div_main.innerHTML=txt;
}

function set_focus(obj_id) {
	var o=document.getElementById(obj_id);
	o.focus();
	o.focus();
}

function tab_menu_set() {
	if (/MSIE 6/i.test(navigator.userAgent)) document.getElementById('top_bkg').style.backgroundImage='url()';
	for (n=0; n<6; n++) {
		var o=document.getElementById('i'+eval(n+1));
		if (!o) continue;
		o.onmouseover=function () { this.style.backgroundPosition=''+eval(-125-(parseInt(this.id.substring(1, 2),10)-1)*200)+'px 0px'; };
		o.onmouseout=function () { this.style.backgroundPosition=''+eval(-25-(parseInt(this.id.substring(1, 2),10)-1)*200)+'px 0px'; };
	}
}

function tr(o, state) {
	if(typeof(o)=='string'){
		obj = document.getElementById(o);
		if (state==1) obj.className='active'; else obj.className='';
	}else if (state==1) o.className='active'; else o.className='';
}

function keypress_click(e, btn_id) {
	var keycode=0;
	if (e.keyCode) keycode=e.keyCode; else keycode=e.which;
	if (keycode==0x0d) document.getElementById(btn_id).click();
}

function f_focus(id) {
	var o=document.getElementById(id);
	if (o) {
		try { o.focus(); } catch (e) { }
	} else {
		setTimeout('f_focus(\''+id+'\')', 500);
	}
}

