    // convert all characters to lowercase to simplify testing

    var agt=navigator.userAgent.toLowerCase();

    // *** BROWSER VERSION ***
    // Note: On IE5, these return 4, so use is_ie5up to detect IE5.
    var is_major = parseInt(navigator.appVersion);
    var is_minor = parseFloat(navigator.appVersion);

    var is_ie     = ((agt.indexOf("msie") != -1) && (agt.indexOf("opera") == -1));
    var is_ie3    = (is_ie && (is_major < 4));
    var is_ie4    = (is_ie && (is_major == 4) && (agt.indexOf("msie 4")!=-1) );
    var is_ie4up  = (is_ie && (is_major >= 4));
    var is_ie5    = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")!=-1) );
    var is_ie5_5  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.5") !=-1));
    var is_ie5up  = (is_ie && !is_ie3 && !is_ie4);
    var is_ie5_5up =(is_ie && !is_ie3 && !is_ie4 && !is_ie5);
    var is_ie6    = (is_ie && (is_major == 4) && (agt.indexOf("msie 6.")!=-1) );
    var is_ie6up  = (is_ie && !is_ie3 && !is_ie4 && !is_ie5 && !is_ie5_5);
    var is_opera = (window.opera)?true:false;
    var is_opera7 = (window.opera)?true:false;
    var is_gecko = (agt.indexOf('gecko') != -1);


if(document.all && !document.getElementById)
    document.getElementById = function(id) { return document.all[id]; }

if(document.all && !document.getElementsByTagName)
    document.getElementsByTagName = function(tag) { return document.all.tags(tag); }


var lo = 1;
function sof (a) {
	if (document.getElementById('foto' + lo)) document.getElementById('foto' + lo).style.display = 'none';
	document.getElementById('oferta' + lo).style.display = 'none';
	document.getElementById('lin' + lo).className = '';
	lo = a;
	if (document.getElementById('foto' + lo)) document.getElementById('foto' + lo).style.display = '';
	document.getElementById('oferta' + lo).style.display = '';
	document.getElementById('lin' + lo).className = 'selected';

}

function footReset() {
	f = document.getElementById('footer').style.position="relative";
	f = document.getElementById('footer').style.position="absolute";
	//alert('test');
	if (txtalert != '') {
		alert(txtalert);
		txtalert = '';
	}
}


function flash(name,src,x,y,ver,opcja) {
	

	if (opcja == 'w3c') {
		document.write ('<object id="'+name+'" type="application/x-shockwave-flash" data="'+src+'" width="'+x+'" height="'+y+'" >');
		document.write ('<param name="movie" value="'+src+'" >');
		document.write ('<param name="swliveconnect" value="true">');
		document.write ('</object>');
	}
	else {

		document.write ('<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"');
		document.write ('codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version='+ver+',0,0,0"');
		document.write ('width='+x+' height='+y+' id="'+name+'">');
		document.write ('<param name=movie value="'+src+'">');
		document.write ('<param name=quality value=high>');

		if (opcja == 'transparent') document.write ('<param name="wmode" value="transparent">');

		document.write ('<param name="swliveconnect" value="true">');
		document.write ('<embed src="'+src+'" quality="high" width="'+x+'" height="'+y+'"');
		document.write (' type="application/x-shockwave-flash"');
		document.write (' pluginspage="http://www.macromedia.com/downloads/"');
		document.write (' name="'+name+'" swliveconnect="true">');
		document.write ('</embed>');
		document.write ('</object>');
	}
}



var lastWin;
function setImg (imgSrc,reSize) {
	if (lastWin.jestem) {
		
		if (reSize == 1) {
			lastWin.document.body.innerHTML = '<img src="'+imgSrc+'" id="obrazek" onload="window.resizeTo(this.width + 10,this.height + 30);window.moveTo(20,20);" >'; 
			lastWin.focus();
		}
		else {
			lastWin.document.body.innerHTML = '<img src="'+imgSrc+'" id="obrazek" >'; 
		}
			
	}	
	else {
		setTimeout("setImg('"+imgSrc+"', '"+reSize+"')",100);
	}
}


function setSizeImg () {
	if (lastWin.document.getElementById('obrazek')) {

	//	lastWin.resizeTo(lastWin.document.getElementById('obrazek').width + 10,lastWin.document.getElementById('obrazek').height + 30);
	//	lastWin.moveTo(20,20); 
		alert(lastWin.document.getElementById('obrazek').src);
		lastWin.close(); 
		zoomImg(lastWin.document.getElementById('obrazek').src,lastWin.document.getElementById('obrazek').width,lastWin.document.getElementById('obrazek').height);
	}	
	else {
		setTimeout("setSizeImg()",100);
	}
}

// onload="window.resizeTo(this.width + 10,this.height + 30);window.moveTo(20,20);

function zoomImg(imgSrc,xSize,ySize) {
	reSize = 1;
	if (xSize && ySize) reSize = 0;
	if (!xSize) xSize=300;
	if (!ySize) ySize=300;
	scrollBary='no';
	xPos=20;
	lastWin = window.open('','Zoom', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollBary+',resizable=yes,fullscreen=no,channelmode=no,width='+xSize+',height='+ySize+',top=0,left='+xPos);
	
	setImg (imgSrc,reSize);
	void(0);
}
function zoom2(imgSrc) {
	lastWin = window.open('sdgsdgsd','zoomOkno','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,fullscreen=no,channelmode=no,width=300,height=300,top=0,left=150');

	void(0);
}

function oW (path,Xsiz,Ysiz,Xp,Yp,resi,scrollb) {
	if (path.indexOf('zoom.php') != -1) path = '/heuristic2/'+path;
	var przed = '';
	if (!(Xsiz > 0)) { Xsiz = 300; }
	if (!(Ysiz > 0)) { Ysiz = 300; }
	if (Xp == 'right') Xp = screen.width - 20 - Xsiz;
	if (!(Xp > 0)) { Xp = 30; }
	if (!(Yp > 0)) { Yp = 30; }
	if (resi == null) resi = 'yes';
	if (scrollb == null) scrollb = 'yes';
	var w = window.open(przed+path, 'fotozoom', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars='+scrollb+',resizable='+resi+',fullscreen=no,channelmode=no,width='+Xsiz+',height='+Ysiz+',top='+Yp+',left='+Xp);
	w.focus();
	void(0);
}

function el (id) {
        return document.getElementById(id);
}

function tf (txt,id) {
		if (el(id).value == '') {
	        alert(txt);
			el(id).focus();
			return false;
		}
		else return true;
}

function ts (txt,id) {
		if (el(id).selectedIndex == 0) {
	        alert(txt);
			el(id).focus();
			return false;
		}
		else return true;
}

function te (txt,id) {
		if (el(id).value != '' && el(id).match(/^.*\@.*\..*$/)==null) {
	        alert(txt);
			el(id).focus();
			return false;
		}
		else return true;
}

function tc (txt,id) {
		if (!(el(id).checked)) {
		
	        if (txt != '') { alert(txt); el(id).focus(); }
			return false;
		}
		else return true;
}



function pobierz(nazwa) {
    if (document.cookie.length > 0) {
        startc = document.cookie.indexOf(nazwa + "=");
        if (startc != -1) {
            startc += nazwa.length + 1;
            endc = document.cookie.indexOf(";", startc);
            if (endc == -1) {
                endc = document.cookie.length;
            }
            return unescape(document.cookie.substring(startc,endc));
        }
	return false;
    }
    return false;
}

function rejestruj(nazwa, wartosc,dni) {
    var dzisiaj=new Date();
    var wygasnie=new Date();
    !dni ?dni=7 :"";
    // dni - data po kt�rej ciastko traci wa?no?a (domy?lnie tydzien)
    // je?li dni==0 to wa?ne w ci1gu danej "sesji"
    wygasnie.setTime(dzisiaj.getTime()+1000*60*60*24*dni);
	document.cookie=nazwa+"="+escape(wartosc)+";expires="+wygasnie.toGMTString();
}

function sClear(obj,itxt) {
	if (obj.value == itxt) obj.value = '';
}
function sReturn(obj,itxt) {
	if (obj.value == '') obj.value = itxt;
}


// **************** MENU *******************

var activeSubMenu = false;
var timeOut = 1000;

$(document).ready(function(){
	$('#menu ul li a.menu').mouseover(function(){subMenu($(this).get(0), 1);});
	$('#menu ul li a.menu').mouseout(function(){subMenu($(this).get(0), 0);});
	$('#menu ul li ul.submenu').mouseover(function(){overMenu($(this).get(0));
							 if($(this).parent().attr('class') != 'selected')
							 {
							 	$(this).parent().addClass('selected2');
							 }});
	$('#menu ul li ul.submenu').mouseout(function(){outMenu($(this).get(0));
							if($(this).parent().attr('class') != 'selected')
							{
								$(this).parent().removeClass('selected2');
							}});
});

function subMenu(obj,show)
{
  if(obj.nextSibling)
  {
    if(obj.nextSibling.innerHTML)
    {
      activeSubMenu = t = obj.nextSibling;	

      if (show)
      {
	allul = document.getElementsByTagName('ul');
	for (a = 0; a < allul.length; ++a) if (allul[a].className == 'submenu') allul[a].style.visibility = 'hidden';
	t.style.visibility = 'visible';
      }
      else
      {
        activeSubMenu = false;
	setTimeout ("hideSubmenu(document.getElementById('"+t.id+"'))",timeOut);
      }
    }
  }
}

function hideSubmenu(t) {
	if (!activeSubMenu || activeSubMenu != t) t.style.visibility = 'hidden';
}

function overMenu(t) {
	activeSubMenu = t;
}

function outMenu(t) {
	activeSubMenu = false;
 	setTimeout ("hideSubmenu(document.getElementById('"+t.id+"'))",timeOut);
}

function addslashes(str) {
	str=str.replace(/\'/g,'\\\'');
	str=str.replace(/\"/g,'\\"');
	str=str.replace(/\\/g,'\\\\');
	str=str.replace(/\0/g,'\\0');
	return str;
}
function stripslashes(str) {
	str=str.replace(/\\'/g,'\'');
	str=str.replace(/\\"/g,'"');
	str=str.replace(/\\\\/g,'\\');
	str=str.replace(/\\0/g,'\0');
	return str;
}

function emailValid(t,im,em) {
	
	var imie = document.getElementById('newsImieF');
	var mail = document.getElementById('newsEmailF');
	var er = document.getElementById('newsEmailI');
	
	try{
	if (!imie.value) {
		er.innerHTML = im;
		mail.focus(); 
		mail.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	else {
		if (mail.value.indexOf('@',0) == -1 || mail.value.indexOf('.',0) == -1){
			er.innerHTML = em;
			mail.focus(); 
			mail.parentNode.parentNode.className = 'alertRow';
			return false;
		}
	}
	}
	catch(e){}
}

function emailPassValid(t,g) {
	
	var email = document.getElementById('emailF');
	var eror = document.getElementById('emailI');
	
	try{
	if (email.value.indexOf('@',0) == -1 || email.value.indexOf('.',0) == -1){
		eror.innerHTML = g;
		email.focus(); 
		email.parentNode.parentNode.className = 'alertRow';
		return false;
	}
	}catch(e){}
}


function prints(a) {


	var links = document.location.href;
	if(links.indexOf('#') != -1) {
		links=document.location.href.substring(0,links.indexOf('#'));

	}

	if(links[links.length-1] != '/') {
		links = links+'&print=1';
	}
	else {
		links = links+'page.php?print=1';
	}

	oW(links,740,740);

}


// **************** JQUERY *******************

$(document).ready( function(){

	// mp3 player
        $('img.actItemMp3').each(function(){

               if (this.alt != '') {
                       $(this).after('<object type="application/x-shockwave-flash" style="width: ' + this.width + 'px; height:' + this.height + 'px;" data="/mp3player.swf?mp3file=' + this.alt + '&txt=' + this.title + '"><param name="movie" value="/mp3player.swf?mp3file=' + this.alt + '&txt=' + this.title + '"/><param name="wmode" value="transparent" /></object>');
               }
        });
        $('img.actItemMp3').remove();


	// youtube player
        $('img.actItemYoutube').each(function(){

		if (this.alt != '') {
			$(this).after('<object type="application/x-shockwave-flash" style="width: ' + this.width + 'px; height:' + this.height + 'px;" data="' + this.alt + '"><param name="movie" value="' + this.alt + '" /><param name="wmode" value="transparent" /></object>');
		}		
	});
	$('img.actItemYoutube').remove();


	// last gallery
	//$('.last_gallery').cycle({fx: 'fade',
	//	                       speed: 300,
	//        	               timeout: 5000});


	// colorbox init
	$("a.colorbox").colorbox({opacity:0.8,title:function(){return $(this).attr('name');}});

	$(".blad").colorbox({width:"440px", height:"280px", iframe:true}); 

	// search pages
	$('#searchform .searchsitebtn').click(function(){
		if ($('#searchform .searchsiteedit').attr('value').match(/^[0-9a-zA-ZąćęłńóśźżĄĆĘŁŃÓŚŹŻ\_\-\ ]{0,}$/)) {
			window.location.href = $('#searchform').attr('action') + '/q,' + $('#searchform .searchsiteedit').attr('value') + '.html';
		}
		else {
			alert($('#badquery').attr('value'));
		}
		return false; 
	});


	$('.reminder').click(function(){

		$('#reminder').show();
		$('#remindermarg').show();
		return false;
		
	});

	$('#remindermarg .close').click(function(){

		$('#reminder').hide();
		$('#remindermarg').hide();
		return false;
		
	});

	$(".sm_button").colorbox({width:"400px", inline:true, href:"#send_message", onLoad:function(){
		var id=$(this).attr('id').split('_');
		var id=id[1];
        	$("#smid").val(id);
   	}
	});

	$("#inbox_zak1").click(function(){
		$("#sinbox_zak2").css('display','none');
		$("#sinbox_zak1").css('display','block');
		$("#inbox_zak2").css('font-weight','normal');
		$(this).css('font-weight','bold');
		return false;
	});
	$("#inbox_zak2").click(function(){
		$("#sinbox_zak1").css('display','none');
		$("#sinbox_zak2").css('display','block');
		$("#inbox_zak1").css('font-weight','normal');
		$(this).css('font-weight','bold');
		return false;
	});

	$('.fotoDel').click(function() {
		delRet = confirm('Czy na pewno chcesz usunąć to zdjecie?'); 
		if(delRet)
		{
			window.location='/services/foto_delete.php?id='+$(this).attr('tag');
		}
	});

	$('.blockDel').click(function() {
		delRet = confirm('Czy na pewno chcesz oblokować użytkownika?'); 
		if(delRet)
		{
			window.location='/services/block.php?idt='+$(this).attr('tag');
		}
	});

	$('.friendsDel').click(function() {
		delRet = confirm('Czy na pewno chcesz usunąć z  listy znajomych?'); 
		if(delRet)
		{
			window.location='/services/friends.php?idt='+$(this).attr('tag');
		}
	});

	$('.fotoMain').click(function() {
		window.location='/services/foto_setmain.php?id='+$(this).attr('tag');
	});



	


	$('#list_actb').toggle(function() {
	  $('#list_act').css('overflow','visible');
		$(this).text('ukryj');
	}, function() {
	 $('#list_act').css('overflow','hidden');
	$(this).text('pokaż wiecęj');
	});

	/*************** ludzie - wyszukiwarka mala**********************/

	$("#fs5btn2").click(function(){
	//var fq5 = $("#fq5").val().replace(/[\.,\/]/g,'');
	var fq3 = $("#fq3").val().replace(/[\.,\/]/g,'');
	var fq0 = $("#fq0").val();
	var fq7 = $("#fq7").val();
	var fq8 = $("#fq8").val();
	var fq00 = fq0 - fq7;
	var fq01 = fq0 - fq8;
	var fq6 ='';
	//var fq6 = $("#fq6").val();
	//var fq4 = $("#fq6").val();
	if ($('#fq6').is(':checked')){
		fq6 = 2;
	}
	if ($('#fq4').is(':checked')){
		fq6 = 1;
	}

	var fq9 = $("#fq9").val();
	//alert('kliksks '+fq6+fq7+fq9);
	if (fq7 == fq8 && fq7 < 1 && fq8 < 1){
	window.location=fq9+'/eq-gender,'+fq6+',query-city,'+fq3+'.html';
}
else{
	window.location=fq9+'/eq-gender,'+fq6+',gteq-dt_birth,'+fq00+',lteq-dt_birth,'+fq01+',query-city,'+fq3+'.html';
}
	return false;
	});



/*************** ludzie - wyszukiwarka zaawansowana **********************/

	$("#fs5btn3").click(function(){
	//var fq5 = $("#fq5").val().replace(/[\.,\/]/g,'');
	var fq3 = $("#fq3").val().replace(/[\.,\/]/g,'');
	var fq12 = $("#fq12").val().replace(/[\.,\/]/g,'');
	var fq0 = $("#fq0").val();
	var fq22 = $("#fq22").val();
	var fq7 = $("#fq7").val();
	var fq8 = $("#fq8").val();
	var fq24 = $("#fq24").val();
	var fq00 = fq0 - fq7;
	var fq01 = fq0 - fq8;
	var fq6 ='';
	//var fq6 = $("#fq6").val();
	//var fq4 = $("#fq6").val();
	if ($('#fq6').is(':checked')){
		fq6 = 2;
	}
	if ($('#fq4').is(':checked')){
		fq6 = 1;
	}

	var fq9 = $("#fq9").val();

	if ( fq24 > 0)
	{
		window.location=fq9+'/'+fq24;
	
	} else{
	if ( fq8 == '' && fq7 == ''){
		window.location=fq9+'/eq-gender,'+fq6+',query-city,'+fq3+',query-name,'+fq12+',eq-woj,'+fq22+'.html';
	
	}
	else if ( fq7 == ''){
		window.location=fq9+'/eq-gender,'+fq6+',lteq-dt_birth,'+fq01+',query-city,'+fq3+',query-name,'+fq12+',eq-woj,'+fq22+'.html';
	
	}
	else
	if ( fq8 == ''){
		window.location=fq9+'/eq-gender,'+fq6+',gteq-dt_birth,'+fq00+',query-city,'+fq3+',query-name,'+fq12+',eq-woj,'+fq22+'.html';
	
	}
	else{
		//alert('kliksks '+fq6+fq7+fq9);
		window.location=fq9+'/eq-gender,'+fq6+',gteq-dt_birth,'+fq00+',lteq-dt_birth,'+fq01+',query-city,'+fq3+',query-name,'+fq12+',eq-woj,'+fq22+'.html';
	}
}
return false;
	});




$('#sonda_form').submit(function() {
		$('#_sonda_ajax').css('display', 'block');
		var tmpsel=0;

		//alert($('#sonda_form').find('[name=vote]').val());
			$('#sonda_form').find('[name=vote]').each(function() {
				if($(this).attr('checked'))
				{
					tmpsel=$(this).val();
				}
			});

		$.get('/page.php', {akcja:$('#sonda_form').find('[name=akcja]').val(), cat:$('#sonda_form').find('[name=cat]').val(), sondaID:$('#sonda_form').find('[name=sondaID]').val(), vote:tmpsel, nobox:'1', sid:$('#sonda_form').find('[name=_bid]').val()  }, function(data) {
		
			$('#'+$('#sonda_form').find('[name=bid]').val()).html(data);
					//alert(data);
		});

		return false;

	});


});





$(document).ready(function() {

	$('.bigpager_frame').cycle({
		fx:	'fade', 
		speed:       200,
		timeout:     2000,
		pager:      '.bp_pager',
		pagerEvent: 'mouseover'
	});

	$('.bp_pager a').click(function() {
		return false;
	});



});

function getminical(objclass, cat, year, month) {
	$('.'+objclass+' .preloader').height(parseInt($('.'+objclass).parent().height()) + parseInt($('.'+objclass).parent().css('padding-top')));
	$('.'+objclass+' .preloader').css('visibility','visible');

        $.ajax({
        	url: '/page.php',
		data: "cat="+cat+"&year="+year+"&month="+month,
        	type: "GET",
        	success: function(html){
			$('.'+objclass+' .preloader').css('visibility','hidden');

			$('.'+objclass).remove();
			$('.calendar').append(html);

			
		}
        });
}


// dodawanie wydarzenia 
$(document).ready(function(){
	$("#eventyear").change(function () {
		var str = "";
		$("#eventyear option:selected").each(function () {
			str += $(this).text() + " ";
		});
		$("#eventyeardiv").text(str);
		})
	.trigger('change');


	$("#eventmonth").change(function () {
		var str = "";
		$("#eventmonth option:selected").each(function () {
			str += $(this).text() + " ";
		});
		$("#eventmonthdiv").text(str);
		})
	.trigger('change');


	$("#eventday").change(function () {
		var str = "";
		$("#eventday option:selected").each(function () {
			str += $(this).text() + " ";
		});
		$("#eventdaydiv").text(str);
		})
	.trigger('change');


	$("#eventhour").change(function () {
		var str = "";
		$("#eventhour option:selected").each(function () {
			str += $(this).text() + " ";
		});
		$("#eventhourdiv").text(str);
		})
	.trigger('change');


	$("#eventminute").change(function () {
		var str = "";
		$("#eventminute option:selected").each(function () {
			str += $(this).text() + " ";
		});
		$("#eventminutediv").text(str);
		})
	.trigger('change');


	$("#eventtyp").change(function () {
		var str = "";
		$("#eventtyp option:selected").each(function () {
			str += $(this).text() + " ";
		});
		$(".eventtypdiv").text(str);
		})
	.trigger('change');


	// nazwa obrazu - wydarzenia
	$('.eventchoicefile .eventnoselname').change(function(){
		var war = $(this).val();
		war = war.match(/[-_\w]+[.][\w]+$/i)[0];
		$(this).parent().find('.eventselname').val(war);
		$(this).parent().find('.eventselname').css('right','0');
	});



	// checkboxy i radiobuttony formularzy
	$('#dbcformFperm').change(function(){
		if($(this).is(':checked')) {
			$(this).parent().css('backgroundPosition', '0% 0%');
		}
		else{
			$(this).parent().css('backgroundPosition', '0% 100%');
		}
	});

	$('#fq4').change(function(){
		if($(this).is(':checked')) {
			$('.fq4').css('backgroundPosition', '0% 100%');
			$('.fq6').css('backgroundPosition', '0% 0%');
		}
		else{
			$('.fq4').css('backgroundPosition', '0% 0%');
			$('.fq6').css('backgroundPosition', '0% 100%');
		}
	});

	$('#fq6').change(function(){
		if($(this).is(':checked')) {
			$('.fq6').css('backgroundPosition', '0% 100%');
			$('.fq4').css('backgroundPosition', '0% 0%');
		}
		else{
			$('.fq6').css('backgroundPosition', '0% 0%');
			$('.fq4').css('backgroundPosition', '0% 100%');
		}
	});


	$('.deleventfile').click(function(){
		//$('#e'+$(this).attr("id")).css('display','none');
		$('#e'+$(this).attr("id")).html("");
		return false;
	});


	// sparawdzanie czy user jest pełnoletni
	$('.DatePickerBtn, .DatePickerBtnSelect').live('click', function(){

		$('#dbformFdt_birth').parent().next().text('');	

		var db = $('#dbformFdt_birth').val();

		var dzi = db.substr(0,2);
		var mie = db.substr(3,2)-1;
		var rok = db.substr(6,4);

		var wybrana = new Date(rok, mie, dzi);
		var obecna  = new Date();
		var roznica = obecna.getTime() - wybrana.getTime();
		var ilelat  = Math.floor(roznica/1000/60/60/24/365);

		if(ilelat < 18){
			$('#dbformFdt_birth').val('');
			$('#dbformFdt_birth').parent().next().html('Min. 18&nbsp;lat');	
		}
		
	});

	$('form').submit(function(){
		var wiek = $('#dbformFdt_birth', this).parent().next().text();
		if(wiek != '') return false;
	});

});

function pokazInput(){
	$('#listinputfile').children().each(function() {
		var atryb = $(this).attr('style');
		//alert(atryb);
		if(atryb){
			$(this).removeAttr('style');
			return false;
		}
	});

}
