var main_url='http://www.n-cat.pl/';

function $(id){
	return document.getElementById(id);
}

//-------------------------------------------
//
//-------------------------------------------
function nwin(page, x, y, scr)
{
 sx = screen.availWidth;
 sy = screen.availHeight;
 px = (sx/2)-(x/2);
 py = (sy/2)-(y/2);
 window.open(page,'','top='+py+',left='+px+',width='+x+',height='+y+'resizable=no,scrollbars='+scr+',status=yes');
 return;
}

//-------------------------------------------
//
//-------------------------------------------
function show_gmaps(){
	var src=main_url+'mapa.php?b=' + $('branza').value + '&s=' + $('slowo').value + '&u=' + $('ulica').value
	+ '&m=' + $('miasto').value + '&w=' + $('wojewodztwo').value;
	nwin(src,600,550,false);
	return false;
}

//-------------------------------------------
//
//-------------------------------------------
function show_gmaps_s(){
	
	var src=main_url+'mapa.php?b=' + $('s_branza').value + '&s=' + $('s_slowo').value + '&u=' + $('s_ulica').value
	+ '&m=' + $('s_miasto').value + '&w=' + $('s_wojewodztwo').value;
	nwin(src,600,550,false);
	return false;
}

//-------------------------------------------
//
//-------------------------------------------
function show_gmaps_a(){
	var src=main_url+'mapa.php?b=' + $('a_branza').value + '&s=' + $('a_slowo').value + '&u=' + $('a_ulica').value
	+ '&m=' + $('a_miasto').value + '&w=' + $('a_wojewodztwo').value
	+ '&o=' + $('a_opis').value + '&ct=' + $('a_telefon').value
	+ '&oe=' + $('a_email').value + '&ow=' + $('a_www').value
	+ '&oo=' + $('a_oferta').value + '&k=' + $('a_kod').value + '&n=' + $('a_nr_lokalu').value;
	nwin(src,600,550,false);
	return false;
}

function opener(url){
	window.opener.location=url;
	return false;	
}

//-------------------------------------------
//
//-------------------------------------------
function zliczaj(id_tekstarea, id_licznika, maksymalna){ 
 with(document.forms[0]) { 

  tekstarea=document.getElementById(id_tekstarea);
  var licznik=document.getElementById(id_licznika);
  var tekst = tekstarea.value; // cały text z pola textarea 
  var dl_tresc =tekstarea.value.length; // długoś tekstu z textarea 
  var prawdziwa = 0; // licznik znaków 
  var entery = 0; 

  for (i=0; i<dl_tresc; i++) { 
     if (tekst.charAt(i) == "\n") { 
       prawdziwa++; 
       entery++; 
       if (navigator.appName != "Netscape") i++; 
     } 
     prawdziwa++; 
  } // koniec for i 

licznik.innerHTML= maksymalna - prawdziwa; // wyświetl komunikat o licznie znaków 
if (prawdziwa>maksymalna) { 
    if (navigator.appName != "Netscape") 
      tekstarea.value = tekstarea.value.substring(0,maksymalna); 
    else 
	  tekstarea.value = tekstarea.value.substring(0,maksymalna-entery);
	  licznik.innerHTML=0;
//    alert("Maksymalna długość to " + maksymalna +"!"); 
}
} // koniec with 
}

//-------------------------------------------
//  Image select 
//-------------------------------------------
function change_select_image(imagedir,id_image,id_select) {
if (!document.images) return
	image=document.getElementById(id_image);
	select=document.getElementById(id_select);
	val=select.options[select.selectedIndex].value;
	idm=val.split('/')
	if (idm[1]==null) {
		image.src= imagedir + 'th_' + val;
	} else {
		image.src= imagedir + idm[0] + '/th_' + idm[1]		
	}
}

function change_select_full_image(imagedir,id_image,id_select) {
if (!document.images) return
	image=document.getElementById(id_image);
	select=document.getElementById(id_select);
	image.src= imagedir + select.options[select.selectedIndex].value
}

//-------------------------------------------
// Show Hide blok
//-------------------------------------------
function hide_show(rid) {
	document.getElementById(rid).style.display = document.getElementById(rid).style.display == 'none' ? 'block' : 'none'
}

//-------------------------------------------
// UBBC Code
//-------------------------------------------
// inicjacja edytora
// onload=function(){
// 	input_text=document.getElementById('tresc')
// }

stos=[];
T=[];
C=alert;
B=unescape;


function init_ubbc(id){
	input_text=document.getElementById(id)
}

function insert_tag(x){
	document.selection ? (input_text.focus(), document.selection.createRange().text=x)
	:(input_text.selectionStart || input_text.selectionStart=='0') 
	? input_text.value=input_text.value.substring(0,input_text.selectionStart) + x 
	+ input_text.value.substring( input_text.selectionEnd, input_text.value.length)
	:input_text.value +=x;
	input_text.focus()
}

function s(){
	return document.selection ? document.selection.createRange().text:input_text.value.substring(
	input_text.selectionEnd || 0, input_text.selectionStart || 0)
}



function set_tag(i,x){
	document.getElementById(i).value=i+x
}

function close_all_tag(e){
	while(stos[0]){
		insert_tag('[/'+(e=stos.pop())+']');
		T[e]=0;
		set_tag(e,'')
	}
}

function R(x){
	T[x] ? '' : T[x]=0;
	T[x] ? CT(x):(stos.push(x),T[x]=1,insert_tag('['+x+']'),set_tag(x,'*'))
}
	

function CT(x,a){T[a=stos.pop()]=0;
	insert_tag('[/'+a+']');
	set_tag(a,'');
	a!=x?CT(x):''
}

//
// Wywolania
//

function insert_code(x,z){
(z=s())?insert_tag('['+x+']'+z+'[/'+x+']'):R(x)
}

function select_to_code(l,t){
	insert_tag("["+t+"="+l.value+"]"+s()+"[/"+t+"]")
}

function list(x,li){
	x='[list]\n';
	do{li=prompt('Wpisz element listy (jesli chcesz zakonczyc dopisywanie do listy pozostaw pole puste lub kliknij \'Anuluj\'','');
		x+=li?'[*]'+li+'[/*]\n':''
	}
	while(li);
	insert_tag(x+'[/list]')
};

function url(u,d,z){
	insert_tag("[url="+(u=prompt("Podaj adres strony lub pliku","http://"))+"]"+(s()?s():((d=prompt("Opis odnosnika",""))?d:u))+"[/url]")
}

function img(z){
	insert_tag("[img]"+((z=s())?z:prompt("Podaj sciezke do grafiki","http://"))+"[/img]")
}

function qot(t){
	insert_tag("[quote"+((t=prompt('Podaj imie cytowanej osoby'))?"="+t:"")+"]"+s()+"[/quote]")
}

function hide(t){
	insert_tag("[hide"+((t=prompt('Tytuł bloku'))?"="+t:"")+"]"+s()+"[/hide]")
}


//-------------------------------------------
// Plywajaca lista
//-------------------------------------------
var ua = navigator.userAgent.toLowerCase();
var div_size_x=0;
var div_size_y=0;

if (document.getElementById || document.all)
	document.write('<div id="imgplywak_er" style="position:absolute;visibility:hidden;z-index:200;"></div>')

function getplywak_object()
	{
	if (document.getElementById)
		return document.getElementById("imgplywak_er")
	else if (document.all)
		return document.all.plywak_imagid
	}

function getplywak_obj()
	{
	if (document.getElementById)
		return document.getElementById("imgplywak_er").style
	else if (document.all)
		return document.all.plywak_imagid.style
	}

function truebody()
	{
	return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body
	}

function plywak_Off()
	{
	//document.onmousemove=getMouseXY;
	getplywak_obj().visibility="hidden";
	}

function plywak_On(title,text_html,size_x,size_y)
	{
	if(ua.indexOf('opera') == -1 && ua.indexOf('safari') == -1)
		{
		getplywak_obj().left="-500px";
		divsize_x = parseInt(size_x) + 2;
		getplywak_object().innerHTML = '<div class="blok1"><div class="blok1_title">'+title+'</div><div class="blok1_main">'+text_html+'</div></div>';
		getplywak_obj().visibility="visible";
		div_size_x = parseInt(size_x)+25;
		div_size_y = parseInt(size_y)+130;
		document.onmousemove=followmouse;
		}
	}

function followmouse(e)
	{
	var docwidth=document.all? truebody().scrollLeft+truebody().clientWidth : pageXOffset+window.innerWidth-15
	var docheight=document.all? Math.min(truebody().scrollHeight, truebody().clientHeight) : Math.min(document.body.offsetHeight, window.innerHeight)
if(typeof e != "undefined")
	{
		xcoord = 5+e.pageX;
		ycoord = 5+e.pageY;
		
	}
else if (typeof window.event != "undefined")
	{
		xcoord = truebody().scrollLeft+5+event.clientX;
		ycoord = truebody().scrollTop+5+event.clientY;
	}
	getplywak_obj().left=xcoord+"px"
	getplywak_obj().top=ycoord+"px"
	}


//
// Awatar w konfigu
//
function showimageavatar() {
if (!document.images) return
document.images.avatar.src=
	'./image/avatar/' + document.formregister.avatar.options[document.formregister.avatar.selectedIndex].value
}


//-----------------------------------------
// 4 xhtml -> external to blank
//-----------------------------------------

onload = function()
{
 for(var i = 0; i < document.links.length; ++i){
  if (document.links[i].rel == 'external'){
   document.links[i].target = '_blank';
  }
 }
}

