D=document;
function selectAll(a,b,q){
	inp = D.getElementsByName(a);
	for(q=0;q<inp.length;q++) inp[q].checked=(b.checked==1)?1:0;
	return true;
}
function openPopUp(url,id,width,height,extra){
	if(extra!==''){
		opt = extra;
	}else{
		opt = 'status=no,location=no,menubar=no,toolbar=no';
	}
	return window.open(url,id,'top=150,left=200,width='+width+',height='+height+','+opt);
}
function popUp(url,windowName,windowTitle,closeOnClick,width,height,t){
	if(!url)return
	function readSize(){if(t.complete)showPopup(t.width,t.height);else setTimeout(readSize,1e2)}
	function showPopup(w,h){with(window.open('',windowName||'','width='+(width||w)+',height='+(height||h)+',top=0,left=0,scrollbars=yes').document){open();write('<html><head><title>'+(windowTitle||'')+'</title></head><body style="margin:0;padding:0"><img src="'+url+'" style="display:block'+(closeOnClick?';cursor: pointer" onclick="self.close()" title="Zamknij okno"':'"')+'></body></html>');close()}}
	if(!width||!height)t=new Image(),t.src=url,readSize()
	else showPopup(width,height)
}

function checkInputs(a,i,q,x){
	inp = ['input','textarea','select'];
	for(i=x=0;i<inp.length;i++){
		a = D.getElementsByTagName(inp[i]);
		for(q=0;q<a.length;q++){
			if(a[q].value=='' && (a[q].tagName.toLowerCase()=='input' || a[q].tagName.toLowerCase()=='textarea') && a[q].getAttribute('required') == 'true') x++;
			if(a[q].selectedIndex == 0 && a[q].tagName.toLowerCase()=='select' && a[q].getAttribute('required') == 'true')	x++;
			
		}
	}
	if(D.getElementById('btn_next')) btn = D.getElementById('btn_next');
	else if(D.getElementById('btn_save')) btn = D.getElementById('btn_save');
	else return false;
	return (x>0) ? btn.disabled=1 : btn.disabled=0;
}
function setStruct(a,t,b,c,d){
	b=D.getElementById('elemid');
	c=D.getElementById('elemname');
	d=D.getElementById('openerelem');
	b.value=a;
	c.value=t.innerHTML;
	return (b.value == '' || c.value == '' || d.value == '') ? false : insertStruct();
}
function insertStruct(a,b,c){
	a=D.getElementById('elemid').value;
	b=D.getElementById('elemname').value;
	c=D.getElementById('openerelem').value;
	opener.window.document.getElementById('elem_'+c).value=b;
	opener.window.document.getElementById('elem_'+c).focus();
	opener.window.document.getElementById('elemid_'+c).value=a;
	window.close();
	return true;
}
function insertImage(){
	a=D.getElementById('openerelem');
	b=opener.document.getElementsByName(a.value)[0];
	switch(b.tagName.toLowerCase()){
		case 'select':
			for(var q=0,x=D.getElementsByName('cid[]');q<x.length;q++){
				if(x[q].checked==1){
					myText=opener.document.createTextNode(D.getElementById('name_'+x[q].id).value);
					myOpt=opener.document.createElement('option');
					myOpt.value = x[q].value;
					myOpt.id = 'opt'+q;
					myOpt.selected = 'selected';
					myOpt.appendChild(myText);
					b.appendChild(myOpt);
				}
			}
			
		break;
		case 'iframe':
			for(var q=0,x=D.getElementsByName('cid[]');q<x.length;q++){
				if(x[q].checked==1){
					if(b.contentWindow.document){
						b.contentWindow.document.execCommand('insertimage',null,D.getElementById('img_root').value+'/full_size/'+D.getElementById('name_'+x[q].id).value);
					}
				}
			}
			
		break;
	}
	window.close();
	return true;
}
function showPanel(a){
	el=D.getElementsByTagName('div');
	th=a.id.slice(4);
	for(q=0;q<el.length;q++) if(el[q].id.match(/^p_[0-9]+$/)) if((lid=el[q].id.slice(2)) == th){ el[q].style.display='block'; D.getElementById('btn_'+lid).className='panelopen';}else{ el[q].style.display='none';D.getElementById('btn_'+lid).className='';}
	return true;
}
function blockExpireDate(t,a,q){
	a=D.getElementsByTagName('input');
	for(q=0;q<a.length;q++)	if(a[q].getAttribute('datetime') == t.id) a[q].disabled = (t.checked == 1) ? 0 : 1;
	return true;
}

// findChecked(nazwa_checkboxa,liczba_dostepnych_btn,liczba_zaznaczonych)
function findChecked(a,b,c){
	elem = D.getElementsByName(a);
	for(q=x=0;q<elem.length;q++)if(elem[q].checked==1)x++;
	for(i=1;i<=b;i++) D.getElementById('btn_'+i).disabled = (x >= c) ? 0 : 1;
	return true;
}

function removeSelectedOptions(pic,i,q,toDel){
	toDel = []; obj = D.getElementById(pic);
	if((l=obj.options.length) > 0){
		for(q=i=0;q<l;q++) if(obj.options[q].selected == 1) toDel[i++] = obj.options[q].id;
		for(q=0;q<toDel.length;q++)	obj.removeChild(D.getElementById(toDel[q]));
	}
	return true;
}

function submitForm(name){
	D.getElementById(name).submit();
	return true;
}
function reloadOpener(t,l){
	window.opener.location.reload();
	if(window.opener.document.getElementById('preloader')){
		t = opener.innerHeight/2;
		l = (opener.innerWidth/2)-50;
		with(opener.document.getElementById('preloader').style){
			top=t+'px';
			left=l+'px';
			display='block';
		}
	}
}

