var isWorking = false;        // est-ce que le canal est occupé
var currentObj = null;
var cX0,cY0,il0,it0;

function getHTTPObject() {
  var xmlhttp;
  /*@cc_on
@if (@_jscript_version >= 5)
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) { xmlhttp = false; }
}
@else
xmlhttp = false;
@end @*/
  if (!xmlhttp && typeof XMLHttpRequest != 'undefined') {
    try {
      xmlhttp = new XMLHttpRequest();
      } catch (e) {
      xmlhttp = false;
      }
  }
  return xmlhttp;
}

var http = getHTTPObject();

function _remote(serveur, esclave) {
	if (!isWorking && http) {
		http.open("GET", serveur, true);
		http.onreadystatechange = esclave;
		isWorking = true;
		http.send(null);
	}
}

// Résultat de recherche de motos
function remote_motos_liste(type, marque,categorie, direction) {
	if (direction != 0) direction = '&direction=' + direction;
	else direction = '';
	_remote("/include/remote.php?fonc=remote_motos_liste&type=" + type + "&marque=" + escape(marque) + '&categorie=' + categorie + direction, _remote_motos_liste);
}

function _remote_motos_liste() {
	if (http.readyState == 4) {
		if (http.responseText != '')
			document.getElementById('DIVcontenu').innerHTML = http.responseText;
		else
			document.getElementById('DIVcontenu').innerHTML = "<span class=texte12Bblanc>Il n'y a pas de produit pour cette recherche.</span>";
		isWorking = false;
	}
}

// Fiche d'une moto
function remote_motos_fiche(valeur) {
	_remote("/include/remote.php?fonc=remote_motos_fiche&id=" + valeur, _remote_motos_fiche);
}

function _remote_motos_fiche() {
	document.getElementById('DIV_produit_photo').src = "/images/no_photo-s.jpg";

if (http.readyState == 4) {
		if (http.responseText != '') {
			contenu = http.responseText.split("|");
			document.getElementById('DIV_produit_nom').innerHTML = contenu[0];
			document.getElementById('DIV_produit_photo').src = contenu[1];
			document.getElementById('DIV_data').innerHTML = contenu[2];
/*
			document.getElementById('DIV_produit_moteur').innerHTML = contenu[0];
			document.getElementById('DIV_produit_transmission').innerHTML = contenu[1];
			document.getElementById('DIV_produit_poids').innerHTML = contenu[2];
			document.getElementById('DIV_produit_hauteur_siege').innerHTML = contenu[3];
			document.getElementById('DIV_produit_reservoir').innerHTML = contenu[4];
			document.getElementById('DIV_produit_couleur').innerHTML = contenu[5];
			document.getElementById('DIV_produit_montant').innerHTML = contenu[6];
			document.getElementById('DIV_description').innerHTML = '<br />' + contenu[9] + '<br />';
*/
			document.getElementById('DIVrecherche').style.display = 'none';
			document.getElementById('DIVfiche').style.display = 'block';
		}
		isWorking = false;
	}
}


///////////////////////////////////////////////
// Fonctions et classes
function remplacer(source,varIN,varOUT) {
	retour = '';
	for (i=0; i < source.length; i++) {
		s = source.substr(i,1);
		if (s == varIN) retour += varOUT;
		else retour += s;
	}
	
	return retour;
}

function number_format(valeur) {
	result = Math.floor(valeur) + ".";
	cents = 100*(valeur-Math.floor(valeur))+0.5;
	result += Math.floor(cents/10);
	result += Math.floor(cents%10);
	return result;
}
