/**
 * @namespace adv.js
 * @author Pawel Knapik
 */

 if(typeof adv == 'undefined')
 var adv = {
 	version : '0.8',
	init : function() {
		addClass(document.documentElement,'js')
	}
 }

Array.prototype.inArray=function(v){for(var i=this.length-1;i>=0;i--)if(this[i]===v)return true;return false}
Array.prototype.unique=function(){var t=[];for(var i=0,j=this.length;i<j;i++) t.inArray(this[i])?'':t.push(this[i]);return t;}

/** @id getElementsByClass */
function getElementsByClass(s,n,t) {
	var c=[],e=(n?n:document).getElementsByTagName(t?t:'*'),r=new RegExp("(^|\\s)"+s+"(\\s|$)");
	for(var i=0,j=e.length;i<j;i++)r.test(e[i].className)?c.push(e[i]):'';return c}
	
/** @id dollar */
$ = function(){
	var r=[],a=arguments;for(var i=0,j=a.length;i<j;i++){(typeof a[i]=='string')?(r.push(document.getElementById(a[i]))):(r.push(a[i]))}
	return(r.length==1)?r[0]:r
}
/** @id addEvent */
function addEvent(O,E,F,x){
	O=O.length?O:[O];var i=O.length;
	while(i--){O[i].addEventListener?O[i].addEventListener(E,F,1):(x=O[i].attachEvent)?x('on'+E,F):''}
}
/** @id hasClass */
function hasClass(e,c) { return RegExp("(^|\\s)"+c+"(\\s|$)").test(e.className)?true:false; }

/** @id replaceClass */
function replaceClass(e,c,cc) { if(hasClass(e,cc))cc=''; e.className=e.className.replace(RegExp("(^|\\s)"+c+"(\\s|$)"),' '+cc); }

/** @id addClass */
function addClass(e,c) { if(!hasClass(e,c)) e.className=e.className+=(' '+c) }

/** @id toggle */
function toggleClass(e,a,b) { hasClass(e,a)?replaceClass(e,a,b):replaceClass(e,b,a) }

/*Subskrypcja*/

function dodaj(){
	okno = window.open('','','width=400,height=300,left=50,top=50');
	with(document.subform) {
		jump=action+'?job=dodaj_email&email='+(email.value)+'&lista='+(lista.value)+'&redirect_brak_emaila='+(redirect_brak_emaila.value)+'&redirect_email_niepraw='+(redirect_email_niepraw.value)+'&redirect_email_juz_jest='+(redirect_email_juz_jest.value)+'&redirect_dodano='+(redirect_dodano.value)+'&redirect_usunieto='+(redirect_usunieto.value)+'&redirect_brak_w_bazie='+(redirect_brak_w_bazie.value)
	}
	okno.location = jump;
}
function usun(){
	okno = window.open('','','width=400,height=300,left=50,top=50');
	with(document.subform) {
		jump=action+'?job=usun_email&email='+(email.value)+'&lista='+(lista.value)+'&redirect_brak_emaila='+(redirect_brak_emaila.value)+'&redirect_email_niepraw='+(redirect_email_niepraw.value)+'&redirect_email_juz_jest='+(redirect_email_juz_jest.value)+'&redirect_dodano='+(redirect_dodano.value)+'&redirect_usunieto='+(redirect_usunieto.value)+'&redirect_brak_w_bazie='+(redirect_brak_w_bazie.value)
	}

	okno.location = jump;
}

/*do subskrypcji*/
function submitSubscription(formObject) {
	dodaj();
	return false;
}

/* nowe okno */
var newWin = function(a) {
	for(var i=a.length-1;i>=0;i--) {
		if(a[i].href.indexOf('.pdf')>0||a[i].href.indexOf('.ppt')>0||a[i].href.indexOf('.doc')>0||a[i].href.indexOf('.txt')>0||a[i].href.indexOf('.xls')>0||a[i].href.indexOf('.html')>0||a[i].href.indexOf('_generate')>0||!a[i].href.indexOf('arbomedia.pl')>0) {
			a[i].setAttribute('target','_blank');
		}
		if(a[i].href.indexOf('.jpg')>0) {
			a[i].onclick=function(){ popup(this.href); return false; }
		}
	}
}

function popup(img) {
	foto1= new Image();
	foto1.src=img;
	conl(img);
}

function viewFoto(img) {
	var foto1,sz,wys,left,wywolaj,tp,tmp;
	foto1 = new Image();
	foto1.src = img;
	sz = foto1.width;
	wys = foto1.height;
	left = Math.floor((screen.width-sz)/2);
	tp = Math.floor((screen.height-wys)/2);
	wywolaj = "width="+sz+",height="+wys+",top="+tp+",left="+left;
	newwindow=window.open('','newwindow',wywolaj);
	tmp = newwindow.document;
	tmp.writeln('<html><head>');
	tmp.writeln('<meta http-equiv="Content-Type" content="application/xhtml+xml; charset=utf-8" />');
	tmp.writeln('<title>popup</title>');
	tmp.writeln('<!--[if IE]><meta http-equiv="imagetoolbar" content="no" /><meta name="MSSmartTagsPreventParsing" content="true" /><![endif]-->');
	tmp.writeln('</head><body style="margin:0;padding:0"><a href="javascript:self.close()"><img src="' + img + '" alt="" border="0"></a></body></html>');
	tmp.close();
}

function conl(img) {
	if( (foto1.width!=0) && (foto1.height!=0) ) {
		viewFoto(img);
	}
	else {
		fun="conl('"+img+"')";
		inter=setTimeout(fun,20);
	}
}

