var wersja = parseInt(navigator.appVersion);
var przegladarka=navigator.userAgent.toLowerCase();

var __ie3    = (__ie && (wersja < 4));
var __ie4    = (__ie && (wersja == 4) && (przegladarka.indexOf("msie 4") != -1) );
var __ie     = ((przegladarka.indexOf("msie") != -1) && (przegladarka.indexOf("opera") == -1));
var __ie5    = (__ie && (wersja == 4) && (przegladarka.indexOf("msie 5.0") != -1) );
var __ie5up  = (__ie && !__ie3 && !__ie4);
var __ie5_5  = (__ie && (wersja == 4) && (przegladarka.indexOf("msie 5.5") != -1));
var __ie6up  = (__ie && !__ie3 && !__ie4 && !__ie5 && !__ie5_5);

//nowe okienko
function noweOkno(url, nazwa, szerokosc, wysokosc) {
   _left = (screen.width) ? (screen.width - szerokosc) / 2 : 0;
   _top = (screen.height) ? (screen.height - wysokosc) / 2 : 0;
   window.open(url, nazwa, 'toolbar=0,location=0,directories=0,menubar=0,status=0,scrollbars=0,resizable=0,left='+_left+',top='+_top+',width='+szerokosc+',height='+wysokosc);
}



//nowe okienko ze zdjęciem
function noweOknoZdjecie(dane, nazwa, szerokosc, wysokosc) {
   noweOkno(dane, nazwa, szerokosc+10, wysokosc+80);
}


/* //nowe okienko ze zdjęciem
function noweOknoZdjecie(dane, nazwa, szerokosc, wysokosc) {
   noweOkno(dane, nazwa, szerokosc+10, wysokosc+80);
}*/

// obsluga select w celu dodanie ogloszenia
function js_dodaj(sesid){
  if(sesid != '')
    sesid = '?PHPSESSID='+sesid;
	window.location.href = "/"+document.frm.d_dodaj[document.frm.d_dodaj.selectedIndex].value+"_dodaj/"+sesid;
	return false;
}
function js_dodaj2(sesid){
  if(sesid != '')
    sesid = '?PHPSESSID='+sesid;
	window.location.href = "/"+document.frm2.d_dodaj[document.frm2.d_dodaj.selectedIndex].value+"_dodaj/"+sesid;
	return false;
}

// obsluga select w celu szukania ogloszenia
function js_szukaj(sesid){
  if(sesid != '')
    sesid = '?PHPSESSID='+sesid;
	window.location.href = "/"+document.frm.d_szukaj[document.frm.d_szukaj.selectedIndex].value+"/"+sesid;
	return false;
}
function js_szukaj3(sesid){
  if(sesid != '')
    sesid = '?PHPSESSID='+sesid;
	window.location.href = "/"+document.frm3.d_szukaj[document.frm3.d_szukaj.selectedIndex].value+"/"+sesid;
	return false;
}

function walidacja_mail(adres){
	wzor=/^[0-9a-zA-Z.]+\@[0-9a-zA-Z]+\.[0-9a-zA-Z.]+$/;
	if(adres!=null && wzor.test(adres)==true && adres.length!=0){
		return true;
	}else{
		if(adres!=null)
			alert("Błędny format adresu e-mail!");
		return false;
	}
}

function walidacja(_formularz, _polaFormularz) {
	// zawiera odwołanie do elementu
	var zmiennaElement = '';

	// sprawdzany czy pola s± wypełnione
	for(var i=0; i < _polaFormularz.length; i++){
		zmiennaElement = "_formularz.elements['" + _polaFormularz[i] +"']";
		if(eval(zmiennaElement + '.value') == ""){
			alert("Musisz wypełnić pole: " + _polaFormularz[i]);
			eval(zmiennaElement + '.focus()');
			eval(zmiennaElement + '.select()');
			return false;
		}
	}

	// blokujemy klawisz Submit, by nie mozna bylo dwokrotnie go wcisn±ć
	for(var i=0; i < _formularz.length; i++)
		if(_formularz[i].type == 'submit')
			_formularz.elements[i].disabled = true;

	return true;
}



licz=0;

function otworzOkno(nazwa,szer,wys) {
config='left=100,top=40,width='+szer+',height='+wys+',innerheight='+wys+',innerwidth='+szer+',toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no';
kitekSC='okno' + licz;
stadion=window.open('',kitekSC,config)
stadion.document.write('<html><head>');
stadion.document.write('<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-2">');
stadion.document.write('<TITLE>....</title>');
stadion.document.write('<script language="javascript">');
stadion.document.write('setTimeout(');
stadion.document.write('"self.close()');
stadion.document.write(';",70000)');stadion.document.write('</');
stadion.document.write('script>');
stadion.document.write('</HEAD>');
stadion.document.write('<body bgcolor=white leftmargin=0 topmargin=0 marginheight=0 marginwidth=0>');
stadion.document.write('<DIV align=center><a href=# onclick="javascript:self.close();"><img src='+nazwa+' border=0></A></DIV>');
stadion.document.write('</body></html>');
stadion.focus();
licz+=1;
//return true;
};


function zamien_znaki(tekst){



 return tekst.replace(/[±ę¶ćółńżĽ]/g,function(s){
return(s=='±'?'%C4%85':s=='ę'?'%C4%99':s=='¶'?'%C5%9B':s=='ć'?'%C4%87':
s=='ó'?'%C3%B3':s=='ł'?'%C5%82':s=='ń'?'%C5%84':s=='ż'?'%C5%BC':s=='Ľ'?'%C5%BA':'');});

}

// obsługa wyszukiwarek //
function szukaj_w_sieci(wyszukiwarka, tresc) {
	if(wyszukiwarka == 1){
		window.open("http://szukaj.wp.pl/szukaj.html?szukaj=" + tresc.toLowerCase()); return false;
	}
	if(wyszukiwarka == 2){
		window.open("http://szukaj.onet.pl/query.html?qt=" + tresc.toLowerCase()); return false;
	}
	if(wyszukiwarka == 3){
		window.open("http://szukaj.interia.pl/avp/query.html?sc=on&all=true&q=" + tresc.toLowerCase()); return false; 
	}
	if(wyszukiwarka == 4){
		window.open("http://www.google.pl/search?hl=pl&lr=lang_pl&btnG=Szukaj&q=" + zamien_znaki(tresc.toLowerCase())); return false;
	}
	if(wyszukiwarka == 5){
		window.open("http://www.altavista.com/web/results?itag=wrx&kgs=0&kls=0&q=" + zamien_znaki(tresc.toLowerCase())); return false;
	}
}  




/*
Script Name: Javascript Cookie Script
Author: Public Domain, with some modifications
Script Source URI: http://techpatterns.com/downloads/javascript_cookies.php
Version 1.1.0
Last Update: 24 August 2007

1.1.0 fixes a problem with Get_Cookie that did not correctly handle
cases where multiple cookies might test as the same, like: site1, site

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
*/

// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );

// To use, simple do: Get_Cookie('cookie_name'); 
// replace cookie_name with the real cookie name, '' are required
function Get_Cookie( check_name ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for ( i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
		// if the extracted name matches passed check_name
		if ( cookie_name == check_name )
		{
			b_cookie_found = true;
			cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found ) 
	{
		return null;
	}
}

/*
only the first 2 parameters are required, the cookie name, the cookie
value. Cookie time is in milliseconds, so the below expires will make the 
number you pass in the Set_Cookie function call the number of days the cookie
lasts, if you want it to be hours or minutes, just get rid of 24 and 60.

Generally you don't need to worry about domain, path or secure for most applications
so unless you need that, leave those parameters blank in the function call.
*/
function Set_Cookie( name, value, expires, path, domain, secure ) {
	// set time, it's in milliseconds
	var today = new Date();
	today.setTime( today.getTime() );
	// if the expires variable is set, make the correct expires time, the
	// current script below will set it for x number of days, to make it
	// for hours, delete * 24, for minutes, delete * 60 * 24
	if ( expires )
	{
		expires = expires * 1000 * 60 * 60 * 24;
	}
	//alert( 'today ' + today.toGMTString() );// this is for testing purpose only
	var expires_date = new Date( today.getTime() + (expires) );
	//alert('expires ' + expires_date.toGMTString());// this is for testing purposes only

	document.cookie = name + "=" +escape( value ) +
		( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + //expires.toGMTString()
		( ( path ) ? ";path=" + path : "" ) + 
		( ( domain ) ? ";domain=" + domain : "" ) +
		( ( secure ) ? ";secure" : "" );
}

// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
	if ( Get_Cookie( name ) ) document.cookie = name + "=" +
			( ( path ) ? ";path=" + path : "") +
			( ( domain ) ? ";domain=" + domain : "" ) +
			";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}

