function addLoadEvent(func)
{
	var oldonload = window.onload;
	if (typeof window.onload != 'function')
	{
		window.onload = func;
	}
	else
	{
		window.onload = function()
		{
			if (oldonload)
			{
				oldonload();
			}
			func();
		}
	}
}

function externalLinks()
{
	if (!document.getElementsByTagName) 
		return;

	var anchors = document.getElementsByTagName("a");
	for (var i=0; i<anchors.length; i++)
	{
		var anchor = anchors[i];
		if (anchor.getAttribute("href") && anchor.getAttribute("rel") == "external")
			anchor.target = "_blank";                                               
	}
}

addLoadEvent(externalLinks);


var valid = new validate();

function validate()
{
	this.error = 'error';
	this.err_field = 'Prašome užpildyti visus laukelius, pažymėtus žvaigždute (*).';

	this.check = function(form)
	{
		var reg = /\*/;
		var last_fail = false;
		this.form = typeof(form) != 'undefined' ? document.getElementById(form) : document;
		var labels = document.getElementsByTagName('label');

        for (i = labels.length - 1; i >= 0; i--)
		{
			if (reg.test(labels[i].innerHTML) && document.getElementById(labels[i].htmlFor))
			{
				input = document.getElementById(labels[i].htmlFor);
				if (input.value == '')
				{
					last_fail = input;
					labels[i].style.fontWeight = 'bold';
				}
				else
				{
					labels[i].style.fontWeight = 'normal';
				}
			}
        }                                          

		if (last_fail)
		{
			document.getElementById(this.error).style.display = 'block';
			document.getElementById(this.error).innerHTML = this.err_field;

			last_fail.focus();

			return false;
		}

		return true;
	}
}