window.onload = function() {
	setFooter();
}
window.onresize = function() {
	setFooter();
}

// Inizializzazione della variabile contatore anti-spam
var counterKeys = 0;

// Mostra / nasconde i sottomenu
function showHide(section){
	var children = section.parentNode.childNodes;
	for (i = 0; i < children.length; i++) {
		if (children[i].className == "subsection") {
			if (children[i].style.display == 'block'){
				children[i].style.display = 'none';
			} else {
				children[i].style.display = 'block';
			}
		}
	}
}

// Restituisce l'atezza in px della finestra
function getWindowHeight() {
	var windowHeight = 0;
	if (typeof(window.innerHeight) == 'number') {
		windowHeight = window.innerHeight;
	} else {
		if (document.documentElement && document.documentElement.clientHeight) {
			windowHeight = document.documentElement.clientHeight;
		}	else {
			if (document.body && document.body.clientHeight) {
				windowHeight = document.body.clientHeight;
			}
		}
	}
	return windowHeight;
}
// Posiziona il footer in fondo alla pagina
function setFooter() {
	if (document.getElementById) {
		var windowHeight = getWindowHeight();
		if (windowHeight>0) {
			var contentHeight = document.getElementById('box').offsetHeight;
			var footerElement = document.getElementById('footer');
			var footerHeight = footerElement.offsetHeight;
			if (windowHeight - (contentHeight + footerHeight) >= 0) {
				footerElement.style.position = 'relative';
				footerElement.style.top = (windowHeight - (contentHeight + footerHeight) - 5) + 'px';
			} else {
				footerElement.style.position = 'static';
			}
		}
	}
}

// Questa funzione viene invocata quando si verifica un evento onKeyUp sul form
function avoidSpam(){
	// Aumenta il contatore anti-spam. Se rimane a 0 quando i dati del form verranno passati al db,
	// il valore enabled sarà N e il messaggio, sebbene salvato, non sarà visualizzato
	counterKeys++;
}

// Invocata dal submit di un form con script anti spam
function submitMsg(btn){
	// Append di un input hidden al form per il passaggio del contatore anti-spam
	frm = btn.form;
	inputCounter = document.createElement('INPUT');
	inputCounter.setAttribute('name', 'counter');
	inputCounter.setAttribute('type', 'hidden');
	inputCounter.setAttribute('value', counterKeys);
	frm.appendChild(inputCounter);
	frm.submit();
}

function changingPage(startingRow){
	var obj = document.getElementById('input_starting_row');
	obj.value = startingRow;
	obj.form.submit();
}

function checkPrivacy(checkbox) {
	var btn = document.getElementById('btnSubmit');
	if (checkbox.checked == true) {
		btn.removeAttribute('disabled');	
	} else {
		btn.setAttribute('disabled', 'disabled');
	}
}
