
function validateIscrizione(form) {
var UserMail = form.e_mail.value;
var UserMailControllo = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
var Userlang = form.lang.value;
	if(UserMail == "") {
		if(Userlang==1){
	    inlineMsg('e_mail','<h1>ATTENZIONE!</h1>Inserisci la tua mail.',3);
	    return false;
		}
		if(Userlang==2){
	    inlineMsg('e_mail','<h1>ATTENTION!</h1>Enter mail.',3);
	    return false;
		}
		if(Userlang==5){
	    inlineMsg('e_mail','<h1>ATTENTION!</h1>Inscrire mail.',3);
	    return false;
		}
  	}
 	if(!UserMail.match(UserMailControllo)) {
		if(Userlang==1){
    	inlineMsg('e_mail','<h1>ATTENZIONE!</h1>E-Mail inserita non corretta.<br><br><small>Deve essere inserita nel formato nome@esempio.it</small>',3);
    	return false;
		}
		if(Userlang==2){
    	inlineMsg('e_mail','<h1>ATTENTION!</h1>E-mail not correct.<br><br><small>It must be entered in format name@example.com</small>',3);
    	return false;
		}
		if(Userlang==5){
    	inlineMsg('e_mail','<h1>ATTENTION!</h1>E-mail pas correct.<br><br><small>Il doit être inscrite en format nom@exemple.fr</small>',3);
    	return false;
		}
		
  	}

//return true;
document.forms.iscrizione.action="iscrizione_nw.php?lang=" + Userlang;
}




function controlla_mail(form) {
var UserMail = form.e_mail.value;
var UserMailControllo = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
var UserAzienda = form.azienda.value;
var UserNome = form.nome.value;
var Userlang = form.lang.value;

	if(UserAzienda == "") {
		if(Userlang==1){
		    inlineMsg('e_mail','<h1>ATTENZIONE!</h1>Inserisci nome azienda.',3);
		    return false;
		}
		if(Userlang==2){
		    inlineMsg('e_mail','<h1>ATTENTION!</h1>Enter Firm name.',3);
		    return false;
		}
		if(Userlang==5){
		    inlineMsg('e_mail','<h1>ATTENTION!</h1>Inscrire nom de la Maison.',3);
		    return false;
		}
		
  	}
	
		
	if(UserNome == "") {
		if(Userlang==1){
	    	inlineMsg('e_mail','<h1>ATTENZIONE!</h1>Inserisci il tuo nome.',3);
	    	return false;
			}
		if(Userlang==2){
		  inlineMsg('e_mail','<h1>ATTENTION!</h1>Enter your name.',3);
		    return false;
		}
		if(Userlang==5){
		    inlineMsg('e_mail','<h1>ATTENTION!</h1>Inscrire Votre nom.',3);
		    return false;
		}
  	}
	
	if(UserMail == "") {
			if(Userlang==1){
	    	 inlineMsg('e_mail','<h1>ATTENZIONE!</h1>Inserisci la tua mail.',3);
	    	return false;
			}
			if(Userlang==2){
	    	 inlineMsg('e_mail','<h1>ATTENTION!</h1>Enter your mail.',3);
	    	return false;
			}
			if(Userlang==5){
	    	 inlineMsg('e_mail','<h1>ATTENTION!</h1>Inscrire Votre mail.',3);
	    	return false;
			}
	   
	    
  	}
 	if(!UserMail.match(UserMailControllo)) {
			if(Userlang==1){
	    	 inlineMsg('e_mail','<h1>ATTENZIONE!</h1>E-Mail inserita non corretta.<br><br><small>Deve essere inserita nel formato nome@esempio.it</small>',3);
	    	return false;
			}
    		if(Userlang==2){
	    	 inlineMsg('e_mail','<h1>ATTENTION!</h1>E-mail not correct.<br><br><small>It must be entered in format name@example.com</small>',3);
	    	return false;
			}
			if(Userlang==5){
	    	 inlineMsg('e_mail','<h1>ATTENTION!</h1>E-mail pas correct.<br><br><small>Il doit être inscrite en format nom@exemple.fr</small>',3);
	    	return false;
			}

  	}



//return true;
document.forms.contatti.action="mail.php?lang=" + Userlang;
}





// form validate LOGIN //
function validateLogin(form) {
  var UserMail = form.UserMail.value;
  var UserPass = form.UserPass.value;
  var UserMailControllo = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  // var UserPassControllo = /^[a-zA-Z0-9]+(([\'\,\.\- ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
  if(UserMail == "") {
    inlineMsg('UserMail','<h1>ATTENZIONE!</h1>Inserisci la tua mail di registrazione.',3);
    return false;
  }
  if(!UserMail.match(UserMailControllo)) {
    inlineMsg('UserMail','<h1>ATTENZIONE!</h1>E-Mail inserita non corretta.<br><br><small>Deve essere inserita nel formato nome@esempio.it</small>',3);
    return false;
  } 
  if(UserPass == "") {
    inlineMsg('UserPass','<h1>ATTENZIONE!</h1>Il campo "Password" &egrave; obbligatorio.',3);
    return false;
  }
  /* if(!UserPass.match(UserPassControllo)) {
    inlineMsg('UserPass','<h1>ATTENZIONE!</h1>Password inserita non corretta.<br><br><small>La password deve avere almeno 6 caratteri; ammessi A..Z, a..z, 0..9</small>',3);
    return false;
  } */
return true;
}


//form validateDiscussione
function validateDiscussione(form) {
  var titoloDisc = form.titoloDisc.value;
  var descDisc = form.descDisc.value;
  if(titoloDisc == "") {
    inlineMsg('titoloDisc','<h1>ATTENZIONE!</h1>Il campo "Titolo" &egrave; obbligatorio.',3);
    return false;
  }
  if(descDisc == "") {
    inlineMsg('descDisc','<h1>ATTENZIONE!</h1>Il campo "SottoTitolo" &egrave; obbligatorio. Inserisci una descrizione dell&#8217;argomento',3);
    return false;
  } 
return true;
}

//form validateCommento
function validateCommentoForum(form) {
  var testoCommento = form.testoCommento.value;
  if(testoCommento == "") {
    inlineMsg('testoCommento','<h1>ATTENZIONE!</h1>Il campo "Testo" &egrave; obbligatorio.',3);
    return false;
  }
return true;
}

//limita caratteri text area forum nuova discussione
function limitaText(areaName,limit) {
	if (areaName.value.length>limit) {
		areaName.value=areaName.value.substring(0,limit);
		alert("ATTENZIONE! Hai superato il limite massimo di caratteri consentiti!")
		//inlineMsg('descDisc','<h1>ATTENZIONE!</h1>Hai superato il limite massimo di caratteri consentiti!',3);
		//inlineMsg('testoAnnunci','<h1>ATTENZIONE!</h1>Hai superato il limite massimo di caratteri consentiti!',3);
	}	
}


// form validateContatti 
function validateContatti(form) {
  var mail = form.mail.value;
  var mailControllo = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var nome = form.nome.value;
  var securityCode = form.securityCode.value;
  if(nome == "") {
    inlineMsg('nome','<h1>ATTENZIONE!</h1>Il campo "Nome" &egrave; obbligatorio.',3);
    return false;
  }      
  if(mail == "") {
    inlineMsg('mail','<h1>ATTENZIONE!</h1>Il campo "E-Mail" &egrave; obbligatorio.',3);
    return false;
  }
  if(!mail.match(mailControllo)) {
    inlineMsg('mail','<h1>ATTENZIONE!</h1>E-Mail inserita non corretta.<br><br><small>Deve essere inserita nel formato nome@esempio.it</small>',3);
    return false;
  }
  if(securityCode == "") {
    inlineMsg('securityCode','<h1>ATTENZIONE!</h1>Inserisci il codice che compare nell&#8217;immagine.',3);
    return false;
  }
return true;
}


// form validateRegistrazione //
function validateRegistrazione(form) {
  var nome = form.nome.value;
  var cognome = form.cognome.value;
  var provincia = form.provincia.value;
  var annonascita = form.annonascita.value;
  var nickname = form.nickname.value;
  var nicknameControllo = /^[a-zA-Z0-9]+(([\'\,\.\- ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
  var mail = form.mail.value;
  var mailControllo = /^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$/;
  var pass = form.pass.value;
  var passControllo = /^[a-zA-Z0-9]+(([\'\,\.\- ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
  var passRipeti = form.passRipeti.value;
  var securityCode = form.securityCode.value;
  
  if(nome == "") {
    inlineMsg('nome','<h1>ATTENZIONE!</h1>Il campo "Nome" &egrave; obbligatorio.',3);
    return false;
  }
  if(cognome == "") {
    inlineMsg('cognome','<h1>ATTENZIONE!</h1>Il campo "Cognome" &egrave; obbligatorio.',3);
    return false;
  }
  if(provincia == "") {
    inlineMsg('provincia','<h1>ATTENZIONE!</h1>Il campo "Provincia" &egrave; obbligatorio.',3);
    return false;
  }
  if(annonascita == "") {
    inlineMsg('annonascita','<h1>ATTENZIONE!</h1>Il campo "Anno di nascita" &egrave; obbligatorio.',3);
    return false;
  }
  if(nickname.length < 6) {
    inlineMsg('nickname','<h1>ATTENZIONE!</h1>Il campo "Nickname" &egrave; obbligatorio.<br><br><small>Sar&agrave; il nome che comparir&agrave; nei messaggi/annunci che inserirai. Il Nickname deve avere almeno 6 caratteri.</small>',5);
    return false;
  }  
  if(!nickname.match(nicknameControllo)) {
    inlineMsg('nickname','<h1>ATTENZIONE!</h1>Nickname inserito non corretto.<br><br><small>Il Nickname deve avere almeno 6 caratteri; ammessi aA..zZ, 0..9</small>',5);
    return false;
  }
  if(mail == "") {
    inlineMsg('mail','<h1>ATTENZIONE!</h1>Il campo "E-Mail" &egrave; obbligatorio.',3);
    return false;
  }
  if(!mail.match(mailControllo)) {
    inlineMsg('mail','<h1>ATTENZIONE!</h1>E-Mail inserita non corretta.<br><br><small>Deve essere inserita nel formato nome@esempio.it</small>',3);
    return false;
  }
  if(pass.length < 6) {
    inlineMsg('pass','<h1>ATTENZIONE!</h1>Il campo "Password" &egrave; obbligatorio.<br><br><small>La Password deve avere almeno 6 caratteri.</small>',3);
    return false;
  }  
  if(!pass.match(passControllo)) {
    inlineMsg('pass','<h1>ATTENZIONE!</h1>Password inserita non corretta.<br><br><small>La password deve avere almeno 6 caratteri; ammessi aA..zZ, 0..9</small>',5);
    return false;
  }
  if(passRipeti == "") {
    inlineMsg('passRipeti','<h1>ATTENZIONE!</h1>Il campo "Ripeti Password" &egrave; obbligatorio.',3);
    return false;
  } 
  if(pass != passRipeti) {
    inlineMsg('passRipeti','<h1>ATTENZIONE!</h1>Le Password inserite non coincidono.',3);
    return false;
  } 
  if(securityCode == "") {
    inlineMsg('securityCode','<h1>ATTENZIONE!</h1>Inserisci il codice che compare nell&#8217;immagine.',3);
    return false;
  }
return true;
}

// form validatePassword //
function validatePassword(form) {
  var pass = form.pass.value;
  var passControllo = /^[a-zA-Z0-9]+(([\'\,\.\- ][a-zA-Z0-9 ])?[a-zA-Z0-9]*)*$/;
  var passRipeti = form.passRipeti.value;

  if(pass.length < 6) {
    inlineMsg('pass','<h1>ATTENZIONE!</h1>Il campo "Password" &egrave; obbligatorio.<br><br><small>La Password deve avere almeno 6 caratteri.</small>',3);
    return false;
  }  
  if(!pass.match(passControllo)) {
    inlineMsg('pass','<h1>ATTENZIONE!</h1>Password inserita non corretta.<br><br><small>La password deve avere almeno 6 caratteri; ammessi aA..zZ, 0..9</small>',5);
    return false;
  }
  if(passRipeti == "") {
    inlineMsg('passRipeti','<h1>ATTENZIONE!</h1>Il campo "Conferma Password" &egrave; obbligatorio.',3);
    return false;
  } 
  if(pass != passRipeti) {
    inlineMsg('passRipeti','<h1>ATTENZIONE!</h1>Le Password inserite non coincidono.',3);
    return false;
  } 
return true;
}



//form validateCreaPPC//
function validateCreaPPC(form) {
return true;
}


//form validateCaricaPPC
function validateCaricaPPC(form) {
return true;
}


// SCRIPT CONTROLLO COMUNE PER TUTTO //

var MSGTIMER = 40;
var MSGSPEED = 10;
var MSGOFFSET = 4;
var MSGHIDE = 4;

function inlineMsg(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg')) {
    msg = document.createElement('div');
    msg.id = 'msg';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  //msg.style.top = topposition + 'px';
  msg.style.top = '450 px';
  msg.style.left = (window.screen.width-370)/2 + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;
  }
  window.setTimeout("hideMsg()", (autohide * 1000));
}

function hideMsg(msg) {
  var msg = document.getElementById('msg');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg(0)", MSGTIMER);
  }
}

function fadeMsg(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg');
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}






function inlineMsg2(target,string,autohide) {
  var msg;
  var msgcontent;
  if(!document.getElementById('msg2')) {
    msg = document.createElement('div');
    msg.id = 'msg2';
    msgcontent = document.createElement('div');
    msgcontent.id = 'msgcontent';
    document.body.appendChild(msg);
    msg.appendChild(msgcontent);
    msg.style.filter = 'alpha(opacity=0)';
    msg.style.opacity = 0;
    msg.alpha = 0;
  } else {
    msg = document.getElementById('msg2');
    msgcontent = document.getElementById('msgcontent');
  }
  msgcontent.innerHTML = string;
  msg.style.display = 'block';
  var msgheight = msg.offsetHeight;
  var targetdiv = document.getElementById(target);
  targetdiv.focus();
  var targetheight = targetdiv.offsetHeight;
  var topposition = topPosition(targetdiv) - ((msgheight - targetheight) / 2);
  //msg.style.top = topposition + 'px';
  msg.style.top = '450 px';
  msg.style.left = (window.screen.width-370)/2 + 'px';
  clearInterval(msg.timer);
  msg.timer = setInterval("fadeMsg2(1)", MSGTIMER);
  if(!autohide) {
    autohide = MSGHIDE;
  }
  window.setTimeout("hideMsg2()", (autohide * 1000));
}

function hideMsg2(msg) {
  var msg = document.getElementById('msg2');
  if(!msg.timer) {
    msg.timer = setInterval("fadeMsg2(0)", MSGTIMER);
  }
}

function fadeMsg2(flag) {
  if(flag == null) {
    flag = 1;
  }
  var msg = document.getElementById('msg2');
  //alert(msg);
  var value;
  if(flag == 1) {
    value = msg.alpha + MSGSPEED;
  } else {
    value = msg.alpha - MSGSPEED;
  }
  msg.alpha = value;
  msg.style.opacity = (value / 100);
  msg.style.filter = 'alpha(opacity=' + value + ')';
  if(value >= 99) {
    clearInterval(msg.timer);
    msg.timer = null;
  } else if(value <= 1) {
    msg.style.display = "none";
    clearInterval(msg.timer);
  }
}



// calcola l'altezza //
function topPosition(target) {
  var top = 100;
  if(target.offsetParent) {
    while(1) {
      top += target.offsetTop;
      if(!target.offsetParent) {
        break;
      }
      target = target.offsetParent;
    }
  } else if(target.y) {
    top += target.y;
  }
  return top;
}
