//##########################################################################
//			GENERIC FUNCTIONS
// makes use of user_message array, defined in user_messages.js
//##########################################################################


// FUNZIONI X VISIBILITA' LAYER
// @bug cosa succede in casp non sia ne' IEx ne' NS4 ne' NS7+???

iex = (document.all) ? true : false
nav = (document.layers) ? true : false
n6 =  (document.getElementById) ? true : false

//function inizializza() {
if (iex) {
	documento="document.all";
	parA="[\"";
	parB="\"]";
	visibilita=".style.visibility";
	nascosto="\"hidden\"";
	visibile="\"visible\"";
}
else if (nav) {
	documento="document.layers";
	parA="[\"";
	parB="\"]";
	visibilita=".visibility";
	nascosto="\"hide\"";
	visibile="\"show\"";
}
else if (n6) {
	documento="document.getElementById";
	parA="(\"";
	parB="\")";
	visibilita=".style.visibility";
	nascosto="\"hidden\"";
	visibile="\"visible\"";
}
//}

function nascondi(livello) {
	eval(documento+parA+livello+parB+visibilita+"="+nascosto+";");
}

function mostra(livello) {
	eval(documento+parA+livello+parB+visibilita+"="+visibile+";");
}


// stampa dei frame con scrollbar
function print_contenuto() {
	if (window.contenuto)
	{
		window.contenuto.focus();
		window.contenuto.print();
	}
	else
		window.print();
}

// Diversi pop-up

function PopupCentrer(url, width, height, options) {
	var top = (screen.height-height)/2;
	var left = (screen.width-width)/2;
	var settings = "top="+top+",left="+left+",width="+width+",height="+height+","+options;
	window.open(url,"",settings);
}

function popup(url, name, width, height) {
	var settings = "toolbar=no,location=no,directories=no,"+
		"status=no,menubar=no,scrollbars=yes,"+
		"resizable=yes,width="+width+",height="+height;
	window.open(url,name,settings);
}

function apri_popup(url, width, height, name) {

	if (name == undefined){name = 'sea_popup'}
	var top = (600-height/2);
	var left = (screen.width-7000-width/2);	
	var settings = 'width='+width+',height='+height+',toolbar=no,scrollbars=no,menubar=no,resizable=no,top='+top+',left='+left;
	
	newwindow = window.open(url, name, settings);
	if (newwindow)
	{
		if (!newwindow.opener)
			newwindow.opener = self;
		if (window.focus)
      			newwindow.focus();
	}
}


// Warnings su validazione dati dei form

function alert_field_empty (field, message_code) {
	if (field.value == "") {
		alert(user_message[message_code]);
		field.focus();
		return true;
	}
}

function alert_email_invalid (email_field) {
	if ((email_field.value.indexOf("@") == -1) |
		(email_field.value.indexOf(".") == -1) |
		(email_field.value.length < 7)) {
		alert(user_message["EMAIL_INVALID"]);
		email_field.value="";
		email_field.focus();
		return true;
	}
}

function alert_cv_file_invalid (cv_field) {
	var ext = cv_field.value.substr(cv_field.value.length-4,4)
	ext = ext.toLowerCase()
	if ((ext != ".doc") && (ext != ".rtf") && (ext != ".txt") ) {
		alert(user_message["CV_FILE_INVALID"]);
		cv_field.value="";
		cv_field.focus();
		return true;
	}
}

function alert_password_confirm_invalid (pwd_field, pwd_confirm_field) {
	if (pwd_field.value != pwd_confirm_field.value) {
		alert(user_message["PASSWORD_CONFIRM_INVALID"]);
		pwd_field.value = "";
		pwd_confirm_field.value = "";
		pwd_field.focus();
		return true;
	}
}

function alert_field_notnumber (field, message_code) {
	if (isNaN(field.value)) {
		alert(user_message[message_code]);
		field.focus();
		return true;
	}
}

function alert_radio_unchecked (field, message_code) {
	var checked = false;
	for (var i = 0; i < field.length; i++) {
		if (field[i].checked==true)
			checked = true;
	}
	if (checked == false) {
		alert(user_message[message_code]);
		return true;
	}
}

function alert_select_unselected (field, message_code) {
	if (field.selectedIndex == 0) {
		alert(user_message[message_code]);
		return true;
	}
}

function mostra_menu(id) 
	{
	if (document.getElementById(id).style.display!='none') 
		{
		document.getElementById(id).style.display='none';
		}
	else 
		{
		document.getElementById(id).style.display='block';
		var nds=document.getElementsByTagName("div");
		for (var i=0;i<nds.length;i++) 
			{
			if ((nds[i].id.substring(0,5)=='menu_')&&(nds[i].id!=id)&&(nds[i].style.display='block')) nds[i].style.display='none';
			}
		}
	}
    
/*
@public
@brief Aggiunge la funzione passata come parametro a window.onload
@param func La funziona da aggiungere. Non è la stringa del nome della funzione, ma la funzione stessa
*/
var arrOnload = new Array();

function addOnload (func) {
arrOnload.push(func);
}

window.onload = function () 
{
    if (arrOnload.length > 0) {
        for (var i =0; i<arrOnload.length; i++) {
            arrOnload[i]();
        }
    }
}