function showUser(id) {
	window.open('index.php?layout=popup&p=userpopup&userid=' + id, 'userpopup', 'width=400,height=300,top=50,left=50');
	return false;
}

function showDiv(id) {
	document.getElementById(id).style.display = 'block';
}

function hideDiv(id) {
	document.getElementById(id).style.display = 'none';
}

function getRnd(from, to) {
	return ( from + Math.floor(Math.random() * to) );
	
}

function fillRandomNumbers(ary) {
	
	ary = new Array();
	for (i = 0; i<5; i++) {
		var x = getRnd(1, 90);
		while (ary[x] == 1) {
			var x = getRnd(1, 90);
		}
		ary[x] = 1;
	}

	for (i=1; i<91; i++) {
		if (ary[i] == 1) {
			var box = getID('box_' + i);
			box.checked = true;
			toggleFieldStyle(i);
		}
	}
	
	return true;
}

function checkBoard(obj_id, action) {
	var j = 0;
	if (action == 'check') {
		var box_current = getID('box_' + obj_id);
		for (i = 1; i<91; i++) {
			var box = getID('box_' + i);
			if (box.checked) j++;
			if (j > 5) {
				box_current.checked = false;
				alert('Pontosan 5 számot kell megjelölni!');
				return false;
			}
		}
		return true;
	}
	if (action == 'submit') {
		for (i = 1; i<91; i++) {
			var box = getID('box_' + i);
			if (box.checked) j++;
		}
		if (j < 5) {
			alert('Pontosan 5 számot kell megjelölni!');
			return false;
		}
		else {
			getID('id_numfield').submit();
			return true;
		}
	}
	if (action == 'clear') {
		for (i = 1; i<91; i++) {
			var cell = getID('numField_' + i);
			cell.className = 'off';
			var box = getID('box_' + i);
			box.checked = false;
		}
		return true;
	}
}

function toggleField(obj_id) {
	if (checkBoard(obj_id, 'check')) {
		toggleFieldStyle(obj_id);
	}
	return true;
}

function toggleFieldStyle(obj_id) {
	var cell = getID('numField_' + obj_id);
	var box = getID('box_' + obj_id);

	if (box.checked) {
		cell.className = 'on';
	}
	else {
		cell.className = 'off';
	}

	return true;
}

function newwin (link,name,settings) {
	x = window.open (link,name,settings);
}

function getID(data) {
	return document.getElementById(data);
}