// JavaScript Document
function initques() {
	if(document.getElementById("dd1") ) {

		//document.getElementById("dd1").style.display = 'block';
		$("#dd1").show("slow");
		document.getElementById("link_dd1").style.backgroundImage = "url('images/moins.gif')";
		document.getElementById("link_dd1").style.backgroundPosition = "0 0";
		document.getElementById("dt1").style.marginBottom = '0px';
		$('dt a').click(function() {
			return false;
		}
		);
		$('#dt1 a').css("color","#FFF");
	}
}

function initques1() {
	if(document.getElementById("dd1") ) {

		//document.getElementById("dd1").style.display = 'block';
		$("#dd1").show("slow");
		document.getElementById("link_dd1").style.backgroundImage = "url('images/moins1.gif')";
		document.getElementById("link_dd1").style.backgroundPosition = "0 3px";
		document.getElementById("dt1").style.marginBottom = '0px';
		$('dt a').click(function() {
			return false;
		}
		);
		$('#dt1 a').css("color","#e86025");
	}
}


function PlaceMenu(){
	var ul_width=$("#ul_menu").width();
	var doc_width=$(document).width();
	var new_width=0;

	$('#ul_menu li').each(function(index) {
		if($(this).width()) new_width += $(this).width();
	});


	//alert(new_width);
	if(ul_width >= new_width) $("#ul_menu").css({ left: ((doc_width-ul_width)/2)+'px' });
	$("#ul_menu").css({ width: new_width+'px' });
	$("#myslidemenu").css({ width: ((new_width))+'px' });
	$("#ul_menu").css({ visibility:'visible' });
}


function popupcentree(page,largeur,hauteur,options) {
	var top=(screen.height-hauteur)/2;
	var left=(screen.width-largeur)/2;
	window.open(page,"","top="+top+",left="+left+",width="+largeur+",height="+hauteur+","+options);
}

function checkForm(){
	nom = checkTxtEmpty('nom_ctct');
	prenom = checkTxtEmpty('prenom_ctct');
	email = checkemail('email_ctct');
	organisme = checkTxtEmpty('org_ctct');
	//tel = checkTxtEmpty('tel_ctct'); 

   //  ajout de .title == "num_fr" que ds la france 
    if(document.getElementById('tel_ctct').attributes.getNamedItem("xml:lang").value == "fr")
    {tel = checkTxtEmpty('tel_ctct');}
	

	//dans le cas de l'irland la ville n'exite pas
	if(document.getElementById('ville_ctct')){
		ville = checkTxtEmpty('ville_ctct');

		if (!(nom && prenom && email && organisme && ville && tel ))
		{
			document.getElementById('must').style.color='#FF0000';
			window.location="#info_general";
			return false ;
		}else return true;

	}else{

		if (!(nom && prenom && email && organisme))
		{
			document.getElementById('must').style.color='#FF0000';
			window.location="#info_general";
			return false ;
		}else return true;

	}
}


function checkFormEventSubscribe(){

	nom = checkTxtEmpty('nom_event_inscription');
	prenom = checkTxtEmpty('prenom_event_inscription');
	fonction = checkTxtEmpty('fonction_event_inscription');
	secteur = checkTxtEmpty('secteur_inscription');
	effectif_ctct = checkSelectLike('effectif_inscription',"Sélectionner");
	tel_ctct = checkTxtEmpty('telephone_event_inscription');
	valid_phone= checkTxtEmpty('telephone_event_inscription');
	adresse = checkTxtEmpty('adresse_event_inscription');
	//dans le cas de l'irland le cp n'exite pas
	if(document.getElementById('cp_event_inscription')) CP = checkTxtEmpty('cp_event_inscription');
	email = checkemail('email_event_inscription');
	organisme = checkTxtEmpty('societe_event_inscription');
	is_client=IsChecked('is_client_event_inscription');


	if(document.getElementById('cp_event_inscription')){
		if (!(nom && prenom && email && organisme && fonction &&  secteur && effectif_ctct && adresse && CP && is_client && valid_phone  ))
		{
			document.getElementById('must').style.color='#FF0000';
			window.location="#inscription";
			return false ;
		}else{
			return true;
		}
	}else{
		if (!(nom && prenom && email && organisme && fonction &&  secteur && effectif_ctct && adresse && is_client && valid_phone  ))
		{
			document.getElementById('must').style.color='#FF0000';
			window.location="#inscription";
			return false ;
		}else{
			return true;
		}
	}

	/*if(document.getElementById('textarea_event_inscription')){
	textarea_event_inscription=checkTxtEmpty('textarea_event_inscription');

	if (!(nom && prenom && email && organisme && fonction &&  secteur && effectif_ctct && adresse && CP && is_client && valid_phone && textarea_event_inscription ))
	{
	document.getElementById('must').style.color='#FF0000';
	window.location="#inscription";
	return false ;
	}
	else
	return true;

	}else{

	if (!(nom && prenom && email && organisme && fonction &&  secteur && effectif_ctct && adresse && CP && is_client && valid_phone  ))
	{
	document.getElementById('must').style.color='#FF0000';
	window.location="#inscription";
	return false ;
	}
	else
	return true;

	}*/
}


function checkSelectLike(idElement,value){
	if (document.getElementById(idElement).value != value)
	{
		document.getElementById(idElement).style.backgroundColor = '#FFFFFF';
		return true
	}else{
		document.getElementById(idElement).style.backgroundColor = '#ffe6e6';
		return false
	}
}


function IsChecked2(idElement){
	if ($('.'+idElement+':checked').val() !== undefined){
		$('.'+idElement).each(function(e) {$('#'+idElement+e).css('color', '#615144');});return true;
	}else{
		$('.'+idElement).each(function(e) {$('#'+idElement+e).css('color', 'red');});return false;
	}
}



function IsChecked(idElement){
	if (document.getElementsByName(idElement)[0].checked || document.getElementsByName(idElement)[1].checked)
	{
		document.getElementById("is_client_event_inscription_label_non").style.color = '#615144';
		document.getElementById("is_client_event_inscription_label_oui").style.color = '#615144';
		return true
	}else{

		document.getElementById("is_client_event_inscription_label_non").style.color = 'red';
		document.getElementById("is_client_event_inscription_label_oui").style.color = 'red';
		return false
	}
}


function checkFormCandidature(){
	nom = checkTxtEmpty('nom_candidature');
	email = checkemail('email_candidature');
	tel_candidature = checkTxtEmpty('tel_candidature');
	tel_candidature = checkTxtEmpty('tel_candidature');
	cv_candidature = checkTxtEmpty('cv_candidature');
	valid_phone= checkTxtEmpty('tel_candidature');

	if (!(nom && email && tel_candidature && cv_candidature && valid_phone))
	{

		document.getElementById('must').style.color='#FF0000';
		window.location="#info_general";
		return false ;
	}
	else
	return true;
}


function showhidedd2(iid){
	var image = "link_dd"+iid;
	var dd = "dd"+iid;
	var dt = "dt"+iid;
	var dta = '#'+dt+' a';
	if (document.getElementById(dd).style.display == 'block'){
		//alert(image);
		$(dta).css("color","#FFF");
		//document.getElementById(dd).style.display = 'none';
		//$("#"+dd).fadeOut("slow");
		$("#"+dd).hide("slow");
		//document.getElementById(dt).style.marginBottom = '30px';
		document.getElementById(image).style.backgroundImage = "url('images/plus.gif')";
		document.getElementById(image).style.backgroundPosition = "0 0";
	} else {
		//alert(image);
		document.getElementById(dt).style.marginBottom = '0px';
		$(dta).css("color","#FFF");
		//document.getElementById(dd).style.display = 'block';
		$("#"+dd).show("slow");
		document.getElementById(image).style.backgroundImage = "url('images/moins.gif')";
		document.getElementById(image).style.backgroundPosition = "0 0";
	}
}


function showhidedd3(iid){
	var image = "link_dd"+iid;
	var dd = "dd"+iid;
	var dt = "dt"+iid;
	var dta = '#'+dt+' a';
	if (document.getElementById(dd).style.display == 'block'){
		//alert(image);
		$(dta).css("color","#59483a");
		//document.getElementById(dd).style.display = 'none';
		//$("#"+dd).fadeOut("slow");
		$("#"+dd).hide();
		//document.getElementById(dt).style.marginBottom = '30px';
		document.getElementById(image).style.backgroundImage = "url('images/plus1.gif')";
		document.getElementById(image).style.backgroundPosition = "0 3px";
	} else {
		//alert(image);
		document.getElementById(dt).style.marginBottom = '0px';
		$(dta).css("color","#e86025");
		//document.getElementById(dd).style.display = 'block';
		$("#"+dd).show();
		document.getElementById(image).style.backgroundImage = "url('images/moins1.gif')";
		document.getElementById(image).style.backgroundPosition = "0 3px";
	}
}


/*$(document).ready(function() {
// Handler for .ready() called.
$("#events #dd1").hide("slow");
$("#events #dd1_ctt").show("slow");
if(document.getElementById("link_dd1") ) document.getElementById("link_dd1").style.backgroundImage = "url('images/moins.gif')";
});*/

function sh_h(iid) {
	iid1 = "#"+iid;
	iid2 = "#"+iid+"_ctt";
	lien = "link_"+iid;
	//alert(window.document.getElementById(iid).style.visibility+iid);
	if (window.document.getElementById(iid).style.display == '' || window.document.getElementById(iid).style.display == 'block'){
		$(iid2).show("slow");
		$(iid1).hide("slow");
		document.getElementById(lien).style.backgroundImage = "url('images/moins.gif')";
	}else{
		$(iid1).show("slow");
		$(iid2).hide("slow");
		document.getElementById(lien).style.backgroundImage = "url('images/plus.gif')";
	}
}


//Fonctions control formulaire


var loc=false;
function checkemail(iid){
	var invalidcheck=0;
	var str=document.getElementById(iid).value;
	var filter=/^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/i;



	//var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i

	if (filter.test(str)){
		var tempstring=str.split("@")
		tempstring=tempstring[1].split(".")
		if (invalidcheck!=1)
		{
			document.getElementById(iid).style.backgroundColor ='#FFFFFF';
			testresults=true
		}
		else{
			testresults=false
		}
	}else{
		document.getElementById(iid).style.backgroundColor ='#ffe6e6';
		testresults=false
	}
	return (testresults)
}

function checkTxtEmpty(idElement){
	if (document.getElementById(idElement).value != "")
	{
		document.getElementById(idElement).style.backgroundColor = '#FFFFFF';
		return true
	}else{
		document.getElementById(idElement).style.backgroundColor = '#ffe6e6';
		return false
	}
}



function checkPhone(idElement){
	if (document.getElementById(idElement).value.match(/^[0-9]{10,20}$/g)){
		document.getElementById(idElement).style.backgroundColor = '#FFFFFF';
		return true;
	}else{
		document.getElementById(idElement).style.backgroundColor = '#ffe6e6';
		return false;
	}
}

function checkEgality(arg1, arg2){

	arg3 = document.getElementById(arg1).value;
	arg3 = arg3.toLowerCase();
	arg4 = document.getElementById(arg2).value;
	arg4 = arg4.toLowerCase();

	//alert(arg3+"--"+arg4);

	if ((arg3 == arg4) && arg3 != "" && arg4 != "") {

		if (arg3.length>5 && arg4.length>5) {
			//alert(arg3.length+"toot");
			arg = arg3.split("");
			//arg = arg.toLowerCase();
			//alert(arg);
			a_char =new Array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","0","1","2","3","4","5","5","6","7","8","9","_");

			continuer = true;

			for (j = 0; j<arg.length; j++) {
				exist = false;
				//alert(arg+"--"+arg[j]);
				for (i=0; i<a_char.length;i++) {
					//alert(arg[j]+"--"+a_char[i]);
					if (arg[j] == a_char[i]) {
						exist = true;
						break;
					}
				}
				//alert(exist);
				if (exist == false) {
					continuer = false;
					break;
				}
			}
			if (continuer == true) {
				document.getElementById(arg1).style.backgroundColor = '#FFFFFF';
				document.getElementById(arg2).style.backgroundColor = '#FFFFFF';
				document.getElementById('pwalert').style.color='#000000';
				loc=false;
				return true;
			}
		}
	}

	document.getElementById(arg1).style.backgroundColor = '#ffe6e6';
	document.getElementById(arg2).style.backgroundColor = '#ffe6e6';
	if(!loc){ window.location.href = "#code_access" ;loc=true;}
	document.getElementById('pwalert').style.color='#FF0000';
	return false;
}
function checkTel(idElement){
	nbr = document.getElementById(idElement).value
	if (nbr.length == 10 && !isNaN(nbr))
	{
		document.getElementById(idElement).style.backgroundColor = '#FFFFFF';
		return true
	}
	else
	{
		document.getElementById(idElement).style.backgroundColor = '#ffe6e6';
		return false
	}
}


function checknum(idElement,numchar){
	nbr = document.getElementById(idElement).value
	// Puisque le champ code postal n'est pas obligatoire on le verifie au cas ou il est rempli
	if ((nbr.length == numchar && !isNaN(nbr)) || (nbr.length == 0))
	return true
	else
	return false
}

function checkBox(idElement){
	//alert(document.getElementById(idElement).checked);
	if (document.getElementById(idElement).checked == true) {
		document.getElementById(idElement+'1').style.color = '#5c5c5c';
		return true
	} else if (document.getElementById(idElement).checked == false) {
		document.getElementById(idElement+'1').style.color = '#FF0000';
		return false
	}
}


function checkall(){
	nom = checkTxtEmpty('nom_membre');
	email = checkemail('email_membre');
	organisme = checkTxtEmpty('organisme_membre');

	if (!(nom && email && organisme))
	{

		document.getElementById('must').style.color='#FF0000';
		return false ;
	}
	else
	return true;
}


function checkall1(){
	nom = checkTxtEmpty('nom_membre');
	prenom = checkTxtEmpty('prenom_membre');
	email = checkemail('email_membre');
	tel = checkTel('tel_membre');
	cond_use = checkBox('cond_use');

	if (!(nom && prenom && email && tel && cond_use))
	{

		document.getElementById('must').style.color='#FF0000';
		return false ;
	}
	else
	return true;
}



function checkall2(){
	if(document.getElementById('codep_membre')) codep = checknum('codep_membre',5);
	else codep=true;
	nom = checkTxtEmpty('nom_membre');
	prenom = checkTxtEmpty('prenom_membre');
	fonction = checkTxtEmpty('fonction_membre');
	tel = checkTxtEmpty('tel_membre');
	valide_phone=checkTxtEmpty('tel_membre');
	email = checkemail('email_membre');
	reponse = checkEgality('cpassw_membre','passw_membre');
	etablissement = checkTxtEmpty('etablissement_membre');


	if(document.getElementById('ville_membre')){
		ville = checkTxtEmpty('ville_membre');
		if (!codep) {
			alert("Veuillez saisir le code postal correctement !");
			return false ;
		}else if (!(nom && prenom && email && tel && fonction && reponse && etablissement && valide_phone && ville))
		{
			document.getElementById('must').style.color='#FF0000';
			if(!loc){ window.location.href = "#info_general" ;loc=true;}
			return false ;
		}
		else{
			loc=false;
			return true;
		}

	}else{


		if (!codep) {
			alert("Veuillez saisir le code postal correctement !");
			return false ;
		}else if (!(nom && prenom && email && tel && fonction && reponse && etablissement && valide_phone))
		{
			document.getElementById('must').style.color='#FF0000';
			if(!loc){ window.location.href = "#info_general" ;loc=true;}
			return false ;
		}
		else{
			loc=false;
			return true;
		}


	}
}

function checkall6(){


	codep = checknum('codep_membre',5);
	nom = checkTxtEmpty('nom_membre');
	prenom = checkTxtEmpty('prenom_membre');
	fonction = checkTxtEmpty('fonction_membre');
	tel = checkTxtEmpty('tel_membre');
	etablissement = checkTxtEmpty('etablissement_membre');

	if (!codep) {
		alert("Veuillez saisir le code postal correctement !");
		if(!loc){ window.location.href = "#info_general" ;loc=true;}
		return false ;
	}else if (!(nom && prenom && tel && fonction && etablissement))
	{
		document.getElementById('must').style.color='#FF0000';
		if(!loc){ window.location.href = "#info_general" ;loc=true;}
		return false ;
	}
	else{
		loc=false;
		return true;
	}
}

function checkall7(){
	oldpassw = checkTxtEmpty('oldpassw_membre');
	reponse = checkEgality('cpassw_membre','passw_membre');
	if (!(oldpassw && reponse))
	{
		if(!loc){ window.location.href = "#code_access" ;loc=true;}
		return false ;
	}
	else{
		loc=false;
		return true;
	}
}

function checkall3(){
	nom = checkTxtEmpty('nom_membre');
	email = checkemail('email_membre');

	if (!(nom && email ))
	{
		document.getElementById('must').style.color='#FF0000';
		return false ;
	}
	else
	return true;
}


function checkall5() {
	passwa = checkTxtEmpty('passwa');
	emaila = checkemail('emaila');

	if (!(passwa && emaila))
	{
		return false ;
	}
	else
	return true;
}

function checkall8() {
	passwa = checkTxtEmpty('passwa_log');
	emaila = checkemail('emaila_log');

	if (!(passwa && emaila))
	{
		return false ;
	}
	else
	return true;
}



function checkall4(){
	email = checkemail('email_membre');

	if (!(email))
	{
		return false ;
	}
	else
	return true;
}

/*function checkemail(iid){
var invalidcheck=0;
var str=document.getElementById(iid).value
var filter=/^(\w+(?:\.\w+)*)@((?:\w+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
if (filter.test(str)){
var tempstring=str.split("@")
tempstring=tempstring[1].split(".")
if (invalidcheck!=1)
{
document.getElementById(iid).style.backgroundColor ='#FFFFFF';
testresults=true
}
else{
testresults=false
}
}else{
document.getElementById(iid).style.backgroundColor ='#ffe6e6';
testresults=false
}
return (testresults)
}*/



function openpopup(){
	window.open('', 'popup', 'width=500,height=220,scrollbars=0,left=' + ((screen.width - 500)/2) + ',top=' + ((screen.height - 300)/2) );
}
