// JavaScript Document
function init(){
	document.getElementById("ongt_ctt1").style.display = "block";
}
function initques() {
	document.getElementById("dd1").style.display = 'block';
	document.getElementById("link_dd1").style.backgroundImage = "url('../images/moins.gif')";
	document.getElementById("link_dd1").style.backgroundPosition = "0 4px";
	document.getElementById("dt1").style.marginBottom = '0px';
	 $('.addval dt a').click(function() {    
      return false;
      }
      );
      	$('#dt1 a').css("color","#0098d8");
  }
//$(document).ready(function() {initques();});


function openNewWindow(){
	if (window.document.getElementById("anoterblock").style.display == 'block'){
		window.document.getElementById("anoterblock").style.display = 'none';
	}else{
		window.document.getElementById("anoterblock").style.display = 'block';
	}
}

function ogt_active() {
	for (i=1; i<5; i++) {
		//alert(document.getElementById("ongt_ctt"+i).style.display);
		if (document.getElementById("ongt_ctt"+i).style.display == "block") {			
			//alert("toto"+i);
			break;
		}			
	}	
	return i;
}

function openNewWindow1(){
	
	i=ogt_active();
	
	if (window.document.getElementById("anoterblock"+i).style.display == 'block'){
		window.document.getElementById("anoterblock"+i).style.display = 'none';
	}else{
		window.document.getElementById("anoterblock"+i).style.display = 'block';
	}
}

function show_ctt(i,k){
	for (j=1; j<=k; j++) {
		if (j!=i) {
			document.getElementById("ongt_ctt"+j).style.display = "none";
		} else {
			document.getElementById("ongt_ctt"+j).style.display = "block";
		}
	}
}


function showhide(iid){
	if (window.document.getElementById(iid).style.display == 'block'){
		window.document.getElementById(iid).style.display = 'none';
	}else{
		window.document.getElementById(iid).style.display = 'block';
	}
}

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);
	document.getElementById(dt).style.marginBottom = '30px';
	$(dta).css("color","#7d7d7d");
	document.getElementById(dd).style.display = 'none';
	document.getElementById(image).style.backgroundImage = "url('../images/plus1.gif')";
	document.getElementById(image).style.backgroundPosition = "0 4px";
  } else {
	  //alert(image);
	document.getElementById(dt).style.marginBottom = '0px';
	$(dta).css("color","#0098d8");
	document.getElementById(dd).style.display = 'block';
	document.getElementById(image).style.backgroundImage = "url('../images/moins.gif')";
	document.getElementById(image).style.backgroundPosition = "0 4px";
  }
}
function openpopup(){
	window.open('', 'popup', 'width=910,height=700,scrollbars=0,left=' + ((screen.width - 910)/2) + ',top=' + ((screen.height - 700)/2) );	
	}
	
function openpopup1(){
	window.open('', 'popup', 'width=910,height=600,scrollbars=0,left=' + ((screen.width - 910)/2) + ',top=' + ((screen.height - 600)/2) );	
	}

function openpopup2(iid){
	window.open('../ecoutez-temoignage.php?id='+iid, 'popup', 'width=240,height=100,scrollbars=0,left=' + ((screen.width - 310)/2) + ',top=' + ((screen.height - 100)/2) );	
	}





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 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 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';
			return true;
		}
	  }
	} 
		
		document.getElementById(arg1).style.backgroundColor = '#ffe6e6';
		document.getElementById(arg2).style.backgroundColor = '#ffe6e6';
		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');
email = checkemail('email');
organisme = checkTxtEmpty('organisme');

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


function checkall1(){
nom = checkTxtEmpty('nom');
prenom = checkTxtEmpty('prenom');
email = checkemail('email');
tel = checkTel('tel');
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(){
	codep = checknum('codep',5);
	nom = checkTxtEmpty('nom');
	prenom = checkTxtEmpty('prenom');
	fonction = checkTxtEmpty('fonction');
	tel = checkTxtEmpty('tel');
	email = checkemail('email');
	reponse = checkEgality('cpassw','passw');
	etablissement = checkTxtEmpty('etablissement');
	
	if (!codep) {
		alert("Veuillez saisir le code postal correctement !");
		return false ;
	}else if (!(nom && prenom && email && tel && fonction && reponse && etablissement))
	{
		document.getElementById('must').style.color='#FF0000';
		return false ;
	}
	else	
		return true;
}
function checkall4(){
email = checkemail('email');

if (!(email))
{
	return false ;
}
else	
	return true;
}
function checkall6(){
	
	
	codep = checknum('codep',5);
	nom = checkTxtEmpty('nom');
	prenom = checkTxtEmpty('prenom');
	fonction = checkTxtEmpty('fonction');
	tel = checkTxtEmpty('tel');
	etablissement = checkTxtEmpty('etablissement');
	
	if (!codep) {
		alert("Veuillez saisir le code postal correctement !");
		return false ;
	}else if (!(nom && prenom && tel && fonction && etablissement))
	{
		document.getElementById('must').style.color='#FF0000';
		return false ;
	}
	else	
		return true;
}

function checkall7(){
	oldpassw = checkTxtEmpty('oldpassw');
	reponse = checkEgality('cpassw','passw');
	if (!(oldpassw && reponse))
	{
		return false ;
	}
	else	
		return true;
}

function checkall3(){
	nom = checkTxtEmpty('nom');
	email = checkemail('email');
	email_ami = checkemail('email_ami');
	
	if (!(nom && email && email_ami))
	{
		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;
}
