//biblioteka JS strony http://canoe.art.pl. Autor: Piotr Romanowski (http://www.proteq.net) COPYRIGHT 2003,2004  - wszelkie prawa zastrzeżone.

var d=document,ie=d.all&&!window.opera,dom=d.getElementById,ie4=ie&&!dom,ION=[],IOFF=[],s=[],SITE='',SCROLLER=0,j=0;

function checkJS(a,p){p=d.body;a='/browser.php?b='+escape(navigator.userAgent);
if(ie&&!dom){p.insertAdjacentHTML('BeforeEnd','<iframe src="'+a+'" />')}else{c=d.createElement('iframe');c.src=a;c.style.display='none';p.appendChild(c);}}


onload=function(){

	if (self != top) top.location.href = self.location.href;
//checkJS()
}
function getTag(o,t){return ie4?t=='*'?o.all:o.all.tags(t):o.getElementsByTagName(t)}
function getEl(o){return ie4?d.all[o]:d.getElementById(o)}
function getPar(o){return dom?o.parentNode:ie4?o.parentElement:o}


function img(n,u,w,h,W){
	W=window.open('/foto/klik_count.php?akcja=dodaj&szer='+w+'&wys='+h+'&kat='+n+'&zdj='+u,'','left=0,top=0,width='+w+',height='+h+',innerheight='+h+',innerwidth='+w+',resizable=yes')
	return W.opener&&W.opener==self;
}
function wopen(u,w,h,W)
{
	W=window.open(u,'','left=0,top=0,width='+w+',height='+h+',innerheight='+h+',innerwidth='+w+',resizable=yes')
	return!W.opener&&W.opener==self;
}
function showImg(u)
{
	var s=u.match(/([^#]+)#([0-9]+),([0-9]+)/)
	return wopen(s[1], s[2], s[3]);
}

function go_url(url){location.href=url}

function setOnclickEvent(id)
{
	var imgs = getTag(getEl(id),'a');
	for(var i=0,c=imgs.length;i<c;i++)
	{
		if(getPar(imgs[i]).tagName.toLowerCase() == 'li')
		{
			imgs[i].onclick=function(){return showImg(this.href)}
		}
	}
}

function loadMenu()
{
	if(!dom||!ie)return;
	var div = getTag(getEl('pm'),'div');
	for(var i=0,c=div.length;i<c;i++)
	{
	try
	{
		div[i].getElementsByTagName('table')[0].style.width = (div[i].offsetWidth + 1) + 'px';
	}
	catch(e){}
	  	div[i].onmouseover=function(){this.className='over';this.firstChild.className='h';}
		div[i].onmouseout=function(){this.firstChild.className='';this.className=''}
	}
}

function setURollover(id)
{
//fix dla IE, który nie potrafi przesuwać tła nie migocząc ;)
	if(!ie)return
	var img=getTag(getEl(id), 'img')
	for(var i=0,c=img.length;i<c;i++)
	{
		if(img[i].src.lastIndexOf('_off'))
		{
			with(IOFF['u'+i] = new Image)src = img[i].src
			with(ION['u'+i] = new Image)src = img[i].src.replace('_off', '_on')
			img[i].id = 'u'+i
		}
		img[i].onmouseover = function(){this.src = ION[this.id].src}
		img[i].onmouseout = function(){this.src = IOFF[this.id].src}
		
	}
}
function ieHover(id, tag, el)
{
//fix dla IE, który nie obsługuje :hover ;)
	//if(!ie)
	return
	el=getTag(getEl(id), tag)
	for(var i=0,c=el.length;i<c;i++)
	{
		el[i].onmouseover = function(){this.style.padding='10px'}
	}	
}

/*
function oNas(id, o){
	for(var i=0,c=onas.length;i<c;i++)
	{
	if(onas[i].className == 'onas'){onas[i].style.display='none';}
	}
		for(var i=0,c=LI.length;i<c;i++)
		{
			LI[i].id=LI[i].id.replace('h','')
		}
o.parentNode.id = o.parentNode.id+'h'
oTmp=o
o.blur()
	return getEl(id).style.display='block';
}
*/
var AJAX_RESPONSE_OBJECT = {}
function akordy(o, url)
{
	url=o.href;
	var conn = false
	var idx = parseInt(url.slice(url.lastIndexOf('/')+1))
	var plus = idx<12?idx+1:1;
	var minus = idx>-12?idx-1:-1;
	AJAX_RESPONSE_OBJECT = getEl("akordy")
	conn = connect(url.replace('utwory/teksty/','akordy/'))
				
   getEl('uplus').href = url.slice(0, url.lastIndexOf('/')+1) + plus
   getEl('uminus').href = url.slice(0, url.lastIndexOf('/')+1) + minus
   return conn
}
function koncerty(o)
{
	var conn = false
	AJAX_RESPONSE_OBJECT = getEl("klista")//ze względu na IE trzeba podmienic cala tabele :/
	conn = connect(o.href.replace('koncerty/','ws_koncerty/')+('/'+(new Date()).getTime()))//ze względu na cache IE
	var kma = getTag(getEl('km'), 'a');
	for(var i=0,c=kma.length;i<c;){kma[i++].className=''}
	o.className ='on';
	o.blur()
	return conn
}

//AJAX

function response()
{
	if (http_request.readyState == 4) {
                    if (http_request.status == 200) {
                        AJAX_RESPONSE_OBJECT.innerHTML = http_request.responseText;
                        try{getEl('wait').style.visibility='hidden'}catch(e){}
                    } 
                }
}
var http_request = false;

function connect(url)
{
	try{getEl('wait').style.visibility='visible'}catch(e){}
	http_request = false;
   if (window.XMLHttpRequest){ // Mozilla, Safari,...
            http_request = new XMLHttpRequest();
            if (http_request.overrideMimeType){
                http_request.overrideMimeType('text/xml');
            }
        } else if (window.ActiveXObject){ // IE
            try {
                http_request = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try {
                    http_request = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){}
            }
        }
        if (!http_request){
            return false;
        }
        http_request.onreadystatechange = response;
        http_request.open('GET', url, true);
        http_request.send(null);
		return true
}
function email(container){
	if(!dom)return;
var content=getEl(container);
content.innerHTML = content.innerHTML.replace(/ ([^(MAŁPA)|\s]+)MAŁPA([^\s]+)/g, ' <a href="mailto:$1@$2">$1@$2</a>')
}
function ne(t){return t>''}
function phoneOrMail(t,f){return phone(f['phone'].value,f)|isMail(f['email'].value,f)}
function phone(t,f){return t>''}
function isUrl(t,f){return /^(https?:\/\/)?[\w\.-]+\.[a-z]{2,5}$/i.test(t)}
function isMail(t,f){return /^[\w\.-]{2,}@[\w\.-]+\.[a-z]{2,5}$/i.test(t)}
var vtmp
function validate(f,s,a,e,ac){
 for(a=0;e=f[a++];){
 	ac=e.alt.split('|');
 	if(vtmp)vtmp.className=vtmp.className.replace(' e', '');if(ac[1])vtmp=e;
  if((s=self[ac[0]])&&!s(e.value,f))
   {e.className +=' e';alert(ac[1]);return!e.focus()}}
}

function oNas(m1, m2) {
	var am1 = getTag(getEl(m1), 'a')
	
	for (var i=0, c=am1.length; i<c;i++) {
		am1[i].rel = 'o'+(i+1)
		am1[i].onmouseover=function(){getEl(this.rel).className = 'h'}
		am1[i].onmouseout=function(){getEl(this.rel).className = ''}
	}
}
