function setMaxLength() {
	var x = document.getElementsByTagName('textarea');
	var counter = document.createElement('div');
	counter.className = 'counter';
	for (var i=0;i<x.length;i++) {
		if (x[i].getAttribute('maxlength')) {
			var counterClone = counter.cloneNode(true);
			counterClone.relatedElement = x[i];
			counterClone.innerHTML = '<span>0</span>/'+x[i].getAttribute('maxlength');
			x[i].parentNode.insertBefore(counterClone,x[i].nextSibling);
			x[i].relatedElement = counterClone.getElementsByTagName('span')[0];

			x[i].onkeyup = x[i].onchange = checkMaxLength;
			x[i].onkeyup();
		}
	}
}

function PopPreview(url) {
	var iMyWidth;
	var iMyHeight;
	//half the screen width minus half the new window width (plus 5 pixel borders).
	iMyWidth = (window.screen.width/2) - (620 + 10);
	//half the screen height minus half the new window height (plus title and status bars).
	iMyHeight = (window.screen.height/2) - (770 + 50);
	//Open the window.
	var win2 = window.open(url,"Window2","status=no,height=700,width=1100,resizable=yes,left=" + iMyWidth + ",top=" + iMyHeight + ",screenX=" + iMyWidth + ",screenY=" + iMyHeight + ",toolbar=no,menubar=no,scrollbars=no,location=no,directories=no");
	win2.focus();
}


function checkMaxLength() {
	var maxLength = this.getAttribute('maxlength');
	var currentLength = this.value.length;
	if (currentLength > maxLength)
		this.relatedElement.className = 'toomuch';
	else
		this.relatedElement.className = '';
	this.relatedElement.firstChild.nodeValue = 'Simbolių: '+currentLength;
	// not innerHTML
}
		 

function check_post() {

	var vardas = posto_forma.vardas.value.length;
	var postas = posto_forma.tekstas.value.length;
	var valid  = posto_forma.valid.value.length;
	var topikas = posto_forma.topikas_input.value.length;

	if ((vardas < 3) || (vardas > 30))	{
		alert('Vardo ilgis turi būti nuo 3 iki 30 simbolių!');
		var returnas = false;

	} else if (topikas < 5 || topikas > 100)	{
		alert('Temos ilgis turi būti nuo 5 iki 100 simbolių!');
		var returnas = false;

	} else if (postas < 5 || postas > 2000)	{
		alert('Pranešimo ilgis turi būti nuo 5 iki 2000 simbolių!');
		var returnas = false;

	} else if (valid != 4)	{
		alert('Saugos kodas turi susidaryt iš 4 simbolių!');
		var returnas = false;

	} else {
		var returnas = true;
	}
	
	
	return returnas;
	
}
