// ----- iBrowser

var iBrowser={Family:false};
if (typeof(window.opera)!='undefined')
	iBrowser.Family='opera';
else if (navigator.plugins.length>0)
	iBrowser.Family='mozilla';
else if (navigator.appName=='Microsoft Internet Explorer')
	iBrowser.Family='msie';
	
// -----

function iDocumentReload() {
	var form=document.forms[0];
	if (!form) return;
	document.forms[0]['Step'].value='Update';
	form.submit();
}

function iFormReload(form) {
	var step=form[(document.iDocumentPrefix?document.iDocumentPrefix:'')+'Step'];
	if (step)
		step.value='Update';
	form.submit();
}

function iDump(v) {
	var t='';
	for(e in v) {
		x=v[e]
		if (typeof(x)=='function')
			{}//t+=e+'=[function]; ';
		else if (typeof(x)=='object')
			{}//t+=e+"=[object];\n";
		else if (typeof(x)=='string')
			{}//t+=e+"="+x+";\n";
		else
			t+=e+'='+x+";\n";
	}
	alert(t);
}

document.iShopList=[];
function iShopShow(id) {
	for(i=0;i<document.iShopList.length;i++) {
		var div=document.getElementById('Shop_'+document.iShopList[i]);
		div.style.display=(document.iShopList[i]==id ? 'block' : 'none');
	}
}

document.iHints=[];
function iHints() {
	document.iHintClass=(iBrowser.Family=='msie'?'Hint-MSIE':'Hint');
	var list=document.getElementsByTagName('A');
	for(i=0;i<list.length;i++)
		if (list[i].className.indexOf('Hint')>=0) {
			var a=list[i];
			if (a.name!='') {
				a.onmouseover=iHintOver;
				a.onmouseout=iHintOut;
				document.iHints.push(a);
			}
		}
	var html='';
	html+='<div id=Hint class=Hint-Hidden><div class=Hint-Header><div id=Hint-Body class=Hint-Body></div></div><div class=Hint-Footer></div></div>';
	document.write(html);
	document.iHintBody=document.getElementById('Hint-Body');
	document.iHintWindow=document.getElementById('Hint');
}

function iPosition(element) {
	var x=0;var y=0;
	html='';
	while (element) {
		html+=element.tagName+'.'+element.id+'('+element.style.display+')'+'='+element.offsetTop+',';
		if ((element.tagName!='TR')&&(element.tagName!='TBODY'))
			x+=element.offsetLeft;
		y+=element.offsetTop;
		if (element!=document.body)
			element=element.parentNode;
		else
			break;
	}
	//alert(html);
	return({X:x,Y:y});
}

function iHintOver() {
	document.iHintBody.innerHTML=this.name;
	document.iHintWindow.className=document.iHintClass;
	var x=0;var y=0;var dy=this.offsetHeight;
	var element=this;
	while (element) {
		if ((element.tagName!='TR')&&(element.tagName!='TBODY'))
			x+=element.offsetLeft;
		y+=element.offsetTop;
		if (element!=document.body)
			element=element.parentNode;
		else
			break;
	}
	if (document.getElementById('sitebodyB'))
		x-=80;
	document.iHintWindow.style.left=(x)+'px';
	document.iHintWindow.style.top=(y+dy)+'px';
}

function iHintOut() {
	document.iHintWindow.className='Hint-Hidden';
}

// --- iContext ---

document.iContexts={};
function iContexts() {
	document.iContextClass=(iBrowser.Family=='msie'?'Context-MSIE':'Context');
	var list=document.getElementsByTagName('DIV');
	for(i=0;i<list.length;i++)
		if ((list[i].className.indexOf('ContextArea')>=0)&&(!document.iContexts[list[i].id])) {
			var div=list[i];
			var panel=document.getElementById(div.id+'-ContextPanel');
			if ((panel)&&(div.id!='')) {
				div.iContextPanel=panel;
				var html=div.iContextPanel.innerHTML;
				html='<div class=Context-Header><div class=Context-Body>'+html+'</div></div><div class=Context-Footer></div>';
				div.iContextPanel.innerHTML=html;
				div.iContextPanel.className='Context-Hidden';
				div.onmouseover=iContextOver;
				div.onmouseout=iContextOut;
				document.iContexts[div.id]=div;
			}
		}
}

function iContextOver(e) {
	//var p=iPosition(this);
	if (iBrowser.Family=='msie') {
		p=iPosition(this);
		q=iPosition(this.iContextPanel.parentNode);
		p.X=p.X-q.X;
		p.Y=p.Y-q.Y;
	} else
		p={X:this.offsetLeft,Y:this.offsetTop};
	//alert(this.offsetLeft);
	this.iContextPanel.style.left=(p.X+20)+'px';
	this.iContextPanel.style.top=(p.Y+40)+'px';
	//this.iContextPanel.style.display='block';
	this.iContextPanel.className=document.iContextClass;
}

function iContextOut(e) {
	this.iContextPanel.className='Context-Hidden';
	//this.iContextPanel.style.display='none';
}

// --- iFlash ---

function iFlashHtml(src,width,height,id,bgcolor,flashvars) {
	/*var vars=[];
	for(e in flashvars) {
		vars.push(e+'='+iFlashEscape(flashvars[e]));
	}
	vars=vars.join('&');*/
	
	var html='';
	/*if (id) {
		html+='<SCRIPT LANGUAGE=VBScript\> \n';
		html+='on error resume next \n';
		html+='Sub '+id+'_FSCommand(ByVal command, ByVal args)\n';
		html+='  call '+id+'_DoFSCommand(command, args)\n';
		html+='end sub\n';
		html+='</SCRIPT\>';
	}*/
	html+='<object type="application/x-shockwave-flash"';
	html+='   width="'+width+'px"';
	html+='   height="'+height+'px"';
	if (id) {
		html+='   id="'+id+'"';
		html+='   name="'+id+'"';
	}
	html+='   data="'+src+'">';
	html+='<param name=movie value="'+src+'">';
	html+='<param name=flashvars value="'+flashvars+'">';
	html+='<param name=quality value=high>';
	html+='<param name=menu value=false>';
	if (bgcolor=='transparent')
		html+='<param name=wmode value=transparent>';
	else if (bgcolor)
		html+='<param name=bgcolor value='+bgcolor+'>';
	html+='</object>';
	//alert(html);
	return(html);
}

function iFlashGenerate(src,width,height,id,bgcolor,flashvars,install) {
	var html='';
	if ((!install)||(iFlashVersion()>=6)) {
		html+=iFlashHtml(src,width,height,id,bgcolor,flashvars);
	} else if (install) {
		html+='<p>Do prawidłowego działania serwisu wymagany jest plugin Macromedia Flash 6 lub nowszy.</p><p>';
		html+=iFlashHtml('layout/flash.swf',70,70,'href=index.php');
		html+='</p><p>Nie widzisz animacji? Zainstaluj plugin:</p><p>';
		html+='<a href="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" target=_blank><img src="layout/flash.gif" width=75 height=75></a>';
		html+='</p>';
	}
	document.write(html);
}

function iFlashVersion() {
	var i,v=0;
	if (navigator.plugins.length) {
		var p=navigator.plugins;
		if ((p)&&(p.length>0)&&(p['Shockwave Flash']))	{
			var w=p['Shockwave Flash'].description.split(' ');
				for(i=0;i<w.length;i++) {
					var j=parseInt(w[i]);
					if (!isNaN(j))
						v=Math.max(v,j);
				}
		}
		return(v);
  	} else {
		for(v=10;v>0;v--) {
			var x=null;
			try {
				x=new ActiveXObject("ShockwaveFlash.ShockwaveFlash."+v);
			} catch(e) {}
			if (x) return(v);
		}
		return(0);
	}
}

function iImageZoom(src,dx,dy) {
	var sx=(window.screen.width-dx)/2;
	var sy=(window.screen.height-dy)/2;
	dx+=20;
	dy+=20;
	window.open(src,'','width='+dx+',height='+dy+',innerWidth='+dx+',innerHeight='+dy+',left='+sx+',top='+sy);
}

function iPrint(url) {
	window.open(url,'','width=640,height=480,resizable,scrollbars,status');
}

function iRowInit(formid,id,count) {
	var html='';
	html+='<input type=hidden name="'+id+'_Count" value="0"><div class="PageList">';
	html+='<a href="javascript://" onclick="iRowAdd(\''+formid+'\',\''+id+'\')" class="more">nowy wiersz</a> ';
	html+='<a href="javascript://" onclick="iRowDelete(\''+formid+'\',\''+id+'\')" class="more">usuń ostatni wiersz</a></div>';
	document.write(html);
	for(i=1;i<=count;i++)
		iRowAdd(formid,id);
}

function iRowAdd(formid,id) {
	var form=document.forms[formid];
	var count=parseInt(form.elements[id+'_Count'].value);
	count++;
	var div=document.getElementById(id+'-'+count);
	if (div) {
		form.elements[id+'_Count'].value=count;
		//form.elements[id+'_'+count].value='1';
		div.style.display='block';
	}
}

function iRowDelete(formid,id) {
	var form=document.forms[formid];
	var count=parseInt(form.elements[id+'_Count'].value);
	if (count>0) {
		var div=document.getElementById(id+'-'+count);
		div.style.display='none';
		//form.elements[id+'_'+count].value='';
		count--;
		form.elements[id+'_Count'].value=count;
	}
}

function iBookOpen(pages) {
	var s='';
	for(var i=0;i<pages.length;i++) {
		if (i>0)
			s+=',';
		s+=pages[i];
	}

	var dx=640;
	var dy=440;	
	var sx=(window.screen.width-dx)/2;
	var sy=(window.screen.height-dy)/2;
	dx+=20;
	dy+=20;
	window.open('book.php?pages='+escape(pages),'Book','width='+dx+',height='+dy+',innerWidth='+dx+',innerHeight='+dy+',left='+sx+',top='+sy+',resizable');
}

function iRightBack(text,separator) {
  var p=text.lastIndexOf(separator);
  if (p>=0)
  	return(text.substr(p+separator.length));
  else
  	return(text);
}

function iBannerSkyscrapper(banners) {
	var r=Math.floor(Math.random()*banners.length);
	banner=banners[r];
	dx=160;
	dy=600;
	if(banner.format=='swf') {
		iFlashGenerate(banner.src,dx,dy,false,'transparent','click='+escape(banner.url)+'&clicktag='+escape(banner.url)+'&gdaclick='+escape(banner.url),false);
	} else {
		var t='';
		if (banner.url)
			t+='<a href="'+banner.url+'">';
		t+='<img src="'+banner.src+'" alt="" style="width:'+dx+'px;height:'+dy+'px;">';
		if (banner.url)
			t+='</a>';
		document.write(t);
	}
}
