// Formulaire Inscription
function submit_register_1(is_mybtn){
	msg_erreur="Sono successi i seguenti errori \n";
	
	if(document.form_register.pseudo.value == ''){
		msg_erreur += "- Inserisci il tuo nome di accesso. \n";
	}
	
	if(!VerificationEmail(document.form_register.email.value)){
		msg_erreur += "- Il tuo indirizzo mail deve avere il seguente formato xxx@yyy.zzz\nExemple : jsmith@votre-hebergeur.com \n";
	}
	
	if(document.form_register.password.value == ''){
		msg_erreur += "- Inserisci la tua password. \n";
	}
	
	if(document.form_register.password.value != document.form_register.confirmpassword.value){
		msg_erreur += "- Conferma la password. \n";
	}
	
	if(document.form_register.code.value == ''){
		msg_erreur += "- Per favore inserisci il codice di sicurezza. \n";
	}
	
	if(document.getElementById("retour_verif_pseudo").innerHTML == "Non disponibile"){
		msg_erreur += "- Nome di accesso non valido. \n";
	}
	if(document.getElementById("retour_verif_email").innerHTML == "Non disponibile"){
		msg_erreur += "- Indirizzo mail non valido. \n";
	}
	
	if(msg_erreur!="Sono successi i seguenti errori \n"){ 
		alert(msg_erreur); 
		if(is_mybtn == 0)
			{ return false; }
	}	
	
	else{
		if(is_mybtn == 1)
			{ document.form_register.submit(); }
	}	
}

function submit_register_2(is_mybtn){
	msg_erreur="Sono successi i seguenti errori \n";
	
	ext = recup_extension(document.form_register.photo.value);// on appelle la fonction de récupération de l'extension et on récupere l'extension
	if(ext){
		if(ext!=".jpg" && ext!=".jpeg"){
			msg_erreur += "- Scegli un file jpg per le tue foto.";
		}
	}
	
	if(msg_erreur!="Sono successi i seguenti errori \n"){ 
		alert(msg_erreur); 
		if(is_mybtn == 0)
			{ return false; }
	}	
	
	else{
		if(is_mybtn == 1)
			{ document.form_register.submit(); }
	}	
}
/////////////////////////////////////////////////////////////////////////

function submit_search(is_mybtn,page)
	{
	if(page == 1)
		{ form = document.form_global_search_page; }
	else
		{ form = document.form_global_search; }
		
	if(form.keyword_global_search_site.value == '' || form.keyword_global_search_site.value == 'Cercare una ricetta, un utente o un ingrediente?')
		{ 
		alert("Per favore inserisci una ricerca"); 
		if(is_mybtn == 0)
			{ return false; }
		}
	else
		{
		if(is_mybtn == 1)
			{ form.submit(); }
		}
	}
function submit_search_blog(my_var)
	{
	if(document.getElementById('keyword_blog_search').value == '')
		{
		alert("Per favore inserisci una ricerca"); 
		if(my_var == 0)
			{ return false; }
		}
	else
		{document.form_blog_search.submit();}
	}
function validate_sign_in()
	{
	var keycode;
	if (window.event) keycode = window.event.keyCode;
	//else if (e) keycode = e.which;

	if(keycode == 13)
		{ document.form_sign.submit(); }
	}
	
function submit_sign_in()
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if(document.form_sign.login.value == '')
		{ msg_erreur += "- Inserisci la tua login \n";}
		
	if(document.form_sign.password.value == '')
		{ msg_erreur += "- Inserisci la tua password \n";}
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{document.form_sign.submit();}
	}
	
function submit_sign_in2()
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if(document.form_sign2.login.value == '')
		{ msg_erreur += "- Inserisci la tua login \n";}
		
	if(document.form_sign2.password.value == '')
		{ msg_erreur += "- Inserisci la tua password \n";}
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{document.form_sign2.submit();}
	}

function submit_register()
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if(document.form.first_name.value == '')
		{ msg_erreur += "- Inserisci il cognome \n";}

	if(document.form.last_name.value == '')
		{ msg_erreur += "- Inserisci il nome \n";}
		
	if(!document.form.email.value.match( "\\S+@\\S+\\.\\S+" ))
		{ msg_erreur += "- Inserisci indirizzo email valido \n";}
		
	if(document.form.password.value == '')
		{ msg_erreur += "- Inserisci la tua password \n";}
		
	if(document.form.confirm_password.value == '')
		{ msg_erreur += "- Conferma la password \n";}
		
		
	if(document.form.pseudo.value == '')
		{ msg_erreur += "- Inserisci il tuo nickname \n";}
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{document.form_sign.submit();}
	}

function submit_search_member()
	{
	document.form_search_member.submit();
	}

function submit_newsletter_subscribe(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	if(!document.form_newsletter_subscribe.email.value.match( "\\S+@\\S+\\.\\S+" ))
		{ msg_erreur += "- Inserisci indirizzo email valido \n";}
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ 
		alert(msg_erreur); 
		if(is_mybtn == 0)
			{ return false; }
		}
	else
		{
		if(is_mybtn == 1)
			{ document.form_newsletter_subscribe.submit(); }
		}
	}

// FORMULAIRE SEND TO FRIEND
function validateSendToFriendForm(chaine,verif,theForm)
{
	if(theForm["name"].value=="")
		{
		alert("Please enter your name" );
		theForm.name.focus();
		return false;
		}
		
	if(!theForm.email.value.match( "\\S+@\\S+\\.\\S+" ))
		{ 
		alert("Inserisci indirizzo email valido address");
		theForm.email.focus();
		return false;
		} 
		
	if(!theForm.friend_email.value.match( "\\S+@\\S+\\.\\S+" ))
		{ 
		alert("Inserisci un indirizzo email valido di un tuo amico");
		theForm.friend_email.focus();
		return false;
		} 
	if(verif_chaine(chaine,verif) == 1 )
		{
		alert("Hai dimenticato il link. L'abbiamo aggiunto per te" );
		theForm.comments.value += "\n\nControlla la seguente ricetta... "+verif;
		theForm.comments.focus();
		return false;
		}
	else
		{theForm.submit(); }
}

function verif_chaine(chaine,verif)
	{
	if(chaine.indexOf(verif)==-1)
		{ retour = 1;}
	else
		{ retour = 0;}
	return retour;
	}
////////////////////////////////////////////////////

// FORMULAIRE COMMENTAIRE RECETTE
function validateCommentForm(theForm)
{
	if( theForm["comment"].value=="" )
	{
		alert("Grazie per inserire un commento prima di inviare.");
		theForm.comment.focus();
		//return false;
	}
	else
	{theForm.submit(); }
}


// FORMULAIRE CONTACT
function VerifyEmail( email )
{	
	if( email && email.match( "\\S+@\\S+\\.\\S+" ) )
	{
		return true;
	}
	else
	{
		alert( "Il tuo indirizzo mail deve avere il seguente formato xxx@yyy.zzz\nExemple : jsmith@votre-hebergeur.com" );
		return false;
	}
	return true;
}

function validateForm( theForm )
{
	if( theForm["firstname"].value=="" )
	
	{
		alert( "Inserisci il cognome." );
		theForm.firstname.focus();
		return false;
	}
	
	if( theForm["name"].value=="" )
	{
		alert( "Inserisci il nome." );
		theForm.name.focus();
		return false;
	}


	if( !VerifyEmail( theForm["email"].value ) )
	{
		theForm["email"].focus();
		return false;
	}
	

	if( theForm["comments"].value=="" )
	{
		alert( "Inserisci un commento." );
		theForm.comments.focus();
		return false;
	}

	theForm.submit(); 
}


// FORMULAIRE NEWSLETTER
function validate_form_newsletter(theForm)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	if(theForm.language.value == '')
		{ msg_erreur += "- La lingua e' obbligatoria \n";}
		
	if(theForm.subject.value == '')
		{ msg_erreur += "- Il soggetto e' obbligatorio \n";}

	if(theForm.message.value == '')
		{ msg_erreur += "- Il messaggio e' obbligatorio \n";}
		
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{theForm.submit();}
	}
/////////////////////////////////////

function input_focus(id)
	{
	document.getElementById(id).style.backgroundColor = "#ddeadd";
	}
	
function input_blur(id)
	{
	document.getElementById(id).style.backgroundColor = "#f1f6f1";	
	}

function focus_textarea(id,txt)
	{
	if(document.getElementById(id).value == txt)
		{
		document.getElementById(id).className = "textarea_register";
		document.getElementById(id).value = "";
		}
	}
function blur_textarea(id,txt)
	{
	if(document.getElementById(id).value == "")
		{
		document.getElementById(id).value = txt;
		document.getElementById(id).className = "textarea_register_exemple";
		}
	}

// Formulaire choix des commentaires à imprimer
function select_all(nb_comment)
	{
	for(i=1;i<=nb_comment;i++)
		{
		comment = "comment_num_"+i;
		document.getElementById(comment).checked = true;
		}
	}
function unselect_all(nb_comment)
	{
	for(i=1;i<=nb_comment;i++)
		{
		comment = "comment_num_"+i;
		document.getElementById(comment).checked = false;
		}
	}
///////////////////////////////////////		

function recup_extension(fichier) // fonction de récupération extension fichier
{
	 if (fichier!="")// si le champ fihier n'est pas vide
	 {
		nom_fichier=fichier;// on récupere le chemin complet du fichier
		nbchar = nom_fichier.length;// on compte le nombre de caractere que compose ce chemin
		extension = nom_fichier.substring(nbchar-4,nbchar); // on récupere les 4 derniers caracteres
		extension=extension.toLowerCase(); //on uniforme les caracteres en minuscules au cas ou cela aurait été écris en majuscule...
		return extension; // on renvoi l'extension vers la fonction appelante
	 }
}

// FORMULAIRE CREER RECETTE
function submit_recipe()
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if(document.TheForm.name.value == '')
		{ msg_erreur += "- Il nome e' obbligatorio \n";}

	if(document.TheForm.id_cooking_style.value == '')
		{ msg_erreur += "- Lo stile in cucina e' obbligatorio \n";}

	if(document.TheForm.id_recipe_type.value == '')
		{ msg_erreur += "- Il tipo di ricetta e' obbligatorio \n";}
	
	if(document.TheForm.level.value == '')
		{ msg_erreur += "- Il livello e' obbligatorio \n";}
	
	if(document.TheForm.nb_people.value == '')
		{ msg_erreur += "- Il numero di persone e' obbligatorio \n";}
	if(isNaN(document.TheForm.nb_people.value))
		{ msg_erreur += "- Il numero di persone deve essere un numero \n";}
		
	if(document.TheForm.preparation_delay.value == '')
		{ msg_erreur += "- I tempi di preparazione sono obbligatori \n";}
	if(isNaN(document.TheForm.preparation_delay.value))
		{ msg_erreur += "- I tempi di preparazione deve essere un numero \n";}
		
	if(document.TheForm.temps_total.value == '')
		{ msg_erreur += "- Il tempo di cottura e' obbligatorio \n";}
	if(isNaN(document.TheForm.temps_total.value))
		{ msg_erreur += "- Il tempo di cottura deve essere un numero \n";}
		
	if(document.TheForm.photo_recette.value != "")
		{
		extension_photo = recup_extension(document.TheForm.photo_recette.value);
		if(extension_photo != ".jpg" && extension_photo != ".gif" && extension_photo != ".png")
			{ msg_erreur += "- Formato del documento non valido \n";}
		}	
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); return false; }
	else
		{document.TheForm.submit();}
	}

function check_mesure()
	{
	// 11 = autres
	if(document.getElementById('mesure').value == "11")
		{ document.getElementById('mesure_txt').style.display = "inline"; }
	else
		{ document.getElementById('mesure_txt').style.display = "none"; }
	}
////////////////////////////

// form invite ami
function submit_invite(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if(document.form_invite.hidden_guest_list.value == '')
		{ msg_erreur += "- Inserisci almeno un destinario \n";}
		
	if(document.form_invite.message.value == '')
		{ msg_erreur += "- Inserisci un messaggio \n";}

	if(msg_erreur!="Sono successi i seguenti errori \n")
		{
		alert(msg_erreur); 
		if(is_mybtn == 0)
			{ return false; }
		}
	else
		{
		if(is_mybtn == 1)
			{ document.form_invite.submit(); }
		}
		
	}
	
// form importer amis
function submit_import_friends()
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if(!document.form_import.email.value.match( "\\S+@\\S+\\.\\S+" ))
		{ msg_erreur += "- La tua email e' obbligatoria \n";}

	var domaine = document.form_import.email.value.split("@");
	/*if(domaine[1] != "hotmail.com" && domaine[1] != "hotmail.fr" && domaine[1] != "gmail.com" && domaine[1] != "yahoo.fr" && domaine[1] != "yahoo.com")
		{ msg_erreur += "- Devi avere un indirizzo hotmail,gmail o yahoo  \n";}*/
	if(domaine[1] != "gmail.com" && domaine[1] != "hotmail.com" && domaine[1] != "hotmail.fr")
		{ msg_erreur += "- Devi avere un indirizzo gmail o hotmail \n";}

	if(document.form_import.password.value == '')
		{ msg_erreur += "- La tua password e' obbligatoria \n";}

	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); return false; }
	else
		{document.form_import.submit();}
	}
	
// form importer amis csv
function submit_import_friends_csv()
	{
	msg_erreur="Sono successi i seguenti errori \n";

	var check_format = check_format_fichier('.csv',document.form_import_csv.fichier.value);
	
	if(check_format == 1)
		{ 
		msg_erreur+="- Documento non valido, e' richiesta estensione .csv \n";
		} 	

	if(document.form_import_csv.messagery.value == '')
		{ msg_erreur += "- La casella vocale e' obbligatoria \n";}

	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); return false; }
	else
		{document.form_import_csv.submit();}
	}	

// form validerimporter amis csv
function submit_import_validate()
	{
	msg_erreur="Sono successi i seguenti errori \n";

	// on defini un tableau de toutes les imgs
	var anchors = document.getElementsByTagName('input');
	var nb_check = 0;
	// on boucle le tableau
	for (var i=0; i<anchors.length; i++)
		{
		var anchor = anchors[i];
		// Ne zoom que les elements qui possede l'attribut zoomable et ou zoomable==1
		its_checkbox = String(anchor.getAttribute('its_checkbox'));
		
		if(its_checkbox==1)
			{
			id_anchor = String(anchor.getAttribute('id'));
			if(document.getElementById(id_anchor).checked)
				{ nb_check++; }
			}
		}

	if(nb_check == 0)
		{ msg_erreur += "- Per cortesia controlla almeno 1 contatto \n"; }
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); return false; }
	else
		{document.form_import_validate.submit();}
	}	
	
// confirm delete friend
function confirm_delete_friend(page)
	{
	if(confirm("Vuoi davvero cancellare questo amico?"))
		{ window.location = page;}
	}
	
	
// Lost password
function submit_lost_password()
	{
	if(!document.form.email.value.match( "\\S+@\\S+\\.\\S+" ))
		{ alert("Per cortesia inserisci una mail valida"); return false;  }
	else
		{document.form.submit();}
	}
	
function check_form_contact()
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if(document.form_contact.firstname.value == '')
		{ msg_erreur += "- Il cognome e' obbligatorio \n";}
	if(document.form_contact.name.value == '')
		{ msg_erreur += "- Il nome e' obbligatorio \n";}
		
	if(!document.form_contact.email.value.match( "\\S+@\\S+\\.\\S+" ))
		{ msg_erreur += "- Inserisci indirizzo email valido \n";  }
	if(document.form_contact.object.value == '')
		{ msg_erreur += "- Il soggetto e' obbligatorio \n";}
	if(document.form_contact.comments.value == '')
		{ msg_erreur += "- I commenti sono obbligatori \n";}
	if(document.form_contact.code.value == '')
		{ msg_erreur += "- Il codice di sicurezza e' obbligatorio \n";}
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); return false; }
	else
		{document.form_contact.submit();}
	}
	
function verif_dispo(champ,value,default_value)
	{
	if(value == default_value)
		{
		document.getElementById("retour_verif_"+champ).innerHTML = "";
		}
	else
		{
	   var xhr_object = null; 
		 value = noaccent(value);
	   if(window.XMLHttpRequest) // Firefox 
		  xhr_object = new XMLHttpRequest(); 
		else if(window.ActiveXObject) // Internet Explorer 
		  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	   else { // XMLHttpRequest non supporté par le navigateur 
		  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
		  return; 
	   } 
	 
	   xhr_object.open("POST", "verif_dispo.php", true); 
		 
	   xhr_object.onreadystatechange = function() { 
		  if(xhr_object.readyState == 4) 
			 { 
			 if(xhr_object.responseText == 0)
				{
				document.getElementById("retour_verif_"+champ).innerHTML = "";
				//document.getElementById('retour_verif').style.color = "green";
				}
			else
				{
				document.getElementById("retour_verif_"+champ).innerHTML = "Non disponibile"; 
				document.getElementById("retour_verif_"+champ).style.color = "red";
				}
			 }
	   } 
	 
	   xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	   var data = "champ="+champ+"&value="+value;
	   xhr_object.send(data); 
		}
	}		
	
 function replaceAll(str, search, repl) {
 while (str.indexOf(search) != -1)
 str = str.replace(search, repl);
 return str;
 } 

 // Remplace les caractères accentués
 function noaccent(str) {
 var spec = new Array("é", "É", "è", "È", "ê", "Ê", "ë", "Ë", "à", "À", "ù", "Ù", "ç", "Ç");
 var norm = new Array("e", "E", "e", "E", "e", "E", "e", "E", "a", "A", "u", "U", "c", "C");
 for (var i = 0; i < spec.length; i++)
 str = replaceAll(str, spec[i], norm[i]);
 return str;
 }
 
  // verif supprimer son compte
function submit_profil_delete(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if(document.form_profil_delete.account.checked == false && document.form_profil_delete.comments.checked == false)
		{ msg_erreur += "- Devi scegliere almeno una cosa da cancellare \n";}

		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); return false; }
	else
		{
		if(is_mybtn == 1)
			{ document.form_profil_delete.submit();}
		}
	
	}
	
 // GROUPES /////////////////////////////////////////////////////////////////
// creation groupe
function submit_group_create(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	if (document.form_group_create.name.value == '')
		 { msg_erreur+="- Inserisci un nome \n"; } 	
	
	// si il y a une photo on verifie le format
	if(document.form_group_create.avatar.value != '')
		 { 
		var extension = recup_extension(document.form_group_create.avatar.value);
		
		if(extension != '.jpg')
			{ msg_erreur += "- Formato immagine non valido,solo jpg \n"; }
		 } 
		 
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_group_create.submit(); }
		}
	}
	
// ajout admin
function submit_group_admin_add(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	if (document.form_group_admin_add.id_admin.value == '')
		 { msg_erreur+="- Schegli un nome dalla lista \n"; } 	
		 
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_group_admin_add.submit(); }
		}
	}

// ajout membre
function submit_group_membre_add(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	if (document.form_group_member_add.id_member.value == '')
		 { msg_erreur+="- Schegli un nome dalla lista \n"; } 	
		 
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_group_member_add.submit(); }
		}
	}

// verifie les formats de fichiers de partage avec le groupe et qu'il y a qqch a partager
function submit_form_activity(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	// si tout est vide
	if(document.form_activity.comment.value == '' && document.form_activity.img_filename.value == '' && document.form_activity.video_filename.value == '' && document.form_activity.embed.value == '')
		{
		msg_erreur += "- Inserisci un messaggio \n";	
		}
	
	// si il y a une photo on verifie le format
	if(document.form_activity.img_filename.value != '')
		 { 
		var extension = recup_extension(document.form_activity.img_filename.value);
		
		if(extension != '.jpg')
			{ msg_erreur += "- Formato immagine non valido,solo jpg \n"; }
		 } 	
		 
	// si il y a une video on verifie le format
	if(document.form_activity.video_filename.value != '')
		 { 
		var extension = recup_extension(document.form_activity.video_filename.value);
		
		if(extension != ".flv" && extension != ".mpg" && extension != ".3gp" && extension != ".avi" && extension != "mpeg"  && extension != ".wmv" && extension != ".vob")
			{ 
			msg_erreur+="- Solo i formati seguenti sono accettati: flv,.mpg,.mpeg,.3gp,.avi,.wmv,.vob \n";
			} 	
		 } 	
		 
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_activity.submit(); }
		}
	}
	
// verifie les commentaire sur une activité
function submit_activity_comment(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	// si tout est vide
	if(document.form_comment.comment.value == '' || document.form_comment.comment.value == 'Scrivi un commento...')
		{
		msg_erreur += "- Inserisci un messaggio \n";	
		}
	
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_comment.submit(); }
		}
	}
	
function check_friend(id_friend)
	{
	if(document.getElementById('id_friend_'+id_friend).checked == false)
		{ document.getElementById('id_friend_'+id_friend).checked = true; }
	else
		{ document.getElementById('id_friend_'+id_friend).checked = false; }
	}
	
// invitations amis	
function submit_group_friend_add(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_group_friend_add.submit(); }
		}
	}
	
// invitations par email
function submit_group_invite_email(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	if (document.form_group_invite_mail.message.value == '')
		 { msg_erreur+="- Inserisci un messaggio \n"; } 	
		 
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_group_invite_mail.submit(); }
		}
	}

// newsletter groupe
function submit_group_mail(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";

	if (document.form_group_mail.subject.value == '')
		 { msg_erreur+="- Inserisci un argomento \n"; } 
		 
	if (document.form_group_mail.message.value == '')
		 { msg_erreur+="- Inserisci un messaggio \n"; } 	
		 
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_group_mail.submit(); }
		}
	}

// ajouter une photo dans un groupe
function submit_group_photo_add(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	if(document.form_group_photo_add.photo.value != "")
		{
		extension_photo = recup_extension(document.form_group_photo_add.photo.value);
		if(extension_photo != ".jpg")
			{ msg_erreur += "- Formato immagine non valido,solo jpg \n";}
		}
	else
		{ msg_erreur += "- Per favore scegli un'immagine \n"; }
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_group_photo_add.submit(); }
		}
	}

// ajouter une video dans un groupe
function submit_group_video_add(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	if(document.form_group_video_add.video.value != "")
		{
		var extension = recup_extension(document.form_group_video_add.video.value);
	
		if(extension != ".flv" && extension != ".mpg" && extension != ".3gp" && extension != ".avi" && extension != "mpeg"  && extension != ".wmv" && extension != ".vob")
			{ 
			msg_erreur+="- Solo i formati seguenti sono accettati: flv,.mpg,.mpeg,.3gp,.avi,.wmv,.vob \n";
			} 	
		}
		
	if(document.form_group_video_add.embed.value == "" && document.form_group_video_add.video.value == "")
			{ msg_erreur += "- Per favore scegli un video \n"; }
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_group_video_add.submit(); }
		}
	}
/////////////////////////////////////////////////////////////////////////////

// mettre à jour son statut
function submit_profil_status(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
		
	if(document.form_profil_status.status.value == "")
			{ msg_erreur += "- Scrivi qualche cosa \n"; }
	if(document.form_profil_status.status.value.length > 113)
			{ msg_erreur += "- Il tuo stato è troppo lungo \n"; }
	if(document.form_profil_status.file.value != "")
			{ 
			var extension = recup_extension(document.form_profil_status.file.value);
			
			if(extension != '.jpg')
				{ msg_erreur += "- Formato immagine non valido,solo jpg \n"; }
			}
			
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_profil_status.submit(); }
		}	
	}
	
// verifie les messages sur le wall
function submit_wall_msg(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	// si tout est vide
	if(document.form_comment.comment.value == '' || document.form_comment.comment.value == 'Scrivi un commento...')
		{
		msg_erreur += "- Inserisci un messaggio \n";	
		}
	
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_comment.submit(); }
		}
	}

// verifie les messages sur le wall
function submit_status_comment(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
	
	// si tout est vide
	if(document.form_comment_status.comment.value == '' || document.form_comment_status.comment.value == 'Scrivi un commento...')
		{
		msg_erreur += "- Inserisci un messaggio \n";	
		}
	
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_comment_status.submit(); }
		}
	}
	
	
////////////////////////////////////////////////////////	
// FB CONNECT	
// Commentaire avec FB connect
function check_form_comment_fb(comment_type)
	{
	// pas de commentaire
	if(document.getElementById('comment').value == '')
		{ alert( "Scrivi un commento prima di pubblicare." ); }
	// le commentaire est écrit
	else
		{
		// verifie si la case a cocher existe
		if(document.getElementById('publish_fb'))
			{
			// verifie si la case a cocher est cochée	
			if(document.getElementById('publish_fb').checked == true)
				{ publish_comment_2_fb(comment_type); }
			// pas coché on peu commenté
			else
				{ document.form_comment.submit(); }			
			}
		// la case a cocher n'existe pas, on commente
		else
			{ document.form_comment.submit(); }
		}
	}
	
function publish_comment_2_fb(comment_type)
	{
	// recup des infos
	comment = document.getElementById('comment').value;
	id_object = document.getElementById('id_object').value;

	var xhr_object = null; 
	 
	if(window.XMLHttpRequest) // Firefox 
	  xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject) // Internet Explorer 
	  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else { // XMLHttpRequest non supporté par le navigateur 
	  alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest..."); 
	  return; 
	} 
	
	xhr_object.open("POST", "../publish_comment_2_fb.php", true); 
	 
	xhr_object.onreadystatechange = function() { 
	  if(xhr_object.readyState == 4) 
		 { 

		 // si l'utilisateur n'as pas autorisé l'app Cook n'Share on affiche la div pour le faire
		 if(xhr_object.responseText == 'need_grand')
		 	{ 
			document.getElementById('fb_grand').innerHTML = "<p class='fb_grand_close'><a href='javascript:void(0);' class='lien_vert' onclick='javascript:hide_fb_grand();' title='Chiudi'>X Chiudi</a></p>Per autorizzare Cook n\'Share a pubblicare il tuo profilo <fb:prompt-permission perms='read_stream,publish_stream'>clicca qui</fb:prompt-permission>.<br /><br />Dovrai ancora validare il tuo commento.";
			document.getElementById('fb_grand').style.display = "block"; 
			
			FB.XFBML.Host.parseDomTree(); }
		// le commentaire est posté sur fb, on commente
		else
			{ document.form_comment.submit(); }
		 }
	} 
	
	xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
	var data = "comment="+comment+"&id_object="+id_object+"&comment_type="+comment_type; 
	xhr_object.send(data); 
	}
	
function hide_fb_grand()
	{
	document.getElementById("fb_grand").style.display='none';	
	}
////////////////////////////////////////////////////////////	

// INVITATIONS MULTIPLES ///////////////////////////////////////////////////////////////////
var tab_guest = new Array();

// pour ajouter un invité
function invite_add(value)
	{
	if(!value.match( "\\S+@\\S+\\.\\S+" ))
		{ alert('Inserisci un indirizzo email valido'); }
	else
		{
		if(in_array(tab_guest, value))
			{ alert('Hai già inserito questa email'); }
		else
			{
			var xhr_object = null; 
			 
			if(window.XMLHttpRequest) // Firefox 
			  xhr_object = new XMLHttpRequest(); 
			else if(window.ActiveXObject) // Internet Explorer 
			  xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
			else { // XMLHttpRequest non supporté par le navigateur 
			  alert("Il tuo browser non supporta XMLHTTPRichiesta..."); 
			  return; 
			} 
			
			xhr_object.open("POST", "verif_dispo.php", true); 
			 
			xhr_object.onreadystatechange = function() { 
			  if(xhr_object.readyState == 4) 
				 { 
				 // email deja utilisé
				 if(xhr_object.responseText == 1)
					{ alert('Questa mail appartiene già ad un utente registrato'); }
				// email non utilisé
				else
					{
					tab_guest.push(value);	
					document.getElementById('invite_name').value = '';
					invite_display();
					invite_recup();
					}
				 }
			} 
			
			xhr_object.setRequestHeader("Content-type", "application/x-www-form-urlencoded"); 
			var data = "champ=email&value="+value; 
			xhr_object.send(data); 
			}
		}
	document.getElementById('invite_name').focus();
	}

function invite_delete(id)
	{
	delete tab_guest[id];	
	invite_display();
	invite_recup();
	}
// pour afficher un invité
function invite_display()
	{
	guest_list_content = "";
	for(i=0;i<tab_guest.length;++i)
		{
		if(tab_guest[i])
			{ 
			guest_list_content += "<span class='invite_multiple'><span class='invite_multiple_email'>"+tab_guest[i]+"</span> <a href='javascript:void(0);' onclick='javascript:invite_delete("+i+");' class='lien_vert'>X</a></span>";
			}
		}
	guest_list_content += "<div class='my_clear'></div>";
	document.getElementById('guest_list').innerHTML = guest_list_content;
	}

// pour mettre le tableau d'invités dans un champ hidden
function invite_recup()
	{
	str_guest = tab_guest.join(',');
	document.getElementById('hidden_guest_list').value = str_guest;
	}

// recherche dans un tableau
function in_array(array, p_val) {
    for(var i = 0, l = array.length; i < l; i++) {
        if(array[i] == p_val) {
            rowid = i;
            return true;
        }
    }
    return false;
}
///////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////

// PHOTOS RESTAURANT
// mettre à jour son statut
function submit_restaurant_photo(is_mybtn)
	{
	msg_erreur="Sono successi i seguenti errori \n";
		

	var extension = recup_extension(document.form_img.fichier.value);
	
	if(extension != '.jpg')
		{ msg_erreur += "- Formato immagine non valido,solo jpg \n"; }

	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); }
	else
		{
		if(is_mybtn == 1)
			{ document.form_img.submit(); }
		}	
	}	
//////////////////////////////////////


//AJOUT DE RECETTE V2
//FORMULAIRE CREER RECETTE

//function submit_recipe_v2(str_ids_cooking_style)
function submit_recipe_v2()
	{
	// explode la chaine et en fait un tableau
	//var tab_ids_cooking_style = str_ids_cooking_style.split(';');
	// supprime la derniere valeure du tableau (qui est vide)
	//tab_ids_cooking_style.pop();
	//var nb_cs_checked = 0;
	
	msg_erreur="Sono successi i seguenti errori \n";

	if(document.TheForm.name.value == '')
		{ msg_erreur += "- Il nome e' obbligatorio \n";}
		
	//for(i=0;i<tab_ids_cooking_style.length;i++)
	//	{
	//	if(document.getElementById("cs_"+tab_ids_cooking_style[i]).checked)
	//		{ nb_cs_checked++; }
	//	}
	//if(nb_cs_checked == 0)
		//{ msg_erreur += "- Veuillez choisir au moins un style de cuisine \n";}
	
	if(document.TheForm.id_cooking_style.value == '')
		{ msg_erreur += "- Lo stile in cucina e' obbligatorio \n";}
	
	if(document.TheForm.id_recipe_type.value == '')
		{ msg_erreur += "- Il tipo di ricetta e' obbligatorio \n";}
	
	if(document.TheForm.level.value == '')
		{ msg_erreur += "- Il livello e' obbligatorio \n";}
	
	if(document.TheForm.nb_people.value == '')
		{ msg_erreur += "- l numero di persone e' obbligatorio \n";}
	if(isNaN(document.TheForm.nb_people.value))
		{ msg_erreur += "- Il numero di persone deve essere un numero \n";}
		
	if(document.TheForm.preparation_delay.value == '')
		{ msg_erreur += "- I tempi di preparazione sono obbligatori \n";}
	if(isNaN(document.TheForm.preparation_delay.value))
		{ msg_erreur += "- I tempi di preparazione deve essere un numero \n";}
		
	if(document.TheForm.temps_total.value == '')
		{ msg_erreur += "- Il tempo di cottura e' obbligatorio \n";}
	if(isNaN(document.TheForm.temps_total.value))
		{ msg_erreur += "- Il tempo di cottura deve essere un numero \n";}
	
	if(document.TheForm.photo_recette.value != "")
		{
		extension_photo = recup_extension(document.TheForm.photo_recette.value);
		if(extension_photo != ".jpg")
			{ msg_erreur += "- Formato del documento non valido, .jpg \n";}
		}
		
	if(msg_erreur!="Sono successi i seguenti errori \n")
		{ alert(msg_erreur); return false; }
	else
		{
		display_div('please_wait',0);
		window.onbeforeunload = function(e){ return "Stai ancora scaricando! Sei sicuro di voler uscire da questa pagina?"; } 
		document.TheForm.submit();	
		}
	
	}

function finish_add_recipe(location)
	{
	window.onbeforeunload = "";
	window.location = location;
	}
	
function error_add_recipe(message)
	{
	window.onbeforeunload = "";
	show_message('div_message',message);
	}
////////////////////////////

//Concours un délice de printemps
var ingredients_printemps = new Array();
var ingredients_printemps_required = new Array('kiwi','fragola','fragole','mango','manghi','ciliegia','ciliege'
			,'banana','banane','ravanello','ravanelli','asparago','asparagi','carota','carote','barbabietola'
			,'spinacio','spinaci');

function submit_recipe_printemps(concours)
{
msg_erreur="Sono successi i seguenti errori \n";

if(document.TheForm.name.value == '')
	{ msg_erreur += "- Il nome e' obbligatorio \n";}

if(document.TheForm.id_cooking_style.value == '')
{ msg_erreur += "- Lo stile in cucina e' obbligatorio \n";}

if(document.TheForm.id_recipe_type.value == '')
	{ msg_erreur += "- Il tipo di ricetta e' obbligatorio \n";}

if(document.TheForm.level.value == '')
	{ msg_erreur += "- Il livello e' obbligatorio \n";}

if(document.TheForm.nb_people.value == '')
	{ msg_erreur += "- l numero di persone e' obbligatorio \n";}
if(isNaN(document.TheForm.nb_people.value))
	{ msg_erreur += "- Il numero di persone deve essere un numero \n";}
	
if(document.TheForm.preparation_delay.value == '')
	{ msg_erreur += "- I tempi di preparazione sono obbligatori \n";}
if(isNaN(document.TheForm.preparation_delay.value))
	{ msg_erreur += "- I tempi di preparazione deve essere un numero \n";}
	
if(document.TheForm.temps_total.value == '')
	{ msg_erreur += "- Il tempo di cottura e' obbligatorio \n";}
if(isNaN(document.TheForm.temps_total.value))
	{ msg_erreur += "- Il tempo di cottura deve essere un numero \n";}

if(document.TheForm.photo_recette.value != "")
	{
	extension_photo = recup_extension(document.TheForm.photo_recette.value);
	if(extension_photo != ".jpg" && extension_photo != ".gif" && extension_photo != ".png")
		{ msg_erreur += "- Formato del documento non valido, .jpg \n";}
	}
	
// Concours délice printemps
if((document.getElementById("concours_1") && document.getElementById("concours_1").checked) || concours==1){
	
	if(check_concours_printemps_2010()==0){
		msg_erreur+="- Vogliate utilizzare gli ingredienti indicati nel seguente elenco per partecipare al concorso: kiwi, fragola, mango, ciliegia, banana, ravanello, asparago, carota, barbabietola, spinacio.";
		msg_erreur += " \n";
	}
}
///////////////////////////////////////


if(msg_erreur!="Sono successi i seguenti errori \n")
	{ alert(msg_erreur); return false; }
else
	{
	display_div('please_wait',0);
	//window.onbeforeunload = function(e){ return "Stai ancora scaricando! Sei sicuro di voler uscire da questa pagina?"; }
    $(window).bind('beforeunload', function(){ 
		return "Stai ancora scaricando! Sei sicuro di voler uscire da questa pagina?";
        } 
    );
	document.TheForm.submit();	
	}
}

//verifie les ingredients
function check_concours_printemps_2010(){

	var nb_good_ingredients = 0;
	var tab_ing = document.TheForm.ingredients.value.split("\n");
	var tab_ing_final = Array();
	var tab_temp = Array();
	
	for(i=0;i<tab_ing.length;++i){
		tab_temp = tab_ing[i].split(" ");
		for(j=0;j<tab_temp.length;++j){
			tab_ing_final.push(tab_temp[j]);
		}
	}
	
	for(i=0;i<tab_ing_final.length;++i){
	if(tab_ing_final[i]!='' && tab_ing_final[i]!=null){
		if(in_array(ingredients_printemps_required, noaccent(tab_ing_final[i]).toLowerCase()))
			{ nb_good_ingredients++; }
		}
	}
	
	return nb_good_ingredients;
}

//INSCRIPTION NEWSLETTER
function submit_form_newsletter(is_mybtn){
	msg_erreur="Sono successi i seguenti errori \n";

	if(!VerificationEmail(document.form_newsletter.email.value)){
		msg_erreur += "- Il tuo indirizzo mail deve avere il seguente formato xxx@yyy.zzz\nExemple : jsmith@votre-hebergeur.com \n";
	}
	
	var nb_check = 0;
	for(i=2;i<7;i++){
		var my_checkbox = eval('document.form_newsletter.newsletter_'+i);
		if(my_checkbox){
			if(my_checkbox.checked) { nb_check++;}
		}
	}
	if(nb_check == 0){
		msg_erreur += "- Inserisci almeno un newsletter \n";
	}
	
	
	if(msg_erreur!="Sono successi i seguenti errori \n"){ 
		alert(msg_erreur); 
		return false;
	}	
}