function initForms(){
	aInput = document.getElementsByTagName("input")
	aTextAreas = document.getElementsByTagName("textarea")
	aButtons = [];
	aText = [];
	
	for (var i=0; i<aInput.length; i++){
		switch(aInput[i].type){
			case 'text':
				aText[aText.length] = aInput[i];
				break;
			case 'password':
				aText[aText.length] = aInput[i];
				break;	
			case 'button':
				aButtons[aButtons.length] = aInput[i];
				break;
		}
	}
	
	for (var i=0; i<aButtons.length; i++){
		aButtons[i].onmouseover = function(){
			this.className = 'buttonhover'
		}
		aButtons[i].onmouseout = function(){
			this.className = 'button'
		}
	}
	
	for (var i=0; i<aText.length; i++){
		aText[i].onfocus = function(){
			this.className = 'textfocus'
		}
		aText[i].onblur = function(){
			this.className = 'text'
		}
	}

	for (var i=0; i<aTextAreas.length; i++){
		aTextAreas[i].onfocus = function(){
			this.className = 'textfocus'
		}
		aTextAreas[i].onblur = function(){
			this.className = 'text'
		}
	}		

}

function form1_validator(formid){

myform = document.getElementById(formid);
//controllo email
	if(myform.mittente.value == "" || myform.mittente.value.indexOf('@') < 0 || myform.mittente.value.indexOf('.') < 0 || myform.mittente.value.length < 6){
	    alert("Inserire un indirizzo e-mail valido");
	    myform.mittente.focus();
		return;
  	}
	
	//controllo oggetto
	if (myform.oggetto.value == ""){
		alert("Inserire l'oggetto del messaggio");
		myform.oggetto.focus();
		return;
	}
	
	//controllo testo
	if (myform.corpo.value == ""){
	    alert("Inserire il testo del messaggio");
	    myform.corpo.focus();
		return;
	}
	
	myform.submit();
}

/*****************************  FORM UPLOAD VALIDATOR *************************************************/

function formupload_validator(formid){
	var myform ;
	myform = document.getElementById(formid);

	//controllo titolo
	if (myform.titolo.value == ""){
	    alert("Inserire un titolo descrittivo per il file.");
	    myform.titolo.focus();
		return false;
	}
	
	//controllo testo
	if (myform.note.value == ""){
	    alert("Inserire una piccola descrizione del contenuto del file.");
	    myform.note.focus();
		return false;
	}
	
	//controllo la cartella
	if (myform.subfolder.value == ""){
		alert("selezionare la cartella in cui caricare il documento");
		myform.subfolder.focus();
		return false;
	}
	
	//controllo file
	if (myform.blob.value != ""){
		var r = confirm("Sei sicuro che sia proprio questo:\n\n" + myform.blob.value + "\n\nil file che vuoi caricare?");
		if (r==false) {
		    myform.blob.focus();
			return false;
		}	   
	}else{
		alert("selezionare un file da caricare");
		myform.blob.focus();
		return false;
	}

	
	//  OK POSSO INVIARE I DATI DEL FORM
	
	myform.submit();

}





function alertconferma() {
   var r=confirm("Press a button");
	 if (r==true){
	    document.write("You pressed OK!");
	 } else {
	    document.write("You pressed Cancel!");
	 }
}






// controllo video a fullscreen
function fullScreen(theURL) {
	window.open(theURL, '', 'fullscreen=yes, scrollbars=yes, width=' + screen.width + ', height='+ screen.height);
}


window.onload=function(){
	/*script per allineare le altezze delle due colonne al caricamento della pagina*/
	if (document.getElementById('leftcol') && document.getElementById('content')){
		var leftH = document.getElementById('leftcol').offsetHeight;
		var centerH = document.getElementById('content').offsetHeight;
		var maxH = (leftH > centerH)?leftH:centerH;
		document.getElementById('leftcol').style.height = document.getElementById('content').style.height = maxH + 'px';
	}
	
	if (document.all) setFooterPosition();
}

/*script per simulare il position:fixed sul footer*/
function setFooterPosition(){
	var clientH = document.documentElement.clientHeight;
	var yOffset = document.documentElement.scrollTop;
	var footer = document.getElementById("footer");
	footer.style.top=clientH-34+yOffset+'px';
}


if (document.all){
	window.onscroll=setFooterPosition;
	window.onresize=setFooterPosition;
}

// aggiunge la url ai bookmarks
function addbookmark(){	
	var	url = "http://www.sfpid.it";
	var	nome = "Scuola di Formazione di Psicoterapia ad Indirizzo Dinamico";
		if (document.all)
		window.external.AddFavorite(url,nome)
}

	

// forse serve per il tornasu dinamico
function click(e){if (document.all) if (event.button == 2) return false;if
	(document.layers) if (e.which == 3) return false;}
	function click2(){event.returnValue=false;return false;}if (document.layers)
	document.captureEvents(Event.MOUSEDOWN);document.onmousedown=click;document.oncontextmenu=click2;
	


// ################################################################
// ######   COOKIES ###############################################
// ################################################################

// SETTA la data di espirazione A 31 GIORNI

var exp = new Date();                      
exp.setTime(exp.getTime() + (1000 * 60 * 60 * 24 * 31));

var path = "/";

// SETTA IL COOKIE

function setCookieFont(value, expires, percorso) {
	document.cookie = "sFont=" + escape(value) + "; expires=" + expires.toGMTString() + "; path=" + escape(percorso);
}

function setCookieSize(value, expires, percorso) {
	document.cookie = "sSize=" + escape(value)+ "; expires=" + expires.toGMTString() + "; path=" + escape(percorso);
}

function setCookieAllinea(value, expires, percorso) {
	document.cookie = "sAllinea=" + escape(value)+ "; expires=" + expires.toGMTString() + "; path=" + escape(percorso);
}

//  SALVA I VALORI DEGLI ELEMENTI DEL FORM
function setValueFont(face) {
	document.getElementById('content').style.fontFamily = face;
	setCookieFont(face, exp, path);
}

function setValueSize(size) {
	document.getElementById('content').style.fontSize = size;
	setCookieSize(size, exp, path);
}

function setValueAllinea(allignement) {
	document.getElementById('content').style.textAlign = allignement;  
	setCookieAllinea(allignement, exp, path);
}


// #############################################################################################
// ########   FUNZIONI DI INIZIALIZZAZIONE #####################################################
// #############################################################################################


// inizializza le proprietà di style del content che consente a Mozilla di espandere bene il menù principale


function getCookie(NameOfCookie){

// Prima controlliamo se c'è un cookie memorizzato.
	if (document.cookie.length > 0){ 

// Poi controlliamo se il nome del cookie è conservato nell'oggetto
// "document.cookie"della pagina 
			begin = document.cookie.indexOf(NameOfCookie+"="); 
			
			if (begin != -1){ 
// Il nostro cookie era presente. 
// Il valore memorizzato nel cookie viene rimandato dalla funzione.
			begin += NameOfCookie.length+1; 
			end = document.cookie.indexOf(";", begin);
			if (end == -1) end = document.cookie.length;
			return unescape(document.cookie.substring(begin, end)); } 
			}
return null; 
// Il nostro cookie non era presente. 
// Il valore "null" viene rimandato dalla funzione.
}

