
var ns4 = document.layers
var ie4 = document.all
var ns6 = document.getElementById&&!document.all

/*******************************************************************************
 *	( GENERALE ) SUPPRESSION D'UN ENREGISTREMENT
 *******************************************************************************/
function remove(elementUrl, id)
{
	if( confirm("Supprimer cet enregistrement ?") )
	{
		location.href = elementUrl + ".supprimer.traitement.php?id=" + id;
	}
}	

/*******************************************************************************
 *	ROOLOVER SUR UNE LIGNE
 *******************************************************************************/
function setPointer(theRow, thePointerColor)
{    
	
	if (typeof(theRow.style) == 'undefined' || typeof(theRow.cells) == 'undefined') 
	{
        return false;
    }

    var rowCells = theRow.cells.length;
    for (var c = 0; c < rowCells; c++) 
	{
        //theRow.cells[c].bgColor = thePointerColor;
		//alert(theRow.cells[c].id);
		if (theRow.cells[c].id != 'tdtransac')	theRow.cells[c].style.background = thePointerColor;
    }

    return true;
} 

/*******************************************************************************
 *	ROOLOVER SUR UNE IMAGE
 *******************************************************************************/
function RollOver(img, url) 
{
	img.src = url;	
}

/*******************************************************************************
 *	OUVRIR UNE IMAGE
 *******************************************************************************/
function openPhoto(path)
{		
	fw = 400;
	fh = 300;			
	x = (screen.width - fw)/2;
	y = (screen.height - fh)/2;
	window.open(path, "PHOTO", "status=0,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=yes,resizable=yes,width=" + fw + ",height=" + fh + ",left=" + x + ",top=" + y);			
}	

/*******************************************************************************
 * FONCTION GETXMLHTTP
 * DESCRIPTION : 
*******************************************************************************/
function getXMLHTTP()
{
		var xhr=null;
		if(window.XMLHttpRequest)
		{
			xhr = new XMLHttpRequest();
		}
		else if(window.ActiveXObject)
		{ 
			try 
			{
				xhr = new ActiveXObject("Msxml2.XMLHTTP");
			} 
			catch (e) 
			{
				try 
				{
					xhr = new ActiveXObject("Microsoft.XMLHTTP");
				} 
				catch (e1) 
				{
					xhr = null;
				}
			}
		}
		else 
		{ 
			alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");
		}
		return xhr;
}

/************************************************************************
 * Function	: loadRegion 
 *			  Recuperer la liste des regions d'un pays
 ************************************************************************/
function loadRegion(idPays, idRegion, idDepartement)
{ 	
	if(idPays != -1)
	{
		var _xmlHttp = getXMLHTTP(); 

		if(_xmlHttp)
		{ 	
			_xmlHttp.open("GET", "ajax.pays.region.php?id=" + idPays, true); 
			_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp.onreadystatechange = function() 
			{ 	
				if(_xmlHttp.readyState == 4 && _xmlHttp.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp.responseText + ")");
				
					document.forms[0].idRegion.options.length = rsAjax.liste.length + 1;
					document.forms[0].idRegion.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{
						if(idRegion == rsAjax.liste[i].id)
						{
							document.forms[0].idRegion.options.selectedIndex = (i+1);
							loadDepartement(idRegion, idDepartement);
						}
						document.forms[0].idRegion.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idRegion.options[i+1].text = rsAjax.liste[i].libelle;
					}	
					
					if(idRegion == null)
					{
						document.forms[0].idDepartement.options.length = 1;
					}

				} 
			}
			_xmlHttp.send(null) 
		}
	}
} 

function notify(flag, processingName) 
{	
	// wait indicator
	var e = document.getElementById(processingName);

	// use relative path only...
	var waiting =  '<img src="img/indicator.gif" border="0" alt="processing"/>';

	var done = '&nbsp;';
	e.innerHTML = (flag) ? waiting : done;
}

function populateDepartement(rs)
{	
	var srubElt = new form_select(document.getElementById('idDepartement'));
	srubElt.def_option = {'-1' : 'Selectionnez un département'};

	srubElt.reset();
	srubElt.populate(rs);
	srubElt.disable(false);

	notify(false, "processingDepartement");
}


/************************************************************************
 * Function	: loadDepartement 
 *			  Recuperer la liste des departements d'une region
 ************************************************************************/
 var BASEURL =  '/';
function loadDepartement(idPays, idDepartement)
{ 	
	if(idPays != -1)
	{
		var _xmlHttp = getXMLHTTP(); 

		if(_xmlHttp)
		{ 	
			_xmlHttp.open("GET", "/backoffice/ajax.pays.departement.php?id=" + idPays, true); 
			_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp.onreadystatechange = function() 
			{ 	
				if(_xmlHttp.readyState == 4 && _xmlHttp.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp.responseText + ")");
				
					document.getElementById("libelleRegion").innerHTML = "";

					document.forms[0].idDepartement.options.length = rsAjax.liste.length + 1;						
					document.forms[0].idDepartement.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{
						if(idDepartement == rsAjax.liste[i].id) document.forms[0].idDepartement.options.selectedIndex = (i+1);
						document.forms[0].idDepartement.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idDepartement.options[i+1].text = rsAjax.liste[i].libelle;
					}				
				} 
			}
			_xmlHttp.send(null) 
		}
	}
} 

function loadDepartement_V2(idPays, idDepartement)
{ 	
	var ao = new AjaxObject();
	ao.setCallback('populateDepartement', 'text');
	ao.sndReq('POST', BASEURL + 'backoffice/ajax.pays.departement.2.php', {"id":idPays});

	notify(true, "processingDepartement");
	
	// Pour supprimer libelleRegion
	document.getElementById("libelleRegion").innerHTML = '&nbsp;';
}

/************************************************************************
 * Function	:	loadPaysLibelle
 *				Affiche le libelle du pays selectionné
 ************************************************************************/
function loadRegionLibelle(idDepartement)
{ 		
	if(idDepartement != -1)
	{
		var _xmlHttp = getXMLHTTP(); 

		if(_xmlHttp)
		{ 	
			_xmlHttp.open("GET", "/backoffice/ajax.departementRegion.php?id=" + idDepartement, true); 
			_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp.onreadystatechange = function() 
			{ 	
				if(_xmlHttp.readyState == 4 && _xmlHttp.status == 200) 
				{	
					var rsAjax = eval("(" + _xmlHttp.responseText + ")");			
					document.getElementById("libelleRegion").innerHTML = rsAjax.liste[0].libelle;
				} 
			}
			_xmlHttp.send(null) 
		}
	}	
} 

/************************************************************************
 * Function	: loadCategorieTheme 
 *			  Recuperer la liste des themes d'une categorie
 ************************************************************************/
function loadCategorieTheme(idCategorie, idTheme)
{ 	
	if(idPays != -1)
	{
		var _xmlHttp = getXMLHTTP(); 

		if(_xmlHttp)
		{ 	
			_xmlHttp.open("GET", "ajax.annuaire.categorie.theme.php?id=" + idCategorie, true); 
			_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp.onreadystatechange = function() 
			{ 	
				if(_xmlHttp.readyState == 4 && _xmlHttp.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp.responseText + ")");
				
					document.forms[0].idRubrique.options.length = rsAjax.liste.length + 1;						
					document.forms[0].idRubrique.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{
						if(idTheme == rsAjax.liste[i].id) document.forms[0].idRubrique.options.selectedIndex = (i+1);
						document.forms[0].idRubrique.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idRubrique.options[i+1].text = rsAjax.liste[i].libelle;
					}				
				} 
			}
			_xmlHttp.send(null) 
		}
	}
} 

/************************************************************************
 * Function	: loadModele 
 *			  Recuperer la liste des modèles d'une marque
 ************************************************************************/
function loadModele(idMarque, idModele)
{ 	
	if(idMarque != -1)
	{
		var _xmlHttp = getXMLHTTP(); 

		if(_xmlHttp)
		{ 	
			_xmlHttp.open("GET", "/backoffice/ajax.marque.modele.php?id=" + idMarque, true); 
			_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp.onreadystatechange = function() 
			{ 	
				if(_xmlHttp.readyState == 4 && _xmlHttp.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp.responseText + ")");
				
					document.forms[0].idModele.options.length = rsAjax.liste.length + 1;
					document.forms[0].idModele.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{						
						if(idModele == rsAjax.liste[i].id) document.forms[0].idModele.options.selectedIndex = (i+1);
						document.forms[0].idModele.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idModele.options[i+1].text = rsAjax.liste[i].libelle;
					}	
					
					if(document.forms[0].idCote && (idModele == null))
					{
						document.forms[0].idCote.options.length = 1;
					}
				} 
			}
			_xmlHttp.send(null) 
		}
	}
} 


/************************************************************************
 * Function	: loadModele 
 * Version 2
 ************************************************************************/
function notifier(flag, processingName) 
{	

	// wait indicator
	var e = document.getElementById(processingName);

	// use relative path only...
	var waiting =  '<img src="/backoffice/img/indicator.gif" border="0" alt="processing"/>';

	var done = '&nbsp;';
	e.innerHTML = (flag) ? waiting : done;
}

function populateModele(rs)
{
	//var rubElt = new form_select(document.getElementById('id_marque'));
	var srubElt = new form_select(document.getElementById('idModele'));
	srubElt.def_option = {'-1' : 'Sélectionnez un modèle'};

	srubElt.reset();
	srubElt.populate(rs);
	srubElt.disable(false);

	notifier(false, "processingModele");
}

function loadModele_V2(idMarque, idModele)
{ 
	var ao = new AjaxObject();
	ao.setCallback('populateModele', 'text');  // passe la fonction comme chaine !
	ao.sndReq('POST', BASEURL + 'backoffice/ajax.marque.modele.2.php', {"id":idMarque});

	notifier(true, "processingModele");
} 

function selectedElement(idMarque, selectName, selectedValue)
{
	loadModele_V2(idMarque, "");
	var currentSelect = document.getElementById(selectName);
	for(var i = 0; i<currentSelect.options.length; i++)
	{
		if(selectedValue == currentSelect.options[i].value)
		{
			currentSelect.options[i].selected = true;
		}
	}	
}


/************************************************************************
 * Function	: loadModeleAndCote 
 *			  Recuperer la liste des modèles et des cotes d'une marque
 ************************************************************************/
function loadModeleAndCote(idMarque, idModele, idCote)
{ 	
	if(idMarque != -1)
	{
		var _xmlHttp = getXMLHTTP(); 
		var _xmlHttp2 = getXMLHTTP(); 

		if(_xmlHttp)
		{ 	
			_xmlHttp.open("GET", "/backoffice/ajax.marque.modele.php?id=" + idMarque, true); 
			_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp.onreadystatechange = function() 
			{ 	
				if(_xmlHttp.readyState == 4 && _xmlHttp.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp.responseText + ")");
				
					document.forms[0].idModele.options.length = rsAjax.liste.length + 1;
					document.forms[0].idModele.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{						
						if(idModele == rsAjax.liste[i].id) document.forms[0].idModele.options.selectedIndex = (i+1);
						document.forms[0].idModele.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idModele.options[i+1].text = rsAjax.liste[i].libelle;
					}						
				} 
			}
			_xmlHttp.send(null); 
		}

		if(_xmlHttp2)
		{ 	
			_xmlHttp2.open("GET", "/backoffice/ajax.marque.cote.php?id=" + idMarque, true); 
			_xmlHttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp2.onreadystatechange = function() 
			{ 	
				if(_xmlHttp2.readyState == 4 && _xmlHttp2.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp2.responseText + ")");
				
					document.forms[0].idCote.options.length = rsAjax.liste.length + 1;
					document.forms[0].idCote.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{						
						if(idCote == rsAjax.liste[i].id) document.forms[0].idCote.options.selectedIndex = (i+1);
						document.forms[0].idCote.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idCote.options[i+1].text = rsAjax.liste[i].libelle;
					}						
				} 
			}
			_xmlHttp2.send(null); 
		}
	}
}

function loadCoteByMarque(idMarque)
{
	if(idMarque != -1)
	{
		var _xmlHttp2 = getXMLHTTP(); 
		if(_xmlHttp2)
		{ 	
			_xmlHttp2.open("GET", "/backoffice/ajax.marque.cote.php?id=" + idMarque, true); 
			_xmlHttp2.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp2.onreadystatechange = function() 
			{ 	
				if(_xmlHttp2.readyState == 4 && _xmlHttp2.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp2.responseText + ")");
				
					document.forms[0].idCote.options.length = rsAjax.liste.length + 1;
					document.forms[0].idCote.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{						
						if(idCote == rsAjax.liste[i].id) document.forms[0].idCote.options.selectedIndex = (i+1);
						document.forms[0].idCote.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idCote.options[i+1].text = rsAjax.liste[i].libelle;
					}						
				} 
			}
			_xmlHttp2.send(null);
		}
	}
}


/***** Version 2 de loadModeleAndCote *******/
function populateCote(rs)
{
	var srubElt = new form_select(document.getElementById('idCote'));
	srubElt.def_option = {'-1' : 'Cote'};

	srubElt.reset();
	srubElt.populate(rs);
	srubElt.disable(false);

	notifier(false, "processingCote");
}

function loadModeleAndCote_V2(idMarque, idModele, idCote)
{ 
/*	var bo = new AjaxObject();
	bo.setCallback('populateCote', 'text');  // passe la fonction comme chaine !
	bo.sndReq('POST', BASEURL + 'backoffice/ajax.marque.cote.2.php', {"id":idMarque});
*/
	loadCoteByMarque(idMarque);
	loadModele_V2(idMarque, idModele);
}

function loadCote_V2(idMarque)
{ 
	var bo = new AjaxObject();
	bo.setCallback('populateCote', 'text');  // passe la fonction comme chaine !
	bo.sndReq('POST', BASEURL + 'backoffice/ajax.marque.cote.2.php', {"id":idMarque});

	notifier(true, "processingCote");
}

/************************************************************************
 * Function	: loadCote
 *			  Recuperer la liste des cotes d'un modele
 ************************************************************************/
function loadCote(idModele, idCote)
{ 	
	if(idModele != -1)
	{
		var _xmlHttp = getXMLHTTP(); 

		if(_xmlHttp)
		{ 	
			_xmlHttp.open("GET", "/backoffice/ajax.modele.cote.php?id=" + idModele, true); 
			_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp.onreadystatechange = function() 
			{ 	
				if(_xmlHttp.readyState == 4 && _xmlHttp.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp.responseText + ")");
				
					document.forms[0].idCote.options.length = rsAjax.liste.length + 1;
					document.forms[0].idCote.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{
						if(idCote == rsAjax.liste[i].id) document.forms[0].idCote.options.selectedIndex = (i+1);
						document.forms[0].idCote.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idCote.options[i+1].text = rsAjax.liste[i].libelle;
					}	
				} 
			}
			_xmlHttp.send(null) 
		}
	}
} 

/************************************************************************
 * Function	: loadVaeType(idVae, idType)
 *			  Recuperer la liste des themes d'une categorie d'annonce
 ************************************************************************/
function loadVaeType(idVae, idType)
{ 	
	if(idVae != -1)
	{
		var _xmlHttp = getXMLHTTP(); 

		if(_xmlHttp)
		{ 	
			_xmlHttp.open("GET", "/backoffice/ajax.annonce.categorie.theme.php?id=" + idVae, true); 
			_xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
			_xmlHttp.onreadystatechange = function() 
			{ 	
				if(_xmlHttp.readyState == 4 && _xmlHttp.status == 200) 
				{		
					var rsAjax = eval("(" + _xmlHttp.responseText + ")");
				
					document.forms[0].idType.options.length = rsAjax.liste.length + 1;
					document.forms[0].idType.options.selectedIndex = 0;

					for(var i = 0; i<rsAjax.liste.length; i++)
					{
						if(idType == rsAjax.liste[i].id) document.forms[0].idType.options.selectedIndex = (i+1);
						document.forms[0].idType.options[i+1].value = rsAjax.liste[i].id;
						document.forms[0].idType.options[i+1].text = rsAjax.liste[i].libelle;
					}	
				} 
			}
			_xmlHttp.send(null) 
		}
	}
} 
/******* Version 2 loadVaeType_v2  ********/
function populateType(rs)
{
	//var rubElt = new form_select(document.getElementById('id_marque'));
	var srubElt = new form_select(document.getElementById('idType'));
	srubElt.def_option = {'-1' : 'Selectionnez un type'};

	srubElt.reset();
	srubElt.populate(rs);
	srubElt.disable(false);

	notifier(false, "processingType");
}
function loadVaeType_V2(idVae, idType)
{ 
	var ao = new AjaxObject();
	ao.setCallback('populateType', 'text');  // passe la fonction comme chaine !
	ao.sndReq('POST', BASEURL + 'backoffice/ajax.annonce.categorie.theme.2.php', {"id":idVae});

	notifier(true, "processingType");
}




function changePhoto(currentPhotoImg)
{
	if(ns4)
	{
		document.forms[0].elements["currentPhoto"].src = currentPhotoImg;
	}
	else if(ns6)
	{		
		document.getElementById("currentPhoto").src = currentPhotoImg;
	}
	else if(ie4)
	{		
		document.forms[0].elements["currentPhoto"].src = currentPhotoImg;
	}
}

function checkMaxLength(elt,maxlength) {

 	var old=elt.currentLength;
	
   elt.currentLength=elt.value.length;
   if(elt.currentLength > maxlength ) {
     //alert('Too much data in the text box!');
	 elt.value = elt.value.substring(0, maxlength)
	 elt.style.border='2px solid red';
 
   } else {
   	elt.style.border='1px solid #cccccc';
   }
  }
  
function montre(id) {

var d = document.getElementById(id);

if (d.style.display=='none')	d.style.display='block';
else	d.style.display='none';
	
}