function init() {

	var y = document.getElementsByTagName('img');
	for (var i=0; i<y.length; i++) {
		if (y[i].getAttribute('selectnumber')) {
			y[i].onclick = selectNumber;
		}
		if (y[i].getAttribute('preselect')) {
			selectNumber(new Object, y[i].getAttribute('preselect'));
		}
	}
	
	var y = document.getElementsByTagName('area');
	for (var i=0; i<y.length; i++) {
		if (y[i].getAttribute('openpopup')) {
			y[i].onclick = openPopup;
		}
	}

	var y = document.getElementsByTagName('a');
	for (var i=0; i<y.length; i++) {
		if (y[i].getAttribute('openpopup')) {
			y[i].onclick = openPopup;
		}
		else if (y[i].getAttribute('submit')) {
			y[i].onclick = submit_form;
		}
		else if (y[i].getAttribute('resetSelectedNumbers') == '1') {
			y[i].onclick = resetSelectedNumbers;
		}
		else if (y[i].getAttribute('generateRandomNumbers') == '1') {
			y[i].onclick = generateRandomNumbers;
		}
		else if (y[i].getAttribute('numberAction')) {
			y[i].onclick = numberAction;
		}
    }
	
	var y = document.getElementsByTagName('form');
	for (var i=0; i<y.length; i++) {
		y[i].onsubmit = form_onsubmit;
	}

	var y = document.getElementsByTagName('div');
	for (var i=0; i<y.length; i++) {
		if ((y[i].className == 'text') && (y[i].getAttribute('submit'))) {
			y[i].onclick = submit_form;
		}
		else if ((y[i].className == 'text') && (y[i].getAttribute('location'))) {
			if (y[i].getAttribute('inactivated')) {
				y[i].style.color = '#999';
			}
			y[i].onclick = link_onclick;
		}
		else if (y[i].getAttribute('numberAction')) {
			if (y[i].getAttribute('inactivated')) {
				y[i].style.color = '#999';
			}
			y[i].onclick = numberAction;
		}
		else if (y[i].getAttribute('closewindow')) {
			y[i].onclick = closewindow;
		}
	}

	var y = document.getElementsByTagName('li');
	for (var i=0; i<y.length; i++) {
		if (y[i].getAttribute('location')) {
			if (y[i].getAttribute('inactivated')) {
				y[i].style.color = '#999';
			}
			y[i].onclick = link_onclick;
		}
	}

	var y = document.getElementsByTagName('select');
	for (var i=0; i<y.length; i++) {
		if (y[i].getAttribute('onchange') == 'jumptoblock') {
			y[i].onchange = jumptoblock;
		}
	}
}

var highlightedBlock = '';

function jumptoblock() {

	var block = '';

	if (highlightedBlock) {
		document.getElementById(highlightedBlock + 'block').style.backgroundColor='#ffffff';
		document.getElementById(highlightedBlock + 'block').style.padding='0px';
	}

	block = document.getElementById(this.value + 'block');
	if (block) {
		document.location.hash='#' + this.value;
		highlightedBlock = this.value;
		block.style.backgroundColor='#ffff99';
		block.style.padding='10px';
		return true;
	}

	return false;
}

function closewindow() {
	window.close();
}


var selectedNumbers = new Array();

function selectNumber(object, number, noremove) {

	var number;
	var numberid = '';
	var bnumberid = '';

	if (!noremove) noremove = 0;

	if (!number) number = this.getAttribute('selectnumber');
	if (number) {

		numberid = 'gf_number_' + number;
		bnumberid = 'gf_bnumber_' + number;
		// if (document.getElementById(numberid).className == 'number_selected') {
		if (selectedNumbers[number] == 1) {
			if (!noremove) {
				document.getElementById(numberid).className = 'number';
				document.getElementById(bnumberid).style.display = 'none';
				selectedNumbers[number] = 0;
			}
		}
		else {
			if (selectedNumbersCount() == 7) {
				alert('Csak 7 számot jelölhetsz be!');
				return false;
			}

			document.getElementById(numberid).className = 'number_selected';
			document.getElementById(bnumberid).style.display = 'inline';
			selectedNumbers[number] = 1;
		}
	}

}

function generateRandomNumbers() {
	
	var randomNumbers = new Array();
	var count = 0;

	resetSelectedNumbers();

	while (count < 7) {
		randomNumbers[getRandom(70)] = 1;
		count = 0;
		for (var i = 0; i < randomNumbers.length; i++) {
			if (randomNumbers[i] == 1) {
				count++;
			}
		}
	}

	for (var i = 0; i < randomNumbers.length; i++) {
		if (randomNumbers[i] == 1) {
			selectNumber(new Object, i);
		}
	}

	return false;
}

function getRandom(num) {
	return Math.floor(Math.random()*num)+1;
}

function resetSelectedNumbers() {

	for (var i = 0; i < selectedNumbers.length; i++) {
		if (selectedNumbers[i] == 1) {
			selectNumber(new Object, i);
		}
	}

	return false;
}

function selectedNumbersCount() {
	
	var count = 0;

	for (var i = 0; i < selectedNumbers.length; i++) {
		if (selectedNumbers[i] == 1) {
			count++;
		}
	}

	return count;
}

function useFavorites(numbers) {

	var _numbers = new Array();

	resetSelectedNumbers();
	if (numbers && numbers != '') {
		_numbers = explodeArray(numbers, ',');
		for (var i = 0; i < _numbers.length; i++) {
			selectNumber(new Object, _numbers[i], 1);
		}
	}
}

function explodeArray(item,delimiter) {
  tempArray=new Array(1);
  var Count=0;
  var tempString=new String(item);

  while (tempString.indexOf(delimiter)>0) {
    tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
    tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1); 
    Count=Count+1
  }

  tempArray[Count]=tempString;
  return tempArray;
}

function numberAction() {
	
	var location;
	var numbers = '';

	if ((this.getAttribute('inactivated')) && (this.getAttribute('inactivated') != '')) {
		alert(this.getAttribute('inactivated'));
		return false;
	}
	
	if (selectedNumbersCount() != 7) {
		alert('Jelölj be 7 számot!');
		return false;
	}

	location = this.getAttribute('numberAction');

	if (location) {
		for (var i = 0; i < selectedNumbers.length; i++) {
			if (selectedNumbers[i] == 1) {
				if (numbers != '') {
					numbers = numbers + ',' + i;
				}
				else {
					numbers = i;
				}
			}
		}
		location = location + '/' + numbers;
		timer = setTimeout("document.location='" + location + "'", 10);
	}

	return false;
	
}

function link_onclick() {
	
	var timer = 0;
	var location;
	var picWidth = 200;
	var picHeight = 200;

	if (timer) clearTimeout(timer);
	location = this.getAttribute('href');
	if (!location) location = this.getAttribute('location');
	
	if ((this.getAttribute('inactivated')) && (this.getAttribute('inactivated') != '')) {
		alert(this.getAttribute('inactivated'));
		return false;
	}
	
	if ((location) && (location != '')) {
		timer = setTimeout("document.location='" + location + "'", 10);
	}

	return false;	
}

function form_onsubmit() {
	formname = this.getAttribute('name');
	if (formname == 'searchform') {
		if (document.forms['' + formname + ''].searchtext.value.length < 3) {
			new Effect.Shake('searchfield');
			Effect.Appear('searchfieldwarning', {
				duration:2.0,
				transition:Effect.Transitions.wobble,
				afterFinish: function() {
					setTimeout((function() { new Effect.Fade('searchfieldwarning'); } ), 1000);
				}
			});
			return false;
		}
	}
	if (formname == 'newsletterform') {
		if (document.forms['' + formname + ''].newsletteremail.value =='' || document.forms['' + formname + ''].newsletteremail.value =='e-mail cím') {
			visible('emailfieldmsg',false,'');
			new Effect.Shake('emailfield');
			Effect.Appear('emailfieldwarning', {
				duration:2.0,
				transition:Effect.Transitions.wobble,
				afterFinish: function() {
					setTimeout((function() { new Effect.Fade('emailfieldwarning'); } ), 1000);
				}
			});
			return false;
		}
	}
}

function submit_form() {

	var formname;

	formname = this.getAttribute('submit');
	if (formname == 'searchform') {
		if (document.forms['' + formname + ''].searchtext.value.length < 3) {
			new Effect.Shake('searchfield');
			Effect.Appear('searchfieldwarning', {
				duration:2.0,
				transition:Effect.Transitions.wobble,
				afterFinish: function() {
					setTimeout((function() { new Effect.Fade('searchfieldwarning'); } ), 1000);
				}
			});
			return false;
		}
	}
	if (formname == 'newsletterform') {
		if (document.forms['' + formname + ''].newsletteremail.value =='' || document.forms['' + formname + ''].newsletteremail.value =='e-mail cím') {
			visible('emailfieldmsg',false,'');
			new Effect.Shake('emailfield');
			Effect.Appear('emailfieldwarning', {
				duration:2.0,
				transition:Effect.Transitions.wobble,
				afterFinish: function() {
					setTimeout((function() { new Effect.Fade('emailfieldwarning'); } ), 1000);
				}
			});
			return false;
		}
	}
	document.forms['' + formname + ''].submit();

	return false;
}

var bl_pos = 0;

function shift_left(id) {

	var current = 0;
	var l = 1;
	
	if (bl_pos < bl_maxpos) {
		bl_pos = bl_pos + bl_width;
		current = document.getElementById(id).style.left;
		if (current == '') current = 0;
		else current = parseInt(current);
		for (i = (0 - current); i <= bl_pos; i+=(bl_width/10)) {
			setTimeout("changePos('" + id + "', '" + i + "')", l*100);
			l++;
		}
	}
	
	setTimeout("checkButtonbarPos(" + bl_pos + ")", l*100);
}

function shift_right(id) {

	var l = 1;
	var k = 0;

	if (bl_pos > 0) {
		bl_pos = bl_pos - bl_width;
		current = document.getElementById(id).style.left;
		if (current == '') current = 0;
		else current = parseInt(current);
		for (i = current; i <= (0 - bl_pos); i+=(bl_width/10)) {
			k = 0 - i;
			setTimeout("changePos('" + id + "', '" + k + "')", l*100);
			l++;
		}
	}

	setTimeout("checkButtonbarPos(" + bl_pos + ")", l*100);
}

function checkButtonbarPos(bl_pos) {

	if (bl_pos == 0) {
		document.getElementById('buttonbar-left-arrow').style.display = 'none';
		document.getElementById('buttonbar-right-arrow').style.display = 'block';
	}
	
	if (bl_pos > 0) {
		if (bl_pos == bl_maxpos) document.getElementById('buttonbar-right-arrow').style.display = 'none';
		else document.getElementById('buttonbar-right-arrow').style.display = 'block';

		document.getElementById('buttonbar-left-arrow').style.display = 'block';
	}

}

function changePos(id, bl_pos) {
	document.getElementById(id).style.left = -bl_pos + 'px';
}


function visible(obj, visible, display) {
	if (!display) display = '';

	if (document.all) {
		if (window.document.all(obj)) {
			if (visible=='change') visible=window.document.all(obj).style.display=='none';
			if (visible) window.document.all(obj).style.display=display;
			else window.document.all(obj).style.display='none';
		}
    }
    else if (document.getElementById) {
		if (document.getElementById(obj)) {
			if (visible=='change') visible=document.getElementById(obj).style.display=='none';
			if (visible) {
				document.getElementById(obj).style.display=display;
			}
			else document.getElementById(obj).style.display='none';
		}
	}
	
    return true;
}

function openPopup() {

	var location;
	var windowName;
	var width;
	var height;
	var popuptype;
	var popunder = '0';
	var noreturn = '0';

	location = this.getAttribute('openpopup');
	wName = this.getAttribute('wName');
	pWidth = this.getAttribute('pWidth');
	pHeight = this.getAttribute('pHeight');
	popuptype = this.getAttribute('popuptype');
	popunder = this.getAttribute('popunder');
	noreturn = this.getAttribute('noreturn');

	if (!wName) wName = 'name';
	if (!popuptype) popuptype = 'restricted';

	if (popuptype == 'normal') {
		var openedWindow = newWindow = window.open(location);
	}
	else {
		var openedWindow = newWindow = window.open(location, wName ,'width='+pWidth+',height='+pHeight+',status=no,toolbar=no,menubar=no,location=no,directories=no,resizable=yes,scrollbars=yes,titlebar=no');
	}

	if (popunder == '1') {
		window.focus();
		openedWindow.blur();
	}

	if (!noreturn) {
		return false;
	}

	return true;
}

