function changeVisible(layerName) {
	$("#"+layerName).toggle();
	saveMultipleCookie('layersVisible', layerName, $("#"+layerName).css("display"));
}

function changeVisibleSlide(layerName) {
	$("#"+layerName).slideToggle("slow");
	saveMultipleCookie('layersVisible', layerName, $("#"+layerName).css("display"));
}

function changeVisibleButton(layerName, buttonName, buttonShow, buttonHide) {
	$("#"+layerName).toggle();
	if($("#"+layerName).css("display") == "none") {
		$("#"+buttonName).html('<img src="'+buttonShow+'" alt="" onclick="changeVisibleButton(\''+layerName+'\', \''+buttonName+'\', \''+buttonShow+'\', \''+buttonHide+'\');">');
	}
	else {
		$("#"+buttonName).html('<img src="'+buttonHide+'" alt="" onclick="changeVisibleButton(\''+layerName+'\', \''+buttonName+'\', \''+buttonShow+'\', \''+buttonHide+'\');">');
	}
	saveMultipleCookie('layersVisible', layerName, $("#"+layerName).css("display"));
}

function loadLayersVisible(layersToCheck) {
	if(haveCookie('layersVisible')) {
		for(i=0; i<layersToCheck.length; i++) {
			layerName = layersToCheck[i];
			layerValue = getMultipleCookieValue('layersVisible', layerName);
			if(layerValue !== false) {
				$("#"+layerName).css("display", layerValue);	
			}
		}
	}
}

function loadLayersVisibleButton(layersToCheck) {
	if(haveCookie('layersVisible')) {
		for(i=0; i<layersToCheck.length; i++) {
			layerName = layersToCheck[i][0];
			buttonName = layersToCheck[i][1];
			buttonShow = layersToCheck[i][2];
			buttonHide = layersToCheck[i][3];			
			layerValue = getMultipleCookieValue('layersVisible', layerName);
			if(layerValue !== false) {
				$("#"+layerName).css("display", layerValue);	
			}
			if(layerValue == "none") {
				$("#"+buttonName).html('<img src="'+buttonShow+'" alt="" onclick="changeVisibleButton(\''+layerName+'\', \''+buttonName+'\', \''+buttonShow+'\', \''+buttonHide+'\');">');
			}
			else {
				$("#"+buttonName).html('<img src="'+buttonHide+'" alt="" onclick="changeVisibleButton(\''+layerName+'\', \''+buttonName+'\', \''+buttonShow+'\', \''+buttonHide+'\');">');
			}			
		}
	}
}

function changeGroupVisible(groupPrefix, groupContentPrefix, inactiveTabClass, activeTabClass, activeElementNr, elementsCount, saveCookie) {
	var i;
	for(i=1; i<(elementsCount+1); i++) {
		if(document.getElementById(groupPrefix+'_'+i).className != 'zaklOff') {
			document.getElementById(groupPrefix+'_'+i).className = inactiveTabClass;
		}
		document.getElementById(groupContentPrefix+'_'+i).style.display = "none";
	}	
	document.getElementById(groupPrefix+'_'+activeElementNr).className = activeTabClass;
	document.getElementById(groupContentPrefix+'_'+activeElementNr).style.display = "";	
	if(saveCookie != false) {
		saveMultipleCookie('groupVisible', groupPrefix+'|'+groupContentPrefix+'|'+inactiveTabClass+'|'+activeTabClass+'|'+elementsCount, activeElementNr);
	}
}

function changeFontSize(elementID, fontSize) {
	document.getElementById(elementID).style.fontSize=fontSize;	
	saveMultipleCookie('textSizes', elementID, fontSize);
}

function loadGroupVisible() {
	var groupArr, j;
	groupArr = new Array();
	groupArr = getMultipleCookieAll('groupVisible');
	for(j=0; j<groupArr.length; j++) {
		tmpOptions = groupArr[j][0].split('|');
		if(document.getElementById(tmpOptions[0]+'_'+1) != null) {
			changeGroupVisible(tmpOptions[0], tmpOptions[1], tmpOptions[2], tmpOptions[3], parseInt(groupArr[j][1]), parseInt(tmpOptions[4]));
		}
	}
}



function updateList(elementID, action) {
	var mainNode, tmpNode, prevNode, actionDone, counter = 0, actionDone = false;
	mainNode = document.getElementById(elementID);
	if(mainNode.hasChildNodes()) {
		plusDiv = document.getElementById('symbolPlus');
		minusDiv = document.getElementById('symbolMinus');	
		for(i=0; i<mainNode.childNodes.length; i++) {
			tmpNode = mainNode.childNodes.item(i);
			if(tmpNode.nodeName != '#text' && tmpNode.nodeName != '#comment') {
				if(tmpNode.style.display == 'none') {
					if(separatorID.length > 0) {
						separatorDiv = document.getElementById(separatorID);
					}				
					if(action == '+') {
						tmpNode.style.display = 'list-item';
						actionDone = true;
						if(counter >= minElements) {		
							minusDiv.style.display = "inline";
							if(separatorID.length > 0) {
								separatorDiv.style.display = "inline";
							}
						}						
						if(counter == (maxElements-1)) {
							plusDiv.style.display = "none";
							if(separatorID.length > 0) {
								separatorDiv.style.display = "none";
							}						
						}						
					}
					if(action == '-') {
						if(counter > minElements) {
							prevNode.style.display = 'none';
						}
						if(counter == (minElements+1)) {
							minusDiv.style.display = "none";
							if(separatorID.length > 0) {
								separatorDiv.style.display = "none";
							}						
						}							
						actionDone = true;						
					}
					break;
				}
				prevNode = tmpNode;
				counter++;
			}
		}
		if(action == '+') {
			saveMultipleCookie('dynamicListsCount', elementID, counter+1);
		}
		else {
			saveMultipleCookie('dynamicListsCount', elementID, counter);
		}
		if(actionDone == false && action == '-') {
			if((counter-1) > minElements) {
				prevNode.style.display = 'none';
			}		
			plusDiv.style.display = "inline";					
			if(separatorID.length > 0) {
				separatorDiv.style.display = "inline";
			}			
		}
	}
}

function loadList(elementID) {
	var mainNode, tmpNode, counter = 0, maxVal;
	if(haveCookie('dynamicListsCount')) {
		mainNode = document.getElementById(elementID);
		maxVal = getMultipleCookieValue('dynamicListsCount', elementID);
		plusDiv = document.getElementById('symbolPlus');
		minusDiv = document.getElementById('symbolMinus');			
		if(mainNode.hasChildNodes()) {
			for(i=0; i<mainNode.childNodes.length; i++) {
				tmpNode = mainNode.childNodes.item(i);
				if(tmpNode.nodeName != '#text' && tmpNode.nodeName != '#comment') {
					if(counter < maxVal) {
						tmpNode.style.display = 'list-item';
						if(counter >= minElements) {		
							minusDiv.style.display = "inline";
							if(separatorID.length > 0) {
								separatorDiv.style.display = "inline";
							}
						}						
						if(counter == (maxElements-1)) {
							plusDiv.style.display = "none";
							if(separatorID.length > 0) {
								separatorDiv.style.display = "none";
							}						
						}							
						counter++;
					}
				}
			}
		}
	}
}

