var CPT_RADAR = 0;
/*
confirmation url
*/
function ConfirmationUrl(msg, url)
{
	var input = confirm(msg)
	
	if (input)
		document.location = url;
}

   function getPosition(id)
   {
    obj = document.getElementById(id);
     var x=0,y=0;
     while (obj!=null)
     {
       x+=obj.offsetLeft-obj.scrollLeft;
       y+=obj.offsetTop-obj.scrollTop;
       obj=obj.offsetParent;
     }
     return {x:x,y:y};
   }

  //affiche le mot clé selectionné dans le champ de recherche
  function set_suggest(s){
   document.getElementById('keyword__').value = s;
   document.getElementById('suggest').style.display = 'none';
  }
  function SuggestSubmit(url)
  {
    document.getElementById('suggest').style.display = 'none';
    var key = document.getElementById('keyword__').value;
    ajaxDisplay(url+'skinPage=Empty&SuggestSearch='+key,'search');
  }
  function suggestSearch(url,id,id_div)
  {
   document.getElementById('suggest').style.left = getPosition(id).x+2;
   if (navigator.appName=='Microsoft Internet Explorer') document.getElementById('suggest').style.top = getPosition(id).y+25;
   document.getElementById('suggest').style.width = document.getElementById(id).clientWidth;
    var keyword = document.getElementById(id).value;
    ajaxDisplay(url+keyword,id_div);
  }
/*
 functions javascripts des pages du site
*/
function gestionAffichageAlterne (tabParam){ 
	for (i=0;i<tabParam.length;i++)
		if (document.getElementById(tabParam[i]).style.display == 'none') 
			document.getElementById(tabParam[i]).style.display = 'block';
		else
		{
			if (document.getElementById(tabParam[i]).style.display =="")
				document.getElementById(tabParam[i]).style.display = 'block';
			else
				document.getElementById(tabParam[i]).style.display = 'none';						
		}
}
function ajaxDisplayAlterne (url,divName) {
  
  if (document.getElementById(divName).style.display == 'block')
  {
   document.getElementById(divName).style.display = 'none';
   
  }
  else
     ajaxDisplay (url,divName);
}
function ajaxDisplay (url,divName) {
	if (document.getElementById(divName))
	{
	document.getElementById(divName).style.display = 'block';
	if (url == "vider")
	{
		document.getElementById(divName).innerHTML = '';
	}
	else if (url == "radar")
	{
	 url = document.getElementById('radar').firstChild.getAttribute('src').split('?')[0];
	 url = url + "?id="+CPT_RADAR;
	 CPT_RADAR += 1;
    document.getElementById('radar').firstChild.setAttribute('src',url);
  }
  else
	{
		var xhr = null; 
		if (window.XMLHttpRequest) // Firefox 
		   xhr = new XMLHttpRequest(); 
		else if (window.ActiveXObject) // Internet Explorer 
		   xhr = new ActiveXObject("Microsoft.XMLHTTP"); 
		else 
		{// XMLHttpRequest non supporté par le navigateur 
		   document.getElementById(divName).innerHTML =  '<div id="' + divName + '" style="width:100%;overflow:auto;">Votre navigateur ne supporte pas les objets XMLHTTPRequest.<br>Nous vous conseillons de le mettre à jour.</div>'; 
		   return; 
		}
	 	xhr.open("GET", url, true);
		xhr.onreadystatechange  = function () 
		{
			if (xhr.readyState == 4)
				if (xhr.status == 200)
					document.getElementById(divName).innerHTML = xhr.responseText;
		}
		xhr.send(null);
	}
	}
}

function ajaxSubmit(form,url,div)
{
	var variables = form.elements;
	for (i=0; i < variables.length ; i++)
	{
	 if (variables[i].multiple)
	 {
    for (j=0; j < variables[i].length; j++)
    {
      if (variables[i].options[j].selected)
      {
        var value = variables[i].options[j].value;
    		value = value.replace('/','-');
    		value = value.replace('&','');
    		value = value.replace('#','');
    		value = value.replace('’',"'");
    		value = value.replace('…',"...");
    		url = url+'&'+variables[i].name+'='+value;
      }
    }
   }
   else
   {
		var value = variables[i].value;
		while (value.indexOf('?') != -1)
			value = value.replace('?','%3F');
		while (value.indexOf('/') != -1)
			value = value.replace('/','-');
		while (value.indexOf('&') != -1)
			value = value.replace('&','');
		while (value.indexOf('#') != -1)
			value = value.replace('#','');
		while (value.indexOf('’') != -1)
			value = value.replace('’',"'");
		while (value.indexOf('…') != -1)
			value = value.replace('…',"...");
		while (value.indexOf("\r\n") != -1)
			value = value.replace("\r\n","<br>");
		while (value.indexOf("\n") != -1)
			value = value.replace("\n", "<br>");
		while (value.indexOf("\r") != -1)
			value = value.replace("\r","<br>");
		url = url+'&'+variables[i].name+'='+value;
	 }
	}
	ajaxDisplay(url,div);
}

// fonction qui verifie les infos et valide le formulaire si tout est ok (CONNECTION)
function verif_connection () {
	var message = "";
	var pass = document.frmConnection.password.value;
	var email = document.frmConnection.email.value;
	var arobase = email.split("@");
	var point = email.split(".");
	var reg = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]{2,}[.][a-zA-Z]{2,4}$/
	
	// verif que les champs ne sont pas vides
	if (reg.exec(email) == null){
		message += "L'adresse e-mail n'est pas valide : veuillez saisir une adresse e-mail valide.   \r\n";
		document.frmConnection.email.focus();
		alert(message);
		return false;
	}
	if (email == ""){
		message += " L'adresse e-mail n'a pas été saisie : ce champs est obligatoire.   \n\r";

		document.frmConnection.email.focus();
		alert(message);
		return false;
	}
	if ((arobase.length < 2) || (point.length < 2)){
		message += "L'adresse e-mail n'est pas valide : veuillez saisir une adresse e-mail valide.   \r\n";
		document.frmConnection.email.focus();
		alert(message);
		return false;
	}
	if (pass == ""){
		message += "Le password n'a pas été saisi : ce champs est obligatoire.   \n\r";
		document.frmConnection.password.focus();
		alert (message);
		return false;
	}
}

//////////////////////////////////////////////
// Verification du formulaire d'inscription
//////////////////////////////////////////////
function verifFormu(formulaire, contexte){
	var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,4}$/
	
	var message = '';
	var email = formulaire.email.value;
	
	
	
	if (contexte == 'interet'){
		
	}

	if (contexte == '360'){
		if (formulaire.prenom.value == ''){
			message = "Le prénom est obligatoire   \r\n";
			formulaire.prenom.focus();
			alert(message);
			return false;
		}
		
		if (formulaire.nom.value == ''){
			message = "Le nom est obligatoire.   \r\n";
			formulaire.nom.focus();
			alert(message);
			return false;
		}
	}	
	
	
	if (email == ''){
		message = "L'adresse e-mail est obligatoire.   \r\n";
		formulaire.email.focus();
		alert(message);
		return false;
	}
	
	if (reg.exec(email) == null){
		message = "L'adresse e-mail n'est pas valide : veuillez saisir une adresse e-mail valide.   \r\n";
		formulaire.email.focus();
		alert(message);
		return false;
	}
}

//////////////////////////////////////////////////////////////////
// fonction qui valide les parties une par une du 2eme test tricam
//////////////////////////////////////////////////////////////////

function verif_click (prems, deuz, etape1, etape2) {
	if (prems.id == "partie_1") {
		var temoin = 0;
		var choix = document.frmProfil2.que2_1;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val1 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_2;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val2 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_3;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val3 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_4;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val4 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_5;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val5 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_6;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val6 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_7;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val7 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_8;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val8 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_9;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val9 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_10;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val10 = choix[i].value;
			}
		}
		if (temoin == 10) {
			var result = val1+":"+val2+":"+val3+":"+val4+":"+val5+":"+val6+":"+val7+":"+val8+":"+val9+":"+val10+":";
			document.frmProfil2.tricam2_1.value = result;
			//prems.style.display = 'none';
			//deuz.style.display = '';
			//etape1.style.display = 'none';
			//etape2.style.display = '';
			document.getElementById('partie_1').style.display='none';
			document.getElementById('partie_2').style.display='block';
		}
	}
	if (prems.id == "partie_2") 
	{
		var temoin = 0;
		var choix = document.frmProfil2.que2_11;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val1 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_12;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val2 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_13;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val3 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_14;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val4 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_15;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val5 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_16;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val6 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_17;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val7 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_18;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val8 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_19;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val9 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_20;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val10 = choix[i].value;
			}
		}
		if (temoin == 10) {
			var result = val1+":"+val2+":"+val3+":"+val4+":"+val5+":"+val6+":"+val7+":"+val8+":"+val9+":"+val10+":";
			document.frmProfil2.tricam2_2.value = result;
			//prems.style.display = 'none';
			//deuz.style.display = '';
			//etape1.style.display = 'none';
			//etape2.style.display = '';
			document.getElementById('partie_2').style.display='none';
			document.getElementById('partie_3').style.display='block';
		}
	}
	if (prems.id == "partie_3") {
		var temoin = 0;
		var choix = document.frmProfil2.que2_21;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val1 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_22;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val2 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_23;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val3 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_24;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val4 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_25;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val5 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_26;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val6 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_27;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val7 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_28;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val8 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_29;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val9 = choix[i].value;
			}
		}
		var choix = document.frmProfil2.que2_30;
		for (var i = 0; i < choix.length; i++) {
			if (choix[i].checked == true) {
				temoin++;
				var val10 = choix[i].value;
			}
		}
		if (temoin == 10) {
			var result = val1+":"+val2+":"+val3+":"+val4+":"+val5+":"+val6+":"+val7+":"+val8+":"+val9+":"+val10+":";
			document.frmProfil2.tricam2_6.value = result;
			document.frmProfil2.submit();
		}
	}
}

function doc() {
	var formulaire 	= document.question;
	var formulaire2 = document.documents;

	formulaire2.titre.value 	= formulaire.titre.value;
	formulaire2.addCategorie.value 	= formulaire.addCategorie.value;
	formulaire2.categorie.value 	= formulaire.categorie.value;
	formulaire2.question.value 		= formulaire.question.value;

	formulaire2.submit();
}

function ShowCVMap(id_user, id_div, adr)
{
	$.post(adr + "/cvmap/object", { id_user:id_user }, function(data) {
		$("#"+id_div).html('');
		$("#"+id_div).html(data);
		$("#"+id_div).slideDown();
	});
}