function draw_smenu(num_menu){
	document.getElementById('m'+num_menu).className="opacityMax";
	var ssmenu=0;
	
	for(i=1;document.getElementById('m'+num_menu+'r'+i);i++){
		//alert('m'+num_menu+'r'+i);
		document.getElementById('m'+num_menu).style.color='#FFF';
		document.getElementById('m'+num_menu+'r'+i).style.display='';
		ssmenu=1;
	}
	
	for(j=1;document.getElementById('m'+j);j++){
		if(j!=num_menu){
			if(ssmenu==1){document.getElementById('m'+j).className="opacityMin";}
			
			for(i=1;document.getElementById('m'+j+'r'+i);i++){
				document.getElementById('m'+j+'r'+i).style.display='none';
				
			}
		}
	}
	
}

function clear_smenu(num_menu){
	for(i=1;document.getElementById('m'+num_menu+'r'+i);i++){
		document.getElementById('m'+num_menu+'r'+i).style.display='none';
	}
	
	for(j=1;document.getElementById('m'+j);j++){
		document.getElementById('m'+j).className="opacityMax";
	}
	
}

function changeLanguage(lng){
	urlActu = window.location.href;
	var isAncre=urlActu.lastIndexOf("#");
	var isVar=urlActu.lastIndexOf("?");
	var isIndex=urlActu.lastIndexOf("index.php");
	
	
	url = urlActu+'index.php?lng='+lng;
	
	if(isIndex != -1){var url = urlActu+'?lang='+lng;}
	if(isVar != -1){var url = urlActu+'&lang='+lng;}
	if(isAncre != -1){var url = urlActu.substring(0,urlActu.lastIndexOf("#"))+'&lang='+lng;}
	
	window.location.href=url;
}


function valid_signIn(){

	var email=document.signIn.email.value;
	var haveEmail=document.getElementById('yesHavePswd');
	var password=document.signIn.password.value;

    if(document.getElementById('error_00')!=undefined){
       document.getElementById('error_00').style.display='none';
    }

    document.getElementById('error_01').style.display='none';
    document.getElementById('error_02').style.display='none';

	if(haveEmail.checked==true){

        if(email=="" || password==""){
        document.getElementById('error_02').style.display='block';
        return false;
        }
    	if(email.search(/^[^._-][a-z0-9._-]+[^._-]@[a-z0-9._-]+([a-z0-9]+[^._-])?[.-]+[a-z]{2,4}$/)==-1){
        document.getElementById('error_01').style.display='block';
        return false;
        }
	}

return true;
}

function valid_register(){

	var organization=document.register.inscr_host_organization.value;
	var category = getRadioValue(document.register.inscr_category);
	var firstname=document.register.inscr_firstname.value;
	var lastname=document.register.inscr_lastname.value;
	var country = document.register.inscr_country.value;

	if(document.getElementById('inscr_email')!=undefined){
	var email=document.register.inscr_email.value;
	var email2=document.register.inscr_email2.value;
	}

	var pswd=document.register.inscr_pswd.value;
	var pswd2=document.register.inscr_pswd2.value;
	var termUse=document.getElementById('termUse');

    if(document.getElementById('error_00')!=undefined){
       document.getElementById('error_00').style.display='none';
    }

    document.getElementById('error_01').style.display='none';
    document.getElementById('error_02').style.display='none';
    document.getElementById('error_03').style.display='none';
    document.getElementById('error_04').style.display='none';
    document.getElementById('error_05').style.display='none';

    if(organization=="" || category=="" || firstname=="" || lastname=="" || country==""  || pswd=="" || pswd2==""){
        document.getElementById('error_02').style.display='block';
        return false;
    }

	if(document.getElementById('inscr_email')!=undefined){

		if(email.search(/^[^._-][a-z0-9._-]+[^._-]@[a-z0-9._-]+([a-z0-9]+[^._-])?[.-]+[a-z]{2,4}$/)==-1){
		    document.getElementById('error_01').style.display='block';
		    return false;
		}
	}

   if(email != email2){
   		document.getElementById('error_04').style.display='block';
        return false;
   }

   if(pswd != pswd2){
   		document.getElementById('error_05').style.display='block';
        return false;
   }

   if(termUse.checked==false){
      document.getElementById('error_03').style.display='block';
      return false;
   }

return true;
}
//Renvoie la valeur slctionne d'un champ radio

function getRadioValue(field){

  for (i= 0; i < (field.length); ++i) {
   if(field[i].checked == true){
    return field[i].value;
   }
  }
  return "";
}

//Validation d'adresse email
function validEmail(field){
	if(field.search(/^[^._-][a-z0-9._-]+[^._-]@[a-z0-9._-]+([a-z0-9]+[^._-])?[.-]+[a-z]{2,4}$/)==-1){
		return false;
	}
return true;
}

//Verifi si l'adresse n'existe pas dans la bdd (appel AJAX)
function verifEmail(){
	email=document.register.inscr_email.value;
	if(email.search(/^[^._-][a-z0-9._-]+[^._-]@[a-z0-9._-]+([a-z0-9]+[^._-])?[.-]+[a-z]{2,4}$/)!=-1){
		var url='campaign/verifEmail.php?email='+email;
		ahah(url,"validEmail");
	}
	else{
	EMAIL_VALID=0;
	document.getElementById("validEmail").innerHTML="<span class='aff_error'>Adresse e-Mail invalide</span>";
	document.getElementById('champ_email').style.backgroundColor='#ffc4c4';
	}
}

//Ouverture POP-UP pour le recadrage des image
function popRecadre(img,key_event,nom,backoffice,hauteur,largeur) {
if(backoffice==1){var url="../campaign/recadre.php?img="+img+"&key_event="+key_event+"&nom="+nom+"&backoffice=1&hauteur="+hauteur+"&largeur="+largeur;}
else{var url="campaign/recadre.php?img="+img+"&key_event="+key_event+"&nom="+nom+"&hauteur="+hauteur+"&largeur="+largeur;}

var options="menubar=no,scrollbars=yes,statusbar=no";
var largeur="600";
var hauteur="500";
var haut=(screen.height-hauteur)/2;
var Gauche=(screen.width-largeur)/2;
window.open(url,"rec","top="+haut+",left="+Gauche+",width=600,height=500,menubar=no,scrollbars=yes,statusbar=no");
}

//Validation du formulaire step 1
function validStep1(){
var location=document.forms["step1"].location.value.length;
var country=document.forms["step1"].country.value;
var title=document.forms["step1"].title.value.length;
var description=document.forms["step1"].description.value.length;


	if(location && country && title && description){
		return true;
	}
	else{
	alert("Veuillez remplir tous les champs.");
	return false;
	}
}

// Vérifie si la case des conditions est cochée.
function sendEvent(EDIT_URL){
var termUse=document.getElementById('termUse');
   if(termUse.checked==false){
      document.getElementById('error_01').style.display='block';
      return false;
   }
   window.location.href='index.php?nav=campaign&rub=addEvent&opt=step4&submit=yes'+EDIT_URL;
}

//Validation du formulaire step 1
function validStep1(){

var title=document.step1.title.value;
var description=document.step1.description.value;
var eventType=getRadioValue(document.step1.eventType);
var eventEmail=validEmail(document.step1.eventEmail.value);
var websiteLink=document.step1.websiteLink.value;

var hostOrganization=document.step1.hostOrganization.value;
var organizationType=getRadioValue(document.step1.organizationType);
var contactName=document.step1.contactName.value;
var publicEmail=validEmail(document.step1.publicEmail.value);
var publicPhone=document.step1.publicPhone.value;
var organizerWebsite=document.step1.organizerWebsite.value;

var location=document.step1.location.value;
var country=document.step1.country.value;
var street=document.step1.street.value;
//var additional=document.step1.additional.value;
var postalCode=document.step1.postalCode.value;

	document.getElementById('error_01').style.display='none';
    document.getElementById('error_02').style.display='none';
    document.getElementById('error_03').style.display='none';

	if(title=="" || description=="" || eventType=="" ||  hostOrganization=="" || organizationType=="" || contactName==""   )
	{
	document.getElementById('error_01').style.display='block';
	return false;
	}


	if(publicEmail == false){
	document.getElementById('error_02').style.display='block';
	return false;
	}

return true;
}

//Demande une confirmation avant de supprimer un Event.
function confirmationDeleteEvent(key){
	if (confirm("Etes vous sûr de vouloir supprimer cet événement ?")){
	 	window.location.href='index.php?nav=campaign&rub=addEvent&opt=step4&delete=yes&key_delete='+key;
	}
}

//Ajoute un champ Email dans le Your Friends
function rgb2hex(c) {
   var hex = '';
   var array = /([0-9]+)[, ]+([0-9]+)[, ]+([0-9]+)/.exec(c);
   for(i = 1; i < 4; i++) hex += ('0' + parseInt(array[i]).toString(16)).slice(-2);
   return '#' + hex;
}

function getStyleInfo(obj, style) {
	obj = document.getElementById(obj);
	var ret =" ";     
	//Pour IE 
	if (obj.currentStyle) ret = obj.currentStyle[style];
	//Pour le DOM 
	if (document.defaultView && document.defaultView.getComputedStyle) {
		//Safari Mac ne peut pas acceder aux objets qui sont en display:none.
		//On considere donc que si c'est ce qui est demande et qu'il n'y a pas de réponse, c'est que c'est du "none"
		if (!document.defaultView.getComputedStyle(obj, "") && style=="display") ret = "none";
		//Sinon on prends le résultat 
		else ret = document.defaultView.getComputedStyle(obj, "")[style];     } 
		//Safari Mac retourne les couleurs en rgba et rgba(0,0,0,0) => transparent 
		if (style=="backgroundColor" && ret=="rgba(0, 0, 0, 0)") ret = "transparent";
		return ret;
		}

function addFriend(){
	var email2_display = getStyleInfo("yourFriendsEmail_2","display");
	if(email2_display=="none"){
	document.getElementById("yourFriendsEmail_2").style.display="block";
	}
	else{
	document.getElementById("yourFriendsEmail_3").style.display="block";
	document.getElementById("addFriends").style.display="none";
	}
}

function sendMails(){
	var yourEmail = validEmail(document.sendFriends.yourEmail.value);
	var yourName = document.sendFriends.yourName.value;
	
	var yourFriendsEmail_1 = validEmail(document.sendFriends.yourFriendsEmail_1.value);
	var yourFriendsEmail_2 = validEmail(document.sendFriends.yourFriendsEmail_2.value);
	var yourFriendsEmail_3 = validEmail(document.sendFriends.yourFriendsEmail_3.value);
	
	var FriendsEmail_1 = document.sendFriends.yourFriendsEmail_1.value;
	var FriendsEmail_2 = document.sendFriends.yourFriendsEmail_2.value;
	var FriendsEmail_3 = document.sendFriends.yourFriendsEmail_3.value;
	
	var myEmail = document.sendFriends.yourEmail.value;
	
	var myImage = document.sendFriends.image.value;
	
	document.getElementById("error_01").style.display="none";
	document.getElementById("error_02").style.display="none";
	document.getElementById("error_03").style.display="none";
	
	
	var message=document.sendFriends.message.value;
	message=message.replace(/\n/g,"<br/>");
	
	if(yourName && yourEmail==true && yourFriendsEmail_1==true){
		if(FriendsEmail_2!="" && yourFriendsEmail_2==false){
			document.getElementById("error_03").style.display="block";
			return 0;}
		if(FriendsEmail_3!="" && yourFriendsEmail_3==false){
			document.getElementById("error_03").style.display="block";
			return 0;}
			
			document.getElementById("error_01").style.display="none";
			document.getElementById("error_02").style.display="none";
			document.getElementById("error_03").style.display="none";
			var url="emails/sendFriends.php?yourName="+yourName+"&yourEmail="+myEmail+"&yourFriendsEmail_1="+FriendsEmail_1+"&yourFriendsEmail_2="+FriendsEmail_2+"&yourFriendsEmail_3="+FriendsEmail_3+"&image="+myImage+"&message="+message;
			ajaxMailer(url,"zone_envoi")
	}
	else{
		if (yourEmail == false){
		document.getElementById("error_02").style.display="block";
		return false;
		}
		if (yourFriendsEmail_1 == false){
		document.getElementById("error_03").style.display="block";
		return false;
		}
	document.getElementById("error_01").style.display="block";
	}
}