/*	Cambler  2009, http://cambler.pl/	*/

var pg=1, tab=0, timerID=0, reply_to=0, reply_id=0, blip = new Array(), blip_imt = new Array(), mainst, last_fboxl, last_fboxl_id, last_fboxl_id_two;

function close_all() {var o = document.getElementById('dropdown_1'); if(o) {o.style.display='none';remove_class(document.getElementById('more_tasks'), 'selm');}document.getElementById('dropdown_2').style.display='none';document.getElementById('dropdown_3').style.display='none';}
function hide_menu() {timerID = setTimeout('close_all()', 200);         }
function GetTop(ele) {if (ele.offsetParent) return (ele.offsetTop + GetTop(ele.offsetParent));else return (ele.offsetTop);}
function GetLeft(ele) {if (ele.offsetParent) return ele.offsetLeft + GetLeft(ele.offsetParent);else return ele.offsetLeft;}
function show_menu(el,th, offsetTop) {close_all();document.getElementById(el).style.left=GetLeft(th)+'px';document.getElementById(el).style.top=GetTop(th)+offsetTop+'px';document.getElementById(el).style.display='block';clearTimeout(timerID);}//-145
function show_menu2(el,th) {close_all();document.getElementById(el).style.left=GetLeft(th)+'px';document.getElementById(el).style.display='block';clearTimeout(timerID);}
function clear_timer() {clearTimeout(timerID);}

//const compose_msg = '<div class="clearfix"><div class="list564 clearfix" style="float:left;display:inline;"><div class="slbl">Wyślij do</div></div><div class="list564" style="margin-left:6px;float:left;display:inline;font-weight:normal;"><input type="text" id="to" name="to" value="" maxlength="30" class="textbox" /></div><div class="list564 ch" id="ch2">160</div><div id="pss2" class="pss"></div><textarea rows="2" id="p" name="p" class="sfi" accesskey="u" style="width:98%;" autocomplete="off" maxlength="160" onkeyup="chf(this,true);"></textarea><div style="width:100%;float:left;"><div class="sbt2" id="bs2"><a href="#sent"><span>Wyślij</span></a></div></div></div>';

// ============================
var tt;function fade3(i, l) {var o = document.getElementById(l);o.style.filter="Alpha(Opacity="+i+")";o.style.opacity=''+(i/100)+'';if( i > 0 ) {i -= 2;setTimeout("fade3("+i+",'"+l+"');",0);} else {o.innerHTML = tt;tt='';o.style.filter="Alpha(Opacity=100)";o.style.opacity=100;}}

function m_since() {
var client = new HttpClient();
client.pcs='';

client.callback = function(result) {
	
	var p = document.getElementById('posts');
	var result = eval('('+result+')');

	if(result.count) {
		//pg = result.last_id; 
		$('#body').find('.added_st').each(function(index) {
    		$(this).remove();
		});
		p.childNodes[0].style.borderTop = '1px solid #adadad';
		p.innerHTML = result.body+p.innerHTML;
		/*if(result.first_id)*/ since_count = result.first_id;

		if(tab==0 || tab==2 || tab==3) $('#body').find('.priv').each(function(index){$(this).tipsy({gravity: 's'});});
	}
}

switch(tab) {
case 0: {
	client.makeRequest('since.php?since_date='+since_count,null);//+'&c'
  }break;
}
setTimeout('m_since()', 10000);
}

function toogle_loader1() {
	var o =	document.getElementById('more_bar');o.firstChild.style.color = '#bbb';o.firstChild.style.backgroundImage = "url(http://s2.cambler.pl/img/ajax-loader.gif)";
}

function toogle_loader0() {
	var o =	document.getElementById('more_bar');o.firstChild.style.color = '#333';o.firstChild.style.backgroundImage = "url(http://s2.cambler.pl/img/more_bar_down.png)";
}


function toogle_ssx(ss) {
var o = document.getElementById('ssx');
//if(o.className == '') {
if(ss) {
	o.className = 'windo2_wrapper';
	document.getElementById('priv_label').style.display = '';
	document.getElementById('pub_label').style.display = 'none';
	o.style.display = 'none';
} else {
	o.className = '';
	document.getElementById('priv_label').style.display = 'none';
	document.getElementById('pub_label').style.display = '';
	o.style.display = '';
}
}
function show_ssx() {document.getElementById('ssx').style.display = '';}
function close_ssx() {document.getElementById('ssx').style.display = 'none';}

function windo(title, text, buttons) {

var o = document.getElementById('windo_wrapper');

o.style.display = 'block';
o.style.left = document.body.clientWidth / 2 - 285 +'px';o.style.top = '50px';
if(!buttons) o.getElementsByTagName('div')[0].getElementsByTagName('div')[3].style.display = 'none';

o.getElementsByTagName('div')[0].getElementsByTagName('div')[0].getElementsByTagName('div')[1].innerHTML = text;

}

function close_windo() {document.getElementById('windo_wrapper').style.display = 'none';}

function htmlspecialchars(str) {
	if (typeof(str) == 'string') {
		str = str.replace(/&/g, "&amp;"); /* must do &amp; first */
		str = str.replace(/"/g, "&quot;");
		str = str.replace(/'/g, "&#039;");
		str = str.replace(/</g, "&lt;");
		str = str.replace(/>/g, "&gt;");
	}
	return str;
}

function rhtmlspecialchars(str) {
	if (typeof(str) == 'string') {
		str = str.replace(/&gt;/ig, ">");
		str = str.replace(/&lt;/ig, "<");
		str = str.replace(/&#039;/g, "'");
		str = str.replace(/&quot;/ig, '"');
		str = str.replace(/&amp;/ig, '&'); /* must do &amp; last */
	}
	return str;
}


function follow_recomend(o) {
if(confirm('Czy chcesz dodać użytkownika do listy obserwowanych?')){
	var client = new HttpClient();
    client.pcs='';
    var o = o.parentNode.parentNode.parentNode;
    var ind = parseInt(o.id.split('_')[1])-1;
	client.callback = function(result) {
		if(result) {
			fade3(20, o.id);
	    	tb = result.split('%');
	    	tb[0] = parseInt(tb[0]);
	    	//if(isNaN(tb[0])) tb[0] = parseInt(tb[0]); else tb[0] = 0;
			recomends[ind] =  tb[0]; 
			tt = tb[1];
			msg('Dodano użytkownika do obserwowanych');
		}
	}
	client.makeRequest('ajax/get.php?k=4&u='+recomends[ind]+'&n0='+recomends[0]+'&n1='+recomends[1]+'&n2='+recomends[2],null);
}
}
/*
function odswiez() {
	//m_since_count();
	setTimeout('odswiez()', 60000);
}

function m_since_count() {
var client = new HttpClient();
client.pcs='';

client.callback = function(result) {
	//result = result.split(',');
	//pg = tb[0];pf = tb[1];
	//since_count
	var o = document.getElementById('results_update');
	//result=1;
	if(result > 0) o.style.display = 'block';
	if(result == 1) o.innerHTML = result+' nowy wpis'; else  o.innerHTML = result+' nowych wpisów';
}

switch(tab) {
case 0: {
	client.makeRequest('since.php?since='+since_count+'&c',null);
  }break;
}
setTimeout('m_since_count()', 120000);
}
*/



// -------------------------------------------
function chf(e,o) {
//var e = document.getElementById('s');
var e = document.getElementById('s').value;
e = $.trim(e);
var l= 160-e.length;
if(o) b = document.getElementById('ch2'); else {b = document.getElementById('ch');if(e.charAt(0)=='@') document.getElementById('slbl').innerHTML = 'Odpowiedz dla...'; else document.getElementById('slbl').innerHTML = 'Co teraz robisz...?';};
b.innerHTML = l;
if(l<0) b.style.color='red'; else b.style.color='#666';
if(o) b = document.getElementById('bs2'); else b = document.getElementById('bs');
if((l<160 && l>=0) || document.getElementById('filename').value != '') {
	b.disabled = false;
} else {b.disabled = true;}
if(document.getElementById('priv_label').style.display == '') if(!document.getElementById('to').value) b.disabled = true;
}

function atab(n) {
	switch (n) {
		case 1: {
			var o = document.getElementById('atab1');o.style.color = '#444';o.style.backgroundColor = '#C9D7E7';//o.style.fontWeight = 'bold';
			var o = document.getElementById('atab2');o.style.color = '#555';o.style.backgroundColor = '#E9F0F5';//o.style.fontWeight = '';
			var o = document.getElementById('atab5');o.style.color = '#555';o.style.backgroundColor = '#E9F0F5';//o.style.fontWeight = '';
			document.getElementById('a_link').style.display = '';document.getElementById('a_map').style.display = 'none';document.getElementById('a_photo').style.display = 'none';
		} break;
		case 2: {
			var o = document.getElementById('atab2');o.style.color = '#444';o.style.backgroundColor = '#C9D7E7';//o.style.fontWeight = 'bold';
			var o = document.getElementById('atab1');o.style.color = '#555';o.style.backgroundColor = '#E9F0F5';//o.style.fontWeight = '';
			var o = document.getElementById('atab5');o.style.color = '#555';o.style.backgroundColor = '#E9F0F5';//o.style.fontWeight = '';
			document.getElementById('a_map').style.display = '';document.getElementById('a_link').style.display = 'none';document.getElementById('a_photo').style.display = 'none';
			set()
		} break;
		case 7: {
			document.getElementById('a_map').style.display = 'none';document.getElementById('a_link').style.display = 'none';document.getElementById('a_photo').style.display = 'none';document.getElementById('atab').style.display = 'block';document.getElementById('atabs').style.display = 'none';
			document.getElementById('atab5').style.backgroundColor = '#E9F0F5';
		} break;
		case 5: {
			if(document.getElementById('a_photo').style.display == '') {
				atab(7);
				document.getElementById('atab5').style.backgroundColor = '#E9F0F5';
			} else {
			var o = document.getElementById('atab5');o.style.color = '#444';o.style.backgroundColor = '#C9D7E7';//o.style.fontWeight = 'bold';
			var o = document.getElementById('atab2');o.style.color = '#555';o.style.backgroundColor = '#E9F0F5';//o.style.fontWeight = '';
			var o = document.getElementById('atab1');o.style.color = '#555';o.style.backgroundColor = '#E9F0F5';//o.style.fontWeight = '';
			document.getElementById('a_photo').style.display = '';document.getElementById('a_map').style.display = 'none';document.getElementById('a_link').style.display = 'none';
			}
		} break;
		default: {
			atab(7);
			document.getElementById('atabs').style.display = 'block';document.getElementById('atab').style.display = 'none';	
			var o = document.getElementById('atab1');o.style.color = '#444';o.style.backgroundColor = '#C9D7E7';//o.style.fontWeight = 'bold';
			var o = document.getElementById('atab2');o.style.color = '#555';o.style.backgroundColor = '#E9F0F5';//o.style.fontWeight = '';
			var o = document.getElementById('atab5');o.style.color = '#555';o.style.backgroundColor = '#E9F0F5';//o.style.fontWeight = '';
			document.getElementById('a_link').style.display = '';document.getElementById('a_map').style.display = 'none';
		}
	}	 
}
    
    var marker;
    var init;

    function set() {
		if(!document.getElementById('gmapi')) {
			var script = document.createElement('script');
			script.src = 'http://www.google.com/jsapi?key=ABQIAAAAgqDdgYprMUR5Amr41SVgVRRjZD9c86WXBK5M_PBIXs2hsYDHmBRhsnSjq-FRl-DkgrRIpClehXaUXQ';
			script.type = 'text/javascript';
			script.id = 'gmapi';
			script.onload = function(){
				if(!init) {google.load("maps", "2", {"callback" : initialize});init=true;}
			}
			document.getElementsByTagName('head')[0].appendChild(script);
		} else if(!init) {google.load("maps", "2", {"callback" : initialize});init=true;}
	}

    function initialize() {
		map = new google.maps.Map2(document.getElementById("maps_google"));
		map.setCenter(new GLatLng(52.308478623663355, 21.060791015625), 5);
		map.addControl(new google.maps.LargeMapControl3D());
		
	var latlng = new google.maps.LatLng(52.308478623663355, 21.060791015625);
	var ico=new GIcon();
	ico.image = 'http://s.cambler.pl/img/marker2.png';
	ico.shadow = 'http://maps.gstatic.com/mapfiles/shadow50.png';
	ico.iconSize=new google.maps.Size(20,34);
	ico.iconAnchor=new google.maps.Point(10,34);
	ico.infoWindowAnchor=new google.maps.Point(18,2);
	ico.infoShadowAnchor=new google.maps.Point(22,6);
	marker = new google.maps.Marker(latlng,{draggable:true,icon:ico});

		google.maps.Event.addListener(map,"click", function(overlay, latlng) {  
			if (latlng) {
				this.removeOverlay(marker);
				map.addOverlay(marker = new google.maps.Marker(latlng,{draggable:true,icon:ico}));
				position = latlng.toString().replace("(","").replace(")","").replace("+","").split(",");
			} 					
		});	
    }
    
    
function search_map(o, e) {
	if( e.which ) keyCode = e.which; else if( e.keyCode ) keyCode = e.keyCode;
	if( 13 == keyCode ) {
	 
	var place = o.value;
    var geocoder, x, y = null;

      if(GBrowserIsCompatible()) geocoder = new GClientGeocoder();
      
      if (geocoder) {
        geocoder.getLatLng(
          place,
          function(point) {
            if (point) {
              map.setCenter(point, 14);
              var latlng = point;
              var ico=new GIcon();
              ico.image = 'http://s.cambler.pl/img/marker2.png';
              ico.shadow = 'http://maps.gstatic.com/mapfiles/shadow50.png';
              ico.iconSize=new google.maps.Size(20,34);
              ico.iconAnchor=new google.maps.Point(10,34);
              ico.infoWindowAnchor=new google.maps.Point(18,2);
              ico.infoShadowAnchor=new google.maps.Point(22,6);
              map.removeOverlay(marker);
              map.addOverlay(marker = new google.maps.Marker(latlng,{draggable:true,icon:ico}));
            } else msg('Nie znaleziono podanego miejsca!', 1);
          }
        );
      }
	 }
}
    
    
    /*
function getmap(o, x, y) {

    var init;

	if(!window['google']) {
		var script = document.createElement('script');
		script.src = 'http://www.google.com/jsapi?key=ABQIAAAAgqDdgYprMUR5Amr41SVgVRRjZD9c86WXBK5M_PBIXs2hsYDHmBRhsnSjq-FRl-DkgrRIpClehXaUXQ';
		script.type = 'text/javascript';
		script.onload = function(){
			if(!init) {google.load('maps', '2', {'callback' : initialize});init=true;}
		}
		document.getElementsByTagName('head')[0].appendChild(script);
	} else if(!init) {google.load('maps', '2', {'callback' : initialize});init=true;}

    function initialize() {

    	var tag = document.createElement('div');
    	tag.className = 'maps_google';
    	o = o.parentNode.parentNode.appendChild(tag);
 
    	
    	o = o.parentNode.parentNode;
    	var mid = o.parentNode.id;
    	
    	if(!document.getElementById('map_'+mid)) {
			o.innerHTML += '<div class="post_maps_container"><div id="map_'+mid+'" class="maps_google"></div></div>';// <div id="pss"></div>      <div class="maps_info">Bialystok, Polska</div>
			map = new google.maps.Map2(document.getElementById('map_'+mid));
			map.setCenter(new GLatLng(x, y), 11);
			map.addControl(new google.maps.LargeMapControl3D());//SmallZoomControl3D
			var latlng = new google.maps.LatLng(x, y);
			var ico=new GIcon();
			ico.image = 'http://s.cambler.pl/img/marker.png';
			ico.iconSize=new google.maps.Size(20,34);
			ico.iconAnchor=new google.maps.Point(10,34);
			ico.infoWindowAnchor=new google.maps.Point(18,2);
			ico.infoShadowAnchor=new google.maps.Point(22,6);
			map.addOverlay(marker = new google.maps.Marker(latlng,{icon:ico}));
		}
    }
}*/

function getmap(o, x, y) {

	if(!document.getElementById('map_'+o.parentNode.parentNode.parentNode.id)) {

		o.style.backgroundImage = 'url(\'s/img/snn.gif\')';//o2.style.backgroundLeft = '6px';

	    var init;

		if(!document.getElementById('gmapi')) {
			var script = document.createElement('script');
			script.src = 'http://www.google.com/jsapi?key=ABQIAAAAgqDdgYprMUR5Amr41SVgVRRjZD9c86WXBK5M_PBIXs2hsYDHmBRhsnSjq-FRl-DkgrRIpClehXaUXQ';
			script.type = 'text/javascript';
			script.id = 'gmapi';
			script.onload = function(){
				if(!init) {google.load('maps', '2', {'callback' : initialize});init=true;}
			}
			document.getElementsByTagName('head')[0].appendChild(script);
		} else if(!init) {google.load('maps', '2', {'callback' : initialize});init=true;}

	}

    function initialize() {
    	/*
    	var tag = document.createElement('div');
    	tag.className = 'maps_google';
    	o = o.parentNode.parentNode.appendChild(tag);
    	*/
    	
    	//o = o.parentNode.parentNode;
    	var mid = o.parentNode.parentNode.parentNode.id;
    	
    	if(!document.getElementById('map_'+mid)) {
    	
    		var latlng = new google.maps.LatLng(x, y);
			var ico=new GIcon();
			ico.image = 'http://s.cambler.pl/img/marker2.png';
			ico.shadow = 'http://maps.gstatic.com/mapfiles/shadow50.png';
			ico.iconSize=new google.maps.Size(20,34);
			ico.iconAnchor=new google.maps.Point(10,34);
			ico.infoWindowAnchor=new google.maps.Point(18,2);
			ico.infoShadowAnchor=new google.maps.Point(22,6);

    		o.style.backgroundImage = 'url(\'s/img/local2.gif\')';
			o.parentNode.parentNode.innerHTML += '<div class="post_maps_container"><div id="map_'+mid+'" class="maps_google"></div></div>';// <div id="pss"></div>      <div class="maps_info">Bialystok, Polska</div>
			map = new google.maps.Map2(document.getElementById('map_'+mid));
			map.setCenter(new GLatLng(x, y), 11);
			map.addControl(new google.maps.LargeMapControl3D());//SmallZoomControl3D

			map.addOverlay(marker = new google.maps.Marker(latlng,{icon:ico}));
		}
    }
}


function getvideo(o, v) {o.parentNode.parentNode.innerHTML = '<object width="429" height="347"><param name="movie" value="http://youtube.com/v/'+v+'&fs=1&autoplay=1" /><param name="allowFullScreen" value="true" /><embed src="http://youtube.com/v/'+v+'&fs=1&autoplay=1" type="application/x-shockwave-flash" allowfullscreen="true" width="429" height="347"></embed></object>';}

function showMyVideos(json) {
	var vvi = json['entry']['id']['$t'];
	vvi = vvi.substr(vvi.lastIndexOf('/')+1);

	var duration = json['entry']['media$group']['yt$duration']['seconds'], secs = duration%60;
	duration = parseInt(duration/60)+':'+(secs < 10 ? '0'+secs : secs);
	
	var content= json['entry']['content']['$t'];
	if(content.length > 160) content = json['entry']['content']['$t'].substr(0, 160)+'...';
	

	document.getElementById('vi_'+vvi).innerHTML = '<a href="'+json['entry']['link'][0]['href']+'">'+json['entry']['title']['$t']+'</a><div class="vidsrc">youtube.com</div><div class="vidsrc">Czas trwania: <span>'+duration+'</span></div><div style="font-size:11px;">'+content+'</div>';
}

function gvid(vid, id) {
	var fileref=document.createElement('script');
	fileref.type = 'text/javascript';
	fileref.src = 'http://gdata.youtube.com/feeds/api/videos/'+vid+'?alt=json-in-script&callback=showMyVideos';
	document.getElementsByTagName('head')[0].appendChild(fileref);
//	alert(vid);
}

function getvid(vid, id) {setTimeout("gvid(\'"+vid+"\', "+id+")", 0);}

/*
function send() {
var o=document.getElementById('p'), to=document.getElementById('to');
if(o.value) {
	var client = new HttpClient();
    client.requestType = 'POST';
    client.pcs='pss2';
    
	client.callback = function(result) {
		if(result!='0') {
			if(tab==3) {
			var p = document.getElementById('posts');
			//p.style.borderTop = '1px dotted #D2DADA;';
			p.innerHTML = result+p.innerHTML;
			p.childNodes[0].style.background = 'rgb(255,255,210)';		
			setTimeout(function(){yellowFade(p.childNodes[0]);}, 2000);
			} else msg('Wiadomość została wysłana');
			o.value='';to.value='';
  			o.blur();
    		b = document.getElementById('bs');
   			b.className='sbt2';
			b.onclick='';
			document.getElementById('ch').innerHTML = '160';
			close_windo();
		} else msg('Błąd! Wiadomość nie została wysłana',1);
//		} else msg('Wiadomość może zostać wysłana tylko osobie, która cię obserwuje!',1);
	} 
    client.makeRequest('s.php?m=1',o.value+'@#'+to.value,'text/plain');

}//document.pw.submit();
}*/

function chkey(e){
	 if( e.which ) keyCode = e.which; else if( e.keyCode ) keyCode = e.keyCode;
	 if( 13 == keyCode ) {set_status();}
}

/*function set_status() {
var o=document.getElementById('s');
if(o.value) {
	var client = new HttpClient();
    client.requestType = 'POST';
    client.pcs='pss';
	client.callback = function(result) {
		if(result!=0) {if(tab==0) {
			var p = document.getElementById('posts');
			p.style.borderTop = '1px dotted #D2DADA;';
			//var g = document.getElementById('upd');
			//g.innerHTML=Number(g.innerHTML)+1;
			//if(Number(g.innerHTML)==1) p.innerHTML = result; else p.innerHTML = result+p.innerHTML;

			tb = result.split('<<');
			result = tb[0];
			since_count = parseInt(tb[1]);
			p.innerHTML = result+p.innerHTML;
			document.getElementById('last').innerHTML = '<b>Ostatnie:</b> '+p.getElementsByTagName('div')[0].getElementsByTagName('div')[2].innerHTML+'<br /><span class="time">'+p.getElementsByTagName('div')[0].getElementsByTagName('div')[3].getElementsByTagName('span')[0].innerHTML+'</span>';
			p.childNodes[0].style.background = 'rgb(255,255,210)';		
			setTimeout(function(){yellowFade(p.childNodes[0]);}, 2000);
			document.getElementById('results_update').style.display = 'none';
		} else msg('Ustawiono nowy status');
		} 
	}
	var ot = o.value;
    
	if(document.getElementById('a_link').style.display != 'none') {atab(7);ot = ot+'#~1'+document.getElementById('link').value;
	} else if(document.getElementById('a_map').style.display != 'none') {atab(7);ot = ot+'#~2'+marker.getLatLng();}    

	var rg = new RegExp("^@([0-9A-Z_]+)", "i");
	var res = ot.match(rg);
	if(res && res[1] == reply_to) params = '?reply_id='+reply_id; else params = '';
	reply_to=0;reply_id=0;
	
    client.makeRequest('s.php'+params,ot,'text/plain');
    document.getElementById('link').value = '';document.getElementById('link').onblur();

//    client.makeRequest('s.php',o.value,'text/plain');
    o.value='';
    o.blur();
    b = document.getElementById('bs');
    b.className='sbt2';
	b.onclick='';
	document.getElementById('ch').innerHTML = '160';
}
}*/
var rty;

function set_status() {
	var ot2 = new Object(), die, o = document.getElementById('pss');

if(document.getElementById('filename').value != '') {
	o.style.display = 'block';o.style.visibility  = 'visible';
 	ajaxUpload();
 	return false;
}

	if(rty) {
		rty = eval('('+rty.substring(0, rty.lastIndexOf('}')+1)+')');
		
		if(rty.is_upload) {
			ot2.photo = rty.id;
			rty = null;
		} else {
			o.style.display = 'none';
			msg(rty.error, 1);
			rty = null;
			return false;
		}
	}

var o=document.getElementById('s'), to=document.getElementById('to'), ol = $.trim(o.value);
if(ol || ot2.photo) {
	var client = new HttpClient();
    client.requestType = 'POST';
    client.pcs='pss';

if(document.getElementById('priv_label').style.display == '') {

	client.callback = function(result) {

		if(result!='0') {
			if(tab==3) {
			var p = document.getElementById('posts');
			//p.style.borderTop = '1px dotted #D2DADA;';
			//p.innerHTML = result+p.innerHTML;
			var result = eval(result);
			p.innerHTML = result[0]+p.innerHTML;
			p.childNodes[0].style.background = 'rgb(255,255,210)';		
			setTimeout(function(){yellowFade(p.childNodes[0]);}, 2000);
			} else msg('Wiadomość została wysłana');
			to.value='';
			//close_windo();
			close_ssx();
		} else msg('Błąd! Wiadomość nie została wysłana',1);
	}

	ot2.priv_to = to.value;
	if(to.value == reply_to) ot2.reply_id = reply_id;
	
} else {

	client.callback = function(result) {
		if(result!=0) {if(tab==0) {
			var p = document.getElementById('posts');
			p.style.borderTop = '1px dotted #D2DADA;';
			var result = eval(result);
			p.innerHTML = result[0]+p.innerHTML;
			document.getElementById('last').innerHTML = '<b>Ostatnie:</b> '+result[1];
			p.childNodes[0].style.background = 'rgb(255,255,210)';		
			setTimeout(function(){yellowFade(p.childNodes[0]);}, 2000);
			//document.getElementById('results_update').style.display = 'none';
		} else msg('Ustawiono nowy status');
		} 
	}

}

	var rg = new RegExp("^@([0-9A-Z_]+)", "i");
	var res = o.value.match(rg);
	if(res && res[1] == reply_to) ot2.reply_id = reply_id;
	
	
	ot2.text = o.value;

	if(document.getElementById('a_link').style.display != 'none') {
		ot2.att_link = document.getElementById('link').value;
	} else if(document.getElementById('a_map').style.display != 'none') {
		ot2.att_geo = marker.getLatLng().toString();
	}
	atab(7);

	ot2 = $.toJSON(ot2);

    client.makeRequest('s.php', ot2, 'text/plain');

	

//    client.makeRequest('s.php?priv_to='+to.value,o.value,'text/plain');


	reply_to=0;reply_id=0;
	document.getElementById('link').value = '';document.getElementById('link').onblur();

	o.value='';
	o.blur();
	b = document.getElementById('bs');
	b.disabled = true;
	//b.onclick='';
	document.getElementById('ch').innerHTML = '160';

}

}

function yellowFade(el) {
  var b = 210;
//  setTimeout(f, 300000);
  function f() {
    el.style.background = 'rgb(255,255,'+ (b+=2) +')';
    if (b < 255) {
      setTimeout(f, 40);
    }
  };
  f();
}

function remove(id,pm) {
if(confirm('Czy na pewno chcesz usunąć ten post?')){
	if(pm && pm!=3) var n = '&p'; else var n = '';
	var client = new HttpClient();
	client.pcs='';
	
	client.callback = function(result) {
		if(result) {
			if(pm!=3) {
				document.getElementById('p'+id).parentNode.removeChild(document.getElementById('p'+id));
				if(pm!=1) {
					//var g = document.getElementById('upd');
					//g.innerHTML=Number(g.innerHTML)-1;
					var p = document.getElementById('posts');
					//if(Number(g.innerHTML)==0) {p.style.borderTop = 'none';p.innerHTML = '<div class="no_items">Brak postów</div>';document.getElementById('last').style.display = 'none';}
					document.getElementById('last').innerHTML = '<b>Ostatnie:</b> '+result;
				}
			} else location.href = '.';
		}
	}
   client.makeRequest('ajax/del_post.php?id='+id+n,null);
   return false; 
}
}

function reply(n, id) {
	 var o = document.getElementById('s');
	 o.focus();
	 o.value = '@'+n+' '+o.value;
	 chf(o);
	 reply_to = n;
	 reply_id = id;
}

function reply_m(n, id) {
	if(!(tab == 2 || tab == 3)) ct(3);
	//windo('', compose_msg);
	show_ssx();
	// var to=);
	document.getElementById('s').focus();
	document.getElementById('to').value = n;
	reply_to = n;
	reply_id = id;
}

function quote(id) {
	 var o = document.getElementById('s');
	 o.focus();
	 o.value = '[s'+id+'] '+o.value;
	 chf(o);
}

function fav(id,o) {
var client = new HttpClient();
client.pcs='';
if(o.className == 'a1') {
	client.callback = function(result) {if(result==1) {o.className = 'a4';}}
	client.makeRequest('ajax/add_fav.php?id='+id,null);
} else {
	client.callback = function(result) {if(result==1) {o.className = 'a1';}}
	client.makeRequest('ajax/del_fav.php?id='+id,null);
}
return false; 
}

function savq(q,o) {
var client = new HttpClient();
client.pcs='';

if(o.innerHTML != 'zapisz') {
	client.callback = function(result) {
	if(result==1) {
		var obj = document.getElementById('savq'), tbl = obj.getElementsByTagName('div');
		for (i=0;i<tbl.length;i++) if(tbl[i].firstChild.innerHTML==htmlspecialchars(q)) obj.removeChild(tbl[i]);
		o.innerHTML = 'zapisz';o.className = 'sv';
	}		
	}
	client.makeRequest('ajax/savq.php?q='+escape(q)+'&d=1',null);
} else {
	client.callback = function(result) {
	if(result==1) {
		var y = document.getElementById('savq_n');if(y) y.style.display = 'none';
		a = document.createElement('div');
		a.innerHTML = '<a onclick="getq(this);">'+htmlspecialchars(q)+'</a>';
		document.getElementById('savq').appendChild(a);
		o.innerHTML = 'usuń';o.className = 'dv';
	}		
	}
	client.makeRequest('ajax/savq.php?q='+escape(q),null);
}
return false;
}

function getq(o) {
var client = new HttpClient(), s_tmp = '';
client.requestType = 'POST';
//document.getElementById('hts').style.display = 'none';
var v = rhtmlspecialchars(o.innerHTML);
document.getElementById('q').value = v;



		
		document.getElementById('fboxl').style.display = 'none';
		for (i=1;i<6;i++) remove_class(document.getElementById('m'+i), 'selm');
		//.style.backgroundColor = '';//document.getElementById('m11').style.backgroundColor = '';
		var tbl = document.getElementById('savq').getElementsByTagName('div');
		for (i=0;i<tbl.length;i++) remove_class(tbl[i], 'selm');
		var tbl = document.getElementById('groups').getElementsByTagName('div');
		for (i=0;i<tbl.length;i++) remove_class(tbl[i], 'selm');
		//o.parentNode.style.backgroundColor = sclr;
		add_class(o.parentNode, 'selm');

	document.getElementById('bdd').innerHTML = '';
	document.title = 'Cambler - Szukaj - '+v;
	client.callback = function(result) {
	    var result = eval('('+result+')');
	    
	    s_tmp = '<div id="last" style="font-size:11px"> '+(result.count == 20 ? 'ponad '+result.count : result.count)+' '+(result.body == 1 ? (v[0]=='#' ? 'wynik zawierający tag' : 'wynik pasujący do') : (v[0]=='#' ? 'wyników zawierających tag' : 'wyników pasujących do'))+': <span style="font-family:Arial;background:#EEF3F7;padding:1px 4px 2px 4px">'+htmlspecialchars(v)+'</span></div>';	
		s_tmp+= '<div class="list561" style="float:left;"><h2>Wyniki wyszukiwania</h2></div><div class="svq">'+(result.is_saved ? '<a onclick="savq(\''+v+'\', this);" class="dv">usuń</a>' : '<a onclick="savq(\''+v+'\', this);" class="sv">zapisz</a>')+'</div>';

	    
	    if(result.count) {
			pg = result.last_id; 
			//var tb = new Array();
			//tb = result.split('<<');
			//pg = tb[1];
			//document.getElementById('bdd').innerHTML = s_tmp+result.body;
			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="clearfix" style="float:left;">'+result.body+'</div><a id="more_bar" onclick="m_ct(\''+v+'\');"'+(result.count > 19 ? '' : ' style="display:none;"')+'><span>więcej</span></a>';//<div id="pcm" class="pcs" style="margin:50px auto;clear:both;">Ładowanie...</div>

		} else {

			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="no" style="border:none;"><div class="nobody7">Brak wyników dla zapytania</div>';

		}
		window.location.href = window.location.href.substr(0,window.location.href.indexOf('#'))+'#search?q='+v;tab=6;
	}

	//document.getElementById('wdd').style.display = '';
	toogle_ssx(false);
	client.makeRequest('c_search.php',v,'text/plain');    
}

function get_group(o, id) {
var client = new HttpClient(), s_tmp = '';

//	var client = new HttpClient();
//	client.requestType = 'POST';

		document.getElementById('fboxl').style.display = 'none';
		for (i=1;i<6;i++) remove_class(document.getElementById('m'+i), 'selm');//document.getElementById('m'+i).style.backgroundColor = '';//document.getElementById('m11').style.backgroundColor = '';
		var tbl = document.getElementById('savq').getElementsByTagName('div');
		for (i=0;i<tbl.length;i++) remove_class(tbl[i], 'selm'); //tbl[i].style.backgroundColor = '';
		var tbl = document.getElementById('groups').getElementsByTagName('div');
		for (i=0;i<tbl.length;i++) remove_class(tbl[i], 'selm');// tbl[i].style.backgroundColor = '';
		//o.parentNode.style.backgroundColor = sclr;
		add_class(o.parentNode, 'selm');

	document.getElementById('bdd').innerHTML = '';
	document.title = 'Lista '+o.innerHTML+' | Cambler';
	
	s_tmp = '<div class="list561" style="margin-top:10px"><h2>Wpisy z listy '+o.innerHTML+'</h2></div>';// &ldquo;  &bdquo;
	
	client.callback = function(result) {
	    var result = eval('('+result+')');
	    if(result.count) {
			pg = result.last_id; 
			//var tb = new Array();
			//tb = result.split('<<');
			//pg = tb[1];
			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="clearfix" style="float:left;">'+result.body+'</div><div id="pcm" class="pcs" style="margin:50px auto;">Ładowanie...</div><a id="more_bar" onclick="m_ct('+id+');"'+(result.count > 19 ? '' : ' style="display:none;"')+'><span>więcej</span></a>';//
		} else {
			
			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="no" style="border:none;"><div class="nobody7">Brak wyników dla tej listy.</div>';
			
		}
		window.location.href = window.location.href.substr(0,window.location.href.indexOf('#'))+'#group?id='+id;tab=10;
	}

	//document.getElementById('wdd').style.display = '';
	toogle_ssx(false);
	client.makeRequest('c_group.php?id='+id,null);    
}

function add_class(b,a){if(!new RegExp("\\b"+a+"\\b","i").test(b.className)){b.className+=' '+a}}
function remove_class(b,a){b.className=b.className.replace(new RegExp("\\b"+a+"\\b","i"),'')}

function ct(e,ib) {
var client = new HttpClient(), s_tmp = '';
document.getElementById('fboxl').style.display = 'none';
var tbl = document.getElementById('savq').getElementsByTagName('div');
for (i=0;i<tbl.length;i++) remove_class(tbl[i], 'selm');
var tbl = document.getElementById('groups').getElementsByTagName('div');
for (i=0;i<tbl.length;i++) remove_class(tbl[i], 'selm');
for (i=1;i<6;i++) remove_class(document.getElementById('m'+i), 'selm');//document.getElementById('m11').style.backgroundColor = '';
add_class(document.getElementById('m'+e), 'selm');
document.getElementById('bdd').innerHTML = '';



client.callback = function(result) {
/*	//var s = result.substr(result.length-20);
      var tb = new Array();
      tb = result.split('<<');
	  pg = tb[1];
	  document.getElementById('bdd').innerHTML = tb[0];
	  if(ib) inbox(2);*/

		//var tb = new Array();
		//tb = result.split('<<');
		var result = eval('('+result+')');
		//if(e==1 || e==2 || e==4) 
		if(result.latest_status) s_tmp = '<div id="last"><b>Ostatnie:</b> '+result.latest_status+'</div>'+s_tmp;
		
	if(e!=3) {
		if(result.count) {
			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="clearfix" style="float:left;">'+result.body+'</div>';//tb[0]; <div id="pcm" class="pcs" style="margin:50px auto;">Ładowanie...</div>
			//tb = tb[1].split(',');
			//pg = tb[0];pf = tb[1];
			pg = result.last_id; //pg = tb[0];
			since = result.first_id;//since = tb[1];
			since_count = result.first_id;//since_count = tb[1];
			//if(e==1 || e==3) $('#body').find('.priv').each(function(index){$(this).tipsy({gravity: 's'});});
	  
		} else {
			if(e==1) document.getElementById('bdd').innerHTML = '<div id="last"></div><div id="posts" class="no" style="border:none;"></div>'+result.first_logg; else document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="no" style="border:none;"><div class="nobody7">Brak wyników w tej kategorii</div>';
		}
		
		
	
	} else {
	
			s_tmp = '<div class="clearfix" style="margin:17px 0;clear:both;background:#f1f1f1;padding:3px 8px 2px 8px;border:1px solid #d2d2d2"><div style="float:left;font-size:13px;padding-top:2px">Prywatne wiadomości</div><div style="float:right;"><a class="btt write_mess nomgr" onclick="show_ssx()"><span><span>napisz</span></span></a></div></div><div class="b_tabs b_tabs2 clearfix" style="margin:20px 0 4px 0;"><a id="in1" href="#inbox" onclick="inbox(1);" class="sel_t">Odebrane</a><div class="space"></div><a id="in2" href="#sent" onclick="inbox(2);" style="clear:none;">Wysłane</a><div class="space" style="width:372px;clear:none;"></div></div>';
//			alert('adfgadfg');
		if(result.count) {

			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" style="margin-top:3px;border:none;float:left;">'+result.body+'</div><div style="float:left;width:100%;"></div>';//<div id="pcm" class="pcs" style="margin:50px auto;">Ładowanie...</div>
			//tb = tb[1].split(',');
			//pg = tb[0];pf = tb[1];
			pg = result.last_id; //pg = tb[0];
			since = result.first_id;//since = tb[1];
			since_count = result.first_id;//since_count = tb[1];
			//if(e==1 || e==3) $('#body').find('.priv').each(function(index){$(this).tipsy({gravity: 's'});});
	  
		} else {
			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="no" style="border:none;"><div class="nobody7">Brak wyników w tej kategorii</div></div><div style="float:left;width:100%;"><div id="pcm" class="pcs" style="margin:50px auto;">Ładowanie...</div></div>';
		}

	}	
	
	document.getElementById('bdd').innerHTML = document.getElementById('bdd').innerHTML+'<a id="more_bar" onclick="m_ct(4);"'+(result.count > 19 ? '' : ' style="display:none;"')+'><span>więcej</span></a>';
	$('#body').find('.priv').each(function(index){$(this).tipsy({gravity: 's'});});	
		
		if(ib) inbox(2);
}

//if(e==1) {var fdh = document.getElementById('hts');if(fdh) fdh.style.display = 'block'; } else {var fdh = document.getElementById('hts');if(fdh) fdh.style.display = 'none';}
var href = window.location.href.substr(0,window.location.href.indexOf('#'));

switch(e) {
case 1: {
	//document.getElementById('wdd').style.display = '';
	toogle_ssx(false);
	document.title = 'Cambler';
	client.makeRequest('c_main.php',null);tab=0;
	s_tmp = '<div class="list561"><h2>Wszystkie wpisy</h2></div>';//<div id="you_new" style="clear:both;"><a id="results_update" ref="." accesskey="n" onclick="m_since()"></a></div>
	window.location.href = href+'#home';
  }break;
case 2: {
	//document.getElementById('wdd').style.display = '';
	toogle_ssx(false);
	document.title = '@'+un+' | Cambler';
	client.makeRequest('c_me.php',null);tab=1;
	s_tmp = '<div class="list561"><h2>Wpisy zawierające @'+un+'</h2></div>';
	window.location.href = href+'#replies';
  }break;
case 3: {
	//document.getElementById('wdd').style.display = 'none';
	toogle_ssx(true);
	document.title = 'Skrzynka odbiorcza | Cambler';
	client.makeRequest('c_inbox.php',null);tab=2;
	window.location.href = href+'#inbox';
  }break;
case 4: {
	//document.getElementById('wdd').style.display = '';
	toogle_ssx(false);
	document.title = 'Ulubione | Cambler';
	client.makeRequest('c_fav.php',null);tab=4;
	s_tmp = '<div class="list561"><h2>Twoje ulubione</h2></div>';
	window.location.href = href+'#favorites';
  }break;
/*case 11: {
	//document.getElementById('wdd').style.display = '';
	toogle_ssx(false);
	document.title = 'Cambler - Wszystkie';
	client.makeRequest('c_all.php',null);tab=11;
	s_tmp = '';
  }break;*/
}

/*
$(function() {
	$.ajax({
		type: 'GET',
		url: 'c_fav.php',
		timeout: 2500,
		dataType: 'json',
		success: function(html) {
		//alert('oi');
		alert(html.body);
		},
		beforeSend: function() {
		},
		error: function() {
		}
	});
})
*/



	return false;
}

function q(v) {
if(v.length>2) {
//document.getElementById('hts').style.display = 'none';
	var client = new HttpClient(), s_tmp = '';
	client.requestType = 'POST';
    document.getElementById('q').value = v;
    document.getElementById('fboxl').style.display = 'none';
    var tbl = document.getElementById('savq').getElementsByTagName('div');
    //    var tbl = document.getElementById('savq');if(tbl) {tbl = tbl.getElementsByTagName('div');for (i=0;i<tbl.length;i++) tbl[i].style.backgroundColor = '';}
	for (i=0;i<tbl.length;i++) remove_class(tbl[i], 'selm');
	var tbl = document.getElementById('groups').getElementsByTagName('div');
	for (i=0;i<tbl.length;i++) remove_class(tbl[i], 'selm');
	for (i=1;i<5;i++) remove_class(document.getElementById('m'+i), 'selm');//document.getElementById('m11').style.backgroundColor = '';
	add_class(document.getElementById('m5'), 'selm');
	document.getElementById('bdd').innerHTML = '';
	document.title = 'Cambler - Szukaj - '+v;
	

	
	client.callback = function(result) {
		var result = eval('('+result+')');
		
		s_tmp = '<div id="last" style="font-size:11px"> '+(result.count == 20 ? 'ponad '+result.count : result.count)+' '+(result.body == 1 ? (v[0]=='#' ? 'wynik zawierający tag' : 'wynik pasujący do') : (v[0]=='#' ? 'wyników zawierających tag' : 'wyników pasujących do'))+' <span style="font-family:Arial;font-weight:bold;padding:1px 4px 2px 4px">'+htmlspecialchars(v)+'</span></div>';//background:#EEF3F7;	
		s_tmp+= '<div class="list561" style="float:left;"><h2>Wyniki wyszukiwania</h2></div><div class="svq">'+(result.is_saved ? '<a onclick="savq(\''+v+'\', this);" class="dv">usuń</a>' : '<a onclick="savq(\''+v+'\', this);" class="sv">zapisz</a>')+'</div>';

		if(result.count) {
			pg = result.last_id; 
			//var tb = new Array();
			//tb = result.split('<<');
			//pg = tb[1];
			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="clearfix" style="float:left;">'+result.body+'</div><a id="more_bar" onclick="m_ct(\''+v+'\');"'+(result.count > 19 ? '' : ' style="display:none;"')+'><span>więcej</span></a>';//<div id="pcm" class="pcs" style="margin:50px auto;clear:both;">Ładowanie...</div>
		} else {
		
			document.getElementById('bdd').innerHTML = s_tmp+'<div id="posts" class="no" style="border:none;"><div class="nobody7">Brak wyników dla zapytania.</div>';
		
		}
		window.location.href = window.location.href.substr(0,window.location.href.indexOf('#'))+'#search?q='+v;tab=5;
	}
	//document.getElementById('wdd').style.display = '';
	toogle_ssx(false);
	client.makeRequest('c_search.php',v,'text/plain'); 
}
}

function cp(e,o) {
var client = new HttpClient();
client.pcs='';
switch(e) {
case 1: {
	client.callback = function(result) {document.getElementById('bdd').innerHTML = result;}
	client.makeRequest('c_main.php',null);
  }break;
case 2: {
	var to = document.getElementById('pop');
	if(to.innerHTML=='') {
	client.callback = function(result) {to.innerHTML = result;}
	to.style.display = '';
	o.className = 'up';o.innerHTML = 'mniej';
	to.innerHTML = '<div class="pcs2"></div>';
	client.makeRequest('ajax/get.php?k=2',null);
	} else if(to.style.display) {to.style.display = '';o.className = 'up';o.innerHTML = 'mniej';} else {to.style.display = 'none';o.className = 'down';o.innerHTML = 'więcej';}
  }break;
case 3: {


var to = document.getElementById('fri');
	var today=new Date();today.setDate(today.getDate()+365);

	var to = document.getElementById('fri');
	if(to.innerHTML=='') {
	client.callback = function(result) {to.innerHTML = result;}
	to.style.display = '';
	o.className = 'up';o.innerHTML = 'mniej';
	to.innerHTML = '<div class="pcs2"></div>';
	client.makeRequest('ajax/get.php?k=3',null);
	} else if(to.style.display) {to.style.display = '';o.className = 'up';o.innerHTML = 'mniej';var val = 0;} else {to.style.display = 'none';o.className = 'down';o.innerHTML = 'więcej';var val = 1;}
	document.cookie = 'menu='+val+'; expires='+today.toGMTString();
  }break;
case 4: {
	var to = document.getElementById('groups');
	if(to.style.display) {to.style.display = '';o.className = 'up';o.innerHTML = 'mniej';} else {to.style.display = 'none';o.className = 'down';o.innerHTML = 'więcej';}
  }break;
}
}

function inbox(e) {
var client = new HttpClient();
client.pcs = '';//pcm
client.onSend = function() {document.getElementById('more_bar').style.display = 'none';};


client.callback = function(result) {
	//var tb = new Array();
	//tb = result.split('<<');
	var result = eval('('+result+')');
	//pg = tb[1];
	if(result.count) {
		pg = result.last_id;
		document.getElementById('posts').innerHTML = result.body;
//	var o=document.getElementById('more');
//	if(o) {if(tb[1]==1) o.style.display = 'none'; else o.style.display = '';}


		if(result.count == 20) {
			var o=document.getElementById('more_bar').style.display = '';
			//if(o) o.
		}
	} else {
	
		document.getElementById('posts').innerHTML = '<div class="nobody7">Brak wyników w tej kategorii</div>';//<div class="no_items">brak wpisów</div>';
	
	}
	/*if(e==1 || e==3) */$('#body').find('.priv').each(function(index){$(this).tipsy({gravity: 's'});});
}

if(e==1) {document.getElementById('in1').className = 'sel_t';document.getElementById('in2').className = '';tab=2;document.title = 'Skrzynka odbiorcza | Cambler';} else {document.getElementById('in2').className = 'sel_t';document.getElementById('in1').className = '';tab=3;document.title = 'Skrzynka nadawcza | Cambler';}
document.getElementById('posts').innerHTML = '';
client.makeRequest('t_inbox.php?t='+e,null);
}

function l_hash() {
var h = window.location.href.slice(window.location.href.indexOf('#') + 1);
if(h=='replies') ct(2); else if(h=='inbox') ct(3); else if(h=='favorites') ct(4); else if(h=='sent') ct(3,true); else if(h.substr(0,h.indexOf('?'))=='search') {// else if(h=='all') ct(11);
	var tx = h.slice(h.indexOf('=') + 1);
	var obj = document.getElementById('savq'), tbl = obj.getElementsByTagName('div');
	for (i=0;i<tbl.length;i++) if(tbl[i].firstChild.innerHTML==tx) {getq(tbl[i].firstChild);var t = true;break;}
	if(!t) q(decodeURI(tx));
} else if(h.substr(0,h.indexOf('?'))=='group') {
	var tx = h.slice(h.indexOf('=') + 1);
	get_group(document.getElementById('g'+tx).firstChild,tx);
} else if(h.substr(0,h.indexOf('?'))=='reply') {
	var tx = h.slice(h.indexOf('=') + 1);
	reply(tx);
} else if(h.substr(0,h.indexOf('?'))=='quote') {
	var tx = h.slice(h.indexOf('=') + 1);
	quote(tx);
}

}

function load() {

	chf(document.getElementById('s'));
	
}

function follow(id, del) {
	var client = new HttpClient();
    client.pcs='';
	client.callback = function(result) {
		if(result==1) {
		var p = document.getElementById('follow');
		if(del) {p.innerHTML = '<a class="btt add_friend nomgr" onclick="follow(\''+id+'\');" style="margin-bottom:8px;"><span><span>obserwuj</span></span></a>'} else {p.innerHTML = '<div style="margin-bottom:15px;"><span class="follow2">obserwujesz</span><small style="padding:1px 5px 1px 6px;">[ <a onclick="follow(\''+id+'\',1);">usuń</a> ]</small></div>';}
		}
	}
	if(del) var ac = '&del'; else var ac = '';
    client.makeRequest('http://cambler.pl/ajax/follow.php?uid='+id+ac,'text/plain');
}

function follow_tag(id, del) {
	var client = new HttpClient();
    client.pcs='';
	client.callback = function(result) {
		if(result==1) {
		var p = document.getElementById('follow');
		if(del) {p.innerHTML = '<a class="btt add_friend nomgr" onclick="follow_tag(\''+id+'\');" style="margin-bottom:8px;"><span><span>obserwuj</span></span></a>'} else {p.innerHTML = '<div style="margin-bottom:15px;"><span class="follow2">obserwujesz</span><small style="padding:1px 5px 1px 6px;">[ <a onclick="follow_tag(\''+id+'\',1);">usuń</a> ]</small></div>';}
		}
	}
	if(del) var ac = '&del'; else var ac = '';
    client.makeRequest('http://cambler.pl/ajax/follow.php?tag='+id+ac,'text/plain');
}

function actb_checkkey(e){
	 if( e.which ) keyCode = e.which; else if( e.keyCode ) keyCode = e.keyCode;
	 if( 13 == keyCode ) {q(document.getElementById('q').value);}
}
	
function stin(t,l,o) {
	 if(l) {if(document.getElementById(o).value==''){document.getElementById(o).style.color='#999';document.getElementById(o).value=t}} else {if(document.getElementById(o).value==t){document.getElementById(o).style.color='#333';document.getElementById(o).value='';}}
}

function fade(i, l) {document.getElementById(l).style.filter="Alpha(Opacity="+i+")";document.getElementById(l).style.opacity=''+(i/100)+'';if( i > 0 ) {i -= 2;setTimeout("fade("+i+",'"+l+"');",0);} else document.getElementById(l).style.display='none';}
function blow(i, l) {document.getElementById(l).style.filter="Alpha(Opacity="+i+")";document.getElementById(l).style.opacity=''+(i/100)+'';if( i < 100 ) {i += 50;setTimeout("blow("+i+",'"+l+"');",0);} else document.getElementById(l).style.display='block';}

function fade2(i, l) {document.getElementById(l).style.filter="Alpha(Opacity="+i+")";document.getElementById(l).style.opacity=''+(i/100)+'';if( i > 0 ) {i -= 2;setTimeout("fade2("+i+",'"+l+"');",0);}}
function blow2(i, l) {document.getElementById(l).style.filter="Alpha(Opacity=0)";document.getElementById(l).style.opacity=0;
document.getElementById(l).style.filter="Alpha(Opacity="+i+")";document.getElementById(l).style.opacity=''+(i/100)+'';if( i < 100 ) {i += 4;setTimeout("blow2("+i+",'"+l+"');",0);}}



/*
function fade(i, l) {document.getElementById(l).style.filter="Alpha(Opacity="+i+")";document.getElementById(l).style.opacity=''+(i/100)+'';if( i > 0 ) {i -= 2;setTimeout("fade("+i+",'"+l+"');",0);} else document.getElementById(l).style.display='none';}
function blow(i, l) {document.getElementById(l).style.filter="Alpha(Opacity="+i+")";document.getElementById(l).style.opacity=''+(i/100)+'';if( i < 100 ) {i += 50;setTimeout("blow("+i+",'"+l+"');",0);} else document.getElementById(l).style.display='block';}
*/
function msg(t,er) {
	var o = document.getElementById('hms');
	if(er) o.className = 'her'; else o.className = 'hmg';o.innerHTML = t;o.style.display='block';
	blow(50,'hms');setTimeout("fade(50,'hms');",4000);
}

function del_hint(id) {
	var client = new HttpClient();client.pcs='';
	client.callback = function(result) {if(result==1) {fade(50,'hi'+id);}}
	client.makeRequest('ajax/del_hint.php?id='+id,null);
	return false; 
}

// - --  -- -- -- - --- --



function addText(elname, wrap1, wrap2) {
	if (document.selection) { // for IE 
		var str = document.selection.createRange().text;
		document.forms['inputform'].elements[elname].focus();
		var sel = document.selection.createRange();
		sel.text = wrap1 + str + wrap2;
		return;
	} else if ((typeof document.forms['inputform'].elements[elname].selectionStart) != 'undefined') { // for Mozilla
		var txtarea = document.forms['inputform'].elements[elname];
		var selLength = txtarea.textLength;
		var selStart = txtarea.selectionStart;
		var selEnd = txtarea.selectionEnd;
		var oldScrollTop = txtarea.scrollTop;
		//if (selEnd == 1 || selEnd == 2)
		//selEnd = selLength;
		var s1 = (txtarea.value).substring(0,selStart);
		var s2 = (txtarea.value).substring(selStart, selEnd)
		var s3 = (txtarea.value).substring(selEnd, selLength);
		txtarea.value = s1 + wrap1 + s2 + wrap2 + s3;
		txtarea.selectionStart = s1.length;
		txtarea.selectionEnd = s1.length + s2.length + wrap1.length + wrap2.length;
		txtarea.scrollTop = oldScrollTop;
		txtarea.focus();
		return;
	} else {
		insertText(elname, wrap1 + wrap2);
	}
}


function findPos(obj) {
	var curleft = curtop = 0;
	if (obj.offsetParent) {
	do {curleft += obj.offsetLeft;curtop += obj.offsetTop;} while (obj = obj.offsetParent);
	return {'left':curleft,'top':curtop};
	}
}

function show_camblek(id, owner, cite) {
//alert(last_fboxl_id+'.p'+id);
if(last_fboxl_id) {var tmp = last_fboxl_id;last_fboxl_id = '';psh(document.getElementById(tmp));}last_fboxl_id_two = 0;

if(cite) {
	var last_fboxl = owner.parentNode.parentNode;last_fboxl_id = owner.parentNode.parentNode.id;
} else {
	var last_fboxl = owner.parentNode.parentNode.parentNode.parentNode;last_fboxl_id = owner.parentNode.parentNode.parentNode.parentNode.id;
}
psn(document.getElementById(last_fboxl.id));
//alert(tmp+'.'+last_fboxl.id);
if(tmp != last_fboxl.id) {
//last_fboxl.onmouseout = null;
var client = new HttpClient();
client.pcs='';

		var o = document.getElementById('fboxl');
		document.getElementById('fbody').innerHTML = '<h3>Ładowanie...</h3>';
		o.style.display = 'block';
		document.getElementById('fboxl').style.left = findPos(last_fboxl).left-15+'px';
		
		var arrow_ico = document.getElementById('fboxl').getElementsByTagName('div')[0].getElementsByTagName('div')[0].getElementsByTagName('span')[0];
		arrow_ico.style.left = owner.offsetLeft-10+'px';
		
			arrow_ico.style.top = '-24px';
			arrow_ico.style.backgroundPosition = '0 -75px';
			//document.getElementById('fboxl').style.top =owner.offsetTop+67-(mainst ? 7 : 0)+'px';
			document.getElementById('fboxl').style.top = findPos(owner).top+owner.offsetHeight+14/*-(mainst ? 3 : 0)*/+'px';
		
client.callback = function(result) {

	document.getElementById('fboxl').style.display = 'block';
	if(owner) {
		document.getElementById('fbody').innerHTML = result;
	} else {
		document.getElementById('fbody').innerHTML += result;
	}
}

client.makeRequest('ajax/post_preview.php?id='+id,null);

}
}

function show_camblek2(id/*, owner*/) {

if(id != last_fboxl_id_two) {

var client = new HttpClient();
client.pcs='';
//	owner.onclick = null;//function() {return false};		
client.callback = function(result) {

			
	document.getElementById('fbody').innerHTML += result;
	last_fboxl_id_two = id;	

}
}

client.makeRequest('ajax/post_preview.php?id='+id,null);

return false;
}


function close_fboxl() {
	document.getElementById('fboxl').style.display = 'none';
	var tmp = last_fboxl_id;last_fboxl_id = '';
	psh(document.getElementById(tmp));
}


// - --  -- -- blip API -- - --- --


function setblip(json) {
    blip[json.id] = json;blip[json.id].user_path = blip[json.id].user_path.substring(blip[json.id].user_path.lastIndexOf('/')+1);
    show_blip(json.id);
}

function setblip2(json) {
    blip[json.id] = json;blip[json.id].user_path = blip[json.id].user_path.substring(blip[json.id].user_path.lastIndexOf('/')+1);
    show_blip(json.id, true);
}

function show_blip(id, owner) {
	var body = blip[id].body;
	//body = body.replace(/http:\/\/blip.pl\/s\/([0-9]+)/ig, '<a href="http://blip.pl/s/$1" onclick="getblip2($1, this);return false;">[blip]</a>');
	
body = body.replace(/((https?|ftp):\/\/[a-z0-9@#%\&_=?\/\.,-~]+)/ig, function(args) {

var wuj = args.match(/http:\/\/blip.pl\/s\/([0-9]+)/ig);

	if(wuj) {
		var tmp = wuj[0].substring(wuj[0].lastIndexOf('/')+1);
		return '<a href="http://blip.pl/s/'+tmp+'" onclick="getblip2('+tmp+', this);return false;">[blip]</a>';  //    target="_blank"
	} else return '<a href="'+args+'" target="_blank" rel="nofollow">'+args+'</a>';

});

body = body.replace(/(^|\s|.)#([a-z0-9ąśźćżółęńĄŚŹĆŻÓŁĘŃ\\303\\277]+)/ig, '$1<a href="http://blip.pl/tags/$2" target="_blank">#$2</a>');
body = body.replace(/(^|\s)\^(\w+)/g, '$1<a href="http://$2.blip.pl" target="_blank">^$2</a>');
body = body.replace(/(^|\s)>(\w+)/g, '$1<a href="http://$2.blip.pl" target="_blank">&gt;$2</a>');


	
	
	if(blip[id].pictures_path) {
		var ppa = blip[id].pictures_path.substring(0, blip[id].pictures_path.lastIndexOf('/'));
		ppa = ppa.substring(ppa.lastIndexOf('/')+1);
		var paic = '<a href="" target="_blank"><img id="paa'+blip[id].id+'" class="blip_img" src="" /></a>';
		blip_img(ppa);
	} else var paic = '';
	
	if(owner) {
		document.getElementById('fbody').innerHTML += '<div style="padding-top:10px"><a href="http://'+blip[id].user_path+'.blip.pl/" style="font-weight:bold">'+blip[id].user_path+'</a>: '+body+'</div>'+paic+'<a href="http://blip.pl/s/'+blip[id].id+'" class="hc_meta">'+blip[id].created_at+'</a>';
	} else {
		document.getElementById('fboxl').style.display = 'block';
		document.getElementById('fbody').innerHTML = '<div><a href="http://'+blip[id].user_path+'.blip.pl/" style="font-weight:bold">'+blip[id].user_path+'</a>: '+body+'</div>'+paic+'<a href="http://blip.pl/s/'+blip[id].id+'" class="hc_meta">'+blip[id].created_at+'</a>';
		document.getElementById('fbody').innerHTML += '<div class="ffoot">wygenerowano z użyciem API serwisu <img src="http://static0.blip.pl/images/favicon.gif" style="margin:0 2px -4px 2px" /> <a href="http://blip.pl">Blip.pl</a></div>';
	}
	
	


}

function getblip(id, th, ay) {
	if(last_fboxl_id) {var tmp = last_fboxl_id;last_fboxl_id = '';psh(document.getElementById(tmp));}last_fboxl_id_two = 0;
	var last_fboxl = th.parentNode.parentNode;last_fboxl_id = th.parentNode.parentNode.id;psn(document.getElementById(last_fboxl.id));
	
	var o = document.getElementById('fboxl');
	document.getElementById('fbody').innerHTML = '<h3>Ładowanie...</h3>';
	o.style.display = 'block';
	//o.style.top = 60+document.documentElement.scrollTop+'px';
	/*document.getElementById('fboxl').style.top = th.parentNode.parentNode.offsetTop+ay-135+'px';
	document.getElementById('fboxl').style.left = th.parentNode.parentNode.offsetLeft+430+'px';
	//alert(th.parentNode.parentNode.innerHTML);
	
	document.getElementById('fboxl').getElementsByTagName('div')[0].getElementsByTagName('div')[0].getElementsByTagName('span')[0].style.left = th.offsetLeft-15+'px';*/
	
	document.getElementById('fboxl').style.left = findPos(last_fboxl).left-15+'px';
		
		var arrow_ico = document.getElementById('fboxl').getElementsByTagName('div')[0].getElementsByTagName('div')[0].getElementsByTagName('span')[0];
		arrow_ico.style.left = th.offsetLeft-16+'px';
		
			arrow_ico.style.top = '-24px';
			arrow_ico.style.backgroundPosition = '0 -75px';
			//document.getElementById('fboxl').style.top = th.offsetTop+67-(mainst ? 7 : 0)+'px';
			document.getElementById('fboxl').style.top = findPos(th).top+th.offsetHeight+14/*-(mainst ? 3 : 0)*/+'px';
	
	//alert(document.getElementById('fboxl').getElementsByTagName('div')[0].getElementsByTagName('div')[0].getElementsByTagName('span')[0].className);
	
	//alert(th.offsetLeft);
	
	
	// target="_blank"

if(!blip[id]) {
	var fileref=document.createElement('script');
	fileref.type = 'text/javascript';
	fileref.src = 'http://blip.pl/statuses/'+id+'.json?callback=setblip';
	document.getElementsByTagName('head')[0].appendChild(fileref);
} else show_blip(id);

//return true;
}

function getblip2(id, th) {

	var o = document.getElementById('fboxl');
	//document.getElementById('fbody').innerHTML = '<h3>Ładowanie...</h3>';

if(!blip[id]) {
	var fileref=document.createElement('script');
	fileref.type = 'text/javascript';
	fileref.src = 'http://blip.pl/statuses/'+id+'.json?callback=setblip2';
	document.getElementsByTagName('head')[0].appendChild(fileref);
} else show_blip(id, true);

//	th.onclick = null;
	th.setAttribute('onclick', 'return false;');
//	alert(th.innerHTML);

}

function setblip_img(json) {
	blip_imt[json[0].id] = json;
	var tmi = ppa = json[0].update_path.substring(json[0].update_path.lastIndexOf('/')+1);
    document.getElementById('paa'+tmi).src = json[0].url;
    document.getElementById('paa'+tmi).parentNode.href = json[0].url;
}

function blip_img(id) {
	if(!blip_img[id]) {
		var fileref=document.createElement('script');
		fileref.type = 'text/javascript';
		fileref.src = 'http://blip.pl/updates/'+id+'/pictures.json?callback=setblip_img';
		document.getElementsByTagName('head')[0].appendChild(fileref);
	} else document.getElementById('paa'+id).src = blip_img[id];
}

// - --  -- -- -- - --- --



















