// On definit que le server n'a aucune requette en cours;
var isWorking = false;
var photos = new Array();
var idannonces = new Array()
// On creé l'object Http;
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(); // We create the HTTP Object

// Fonction principal ouvrant la cgi sur le serveur et appelant handleHttpResponse();
function selectCo(url,handler){
	if(!isWorking && http){
		http.open("GET", url, true);
		http.onreadystatechange = handler;
		isWorking = true;
  		http.send(null);
	}
}

//Mise a jour des compteurs Co et New;
function handlerCo(){
	var tab = new Array();
	if (http.readyState == 4) {
		if (http.responseText.indexOf('invalid') == -1){
			result = http.responseText;
			handlerResult(result);
			isWorking = false;
		}
  	}
}

//Selection des coups de coeur;
function handlerResult(tab){
	var tmp  = tab.split("-");
	photos = tmp[0].split(" ");
	idannonces = tmp[1].split(" ");
	for(var i=0;i<4;i++){
		var img = document.getElementById('photo'+i);
		//img.src='/_img/commun/espaceur.gif';
		if(photos[i]){
			img.src = photos[i];
		}
	}
}

function CO_swapImage(indice){
	var img = document.getElementById('photo'+indice);
	img.src = '/images/index/photo1.jpg';
}
function CO_swapImageRestore(indice){
	var img = document.getElementById('photo'+indice);
	if(photos[indice]){
		img.src = photos[indice];
	}else{
		img.src='/_img/commun/espaceur.gif';
	}
}
function ficheDetaillee(indice){
	if(idannonces[indice]){
		var url = '/cgi-bin/annonces/fiche_detaillee.cgi?num=' + idannonces[indice];
		/* window.open(url,'FICHE','width=600,height=600,scrollbars=yes,status=no,menubar=no'); */
		window.location.replace(url);
	}else{
		return;
	}
}