function GetHRObject()
{
	var HttpReq = null;

	if (typeof(XMLHttpRequest) != 'undefined')
	{
		HttpReq = new XMLHttpRequest();
	}
	else
	{
		try
		{
			HttpReq = new ActiveXObject('Microsoft.XMLHTTP');
		}
		catch (e)
		{
			HttpReq = null;
		}
	}

	return HttpReq;
}

function test(){
	alert("test");

}

function AddToPanier(Ref){
new Ajax.Updater('article','ajaxpanier.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=ajouter&ref='+encodeURIComponent(Ref)
       });
alert("Produit ajoutŽ avec succŽs");

}



function GetChain_brand(){
new Ajax.Updater('brand','chain.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=chain'
       });
     
	}
function sendChain(){
var form = $('chains');
var brand = form['f_brand'];
var model = form['f_model'];
var blen = form['f_bar_lenght_inches'];
var pitch = form['f_pitch'];
var gauche = form['f_gauche_mm'];
var chain = ($F(brand))+";"+($F(model))+";"+($F(blen))+";"+($F(pitch))+";"+($F(gauche));

new Ajax.Updater('list_chain','chain.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=chain&chain='+encodeURIComponent(chain)+'&id=list'
       });
     
	}
function GetChain_model(brand){
new Ajax.Updater('model','chain.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=chain&chain='+encodeURIComponent(brand)+'&id=1'
       });
     
	}
	
function GetChain_barlength(brand, model){
new Ajax.Updater('bar_length','chain.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=chain&chain='+encodeURIComponent(brand)+';'+encodeURIComponent(model)+'&id=2&champ=1'
       });
new Ajax.Updater('jauge','chain.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=chain&chain='+encodeURIComponent(brand)+';'+encodeURIComponent(model)+'&id=2&champ=2'
       });
new Ajax.Updater('pas','chain.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=chain&chain='+encodeURIComponent(brand)+';'+encodeURIComponent(model)+'&id=2&champ=3'
       });
       
new Ajax.Updater('valid','chain.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=chain&id=5'
       });
     
	}
	
	
function GetInfoChain(Ref, cat){
var HttpReq = GetHRObject();

	if (!HttpReq)
	{
	
		document.location.href='produit.php?ref='+Ref+'&categorie=6' ;
		return;
	}

	HttpReq.onreadystatechange = function()
	{
	
		if (HttpReq.readyState == 4 && HttpReq.status == 200)
		{
		
			
				var PanierMsgInfo = document.createElement("div");
				PanierMsgInfo.style.backgroundColor = '#999999';
				PanierMsgInfo.style.width = '550px';
				PanierMsgInfo.style.height = '600px';
				PanierMsgInfo.id = 'PanierValidation';
				PanierMsgInfo.style.position = 'absolute';

				var BasketMsg = document.createElement("div");
				BasketMsg.style.width = '550px';
				BasketMsg.style.height = '600px';
				BasketMsg.style.position = 'relative';
				BasketMsg.style.background = 'URL(/images/gui/main/BskPopBg.jpg) center no-repeat #FFFFFF';
				BasketMsg.style.border = '2px solid #333333';
				BasketMsg.style.left = '-5px';
				BasketMsg.style.top = '-5px';

				var HTML = '<div style="background:url(images/popUpFoot.gif) center; padding:3px; color:#FFFFFF; font-weight:bold;">Produit <a href="#" onclick="ProdAlertValidate(true); return false;">Fermer</a></div>'
+ '<div id="visualisation" style="padding:10px;">';

HTML += '</div>'
;
				BasketMsg.innerHTML = HTML;

				PanierMsgInfo.appendChild(BasketMsg);
				document.body.appendChild(PanierMsgInfo);

				if (navigator.appName=="Microsoft Internet Explorer")
				{
					ScrollY = document.documentElement.scrollTop + document.body.scrollTop;
					ScrollX = document.documentElement.scrollLeft + document.body.scrollLeft;
				}
				else
				{
					ScrollY = window.pageYOffset;
					ScrollX = window.pageXOffset;
				}
				var View = {
					width 	: (
						// W3C Compliant calculation
						window.innerWidth ? 
							window.innerWidth : 
							// IE 6 + 
							( document.documentElement && document.documentElement.clientWidth ) ?
								document.documentElement.clientWidth  : 
								// IE 4
								document.body.clientWidth
					),
					height  : (
						// W3C Compliant calculation
						window.innerHeight ? 
							window.innerHeight  : 
							// IE 6 + 
							( document.documentElement && document.documentElement.clientHeight ) ?
								document.documentElement.clientHeight  : 
								// IE 4
								document.body.clientHeight
					)
				}
				
				PanierMsgInfo.style.left = (View.width / 2 	- PanierMsgInfo.offsetWidth / 2 + ScrollX) + 'px';
				PanierMsgInfo.style.top = (View.height / 2 	- PanierMsgInfo.offsetHeight / 2 + ScrollY ) + 'px';
				
				
			
		}
	}



	HttpReq.open('GET', 'ajaxpanier.php?action=ajouter&amp;ref=' + encodeURIComponent(Ref), true);
	HttpReq.send(null);
	new Ajax.Updater('visualisation','ajaxproduit.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'id_rubrique='+encodeURIComponent("6")+'&ref='+encodeURIComponent(Ref)
       });
     


}	
function ResultatRecherchePiDet(Ref){
Ref = Ref.replace(/ /g, "-");
	new Ajax.Updater('pieceresult','recherchepiece.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'ref='+encodeURIComponent(Ref)
       });
     


}
function ChangeAmountDepartement(ItemID, Name){
	var ret = prompt('Veuillez saisir les 2 chiffres du département de livraison','');
	
	if(ret==68){
		ChangeAmount(ItemID, Name);
	}
	else{
		alert("Les produits STIHL et VIKING à moteurs sont disponibles uniquement en magasin.\n" +
		"Pour plus de renseignements,\ntéléphonez nous au 03 89 54 16 45\n"+		
		"Tous nos autres produits sont disponibles en ligne. ")
	}
}

function ChangeAmount(ItemID, Name)
{
	var HttpReq = GetHRObject();

	if (!HttpReq)
	{
	
		document.location.href='panier.php?action=ajouter&amp;ref=' + ItemID ;
		return;
	}

	HttpReq.onreadystatechange = function()
	{
	
		if (HttpReq.readyState == 4 && HttpReq.status == 200)
		{
		
			
				var PanierMsgInfo = document.createElement("div");
				PanierMsgInfo.style.backgroundColor = '#999999';
				PanierMsgInfo.style.width = '340px';
				PanierMsgInfo.style.height = '200px';
				PanierMsgInfo.id = 'PanierValidation';
				PanierMsgInfo.style.position = 'absolute';

				var BasketMsg = document.createElement("div");
				BasketMsg.style.width = '340px';
				BasketMsg.style.height = '200px';
				BasketMsg.style.position = 'relative';
				BasketMsg.style.background = 'URL(/images/gui/main/BskPopBg.jpg) center no-repeat #FFFFFF';
				BasketMsg.style.border = '2px solid #333333';
				BasketMsg.style.left = '-5px';
				BasketMsg.style.top = '-5px';

				var HTML = '<div style="background:url(images/popUpFoot.gif) center; padding:3px; color:#FFFFFF; font-weight:bold;">Panier</div>'
+ '<div>'
+ '<table width="100%" border="0" cellspacing="0" cellpadding="2">'
+ '<tr>'
+ '<td height="70" colspan="3" valign="middle" style="color:#333333; padding-left:20px;">';
if (Name)
{
	HTML += '<div style="font-size:14px; font-weight:bold;">' + Name + '</div>'
	+ '<div>Cet article a bien &eacute;t&eacute; ajout&eacute; &agrave; votre panier.</div>';
}
HTML += '</td>'
+ '</tr>'
+ '<tr>'
+ '<td width="30%" height="48" align="center" valign="top"><a href="#" onclick="ProdAlertValidate(true); return false;"><img src="images/prev.gif" width="45" height="45" border="0" alt="Rester sur la page" title="Rester sur la page" /></a></td>'
+ '<td width="40%" height="48" valign="top">&nbsp;</td>'
+ '<td width="30%" height="48" align="center" valign="top"><a href="#" onclick="ProdAlertValidate(false); return false;"><img src="images/next.gif" width="45" height="45" border="0" alt="Visualiser votre panier" title="Visualiser votre panier" /></a></td>'
+ '</tr>'
+ '<tr>'
+ '<td align="center" style="padding-left:20px;">Rester sur la page</td>'
+ '<td>&nbsp;</td>'
+ '<td align="center" style="padding-right:20px;">Visualiser votre panier</td>'
+ '</tr>'
+ '</table>'
+ '</div>'
;
				BasketMsg.innerHTML = HTML;

				PanierMsgInfo.appendChild(BasketMsg);
				document.body.appendChild(PanierMsgInfo);

				if (navigator.appName=="Microsoft Internet Explorer")
				{
					ScrollY = document.documentElement.scrollTop + document.body.scrollTop;
					ScrollX = document.documentElement.scrollLeft + document.body.scrollLeft;
				}
				else
				{
					ScrollY = window.pageYOffset;
					ScrollX = window.pageXOffset;
				}
				var View = {
					width 	: (
						// W3C Compliant calculation
						window.innerWidth ? 
							window.innerWidth : 
							// IE 6 + 
							( document.documentElement && document.documentElement.clientWidth ) ?
								document.documentElement.clientWidth  : 
								// IE 4
								document.body.clientWidth
					),
					height  : (
						// W3C Compliant calculation
						window.innerHeight ? 
							window.innerHeight  : 
							// IE 6 + 
							( document.documentElement && document.documentElement.clientHeight ) ?
								document.documentElement.clientHeight  : 
								// IE 4
								document.body.clientHeight
					)
				}
				
				PanierMsgInfo.style.left = (View.width / 2 	- PanierMsgInfo.offsetWidth / 2 + ScrollX) + 'px';
				PanierMsgInfo.style.top = (View.height / 2 	- PanierMsgInfo.offsetHeight / 2 + ScrollY ) + 'px';
				
				
			
		}
	}

	if($('myselect')){
		
		var str = '&'+encodeURIComponent($('myselect').name)+'='+encodeURIComponent($('myselect').value);
		//alert(str);
	}
	else{
		var str ='';
		
	}
	HttpReq.open('GET', 'ajaxpanier.php?action=ajouter&amp;ref=' + encodeURIComponent(ItemID)+str, true);
	HttpReq.send(null);
	new Ajax.Updater('article','ajaxpanier.php',
       {
       method: 'get',
        evalScripts:true,
      	 parameters:'action=ajouter&ref='+encodeURIComponent(ItemID)+str
       });
     

}

function ProdAlertValidate(Stay)
{
	ProdAlert = document.getElementById('PanierValidation');
	ProdAlert.parentNode.removeChild(ProdAlert);

	if (!Stay)
		document.location.href = 'panier.php';
}

