var r;
var f_cn_m;

function changeResolution() {
	var dr = documentResolution();
	var stTop = $("stTop");

	if(dr["w"] < 1092 && dr["w"] > 928) {
		stTop.style.position='absolute';
		stTop.style.left="50%";
		stTop.style.marginLeft="-465px";
	} else {
		stTop.style.position='relative';
		stTop.style.left="auto";
		stTop.style.marginLeft="auto";
	}

	changeCnPos();
}

function changeCnPos() {
	if(!deleteShit) {
		var tp = $('stTop');
		var cn = $('stCn');
		cn.style.display='none';
		cn.style.marginLeft=0;
		cn.style.left=tp.offsetLeft+'px';
		cn.style.display='block';
	}
}

window.onresize=changeCnPos;

document.oncontextmenu = show_context;
document.onmouseup = hide_context;

var deleteShit=0;

var last_scrolltop;

function addBanPad() {
	var d = $('b_750');
}

function loginUser(f, l) {
	if(!f) { var f = document.forms['frmLogin']; }
	if(!l) { var l = $('loginTxt'); }

	if(!f.strUserLogin2.value || !f.strUserPassword.value) {
		alert(LANG_GLOBAL_NO_NICK_OR_PASSWORD);
		return false;
	}

	MD5 = MD5_hexhash(f.strUserLogin2.value.toUpperCase() + '|' + f.strUserPassword.value);

	f.MD5.value=MD5;
	f.strUserPassword.value='';

	var req = mint.Request();

	req.OnSuccess = function() {
		if(this.responseText && this.responseText.length<300) {
			l.innerHTML=this.responseText;
		}
		if(!this.responseText) {
			l.innerHTML='<img src="http://img2.epuls.pl/img/ic/ic_preload.gif"> Trwa logowanie';
			document.location=document.location;
		}
	}

	req.SendForm(f);

	return false;
}

var showLog;
var lastLgObj;

function showLoginForm(object, txt) {
	var l = $('loginForm');
	if(object==lastLgObj) {
		showLog=1;
		lastLgObj=null;
	} else {
		showLog=null;
		lastLgObj=object;
	}
	if(!object) { showLog=1; }
	if(!showLog) {
		var p = realPos(object);
		if(!p) {
			var p = realPos(object.parentNode);
		}
		l.style.display='block';

		var cn = object;

		var min_t=0;

		while(cn = cn.offsetParent) {
			if(cn.id=="stCnMn") {
				min_t = cn.scrollTop;
			}
		}

		var t_p =

		l.style.top=p[1]+object.offsetHeight-min_t+6+'px';

		var l_p = p[0]-l.offsetWidth+object.offsetWidth;

		if(l_p<0) { l_p=0; }

		l.style.left=l_p+'px';
		document.forms['frmLogin'].strUserLogin2.focus();
		document.forms['frmLogin'].reset();
		if(!txt) {
			$('loginTxt').innerHTML=LANG_GLOBAL_LOGIN;
		} else {
			$('loginTxt').innerHTML=txt;
		}
		showLog=true;
	} else {
		l.style.display='none';
		showLog=null;
	}
}

function changeStyle(color) {
	document.cookie="EPULS_PL_STYLE="+color+'; path=/; domain=.epuls.pl';
	window.location.href=window.location.href;
	return false;
}

var OA_p=location.protocol=='https:'?'https:':'http:';
var OA_r=Math.floor(Math.random()*99999999);
var OA_channel='';
if(!document.OA_used)document.OA_used=',';
function OA_adjs(z,n)
{
	if(z>-1){
		var az="<"+"script language='JavaScript' type='text/javascript' ";
		az+="src='"+OA_p+"//q.pixelate.pl/www/delivery/ajs.php?n="+n+"&zoneid="+z;
		az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
		az+="&mmm_fo="+(document.mmm_fo)?'1':'0';
		if(document.context)az+="&context="+escape(document.context);
		if(window.location)az+="&loc="+escape(window.location);
		if(document.referrer)az+="&referer="+escape(document.referrer);
		az+="'><"+"/script>";
		document.write(az);
	}
}
function OA_adpop(z,n)
{
	if(z>-1){
		var az="<"+"script language='JavaScript' type='text/javascript' ";
		az+="src='"+OA_p+"//q.pixelate.pl/www/delivery/apu.php?n="+n+"&zoneid="+z;
		az+="&source="+OA_channel+"&exclude="+document.OA_used+"&r="+OA_r;
		if(window.location)az+="&loc="+escape(window.location);
		if(document.referrer)az+="&referer="+escape(document.referrer);
		az+="'><"+"/script>";
		document.write(az);
	}
}

function putBanner(n) {
	var b = document.getElementById('bd_'+n);
	if(b) {
		c=document.getElementById('b_'+n);
		if(c){
			var childs;
			var child;
			var sibling;
			if(b.childNodes.length==2){
				c.style.display='none';
				return false;
			}
			
			var e = b.getElementsByTagName('embed');
			var o = b.getElementsByTagName('object');
			if(e[0]) {
				e[0].setAttribute('wmode', 'opaque');
			}

			if(b.outerHTML){
				childs=b.childNodes.length;
				if(b.childNodes.length){
					child=b.childNodes[0];
				}
				while(child){
					sibling=child.nextSibling;
					if(child.nodeName&&(child.nodeName.toUpperCase()!="SCRIPT")){
						c.insertBefore(child,null);
					}
					child=sibling;
				}
			}else{
				c.insertBefore(b,null);
				b.style.display='block';
			}

			var br = getBrowser();

			if(br['app']=="OP" && br['ver']>=950) {
				var ifs = c.getElementsByTagName('iframe');
				if(ifs.length) {
					ifs[0].attachEvent("onmousewheel", scrollClear);
				}
			}
		}
	}
}
function realPos(object){
	if(object.offsetParent){
		var poX=object.offsetLeft
		var poY=object.offsetTop
		var ofW=object.offsetWidth;
		var ofH=object.offsetHeight;
		while(object=object.offsetParent){
			poX+=object.offsetLeft;
			poY+=object.offsetTop;
		}
		var pos=new Array()
		pos[0]=poX
		pos[1]=poY
		pos[2]=ofW;
		pos[3]=ofH;
		return pos;
	}
}

var adServer;
adServer = 'q.pixelate.pl';

function showUserLink(href)
{
	if(confirm('We cannot guarantee that this site is legal.\nPlease read the FAQ for more info'))
	window.open('/outside_frameset.php?'+href,'_blank');
}
function showClubPicture(id)
{
	window.open('/club_pictures_show_large.php?lngID='+id,'_blank','width=200,height=200,resizable=1,scrollbars=1');
}
function showUserPicture(id)
{
	width=screen.width/2-400;
	height=screen.height/2-200;
	window.open('/profile_pictures_show_large.php?lngID='+id,'_blank','width=800,height=400,resizable=1,scrollbars=yes,top='+height+',left='+width);
}
function showEventPicture(id)
{
	width=screen.width/2-400;
	height=screen.height/2-200;
	window.open('/event_pictures_show_large.php?lngID='+id,'_blank','width=800,height=400,resizable=1,scrollbars=yes,top='+height+',left='+width);
}
function showUserMovie(id)
{
	width=screen.width/2-400;
	height=screen.height/2-200;
	window.open('/profile_movies_show_large.php?lngID='+id,'_blank','width=800,height=550,resizable=1,scrollbars=yes,top='+height+',left='+width);
}
function sendInstantMessage(lngRID,lngSID,strUserName)
{
	if(lngSID!=lngRID)
		//window.open('/messages_send_instant.php?strUserName='+strUserName+'&lngRID='+lngRID,'messages_send_instant'+lngRID,'height=320,width=460');
		popupLauncher('Wiadomo¶æ','/skrzynka/nowa-wiadomosc/?recipientId='+lngRID,500,300);
	else
		alert('Sending to yourself? Now that\'s not gonna work :\)');
}
function sendSupportMessage()
{
	window.open('/messages_send_support.php','messages_send_support','height=350,width=430,scrollbars=yes');
}
function verify(strAction,strQuestion)
{
	if(confirm('Delete '+strQuestion+'?'))
	window.location=strAction;
}
function show_context(click){
	var server='http://img2.epuls.pl/';
	if(navigator.appName.indexOf('Microsoft')!=-1){
		var src_e=event.srcElement;
		var pos_x=event.clientX+document.body.scrollLeft;
		var pos_y=event.clientY+document.body.scrollTop;
	}else{
		var src_e=click.target;
		var pos_x=click.pageX;
		var pos_y=click.pageY;
	}

	var stCnMn = document.getElementById('stCnMn');

	if(stCnMn) {
		if(stCnMn.style.overflow=='auto') {
			pos_y = pos_y + stCnMn.scrollTop - stCnMn.offsetTop;
		}
	}

	if(src_e.tagName=="A"){
		link_e=new String(src_e);
		if(link_e.indexOf('profile.php')!=-1){
			if(!src_e.className){return true;}
			link_s=link_e.split('=');
			id=link_s[1];
			dir_id=id-(id%1000);
			dir_id=dir_id/1000+'/';
			link_s=server+'members/photo/'+dir_id+id+'_b.jpg';
			show_uc(link_s,pos_x,pos_y);
			return false;
		}
		if(link_e.indexOf('/p/')!=1){
                        if(!src_e.className){return true;}
                        link_s=link_e.split('/');
                        id=link_s[5];
                        dir_id=id-(id%1000);
                        dir_id=dir_id/1000+'/';
                        link_s=server+'members/photo/'+dir_id+id+'_b.jpg';
                        show_uc(link_s,pos_x,pos_y);
                        return false;
                }
	}
	if(src_e.tagName=="IMG"){
		link_e=new String(src_e.src);
		if(link_e.indexOf('members/photo')!=-1){
			link_s=link_e.replace(/_s/g,"_b");
			if(src_e.width>=100) { return true; }
			show_uc(link_s,pos_x,pos_y);
			return false;
		}
	}
}
function hide_context(click){
	var uc = document.getElementById('uc');
	if(!uc) { return; }
	if(navigator.appName.indexOf('Microsoft')!=-1){
		uc.style.visibility='hidden';
		uc.style.display='none';
	}else{
		if(click.which==1){
			uc.style.visibility='hidden';
			uc.style.display='none';
		}
	}
}

function show_uc(link_s,pos_x,pos_y){
	var uc = document.getElementById('uc');
	if(!uc) { return; }
	uc_image.src='http://img2.epuls.pl/images/nothing.gif';
	uc_image.src=link_s;
	uc.style.visibility="visible";
	uc.style.display='block';
	uc.style.top=pos_y;
	uc.style.left=pos_x;
}
function get_gsm_logo(format,category,logo)
{
	window.open('gsm_logo_send_popup.php?format='+format+'&cat='+category+'&logo='+logo,'gsm_logo_popup','height=350,width=330,scrollbars=no');
}
function gf_validate_password(password)
{
	var allowedchars='abcdefghijklmnopqrstuvwxyz1234567890,.-;:_+!"@#£¤$%€&/{([)]=}?*';
	var illegalfound=false;
	var character='';
	if(password.length<5)
	return gv_password_error_to_short;
	if(password.length>20)
	return gv_password_error_to_long;
	for(var i=0;i<password.length;i++)
	if(allowedchars.indexOf(password.charAt(i).toLowerCase())==-1)
	return gv_password_error_character;
	return gv_password_error_no;
}
var gv_password_error_no=0;
var gv_password_error_to_short=-1;
var gv_password_error_to_long=-2;
var gv_password_error_character=-3;
function sprintf(str)
{
	var i;
	var arg;
	for(i=1;i<arguments.length;i++)
	{
		arg=arguments[i];
		switch(typeof(arg))
		{
			case 'number':
			str=str.replace(/%d/,arg);
			break;
			case 'boolean':
			str=str.replace(/%b/,arg);
			break;
			default:
			str=str.replace(/%s/,arg);
		}
	}
	return str;
}
function changeDisplay(object,type){
	if(!type||browser['app']=="IE"){type='block';}
	if(!object.style.display&&type){object.style.display==type;}
	if(object.style.display==type||object.style.display==""){
		object.style.display="none";
	}else{
		object.style.display=type;
	}
	repairScroll();
}
function swapBgColor(object,color){
	object.style.backgroundColor=color;
}
function setmood(){
	window.open('/mood_popup.php','epulsmood','width=430,height=320,status=no,scrollbars=yes');
}
function documentResolution(){
	var docRes=new Array();
	if(document.documentElement.clientHeight){
		docRes['h']=document.documentElement.clientHeight;
		docRes['w']=document.documentElement.clientWidth;
	}
	if(document.innerHeight){
		docRes['h']=document.innerHeight;
		docRes['w']=document.innerWidth;
	}else if(document.body){
		docRes['h']=document.body.clientHeight;
		docRes['w']=document.body.clientWidth;
	}
	return docRes;
}
function getBrowser(){
	var bro=navigator.appName;
	var ver=navigator.appVersion;
	var browser=new Array();
	if(bro.indexOf('Microsoft')!=-1){
		browser['app']='IE';
	}else if(bro.indexOf('Opera')!=-1){
		browser['app']='OP';
		var s = navigator.appVersion.split(" ");
		s[0] = s[0].replace(".", "");
		browser['ver']=s[0];
	}else if(bro.indexOf('Netscape')!=-1){
		browser['app']='FF';
	}else{
		browser['app']='UN';
	}
	return browser;
}

browser=getBrowser();

function realPos(object){
	if(object.offsetParent){
		var poX=object.offsetLeft
		var poY=object.offsetTop
		var ofW=object.offsetWidth;
		var ofH=object.offsetHeight;
		while(object=object.offsetParent){
			poX+=object.offsetLeft;
			poY+=object.offsetTop;
		}
		var pos=new Array()
		pos[0]=poX
		pos[1]=poY
		pos[2]=ofW;
		pos[3]=ofH;
		return pos;
	}
}
function setCloud(posX,posY,title1,title2){
	var cl=tCl.style
	cl.top=posY;cl.left=posX;
	document.getElementById('tClTl').innerHTML=title1
	document.getElementById('tClSbTl').innerHTML=title2
	cl.visibility='visible'
}
function showStarCloud(object,title1,title2){
	pos=realPos(object);
	posX=pos[0]+(object.offsetWidth/2);
	posY=pos[1]-44;
	setCloud(posX,posY,title1,title2)
}
function showKmCloud(object,title1,title2){
	pos=realPos(object);
	posX=pos[0]+object.width-3;
	posY=pos[1]-object.height+4;
	setCloud(posX,posY,title1,title2)
}
function showCloud(object,title1,title2){
	pos=realPos(object);
	posX=pos[0]+object.width-7
	posY=pos[1]-20
	setCloud(posX,posY,title1,title2)
}
function hideCloud(){
	tCl.style.visibility="hidden";
}
function printPng(image_src,w,h,title,cssClassName){
	browser=getBrowser();
	_title=(title==undefined||title=='')?'':'title="'+title+'"';
	_css=(cssClassName==undefined||cssClassName=='')?'':'class="'+cssClassName+'"';
	if(browser['app']=="IE"){
		image_text='<span '+_title+' '+_css+' style="width: '+w+'px; height: '+h+'px; display:inline-block; filter:progid:DXImageTransform.Microsoft.AlphaImageLoader(src=\''+image_src+'\', sizingMethod=\'scale\')"></span>'
		document.write(image_text);
	}else{
		document.write('<img src="'+image_src+'" width="'+w+'" height="'+h+'" '+_title+' '+_css+' />');
	}
}
function CenterPopup(ref,w,h){
	var xpos,ypos;
	if(ref.window.document.body){
		xpos=Math.round(ref.window.screenLeft+(ref.window.document.body.clientWidth/2)-((w+5)/2));
		ypos=Math.round(ref.window.screenTop+(ref.window.document.body.clientHeight/2)-((h+25)/2));
	}
	else{
		xpos=150
		ypos=150
	}
	xpos=xpos+Math.round(Math.random()*200-100);
	ypos=ypos+Math.round(Math.random()*200-100);
	return 'width='+w+',height='+h+',left='+xpos+',top='+ypos;
}

var ds_gemius_refresh_counter = 0;
function ds_gemius_timer () {
	var ds_gemius_now = (new Date()).getTime();
	setTimeout ('ds_gemius_timer()', 60*1000);
	ds_gemius_refresh_counter++;
	if (ds_gemius_refresh_counter==1) {
		ds_gemius_data="/redot.gif/id="+ds_gemius_code_hits+"/id="+ds_gemius_code_time+ds_gemius_parameters();
	} else {
		ds_gemius_data="/dot.gif/id="+ds_gemius_code_time;
	}
	ds_gemius_image.src = 'http://idm.hit.gemius.pl/_'+ds_gemius_now+ds_gemius_data;
}

function ds_gemius_parameters() {
	var d=document;
	var href=new String(d.location.href);
	var ref;
	if (d.referrer) { ref = new String(d.referrer); } else { ref = ""; }
	var t=typeof Error;
	if(t!='undefined') {
		eval("try { if (typeof(top.document.referrer)=='string') { ref = top.document.referrer } } catch(exception) { }")
	}
	var url='&tz='+(new Date()).getTimezoneOffset()+'&href='+escape(href.substring(0,299))+'&ref='+escape(ref.substring(0,299));
	if (screen) {
		var s=screen;
		if (s.width) url+='&screen='+s.width+'x'+s.height;
		if (s.colorDepth) url+='&col='+s.colorDepth;
	}
	return url;
}

function noOPScr() {
	if(window.devicePixelRatio) {
		$('stTopCn').style.width="100%";
		$('stTopCn').style.position='absolute';
	}

	if(browser['app']=="OP" && browser['ver']>=950) {
		var b = document.getElementsByTagName('body')[0];
		if(b.attachEvent) {
			b.attachEvent("onmousewheel", scrollCnMn);
			window.onscroll = function() {
				b.scrollTop=0;
			}
		}
	} else {
		var t = $('stTopCn');
		if(t.addEventListener) {
			t.addEventListener("DOMMouseScroll", scrollCnMn, false);
			t.addEventListener("mousewheel", scrollCnMn, false);
		} else if (t.attachEvent) {
			t.attachEvent("onmousewheel", scrollCnMn);
		}
	}
}

function scrollCnMn(e) {
	e = e ? e : window.event;
	var b = document.getElementById('stCnMn');
	var s = e.detail ? e.detail * -15 : e.wheelDelta / 2;
	b.scrollTop = b.scrollTop - s;
	scrollClear(e);
}

function scrollClear(e) {
	e = e ? e : window.event;
	if(e.stopPropagation)
	e.stopPropagation();
	if(e.preventDefault)
	e.preventDefault();
	e.cancelBubble = true;
	e.cancel = true;
	e.returnValue = false;
	return false;
}

var seo_lnks;
var seo_to;

function shSeoCl(cat, obj) {
	if(seo_to) { clearTimeout(seo_to); }

	var lnks = document.getElementById('cl_'+cat);

	if(typeof(seo_lnks)=="object" && seo_lnks!=lnks) {
		seo_lnks.style.display='none';
	}
	
	if(lnks) {
		lnks.style.display='block';	
		var divs = lnks.getElementsByTagName('div');
		seo_lnks = lnks;
		
		object=obj;

		var obj_y = object.offsetTop;
		var obj_x = realPos(obj)[0]-document.getElementById('stCn').offsetLeft;

		if(obj_y==0) { obj_y=8; }

		while(object=object.offsetParent){
			if(object.id=="stCn") {
				break;
			}
			if(object.id) {
				obj_y+=object.offsetTop;
			}
		}
		obj.onmouseout=hdSeoCl;
		lnks.onmouseover=function() {
			if(seo_to) { clearTimeout(seo_to); }
		}
		lnks.onmouseout=function() {
			if(typeof(seo_lnks)=='object') {
		                seo_to = setTimeout('hideSeo()', 400);
        		}
		}

		for(var a = 0; a<divs.length; a++) {
			if(divs[a].className=="arr") {
				var d_arr = divs[a];
			}
			if(divs[a].className=="cn") {
				var d_cn = divs[a];
			}
		}

		d_arr_l=(obj_x-3);

		if((d_arr_l+d_arr.offsetWidth)>d_arr.offsetParent.offsetWidth) {
			d_arr_l=d_cn.offsetLeft+d_cn.offsetWidth-d_arr.offsetWidth-2;
		}

		d_arr.style.left=d_arr_l+'px';

		var p = realPos(obj);

		lnks_t=document.getElementById('stCn').offsetHeight-lnks.offsetHeight-85;

		lnks.style.top=lnks_t+'px';
	}

}

function hdSeoCl() {
	if(typeof(seo_lnks)=='object') {
		seo_to = setTimeout('hideSeo()', 400);
	}
}

function hideSeo() {
	if(typeof(seo_lnks)=='object') {
		seo_lnks.style.display='none';
	}
}

function scrollCn(pos, o)
{
	if(!o) { var o = 'stCnMn'; } else {
		document.getElementsByTagName('body')[0].scrollTop=(pos == undefined ? 0 : pos);
	}
	document.getElementById(o).scrollTop = (pos == undefined ? 0 : pos);
}

function scrollTo(obj, o) {
	if(typeof(obj)=='string') {
		obj = document.getElementById(obj);
	}

	if(obj) {
		var p = realPos(obj);
		var y = p[1] - 127;
		scrollCn(y, o);
	}
}
var win= null;
function popupLauncher(title,link,w,h){
	var winl = (screen.width-w)/2;
	var wint = (screen.height-h)/2;
	var settings ='height='+h+',';
	settings +='width='+w+',';
	settings +='top='+wint+',';
	settings +='left='+winl+',';
	settings +='scrollbars=yes,';
	settings +='resizable=no';
	win=window.open(link,title,settings);
	if(parseInt(navigator.appVersion) >= 4){win.window.focus();}
}
