/*	Panaramus CMS v2, seva@isachenko.com ****************************
	
	Created:  02.02.2005
	Modified: 15.01.2006
	
	JavaScript Functions ********************************************/

	Path = [];
	Menu = [];
	Title = [];
	i = 0;

document.onclick = function(e) {
	var e = e || event;
	var c = e.srcElement || e.target;
	if (Node = document.getElementById('id' + c.id)) {
		Node.style.display = (!Node.offsetHeight) ? 'block' : 'none';
	}
}

function getMenu(CurrentId, CurrentPage) {
	if (Current = document.getElementById(CurrentId)) {
		Current.firstChild.className = 'current';
		if (Node = document.getElementById('id' + CurrentId)) Node.style.display = 'block';
		Path[i] = (CurrentPage) ? '<a href="' + Current.firstChild.getAttribute('href') + '">' + Current.firstChild.innerHTML + '</a>' + ' / ' + CurrentPage : Current.firstChild.innerHTML; i++;
		getPath(Current.getAttribute('parent'));
		ShowNode(Current.parentNode.id);
		SubMenu(CurrentId);
		Path[i] = '<a href="/">Главная</a>';
		document.getElementById('path').innerHTML = Path.reverse().join(' / ');
	} else {
		document.getElementById('path').innerHTML = (CurrentId == '1') ? CurrentPage: '<a href="/">Главная</a> / '+CurrentPage;
	}
}

function ShowNode(Id) {
	if (Id !== 'root') {
		Node = document.getElementById(Id);
		Node.style.display = 'block';
		ShowNode(Node.parentNode.id);
	}
}

function getPath(Parent) {
	if (Item = document.getElementById(Parent)) {
		Path[i] = '<a href="' + Item.firstChild.getAttribute('href') + '">' + Item.firstChild.innerHTML + '</a>';
		Title[i] = Item.firstChild.innerHTML; i++;
		getPath(Item.getAttribute('parent'));
	}
}

function SubMenu(Parent) {
	var li = document.getElementsByTagName('li');
	for (var i = 0 ; i < li.length; i++) if (Parent == li[i].getAttribute('parent')) Menu[i] = '<li><a href="' + li[i].firstChild.getAttribute('href') + '">' + li[i].firstChild.innerHTML + '</a></li>';
	if (div = document.getElementById('submenu')) div.innerHTML = '<ul>'+Menu.join('')+'</ul>';
}

function CheckEmail(email) {
	var s = '[A-Za-z0-9][-\\w]*(\\.[A-Za-z0-9][-\\w]*)*';
	var re = new RegExp('^'+s+'@'+s+'\\.[a-zA-Z]{2,6}$');
	email = email.replace(new RegExp('/\(.*?\)/'), '');
	return re.test(email);
}