Array.prototype.in_array = function(valeur) {
		for (var i in this) { if (this[i] == valeur) return i;}
			return -1;
}
function setCookie(nom, valeur, expiration) {
	document.cookie = nom + "=" + escape(valeur) + ((expiration == null) ? "" : ("; expires=" + expiration.toGMTString()));
}
function getCookie(nom) {
	var recherche = nom+ "=";
	if (document.cookie.length > 0) { 
		offset = document.cookie.indexOf(recherche) ;
		if (offset != -1) { // si le cookie existe
			offset += recherche.length;
			// position du début
			fin = document.cookie.indexOf(";",offset) ;
			// position de la fin 
			if (fin == -1) 
				fin= document.cookie.length;
			return unescape(document.cookie.substring(offset, fin));
		} 
	}
}
function DeleteCookie (name) {
   var exp=new Date();
   exp.setTime (exp.getTime() - 100000);
   var cval=getCookie(name);
  document.cookie=name+"="+cval+"; expires="+exp.toGMTString();
}

function jsRetourMoteur()
{
	var tabPieces = new Array(347,373,376,420,548,604,618,659,663);
        var tabMoteurs = new Array(362,379,384,392,574,572,592,608,649,654);
	var tabPanier = new Array(113,113);
	var str = new String(document.location);
	
	re = new RegExp("^(.+)-([0-9]+)-([0-9]+)-([0-9]+)-([0-9]+)(_[^.]+)?\.html(.*)");
        matches = re.exec(str);
	var action = 'erase';
	if (tabPieces.in_array(matches[2])!=-1)
	{
		action = 'nop';
		//alert('Pieces');
	}
	if (tabMoteurs.in_array(matches[2])!=-1)
	{
		action = 'nop';
		setCookie('diaJetMarineLastMoteurURL', document.location, null);
	}
	var cookieVal = getCookie("diaJetMarineLastMoteurURL");
	if (cookieVal && (tabPanier.in_array(matches[2])!=-1) && cookieVal.length>0)
	{
		action = 'nop';
		//alert('Panier');
		var backDiv = window.document.getElementById('fbasket_back_113');
		if (backDiv)
		{
                  backDiv.innerHTML = '<a class="back lienImage" href="' + cookieVal + '" title="Continuer mes achats"><span><img src="files/113/roll/bt_retour_fiche_moteur.gif" alt="Continuer mes achats" /></span></a>' + backDiv.innerHTML;
		}
	}
	if (action=='erase')
	{
			DeleteCookie('diaJetMarineLastMoteurURL');
	}
}
onLoadFunc[onLoadFunc.length] = 'jsRetourMoteur();';

