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;
}
