function param(id) {if(gtsp(id)) {return (gtsp(id).innerHTML.indexOf('<param')!=-1 || gtsp(id).innerHTML.indexOf('<PARAM')!=-1 || gtsp(id).innerHTML.indexOf('<A')!=-1 || gtsp(id).innerHTML.indexOf('<a')!=-1);}}

function D22D(id){D2D('t'+id,'r'+id)}
function D2D(d1id,d2id){if(gtsp(d2id)){vtmp=gtsp(d1id).innerHTML;gtsp(d1id).innerHTML='';el(d2id,'none');gtsp(d2id).innerHTML=vtmp;ObjReplace(d2id);el(d2id,'');}}



function gtsp(id){get=document.getElementById(id); return get}
function el(id,dis){
    if(gtsp(id)) gtsp(id).style.display=dis
}
function zapal(id)        {
	gtsp(id).className="menu_gif_r on";
}
function zgas(id)        {
	gtsp(id).className="menu_gif_r off";
}

function ONW(str_url,sz,wy){str_param="width="+sz+",height="+wy+",top="+((screen.availHeight-wy)/2)+",left="+((screen.availWidth-sz)/2)+",location=0,menubar=0,resizable=1,scrollbars=1";nokn=window.open(str_url,null,str_param);if(nokn) nokn.focus();}

function checkPlatSMS(obj)	{
	if(obj.options[obj.selectedIndex].value==102)	{
		gtsp("kwota").disabled=true;
		el("kwota","none");
		gtsp("kwota2").disabled=false;
		el("kwota2","");
	}	else	{
		gtsp("kwota").disabled=false;
		el("kwota","");
		gtsp("kwota2").disabled=true;
		el("kwota2","none");
	}
}

function moj_zapal(ob0,ob1,ob2,ob3,ob4) {
	if(ob0.checked==true){
		document.getElementById(ob1).style.visibility='hidden';
		document.getElementById(ob2).style.visibility='hidden';
		document.getElementById(ob3).style.display='';
		document.getElementById(ob4).style.display='none';
	}else{
		document.getElementById(ob1).style.visibility='';
		document.getElementById(ob2).style.visibility='';
		document.getElementById(ob3).style.display='none';
		document.getElementById(ob4).style.display='';
	}
}

if(typeof($) != "undefined")	{
	$(function() {                  
	  $("div.lista_firm_logo a > img").lazyload({
	     placeholder : "layout_images/nowydom/ajax.gif",
	     effect      : "fadeIn"
	  });
	});




var klik=0;

function przechwyc(e) {

	var kod = (window.event) ? window.event.keyCode : e.which;
	
	if($("#search_help_content_s").css("display") == "block" && (kod == 40 || kod == 38 || kod == 13))
	{
		self.klik=1;
		var i=0;
		var poz=$("#li_search li");
		var ile=poz.length;
		var zaznaczone=-1;
		for(i=0;i<ile;i++)
		{
			if($(poz[i]).hasClass("search_selected") && kod != 13)
			{
				zaznaczone=i;
				$(poz[i]).removeClass("search_selected");
			}
		}
		
		//zaznaczanie wyniku
		if(kod == 40 && (zaznaczone+1) >= ile )
			$(poz[zaznaczone]).addClass("search_selected");
		else if(kod == 40 && zaznaczone < ile)
			$(poz[(zaznaczone+1)]).addClass("search_selected");
		else if(kod == 38 && zaznaczone <= 0 )
			$(poz[0]).addClass("search_selected");
		else if(kod == 38 && zaznaczone > 0)
			$(poz[(zaznaczone-1)]).addClass("search_selected");
		else if(kod == 13)
		{
			var poz2=$("#li_search li.search_selected a").attr("href");
			if(poz2)
			{
				window.location=poz2;
			}
		}
		return false;
	}
	else if($("#search_help_typ").css("display") == "block" && (kod == 40 || kod == 38 || kod == 13))
	{
		self.klik=1;
		var i=0;
		var poz=$("#search_help_typ ul li a");
		var ile=poz.length;
		var zaznaczone=-1;
		for(i=0;i<ile;i++)
		{
			if($(poz[i]).hasClass("hov") && kod != 13)
			{
				zaznaczone=i;
				$(poz[i]).removeClass("hov");
			}
		}
		
		//zaznaczanie wyniku
		if(kod == 40 && (zaznaczone+1) >= ile )
			$(poz[zaznaczone]).addClass("hov");
		else if(kod == 40 && zaznaczone < ile)
			$(poz[(zaznaczone+1)]).addClass("hov");
		else if(kod == 38 && zaznaczone <= 0 )
			$(poz[0]).addClass("hov");
		else if(kod == 38 && zaznaczone > 0)
			$(poz[(zaznaczone-1)]).addClass("hov");
		else if(kod == 13)
		{
			var tp=$("#search_help_typ ul li a.hov").attr("class");
			var typ=tp.replace("hov", "");
			typ=typ.replace(" ", "");
			select_search(typ);
		}
		return false;
	}
	else
	{
		self.klik=0;
	}
}

var wygas=0;
var wygas2=0;
function wygas_div()
{
	if(self.wygas == 1)
	{
		$('#search_help_content_s').hide();
		$('#search_help_content_s').html("");
	}
}

function wygas_div2()
{
	if(self.wygas2 == 1)
	{
		$('#search_help_typ').hide();
		$("#head_strzalka").removeClass("strzalka_gora");
		$("#head_strzalka").addClass("strzalka_dol");
	}
}


function check_wysokosc(typ)
{
	if(typ == "index")
	{
		var inc=$("#r750x100").html();
		if(inc && inc.length > 50)
		{
			if(readCookie('moj_logedin'))
			{
				$("#search_help_content_s").css("top", "-325px");
				$("#search_help_typ").css("top", "-325px");
			}
			else
			{
				$("#search_help_content_s").css("top", "-295px");
				$("#search_help_typ").css("top", "-295px");
			}
		}
		else if(readCookie('moj_logedin'))
		{
			$("#search_help_content_s").css("top", "-105px");
			$("#search_help_typ").css("top", "-105px");
		}


		if(readCookie('moj_logedin'))
		{
			$("#search_help_content_s").css("top", "-170px");
			$("#search_help_typ").css("top", "-170px");
		}
	}
	else if(typ == "detail")
	{
		$("#search_help_content_s").css("top", "-93px");
		if(readCookie('moj_logedin'))
		{
			$("#search_help_content_s").css("top", "-124px");
			$("#search_help_typ").css("top", "-124px");
		}
	}
}


$(document).ready(
	function() {


$('#search_help_typ').mouseenter(function(){
	self.wygas2=0;
}).mouseleave(function(){
	self.wygas2=1;
	setTimeout("wygas_div2()",1000);
});


$('#search_help_typ li a').mouseenter(function(){
	$(this).addClass("hov");
}).mouseleave(function(){
	$(this).removeClass("hov");
});


$('#head_search').mouseleave(function(){
	self.wygas2=1;
	setTimeout("wygas_div2()",1000);
});

$('#search_help_input_s').click(function(){
	if($('#search_help_input_s').val() == 'Nazwa firmy...')
		$('#search_help_input_s').val("");
	
	$('#search_help_input_s').attr("class", "inp_white");
});

$('#search_help_content_s').mouseenter(function(){
	self.wygas=0;
}).mouseleave(function(){
	self.wygas=1;
	setTimeout("wygas_div()",1000);
});

$("#search_help_input_s").keyup(function()	{
	if(!self.klik && ($("#search_type").val() == 'projekty' || $("#search_type").val() == 'dom_pl'))
		search_help_delay_s(this);
});	
self.search_help_active=0;
$("#search_help_input_s").blur(function()	{
	var value = jQuery.trim(this.value);
	clearTimeout(self.search_help_time);
	if(value.length && $("#search_type").val() == 'projekty' || $("#search_type").val() == 'dom_pl')	{
		//alert(parent.top.search_help_active);	
		if(!self.search_help_active && klik == 0)	{
			$("#search_help_content_s").html("");
			$("#search_help_content_s").hide();	
		}
	}
});
document.onkeydown = przechwyc;


	reload_aktywnosc();
	setInterval("reload_aktywnosc()", 30000);

		if(readCookie("moj_logedin") == 1)	{
		$("#div_moj").load("/get_menu.php",{},function() {
			$('#link_moj').attr('href','http://moj.dom.pl/' +  readCookie('moj_logedin_username') + '/');	
			TB_init();
		});
	}
			$("#div_moj").load("/get_menu.php", {}, function(){
				$('#search_help_content2').css('top', '-92px');
				$('#link_moj').attr('href', 'http://moj.dom.pl/' + readCookie('moj_logedin_username') + '/');
				TB_init();
			});
	}
);	
}

function zapal_check()
{
	var ile=0;
	var objs=document.getElementsByTagName('input');
	for(i=0;i<objs.length;i++)
	{
		if(objs[i].name=="tem_kat[]" && objs[i].disabled)
		{
			objs[i].disabled = false;
		}
	}
}

function zgas_check()
{
//	alert("Możesz zaznaczyć tylko 3 kategorie tematyczne");
	var ile=0;
	var objs=document.getElementsByTagName('input');
	for(i=0;i<objs.length;i++)
	{
		if(objs[i].name=="tem_kat[]" && !objs[i].checked)
		{
			objs[i].disabled = true;
		}
	}
}
function check_sprawdz()
{
	var ile=0;
	var objs=document.getElementsByTagName('input');
	for(i=0;i<objs.length;i++)
	{
		if(objs[i].name=="tem_kat[]" &&objs[i].checked)
		{
			ile=parseInt(ile+1);
		}
	}
	if(ile >= 3)	
	{
		zgas_check();
	}
	else
	{
		zapal_check();
	}
}
window.onload=function()	{
check_sprawdz();
}

function readCookie(name) {
    var nameEQ = name + "=";var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++) {
        var c = ca[i];
	while (c.charAt(0)==' ') c = c.substring(1,c.length);
	    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
}

function ajaxFunction(url,params,met,akcja,ret){
	var ajaxRequest;  // The variable that makes Ajax possible!
	
	try{
		// Opera 8.0+, Firefox, Safari
		ajaxRequest = new XMLHttpRequest();
		if (ajaxRequest.overrideMimeType) { 
            ajaxRequest.overrideMimeType('text/xml; charset=utf-8'); 
		} 
	} catch (e){
		// Internet Explorer Browsers
		try{
			ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
		} catch (e) {
			try{
				ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
			} catch (e){
				// Something went wrong
				alert("Twoja przeglądarka zawiodła!");
				return false;
			}
		}
	}
	if(met=='post')	{
		ajaxRequest.open("POST", url, true);
	
		//Send the proper header information along with the request
		ajaxRequest.setRequestHeader("Content-type", "application/x-www-form-urlencoded;");
		ajaxRequest.setRequestHeader("Content-length", params.length);
		ajaxRequest.setRequestHeader("Connection", "close"); 
	
	}
	// Create a function that will receive data sent from the server
	ajaxRequest.onreadystatechange = function(){
		if(ajaxRequest.readyState == 4){
			if(ret)	{
				wynik=ajaxRequest.responseXML;
				eval(akcja);	
			}	else	{
				wynik=ajaxRequest.responseText;
				setTimeout('eval("'+akcja+'")',800);
			}
		}
	}
	if(met=='get')	{
		ajaxRequest.open("GET", url+'?'+params, true);
		ajaxRequest.send(null);
	}
	if(met=='post')	{
		ajaxRequest.send(params); 
	}
}

/* moj.dom.pl - ulubione */
function moj_ulubione(ad_id) {
	var search_url=location.protocol+"//"+location.host+"/moj_ulubione.php";
	var search_string="ad_id="+ad_id;
	var akcja="do_moj_ulubione(wynik)";
	ajaxFunction(search_url,search_string,'get',akcja);
}

function do_moj_ulubione(kom)	{
	var zalogowany_moj=readCookie('moj_logedin');
	if(zalogowany_moj)	{
		if(kom==1)	{
			alert("Zapisano do ulubionych!");
		}	else	{
			alert("Błąd zapisu. Spróbuj jeszcze raz!");
		}
	}	else	{
		window.location="http://moj.dom.pl/user_home.php?"+kom;	
	}
	
}
/*dopisane z moj.dom.pl*/

TB_WIDTH = 0;
TB_HEIGHT = 0;

var TB_doneOnce = 0;
var TB_ready = false;
var TB_useReady = true;


// add smoothbox to href elements that have a class of .smoothbox
function TB_init()
{
  TB_ready = true;
	$("a.smoothbox").each(function(el){el.onclick=TB_bind});
}

//window.addEvent('domready', TB_init);
//window.addEvent('load', TB_init);



function TB_bind(event)
{
  if( TB_useReady && !TB_ready ) return;
  
	var event = new Event(event);
	// stop default behaviour
	event.preventDefault();
	// remove click border
	this.blur();
	// get caption: either title or name attribute
	var caption = this.title || this.name || "";
	// get rel attribute for image groups
	var group = this.rel || false;
	// display the box for the elements href
	TB_show(caption, this.href, group);
    this.onclick = TB_bind;
    return false;
}

// called when the user clicks on a smoothbox link
function TB_show(caption, url, rel, loading, disable_close)
{
  if( TB_useReady && !TB_ready ) return;
  
  // set default closing mechanism
  if(!disable_close) { disable_close = 0; }

  // create iframe, overlay and box if non-existent
  if (!$("#TB_overlay").length)
  {
  	if($('#smoothbox_container').length)
    	$(document.createElement('div')).attr('id', 'TB_overlay').appendTo($('#smoothbox_container'));
    else
    	$(document.createElement('div')).attr('id', 'TB_overlay').appendTo(document.body);
    $('#TB_overlay').css('opacity','0.6');
    TB_overlaySize();
  }

  if (!$("#TB_window").length)
  {
  	if($('#smoothbox_container').length)
    	$(document.createElement('div')).attr('id', 'TB_window').appendTo($('#smoothbox_container'));
    else
    	$(document.createElement('div')).attr('id', 'TB_window').appendTo(document.body);
    $('#TB_window').css('display','none');
  	
  }
  else 
  {
    $('#TB_window').remove(); //$('TB_window').dispose();
   	if($('#smoothbox_container').length)
    	$(document.createElement('div')).attr('id', 'TB_window').appendTo($('#smoothbox_container'));
    else
    	$(document.createElement('div')).attr('id', 'TB_window').appendTo(document.body);
    //$('#TB_window').css('opacity','0');
  }
 
  if(disable_close == 0) { $("#TB_overlay").click( function () { TB_remove()}); } else { $("#TB_overlay").click(); }
  window.onscroll = TB_position;
 
  // check if a query string is involved
  var baseURL = url.match(/(.+)?/)[1] || url;
  
  // CODE TO SHOW IFRAME
  var queryString = url.match(/\?(.+)/)[1];
  var params = TB_parseQuery(queryString);

  TB_WIDTH = (params['width'] * 1) + 30;
  TB_HEIGHT = (params['height'] * 1) + 40;
  
  var ajaxContentW = TB_WIDTH - 30, ajaxContentH = TB_HEIGHT - 45;
  
  
  if (url.indexOf('TB_iframe') != -1)
  {
    urlNoQuery = url.split('TB_');
    $("#TB_window").html($("#TB_window").html() + "<div id='TB_title'><div id='TB_ajaxWindowTitle'>" + caption + "</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton' title='Close'>X</a></div></div><iframe frameborder='0' hspace='0' src='" + urlNoQuery[0] + "&in_smoothbox=true' id='TB_iframeContent' name='TB_iframeContent' scrolling='auto' style='width:" + (ajaxContentW + 29) + "px;height:" + (ajaxContentH + 17) + "px;' onload='TB_showWindow()'> </iframe>");
  }
  else
  {
    $("#TB_window").html($("#TB_window").html() + "<div id='TB_title'><div id='TB_ajaxWindowTitle'>" + caption + "</div><div id='TB_closeAjaxWindow'><a href='#' id='TB_closeWindowButton'>X</a></div></div><div id='TB_ajaxContent' style='width:" + ajaxContentW + "px;height:" + ajaxContentH + "px;'></div>");
  }
  
  $("#TB_closeWindowButton").click(function () {TB_remove()});

  if (url.indexOf('TB_inline') != -1)
  {
    $("#TB_ajaxContent").html($(params['inlineId']).html());
    TB_position();
    TB_showWindow();
  }
  else if (url.indexOf('TB_iframe') != -1)
  {
    //alert("UHOH1");
    TB_position();
    if (frames['TB_iframeContent'] == undefined) {//be nice to safari
      $(document).keyup(function(e){
                    var key = e.keyCode;
                    if (key == 27) {
                        TB_remove()
                    }
      });
      TB_showWindow();
    }
  }
  else
  {
    //alert("UHOH2");
    var handlerFunc = function(){
          TB_position();
          TB_showWindow();
    };
    new Request.HTML({
      method: 'get',
      update: $("#TB_ajaxContent"),
      onComplete: handlerFunc
    }).get(url);
  }

  window.onresize = function()
  {
    TB_position();
    TB_overlaySize();
  }

  document.onkeyup = function(event)
  {
    var event = new Event(event);
    if (event.code == 27) { // close
        TB_remove();
    }
  }

}

//helper functions below

function TB_showWindow()
{
  if( TB_useReady && !TB_ready ) return;
  
  if (TB_doneOnce == 0) {
     TB_doneOnce = 1;
      
      $('#TB_window').fadeIn(1000);
  }
  else {
      $('#TB_window').css('opacity', '1');
  }
//  $('TB_window').setStyle('opacity', 1);
}

function TB_remove()
{
  if( TB_useReady && !TB_ready ) return;
  
  //$("#TB_overlay").click();
  document.onkeyup = null;
  document.onkeydown = null;
  
//  if ($('#TB_closeWindowButton')) 
//     $("#TB_closeWindowButton").click();

  $('#TB_window').fadeOut(250, function(){
  	$('#TB_window').remove(); //$('TB_window').dispose();
  });
  
  $('#TB_overlay').fadeOut(400, function(){
  	$('#TB_overlay').remove(); //$('TB_overlay').dispose();
  });
  
  window.onscroll = null;
  window.onresize = null;
  TB_init();
  TB_doneOnce = 0;
  return false;
}

function TB_position()
{
  if( TB_useReady && !TB_ready ) return;
  
  $('#TB_window').animate({
    width: TB_WIDTH + 'px',
    left: ($(window).scrollLeft() + ($(window).width() - TB_WIDTH) / 2) + 'px',
    top: ($(window).scrollTop() + ($(window).height() - TB_HEIGHT) / 2) + 'px'
	},150);	
}

function TB_overlaySize()
{
  if( TB_useReady && !TB_ready ) return;
  
  // we have to set this to 0px before so we can reduce the size / width of the overflow onresize 

  $("#TB_overlay").css({
    "height": '0px',
    "width": '0px'
  });

  $("#TB_overlay").css({
    "height": ($(document).height() + 'px'),
    "width": ($(document).width() + 'px')
  });

}


function TB_parseQuery(query)
{
  if( TB_useReady && !TB_ready ) return;
  
  // return empty object
  if (!query)  return {};
  var params = {};
  
  // parse query
  var pairs = query.split(/[;&]/);
  for (var i = 0; i < pairs.length; i++)
  {
    var pair = pairs[i].split('=');
    if (!pair || pair.length != 2) continue;
    // unescape both key and value, replace "+" with spaces in value
    params[unescape(pair[0])] = unescape(pair[1]).replace(/\+/g, ' ');
  }
  return params;
}


var open_menu;
var current_timeout = new Array();

function showMenu(id1)
{
  if($('#' + id1).length)
  {
    if($('#' + id1).css('display')=='none')
    {
      //alert(open_menu);
      if($('#' + open_menu).length) {hideMenu($('#' + open_menu)); }
      $('#' + id1).css('display','inline');
      startMenuTimeout($('#' + id1));
      $('#' + id1).bind("mouseover",function(e) { killMenuTimeout($('#' + id1)); });
      $('#' + id1).bind("mouseout",function(e) { startMenuTimeout($('#' + id1)); });
      open_menu = id1;
    }
  }
}

function showMenu(id1, id2)
{
  if($('#' + id1).length)
  {
    if($('#' + id1).css('display')=='none')
    {
      //alert(open_menu);
      if($('#' + open_menu).length) {hideMenu($('#' + open_menu)); }
      $('#' + id1).css('display','inline');
     //startMenuTimeout($('#' + id1));

	$('#' + id2).bind("mouseleave",function(e) {startMenuTimeout($('#' + id1));});
	$('#' + id1).bind("mouseover",function(e){killMenuTimeout($('#' + id1)); });
	$('#' + id1).bind("mouseout",function(e) {startMenuTimeout($('#' + id1)); });
	  open_menu = id1;
    }
  }
}


function killMenuTimeout(divEl)
{
  clearTimeout(current_timeout[divEl.id]);
  current_timeout[divEl.id] = '';
}

function startMenuTimeout(divEl)
{
//	alert(divEl.id);
  if(current_timeout[divEl.id] == '') {
    current_timeout[divEl.id] = setTimeout(function() { hideMenu(divEl); }, 1000);
  }
}

function hideMenu(divEl)
{
  divEl.css('display','none');
  current_timeout[divEl.id] = '';
  divEl.unbind("mouseover");
  divEl.unbind("mouseout");
}

function SwapOut(id1) {
  $('#' + id1).src = Rollarrow1.src;
  return true;
}

function SwapBack(id1) {
  $('#' + id1).src = Rollarrow0.src;
  return true;
}
function urldecode( str ) {
    
    var hash_map = {}, ret = str.toString(), unicodeStr='', hexEscStr='';
    
    var replacer = function(search, replace, str) {
        var tmp_arr = [];
        tmp_arr = str.split(search);
        return tmp_arr.join(replace);
    };
    
    // The hash_map is identical to the one in urlencode.
    hash_map["'"]   = '%27';
    hash_map['(']   = '%28';
    hash_map[')']   = '%29';
    hash_map['*']   = '%2A';
    hash_map['~']   = '%7E';
    hash_map['!']   = '%21';
    hash_map['%20'] = '+';
    hash_map['\u00DC'] = '%DC';
    hash_map['\u00FC'] = '%FC';
    hash_map['\u00C4'] = '%D4';
    hash_map['\u00E4'] = '%E4';
    hash_map['\u00D6'] = '%D6';
    hash_map['\u00F6'] = '%F6';
    hash_map['\u00DF'] = '%DF';
    hash_map['\u20AC'] = '%80';
    hash_map['\u0081'] = '%81';
    hash_map['\u201A'] = '%82';
    hash_map['\u0192'] = '%83';
    hash_map['\u201E'] = '%84';
    hash_map['\u2026'] = '%85';
    hash_map['\u2020'] = '%86';
    hash_map['\u2021'] = '%87';
    hash_map['\u02C6'] = '%88';
    hash_map['\u2030'] = '%89';
    hash_map['\u0160'] = '%8A';
    hash_map['\u2039'] = '%8B';
    hash_map['\u0152'] = '%8C';
    hash_map['\u008D'] = '%8D';
    hash_map['\u017D'] = '%8E';
    hash_map['\u008F'] = '%8F';
    hash_map['\u0090'] = '%90';
    hash_map['\u2018'] = '%91';
    hash_map['\u2019'] = '%92';
    hash_map['\u201C'] = '%93';
    hash_map['\u201D'] = '%94';
    hash_map['\u2022'] = '%95';
    hash_map['\u2013'] = '%96';
    hash_map['\u2014'] = '%97';
    hash_map['\u02DC'] = '%98';
    hash_map['\u2122'] = '%99';
    hash_map['\u0161'] = '%9A';
    hash_map['\u203A'] = '%9B';
    hash_map['\u0153'] = '%9C';
    hash_map['\u009D'] = '%9D';
    hash_map['\u017E'] = '%9E';
    hash_map['\u0178'] = '%9F';
 
    for (unicodeStr in hash_map) {
        hexEscStr = hash_map[unicodeStr]; // Switch order when decoding
        ret = replacer(hexEscStr, unicodeStr, ret); // Custom replace. No regexing
    }
    
    // End with decodeURIComponent, which most resembles PHP's encoding functions
    ret = decodeURIComponent(ret);
 
    return ret;
}
function user_moj_log()	{
	if(readCookie('moj_logedin'))	{
		var username = readCookie('moj_logedin_username');
		var displayname = readCookie('moj_logedin_displayname');
		gtsp('user_moj_log_a').href='http://moj.dom.pl/' + username;
		if(displayname)	{
			gtsp('user_moj_log_a').innerHTML='Witaj, ' + urldecode(displayname) + '!';
		}	else	{
			gtsp('user_moj_log_a').innerHTML='Witaj, ' + urldecode(username) + '!';
		}
		el('user_moj_not_log','none');
		el('user_moj_log','');
	}
}
function user_moj_log2()	{
	if(readCookie('moj_logedin'))	{
		var username = readCookie('moj_logedin_username');
		var displayname = readCookie('moj_logedin_displayname');
		gtsp('profil_link').href='http://moj.dom.pl/' + username;
		gtsp('loged_profil').href='http://moj.dom.pl/' + username;
		username_short = username;
		if(username.length > 15)
			var username_short = username.substr(0,12)+'...';
		gtsp('loged_profil').innerHTML=username_short;
		var pms = readCookie('moj_logedin_pms') ? readCookie('moj_logedin_pms') : 0;
		var friends = readCookie('moj_logedin_friends') ? readCookie('moj_logedin_friends') : 0;
		gtsp('profil_tresc').innerHTML='...<a href="http://moj.dom.pl/user_messages.php">nowe wiadomości ('+pms+')</a><span class="moj_or">&nbsp;</span><br/>...<a href="http://moj.dom.pl/user_friends.php">znajomi online ('+friends+')</a><span class="moj_or">&nbsp;</span>';
		gtsp('zalogowany_poczta').innerHTML='<a href="http://poczta.dom.pl/" style="border:0 !important;"><img style="border:0; margin-right:5px;line-height:19px;top:4px;left:25px;position:absolute;" src="/layout_images/icon_poczta.gif" alt="poczta.dom.pl" />Poczta</a><a href="http://moj.dom.pl/user_logout.php">Wyloguj się</a></div>';
		el('user_profil_not_log','none');
		el('user_profil_log','');
	}
	$("#login_div").show();
}

function reload_aktywnosc()
{
	$.ajax({
		  type: "GET",
		  url: 'aktywnosc.php',
		  dataType: "xml",
		  success: function(text){
			var os=$(text).find('osoby').text();
			if(os) {
				$('#user_online').html("<p>"+os+"</p>");
				$("#user_online").show();
			}	else	{
				$("#user_online").hide();
			}
		  },
		  error: function(){
		  }
	});
}

function strzalka_reload(){
	//alert("CLICK");
	//alert($("#head_strzalka").hasClass("strzalka_dol"));
	if($("#head_strzalka").hasClass("strzalka_dol"))
	{
		self.wygas2=0;
		$("#head_strzalka").removeClass("strzalka_dol");
		$("#head_strzalka").addClass("strzalka_gora");
		$("#search_help_typ").show();
		$("#search_help_content_s").hide();
		$("#search_help_content_s").html("");

		if($("#normal_search").css("display") == "none")
		{
			$('#google_input').focus();
		}
		else
		{
			$('#search_help_input_s').focus();
			$('#search_help_input_s').attr("class", "inp_white");

			if($('#search_help_input_s').val()== 'Nazwa projektu...')
				$('#search_help_input_s').val("");
		}

		
	}
	else
	{
		$("#head_strzalka").removeClass("strzalka_gora");
		$("#head_strzalka").addClass("strzalka_dol");
		$("#search_help_typ").hide();
		$("#search_help_typ ul li a").removeClass("hov");
	}
}

function select_search(id)
{
	if(id == 'google')
	{
		$("#normal_search").hide();
		$("#google_search").show();
		//$("#google_input").focus();
	}
	else
	{
		$("#google_search").hide();
		$("#normal_search").show();
		$("#search_help_input_s").attr("class", "inp_"+id);
		$("#search_help_input_s").val("");
		$("#search_type").val(id);
		//zmiana targetu wyszukiwania

		if(id == "projekty")
		{
			$("#searchword_form_top").attr("method", "get");
			$("#searchword_form_top").attr("action", "http://gotowe-projekty-domow.dom.pl/search.php");
			$("#search_help_input_s").attr("name", "searchword");
			$("#search_param").html('<input type="hidden" value="Search" name="do_search">');
		}
		else if(id == "forum")
		{
			$("#searchword_form_top").attr("method", "get");
			$("#searchword_form_top").attr("action", "http://moj.dom.pl/search.php");
			$("#search_help_input_s").attr("name", "search_text");
			$("#search_param").html('<input type="hidden" value="dosearch" name="task"><input type="hidden" value="forum" name="t">');
		}
		else if(id == "dom_pl")
		{
			$("#searchword_form_top").attr("method", "get");
			$("#searchword_form_top").attr("action", "http://www.dom.pl/");
			$("#search_help_input_s").attr("name", "s");
			$("#search_param").html('');
		}
		else if(id == "firmy")
		{
			$("#searchword_form_top").attr("method", "get");
			$("#searchword_form_top").attr("action", "http://firmy.dom.pl/search.php");
			$("#search_help_input_s").attr("name", "searchword");
			$("#search_param").html('<input type="hidden" value="Search" name="do_search">');
		}
		else if(id == "fachowcy")
		{
			$("#searchword_form_top").attr("method", "get");
			$("#searchword_form_top").attr("action", "http://fachowcy.dom.pl/search.php");
			$("#search_help_input_s").attr("name", "searchword");
			$("#search_param").html('<input type="hidden" value="Search" name="do_search">');
		}
		else if(id == "moj_dom_pl")
		{
			$("#searchword_form_top").attr("method", "get");
			$("#searchword_form_top").attr("action", "http://moj.dom.pl/search.php");
			$("#search_help_input_s").attr("name", "search_text");
			$("#search_param").html('<input type="hidden" value="dosearch" name="task">');
		}
		else if(id == "meble")
		{
			$("#searchword_form_top").attr("action", "http://meble.dom.pl/wyszukiwarka/go/szukaj/");
			$("#searchword_form_top").attr("method", "post");
			$("#search_help_input_s").attr("name", "query");
			$("#search_param").html('');
		}
		else if(id == "ksiegarnia")
		{
			$("#searchword_form_top").attr("action", "http://ksiegarnia.dom.pl/advanced_search_result.php");
			$("#searchword_form_top").attr("method", "get");
			$("#search_help_input_s").attr("name", "keywords");
			$("#search_param").html('');
		}
		else if(id == "ogloszenia")
		{
			$("#searchword_form_top").attr("method", "get");
			$("#searchword_form_top").attr("action", "http://ogloszenia.dom.pl/index.php");
			$("#search_help_input_s").attr("name", "e_72");
			$("#search_param").html('<input type="hidden" value="Search" name="do_search">');
		}
		else if(id == "oswietlenie" || id == "lazienki" || id == "rtv-agd")
		{
			$("#searchword_form_top").attr("method", "get");
			$("#searchword_form_top").attr("action", "http://"+id+".dom.pl/search.php");
			$("#search_help_input_s").attr("name", "search_query");
			$("#search_param").html('');
		}
		//$("#search_help_input_s").focus();
	}

	$("#head_strzalka").removeClass("strzalka_gora");
	$("#head_strzalka").addClass("strzalka_dol");
	$("#search_help_typ").hide();
	$("#search_help_typ ul li a").removeClass("hov");
}

function search_help_delay_s(obj)	{
	var value = jQuery.trim(obj.value);
	clearTimeout(self.search_help_time);
	if(value.length >2)	{
		$("#ajax_search").show();
		self.search_help_time = setTimeout("search_help_s('"+obj.value+"')",100);
	}	else	{
		$("#search_help_content_s").html("");
		$("#search_help_content_s").hide();
	}
}

function search_help_s(obj)	{

if($("#search_type").val() == 'dom_pl')
	var param="&dom=1";
else
	var param="";

$.ajax({
  type: "GET",
  url: '/search_help_s.php',
  data: 'search=' + obj+param,
  dataType: "xml",
  success: function(xml){
          var toPrint = '';
		  var ct=0;
		  var ct2=0;
		  var lista="";
		  if($("#search_type").val() == 'dom_pl')
		  {
			 $(xml).find('res').each(function(){
				if(!ct && !ct2)	{
					$('#search_help_content_s').html("");
					//$('<div class="item_search"></div>').html('<span>PROJEKTY:</span>').appendTo('#search_help_content_s');
					$('<ul id="li_search"></ul>').appendTo('#search_help_content_s')
				}	else if(ct && !ct2)	{
					//$('<div class="item_search"></div>').html('<span>PROJEKTY:</span>').appendTo('#search_help_content_s');
					$('<ul id="li_search"></ul>').appendTo('#search_help_content_s');
				}
				var ad_title = $(this).find('res_title').text();
				var ad_link = $(this).find('res_link').text();
				//alert(ad_title);
				lista+='<li class="item_search" style="height:auto;list-style:none"><a style="color:#03318B;display:block;" href="'+ad_link+'">'+ad_title+'</a></li>';
			  
				ct2++;
			  });
		  }
		  else
		  {
			  $(xml).find('res2').each(function(){
				if(!ct && !ct2)	{
					$('#search_help_content_s').html("");
					//$('<div class="item_search"></div>').html('<span>PROJEKTY:</span>').appendTo('#search_help_content_s');
					$('<ul id="li_search"></ul>').appendTo('#search_help_content_s')
				}	else if(ct && !ct2)	{
					//$('<div class="item_search"></div>').html('<span>PROJEKTY:</span>').appendTo('#search_help_content_s');
					$('<ul id="li_search"></ul>').appendTo('#search_help_content_s');
				}
				var ad_title = $(this).find('res2_title').text();
				var ad_link = $(this).find('res2_link').text();
				var ad_foto = $(this).find('res2_foto').text();
				//alert(ad_title);
				lista+='<li class="item_search"><a href="'+ad_link+'"><img style="float:left;margin-right:3px;" src="'+ad_foto+'" alt="'+ad_title+'" width="50" height="33"/></a><a style="color:#03318B;display:block;height:35px;" href="'+ad_link+'">'+ad_title+'</a></li>';
			  
				ct2++;
			  });
		  }
			  lista="<ul id='li_search'>"+lista+"</ul>";
			//lista+="<script type='text/javascript'>$('li.item_search').mouseover(function(){$(this).addClass('search_selected');}).mouseout(function(){$(this).removeClass('search_selected');});</script>";
			$('#search_help_content_s').html(lista);
		  if(ct || ct2)	{
		  	$('#search_help_content_s a').mouseover(function()	{
		  		self.search_help_active=1;
		  	});
		  	$('#search_help_content_s a').mouseout(function()	{
		  		self.search_help_active=0;
		  	});		  	
		  	$('#search_help_content_s').show();
		  	$('#ajax_search').hide();
		  }	else	{
		  	$('#search_help_content_s').hide();		  
		  }


		  $('li.item_search').mouseover(function(){
				var tab_tt=$('li.item_search');
				for(var i=0;i<tab_tt.length;i++)
					$(tab_tt[i]).removeClass('search_selected');
				$(this).addClass('search_selected');
			}).mouseout(function(){
				$(this).removeClass('search_selected');
			});
		  $('#ajax_search').hide();
  },
  error: function(){
  	$('#search_help_content_s').html("");
  	$('#search_help_content_s').hide();
	$('#ajax_search').hide();
  }
});

}
