var check_delay = 200;
var tab_req     = new Array();
var file        = "recherche_ajax.php";
var max_req     = 1;
var max_var     = 3


function listeTypes(collectionid, titrecollection, titreprix) {
	max_req = 1;
	
	for(var i=0; i<max_req; ++i) {
		tab_req[i] = new CreateXMLHTTPRequestObject();
		tab_req[i].setAsynchronous();
		
		document.recindex.collection.length=0;
		document.recindex.collection.options[0] = new Option(titrecollection,"");				
		document.recindex.tranche.length=0;
		document.recindex.tranche.options[0] = new Option(titreprix,"");				
		if (collectionid > 0) {
			// Transmission des données
			data = "";
			data += 'collectionid='+collectionid;
	
			if(!tab_req[i].getFileGet(file, data)) return;
			setTimeout("afficheTypes()", check_delay);
			}
		}
	}


function afficheTypes() {
	for(var i=0; i<max_req; ++i) {
		if(tab_req[i] && tab_req[i].hasResponse()) {
			var rep = tab_req[i].getResponse();

			var nbOptions = 0 ;
			newOptions = rep.split('|||');
			for (var j = 0 ; j < newOptions.length-1 ; ++j) {
				nbOptions++ ;
				explodeOption = newOptions[j].split('**');
				document.recindex.collection.options[nbOptions] = new Option(explodeOption[1],explodeOption[0]);				
				}
			
			
			tab_req[i].validateRequest();
			tab_req.splice(i, 1);
			}
		}
		if(tab_req.length > 0) setTimeout("afficheTypes()", check_delay);
	}


function listePrix(typeid, titreprix) {
	max_req = 1;
	
	for(var i=0; i<max_req; ++i) {
		tab_req[i] = new CreateXMLHTTPRequestObject();
		tab_req[i].setAsynchronous();
		
		
		document.recindex.tranche.length=0;
		document.recindex.tranche.options[0] = new Option(titreprix,"");				
		if (typeid > 0) {
			// Transmission des données
			data = "";
			data += 'typeid='+typeid;
	
			if(!tab_req[i].getFileGet(file, data)) return;
			setTimeout("affichePrix()", check_delay);
			}
		}
	}


function affichePrix() {
	for(var i=0; i<max_req; ++i) {
		if(tab_req[i] && tab_req[i].hasResponse()) {
			var rep = tab_req[i].getResponse();

			var nbOptions = 0 ;
			newOptions = rep.split('|||');
			for (var j = 0 ; j < newOptions.length-1 ; ++j) {
				nbOptions++ ;
				explodeOption = newOptions[j].split('**');
				
				var reg=new RegExp("(&euro;)", "g");
				explodeOption[1]  = explodeOption[1].replace(reg,"€");

				document.recindex.tranche.options[nbOptions] = new Option(explodeOption[1],explodeOption[0]);				
				}
			tab_req[i].validateRequest();
			tab_req.splice(i, 1);
			}
		}
		if(tab_req.length > 0) setTimeout("affichePrix()", check_delay);
	}

function addToDiv(txt) {
	document.getElementById("dData").innerHTML = txt;
}

function changeSrc(txt) {
	var ibig = document.getElementById("big") ;
	if (ibig)
		ibig.src = txt;
	//document.getElementById("dData").scrollTop = document.getElementById("dData").scrollHeight;
}

function toggleCode(b, d) {
    if(b.value == "montrer") {
        b.value = "masquer";
        document.getElementById(d).style.display = "block";
    }
    else {
        b.value = "montrer";
        document.getElementById(d).style.display = "none";
    }
}



// onClick="Javascript: valideRecherche();"
function valideRecherche() {
	if (document.getElementById('type').options[document.getElementById('type').selectedIndex].value != "" && document.getElementById('type').options[document.getElementById('type').selectedIndex].value != "Types de produits" && document.getElementById('prix').options[document.getElementById('prix').selectedIndex].value != "Prix" && document.getElementById('prix').options[document.getElementById('prix').selectedIndex].value != "")
		document.recherche.submit() ;
	else
		alert('Vous devez sélectionner un type de produit et une tranche de prix.');
	}
