function show_page_accessoire(page, total_page) {
	var old_page = parseInt($("#current_pagination").html());

	$('#page'+old_page).hide();

	$('#page'+page).show();

	$("#current_pagination").html(page);
	
	pagination_accessoire(total_page);
}

function pagination_accessoire(total_page) {
	var current_page = parseInt($("#current_pagination").html());
	
	if(current_page>5) min_page = current_page - 5;
	else min_page = 1;
	
	if(current_page > total_page-5) max_page = total_page;
	else max_page = current_page + 5;

	html = '';
	
	min_page = 1;

	if (total_page > 1) {
		if (current_page > min_page) {
			var prevpage = current_page - 1;
	
			$('#link_prev_pagination_accessoires').unbind();
	
			$('#link_prev_pagination_accessoires').click(function(){ 
				show_page_accessoire(prevpage, total_page);
			});

			$('#prev_pagination_accessoires').show();
		}
		else
		{
			$('#prev_pagination_accessoires').hide();
		}
	
		html += '<p class="liste_complementaire">';
		for(i = min_page;i <= max_page;i++) {
			if (i > min_page) html += '&nbsp;<span class="texte_complementaire">-</span>&nbsp;';
			if(i == current_page) html += '<a href="javascript:;" onclick="show_page_accessoire('+i+', '+total_page+')" class="lien_complementaires2">'+i+'</a>';
			else html += '<a href="javascript:;" onclick="show_page_accessoire('+i+', '+total_page+')" class="lien_complementaires">'+i+'</a>';
		}
		html += '</p>';
	
		if (current_page < total_page) {
			var nextpage = current_page + 1;
	
			$('#link_next_pagination_accessoires').unbind();
	
			$('#link_next_pagination_accessoires').click(function(){ 
				show_page_accessoire(nextpage, total_page);
			});

			$('#next_pagination_accessoires').show();
		}
		else
		{
			$('#next_pagination_accessoires').hide();
		}
	}
	else
	{
		$('#prev_pagination_accessoires').hide();
		$('#next_pagination_accessoires').hide();
	}

	$("#list_pagination_accessoires").html(html);
}

function show_page(page, total_page) {
	var old_page = parseInt($("#current_pagination").html());

	$('#page'+old_page).hide();

	$('#page'+page).show();

	$("#current_pagination").html(page);
	
	pagination(total_page);
}

function pagination(total_page) {
	var current_page = parseInt($("#current_pagination").html());
	
	html = '';
	
	min_page = 1;

	if (total_page > 1) {
		if (current_page > min_page) {
			var prevpage = current_page - 1;
	
			html += '<a href="#" onclick="show_page('+prevpage+', '+total_page+')">&lt;</a>&nbsp;';	
		}
	
		for(i = min_page;i <= total_page;i++) {
			if (i > min_page) html += '&nbsp;-&nbsp;';
			if(i == current_page) html += '<a href="#" onclick="show_page('+i+', '+total_page+')" style="text-decoration:underline;">'+i+'</a>';
			else html += '<a href="#" onclick="show_page('+i+', '+total_page+')">'+i+'</a>';
		}
	
		if (current_page < total_page) {
			var nextpage = current_page + 1;
	
			html += '&nbsp;<a href="#" onclick="show_page('+nextpage+', '+total_page+')">&gt;</a>';	
		}
	}

	$("#pagination").html(html);
}

function visibilite_livraison(thingId){
	var targetElement = document.getElementById(thingId) ;
  
	if (targetElement != null) {
		if (targetElement.style.display == 'none') {
			targetElement.style.display = '';
			document.getElementById('type_adresse_liv').value = "2";
		}
		else
		{
			targetElement.style.display = 'none';
			document.getElementById('type_adresse_liv').value = '1';
		}
	}
}

function visibilite2(thingId){
	if ($("#"+thingId) != null) {
		$("#"+thingId).css("visibility");
		if ($("#"+thingId).css("visibility") == "hidden") {
			$("#"+thingId).css("visibility","visible");
		}
		else
		{
			$("#"+thingId).css("visibility","hidden");
		}
	}
}

function autresvues(n, m){
	$('#image_produit_1_'+m).hide();

	$('#image_produit_1_'+n).show();

	$("#current_vue").html(n);

}

function affvue() {
	var n = parseInt($("#current_vue").html());

	$('#autre_vues_'+n).toggle();
}

//Hover
function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function demarche(page) {
		window.open(page,'demarche','width=400,height=400,toolbar=false,scrollbars=false');	
}



function calculette(page) {
		var domaineInitial = "https://www.1euro.com/1euro/calculetteTEG.do";
		var domaineRedirection = "http://www.box1euro.com/calculatrice/calculette1euro.php5";
		if(page.indexOf(domaineInitial) != -1) {
			var parametresUrlInitiale = page.substr(page.indexOf(domaineInitial) + domaineInitial.length,page.length);		
			var urlRedirection = domaineRedirection + parametresUrlInitiale;
			window.open(urlRedirection,'calculette','width=600,height=500,toolbar=false,scrollbars=false');	
		}
		else {
			window.open(page,'calculette','width=600,height=500,toolbar=false,scrollbars=false');		
		}
}

function calculetteOld(page) {
		window.open(page,'calculette','width=600,height=600,toolbar=false,scrollbars=false');	
}
