//var racine_url = "http://localhost/discount-moto/";
var racine_url = "http://www.discount-moto.com/";

function log(o){
	if(window['console'] && window.console['log']){
		console.log(o);
	}
}

//Permet de mettre à zéro le formulaire de connexion
function mazIdentification(){
	document.connexion.login.value="";
	document.connexion.password.value="";
}


function movepic(img_name,img_src) {
	document[img_name].src=img_src;
}


function visibleOrNot(id){
	if (document.getElementById(id) != null){
		var element = document.getElementById(id);
		element.style.visibility = 'visible';
		if (element.style.display == 'none'){
			Effect.BlindDown(id,{ duration: 1.0 });	
		}else{
			Effect.BlindUp(id,{ duration: 1.0 });			
		}
	}
}


function visiOrNot(element){
	if (element != null){
		if (element.style.display == 'block'){
			element.style.display = 'none';
			element.style.visibility = 'hidden';		
		}else{
			element.style.display = 'block';
			element.style.visibility = 'visible';
		}
	}
}	

function imprimer(lien,variable)
    {
    options ="Width=755,Height=600;resizable=yes,scrollbars=yes,toolbar=yes" ;
    window.open(lien+"?id="+variable,"facture", options ) ;
	//window.close();
    }
	
function redirectDetail(gamme,lien){
	
	document.formulaireAjoutArticle.gammeRechargement.value = gamme;
	document.formulaireAjoutArticle.rechargement.value = 1;
	
	lien_ajax(lien,$('content'),$('formulaireAjoutArticle'));
}


function gam(variable,lien){
	
	if (variable !=3){
		if (document.formulaireAjoutArticle.gamme1.checked == true && document.formulaireAjoutArticle.gamme2.checked == true){
			redirectDetail(21,lien);
		}
		else{
			if (document.formulaireAjoutArticle.gamme1.checked && !document.formulaireAjoutArticle.gamme2.checked)
				redirectDetail(1,lien);
			else if(document.formulaireAjoutArticle.gamme2.checked && !document.formulaireAjoutArticle.gamme1.checked)
				redirectDetail(2,lien);
		}
	}
	else{
		
		alert("'STANDARD' est obligatoire pour le type accessoire");
		redirectDetail(variable,lien);
	}
}


function changeImage(id){

	var img_princ = document.getElementById('img_principale');
	var img_princ_petite = document.getElementById('img_principale_hidden');
	
	var img_petite = document.getElementById('photo'+id);
	var img_grande = document.getElementById('photo_hidden_'+id);
	
	//permet d'echanger les photos
	document.getElementById('img_principale').src = img_grande.src;
	document.getElementById('img_principale_hidden').src = img_petite.src;
	
}


	
	
function isIE(){
	var detect = navigator.userAgent.toLowerCase();
	place = detect.indexOf('msie') + 1;
	if (place){
		var arVersion = navigator.appVersion.split("MSIE");
		var version = parseFloat(arVersion[1]);
		return version;
	}
	return 0;
}

/**********CORRECTION PNG *******/	 
function lancer_postit(){
	var ie = isIE();
	if (ie == 0 || ie>=7){
		lancerPostit();
	}
}

function png() {
	var ie = isIE();
	if (ie>=5.5 && ie<7){
		PngFixImg();
	}	
}
/**********FIN CORRECTION PNG *******/


	
function isLien(lien,recherche){
	var reg=new RegExp("[ /]+", "g");
	var tableau=lien.split(reg);
	var size = tableau.length;
	var sizeRecherche = recherche.length;
	for (var i=0;i<size;i++){
		if (tableau[i].length >= sizeRecherche && tableau[i].substr(0,sizeRecherche) == recherche){
			return true;
		}
	}
	return false;
}
	
	
function gestionIdentification (reponse){
	
	fenetre(reponse,200,350);
	
	if ($('rechargementLoginSite') != null && ($('rechargementLoginAdmin') != null  || $('rechargementLoginClient') != null)){
		if ($('rechargementLoginAdmin') != null){
			$('rechargementLoginSite').innerHTML = $('rechargementLoginAdmin').innerHTML;
		}else{
			$('rechargementLoginSite').innerHTML = $('rechargementLoginClient').innerHTML;
		}
	}
	
	if ($('rechargementMenuLogin') != null && $('rechargementMenu') != null){
		$('rechargementMenu').innerHTML = $('rechargementMenuLogin').innerHTML;
	}
}

function redirectURL(lien,element,form){
	lien_ajax(lien,element,form);
}

function fermerFenetre(){
	if(Windows.getFocusedWindow() != null)
		Windows.getFocusedWindow().close();
}

function image(reponse){
		fenetre(reponse,650,700);
}

function fenetre(reponse,height,width){
		Dialog.info(reponse, 
			{
			resizable : false,
			closable : false,
			minimizable : false,
			maximizable : false,
			draggable : false,
			recenterAuto:true,
			gridY:10,
			width:width, 
			height:height,
			destroyOnClose: true, 
			recenterAuto:false,
			showEffect:Effect.BlindDown,
			hideEffect:Effect.Fade,
			className: "discountmoto"
			});
	}


function confirmPop(phrase,lien,form){
		
	var icone = '<center><table align="center" border="0"><tr><td><img src="'+racine_url+'images/icones/attention-30.png" heitgh="30px" width="30px" /><td>';
	phrase = icone+'<td style="font-size:100%;font-weight:bold;">'+phrase+'</td></tr></table></center><br>';
	Dialog.confirm(phrase, 
		{
		resizable : false,
		closable : false,
		minimizable : false,
		maximizable : false,
		draggable : false,
		okLabel: "Oui",
		cancelLabel: "Non",
		width:300, 
		height:100,
		destroyOnClose: true, 
		recenterAuto:true,
		className: "discountmoto", 
		title: 'Dialogue',
		onOk:function()
			{
				fermerLogin();
				if (form != null)
					redirectURL(lien,$('content'),form);
				else 
					redirectURL(lien,$('content'));
				return true;	
			},
		onCancel:function() 
			{return false;}
		});
		
}

function gestionException(exception){
	var reponse = '<div style="position:absolute;top:1px;right:1px;"><a href="javascript:void(0);" onclick="fermerLogin();return false;" ><img src="'+racine_url+'images/bouton-fermeture.gif" height="23px" width="23px" /></a></div><br /><font class="erreur">ERREUR</font><br><br>'+exception;
	fenetre(reponse,150,300);
		
}	


function fermerLogin(){
	fermerFenetre();
	if(Windows.getFocusedWindow() != null){
		if ($('validation_login') != null && $('validation_login').innerHTML == "validation"){
			Windows.getFocusedWindow().close();
			lien_ajax(racine_url+'client/validation_coordonnee_tnt.php',$('content'));
		}else
			Windows.getFocusedWindow().close();
	}
		
	return false;
}


function setupTiny(){
	
	tinyMCE.init({
	    mode: "exact",
	    theme : "advanced",
	    languages : "en",
	    disk_cache : true,
	    skin : "o2k7",
	    elements : "petite_description,descriptif,message",
	    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
	    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,forecolor,|,undo,redo,|,help,code",
	    theme_advanced_buttons3 :""
	  });

	}



function loader(){
	var win = new Window(
			{
			resizable : false,
			closable : false,
			minimizable : false,
			maximizable : false,
			draggable : false,
			width:200, 
			height:50,
			minWidth:50,
			minHeight:50,
			destroyOnClose: false, 
			recenterAuto:true,
			className: "discountmoto"
			});
	win.setHTMLContent('<div id="loader"><img src="'+racine_url+'images/ajax-loader.gif" height="32px" width="32px" /></div><div id="text_loader">Veuillez patienter.<br>Chargement en cours...</div>');
	return win;
}
function scrollMeUp(){
	//setTimeout("new Effect.ScrollTo('topScroll',{duration: 0.2});",500);
}
	function lien_ajax(lien,element,form){
		pub.tm = null;
		//log(element);
		//log(form);
		//log(lien);
		
		var lien_finale = lien;
		var parameters='';
		var method='get';
		if (form != null){
			var pars = Form.serialize(form);
			parameters=pars;
			method='post';
		}
	
			var myAjax = new Ajax.Request(lien_finale ,
				{
				  asynchronous:true,
				  evalScripts:true,
				  parameters : 'ajax=ajax&'+parameters,
				  method: method,
				  encoding: 'ISO-8859-1', 
				  contentType: 'application/x-www-form-urlencoded;',
				  onLoading: function (xhr)
					{ 
						win.showCenter(true);
					},
				  onSuccess: function(xhr)
					{ 
						log(lien);
						if(lien.indexOf('articles/detail')!=-1){
							//scrollMeUp();
							setTimeout("new Effect.ScrollTo('topScroll',{duration: 0.2});",500);
						}						
					},
					onComplete : function(xhr)
					{
						var reponse = xhr.responseText;
						
						var url = donneURL(lien_finale);
						
						if (isLien(url,"login.php")){
							gestionIdentification(reponse);
						}else if(isLien(url,"photo")){
							image(reponse);
						}else if(isLien(url,"qui.php") || isLien(url,"livraison.php")){
							if (isLien(url,"qui.php"))
								fenetre(reponse,300,620);
							else
								fenetre(reponse,350,500);
						}else{
							element.innerHTML = reponse;
							//reponse.evalScripts();
							setTimeout("if (Windows.getFocusedWindow()!=null)Windows.getFocusedWindow().close();",500);
							setTimeout("$('overlay_modal').style.display='none';",500);
							
						}
						
						dhtmlHistory.add("section:"+lien_finale,lien_finale);
						
						//gestion du rechargement du panier
						if (isLien(url,"panier.php") || isLien(url,"cheque.php") || isLien(url,"validation.php"))
							MiseAJourNbArticle();
						
						if(window.pageTracker && pageTracker._trackPageview){
							pageTracker._trackPageview(lien_finale);
						}
						
						if(window.__tracker && __tracker.trackPageview){
							__tracker.trackPageview(lien_finale);
						}
						
						//reponse.evalScripts();
						
						png();
						
						if(document.getElementById('pubPlaceHolder')){
							pub.init();
						}
						
					}
					,
					on404: function(xhr) {
						gestionException("La page est introuvable, veuillez informer le webmaster (webmaster@discount-moto.com) en inquant l'url qui vous a amené à cette erreur.<br><br>Merci de votre implication.");
					}
					,
					onFailure: function(xhr) {
						gestionException("Erreur technique, veuillez informer le webmaster (webmaster@discount-moto.com) en inquant l'url qui vous a amené à cette erreur.<br><br>Merci de votre implication.");
					}
					,
					onException: function (xhr)
					{
						//gestionException("Exception:Erreur technique, veuillez informer le webmaster (webmaster@discount-moto.com) en inquant l'url qui vous a amené à cette erreur.<br><br>Merci de votre implication.");
						log(xhr);
					}
				});	
		//}
	}
	
	
/********MENU DEROULANT*******/
		
var RollIt = { 
	timeout : null, 
	showPopup : function(e,img){
		hideAllMenu(e);
		clearTimeout(this.timeout);         
		if($(e).style.display == 'none')
		{
		   this.timeout = setTimeout(function(){new Effect.BlindDown(e, {duration:0.5})},40);
		   document.getElementById(img).src = racine_url+'images/menu_selection.png';
		}else{
			this.timeout = setTimeout(function(){new Effect.BlindUp(e, {duration:0.5})},40); 
			document.getElementById(img).src = racine_url+'images/menu_normal.png';
		}
	}
}
	
function hideAllMenu(e){
	var alls = document.getElementsByName("accordeon"); 
	var allimg=document.getElementsByName("img_accordeon"); 
	for(var i=0; i<alls.length; i++) { 
		if ($(e) != alls[i]){
			new Effect.BlindUp(alls[i].id, {duration:0.5});
			document.getElementById(allimg[i].id).src = racine_url+'images/menu_normal.png';
		    
		} 
	 }
}	
/********FIN MENU DEROULANT*******/		


/************article hasard*******/
function art_hasard(){
	return true;
	var url = racine_url+"articles/articleHasard.php";
	var laRequete = new Ajax.Request(url,
		{
			method:'get',
			parameters : '',
			onLoading: function ()
			{ 
				$('post-it_droite').innerHTML ='<div style="height:140px;width:160px;text-align:right"><br><br><br><br><center><img src="'+racine_url+'images/ajax-loader-panier.gif" height="20px" width="20px" /></center></div>';
			},
			onSuccess: function(xhr)
			{ 
				if (xhr.responseText != ""){
					$('post-it_droite').innerHTML = xhr.responseText;
				}
				
			}
		});
	
}	

/**********FIN article********/


/******POSTIT*********/
function postit(){
	var url = racine_url+"rechargement.php";
	
	var laRequete = new Ajax.Request(url,
			{
				method:'get',
				parameters : 'rechargementPI',
				onLoading: function ()
				{ 
					$('post-it_gauche').innerHTML = '<div style="height:140px;width:160px;text-align:right"><br><br><br><br><center><img src="'+racine_url+'images/ajax-loader-panier.gif" height="20px" width="20px" /></center></div>';
				},
				onSuccess: function(xhr)
				{ 
					$('post-it_gauche').innerHTML = xhr.responseText;
				}
			}
		);
						
}
/***FIN***POSTIT*********/


function MiseAJourNbArticle(){
	
	var lien_finale = racine_url+'rechargement.php?panier';
	var myAjax = new Ajax.Request(lien_finale ,
		{
		  parameters : 'ajax=ajax',
		  method: 'post',
		   onSuccess: function(xhr)
			{ 
				$('panierRechargement').innerHTML = xhr.responseText;
					
			},
			onException: function (xhr, e)
			{
				gestionException("Erreur technique lors de la mise à jour de votre panier, veuillez informer le webmaster (webmaster@discount-moto.com) en inquant l'url qui vous a amené à cette erreur.<br><br>Merci de votre implication.");
			}
	});	

}

function lancer_art_hasard(){
	 new PeriodicalExecuter(art_hasard,13);
}

function lancerPostit(){
	 new PeriodicalExecuter(postit,45);
}


function donneURL(url){
	var reg=new RegExp("[ /]+", "g");
	var tableau=url.split(reg);
	var size = tableau.length;
	var newURL = "";
	if (size <= 4){
		if (tableau[size-1] != "")
			newURL= tableau[size-1];
		else
			newURL= "index.php";
	
	}
	else{
		for (var i=3;i<size;i++){
			newURL=newURL+tableau[i];
			if (i<(size-1))
				newURL=newURL+"/";
		}
	}
	
	vraiURL= racine_url;
	newURL=vraiURL+newURL;
	return newURL;
}

function redirect(type){
	
	if (type == "compte"){
		fermerLogin();
		lien_ajax(racine_url+'client/index.php',$('content'),null);
	}else if (type == "inscription"){
		fermerLogin();
		lien_ajax(racine_url+'client/inscription.php?ajout',$('content'),null);
	}else if (type == "login"){
		fermerLogin();
		lien_ajax(racine_url+'login.php',$('content'),$('formLoginPopup'));
	}else if(type == "lien_logout"){
		lien_ajax(racine_url+'logout.php',$('site'),null);
	}else if (type == "admin"){
		fermerLogin();
		lien_ajax(racine_url+'admin/index.php',$('content'));
	}else if (type == "perdu"){
		fermerLogin();
		lien_ajax(racine_url+'perdu.php',$('content'));
	}
}
	
	
/********HISTORIQUE*******/		
function historique(){
	
	var historyChange = function historyChange(newLocation,historyData) {
		
		var domaine = newLocation.split("/");
		if (newLocation == "" || newLocation == null) {
			var url = donneURL('index.php');
			 newLocation = "section:"+url;
		}
		newLocation =  newLocation.replace(/section\:/, "");
		  
		if (historyData != null){
			displayLocation(newLocation, historyData);
		}
		
		
	}
	return historyChange;
}
	
	
	function displayLocation(newLocation,sectionData) {
		//console.log(sectionData);
		
		if (!isLien(sectionData,"banque.php"))
			lien_ajax(sectionData,$('content'));
		else
			lien_ajax(racine_url+"articles/paiement.php",$('content'));
	}


/********FIN HISTORIQUE*******/	

		var expedition = {
			setDefaultCodePostal : function(cp){
				this.defautCodePostal = cp;
			},
			defautCodePostal :'',
			init : function(d){
				//console.log(d);
				if(d && d.City){
					jQuery('#domicileCommuneSelector').html('');
					if(d.City.name){
						expedition.domicile.changeCommune(d.City.name);
					}
					else{
						for(var i in d.City){
							if(typeof d.City[i] != 'function' ){
								jQuery('#domicileCommuneSelector').append('<br/><input type="radio" value="'+d.City[i].name+'" name="domicileCommuneselection" onclick="expedition.domicile.changeCommune(this.value);" id="domicileCommuneselection'+i+'"/> <label for="domicileCommuneselection'+i+'" >'+d.City[i].name+'</label>');
							}
						}
					}
					
				}
			},
         selectMode : function(that){
            if(that.value==0){
               jQuery('#livraisonAdresse').show();
               jQuery('#choix_point_livraison').hide();
               jQuery('#tnt').html('');
               jQuery('#choixlivraisonAdresse').attr('checked',false);
               jQuery('#choixlivraisonTravail').attr('checked',false);
               jQuery('#choixlivraisonRelaisColis').attr('checked',false);
            }
            else if(that.value==1){
               jQuery('#livraisonAdresse').hide();
               jQuery('#choix_point_livraison').show();
            }
         },
			getCommune :function(cp,callback){
				jQuery.post('/getCommune.php',{cp:cp},function(d){
					d = eval ('('+d+')');
					//console.log(d);
					if(jQuery('#choixlivraisonTravail').attr('checked')){
						if(d && d.City){
							jQuery('#WtownSelector').html('');
							if(d.City.name){
								jQuery('#Wtown').val(d.City.name);
							}
							else{
								for(var i in d.City){
									if(typeof d.City[i] != 'function' ){
										jQuery('#WtownSelector').append('<br/><input type="radio" value="'+d.City[i].name+'" name="Wtownselection" onclick="jQuery(\'#Wtown\').val(this.value);" id="villechoix'+i+'"/> <label for="villechoix'+i+'" >'+d.City[i].name+'</label>');
									}
								}
							}
							
						}
					}
					
					if(callback){
						callback(d);
					}
				});
			},
			relaisColis : {
				selected : false,
				init : function(){
					expedition.closeAll();
					jQuery('#tnt').html('<div id="tntB2CRelaisColis" class="exemplePresentation"></div><div id="map_canvas" class="exemplePresentation" style="width: 482px; height: 482px;"></div>');
					jQuery('.map_canvas').show();
					jQuery('#validationc').hide();
					expedition.setDefaultCodePostal(jQuery('#domCp').val());
					window.callbackSelectionRelais = this.callbackSelectionRelais;
					tntB2CRelaisColis();
					jQuery('#tntRCSelectedCode').change(this.saveRelais);
				},
				save:function(){
					var codeRelais = jQuery("#tntRCSelectedCode").val();
					var nom = jQuery("#tntRCSelectedNom").val();
					var adresse = jQuery("#tntRCSelectedAdresse").val();
					var codePostal = jQuery("#tntRCSelectedCodePostal").val();
					var commune = jQuery("#tntRCSelectedCommune").val();
						
					if (codeRelais && codeRelais != "") {
						expedition.relaisColis.selected = 'codeRelais='+codeRelais+'&name='+nom+'&address1='+adresse+'&zipCode='+codePostal+'&city='+commune;
						
					}
				},
				callbackSelectionRelais : function(){
					//console.log(a);
					// Récupération des informations
					var codeRelais = jQuery("#tntRCSelectedCode").val();
					var nom = jQuery("#tntRCSelectedNom").val();
					var adresse = jQuery("#tntRCSelectedAdresse").val();
					adresse = adresse.substr(0,32);
					var codePostal = jQuery("#tntRCSelectedCodePostal").val();
					var commune = jQuery("#tntRCSelectedCommune").val();
						
					if (!codeRelais || codeRelais == "") {
						alert("Aucun relais n'a été sélectionné !");
					}
					else {
						jQuery('#choix_point_livraison').hide();
						expedition.relaisColis.selected = 'codeRelais='+codeRelais+'&name='+nom+'&address1='+adresse+'&zipCode='+codePostal+'&city='+commune;
						jQuery('#tnt').html
						('<a href="#nowhere" onclick="jQuery(\'#choix_point_livraison\').show()">Choisir un autre point de livraison</a> | <a href="#nowhere" onclick="expedition.relaisColis.init()">Choisir un autre Relais Colis® pour la livraison</a><h2>Info relais sélectionné</h2>'+
							  "\n<p>Code\t\t: " + codeRelais + 
							  "\n</p><p>Nom\t\t: " + nom +
							  "\n</p><p>Adresse\t\t: " + adresse +
							  "\n</p><p>Code postal\t: " + codePostal +
							  "\n</p><p>Commune\t\t: " + commune+'</p>');
						jQuery('#validationc').show();
						document.location='#tnt';
					}
				}
			},
			closeAll : function(){
				jQuery('#choix_point_livraison').css('border','');
				
				//Relais colis
				jQuery('.map_canvas').hide();
				jQuery('#tnt').html('');
				
				//Domicile
				jQuery('#livraisonAdresse').hide();
				
				//Travail
				jQuery('#livraisonTravail').hide();
				
				jQuery('.error').remove();
				
				jQuery('#validationc').show();
				
				document.location='#choix_point_livraison';
			},
			domicile : {
				init : function(){
					expedition.closeAll();
					jQuery('#livraisonAdresse').show();
					expedition.defautCodePostal = jQuery('#domCp').val();
					expedition.getCommune(expedition.defautCodePostal,expedition.init);
				},
				changeCommune : function(commune){
					jQuery('#domicileCommune').html(commune);
					jQuery('#hiddenDomicileCommune').val(commune);
					jQuery('#domicileCommuneSelector').html('');
				}
			},
			travail : {
				init : function (){
					expedition.closeAll();
					jQuery('#livraisonTravail').show();
				}
			},
			valider : function(){
				
				jQuery('.error').remove();
				
				//Vérification du point de livraison
				var selected = false;
            if(document.getElementById('choixmodelivraisonlaposte')){
               selected = jQuery('#choixmodelivraisonlaposte').attr('checked');
            }
				selected = jQuery('#choixlivraisonAdresse').attr('checked') ? true : selected;
				selected = jQuery('#choixlivraisonTravail').attr('checked') ? true : selected;
				selected = jQuery('#choixlivraisonRelaisColis').attr('checked') ? true : selected;
				
				if(!selected){
					jQuery('#choix_point_livraison').css('border','1px solid #f00');
					return false;
				}
				
				var w = jQuery('#userInfoForm').serialize()+'&';
				
            if(jQuery('#choixmodelivraisonlaposte').attr('checked')){
               w+= jQuery('#choix_mode_livraison_form').serialize()+'&';
               w+= jQuery('#individualForm').serialize();
            }
				//Point de livraison == travail 
				else if(jQuery('#choixlivraisonTravail').attr('checked')){
					w+= jQuery('#livraisonTravail').serialize()+'&entreprise=1';
				}
				//Point de livraison == relaisColis
				else if(jQuery('#choixlivraisonRelaisColis').attr('checked')){
					if(!this.relaisColis.selected){
						jQuery('#choix_point_livraison').before('<div class="error">Veuillez sélectionner un Relais Colis®</div>');
						return false;
					}
					else{
						w+= this.relaisColis.selected;
					}
				}	
				else{
						w+= jQuery('#individualForm').serialize();
				}
				
				
				//document.title='tot';return true;
				
				jQuery.post('/pointDeLivraison.php',w,function(d){
					d = eval ('('+d+')');
					//console.log(d);
					if(d.error.str){
						jQuery('#choix_point_livraison').before('<div class="error">'+d.error.str+'</div>');
					}
					else{
						
					}
					
					//Dans tout les cas on continue ...
					lien_ajax('/articles/paiement.php',$('content'),$('info'));
				});
				
				return false;
			}
		}
var promoCode = {
	minExp : 100,
	expValue : 10,
	value : 0,
	inputKeyup : function(name){
		this.name = name;
		this.value = parseInt(jQuery('#promocodeValue').html());
		this.exp = parseInt(jQuery('#expValue').html());
		this.total = parseInt(jQuery('#totalArtValue').html());
		this.test();
		
	},
	test : function(){
		jQuery.get('/test.php?promoCode='+this.name,{},function(d){
			d = eval('('+d+')');
			promoCode.value = d.value;
			
			jQuery('#totalArtValue').css({color:'#000'});
			jQuery('#promoCodeInput').css({color:'#000'});
			
			if(promoCode.total-promoCode.value<=promoCode.minExp){
				promoCode.exp = promoCode.expValue;
			}
			else{
				promoCode.exp = 0;
			}
			if(d.valid){
				jQuery('#promoCodeProbe').html('Code-promo valide');
			}
			else{
				jQuery('#promoCodeInput').css({color:'#f00'});
				jQuery('#promoCodeProbe').html('Code-promo invalide ou pas encore activé');
				promoCode.value=0;
			}
			
			if(promoCode.value>0 && promoCode.total<=promoCode.value*5){
				jQuery('#totalArtValue').css({color:'#f00'});
				jQuery('#promoCodeProbe').html('Ce code-promo ne peut être utilisé que pour une commande dont le montant dépasse '+(promoCode.value*5)+' euro.');
				promoCode.value=0;
			}
			
			jQuery('#expValue').html(!promoCode.exp?'0':promoCode.exp);
			jQuery('#promocodeValue').html(!promoCode.value?'0':promoCode.value);
			jQuery('#totalCmd').html(promoCode.total-promoCode.value+promoCode.exp);
		});
	}
};
var stopAffaire = {
   select : function(that){
      if(that.id=="type_a_cross"){
         jQuery('#typeStop').html('CROSS');
         jQuery('.a_type_cross').show();
         jQuery('.a_type_route').hide();
      }
      else{
         jQuery('#typeStop').html('ROUTE');
         jQuery('.a_type_cross').hide();
         jQuery('.a_type_route').show();
      }
      return false;
   }

}

shuffle = function(o){ 
	for(var j, x, i = o.length; i; j = parseInt(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
	return o;
};
//531x169
if(pubs==undefined){
	var pubs = [
		{src:'/img/pub/botflyfinishjpg.jpg',href:'http://www.discount-moto.com/articles/cross-bottes/fly.html'},
		{src:'/img/pub/contactbleujpgdiscount.jpg',href:'http://www.discount-moto.com/articles/liste-shot.html'},
		{src:'/img/pub/dcsacjpgdiscount.jpg',href:'http://www.discount-moto.com/articles/sportswear-sac-a-dos.html'},
		{src:'/img/pub/dctravisblockjpgdiscount.jpg',href:'http://www.discount-moto.com/articles/sportswear-chaussures.html'},
		{src:'/img/pub/dcvulcetsurgejpgdiscount.jpg',href:'http://www.discount-moto.com/articles/sportswear-chaussures.html'},
		{src:'/img/pub/pubfirstfffinishjpegdisc.jpg',href:'http://www.discount-moto.com/articles/cross-bottes/firstracing.html'},
		{src:'/img/pub/roadfinishjpgdiscount.jpg',href:'http://www.discount-moto.com/articles/course.php'},
		{src:'/img/pub/vestdc2jpgdiscount.jpg',href:'http://www.discount-moto.com/articles/sportswear-blouson.html'}
		,{src:'/img/pub/vestedc1jpgdiscount.jpg',href:'http://www.discount-moto.com/articles/sportswear-blouson.html'}
		,{src:'/img/pub/fox_covert.jpg',href:'/articles/details-2367.html'}
		//,{src:'/img/pub/foxmonster.png',href:'/articles/details-2512.html'}
		,{src:'/img/pub/pub2.jpg',href:'/articles/details-2156.html'}
		
		,{src:'/img/pub/casqflyjpgdiscount.jpg',href:'http://www.discount-moto.com/articles/cross-casque-cross/fly.html'}
		,{src:'/img/pub/giletshotjpgdiscount.jpg',href:'http://www.discount-moto.com/articles/cross-protections/shot.html'}
		,{src:'/img/pub/packdevojpgdiscount.jpg',href:'http://www.discount-moto.com/articles/cross-ensemble-cross/shot.html'}
		,{src:'/img/pub/PACKFLYENFANTjpgdiscount.jpg',href:'http://www.discount-moto.com/articles/cross-ensemble-cross/fly.html'}
		,{src:'/img/pub/packrockstarjpgdiscount.jpg',href:'http://www.discount-moto.com/articles/details-2366.html'}
		,{src:'/img/pub/packunderrosejpgdiscount.jpg',href:'http://www.discount-moto.com/articles/details-2375.html'}
		,{src:'/img/pub/TITANDISCGRANDJPGDISCOUNT.jpg',href:'http://www.discount-moto.com/articles/cross-protections/fox.html'}
		,{src:'/img/pub/V3MONSTERJPGDISCOUNT.jpg',href:'http://www.discount-moto.com/articles/details-2296.html'}
		/*
		
		,{src:'/img/pub/pub1.jpg',href:'/articles/details-2156.html'}
		,{src:'/img/pub/pub3.jpg',href:'/articles/details-2156.html'}
		,{src:'/img/pub/pub4.jpg',href:'/articles/details-2156.html'}
		,{src:'/img/pub/dcshoe.jpg',href:'/articles/details-2156.html'}
		,{src:'/img/pub/calbute.png',href:'/articles/details-2156.html'}
		,{src:'/img/pub/foxcomp5.jpg',href:'/articles/details-2156.html'}
		,{src:'/img/pub/06.jpg',href:'/articles/details-2156.html'}
		,{src:'/img/pub/07.jpg',href:'/articles/details-2156.html'}
		*/
	];
}
	pubs = shuffle(pubs);
	var pub = {
		id : 'pubPlaceHolder',
		current : 0,
		timeout : 5000,
		speed : 1500,
		nb : pubs.length,
		//cadreImg : 'cadreorange.png',
		cadreImg : 'cadresolde.png',
		init : function(){
			jQuery('#'+pub.id)
			.css({
					width:'599px',
					height:'280px',
					overflow:'hidden'
			})
			.html(
				'<div style="cursor:pointer;position:relative;background:url(/img/'+pub.cadreImg+') no-repeat top left;width:599px;height:280px;z-index:3"><a href="#nowheretogo" onclick="document.location=document.getElementById(\''+pub.id+'linkPub\').href;return false;" style="width:599px;height:280px;display:block"></a></div><a href="'+pubs[0].href+'" id="'+pub.id+'linkPub" style="display:inline-block;width:488px;height:169px;background:url(/img/wait.gif) no-repeat center center;z-index:1;position:relative;top:-225px;left:0px;"><img  alt="" id="'+pub.id+'imgPub" style="width:488px;height:169px;position:absolute;left:0;"/><img  alt="" id="'+pub.id+'imgPub2" style="width:488px;height:169px;position:absolute;left:0;"/></a>'
			);
			
			document.getElementById(pub.id+'imgPub2').onload =document.getElementById(pub.id+'imgPub').onload = function(){			
				jQuery('#'+pub.id+'imgPub'+pub.mod).fadeIn();
				jQuery('#'+pub.id+'linkPub').attr('href',pubs[pub.current].href);
				jQuery('#'+pub.id+'imgPub'+pub.nmod).fadeOut(pub.speed,function(){
					
					pub.tm=setTimeout(pub.next,pub.timeout);
					jQuery('#'+pub.id+'imgPub'+pub.nmod).css('zIndex',1);
					jQuery('#'+pub.id+'imgPub'+pub.mod).css('zIndex',2);
				});
			}
			this.next();
		},
		tm:null,
		next : function(){		
			pub.tm = null;
			pub.current++;
			if(pub.current==pub.nb){
				pub.current = 0;
			}
			pub.mod = '';
			if(pub.current%2!=0){
				pub.mod = 2;
			}
			pub.nmod = 2;
			if(pub.current%2!=0){
				pub.nmod = '';
			}
			jQuery('#'+pub.id+'imgPub'+pub.mod).attr('src',pubs[pub.current].src);
		}
	};

