function xhide(n) {
	document.getElementById(n).style.display = 'none';
}

function xshow(m) {
	document.getElementById(m).style.display = '';
}

function confirmation(message) {
		return confirm(message);
}

function delete_utilisateur() {
	if(confirm('Confirmez-vous la suppression de cet utilisateur ?'))
	{
		return true;
	}
	else
	{
		return false;
	}
}

function load_ajax(area, url) 
{
	var XHR = new XHRConnection();
	document.getElementById(area).innerHTML = "...";
	XHR.setRefreshArea(area);
	XHR.sendAndLoad(url, "GET");
	return true;
}

function set_utilisateur_dans_liste(area,url)
{
	load_ajax(area, url);
}

function get_vehicule_serie(area, url)
{
	load_ajax(area, url);
	xhide('liste_vehicule_modele');
	xhide('liste_vehicule_moteur');
}

function set_vehicule_serie(area, url, id)
{
	load_ajax(area, url);
	xshow('liste_vehicule_modele');
	get_vehicule_modele('liste_vehicule_modele', 'ajax/veh_modele.ajax.php?parent='+id)
}

function get_vehicule_modele(area, url)
{
	load_ajax(area, url);
	xhide('liste_vehicule_moteur');
}

function set_vehicule_modele(area, url,id)
{
	load_ajax(area, url);
	xshow('liste_vehicule_moteur');
	get_vehicule_moteur('liste_vehicule_moteur', 'ajax/veh_moteur.ajax.php?parent='+id)
}

function get_vehicule_moteur(area, url)
{
	load_ajax(area, url);
}

function set_vehicule_moteur(area, url, id)
{
	load_ajax(area, url);
}

function coche_tout(a,b)

{

    var booo = document.getElementById('chk').checked;

    for (i = a; i <= b; i++) 

    {

        if(document.getElementById('chk_' + i ).checked != booo)

        {

            document.getElementById('chk_' + i ).checked = booo;

            document.getElementById('chk_' + i ).onclick();

        }

    }

    document.getElementById('chk').checked = booo;

}

function js_pwgen (nb_chars)
{
    var keylist = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
    var password = '';

    for(var i = 0 ; i < parseInt(nb_chars); i++)
    {
        password += keylist.charAt(Math.floor(Math.random()*keylist.length));       
    }
    return password;
}

function fill_password (nb_chars)
{
    var form = document.form_utilisateur; // à remplacer par le bon nom de formualire
    form.pwd.value = js_pwgen(nb_chars); // à remplacer par le bon nom de champ
}


//popup
var newWin = null;
function closeWin(){
	if (newWin != null){
		if(!newWin.closed)
			newWin.close();
	}
}

function popUp(strURL,strType,strHeight,strWidth) {
	closeWin();
	var strOptions="";
	if (strType=="console") strOptions="resizable,scrollbars,height="+strHeight+",width="+strWidth;
	if (strType=="fixed") strOptions="status,height="+strHeight+",width="+strWidth;
	if (strType=="elastic") strOptions="toolbar,menubar,scrollbars,resizable,location,height="+strHeight+",width="+strWidth;
	newWin = window.open(strURL, 'newWin', strOptions);
	newWin.focus();
}

function next_step_insc_user()
{
	if(document.getElementById('veh_moteur'))
	{
		xhide('form_part_one');
		xshow('form_part_two');
	}
	else
	{
		alert('Vous devez choisir une voiture avant de passer à la suite');
	}
}

 function set_doc_title(file,name){
	var value = document.getElementById(file).value;
	basename_array = value.split('\\');
	var basename = basename_array[basename_array.length-1];
	name_array = basename.split('.');
	//nume = name_array[name_array.length-2];
	nume = '';
	for (i=0; i<=name_array.length-2; i++){
		if (i > 0)
		{
			nume = nume + '.';
		}
		nume = nume + name_array[i];
	}
	if (basename.indexOf('.',0) == -1)
	{
		nume = basename;
	}

	document.getElementById(name).value = nume;
}


function hide_all(sauf)
{
	xshow(sauf);
	if(sauf != 'intro')
	{	
		xhide('intro');
	}
	if(sauf != 'design')
	{	
		xhide('design');
	}
	if(sauf != 'ergonomie')
	{	
		xhide('ergonomie');
	}
	if(sauf != 'moteur')
	{	
		xhide('moteur');
	}
	if(sauf != 'chassis')
	{	
		xhide('chassis');
	}
	if(sauf != 'securite')
	{	
		xhide('securite');
	}
}

  function confirmation_envoi(id)
  {
	if(confirm("Confirmez-vous l'envoi de cette newsletter"))
	{
		popUp("spool.php?id="+id,"console",60,300)
	}
  }
  
  
  
function radiovide() 
{
	//Q1
	ok=false;
	for (var n=0;n<document.sondage.q1.length;n++)
	{
		if ( document.sondage.q1[n].checked)
		{ 
			ok=true;
			n=document.sondage.q1.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir la question 1');
		return false;
	}
	//Q2
	ok=false;
	for (var n=0;n<document.sondage.q2.length;n++)
	{
		if ( document.sondage.q2[n].checked)
		{ 
			ok=true;
			n=document.sondage.q2.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir la question 2');
		return false;
	}
	//Q3
	ok=false;
	for (var n=0;n<document.sondage.q3.length;n++)
	{
		if ( document.sondage.q3[n].checked)
		{ 
			ok=true;
			n=document.sondage.q3.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir la question 3');
		return false;
	}
	//Q4
	ok=false;
	for (var n=0;n<document.sondage.q4.length;n++)
	{
		if ( document.sondage.q4[n].checked)
		{ 
			ok=true;
			n=document.sondage.q4.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir la question 4');
		return false;
	}	
	//Q51
	ok=false;
	for (var n=0;n<document.sondage.q51.length;n++)
	{
		if ( document.sondage.q51[n].checked)
		{ 
			ok=true;
			n=document.sondage.q51.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir entierement la question 5');
		return false;
	}	
	//Q52
	ok=false;
	for (var n=0;n<document.sondage.q52.length;n++)
	{
		if ( document.sondage.q52[n].checked)
		{ 
			ok=true;
			n=document.sondage.q52.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir entierement la question 5');
		return false;
	}	
	//Q53
	ok=false;
	for (var n=0;n<document.sondage.q53.length;n++)
	{
		if ( document.sondage.q53[n].checked)
		{ 
			ok=true;
			n=document.sondage.q53.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir entierement la question 5');
		return false;
	}	
	//Q54
	ok=false;
	for (var n=0;n<document.sondage.q54.length;n++)
	{
		if ( document.sondage.q54[n].checked)
		{ 
			ok=true;
			n=document.sondage.q54.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir entierement la question 5');
		return false;
	}	
	//Q55
	ok=false;
	for (var n=0;n<document.sondage.q55.length;n++)
	{
		if ( document.sondage.q55[n].checked)
		{ 
			ok=true;
			n=document.sondage.q55.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir entierement la question 5');
		return false;
	}	
	//Q56
	ok=false;
	for (var n=0;n<document.sondage.q56.length;n++)
	{
		if ( document.sondage.q56[n].checked)
		{ 
			ok=true;
			n=document.sondage.q56.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir entierement la question 5');
		return false;
	}	
	//Q57
	ok=false;
	for (var n=0;n<document.sondage.q57.length;n++)
	{
		if ( document.sondage.q57[n].checked)
		{ 
			ok=true;
			n=document.sondage.q57.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir entierement la question 5');
		return false;
	}	
	//Q6
	ok=false;
	for (var n=0;n<document.sondage.q6.length;n++)
	{
		if ( document.sondage.q6[n].checked)
		{ 
			ok=true;
			n=document.sondage.q6.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir la question 6');
		return false;
	}	
	//Q8
	ok=false;
	for (var n=0;n<document.sondage.q8.length;n++)
	{
		if ( document.sondage.q8[n].checked)
		{ 
			ok=true;
			n=document.sondage.q8.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir la question 8');
		return false;
	}	
	//Q9
	ok=false;
	for (var n=0;n<document.sondage.q9.length;n++)
	{
		if ( document.sondage.q9[n].checked)
		{ 
			ok=true;
			n=document.sondage.q9.length;
		}
	}
	if (ok == false)
	{
		alert('Vous devez remplir la question 9');
		return false;
	}	
	document.sondage.submit(); 
}  
