/* $Id: commons.js,v 1.8 2007-07-12 09:04:11 pch Exp $ */
function newImage(arg) {
	if (document.images) {
		rslt = new Image();
		rslt.src = arg;
		return rslt;
	}
}

function changeImages() {
	if (document.images && (preloadFlag == true)) {
		for (var i=0; i<changeImages.arguments.length; i+=2) {
			document[changeImages.arguments[i]].src = changeImages.arguments[i+1];
		}
	}
}

/*
	Ujednolicenie odwolan do obiektow (cross-browser).
	Uzycie: var zmienna = new getObj('identyfikator');
*/

var DHTML = (document.getElementById || document.all || document.layers);

function getObj(name){
if (DHTML){
  if (document.getElementById){
  	this.obj = document.getElementById(name);
	this.style = document.getElementById(name).style;
  }
  else if (document.all){
	this.obj = document.all[name];
	this.style = document.all[name].style;
  }
  else if (document.layers){
   	this.obj = document.layers[name];
   	this.style = document.layers[name];
  }
 }
}

function toggleLayer(layerNo){
	if (!DHTML) return;
	var textLayer=new getObj('menuContextLayer'+layerNo);
	var buttonLayer=new getObj('menuContextBullet'+layerNo);
	if (textLayer.style.display!=''){
		buttonLayer.obj.src='/images/lista_minus.gif';
		textLayer.style.display='';
	} else {
		buttonLayer.obj.src='/images/lista_plus.gif';
		textLayer.style.display='none';
	}
}

function changeDiv(num){
	if (!DHTML) return;

	if(clockID && lastDiv==num) {
		clearTimeout(clockID);
		clockID=0;
	}

	divsArray[num].style.display='block';
}

function clearDiv(num){
	if (!DHTML) return;		
	lastDiv = num;
	clockID = setTimeout('clearDivDelayed('+num+')', 1);
	//clearDivDelayed(num);
}

function clearDivDelayed(num){
	divsArray[num].style.display='none';
}


function downCert(selectObj,errMsg){
	var fileName='';
	if (selectObj.selectedIndex!=0){
		fileName+=selectObj[selectObj.selectedIndex].value;
		document.location.href=fileName;
		//selectObj.selectedIndex=0;		
	} else {
		alert(errMsg);
	}
}

function showProvince(n,anh,caption){
	var args = showProvince.arguments;
    var length = showProvince.arguments.length; 
	
	var protocol = document.location.protocol;
	var host = document.location.host;
	var pathname = document.location.pathname;
	var hash = document.location.hash;
	var search = document.location.search;

	if(length==1){
		//document.location.search="?woj="+n+"&show=1&word=";
		search = "?woj="+n+"&show=1&word=";
		hash = "";
		document.location.href=protocol+"//"+host+pathname+search+hash;
	}
    else if (length==2){
		//document.location.search="?woj="+n+"&show=1&word=&#"+anh;
		search = "?woj="+n+"&show=1&word=";
		hash = "#"+anh;
		document.location.href=protocol+"//"+host+pathname+search+hash;
	}
	else if (length==3){
		//document.location.search="?woj="+n+"&show=1&word=&#"+anh;
		search = "?woj="+n+"&show=1&word=" +caption;
		hash = "#"+anh;
		document.location.href=protocol+"//"+host+pathname+search+hash;
	}
}

function removeAllChildren(node){
	if(node){
		while (node.hasChildNodes()){
			node.removeChild(node.firstChild);
		}
	}
}

function addMail(currentId){
	var current = document.getElementById(currentId);
	var to=current.innerHTML.replace(new RegExp('\\[kropka\\]','g'),'.').replace(new RegExp('\\[malpa\\]','g'),'@');
	var a = document.createElement("A");
	var t = document.createTextNode(to);
	a.setAttribute('href','ma'+'il'+'to:'+to);
	a.appendChild(t);
	removeAllChildren(current);
	current.appendChild(a);
}