// gram.pl
// skrypty wspolne

function Login () {
	document.fLogin.submit()
}

function Wyloguj() {
	document.flogout.submit()
}

function m_on (p,mt) {
  p.style.backgroundColor='#eeeeee'
  p.style.cursor='pointer'
  if (mt != 0) p.style.color='#555555'
}

function m_off (p,mt) {
  p.style.backgroundColor=''
  if (mt != 0) p.style.color='#035A85'
}

function mf_on (p,mt) {
	var o = document.getElementById(p);
	o.style.backgroundColor='#eeeeee'
	o.style.cursor='pointer'
	if (mt != 0) o.style.color='#555555'
}

function mf_off (p,mt) {
	var o = document.getElementById(p);
	o.style.backgroundColor=''
	if (mt != 0) o.style.color='#035A85'
}

function trans_on (p) {
  p.style.filter='alpha(opacity=92)'
  p.style.opacity='0.92'
  p.style.cursor='pointer'
}

function trans_off (p) {
  p.style.filter='alpha(opacity=100)'
  p.style.opacity=1
}

function m_h (p) {
  p.style.cursor='pointer'
}

function OpenWindow (w_sLink,w_sName,w_iWidth,w_iHeight) {
	var win = window.open(w_sLink,w_sName,'width='+ w_iWidth +',height='+ w_iHeight +',sizable=no,status=no');
}


function DodajKomentarz(iID,iNewsID,iTyp) {
	OpenWindow ('forum_dodaj_komentarz.asp?tid=' + iID + '&nid=' + iNewsID + '&mid='+ iTyp,'',707,356);
}

function DodajRecenzje(iGID,iTyp,iRodzaj) {
	var t = '';
	if (!isNaN(iTyp)) t = '&t='+ iTyp;
	if (!isNaN(iRodzaj)) t = t + '&tr='+ iRodzaj;
	OpenWindow ('gra_recenzje_dodaj.asp?gid=' + iGID + t,'',707,356);
}


function Zaloguj(sLink) {
	window.location = 'login_01.asp?r=' + sLink;
}

function Tutorial(id) {
	OpenWindow ('pomoc/tutorial_' + id + '_01.html','','568','390');
}

function changeAvatar() {
	OpenWindow ('konto_avatar.asp','',707,356);
}

function menu(mID,aID)
{
	aIMG = new Array('pomoc','sklep','forum','kolektyw','gramsajty','gramirc','konkursy','flaszki');
	var sTmp = '';
	if (aID == 1) sTmp = 'a';
	document.getElementById('m_' + aIMG[mID - 1]).src = 'www/01/img/menu_' + aIMG[mID - 1] + sTmp + '.gif?h=1';
}

function sf(fInput,e) {
	var keycode;

	if (window.event)
		keycode = window.event.keyCode;
	else if (e)
		keycode = e.which;
	else
		return true;
	
	if (keycode == 13) {
		fInput.form.submit();
		return false;
	} else
		return true;
}

function fGo(form) {
	document.getElementById(form).submit();
}

function GoToEnd() {
	var sLink = location.href;
	if (sLink.indexOf('#end') == -1) sLink = sLink + '#end';
	location.href = sLink;
}


function setCookie(c_sName, c_sValue) {
	exdate = new Date;
	exdate.setDate(exdate.getDate()+300);
	document.cookie= c_sName + '=' + c_sValue + ';expires=' + exdate.toGMTString() + ';path=/';
}

function getCookie(c_sName) {
	var sCookie = c_sName + "=";
	var sCookies = document.cookie.split(';');
	for(var i=0;i<sCookies.length;i++) {
		var sTmp = sCookies[i];
		while (sTmp.charAt(0)==' ') sTmp = sTmp.substring(1,sTmp.length);
		if (sTmp.indexOf(sCookie)==0) return sTmp.substring(sCookie.length,sTmp.length);
	}
	return null;
}

//------------------ Tooltip ------------------//

function getAP(i){
  x=y=0;
  do { x+=i.offsetLeft; y+=i.offsetTop; } 
  while (i=i.offsetParent);
  return {x:x,y:y}
} 

function checkToolTip(event) {
  var obj = document.getElementById('tooltip');
  if ((event.offsetX>=parseInt(obj.style.width)-1) || 
	  (event.offsetY>=parseInt(obj.style.height)-1)) 
	  hideToolTip()
}

function showToolTip(p, txt, move) {
	if (!txt)
	{
		return false;
	}
	var obj = document.getElementById('tooltip');
	kor = document.body.clientWidth-952
	if (kor<0) kor = 0; else kor = kor / 2

	obj.style.left=(p.x - kor + 20)+'px';
	obj.style.top=(p.y + 20)+'px';
	obj.innerHTML='<div id="ptxt" style="padding:5px;display:none;">'+txt+'</div>';
	TT(1,1);
	obj.style.display='inline';
}
function hideToolTip() {
	var obj = document.getElementById('tooltip');
	if (document.getElementById('ptxt'))
	{
	document.getElementById('ptxt').style.display='none';
	}
	obj.style.display='none';

}

function TT(i,j) {
  var obj = document.getElementById('tooltip');
  obj.style.width=i+'px';
  obj.style.height=j+'px';

  
  /* Mozilla Fix { */
  var c = obj.innerHTML.replace(/<[^>]*>/ig, "")
  t = c.length
  jInc = 6;
  if (t>160) jInc = 9; 
  if (t>260) jInc = 12;
  if (t>360) jInc = 15;
  if (t>700) jInc = 16;
  /* } */

  if (i<300) {
	setTimeout('TT('+(i+50)+','+(j+jInc)+')',25);
  } else {
	document.getElementById('ptxt').style.display='block';
  }
}
function TTh(i,j) {
  var obj = document.getElementById('tooltip');
  obj.style.width=i+'px';
  obj.style.height=j+'px';
  if (i>=60 && j>=5) {
	setTimeout('TTh('+(i-60)+','+(j-5)+')',20);
  } else {
	obj.style.display='none';	
	
  }
}


// zwraca obiekt o zadanym id
function $(id) {
	return document.getElementById(id);
}

// -- end --


var sel	=	new Array(0);

function mOver(o,n,sr,sif) {
//	var isr = Math.round(sr);
	var isr = Math.floor(sr);
	var osr = Math.round(sr);

	var n = n.replace(/,/,'.');
	n = Math.round(n);
	if (sel[o]) return false;
	
	for (i=1;i<=5;i++) {
		$(o+i).src='/www/01/img_sklep/ico_star_off.gif'
	}
	
	if (sif)
	{
	for (i=1;i<=isr;i++) {
		$(o+i).src='/www/01/img_sklep/ico_star.gif'
	}

	for (i=isr+1;i<=osr;i++) {
		$(o+i).src='/www/01/img_sklep/ico_star_half.gif'
	}

	} 
	else 
	{
		for (i=1;i<=n;i++) {
			$(o+i).src='/www/01/img_sklep/ico_star.gif'
		}

	}
	
}

function mOut(o,n,sr) {
	var isr = Math.floor(sr.replace(/,/,'.'));
	var osr = Math.round(sr.replace(/,/,'.'));
	if (sel[o]) return false;
	for (i=1;i<=n;i++) {
		$(o+i).src='/www/01/img_sklep/ico_star_off.gif'
	}
	for (i=1;i<=isr;i++) {
		$(o+i).src='/www/01/img_sklep/ico_star.gif'
	}

	for (i=isr+1;i<=osr;i++) {
		$(o+i).src='/www/01/img_sklep/ico_star_half.gif'
	}
}

function mClick(typ,o,n,id,uid,sr) {
	var isr = Math.round(sr);
	if (sel[o]) return false;

	advAJAX.get({
		url: 'news_ocen.asp?typ='+typ+'&id='+id+'&uid='+uid+'&ocena='+n,
		onSuccess : function(obj) 
		{
				if (obj.responseText == 'err1') 
				{
					 alert('Już raz oddano głos na ten artykuł');
					 sel[o] = false; 
					 sr = sr.replace(/,/,'.')
					 mOver(o, sr, sr, true);
					 sel[o] = true; 
				} 
				else 
				{
					 //$('spnSrednia').innerHTML = obj.responseText.split('|')[0];
					 $('spnIlosc').innerHTML = obj.responseText.split('|')[1];
				}
		}
	});

	sel[o]=n
}

// -----------------------------------------------------------------------------------

//
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org
//
function getPageScroll(){

	var yScroll;

	if (self.pageYOffset) {
		yScroll = self.pageYOffset;
	} else if (document.documentElement && document.documentElement.scrollTop){	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	} else if (document.body) {// all other Explorers
		yScroll = document.body.scrollTop;
	}

	arrayPageScroll = new Array('',yScroll)
	return arrayPageScroll;
}

// -----------------------------------------------------------------------------------

//
// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez
//
function getPageSize(){

	var xScroll, yScroll;

	if (window.innerHeight && window.scrollMaxY) {
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;
	if (self.innerHeight) {	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	} else if (document.body) { // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight){
		pageHeight = windowHeight;
	} else {
		pageHeight = yScroll;
	}

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth){
		pageWidth = windowWidth;
	} else {
		pageWidth = xScroll;
	}


	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
	return arrayPageSize;
}

function u_tabSwitch(tabDiv, tabOffset){
	if(!$(tabDiv))
		return;
	var tabList = $(tabDiv).getElementsByTagName('div');
	var tabCount = tabList.length, i;
	var tabLast = Math.floor(tabCount / 2);
	for(i = 0;i < tabCount;i++){
		if(i % 2 !== 0){
			tabList[i].className = 'tm';
		}
		else{
			if(i === 0)
				tabList[i].className = 't1';
			else
				tabList[i].className = 't3';
		}
	}
	tabList[tabCount-1].className = 't2';
	tabList[(tabOffset - 1) * 2 + 1].className = 'tm ta';
	if(tabOffset === 1)
		tabList[(tabOffset - 1) * 2].className = 't1 t6';
	else
		tabList[(tabOffset - 1) * 2].className = 't3 t4';
	if(tabOffset === tabLast)
		tabList[(tabOffset - 1) * 2 + 2].className = 't3 t7';
	else
		tabList[(tabOffset - 1) * 2 + 2].className = 't3 t5';
}

// -----------------------------------------------------------------------------------
