//	Count child elements

function countChildElements (parent, child)
{
	var parent = document.getElementById(parent);
	var childCount = parent.getElementsByTagName(child).length;
	return childCount;
}

//	E-mail link

function emailLink (name, domain, label) {	
	if (typeof label == "undefined") {
		document.write('<a href=\"mailto:' + name + '@' + domain + '\">' + name + '@' + domain + '</a>');
	} else {
		document.write('<a href=\"mailto:' + name + '@' + domain + '\">' + label + '</a>');
	}
}

//	Centered popup

var legendWin;

function createWin(url, width, height, scrollable) {
	var left = (screen.width - width) / 2;
	var top = (screen.height - height) / 2;
	if(legendWin == null || legendWin.closed) {
		var props = "resizable,scrollbars=" + scrollable + ",left=" + left + ",top=" + top + ",width=" + width + ",height=" + height;
		legendWin = window.open(url, "legend", props);
		legendWin.focus();
	} else {
		legendWin.close();
		var props = "resizable,scrollbars=" + scrollable + ",left=" + left + ",top=" + top + ",width=" + width + ",height=" + height;
		legendWin = window.open(url, "legend", props);
		legendWin.focus();
	}
}

//	Check comment form

function checkPostcomment ()
{
	if (!document.commentform.username.value) {
		alert('Please, fill the \'Username\' field!');
		return false;
	}
	else if (!document.commentform.email.value) {
		alert('Please, fill the \'E-mail\' field!');
		return false;
	}
	else if (!document.commentform.comment.value) {
		alert('Please, write a comment!');
		return false;
	}
	else return true;
}