var editor;
var otrzymane;
var napisane;
var conv1 = false;
var conv2 = false;
var oact = false;
var nact = false;
var iind = 'http://'+location.host+'/';
var rob3 = '';
var rob4 = '';
var poz2 = false;
var cohh2 = 0;
var tabs2 = ['con_1','con_2','con_3','con_5','con_6'];
var robiecos = false;
var roznica = 0;
var resize = false;
var minimax = 0;
var long = 2;
var przedluztlo = false;
var flashtlo = false;
var flashtloyt = false;
var trackhref = false;
var altohand = false;
var MSIE = false;
if(navigator.userAgent.indexOf('MSIE')>=0 && navigator.userAgent.indexOf('Opera')<0)MSIE=true;
var arVersion = navigator.appVersion.split("MSIE");
var version = parseFloat(arVersion[1]);
var addr;
var inter = false;
function Hejight(){
		return Math.max($('u3').offsetHeight,Math.max($('u1').offsetHeight,$('u2').offsetHeight));
	}
function Tabshow2(){
	if (robiecos) {
		return;
	}
	RemoveAll();
	var fix = this.id.substr(2);
	var conid = "con_"+fix;
	if ($(conid).style.display == 'block') {
		return;
	}
	robiecos = true;
	this.style.background = "url("+iind+"public/default/img/nactive_tab.jpg) top center repeat-x";
	$('sz'+fix+'l').style.background = "url("+iind+"public/default/img/l_tab.jpg) top left repeat-x";
	$('sz'+fix+'r').style.background = "url("+iind+"public/default/img/r_tab.jpg) top right repeat-x";
	//tabs.each(function(tt){
	for (var tt = 0; tt< tabs2.length; tt++){
		//alert($(tabs[tt]).style.display);
		if ($(tabs2[tt]).style.display == 'block') {

			//$(tabs[tt]).style.display = block;
			var costam = new Effect.Fade(tabs2[tt],{duration: 0.2});
			$('sz'+tabs2[tt].substr(4)).style.background = "url("+iind+"public/default/img/nunactive_tab.jpg) top center repeat-x";
			$('sz'+tabs2[tt].substr(4)+'l').style.background = "url("+iind+"public/default/img/ul_tab.jpg) top left repeat-x";
			$('sz'+tabs2[tt].substr(4)+'r').style.background = "url("+iind+"public/default/img/ur_tab.jpg) top right repeat-x";
			rob3 = tabs2[tt];
			break;
		}
	}
	$(conid).style.visibility = 'hidden';
	$(conid).style.display = 'block';
	cohh2 = $(conid).offsetHeight;
	//alert(cohh);
	poz2 = false;
	//roznica = Math.abs($('szrama').offsetHeight-10-cohh2);
	if (cohh2>$('szczegoly').offsetHeight || cohh2>$('szrama').offsetHeight) {

		$('szrama').style.height = cohh2+10+'px';
		$('szczegoly').style.height = cohh2+20+'px';
		if (resize) {
			//if ($('main').offsetHeight-30 < cohh2) {
				$('main').style.height = Math.max(minimax,cohh2+100)+"px";
			//}
			//$('main').style.height = Math.max($('bodyz3').offsetHeight-139,Math.max(minimax,Math.max($('left').offsetHeight,200+cohh2)))+"px";
		}
	}else{
		poz2 = true;
	}
	$(conid).style.visibility = 'visible';
	$(conid).style.display = 'none';
	var trrt = new Effect.Appear(conid,{duration: 0.2,afterFinish: Koniec3});
	rob4 = conid;
}
function OpenTab(id){

}
function Koniec3(){

	$(rob3).style.display = 'none';
	$(rob4).style.display = 'block';
	if (poz2) {
		$('szrama').style.height = cohh2+10+'px';
		$('szczegoly').style.height = cohh2+20+'px';

		if (resize) {
			//if ($('main').offsetHeight-30 < cohh2) {
				$('main').style.height = Math.max(minimax, cohh2+100)+"px";
			//}
			//$('main').style.height = Math.max($('bodyz3').offsetHeight-139,Math.max(minimax,Math.max($('left').offsetHeight,200+cohh2)))+"px";
		}
	}
	if (flashtlo) {
			$('flashtlo').style.left = Math.round(($('bodyz3').offsetWidth-fhz)/2)+"px";
			if (flashtloyt) {
				$('bodyz2').style.height = Math.max($('bodyz3').offsetHeight,GetWH())+"px";
				$('flashtlo').style.height = Math.max($('bodyz3').offsetHeight,GetWH())+"px";
				$('ft').height= Math.max($('bodyz3').offsetHeight,GetWH());
			}
		}
	if (version<=6) {
		$('closebottom').style.top = Math.max(GetWH()-50,139+$('main').offsetHeight+$('foot').offsetHeight-50)+"px";
		$('bottom').style.top = Math.max(GetWH()-35,139+$('main').offsetHeight+$('foot').offsetHeight-35)+"px";
	}
	robiecos = false;
}
function Rownaj(){
	var ram1 = $('szrama').offsetHeight;
	for (var i = 0;i<tabs2.length;i++){
		if ($(tabs2[i]).offsetHeight>ram1 /*&& $(tabs[i]).offsetHeight>parseInt($('szrama').style.height.substr(0,$('szczegoly').style.height.length-2))*/) {
			$('szrama').style.height = $(tabs2[i]).offsetHeight+10+'px';
			$('szczegoly').style.height = $(tabs2[i]).offsetHeight+20+'px';
		}
		var ram1 = $('szrama').offsetHeight;
	}
	if (version<=6) {
		$('closebottom').style.top = Math.max(GetWH()-50,139+$('main').offsetHeight+$('foot').offsetHeight-50)+"px";
		$('bottom').style.top = Math.max(GetWH()-35,139+$('main').offsetHeight+$('foot').offsetHeight-35)+"px";
	}
}
function Rownaj2(){
	var ram1 = $('con_7').offsetHeight;
	$('szrama').style.height = ram1+10+'px';
	$('szczegoly').style.height = ram1+20+'px';
	for (var i = 0;i<tabs2.length;i++){
		if (tabs2[i] != 7) {
			$(tabs2[i]).style.height = ram1+"px";
		}
	}
}
function Edytuj(id,file_id){
	if (robiecos) {
		return;
	}
	robiecos = true;
	var tresc = $('p_'+id).innerHTML;
	var temph = $('p_'+id).offsetHeight;
	var tempw = $('p_'+id).offsetWidth;
	$('f_'+id).remove();
	$('p_'+id).remove();
	var pole = document.createElement('TEXTAREA');
	pole.id = 'tx_'+id;
	//pole.className = 'econ';
	//pole.style.width = "300px";
	pole.style.width = Math.max(320,tempw)+"px";
	pole.style.height = Math.max(95,temph)+"px";
	pole.innerHTML = tresc;
	$('e_'+id).appendChild(pole);
	var guz = document.createElement('IMG');
	guz.src = iind+'public/default/img/icon_save.gif';
	guz.style.cursor = 'pointer';
	guz.id = 'guz_'+id;
	guz.onclick = function(){
		Zapisuj(id,file_id);
	}
	$('e2_'+id).appendChild(guz);
	robiecos = false;
	guz.style.float = 'right';
	//guz.style.marginLeft = '10px';
}

function Zapisuj(id,file_id){
	if (robiecos) {
		return;
	}
	robiecos = true;
	var lod = document.createElement("DIV");
	$('tx_'+id).style.display = "none";
	lod.className = "econ";
	lod.style.background = "url(/public/default/img/loading.gif) center center no-repeat";
	lod.style.width = "350px";
	lod.style.height = "100px";
	lod.id = 'lod_'+id;
	$('e_'+id).appendChild(lod);
	new Ajax.Request(iind+'?module=panel&action=send&file_id='+file_id, {
		method: 'post',
		postBody: 'text='+$F('tx_'+id),
		onSuccess: function(response){
			addFrontInfo(response.responseText);
			var ter = document.createElement("DIV");
			ter.innerHTML = $F('tx_'+id);
			ter.id = 'p_'+id;
			ter.className = 'econ';
			$('e_'+id).appendChild(ter);
			$('tx_'+id).remove();
			$('lod_'+id).remove();
			$('guz_'+id).remove();
			var ret = document.createElement("IMG");
			ret.src = "/public/default/img/ico_edit.gif";
			ret.style.cursor = "pointer";
			ret.style.float = "right";
			ret.id = "f_"+id;
			ret.onclick = function(){
					Edytuj(id,file_id);
			}
			$('e2_'+id).appendChild(ret);
			robiecos = false;
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			robiecos = false;
		}
	});
}
function addFrontInfo(txt){
	/*RemoveAll();*/
	var inf = document.createElement('UL');
	inf.id = 'info_frontmsg';
		var ll = document.createElement('LI');
	if (typeof(txt) == 'array') {
		for(var i = txt.length; i<=0; i--){
			ll.innerHTML += txt[i];
		}
	}else{
		ll.innerHTML = txt;
	}
	inf.appendChild(ll);
	/*$('main').insert({before:inf} );*/
	var tlo = Tlo();
	var srodek = document.createElement('div');
	srodek.id = "gr";
	document.body.appendChild(srodek);
	//document.getElementById("gr").innerHTML = txt;
	document.getElementById("gr").appendChild(inf);
	srodek.style.position = "absolute";
	srodek.style.zIndex = 100;
	srodek.style.left = Math.round((tlo.offsetWidth-459)/2)+"px";
	srodek.style.width = '459px';
	srodek.style.height = '119px';
	srodek.style.background = "url(/public/default/img/komunikat_ok.png) center center no-repeat";

	if (!MSIE || version>6) {
		srodek.style.position = "fixed";
		//srodek.style.top = '80px';
		if (MSIE) {
			srodek.style.top = Math.max(0,Math.round((document.documentElement.clientHeight-119)/2)-50)+"px";
		}else{
			srodek.style.top = Math.max(0,Math.round((window.innerHeight-119)/2)-50)+"px";
		}
	}else{
		var coordinates = $('body').cumulativeScrollOffset();
		srodek.style.top = Math.round((document.documentElement.clientHeight-119)/2)-50+coordinates[1]+'px';
		//srodek.style.top = 50+coordinates[1]+'px';
	}
}
function addStraigthFrontInfo(txt){

	var tlo = Tlo();
	var srodek = document.createElement('div');
	srodek.id = "gr";
	document.body.appendChild(srodek);
	document.getElementById("gr").innerHTML = txt;
	srodek.style.position = "absolute";
	srodek.style.zIndex = 100;
	srodek.style.left = Math.round((tlo.offsetWidth-459)/2)+"px";
	srodek.style.width = '459px';
	srodek.style.height = '119px';
	srodek.style.background = 'url(/public/default/img/komunikat_ok.png) center center no-repeat';

	if (!MSIE || version>6) {
		srodek.style.position = "fixed";
		//srodek.style.top = '80px';
		if (MSIE) {
			srodek.style.top = Math.max(0,Math.round((document.documentElement.clientHeight-119)/2)-50)+"px";
		}else{
			srodek.style.top = Math.max(0,Math.round((window.innerHeight-119)/2)-50)+"px";
		}
	}else{
		var coordinates = $('body').cumulativeScrollOffset();
		srodek.style.top = Math.round((document.documentElement.clientHeight-119)/2)-50+coordinates[1]+'px';
		//srodek.style.top = 50+coordinates[1]+'px';

	}
}
function addFrontError(txt){
	var err = document.createElement('UL');
	err.id = 'error_frontmsg';
	/*left: 100px; top: 45px; width: 330px; font-weight: bold;>
	err.style.position = 'absolute';
	err.style.left = 'absolute';
	err.style.top = 'absolute';
	err.style.width = 'absolute';
	err.style.fontWeight = 'absolute';*/
	if (typeof(txt) == 'array') {
		for(var i = txt.length; i<=0; i--){
			var ll = document.createElement('LI');
			ll.innerHTML = txt[i];
			err.appendChild(ll);
		}
	}else{
		var ll = document.createElement('LI');
		ll.innerHTML = txt;
		err.appendChild(ll);
	}
	/*$('main').insert({before:err} );*/
	var tlo = Tlo();
	var srodek = document.createElement('div');
	srodek.id = "gr";
	document.body.appendChild(srodek);
	//document.getElementById("gr").innerHTML = txt;
	document.getElementById("gr").appendChild(err);
	srodek.style.position = "absolute";
	srodek.style.zIndex = 100;
	srodek.style.left = Math.round((tlo.offsetWidth-459)/2)+"px";
	srodek.style.width = '459px';
	srodek.style.height = '119px';
	srodek.style.background = 'url(/public/default/img/komunikat.png) center center no-repeat';

	if (!MSIE || version>6) {
		srodek.style.position = "fixed";
		//srodek.style.top = '80px';
		if (MSIE) {
			srodek.style.top = Math.max(0,Math.round((document.documentElement.clientHeight-119)/2)-50)+"px";
		}else{
			srodek.style.top = Math.max(0,Math.round((window.innerHeight-119)/2)-50)+"px";
		}
	}else{
		var coordinates = $('body').cumulativeScrollOffset();
		srodek.style.top = Math.round((document.documentElement.clientHeight-119)/2)-50+coordinates[1]+'px';
		//srodek.style.top = 50+coordinates[1]+'px';
	}

}
function delAv(){
	window.location.href = iind+'klubowicze/delav/';
}
function delFile(id){
	window.location.href = iind+'klubowicze/delfile/'+id;
}
function delznaj(id){
	window.location.href = iind+'klubowicze/delznaj/'+id;
}
function addFrontConfirm(txt,Yeshandler,Nohandler){
	var tlo = TloConfirm();
	var srodek = document.createElement('div');
	srodek.id = "gr";
	document.body.appendChild(srodek);
	document.getElementById("gr").innerHTML = '<div style="position: absolute; left: 100px; top: 45px; width: 330px; font-weight: bold;">'+txt+'</div>';
	//document.getElementById("gr").appendChild(err);
	srodek.style.position = "absolute";
	srodek.style.zIndex = 100;
	srodek.style.left = Math.round((tlo.offsetWidth-459)/2)+"px";
	srodek.style.width = '459px';
	srodek.style.height = '119px';
	srodek.style.background = 'url(/public/default/img/komunikat_del.png) center center no-repeat';

	if (!MSIE || version>6) {
		srodek.style.position = "fixed";
		//srodek.style.top = '80px';
		if (MSIE) {
			srodek.style.top = Math.max(0,Math.round((document.documentElement.clientHeight-119)/2)-50)+"px";
		}else{
			srodek.style.top = Math.max(0,Math.round((window.innerHeight-119)/2)-50)+"px";
		}
	}else{
		var coordinates = $('body').cumulativeScrollOffset();
		//srodek.style.top = 50+coordinates[1]+'px';
		srodek.style.top = Math.round((document.documentElement.clientHeight-119)/2)-50+coordinates[1]+'px';
	}
	//alert('??');
	var but1 = document.createElement('IMG');
	but1.src= '/public/default/img/guziki/tak.gif';
	//but1.innerHTML = 'Tak';
	//but1.className = 'but';
	but1.onclick = function(){
		eval(Yeshandler);
	}
	but1.style.position = "absolute";
	but1.style.left = "130px";
	but1.style.bottom = "10px";

	srodek.appendChild(but1);
	var but2 = document.createElement('IMG');
	but2.src= '/public/default/img/guziki/nie.gif';

	//but2.innerHTML = 'Nie';
	if (Nohandler.length>0) {
		but2.onclick = function(){
		eval(Nohandler);
		}
	}else{
		but2.onclick = function(){
			document.body.removeChild(document.getElementById('gr'));
			document.body.removeChild(document.getElementById('bg'));
		}
	}

	//but2.className = 'but';
	but2.style.position = "absolute";
	but2.style.left = "250px";
	but2.style.bottom = "10px";
	srodek.appendChild(but2);
}
function addStraightFrontError(txt){

	var tlo = Tlo();
	var srodek = document.createElement('div');
	srodek.id = "gr";
	document.body.appendChild(srodek);
	document.getElementById("gr").innerHTML = txt;
	//document.getElementById("gr").appendChild(err);
	srodek.style.position = "absolute";
	srodek.style.zIndex = 100;
	srodek.style.left = Math.round((tlo.offsetWidth-459)/2)+"px";
	srodek.style.width = '459px';
	srodek.style.height = '119px';
	srodek.style.background = 'url(/public/default/img/komunikat.png) center center no-repeat';

	if (!MSIE || version>6) {
		srodek.style.position = "fixed";
		//srodek.style.top = '80px';
		if (MSIE) {
			srodek.style.top = Math.max(0,Math.round((document.documentElement.clientHeight-119)/2)-50)+"px";
		}else{
			srodek.style.top = Math.max(0,Math.round((window.innerHeight-119)/2)-50)+"px";
		}
	}else{
		var coordinates = $('body').cumulativeScrollOffset();
		//srodek.style.top = 50+coordinates[1]+'px';
		srodek.style.top = Math.round((document.documentElement.clientHeight-119)/2)-50+coordinates[1]+'px';
	}

}
function RemoveFrontInfo(){
	try{
		new Effect.Fade('info_frontmsg',{duration: 0.4,afterFinish: function(){$('info_frontmsg').remove();}});
		//
	}catch(e){}
}
function RemoveFrontError(){
	try{
		new Effect.Fade('error_frontmsg',{duration: 0.4,afterFinish:  function(){$('error_frontmsg').remove();}});
		//$('error_frontmsg').remove();
	}catch(e){}
}
function RemoveAll(){
	RemoveFrontError();
	RemoveFrontInfo();
}
function Napisane(){
	RemoveAll();
	if (gm == 'napisane' || robiecos) {
		return;
	}
	gm = 'napisane';
	actpage = 1;
	robiecos = true;
	//oact = false;
	for (var i = 1; i <= long; i++){
		$('li'+i).style.backgroundColor = '';
	}
	$('li2').style.backgroundColor = '#b8cfd1';
	if (editor) {
		editor = CKEDITOR.instances.nep1.destroy();
		editor = false;
	}
	ClearAndClean('gora');
	new Ajax.Request(iind+'?module=panel&action=send&napisane='+actpage, {
		method: 'get',
		onSuccess: function(response){
			$('gora').update(response.responseText);
			StopCleaning('gora');
			robiecos = false;
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			robiecos = false;
		}
	});
}
var actpage = 1;

function otrzLoader(page){
	if (robiecos || actpage == page) {
		return;
	}
	RemoveAll();
	actpage = page;
	robiecos = true;
	ClearAndClean('gora');
	new Ajax.Request(iind+'?module=panel&action=send&otrzymane='+actpage, {
		method: 'get',
		onSuccess: function(response){
			//$('gora').update(response.responseText);
			StopCleaning('gora');
			var json = response.responseText.evalJSON();
			if (json.nieprzeczytane) {
				if (!trackhref) {
					trackhref = true;
					var aa = document.createElement("A");
					aa.href = iind+'wiadomosci';
					aa.innerHTML = 'Masz <span id="nieprz"></span> <span id="nieslow"></span> wiadomości';
					$('trackin').innerHTML += ' | ';
					$('trackin').appendChild(aa);
					nieprzeczytane = parseInt(json.nieprzeczytane);
				}
				$('nieprz').innerHTML = json.nieprzeczytane;
				$('nieslow').innerHTML = json.nieslowo;
				$('sz2').style.fontWeight = "bold";
			}
			$('gora').update(json.tresc);
			robiecos = false;
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			robiecos = false;
			StopCleaning('gora');
		}
	});

}
function napiLoader(page){
	RemoveAll();
	if (robiecos || actpage == page) {
		return;
	}
	actpage = page;
	robiecos = true;
	ClearAndClean('gora');
	new Ajax.Request(iind+'?module=panel&action=send&napisane='+actpage, {
		method: 'get',
		onSuccess: function(response){
			$('gora').update(response.responseText);
			StopCleaning('gora');
			robiecos = false;
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			robiecos = false;
			StopCleaning('gora');
		}
	});
}
function Odebrane(){
	RemoveAll();
	if (gm == 'odebrane' || robiecos) {
		return;
	}
	gm = 'odebrane';
	robiecos = true;
	actpage = 1;
	for (var i = 1; i <= long; i++){
		$('li'+i).style.backgroundColor = '';
	}
	$('li1').style.backgroundColor = '#b8cfd1';
	nact = false;
	if (editor) {
		editor = CKEDITOR.instances.nep1.destroy();
		editor = false;
	}
	ClearAndClean('gora');

	new Ajax.Request(iind+'?module=panel&action=send&otrzymane='+actpage, {
		method: 'get',
		onSuccess: function(response){
			StopCleaning('gora');
			var json = response.responseText.evalJSON();
			if (json.nieprzeczytane) {
				nieprzeczytane = parseInt(json.nieprzeczytane);
				if (!trackhref) {
					trackhref = true;
					var aa = document.createElement("A");
					aa.href = iind+'wiadomosci';
					aa.innerHTML = 'Masz <span id="nieprz"></span> <span id="nieslow"></span> wiadomości';
					$('trackin').innerHTML += ' | ';
					$('trackin').appendChild(aa);

				}
				$('nieprz').innerHTML = json.nieprzeczytane;
				$('nieslow').innerHTML = json.nieslowo;
				$('sz2').style.fontWeight = "bold";
			}
			$('gora').update(json.tresc);
			robiecos = false;
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			robiecos = false;
		}
	});
}
function ClearAndClean(id){
	$(id).innerHTML = '';
	$(id).style.background = '#fff url(/public/default/img/loading.gif) center center no-repeat';
}
function ClearAndClean2(id){
	$(id).innerHTML = '';
	$(id).style.background = 'url(/public/default/img/loading.gif) center center no-repeat';
}
function StopCleaning(id){
	$(id).style.background = 'transparent';
}
function Zapisuj2(id){
	robiecos = true;
	var tresc = CKEDITOR.instances.napisz.getData();

	//var patt1=/\n/g;
	//var tresc2 = tresc.replace(patt1,'<br />');
	//var patt2=/\r/g;
	//var tresc3 = tresc2.replace(patt1,'');
	var tresc3 = tresc;
	//var element = CKEDITOR.document.getBody();
	//CKEDITOR.style('background', 'url(/public/default/img/loading.gif) center center no-repeat');
	//alert(element.innerHTML);
	//element.style.background = 'url(/public/defult/img/laoding.gif) center center';
	if (tresc3.empty()) {
		if(!altohand) {
				altohand = true;
				var alto = document.createElement("DIV");
				alto.id = "alto";
				document.body.appendChild(alto);
				document.getElementById("alto").innerHTML = '<div style="margin: 40px 80px;">Wpisz treść wiadomości!</div>';
				//document.getElementById("gr").appendChild(err);
				alto.style.position = "absolute";
				alto.style.zIndex = 100;
				alto.style.left = Math.round(($('bg').offsetWidth-459)/2)+"px";
				alto.style.width = '459px';
				alto.style.height = '119px';
				alto.style.background = 'url(/public/default/img/komunikat.png) center center no-repeat';
				var tt = parseInt($('gr').style.top);
				if (tt<130) {
					$('gr').style.top = "130px";
					tt = 130;
				}
				if (!MSIE || version>6) {
					alto.style.position = "fixed";
				}
				alto.style.top = Math.max(0,tt-130)+"px";
			}
		return false;
	}

	new Ajax.Request(iind+'?module=panel&action=send&wyslij='+id, {
		method: 'post',
		postBody: 'text='+tresc3+'&temat='+$F('t2'),
		onSuccess: function(response){
			var json = response.responseText.evalJSON();
			if(json.kod == 1){
				CKEDITOR.instances.napisz.destroy();
				editor = false;
				document.body.removeChild(document.getElementById('gr'));
				document.body.removeChild(document.getElementById('bg'));
				if (altohand) {
					document.body.removeChild(document.getElementById('alto'));
					altohand = false;
				}
				addFrontInfo(json.tresc);
				robiecos = false;
			}else if(!altohand) {
				altohand = true;
				var alto = document.createElement("DIV");
				alto.id = "alto";
				document.body.appendChild(alto);
				document.getElementById("alto").innerHTML = '<div style="margin: 40px 80px;">'+json.tresc+'</div>';
				//document.getElementById("gr").appendChild(err);
				alto.style.position = "absolute";
				alto.style.zIndex = 100;
				alto.style.left = Math.round(($('bg').offsetWidth-459)/2)+"px";
				alto.style.width = '459px';
				alto.style.height = '119px';
				alto.style.background = 'url(/public/default/img/komunikat.png) center center no-repeat';
				var tt = parseInt($('gr').style.top);
				if (tt<120) {
					$('gr').style.top = "130px";
					tt = 120;
				}
				if (!MSIE || version>6) {
					alto.style.position = "fixed";
				}
				alto.style.top = Math.max(0,tt-120)+"px";
				robiecos = false;
			}
			//element.style.background = 'transparent';
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			robiecos = false;
			//element.style.background = 'transparent';
		}
	});

}
function Napisz(id,tem){
	RemoveAll();
	var tlo = TloConfirm();
	var srodek = document.createElement('div');
	srodek.id = "gr";
	document.body.appendChild(srodek);
	document.getElementById("gr").innerHTML = '<input type="text" name="t2" id="t2" value="Re: '+tem+'" style="width: 500px; margin: 20px 0px;" /><br />';
	document.getElementById("gr").innerHTML += "<textarea name='napisz'></textarea><br />";
	srodek.style.position = "absolute";
	srodek.style.zIndex = 100;
	srodek.style.left = Math.round((tlo.offsetWidth-500)/2)+"px";
	srodek.style.width = '500px';
	srodek.style.height = '400px';
	srodek.style.background = '#fff url(/public/default/img/loading.gif) center center no-repeat';

	if (!MSIE || version>6) {
		srodek.style.position = "fixed";
		//srodek.style.top = '80px';
		if (MSIE) {
			srodek.style.top = Math.max(0,Math.round((document.documentElement.clientHeight-485)/2)-50)+"px";
		}else{
			srodek.style.top = Math.max(0,Math.round((window.innerHeight-485)/2)-50)+"px";
		}
	}else{
		var coordinates = $('body').cumulativeScrollOffset();
		srodek.style.top = 50+coordinates[1]+'px';
	}
	editor = CKEDITOR.replace( 'napisz' ,
    {
        toolbar : 'Basic',
        uiColor : '#6a6a6a',
        width: '500px',
        height: '200px'
    });
	srodek.style.background = 'transparent';


		var but1 = document.createElement('IMG');
		but1.src = '/public/default/img/guziki/wyslij.gif';
		//but1.style.width = '141px';
		//but1.style.height = '24px';
		but1.style.cursor = 'pointer';
		but1.style.float = 'left';

	but1.onclick = function(){
			Zapisuj2(id);
		}
	//but1.innerHTML = 'Wyślij';
	//but1.className = 'but';

	but1.style.margin = '10px 55px';
	document.getElementById("gr").appendChild(but1);

		var but2 = document.createElement('IMG');
		but2.src = 'public/default/img/guziki/anuluj.gif';
		but2.style.cursor = 'pointer';
		//but2.style.width = '141px';
		//but2.style.height = '24px';
		but2.style.float = 'left';
		but2.onclick = function(){
			Anuluj();
		}

	//but2.innerHTML = 'Anuluj';
	//but2.className = 'but';
	but2.style.margin = '10px 40px';
	document.getElementById("gr").appendChild(but2);

}
function Tlo(){
	var tlo = document.createElement('div');
	tlo.className = "tlo";
	tlo.id = 'bg';
	//tlo.style.height = wysokosc()[0]+'px';
	if (window.innerHeight) {
		tlo.style.height = Math.max($('bodyz3').offsetHeight,window.innerHeight)+10+'px';
	}else if (document.documentElement.clientHeight) {
		tlo.style.height = Math.max($('bodyz3').offsetHeight,document.documentElement.clientHeight)+10+'px';
	}
	tlo.onclick = function(){
	//CKEDITOR.instances.napisz.destroy();
		document.body.removeChild(document.getElementById('gr'));
		document.body.removeChild(this);
		if (flashtlo) {
			$('flashtlo').style.left = Math.round(($('bodyz3').offsetWidth-fhz)/2)+"px";
		}
	//teraz2.mydrag.destroy();
	}
	document.body.appendChild(tlo);
	//var arVersion = navigator.appVersion.split("MSIE");
	//var version = parseFloat(arVersion[1]);
	/*if(version <= 6){
		var ifr = document.createElement('IFRAME');
		ifr.src = 'blank.html';
		tlo.appendChild(ifr);
	}*/
	return tlo;
}
function TloConfirm(){
	var tlo = document.createElement('div');
	tlo.className = "tlo";
	tlo.id = 'bg';
	if (window.innerHeight) {
		tlo.style.height = Math.max($('bodyz3').offsetHeight,window.innerHeight)+'px';
	}else if (document.documentElement.clientHeight) {
		tlo.style.height = Math.max($('bodyz3').offsetHeight,document.documentElement.clientHeight)+'px';
	}
	document.body.appendChild(tlo);
	return tlo;

}
function Anuluj(){
	CKEDITOR.instances.napisz.destroy();
	editor = false;
	document.body.removeChild(document.getElementById('gr'));
	document.body.removeChild(document.getElementById('bg'));
	if (altohand) {
		document.body.removeChild(document.getElementById('alto'));
		altohand = false;
	}
}

var gm = 'napisz';
function NapiszN(){
	if (gm == 'napisz' || robiecos) {
		return;
	}
	robiecos = true;
	for (var i = 1; i <= long; i++){
		$('li'+i).style.backgroundColor = '';
	}
	$('li3').style.backgroundColor = '#b8cfd1';
	gm = 'napisz';
	ClearAndClean('gora');
	$('gora').innerHTML = '<p class="nag">NAPISZ WIADOMOŚĆ</p><div style="float: left; padding: 5px; clear: both;">Temat: <input type="text" name="temat" id="temat" value="" style="width: 350px; margin-bottom: 15px;" /><textarea name="nep1" style="margin: 10px 3px;"></textarea></div>';
	editor = CKEDITOR.replace( 'nep1' ,
    {
        toolbar : 'Basic',
        uiColor : '#6a6a6a',
        width: '420px',
        height: '280px'
    });


		var but1 = document.createElement('IMG');
		but1.src= 'public/default/img/guziki/wyslij.gif';
		//but1.style.width = '141px';
		//but1.style.height = '24px';
		but1.style.cursor = 'pointer';
		but1.style.float = 'left';
		but1.style.margin = '10px 0px 10px 25px';


	but1.onclick = function(){
			Zapisuj3();
			return false;
		}
	//but1.innerHTML = 'Wyślij';
	//but1.className = 'but';

	//but1.style.margin = '10px 30px';
	$('gora').appendChild(but1);
	//var dol = document.createElement("DIV");
	//dol.id = 'dol';
	//dol.style.display = 'none';
	//$('gora').appendChild(dol);
    StopCleaning('gora');
    robiecos = false;
}

function Zapisuj3(){
	//CKEDITOR.style("background", "url(/public/default/img/loading.gif) center center");
	RemoveAll();
	var tresc = CKEDITOR.instances.nep1.getData();
	//var element = CKEDITOR.document.getBody();
	//CKEDITOR.style('background', 'url(/public/default/img/loading.gif) center center no-repeat');
	//alert(element.innerHTML);
	//element.style.background = 'url(/public/defult/img/laoding.gif) center center';
	if (tresc.empty()) {
		addFrontError('Wpisz treść wiadomości');
		return false;
	}
	var wyzn = $('znajlist').descendants();
	var odb = [];
	wyzn.each(function(node){
      if (node.id.substr(0,4) == 'wyzn' && node.checked) {
      		odb[odb.length] = node.value;
      }
   });
	if (odb.length == 0) {
		addFrontError('Wybierz przynajmniej jednego adresata');
		return false;
	}
	new Ajax.Request(iind+'?module=panel&action=send&zapisuj='+actpage, {
		method: 'post',
		postBody: 'text='+tresc+'&adresaci='+odb.toString()+'&temat='+$F('temat'),
		onSuccess: function(response){
			var json = response.responseText.evalJSON();
			if(json.kod == 1){
				addFrontInfo(json.tresc);
				CKEDITOR.instances.nep1.destroy();
				gm = '';
				robiecos = false;
				NapiszN();
			}else{
				addFrontError(json.tresc);
			}
			//element.style.background = 'transparent';
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			//element.style.background = 'transparent';
		}
	});
	return false;
}
function Laduj(id,przeczytane){
	if (parseInt(oact) == parseInt(id) || robiecos) {
		return;
	}
	robiecos = true;
	Deseleckt(oact);
	oact = parseInt(id);
	Seleckt(oact);
	if (!przeczytane) {
		deweight(id);
	}
	ClearAndClean('dol');
	new Ajax.Request(iind+'?module=panel&action=send&laduj='+id, {
		method: 'get',
		onSuccess: function(response){
			$('dol').update(response.responseText);
			StopCleaning('dol');
			robiecos = false;
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			StopCleaning('dol');
			robiecos = false;
		}
	});
}

function Laduj2(id){
	if (parseInt(nact) == parseInt(id) || robiecos) {
		return;
	}
	robiecos = true;
	Deseleckt(nact);
	nact = parseInt(id);
	Seleckt(nact);
	ClearAndClean('dol');
	new Ajax.Request(iind+'?module=panel&action=send&laduj2='+id, {
		method: 'get',
		onSuccess: function(response){
			$('dol').update(response.responseText);
			StopCleaning('dol');
			robiecos = false;
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			StopCleaning('dol');
			robiecos = false;
		}
	});
}

function Tak(uid,wid){
	new Ajax.Request(iind+'?module=panel&action=send&tak=1&user_id='+uid+'&wiado_id='+wid, {
		method: 'get',
		onSuccess: function(response){
			//addFrontInfo(response.responseText);
			addFrontInfo('Zgoda została wysłana. Odtąd możesz korespondować z tym uzytkownikiem');
			var json = response.responseText.evalJSON();
			if (json.znajomi) {
				$('znajlist').update(json.znajomi);
				window.location.href = iind+'nowiznajomi';
			}
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
		}
	});
	$('resp').innerHTML = 'Zgodziłeś się';
	return false;
}

function Nie(uid,wid){
	new Ajax.Request(iind+'?module=panel&action=send&nie=1&user_id='+uid+'&wiado_id='+wid, {
		method: 'get',
		onSuccess: function(response){
			addFrontInfo('Odmowa została wysłana. Nie będziesz otrzymywał wiadomości od tego użytkownika');
			//addFrontInfo(response.responseText);
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
		}
	});
	$('resp').innerHTML = 'Odmówiłeś';
	return false;
}
function deweight(id){
	var cz = setTimeout(function(){
		if (parseInt(oact) == parseInt(id)) {
			try{
				$('t_'+id).style.fontWeight = "normal";
				$('n_'+id).style.fontWeight = "normal";
				$('id_'+id).style.fontWeight = "normal";
				$('p_'+id).src = iind+"public/default/img/pp.gif";
				if (nieprzeczytane>0) {
					nieprzeczytane--;
					$('nieprz').innerHTML = nieprzeczytane;
					if (nieprzeczytane == 1) {
						$('nieslow').innerHTML = 'nieprzeczytaną';
					}else if((nieprzeczytane>1 && nieprzeczytane < 5) || (nieprzeczytane> 21 && (nieprzeczytane%10>1 || nieprzeczytane%10<5))){
						$('nieslow').innerHTML = 'nieprzeczytane';
					}else{
						$('nieslow').innerHTML = 'nieprzeczytanych';
					}
				}
				if (nieprzeczytane == 0) {
					$('sz2').style.fontWeight = "normal";
				}
			}catch(e){}
				new Ajax.Request(iind+'?module=panel&action=send&przeczytane='+id, {
					method: 'get'
				});
			}
		},1000);
}
function Seleckt(id){
	$('tr_'+id).style.backgroundColor = "#b8cfd1";
}
function Deseleckt(id){
	$('tr_'+id).style.backgroundColor = "";
}
function Przedluztlo(){
	var daa = setTimeout(function(){
		try{
			$('bg').style.height = Math.max(139+Math.max(80+$('szczegoly').offsetHeight,$('main').offsetHeight)+$('foot').offsetHeight+10,GetWH())+"px";
			if (flashtlo) {
				$('flashtlo').style.left = Math.round(($('bodyz3').offsetWidth-fhz)/2)+"px";
			}
		}catch(e){};
		Footczek();
	},1000);
}
function Przedluztlo2(){
	var daa = setTimeout(function(){
		try{
			$('bg').style.height = Math.max(139+$('main').offsetHeight+$('foot').offsetHeight+10,GetWH())+"px";
			if (flashtlo) {
				$('flashtlo').style.left = Math.round(($('bodyz3').offsetWidth-fhz)/2)+"px";
			}
		}catch(e){}
		Footczek();
	},1000);
}
function Footczek2(){
	try{
			var gal = $('galeria').offsetHeight;
			var man = $('main').offsetHeight;
			var tresc = $('tresc').offsetHeight;
			var pikto = $('pikto').offsetHeight;
			if (gal+pikto*1.5+50>= man) {
				$('main').style.height = "auto";
			}
			/*if (addr = '89.171.9.14') {
				alert(gal);
				alert(tresc);
				alert(man);
			}*/

		}catch(e){

		}

}
function Footczek(){
	//alert();
	//alert($('main').offsetHeight);

	try{
		if ($('szczegoly').offsetHeight+75>$('main').offsetHeight) {
			$('main').style.height = 'auto';
		}
	}catch(e){};

	if (GetWH() == 139+$('main').offsetHeight+$('foot').offsetHeight+$('spacer').offsetHeight) {
		if (flashtlo) {
			$('bodyz2').style.height = Math.max($('bodyz3').offsetHeight,GetWH())+"px";
			$('flashtlo').style.height = Math.max($('bodyz3').offsetHeight,GetWH())+"px";
			if (flashtloyt) {
				$('ft').height= Math.max($('bodyz3').offsetHeight,GetWH());
			}
		}
		if (addr = '89.171.9.14') {
			//alert('?');
		}
		try{
			var gal = $('galeria').offsetHeight;
			var man = $('main').offsetHeight;
			if (gal>= man-50) {
				$('main').style.height = "auto";
			}
			/*if (addr = '89.171.9.14') {
				alert(gal);
				alert(man);
				alert('?');
			}*/

		}catch(e){

		}

		return;
	}
	if(GetWH() >= 139+$('main').offsetHeight+$('foot').offsetHeight+$('spacer').offsetHeight){
		$('main').style.height = GetWH() - 139-$('foot').offsetHeight-$('spacer').offsetHeight-5+"px";
		minimax = $('main').offsetHeight;
		//wh = GetWH();
		if (addr = '89.171.9.14') {
			//alert('??');
		}
		resize = true;
	}else{
		//$('main').style.height = $('szczegoly').offsetHeight+70+"px";
		$('main').style.height = "auto";
		//if (flashtlo) {
		//	$('flashtlo').style.left = Math.round(($('bodyz3').offsetWidth-fhz)/2)+"px";
		//}
		if (addr = '89.171.9.14') {
			//alert('???');
		}
	}
	if (wh != GetWH()) {
		$('main').style.height = 'auto';
	}
	if (flashtlo) {
		$('bodyz2').style.height = Math.max($('bodyz3').offsetHeight,GetWH())+"px";
		$('flashtlo').style.height = Math.max($('bodyz3').offsetHeight,GetWH())+"px";
		if (flashtloyt) {
			$('ft').height= Math.max($('bodyz3').offsetHeight,GetWH());
			//ft.height= Math.max($('bodyz3').offsetHeight,GetWH());
		}
	}
}
function GetWH(){
	if (!MSIE) {
		 return window.innerHeight;
	}else{
		 return document.documentElement.clientHeight;
	}
}
function GetWW(){
	if (!MSIE) {
		 return window.innerWidth;
	}else{
		 return document.documentElement.clientWidth;
	}
}
function DelId(id){
	robiecos = true;
	document.body.removeChild(document.getElementById('gr'));
	document.body.removeChild(document.getElementById('bg'));
	ClearAndClean('gora');
	new Ajax.Request(iind+'?module=panel&action=send&delid='+id+'&actpage='+actpage, {
		method: 'get',
		onSuccess: function(response){
			StopCleaning('gora');
			var json = response.responseText.evalJSON();
			if (json.nieprzeczytane) {
				if (!trackhref) {
					trackhref = true;
					var aa = document.createElement("A");
					aa.href = iind+'wiadomosci';
					aa.innerHTML = 'Masz <span id="nieprz"></span> <span id="nieslow"></span> wiadomości';
					$('trackin').innerHTML += ' | ';
					$('trackin').appendChild(aa);
					nieprzeczytane = parseInt(json.nieprzeczytane);
				}
				$('nieprz').innerHTML = json.nieprzeczytane;
				$('nieslow').innerHTML = json.nieslowo;
				$('sz2').style.fontWeight = "bold";
			}
			$('gora').update(json.tresc);
			robiecos = false;
			addFrontInfo('Wiadomość została usunięta');
			//addFrontInfo(response.responseText);
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
			StopCleaning('gora');
		}
	});
}
function DelOut(id){
	robiecos = true;
	document.body.removeChild(document.getElementById('gr'));
	document.body.removeChild(document.getElementById('bg'));
	ClearAndClean('gora');
	new Ajax.Request(iind+'?module=panel&action=send&delout='+id+'&actpage='+actpage, {
		method: 'get',
		onSuccess: function(response){
			$('gora').update(response.responseText);
			StopCleaning('gora');
			robiecos = false;
			addFrontInfo('Wiadomość została usunięta');
			//addFrontInfo(response.responseText);
		},
		onFailure: function(response){
			addFrontError(response.errorCode);
		}
	});
}
var zam = false;
function Efekt(){
	if (!zam) {
		zam = true;
		if (MSIE && version<= 6) {
			$('bodyz3').style.visibility = 'hidden';
		}else{
			Effect.SwitchOff('bodyz3');
		}
		$('tik').src = '/public/default/img/rozwin.gif';
		return false;
	}else{
		if (MSIE && version<= 6) {
			$('bodyz3').style.visibility = 'visible';
			Footczek();
		}else{
			$('bodyz3').appear({afterFinish:Footczek});
		}
		$('tik').src = '/public/default/img/zwin.gif';
		zam = false;

		/*if (flashtloyt) {
			var b = setTimeout(function(){
				//$('ft').height= Math.max($('bodyz3').offsetHeight,GetWH());
				Footczek();
				},1000);
		}*/
		return false;
	}
}
function setCookie(c_name,value,expiredays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate()+expiredays);
document.cookie=c_name+ "=" +escape(value)+
((expiredays==null) ? "" : ";expires="+exdate.toGMTString());
}
function getCookie(c_name)
{
if (document.cookie.length>0)
  {
  c_start=document.cookie.indexOf(c_name + "=");
  if (c_start!=-1)
    {
    c_start=c_start + c_name.length+1 ;
    c_end=document.cookie.indexOf(";",c_start);
    if (c_end==-1) c_end=document.cookie.length;
    //return unescape(document.cookie.substring(c_start,c_end));
    return document.cookie.substring(c_start,c_end);
    }
  }
return "";
}
function DisYT(){
	if (robiecos) {
		return;
	}
	robiecos = true;
	$('bodyz2').remove();
	setCookie('yt',1,1);
	flashtlo = false;
	flashtloyt = false;
	$('ytdis').stopObserving('click', DisYT);
	$('ytdis').observe("click",EnbYT);
	$('ytdis').src = '/public/default/img/youtube_on.png';
	$('tik').style.visibility = 'hidden';
	if (zam) {
		Efekt();
	}
	robiecos = false;
}
function EnbYT(){
	if (robiecos) {
		return;
	}
	robiecos = true;
	$('tik').style.visibility = 'visible';
	var bodyz2 = document.createElement('DIV');
	bodyz2.id = "bodyz2";
	$('bodyz3').insert({after:bodyz2});
	bodyz2.innerHTML = '<div id="flashtlo"></div>';
	//$('flashtlo').style.left = Math.round(($('bodyz3').offsetWidth-parseInt(GetWW()))/2)+"px";
	$('flashtlo').style.width = "100%";
	$('flashtlo').style.left = "0px";
	//$('flashtlo').style.background = 'url(/public/default/img/loading.gif)';
	$('flashtlo').style.visibility = 'visible';
	var ft = new SWFObject("/public/youtubeplayer_externalxml2.swf", "ft", ""+parseInt(GetWW())+"", ""+Math.max($('bodyz3').offsetHeight,GetWH())+"", "8", "#fff");
	ft.addParam("flashVars", "xml_path=/xml/youtube.xml");
	ft.addParam("wmode", "transparent");
	ft.addParam("bgcolor", "#000000");
	ft.addParam("allowfullscreen", "true");
	ft.write("flashtlo");
	flashtlo = true;
	flashtloyt = true;
	//if (MSIE && version<= 6) {
	//	Efekt();
	//	Efekt();
	//}else{
		//$('bodyz3').style.height = $('bodyz3').offsetHeight+1+"px";
		Footczek();
		//window.resizeTo(GetWW(),GetWH());
		//var dt = setTimeout(function(){
		//ft.Porob();
		//},1000);
		//$('bodyz3').style.display = 'none';
		//$('bodyz3').style.display = 'block';
	//}
	//alert($('ft').offsetWidth+' '+$('ft').offsetHeight);
	//$('bodyz3').remove();
	$('ytdis').src='/public/default/img/youtube_off.png';
	$('ytdis').stopObserving('click', EnbYT);
	$('ytdis').observe("click",DisYT);

	setCookie('yt',0,-1);
	robiecos = false;
}

function Chd(e){
var keynum
var keychar
var numcheck

if(window.event) // IE
{
keynum = e.keyCode
}
else if(e.which) // Netscape/Firefox/Opera
{
keynum = e.which
	if (keynum == 8) {
		return true;
	}
}
keychar = String.fromCharCode(keynum)
numcheck = /\d/
return numcheck.test(keychar)
}

function CheckComplete(ob){
	if (ob.complete) {
		Footczek2();
		if (inter) {
			inter = clearTimeout(inter);
			inter = false;
		}
		return;
	}else{
		inter = setTimeout("CheckComplete($(ob.id))",500);
	}
}
