function string_generator(nb_caract,id) {
	var chaine = 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','6','7','8','9');
	var pass = '';
	var nb, u;
	for (u=1; u <= nb_caract; u++) {
	nb = chaine.length;
	nb = Math.round(Math.random()*chaine.length);
	pass += chaine[nb];
	}
	document.getElementById(id).value = pass;
}

//Permet de sélectionner tout les checkbox
function toggleAll(name) {
var inputs = document.getElementsByTagName('input');
var count  = inputs.length;

for (m = 0; m < count; m++) {
  _input = inputs.item(m);
  if (_input.type == 'checkbox' && _input.id.indexOf('chk-' + name) != -1) {
      _input.checked = document.getElementById(name + '-all').checked;
      }
  }
}

function toggleCheckboxes() {
// written by Daniel P 3/21/07
// toggle all checkboxes found on the page
  	var inputlist = document.getElementsByTagName("input");
  	for (i = 0; i < inputlist.length; i++) {
   	if ( inputlist[i].getAttribute("type") == 'checkbox' ) {	// look only at input elements that are checkboxes
			if (inputlist[i].checked)	inputlist[i].checked = false
			else								inputlist[i].checked = true;
		}
	}
}

function creeXMLHttpRequestObject(){ try{ Req = new ActiveXObject("Microsoft.XMLHTTP"); } catch(Error){ try{Req = new ActiveXObjet("MSXML2.XMLHTTP");} catch(Error){try{Req = new XMLHttpRequest();} catch(Error){alert("Impossible de créer l'objet");}}} return Req; }

function OuvrirPopup(page,nom,option) { window.open(page,nom,option); }

function tick_change(id_img,id_input){
	if(document.getElementById(id_input).value == "1"){
		document.getElementById(id_input).value = "0";
		document.getElementById(id_img).src = "images/tick_no.png";
	}else{
		document.getElementById(id_input).value = "1";
		document.getElementById(id_img).src = "images/tick_yes.png";
	}
}

function vide_champ(id,text){ if(document.getElementById(id).value == text){ document.getElementById(id).value = ""; } }
function remplir_champ(id,text){ if(document.getElementById(id).value == ""){ document.getElementById(id).value = text; } }

function show_conex(){
		$('#bloc_conex_right').slideDown("slow");                     
		$('#conex_and_insc_global').slideUp("slow");                     
}

function showout_conex(){
		$('#conex_and_insc_global').slideDown("slow");                     
		$('#bloc_conex_right').slideUp("slow");                     
}

function show_insc(){
		$('#bloc_insc_right').slideDown("slow");                     
		$('#conex_and_insc_global').slideUp("slow");                     
}

function showout_insc(){
		$('#conex_and_insc_global').slideDown("slow");                     
		$('#bloc_insc_right').slideUp("slow");                     
}

function change_img(img,id){
		document.getElementById(id).src = img;
}

function protec_insc(){
	document.getElementById('protect').innerHTML = "<center><img src='images/btn_insc_validation.jpg' /><br /><img src='images/ajax-loader.gif' /></center>";	
}

function protec_contact(){
	document.getElementById('protect').innerHTML = "<center><img src='images/btn_envoyer.jpg' /><br /><img src='images/ajax-loader.gif' /></center>";	
}


function rubrique(id,nb,radio,champ){

	for(i=1;i<=nb;i++){
	document.getElementById(radio+i).src = "images/radio_no.png";
	}
	
	document.getElementById(radio+id).src = "images/radio_yes.png";
	document.getElementById(champ).value = id;
}

function rubrique_add(id,nb,radio,champ){

	for(i=1;i<=nb;i++){
		if(document.getElementById('bloc_rub_' + i) && document.getElementById('bloc_rub_' + i).style.display != "none"){
				$('#bloc_rub_' + i).slideUp("slow"); 

		}
		document.getElementById(radio+i).src = "images/radio_no.png";
	}


	document.getElementById(radio+id).src = "images/radio_yes.png";
	document.getElementById(champ).value = id;
	
	if(document.getElementById('bloc_rub_' + id)){
		$('#bloc_rub_' + id).slideDown("slow");   
	}
}


function verif_login(){
	
	var login = document.getElementById("login").value;
	if(login.length == 0){
		document.getElementById('login').style.border = "1px solid #77a1d7";
		document.getElementById('login').style.color = "black";	

	}else if(login.length < 3){
				document.getElementById('login').style.border = "1px solid red";	
				document.getElementById('login').style.color = "red";	
	}else{
		if( Req = creeXMLHttpRequestObject()){ Req.onreadystatechange = function(){ if(Req.readyState == 4){ if(Req.status == 200){  		
			
			if(Req.responseText == "0"){
				document.getElementById('login').style.border = "1px solid red";	
				document.getElementById('login').style.color = "red";	
			}else{
				document.getElementById('login').style.border = "1px solid green";	
				document.getElementById('login').style.color = "green";	
			}
		} } } }
				
		Req.open("GET","ajax/verif-login.inc.php?login="+login, true);
		Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		Req.send(null); 
	}
}


function departement(region){

	if( Req = creeXMLHttpRequestObject()){ Req.onreadystatechange = function(){ if(Req.readyState == 4){ if(Req.status == 200){  		
		
		document.getElementById('departements').innerHTML = Req.responseText;	
		
	} } } }
			
	Req.open("GET","ajax/departements.inc.php?region="+region, true);
	Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	Req.send(null); 
}

function departement_recherche(region){

	if( Req = creeXMLHttpRequestObject()){ Req.onreadystatechange = function(){ if(Req.readyState == 4){ if(Req.status == 200){  		
		
		document.getElementById('departements').innerHTML = Req.responseText;	
		
	} } } }
			
	Req.open("GET","ajax/departements_recherche.inc.php?region="+region, true);
	Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
	Req.send(null); 
}

function close_header(){
		$('#banner').slideUp("slow");
		document.getElementById('arrow_close_header').style.display = "none";
		document.getElementById('arrow_open_header').style.display = "";
		
		if( Req = creeXMLHttpRequestObject()){ Req.onreadystatechange = function(){  if(Req.readyState == 4){ if(Req.status == 200){ } } } }			
		Req.open("GET","ajax/header_session.inc.php?h=close", true);
		Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		Req.send(null); 
}

function open_header(){
		$('#banner').slideDown("slow");
		document.getElementById('arrow_close_header').style.display = "";
		document.getElementById('arrow_open_header').style.display = "none";
		
		if( Req = creeXMLHttpRequestObject()){ Req.onreadystatechange = function(){ if(Req.readyState == 4){ if(Req.status == 200){ } } } }			
		Req.open("GET","ajax/header_session.inc.php?h=open", true);
		Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		Req.send(null); 
}

function thumb_open_info(id){
		document.getElementById(id).style.display = "";
}

function thumb_close_info(id){
		document.getElementById(id).style.display = "none";
}

function show_region(num,choix,select){
	if(choix == "1"){
		document.getElementById('map_france_img').src = "images/map/"+ num +".png";
	
		if(Req = creeXMLHttpRequestObject()){ Req.onreadystatechange = function(){  if(Req.readyState == 4){ if(Req.status == 200){
			document.getElementById('nom_region').innerHTML = Req.responseText;
		} } } }			
		
		Req.open("GET","ajax/region.inc.php?r="+ num, true);
		Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		Req.send(null);
		
	}else if(choix == "2"){
		if(select != ""){
			document.getElementById('map_france_img').src = "images/map/"+ select +".png";
			if(Req2 = creeXMLHttpRequestObject()){ Req2.onreadystatechange = function(){  if(Req2.readyState == 4){ if(Req2.status == 200){
				if(Req2.responseText == ""){
					document.getElementById('nom_region').innerHTML = "";
				}else{
					document.getElementById('nom_region').innerHTML = Req2.responseText;
				}
			} } } }			
			
			Req2.open("GET","ajax/region.inc.php?r="+ select, true);
			Req2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
			Req2.send(null);
		}else{                                                                                     
			document.getElementById('map_france_img').src = "images/vide.png";
					document.getElementById('nom_region').innerHTML = "";
		}
	}
}

function show_journal_msg(id,type){

	if(type == 1){
		document.getElementById(id).style.display = "";		
	}else{
		document.getElementById(id).style.display = "none";		
	}

}

function graph_month_line_select(id,visites,date_s){
	
	for(i=1;i<=31;i++){
		if(document.getElementById("selector_"+i)){
			document.getElementById("selector_"+i).style.display = "none";
		}
		if(document.getElementById("barre_graph_selector_"+i)){
			document.getElementById("barre_graph_selector_"+i).style.background = "#252525";
		}
	}
	
	if(document.getElementById("barre_graph_selector_"+id)){
			document.getElementById("barre_graph_selector_"+id).style.background = "#2a2a2a";
	}
	if(document.getElementById("selector_"+id)){
			document.getElementById("selector_"+id).style.display = "block";
	}
	
	document.getElementById("visites_select").innerHTML = visites;
	document.getElementById("date_select").innerHTML = date_s;
	
}


function stats_advert(id,serial,user,emp){

		if( Req = creeXMLHttpRequestObject()){ Req.onreadystatechange = function(){ if(Req.readyState == 4){ if(Req.status == 200){ } } } }			
		Req.open("GET","ajax/stats-advert.inc.php?id="+id+"&serial="+serial+"&user="+user+"&emp="+emp, true);
		Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		Req.send(null); 
	
}

function stats_clic(id){

		if( Req = creeXMLHttpRequestObject()){ Req.onreadystatechange = function(){ if(Req.readyState == 4){ if(Req.status == 200){ } } } }			
		Req.open("GET","ajax/stats-clics.inc.php?id="+id, true);
		Req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); 
		Req.send(null); 
}

function show_map(pays){
	if(pays == "france"){ 
		$('#map_pays_france').slideDown("slow");
		document.getElementById("link_show_map").style.display = "none";
		document.getElementById("link_hidden_map").style.display = "";
	}
}
function hidden_map(pays){
	if(pays == "france"){ 
		$('#map_pays_france').slideUp("slow");
		document.getElementById("link_show_map").style.display = "";
		document.getElementById("link_hidden_map").style.display = "none";
	}
}

