// Esci dalla piattaforma
function EsciPiattaforma(){
	var conferma = window.confirm('Sei sicuro di voler uscire?');
	return conferma;
}

// Valida form Account
function check(){
	var messaggio = "<br><b><font color='#2f88b0'>Sono stati riscontrati i seguenti errori:</font></b><br>";
	check_form=true;
	Nome = document.getElementById("name").value;
	Filtro = /^([a-zA-Z0-9_\.\-\s\'\à?\è\à?\ù\ò\ì])+$/;
	if (!Filtro.test(Nome)) {
	 messaggio = messaggio + "- Campo nome non valido.<br>";
	 check_form=false;
	}
	
	Cognome = document.getElementById("surname").value;
	Filtro = /^([a-zA-Z0-9_\.\-\s\'\à?\è\à?\ù\ò\ì])+$/;
	if (!Filtro.test(Cognome)) {
	 messaggio = messaggio + "- Campo cognome non valido.<br>";
	 check_form=false;
	}                    
	
	EmailAddr = document.getElementById("mail").value;
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!Filtro.test(EmailAddr)) {
	 messaggio = messaggio + "- Formato e-mail non valido.<br>";
	 check_form=false;
	}	

	Username = document.getElementById("username").value;
	Filtro = /^([a-zA-Z0-9_\.\-\s\'\à?\è\à?\ù\ò\ì])+$/;
	if (!Filtro.test(Username)) {
	 messaggio = messaggio + "- Campo username non valido.<br>";
	 check_form=false;
	}   
	  
	Password = document.getElementById("newpassword").value;
	Filtro = /^([a-zA-Z0-9_\.\-\s\'\à?\è\à?\ù\ò\ì])+$/;
	if (!Filtro.test(Password)) {
	 messaggio = messaggio + "- Campo password non valido.<br>";
	 check_form=false;
	}  
	 
	RetypePassword = document.getElementById("retypepassword").value;
	Filtro = /^([a-zA-Z0-9_\.\-\s\'\à?\è\à?\ù\ò\ì])+$/;
	if (!Filtro.test(RetypePassword)) {
	 messaggio = messaggio + "- Password ripetuta non valida.<br>";
	 check_form=false;
	}  			
	
	if(Password != "" && RetypePassword != "" && Password != RetypePassword) {
	 messaggio = messaggio + "- Le due password non coincidono.<br>";
	 check_form=false;			
	}
 if (check_form){ 
	for (i=0;i<document.mieiDati.elements.length-1;i++){
		document.mieiDati[i].readOnly = true;
		document.mieiDati[i].style.background = '#CCCCCC';
	}
	return true;
 }
 else{
	document.getElementById('riepilogoErrori').innerHTML = messaggio;
	return false;
 }
}

// Convalida form recupero password
function recuperaPassword(){
	check_form=true;
	document.getElementById('messaggioInvioEmail').innerHTML =	"";
	EmailAddr = document.getElementById("email").value;
	Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	if (!Filtro.test(EmailAddr)) {
	 document.getElementById('messaggioInvioEmail').innerHTML = "Formato e-mail non valido.<br>";
	 check_form=false;
	}	
	return check_form;
}

//Funzioni per scivere div puntamenti
function puntamento(voceMenu){
 	//document.getElementById('linkAccount').className = 'abilitaOggetti';
	var spazio = "&nbsp;>&nbsp;";
	document.getElementById('linkPuntamenti').innerHTML = spazio + voceMenu;
}

function mioMenu(nome){
	var nomeMenuLivello1 = "Contenuti";
	var nomeMenuLivello2 = "Upload";
	var nomeMenuLivello1a = "Articoli";
	var nomeMenuLivello2a = "Chi siamo";
	var nomeMenuLivello3a = "Punti vendita";
	
	var spazio = "&nbsp;>&nbsp;";
	var testoLivello1 = spazio + nomeMenuLivello1;
	var testoLivello2 = spazio + nomeMenuLivello2;	

	if(nome == nomeMenuLivello1)
		document.getElementById('linkPuntamenti').innerHTML = testoLivello1;
	if(nome == nomeMenuLivello1a || nome == nomeMenuLivello2a || nome == nomeMenuLivello3a)
		document.getElementById('linkPuntamenti').innerHTML = testoLivello1 + spazio + nome;

	if(nome == nomeMenuLivello2)
		document.getElementById('linkPuntamenti').innerHTML = testoLivello2;
	if(nome == nomeMenuLivello1a || nome == nomeMenuLivello2a || nome == nomeMenuLivello3a)
		document.getElementById('linkPuntamenti').innerHTML = testoLivello2 + spazio + nome;
}
//Apri PopUp
function popUp(url,altezza,larghezza) {

	dtStart = new Date();                 
	var reWork = new RegExp('object','gi');	

	try {
			firstwindow=window.open(url,"name1","height=" +altezza +",width="+ larghezza +",scrollbars=1");
			firstwindow.focus();
		}
	catch(e) { }

	if(!reWork.test(String(firstwindow))){
		if(document.all){
			 alert("Blocco Pop-Up attivato!\nDevi disabilitare il blocco delle Pop-Up per poter proseguire.");
		} else{
			alert("Blocco Pop-Up attivato!\nDevi disabilitare il blocco delle Pop-Up per poter proseguire.");
		}
	}		
	return false;
}
//Preloading immagini

function setOpacity(obj, opacity) {
  opacity = (opacity == 100)?99.999:opacity;
  obj.style.filter = "alpha(opacity:"+opacity+")";
  obj.style.KHTMLOpacity = opacity/100;
  obj.style.MozOpacity = opacity/100;
  obj.style.opacity = opacity/100;
}

function initImage() {
  imageId = 'foto';
  image = document.getElementById(imageId);
  setOpacity(image, 0);
  image.style.visibility = 'visible';
  fadeIn(imageId,0);
}
function fadeIn(objId,opacity) {
  if (document.getElementById) {
    obj = document.getElementById(objId);
    if (opacity <= 100) {
      setOpacity(obj, opacity);
      opacity += 10;
      window.setTimeout("fadeIn('"+objId+"',"+opacity+")", 100);
    }
  }
}
