﻿tabDealers = new Array();
tabDealers[0] = "";
tabDealers[1] = "";
tabDealers[2] = "";
tabDealers[3] = "";
tabDealers[4] = "";

tabDealersR = new Array();
tabDealersR[0] = "";
tabDealersR[1] = "";
tabDealersR[2] = "";
tabDealersR[3] = "";
tabDealersR[4] = "";

tabIntitNiveaux = new Array();
tabIntitNiveaux[0] = "pays_";
tabIntitNiveaux[1] = "regi_";
tabIntitNiveaux[2] = "vill_";
tabIntitNiveaux[3] = "stor_";
tabIntitNiveaux[4] = "adre_";

tabIntitBdd = new Array();
tabIntitBdd[0] = "Country";
tabIntitBdd[1] = "Code_for_selection";
tabIntitBdd[2] = "City";
tabIntitBdd[3] = "Shop_name";
tabIntitBdd[4] = "Dealer_address,Zip,City,Code_for_selection,Phone,Fax,email,Website";

function createXMLHttp() {
	if (typeof XMLHttpRequest != "undefined") return new XMLHttpRequest();
	var xhrVersion = [ "MSXML2.XMLHttp.5.0", "MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","Microsoft.XMLHttp" ];
	for (var i = 0; i < xhrVersion.length; i++) { try { var xhrObj = new ActiveXObject(xhrVersion[i]); return xhrObj; }
	catch (e) { } } return null;
}

//colore le bouton sélectionné
function selectBtn(id,niveau,myrsys,idr){
window.status=idr;
	document.getElementById(idr).className= "dealers_item_isselect";
	if (tabDealersR[niveau]!=""){
		document.getElementById(tabIntitNiveaux[niveau]+tabDealersR[niveau]).className= "dealers_item";
	}
	var iLen = String(id).length;
  var newItem = String(id).substring(5, iLen);
	tabDealers[niveau] = newItem;
	iLen = String(idr).length;
  newItem = String(idr).substring(5, iLen);
	tabDealersR[niveau] = newItem;
	majColonnes(niveau,myrsys);
}
//vide les colonnes de niveau supérieur
function majColonnes(niveau,myrsys){
	for (i=niveau+1;i<5;i++){
		//alert (document.getElementById(tabIntitNiveaux[i]+"cl").innerHTML);
		document.getElementById(tabIntitNiveaux[i]+"cl").innerHTML="";
		tabDealers[i]="";
		tabDealersR[i]="";
	}
	majNiveauSuperieur(niveau,myrsys);
}

//affiche le contenu du niveau supérieur
function majNiveauSuperieur(niveau,myrsys){
	if (niveau<2){
		var myrequete = "SELECT DISTINCT("+tabIntitBdd[niveau+1]+") cols_item FROM shopFinder WHERE Country = '"+tabDealers[0] +"'";
	}
	else{
		var myrequete = "SELECT "+tabIntitBdd[niveau+1]+",isNull(rsys_test,0) rsys_test FROM shopFinder WHERE Country = '"+tabDealers[0]+"'";
	}
	if (niveau>0){
		myrequete = myrequete + " AND Code_for_selection='"+tabDealers[1].replace("'","''")+"'";
	}
	if (niveau>1){
		myrequete = myrequete + " AND City='"+tabDealers[2].replace("'","''")+"'";
	}
	if (niveau>2){
		myrequete = myrequete + " AND Shop_name='"+tabDealers[3].replace("'","''")+"'";
	}
	if (myrsys!=""){ 
    //myrequete = myrequete + " AND rsys_test="+myrsys;
    myrequete = myrequete + " AND "+myrsys + " = 1";
  }
	if (niveau<3){
		myrequete = myrequete + " ORDER BY "+tabIntitBdd[niveau+1];
	}
	var req = new createXMLHttp();
	req.open('POST', "/activity/shopfinder_cl.aspx" , true);
	req.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
	myrequete = myrequete.replace(/&/,"andandand");
	
//alert(myrequete );

	var data = "myIntitNiveau="+tabIntitNiveaux[niveau+1]+"&myniveau="+niveau+"&myrsys="+myrsys+"&myrequete="+escape(tabDealersR.join(","),true); //myrequete;
	req.send(data);
	if (req){
		req.onreadystatechange=function(){
			if (req.readyState == 4)  {//4 : état "complete" 
	if (req.status==500)alert (req.responseText);
				if (req.status == 200)  {// 200 : code HTTP pour OK 
	//if (niveau>2)alert (data);
					var liste = req.responseText;
					document.getElementById(tabIntitNiveaux[niveau+1]+"cl").innerHTML = liste;
				}
			}
		}
	}	
}
function initFilters()
{
	//Si la varaible de sélection de la coche existe
	if(filterSelectione)
	{
		//Alors en fonction de sa valeur
		switch(filterSelectione)
		{
			case "rsys_test":
				//On stocke la cible 
				var cible = document.getElementById("rsysCoche");
			break;
			case "riders_equipment":
				var cible = document.getElementById("ridersCoche");
			break;
			case "mp3":
				var cible = document.getElementById("mp3Coche");
			break;
			case "expert_plus":
				var cible = document.getElementById("expertCoche");
			break;
			case "maviclab":
				var cible = document.getElementById("maviclabCoche");
			break;
			case "all":
				var cible = document.getElementById("allCoche");
			break;
		}
		
		//On parametre du coup son background position
		cible.style.backgroundPosition = "0 -10px";
	}
}
