var enablepersist="on"

var contractsymbol='template/img/collapse_tcat.gif'
var expandsymbol='template/img/collapse_tcat_1.gif'

function getElementbyClass(rootobj, classname) {
	var temparray=new Array()
	var inc=0
	var rootlength=rootobj.length
	for (i=0; i<rootlength; i++){
		if (rootobj[i].className==classname)
		temparray[inc++]=rootobj[i]
	}
	return temparray
}

function sweeptoggle(ec){
	var inc=0
	while (ccollect[inc]) {
		ccollect[inc].style.display=(ec=="contract")? "none" : ""
		inc++
	}
	revivestatus()
}


function expandcontent(curobj, cid, pokaz){
	if (ccollect.length>0) {
		document.getElementById(cid).style.display=(document.getElementById(cid).style.display!="none")? "none" : ""
		if (pokaz == 1) {
			curobj.src=(document.getElementById(cid).style.display=="none")? expandsymbol : contractsymbol
		}
	}
}

function revivecontent(){
	selectedItem=getselectedItem()
	selectedComponents=selectedItem.split("|")
	for (i=0; i<selectedComponents.length-1; i++) {
		document.getElementById(selectedComponents[i]).style.display="none"
	}	
}

function revivestatus(){
	var inc=0
	var abc
	while (statecollect[inc]) {
		if (ccollect[inc].style.display == 'none') {
			statecollect[inc].src=expandsymbol;
		} else {
			statecollect[inc].src=contractsymbol;
		}	
		inc++;
	}
}

function get_cookie(Name) { 
	var search = Name + "="
	var returnvalue = "";
	if (document.cookie.length > 0) {
		offset = document.cookie.indexOf(search)
		if (offset != -1) { 
			offset += search.length
			end = document.cookie.indexOf(";", offset);
			
			if (end == -1) {
				end = document.cookie.length;
			}	
			returnvalue=unescape(document.cookie.substring(offset, end))
			
		}
	}
	return returnvalue;
}

function getselectedItem(){
	if (get_cookie(window.location.pathname) != "") {
		selectedItem=get_cookie(window.location.pathname)
		return selectedItem
	} else {
		return ""
	}	
}



function mail(user, domain) {
	window.location = 'mailto:'+user+'@'+domain;
}

function saveswitchstate(){
	var inc=0, selectedItem=""
	while (ccollect[inc]) {
		if (ccollect[inc].style.display=="none") {
			selectedItem+=ccollect[inc].id+"|"
		}
		inc++
	}
	if (get_cookie(window.location.pathname)!=selectedItem) { 
		var expireDate = new Date()
		expireDate.setDate(expireDate.getDate()+parseInt(30))
		document.cookie = window.location.pathname+"="+selectedItem+";path=/;expires=" + expireDate.toGMTString()
	}
}

function do_onload(){
	uniqueidn=window.location.pathname+"firsttimeload"
	var alltags=document.all? document.all : document.getElementsByTagName("*")
	ccollect=getElementbyClass(alltags, "switchcontent")
	statecollect=getElementbyClass(alltags, "showstate")
	if (enablepersist=="on" && get_cookie(window.location.pathname)!="" && ccollect.length>0)
	revivecontent()
	if (ccollect.length>0 && statecollect.length>0)
	revivestatus()
}

function pokazdiva(divid) {
	document.getElementById(divid).style.display = document.getElementById(divid).style.display == 'none' ? 'block' : 'none'
}


function CheckAll() {
	for (var i=0;i<document.form.elements.length;i++)
	{
		var e = document.form.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
		e.checked = document.form.allbox.checked;
		}
}

function CheckCheckAll() {
	var TotalBoxes = 0;
	var TotalOn = 0;
	for (var i=0;i<document.form.elements.length;i++)
	{
		var e = document.form.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox'))
		{
			TotalBoxes++;
		if (e.checked)
		{
		TotalOn++;
		}
		}
	}
	if (TotalBoxes==TotalOn) {document.form.allbox.checked=true;} else {document.form.allbox.checked=false;}
}

function pop_it(the_form,file) {
	my_form = eval(the_form);
	window.open("", "popup", 'top=10,left=10,resizable=no, location=no, width=900, height=500, menubar=no, status=no, scrollbars=yes, menubar=no');
	my_form.action = file;
	my_form.target = "popup";
	my_form.submit();
	return false;

}

function submit_form(the_form,file) {
	my_form = eval(the_form);
	my_form.action = file;
	my_form.target = "";	
	my_form.submit();
	return false;
}

function delete_post(link) {
	if (confirm(postdel_1)){
		window.location.href=link;
	}
}

function link_to_post(pid) {
	temp = prompt(schowek, linkforum + pid );
	return false;
}

function check_selected(dane,what) {
	var strona = dane.elements.what.value;
	if (strona) {
		return true;
	}
	return false;
}

function mod_check_selected(link,strona) {
	if (strona) {
		if (strona == 'deletepost') {
 			if(confirm(topicdelp_1)) { 
 				window.location = link+'&what='+strona;
 				return true;
 			}
 		} else if (strona == 'delete') {
 	 		if(confirm(topicdel_1)) {
 	 		 	window.location = link+'&what='+strona; 	
 				return true;
 			}
 		} else {	
 			window.location = link+'&what='+strona;
			return true;
		}		
	}
	return false;
}

function gotopage(dane,link,stron) {
	var strona = document.getElementById('page').value;
	if ((parseInt(strona, 10)) > 0) {
		if (strona <= stron) {
			pagenum = strona-1;
			window.location = link + '&page=' + pagenum;		
		}
	}
	return false;
}


function getposOffset(overlay, offsettype){
var totaloffset=(offsettype=="left")? overlay.offsetLeft : overlay.offsetTop;
var parentEl=overlay.offsetParent;
while (parentEl!=null){
totaloffset=(offsettype=="left")? totaloffset+parentEl.offsetLeft : totaloffset+parentEl.offsetTop;
parentEl=parentEl.offsetParent;
}
return totaloffset;
}

function overlay(curobj, subobjstr, opt_position){
if (document.getElementById){
var subobj=document.getElementById(subobjstr)
subobj.style.display=(subobj.style.display!="block")? "block" : "none"
var xpos=getposOffset(curobj, "left")+((typeof opt_position!="undefined" && opt_position.indexOf("right")!=-1)? -(subobj.offsetWidth-curobj.offsetWidth) : 0) 
var ypos=getposOffset(curobj, "top")+((typeof opt_position!="undefined" && opt_position.indexOf("bottom")!=-1)? curobj.offsetHeight : 0)
subobj.style.left=xpos+"px"
subobj.style.top=ypos+"px"
return false
}
else
return true
}

function overlayclose(subobj){
document.getElementById(subobj).style.display="none"
}



if (window.addEventListener) {
	window.addEventListener("load", do_onload, false);
} else if (window.attachEvent) {
	window.attachEvent("onload", do_onload);
} else if (document.getElementById) {
	window.onload=do_onload;
}

if (enablepersist=="on" && document.getElementById) {
	window.onunload=saveswitchstate;
}