﻿/**
*
*	JavaScript Function List
*
*	Included in the page <head> section.
*
*	Available functions:
*		vote(answer)			>>	Posts the voting form according to the chosen answer.
*		imageOnMouseOver()		>>	Displays an inside border and zoom icon. Called as an argument of "onmouseover".
*		imageOnMouseOut()		>>	Hides the inside border and zoom icon. Called as an argument of "onmouseout".
*		loadFile(file,target)	>>	Loads the content of an external file into the specified div element (using AJAX).
*		reloadMenu()			>>	Reloads the navigaton menu (once included in the specified div).
*
**/

window.onload = function preloadImages() {
	modal_alert_sign = new Image();
	modal_alert_sign.src = 'img/sign_error_big.png';
	modal_confirm_sign = new Image();
	modal_confirm_sign.src = 'img/sign_warning_big.png';
}

function alert(message) {
	var newblackout = document.createElement('div');
	newblackout.id = 'modal_blackout';
	document.body.appendChild(newblackout);

	var newalert = document.createElement('div');
	newalert.id = 'modal_box';
	newalert.className = 'modal_alert';
	newalert.innerHTML = '<h1>Hiba!</h1><h2>'+message+'</h2><p><button id="modal_button" onclick="closeModal(\'fade\');">OK</button></p>';
	document.getElementById('modal_blackout').appendChild(newalert);
	document.getElementById('modal_button').focus();
}

function confirmAction(message,action) {
	var newblackout = document.createElement('div');
	newblackout.id = 'modal_blackout';
	document.body.appendChild(newblackout);

	newconfirm = document.createElement('div');
	newconfirm.id = 'modal_box';
	newconfirm.className = 'modal_confirm';
	newconfirm.innerHTML = '<h1>Megerősítés szükséges</h1><h2>'+message+'</h2><p><button id="modal_button" onclick="closeModal(\'fade\');'+action+'">OK</button><button id="modal_button" onclick="closeModal(\'fade\');">Mégse</button></p>';
	document.getElementById('modal_blackout').appendChild(newconfirm);
}

function fadeOut(id){
	element = document.getElementById(id);
	if (window.opacity===undefined) { opacity = 100; }
	if (opacity>0) {
		element.setAttribute('style','filter:alpha(opacity='+opacity+');-moz-opacity:'+opacity/100+';opacity:'+opacity/100);
		opacity = opacity-20;
		setTimeout('fadeOut("'+id+'")',50);
	}
	else {
		element.parentNode.removeChild(element);
		delete opacity;
	}
}

function closeModal(mode) {
	if (mode=='fade') {
		fadeOut('modal_blackout');
	}
	else {
		element = document.getElementById('modal_blackout');
		element.parentNode.removeChild(element);
	}
}

function vote(answer) {
	document.poll.poll_answer.value = 'count' + answer;
	document.poll.submit();
}

function imageOnMouseOver() {
	document.getElementById('box').style.border='5px solid #9ACF9A';
	document.getElementById('image').style.margin='-5px';
	document.getElementById('zoom').style.visibility='visible';
}

function imageOnMouseOut() {
	document.getElementById('box').style.border='0px';
	document.getElementById('image').style.margin='0px';
	document.getElementById('zoom').style.visibility='hidden';
}

function loadFile(file,target) {
	var oRequest;
	try { oRequest = new XMLHttpRequest(); }
	catch (e) {
		try { oRequest = new ActiveXObject('Msxml2.XMLHTTP'); }
		catch (e) {
			try { oRequest = new ActiveXObject('Microsoft.XMLHTTP'); }
			catch (e) {
				if (file=='login.php') {
					alert('A böngészője nem támogatja a funkciót! Kérjük, töltse újra az oldalt az időkorlát újraindításához!');
				}
				return false;
			}
		}
	}
	oRequest.onreadystatechange = function() {
		if(oRequest.readyState==4 && file!='login.php') {
			document.getElementById(target).innerHTML = oRequest.responseText;
		}
	}
	oRequest.open('GET',file,true);
	oRequest.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
	oRequest.send(null);
}

function reloadMenu() {
	document.getElementById('navigation').innerHTML = document.getElementById('navigation_reload').innerHTML;
	document.getElementById('navigation_reload').innerHTML = '';
}

