function genereModeleRch(prefix) {
	if ( ! prefix ) prefix = '';
// 	catID = _Elem(prefix+'categorie_id').value;
	catID = 0;
// 	if (_Elem(prefix+'marque_id') && _Elem(prefix+'marque_id').value > 0) {
		marqueID = _Elem(prefix+'marque_id').value;
		remoteSel = new select();
// 		debug('catId='+catID);
		mrqSql = 'AND M.marque_id = '+marqueID+' ';
		
		
		sql = 'SELECT  group_concat(DISTINCT M.modele_id) as selKey, M.libelle as selVal \
		FROM auto_modeles M\
		INNER JOIN auto_vehicules V on V.modele_id = M.modele_id \
		WHERE 1 '+mrqSql+' \
		AND V.enligne = 1 \
		AND V.garage_id in ('+siteId+') \
		GROUP BY libelle \
		ORDER BY libelle \
		 ';
		ary = remoteSel.sql2SelectAjax(sql, prefix+'modele_id', prefix+'rch[modele_id]', 'tabindex="" class="saisieAuto"');
		if (ary.length > 0) {
			_Elem(prefix+'Smodele_id').innerHTML = ary;
			selectAddOption('modele_id', sel_mdl, 0, 'top');
			_Elem('modele_id').value = 0;
		} else {
			sel = document.createElement('select');
			sel.name="rch[modele_id]";
			sel.id = prefix+"modele_id";
			sel.className = "saisieAuto";
			_Elem(prefix+'Smodele_id').innerHTML = '';
			_Elem(prefix+'Smodele_id').appendChild(sel);
			if (_Elem(prefix+"marque_id").value == 0)
				selectAddOption('modele_id', sel_mdl, 0, 'top');
			
			if (_Elem(prefix+"marque_id").value == -1)
				selectAddOption('modele_id', no_veh_in_stk, 0, 'top');
		}
}

var cp = '';
var old_cp = '';
var villePrx = '';
function doVilles(prx) {
	var remoteVilles = new villes(villesCallBack);
  cp = _Elem(prx+'code_postal').value;
  if (cp != old_cp){
    if (cp) { remoteVilles.getvilles(cp); }
    old_cp = cp ;
	villePrx = prx;
  }
}

var villesCallBack = {
  getvilles: function (aryVilles) {
    var sel = _Elem(villePrx+'ville_id');
    sel.length=0;

	if (!aryVilles) {
		var res = document.createElement('option');
        res.value=0;
        res.innerHTML='Pas de villes pour ce Code postal';
        sel.appendChild(res);
	}
    else {
      for (var i = 0; i < aryVilles.length; ++i) {
        var res = document.createElement('option');
        res.value=aryVilles[i]['ville_id'];
        res.innerHTML=aryVilles[i]['commune'];
        sel.appendChild(res);
      }
      }
    }
  }

function addPhoto(id) {
_Elem('iphoto').value= '';
_Elem('iphoto').name= 'photo'+id;
// _Elem('dvphoto').style.display = 'block';
bindDivs('dvphoto', 'photo'+id);

}

function deletePhoto(id) {
	_Elem('hphoto'+id).value = '';
	_Elem('photo'+id).innerHTML = "<a href=\"javascript:addPhoto('"+id+"')\">"+add_photo+"</a><br><br>";
}


// fonctions listes
function sortList(listeName, sortField, sortOrder, page, countField) {
	remoteListe = new liste();
	if (countField) countField = countField;
	else countField = '*';
	_Elem(listeName).innerHTML = remoteListe.ajaxSort(listeName, sortField,sortOrder,page, countField);
}
function reloadList(listeName) {
	remoteListe = new liste();
	_Elem(listeName).innerHTML = remoteListe.ajaxReload(listeName);
}

/**
/* Methode permettant de passer directement au champ suivant pour la saisie de date
/* champ1 : champ de départ
/* champ2 : champ d'arrivée
*/
function Compter(champ1, champ2)
{
	// Nombre de caractères max 2 pour jour et mois
	var max = 2;
	// Longueur actuelle du champ1
	var taille = _Elem(champ1).value.length
	// Si le nombre de caractères est >= au nombre max autorisé, on passe au champ suivant
	if (taille >= max)
	{
		_Elem(champ2).focus();
	}
}


function verifInscription() {
    reqs = new Array('email', 'nom', 'prenom', 'code_postal', 'dnJJ', 'dnMM', 'dnAAAA', 'telephone');
    nbErr = 0;
	fieldTofocus = 'none';
    for (i=0; i<reqs.length; i++) {
        if (_Elem(reqs[i]).value.length < 1) {
            _Elem(reqs[i]).style.borderColor = '#FF0000';
            nbErr ++;
			if (fieldTofocus == 'none') fieldTofocus = reqs[i];
        } else { _Elem(reqs[i]).style.borderColor = '#999999'; }
    }
    // traitements particuliers
	 if (!(emailCheck(_Elem('email').value)==true)) {
        _Elem('email').style.borderColor = '#FF0000';
        nbErr ++;
		if (fieldTofocus == 'none') fieldTofocus = 'email';
    } else { _Elem('email').style.borderColor = '#999999'; }
	
	if (_Elem('ville_id').value > 0) {
        _Elem('ville_id').style.borderColor = '#999999';      
	} else {
		_Elem('ville_id').style.borderColor = '#FF0000';
        nbErr ++;
		if (fieldTofocus == 'none') fieldTofocus = 'ville_id';
	}
    
    if (_Elem('dnJJ').value && _Elem('dnMM').value && _Elem('dnAAAA').value) {
        myDate = new Date(_Elem('dnAAAA').value,_Elem('dnMM').value-1,_Elem('dnJJ').value);
        if ( (myDate.getDate() == _Elem('dnJJ').value) &&
            ((myDate.getMonth()+1) == _Elem('dnMM').value) &&
            (myDate.getFullYear() == _Elem('dnAAAA').value) ) {
            _Elem('dnJJ').style.borderColor = '#999999';
            _Elem('dnMM').style.borderColor = '#999999';
            _Elem('dnAAAA').style.borderColor = '#999999';
        } else {
            _Elem('dnJJ').style.borderColor = '#FF0000';
            _Elem('dnMM').style.borderColor = '#FF0000';
            _Elem('dnAAAA').style.borderColor = '#FF0000';
            nbErr++;
			if (fieldTofocus == 'none') fieldTofocus = 'dnJJ';
        }
    }
	
    // CV
    if (_Elem('cv').value != '') {
        tmp = _Elem('cv').value.split('.');
        if (tmp[tmp.length-1] == 'pdf' || tmp[tmp.length-1] == 'doc' || tmp[tmp.length-1] == 'txt') {
            _Elem('cv').parentNode.style.border = "0px";
        } else {
            _Elem('cv').parentNode.style.border = "1px solid #ff0000";
            nbErr++;
            if (fieldTofocus == 'none') fieldTofocus = 'cv';
        }        
    } else {
        //alert(_Elem('cv').value);
        _Elem('cv').parentNode.style.border = "1px solid #ff0000";
        nbErr++;
        if (fieldTofocus == 'none') fieldTofocus = 'cv';
    }
	
	if (fieldTofocus != 'none') _Elem(fieldTofocus).focus();
    if (nbErr == 0) return true;
    return false;
}