
function show_field( field_id )
{
	el = document.getElementById(field_id);
	el.style.display = 'block';
}

function hide_field( field_id )
{
	el = document.getElementById(field_id);
	el.style.display = 'none';
}

function clear_data_field( obj )
{		
	obj.value = '0000-00-00';
}

function doSection (secNum)
	{
	//doSection odpowiada za rozwijanie obszaru
	el = document.getElementById(secNum);	
	if (el.style.display=="none")
		{
		el.style.display=""
		}
	else
		{
		el.style.display="none"
		}
	}
function noSection (secNum)
	{
	//noSection - za jego zwijanie
	secNum.style.display="none"
	}
	
function doSectionAll (secNum, secName, secMax)
	{	
	elmax = document.getElementById(secMax);	
	var max = elmax.value;
	
	//zwin wszystkie sekcje za wyjatkiem secNum
	for (i=0; i<max; i++)
		{
		var sec = secName+i;
		el = document.getElementById(sec);
		if (el && (sec!=secNum))		
			el.style.display="none";
		}
		
	el = document.getElementById(secNum);
	if (el.style.display=="none")
		{
		el.style.display=""
		}
	else
		{
		el.style.display="none"
		}
	}
	
function SubmitForm(idform)
	{
	document.getElementById(idform).submit();
	}

function GeneratePassword() {
    if (parseInt(navigator.appVersion) <= 3) {
        alert("Przepraszamy Twoja przeglądarka nie obsługuje skryptu");
        return true;
    }
    var length=8;
    var sPassword = "";
    length = document.aForm.charLen.options[document.aForm.charLen.selectedIndex].value;
    var noPunction = (document.aForm.punc.checked);
    var randomLength = (document.aForm.rLen.checked);
    if (randomLength) {
        length = Math.random();
        length = parseInt(length * 100);
        length = (length % 7) + 6
    }
    for (i=0; i < length; i++) {
        numI = getRandomNum();
        if (noPunction) { while (checkPunc(numI)) { numI = getRandomNum(); } }
        sPassword = sPassword + String.fromCharCode(numI);
    }
    el = document.getElementById('password');	
		el.value = sPassword
    return true;
}

function getRandomNum() {
    // between 0 - 1
    var rndNum = Math.random()
    // rndNum from 0 - 1000
    rndNum = parseInt(rndNum * 1000);
    // rndNum from 33 - 127
    rndNum = (rndNum % 94) + 33;
    return rndNum;
}

function checkPunc(num) {
    if ((num >=33) && (num <=47)) { return true; }
    if ((num >=58) && (num <=64)) { return true; }
    if ((num >=91) && (num <=96)) { return true; }
    if ((num >=123) && (num <=126)) { return true; }
    return false;
}


function Tree(id) {
	this.id = id;
	
	var url = unescape(window.location.href.replace(/#.*/, ''));
	var base = window.location.protocol + '//' + window.location.host + window.location.pathname.replace(/[^\/\\]+$/, '');
	
	this.click = function ()
	{
		for (var i = 0, el_node; i < this.parentNode.childNodes.length; i++)
		{
			el_node = this.parentNode.childNodes.item(i)
			if (el_node.nodeName.toLowerCase() == 'ul')
			{
				el_node.style.display = el_node.style.display == 'none' ? 'block' : 'none';
				this.parentNode.className = this.parentNode.className.replace(/(^| +)(opened|closed)( +|$)/g, ' ') + ' ' + (el_node.style.display == 'none' ? 'closed' : 'opened');
				return;
			}
		}
	}
	
	this.start = function (el)
	{
		for (var i = 0, el_node; i < el.childNodes.length; i++)
		{
			el_node = el.childNodes.item(i);
			if (el_node.nodeName.toLowerCase() == 'a')
			{
				el_node.onclick = this.click;
				for (var j = 0; j < el_node.parentNode.childNodes.length; j++)
				{
					if (el_node.parentNode.childNodes.item(j).nodeName.toLowerCase() == 'ul')
					{
						el_node.parentNode.className += ' closed';
						el_node.className = (el_node.className ? el_node.className + ' ' : '') + 'folder';
						break;
					}
					if (el_node.parentNode.childNodes.item(j).nodeName.toLowerCase() == 'li') break;
				}
				var active = el_node.href && unescape(el_node.href.replace(/#.*/, '')) == url;
				if (!active)
				{
					var rel = el_node.getAttribute('rel');
					if (rel)
					{
						var matches = (' ' + rel + ' ').match(/\s+Collection\(([^)]+)\)\s+/i);
						if (matches)
						{
							matches = matches[1].split(',');
							for (var k = 0, pos = -1; k < matches.length; k++)
							{
								if (matches[k].charAt(0) == '[' && (pos = matches[k].lastIndexOf(']')) > 0)
								{
									if (new RegExp(unescape(matches[k].substring(1, pos)), matches[k].substring(pos + 1)).test(url))
									{
										active = true;
										break;
									}
								}
								else
								{
									if (/^[\/\\]/.test(matches[k])) matches[k] = window.location.protocol + '//' + window.location.host + matches[k];
									else if (!/^[a-z0-9]+:/i.test(matches[k])) matches[k] = base + matches[k];
									if (unescape(matches[k].replace(/[\/\\]\.([\/\\])/g, '$1').replace(/[^\/\\]+[\/\\]\.\.[\/\\]/g, '').replace(/#.*/, '')) == url)
									{
										active = true;
										break;
									}
								}
							}
						}
					}
				}
				if (active)
				{
					el_node.className = 'active';
					var el_parentNode = el_node;
					do
					{
						el_parentNode = el_parentNode.parentNode;
						if (el_parentNode.nodeName.toLowerCase() == 'ul')
						{
							el_parentNode.style.display = 'block';
							if (document.getElementById(this.id) != el_parentNode) el_parentNode.parentNode.className = el_parentNode.parentNode.className.replace(/(^| +)(opened|closed)( +|$)/g, ' ') + ' opened';
						}
					}
					while (document.getElementById(this.id) != el_parentNode)
				}
			}
			else if (el_node.nodeName.toLowerCase() == 'ul') el_node.style.display = 'none';
			this.start(el_node);
		}
	}
	
	if (document.getElementById && document.childNodes) this.start(document.getElementById(this.id));
}
