/*****************************************************************************/
/*                                  Core                                     */
/*****************************************************************************/

var hSocks 		= new Array();			//handle du socket, ok je sais c'est pas un socket, mais m'en fout, l'habitude...
var LastLink 	= "";								//Derrnier lien ajax cliqué (pour rafrechire la page au bon endroit)
var LastCall	= new Array();			//Derrnière fonction ajax appelée, pour le bouton back
var CurrCall	= "RefreshPage('shop.html')";	//Page en cour;
var LastIdl		= "";								//Derrnière liste déroulée
var LastIdsl	= "";								//Derrnière sous-liste déroulée
var LastIdslr	= "";								//Derrnière sous-liste déroulée
var LastName	= "";								//Derrnier titre de page
var LastSt		= "";								//Derrnier start								
var LastM			= "";								//Derrnier m
var LastSort	= "";								//Derrnier tri
var LastFunc	= "";								//Derrnière fonction
var MaxTitle	= 27;								//Longueur max du titre
var Follow		= false;						//Suivre le scroll
var x 				= 0;								//Position
var x 				= 0;								//Position
var y 				= 0;
var posx 			= 0;								//Position de la souris
var posy 			= 0;

//Rafraichi la page entière
function RefreshPage(url)
{
	if(url)
		window.location.href = url;
	else if(LastLink)
		window.location.href = LastLink;
	else
		window.location.href = window.location.href;
}

//Page précédente
function Back()
{
	BackCall = LastCall.pop();
	eval(BackCall);
	CurrCall = BackCall;
	//DebugTable(LastCall);
}

//Ajoute le derrnier lien à la liste
function PushLastCall(ThisCall)
{
	LastCall.push(CurrCall);
	CurrCall = ThisCall;
	//DebugTable(LastCall);
}

/*function DebugTable(table)
{
	var debstr = "";
	var i = 0;
	for(i=0;i<table.length;i++)
		debstr = debstr+"["+i+"] -> "+table[i]+"\n";

	alert(debstr);
}*/

//Fonction de traitement des evenements
function Events(id)
{
  //Statu du socket
	switch(hSocks[id].hSock.readyState)
	{
		case 0: //0	Non initialisé
			if(!hSocks[id].Silent&&hSocks[id].Box)
				hSocks[id].Box.innerHTML = "Initialisation...";
		break;
		case 1: //1	Début du transfert
			if(!hSocks[id].Silent&&hSocks[id].Box)
				hSocks[id].Box.innerHTML = "Envoi de la requête...";
		break;
		case 2: //2	Données transférées
			if(!hSocks[id].Silent&&hSocks[id].Box)
				hSocks[id].Box.innerHTML = "Requête envoyée.";
		break;
		case 3: //3	Données accessibles en partie
			if(!hSocks[id].Silent&&hSocks[id].Box)
				hSocks[id].Box.innerHTML = "Reception des données...";
		break;
		case 4: //4	Données accessibles
		  //Code HTTP renvoié
		  switch(hSocks[id].hSock.status)
		  {
		    case 200:	//HTTP 200 OK
		    	//alert(hSock.responseText);
		    	if(hSocks[id].Box)
						hSocks[id].Box.innerHTML = hSocks[id].hSock.responseText;
					if(hSocks[id].CallAfter)
						setTimeout(hSocks[id].CallAfter, 100);
					//Relance l'init pour les liens
					ajaxInit();
		    break;
		    case 503:	//HTTP 503 Service Temporarily Unavailable
		    	if(hSocks[id].Box)
						hSocks[id].Box.innerHTML = "HTTP 503 Service Temporarily Unavailable<BR><BR>Rechargement dans 5 sec...";
					setTimeout(hSocks[id].CallBack, 5000);
		    break;
		    case 404:	//HTTP 404 Not Found
		    	if(hSocks[id].Box)
						hSocks[id].Box.innerHTML = "HTTP 404 Not Found<BR><BR>La page n'existe pas, erreur irrecupérable.";
		    break;
		    default:  //Autre, on affiche l'erreur et on laisse le user se demerder, faut pas deconner non plus...
		    	if(hSocks[id].Box)
						hSocks[id].Box.innerHTML = "Erreur inconnue.<BR>Réponse du serveur:<BR><BR>"+hSock.responseText;
		    break;
			}
			hSocks[id].free = true;
		break;
	}
}

function Socket(id)
{
	this.free = true;
	this.CallBack = "";
	this.Dest = "";
	this.Box = "";
	this.Slient = false;
	this.CallAfter = "";

	if(window.XMLHttpRequest) //Firefox, simple, efficace, tellement bon...
		this.hSock = new XMLHttpRequest(); 
	else if(window.ActiveXObject) //Internet Explorer, jamais comme les autres...
		this.hSock = new ActiveXObject("Microsoft.XMLHTTP"); 
	else //XMLHttpRequest non supporté par le navigateur (Links powaaaa!)
		alert("Votre navigateur ne supporte pas les objets XMLHTTPRequest...");

	if(this.hSock.overrideMimeType) //Un fix pour safari (saleté de mac, peuvent pas utiliser Firefox comme tout le monde?)
     this.hSock.overrideMimeType("text/xml");  //Mais oui Aline, je t'aime quand même ;)

	this.hSock.onreadystatechange = function()
	{
		Events(id);
	}
}

//Initialisation
function InitSock(CallBack, Dest, Silent, CallAfter)
{
	Box = document.getElementById(Dest);

	var id = 0;

	while(id<hSocks.length)
	{
		if(hSocks[id])
		{
			if(!hSocks[id].free)
				id++;
			else
				break;
		}
		else
		{
			break;
		}
	}

	hSocks[id] = new Socket(id);

	hSocks[id].free = false;
	hSocks[id].CallBack = CallBack;
	hSocks[id].Dest = Dest;
	if(Box)
		hSocks[id].Box = Box;
	else
		hSocks[id].Box = false;
	hSocks[id].Silent = Silent;
	hSocks[id].CallAfter = CallAfter;

	return hSocks[id].hSock;
}


/*****************************************************************************/
/*                                  Help                                     */
/*****************************************************************************/
// getPageScroll()
// Returns array with x,y page scroll values.
// Core code from - quirksmode.org

function getPageScroll()
{
	var yScroll;

	if(self.pageYOffset)
		yScroll = self.pageYOffset;
	else if(document.documentElement && document.documentElement.scrollTop)	 // Explorer 6 Strict
		yScroll = document.documentElement.scrollTop;
	else if(document.body)// all other Explorers
		yScroll = document.body.scrollTop;

	arrayPageScroll = new Array('',yScroll) 
	return arrayPageScroll;
}

// getPageSize()
// Returns array with page width, height and window width, height
// Core code from - quirksmode.org
// Edit for Firefox by pHaez

function getPageSize()
{
	var xScroll, yScroll;

	if(window.innerHeight && window.scrollMaxY)
	{	
		xScroll = document.body.scrollWidth;
		yScroll = window.innerHeight + window.scrollMaxY;
	}
	else if(document.body.scrollHeight > document.body.offsetHeight)
	{ // all but Explorer Mac
		xScroll = document.body.scrollWidth;
		yScroll = document.body.scrollHeight;
	}
	else
	{ // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
		xScroll = document.body.offsetWidth;
		yScroll = document.body.offsetHeight;
	}

	var windowWidth, windowHeight;

	if(self.innerHeight)
	{	// all except Explorer
		windowWidth = self.innerWidth;
		windowHeight = self.innerHeight;
	}
	else if(document.documentElement && document.documentElement.clientHeight)
	{ // Explorer 6 Strict Mode
		windowWidth = document.documentElement.clientWidth;
		windowHeight = document.documentElement.clientHeight;
	}
	else if(document.body)
	{ // other Explorers
		windowWidth = document.body.clientWidth;
		windowHeight = document.body.clientHeight;
	}	

	// for small pages with total height less then height of the viewport
	if(yScroll < windowHeight)
		pageHeight = windowHeight;
	else
		pageHeight = yScroll;

	// for small pages with total width less then width of the viewport
	if(xScroll < windowWidth)
		pageWidth = windowWidth;
	else
		pageWidth = xScroll;

	arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight) 
	return arrayPageSize;
}

//Mouvement de la souri
function mouseMove(evt)
{
  var scrolltop  = 0;
	var scrollleft = 0;

  if(document.layers)
  {
    x = evt.x;
		y = evt.y;
  }

  if(document.all)
  {
    x = event.clientX;
		y = event.clientY;
	}
	else
	{
    if(document.getElementById)
    {
      x = evt.clientX;
			y = evt.clientY;
		}
	}

  if(document.documentElement && document.documentElement.scrollTop)
  {
    scrolltop = document.documentElement.scrollTop;
    scrollleft = document.documentElement.scrollLeft;
  }
  else if(document.body)
  {
    scrolltop = document.body.scrollTop;
    scrollleft = document.body.scrollLeft;
  }

  posx = scrollleft + x;
  posy = scrolltop + y;
}

/*****************************************************************************/
/*                                ajaxInit                                   */
/*****************************************************************************/

//Les liens devienent javascript mais gardent leur url
function ajaxInit()
{
	//Liens ajax normaux (retour sur la page activé)
	links = document.getElementsByName("ajaxLink");
	for(i=0;i<links.length;i++)
	//{
		links[i].onclick = function()
		{
			eval(this.title);
			LastLink = this.href;	//Change le lien après l'action, sinon on fait capoter les redirections
			PushLastCall(this.title);
			return false;
		};
		/*links[i].name = "ajaxLinkOk"; //évite de traiter deux fois le lien
	}*/

	//Liens ajax sans retour (login, logout, signin, etc...)
	links = document.getElementsByName("ajaxLinkNoBack");
	for(i=0;i<links.length;i++)
	//{
		links[i].onclick = function()
		{
			eval(this.title);
			return false;
		};
		/*links[i].name = "ajaxLinkNoBackOk"; //évite de traiter deux fois le lien
	}*/

	//Liens ajax pour mail (formulaire de contact)
	links = document.getElementsByName("ajaxMailTo");
	for(i=0;i<links.length;i++)
		links[i].onclick = function()
		{
			eval("PrintContactForm('"+this.title+"');");
			return false;
		};

	//prépare le fond noir
	document.getElementById("overlay").onclick = function(){HideFloatBox();return false;}
}

/*****************************************************************************/
/*                                AjaxPost                                   */
/*****************************************************************************/

//Envoit la requête POST
function AjaxPost(Page, Vars, Dest, Silent, CallAfter)
{
	CallBack = 'AjaxPost("'+Page+'", "'+Vars+'", '+Dest+', '+Silent+', "'+CallAfter+'")';
	//Créer le socket
	hSock = InitSock(CallBack, Dest, Silent, CallAfter);

	//Prépare la requête de la page 
	hSock.open("POST", Page, true);
	//Définit les header HTTP  
	hSock.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
	//Envoie de la requete
	hSock.send(Vars);
}

/*****************************************************************************/
/*                                AjaxGet                                    */
/*****************************************************************************/

//Envoit la requête GET
function AjaxGET(Page, Dest, Silent, CallAfter)
{
	CallBack = 'AjaxGET("'+Page+'", "'+Dest+'", '+Silent+', "'+CallAfter+'")';

	if(Dest=="XMLData")
	{	//Force l'utilisation du conteneur XML en singleton
		while(document.getElementById("XMLDataState").value=="Used")
		{
			setTimeout(CallBack, 100);
			return 0;
		}
		document.getElementById("XMLDataState").value = "Used"
	}

	//Créer le socket
	hSock = InitSock(CallBack, Dest, Silent, CallAfter);

	//Prépare la requête de la page 
	hSock.open("GET", Page, true);
	//Envoie de la requete
	hSock.send(null);
}

/*****************************************************************************/
/*                                Fenêtres                                   */
/*****************************************************************************/

function ShowInfo()
{
	document.getElementById("InfoBulle").style.display = "block";
}

function HideInfo()
{
	document.getElementById("InfoBulle").style.display = "none";
}

function PlaceInfo()
{
	document.getElementById("InfoBulle").style.left = (posx+5)+'px';
	document.getElementById("InfoBulle").style.top = (posy+5)+'px';
}

//Affiche le fond noir
function ShowOverlay()
{
	var arrayPageSize = getPageSize();
	//Element.setHeight('overlay', arrayPageSize[1]);
	document.getElementById("overlay").style.height = arrayPageSize[1]+"px";
	document.getElementById("overlay").style.display = "block";
}

//Cache le fond noir
function HideOverlay()
{
	document.getElementById("overlay").style.display = "none";
}

//Affiche la fenêtre flottente
function ShowFloatBox(title, width, NoOverlay, GreyBg)
{
	if(title.length>MaxTitle)
		title = title.substr(0,MaxTitle-3)+"...";

	title = ".: "+title+" :.";

	if(!NoOverlay)	//Double négation powaaaa
		ShowOverlay();

	BFB = document.getElementById("FB");
	BFBTitle = document.getElementById("FBTitle");
	BFBContent = document.getElementById("FBContent");

	if(GreyBg)
		BFBContent.style.backgroundImage = "url(/images/grey.jpg)";
	else
		BFBContent.style.backgroundImage = "none";

	if(title)
		BFBTitle.innerHTML = "<B>"+title+"</B>";

	if(width)
		BFB.style.width = width+"px";

//Hauteur auto
/*	if(height)
		BFBContent.style.height = height+"px";*/

	BFB.style.display = "block";
}

//Masque la fenêtre flottente
function HideFloatBox()
{
	BFB = document.getElementById("FB");
	BFB.style.display = "none";

	HideOverlay();
	Follow = false;
}

//centre la fenêtre flottente
function CenterFloatBox(width, top, Follow)
{
  Follow = typeof(Follow) != 'undefined' ? Follow : false; //Arf... définition par défaut
	var arrayPageScroll = getPageScroll();

	BFB = document.getElementById("FB");

	if(!window.innerWidth)
		inW = document.body.offsetWidth;	//IE comme d'hab, pas capable...
	else
		inW = window.innerWidth;

	BFB.style.left = ((inW/2)-width)+"px";
	BFB.style.top = (top+arrayPageScroll[1])+"px";

	if(Follow)
		FollowScroll("BFB", top);
}

function FollowScroll(id, top)
{
	var arrayPageScroll = getPageScroll();
	document.getElementById(id).style.top = (top+arrayPageScroll[1])+"px";
	if(Follow)
		window.setTimeout("FollowScroll('"+id+"', "+top+")", 10);
}

//Affiche de gif de chargement
function DisplayAjaxLoader(dest)
{
	box = document.getElementById(dest);
	box.innerHTML = "<CENTER><IMG src=\"/images/ajax-loader.gif\" alt=\"loading\"></CENTER>";
}

//Longue barre de chargement
function DisplayAjaxLoaderBig(left, top)
{
	if(!window.innerWidth)
	{
		inW = document.body.offsetWidth;	//IE comme d'hab, pas capable de...
		inH = document.body.offsetHeight;
	}
	else
	{
		inW = window.innerWidth;
		inH = window.innerHeight;
	}
	left = ((inW/2)-110)-left;
	top = ((inH/2)-10)-top;

	Loader = document.getElementById("ajaxLoaderBig");
	Loader.style.left = left+"px";
	Loader.style.top = top+"px";
	Loader.style.display = "block";
}

function HideAjaxLoaderBig()
{
	Loader = document.getElementById("ajaxLoaderBig");
	Loader.style.display = "none";
}

//Affiche la fenêtre d'ajout du panier
function ShowAddBox()
{
	if(!window.innerWidth)
	{
		inW = document.body.offsetWidth;	//IE comme d'hab, pas capable de...
		inH = document.body.offsetHeight;
	}
	else
	{
		inW = window.innerWidth;
		inH = window.innerHeight;
	}

	ABox = document.getElementById("AddBox");
	ABox.style.left = ((inW/2)-200)+"px";
	ABox.style.top = ((inH/2)-150)+"px";
	ABox.style.display = "block";

	Follow = true;
	FollowScroll("AddBox", (inH/2)-150);
}

function ShowAddBoxSize()
{
	if(!window.innerWidth)
	{
		inW = document.body.offsetWidth;	//IE comme d'hab, pas capable de...
		inH = document.body.offsetHeight;
	}
	else
	{
		inW = window.innerWidth;
		inH = window.innerHeight;
	}

	ABox = document.getElementById("AddBox");
	ABox.style.left = ((inW/2)-200)+"px";
	ABox.style.top = ((inH/2)-250)+"px";
	ABox.style.display = "block";

	Follow = false;
}

//Cache la fenêtre d'ajout du panier
function HideAddBox()
{
	ABox = document.getElementById("AddBox");
	ABox.style.display = "none";
}

/*****************************************************************************/
/*                                Boutiques                                  */
/*****************************************************************************/

function GetBoutique(id)
{
	DisplayAjaxLoader("BoutiqueText");
	DisplayAjaxLoader("BoutiqueImg1");
	DisplayAjaxLoader("BoutiqueImg2");
	DisplayAjaxLoader("BoutiqueImg3");
	AjaxGET("ajax/boutiques.php?id="+id, "BoutiqueText", true);
	AjaxGET("ajax/boutiquestop.php?id="+id, "BoutiqueTitre", true);
	AjaxGET("ajax/boutiquesimg.php?id="+id+"&idimg=1", "BoutiqueImg1", true);
	AjaxGET("ajax/boutiquesimg.php?id="+id+"&idimg=2", "BoutiqueImg2", true);
	AjaxGET("ajax/boutiquesimg.php?id="+id+"&idimg=3", "BoutiqueImg3", true);
}

function GetImg(id, idimg)
{
	ShowFloatBox("Image");
	CenterFloatBox(300,100);
	DisplayAjaxLoader("FBContent");
	AjaxGET("ajax/boutiquesimg.php?id="+id+"&idimg="+idimg+"&big=1", "FBContent", true);
}

/*****************************************************************************/
/*                                  Shop                                     */
/*****************************************************************************/

function LoadList(list, id, c)
{
	AjaxGET("ajax/motolist.php?id="+id+"&c="+c, "XMLData", true, "FillList('"+list+"')");
}

function FillList(list)
{
	var objDom = new XMLDoc(document.getElementById("XMLData").value, xmlError);	
	var i = 0;

	while(objDom.docNode.getElements("ITEM")[i])
	{
		var ID = objDom.docNode.getElements("ITEM")[i].getElements("ID")[0].getText();
		var Texte = objDom.docNode.getElements("ITEM")[i].getElements("TEXTE")[0].getText();
		document.getElementById(list).options[i] = new Option(Texte, ID, false, false);
		i++;
	}
	document.getElementById("XMLDataState").value = "Free"

	if(list!="model")
		lstChange(list);
}

function ShowMotoDet(id)
{
	document.getElementById("motoDetCont").style.display = "block";
	DisplayAjaxLoader("motoDetCont");

	AjaxGET("ajax/moto.php?moto="+id, "motoDetCont");
}

function HideMotoDet()
{
	document.getElementById("motoDetCont").style.display = "none";
}

function LoadPiece(dest)
{
	DisplayAjaxLoader(dest);
	AjaxGET("content/pieces.php", dest, true, "InitPieces()");
}

function LoadPromo(dest)
{
	DisplayAjaxLoader(dest);
	AjaxGET("content/promobig.php", dest);
}

function LoadMoto(id, dest, st)
{
	DisplayAjaxLoader(dest);
	AjaxGET("ajax/artlist.php?moto="+id+"&start="+st, dest, true);

	ShowMotoDet(id);
}

function LoadCatList(id, dest)
{
	DisplayAjaxLoader(dest);
	AjaxGET("ajax/catlist.php?id="+id, dest, true);
}

function LoadArtList(id, dest, st, m, order, sort)
{
	DisplayAjaxLoader(dest);
	if((m!="moto")||(m!="search"))
	{
		idl = LastIdl.substr(1, LastIdl.length);
		idsl = LastIdsl.substr(2, LastIdsl.length);
	}

	if(m=="moto")
		link = "ajax/artlist.php?moto="+id+"&list=0&slist=0&name="+LastName;
	else if(m=="search")
		link = "ajax/search.php?word="+id+"&st="+st;
	else
		link = "ajax/artlist.php?id="+id+"&list="+idl+"&slist="+idsl+"&name="+LastName;

	if(order&&sort)
		link = link+"&order="+order+"&sort="+sort;

	if(st)
		link = link+"&start="+st;
	if(m&&m!="moto")
		link = link+"&marque="+m;

	AjaxGET(link, dest, true);
}

function PrintArt(id, name)
{
	ShowFloatBox(name,750);
	CenterFloatBox(400,40, false);
	DisplayAjaxLoader("FBContent");
	if(LastIdl)
		idl = LastIdl.substr(1, LastIdl.length);
	else
		idl = "0";
	if(LastIdsl)
		idsl = LastIdsl.substr(2, LastIdsl.length);
	else
		idsl = "0";

	AjaxGET("ajax/art.php?art="+id+"&list="+idl+"&slist="+idsl, "FBContent", true);
}

function LoadImg(id, dest)
{
	DisplayAjaxLoader(dest);
	AjaxGET("ajax/artimg.php?id="+id, dest, true);
}

function Sort(order)
{
	if(CurrCall.indexOf("RefreshPage")==0)
		return;

	if(CurrCall.indexOf("menuClick")==0)
		return;

	if(LastSort=="ASC")
		sort = "DESC";
	else
		sort = "ASC";

	func = LastFunc+"('"+LastIdslr+"', '"+LastName+"', '"+LastSt+"', '"+LastM+"', '"+order+"', '"+sort+"')";

	eval(func);
	PushLastCall(func);
}

/*****************************************************************************/
/*                              Shop Interne                                 */
/*****************************************************************************/

function imgClick(id)
{
	LoadImg(id, "artImgCont");
}

function artClick(id, name)
{
	PrintArt(id, name);
}

function menuClick(id, name)
{
	SetTitle(name);
	if(id=="moto")
	{
		LoadPiece("shopCont");
		HideLast("l");
	}
	else if(id=="promo")
	{
		LoadPromo("shopCont");
		HideLast("l");
	}
	else
	{
		switchlist(id, "l");
		LoadCatList(id, "shopCont");
	}
}

function smenuClick(id, name, st, m, order, sort)
{
	if(st)
		LastSt = st;
	if(m)
		LastM = m;
	if(sort)
		LastSort = sort;
		LastM='';
		LastSt='';

	LastFunc = "smenuClick";

	SetTitle(name);
	if(!m&&!st)
		switchlist(id, "sl");
	LoadArtList(id, "shopCont", st, m, order, sort);
}

function switchlist(id, pre)
{
	//Si la liste est déjà déroule, masque et quite
	if(document.getElementById(pre+id))
		if(document.getElementById(pre+id).style.display == "block")
			return;

	HideLast(pre);

	//Affiche la liste demandée
	if(pre=="l")
		LastIdl = pre+id;
	else
	{
		LastIdsl = pre+id;
		LastIdslr = id;
	}

	if(document.getElementById(pre+id))
		document.getElementById(pre+id).style.display = "block";
}

function HideLast(pre)
{
	if(pre=="l")
		if(LastIdl)
			if(document.getElementById(LastIdl))
				document.getElementById(LastIdl).style.display = "none";

	if(LastIdsl)
		if(document.getElementById(LastIdsl))
			document.getElementById(LastIdsl).style.display = "none";
}

function SetTitle(title)
{
	if(document.getElementById("shopTitle"))
		document.getElementById("shopTitle").innerHTML = ".: "+title+" :.";
	LastName = title;
}

//Affiche "chargement..." ...
function loading(id)
{
	if(!document.getElementById(id).options[0])	//IE... qui d'autre...
		document.getElementById(id).options[0] = new Option("", "", false, false);

	list = document.getElementById(id).options[0].text;

	switch(list)
	{
		case "Chargement":
			document.getElementById(id).options[0].text = "Chargement.";
			setTimeout("loading('"+id+"')",400);
		break;
		case "Chargement.":
			document.getElementById(id).options[0].text = "Chargement..";
			setTimeout("loading('"+id+"')",400);
		break;
		case "Chargement..":
			document.getElementById(id).options[0].text = "Chargement...";
			setTimeout("loading('"+id+"')",400);
		break;
		case "Chargement...":
			document.getElementById(id).options[0].text = "Chargement";
			setTimeout("loading('"+id+"')",400);
		break;
	}
}

function lstChange(list)
{
	idMarque = document.getElementById("marque").options[document.getElementById("marque").selectedIndex].value;
	idCylind = document.getElementById("cylindree").options[document.getElementById("cylindree").selectedIndex].value;
	idMoto = document.getElementById("model").options[document.getElementById("model").selectedIndex].value;

	if(list=="marque")
	{
		document.getElementById("cylindree").innerHTML = "<option>Chargement</option>";

		loading("cylindree");
		LoadList("cylindree", idMarque, "");
		list = "cylindree";
		idCylind = "0";
	}

	if(list=="cylindree")
	{
		document.getElementById("model").innerHTML = "<option>Chargement</option>";

		loading("model");
		LoadList("model", idMarque, idCylind);
	}

	if(list=="model")
	{
		LoadMoto(idMoto, "shopCont", "0");
		LastIdl = 0;
		LastIdsl = 0;
	}
}

function InitPieces()
{	
	loading("marque");
	LoadList("marque", "", "", "");
}

/*****************************************************************************/
/*                                 Panier                                    */
/*****************************************************************************/

function CartAct(act, id, lightout)
{
	DisplayAjaxLoaderBig(0, 150);

	dest = "ajax/cart.php?"+act+"="+id;
	if(lightout)
		dest = dest+"&lightout=1";

	AjaxGET(dest, "CartCont", true, "AfterCartAct()");
}

function ValidAct(act, id)
{
	DisplayAjaxLoaderBig(0, 150);
	AjaxGET("ajax/cart.php?"+act+"="+id, "CartCont", true, "AfterValidAct()");
}

function AfterValidAct()
{
	RefreshPage();
}

function AfterCartAct()
{
	RefreshCartBox();
	HideAjaxLoaderBig();
}

function CartAdd(id)
{
	ShowAddBox();
	DisplayAjaxLoader("AddBoxContent");
	AjaxGET("ajax/cart.php?miniout=1&add="+id, "AddBoxContent", true, "RefreshCartBox()");
}

function SizeShow(lang)
{
	ShowAddBoxSize();
	DisplayAjaxLoader("AddBoxContent");
	AjaxGET("content/tableautaille"+lang+".php", "AddBoxContent", true);
}

function SizeUpdate(lang,art)
{
	HideAddBox();
	ShowAddBoxSize();
	DisplayAjaxLoader("AddBoxContent");
	AjaxGET("content/tableautaille"+lang+".php?art="+art, "AddBoxContent", true);
}

function cancelAdd(id)
{
	HideAddBox();
	AjaxGET("ajax/cart.php?miniout=1&rem="+id, "AddBoxContent", true, "RefreshCartBox()");
}

function RefreshCartBox()
{
	AjaxGET("ajax/cartbox.php", "b25", true);
}

/*****************************************************************************/
/*                                  Login                                    */
/*****************************************************************************/

function PrintLogin()
{
	ShowFloatBox("Login",300, false, true);
	CenterFloatBox(200,200);
	DisplayAjaxLoader("FBContent");
	AjaxGET("content/loginform.php", "FBContent", true, "window.document.getElementById('Login').focus()");
}

function Logout()
{
	AjaxGET("ajax/logout.php", "", true, "RefreshPage()");
}

function PostLogin(Page)
{
	Login =  document.getElementById("Login").value;
	Pass  =  document.getElementById("Pass").value;
	AjaxPost("ajax/login.php", "Login="+Login+"&Pass="+Pass, "XMLData", true, "CheckLogin('"+Page+"')");
}

function CheckLogin(Page)
{
	var objDom = new XMLDoc(document.getElementById("XMLData").value, xmlError);
	var Login = objDom.docNode.getElements("LOGIN")[0].getText();
	var Pass = objDom.docNode.getElements("PASS")[0].getText();

	if(Login=="false"||Pass=="false")
	{
		document.getElementById("PassInval").style.display = "block";
	}
	else
	{
		HideFloatBox();
		RefreshPage(Page);
	}
}

/*****************************************************************************/
/*                                  Lost                                     */
/*****************************************************************************/

function PrintLost()
{
	ShowFloatBox("Login",300, false, true);
	CenterFloatBox(200,200);
	DisplayAjaxLoader("FBContent");
	AjaxGET("content/lostform.php", "FBContent", true);
}

function PostLost()
{
	Email =  document.getElementById("Email").value;
	AjaxPost("ajax/lost.php", "Email="+Email, "FBContent", true);
}

/*****************************************************************************/
/*                               Inscription                                 */
/*****************************************************************************/

function PrintSingIn()
{
	ShowFloatBox("Inscription",400, false, true);
	CenterFloatBox(200,200);
	DisplayAjaxLoader("FBContent");
	AjaxGET("content/singinform.php?ajax=1", "FBContent", true);
}

function PostSingIn(post)
{
	if(post)
		PostAct = post;
	else
		PostAct = 0;
	Login  =  document.getElementById("Login").value;
	Pass   =  document.getElementById("Pass").value;
	Pass2  =  document.getElementById("Pass2").value;
	Email  =  document.getElementById("Email").value;
	Email2 =  document.getElementById("Email2").value;
	Newletter = document.getElementById("Newletter").value;
	AjaxPost("ajax/singin.php?ajax=1", "Login="+Login+"&Pass="+Pass+"&Pass2="+Pass2+"&Email="+Email+"&Email2="+Email2+"&Newletter="+Newletter+"&PostAct="+PostAct, "FBContent", true);
}

/*****************************************************************************/
/*                                Adresse                                    */
/*****************************************************************************/

function PrintAdresseMod()
{
	ShowFloatBox("Inscription",400, false, true);
	CenterFloatBox(200,200);
	DisplayAjaxLoader("FBContent");
	AjaxGET("content/adresseform.php?ajax=1&act=Mod", "FBContent", true);
}
function PrintAdresseFactMod()
{
	ShowFloatBox("Inscription",400, false, true);
	CenterFloatBox(200,200);
	DisplayAjaxLoader("FBContent");
	AjaxGET("content/adressefactform.php?ajax=1&act=Mod", "FBContent", true);
}

function PostAdresseMod()
{
	AdresseFrom =  document.getElementById("AdresseFrom").value;
	IDAdresse =  document.getElementById("IDAdresse").value;
	Nom =  document.getElementById("Nom").value;
	Prenom  =  document.getElementById("Prenom").value;
	Titre  =  document.getElementById("TitreM").checked?document.getElementById("TitreM").value:document.getElementById("TitreF").value;
	TitreF  =  document.getElementById("TitreF").value;
	Adresse  =  document.getElementById("Adresse").value;
	Ville = document.getElementById("Ville").value;
	NPA = document.getElementById("NPA").value;
	Pays = document.getElementById("Pays").value;
	Tel = document.getElementById("Tel").value;
	Fax = document.getElementById("Fax").value;

	AjaxPost("content/adresseform.php?ajax=1&act=Mod", "AdresseFrom="+AdresseFrom+"&IDAdresse"+IDAdresse+"&Nom="+Nom+"&Prenom="+Prenom+"&Titre="+Titre+"&Adresse="+Adresse+"&Adresse="+Adresse+"&Ville="+Ville+"&NPA="+NPA+"&Pays="+Pays+"&Tel="+Tel+"&Fax="+Fax, "FBContent", true, "PostAdresseCheck()");
}
function PostAdresseFactMod()
{
	AdresseFrom =  document.getElementById("AdresseFrom").value;
	IDAdresse =  document.getElementById("IDAdresse").value;
	Nom =  document.getElementById("Nom").value;
	Prenom  =  document.getElementById("Prenom").value;
	Titre  =  document.getElementById("TitreM").checked?document.getElementById("TitreM").value:document.getElementById("TitreF").value;
	TitreF  =  document.getElementById("TitreF").value;
	Adresse  =  document.getElementById("Adresse").value;
	Ville = document.getElementById("Ville").value;
	NPA = document.getElementById("NPA").value;
	Pays = document.getElementById("Pays").value;
	Tel = document.getElementById("Tel").value;
	Fax = document.getElementById("Fax").value;

	AjaxPost("content/adressefactform.php?ajax=1&act=Mod", "AdresseFrom="+AdresseFrom+"&IDAdresse"+IDAdresse+"&Nom="+Nom+"&Prenom="+Prenom+"&Titre="+Titre+"&Adresse="+Adresse+"&Adresse="+Adresse+"&Ville="+Ville+"&NPA="+NPA+"&Pays="+Pays+"&Tel="+Tel+"&Fax="+Fax, "FBContent", true, "PostAdresseCheck()");
}

function PostAdresseCheck()
{
	if(document.getElementById("AddrOK").value == "1")
		RefreshPage();
}

/*****************************************************************************/
/*                           Changement de langue                            */
/*****************************************************************************/

function SwitchLng(lng)
{
	AjaxGET("ajax/lang.php?lang="+lng, "FBContent", true, "RefreshPage();");
}

/*****************************************************************************/
/*                                 Contact                                   */
/*****************************************************************************/

function PrintContactForm(mail)
{
	ShowFloatBox("Contact",520);
	CenterFloatBox(180,150);
	DisplayAjaxLoader("FBContent");
	AjaxGET("content/contactform.php?mail="+mail, "FBContent", true);
}

function PostContactFrom()
{
	MailTo	= document.getElementById("mailto").value;
	Mail		= document.getElementById("Mail").value;
	Objet		= document.getElementById("Objet").value;
	Message	= document.getElementById("Message").value;

	AjaxPost("content/contactformpost.php", "mailto="+MailTo+"&Mail="+Mail+"&Objet="+Objet+"&Message="+Message, "FBContent", true);
}

/*****************************************************************************/
/*                           Conditions Générales                            */
/*****************************************************************************/

function PrintCond()
{
	ShowFloatBox("Conditions",800);
	CenterFloatBox(400,20);
	DisplayAjaxLoader("FBContent");
	AjaxGET("content/cond.php?noframe=1", "FBContent", true);
}

/*****************************************************************************/
/*                                SaferPay                                   */
/*****************************************************************************/

function PrintSaferPay()
{
	CommentaireC = document.getElementById("Commentaire").value;

	ShowFloatBox("SaferPay",605);
	CenterFloatBox(300,100);
	DisplayAjaxLoader("FBContent");
	AjaxPost("ajax/saferpay.php", "Commentaire="+CommentaireC, "FBContent", true);
}

/*****************************************************************************/
/*                            Gestion d'erreurs                              */
/*****************************************************************************/

function xmlError(e)
{
	alert(e);
}

/*****************************************************************************/
/*                            Lancement events                               */
/*****************************************************************************/

if(document.layers)
  document.captureEvents(Event.MOUSEMOVE);

if(document.layers||document.all)
  document.onmousemove = mouseMove;

if(document.addEventListener)
  document.addEventListener('mousemove', mouseMove, true);

