var Navigateur = navigator.appName;

if(Navigateur == "Microsoft Internet Explorer")
	var ie = true;
else
	var ie = false;

function popupimage(chemin)
{	
	var html;
	html = '<HTML>\n'
	+ '<HEAD>\n'
	+ '<TITLE>D&eacute;tail de la photo</TITLE>\n'
	+ '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">\n'
	+ '<link rel="stylesheet" href="/charte/style.css" type="text/css">\n'
	+ '</HEAD>\n'
	+ '<BODY onLoad="window.focus();window.resizeTo(document.imageTest.width+35,document.imageTest.height+90);" bgcolor="#FFFFFF" leftmargin="10" topmargin="10" marginwidth="10" marginheight="10">\n'
	+ '<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">\n'
	+ '<tr><td align="center" valign="middle">'
	+ '<img src="'+chemin+'" border="0" name="imageTest"></td></tr>\n'
	+ '</table>\n'
	+ '</BODY>\n'
	+ '</HTML>'
	
	var popup;
	popup = window.open('','popupgo','left=200,top=100,width=10,height=10,toolbar=0,location=0,directories=0,menuBar=0,scrollbars=0,resizable=0');
	popup.document.write(html);
	popup.document.close();
}



function SecureConfirm(obj)
{
	if(confirm('Voulez-vous supprimer votre adresse du carnet ?')) {
		return true;
	}else{
		return false;
	}
}

var fondDiv = false;
var dataDiv = false;

// Ajout newsletter
function addNewsletter(action, idForm) {

	if($(idForm)){
			new Ajax(
			'/js/ajax/newsletter.php',
			{
				method: 'get',
				data:$(idForm).toQueryString(),
				onSuccess: function(req) {
					var arr = req.split("|");
					if(arr[0]=="err"){
						$('msg_erreur_popup').style.display = "block";
						$('msg_ok_popup').style.display = "none";
						$('msg_erreur_popup').innerHTML = arr[1];
					}else{
						$('msg_ok_popup').style.display = "block";
						$('msg_erreur_popup').style.display = "none";
						$('txt_newsletter').style.display = "none";
						$('msg_ok_popup').innerHTML = arr[1];
					}	
				},
				evalScripts: true
			}
		).request();
	}else{
		
			if(!fondDiv){
				fondDiv = document.createElement('div');
				fondDiv.style.position = 'absolute';
				document.body.appendChild(fondDiv);
			}
			fondDiv.innerHTML = '';
		
			$(fondDiv).setStyles({
			   backgroundColor: '#000000',
			   width: '100%',
			   height: getScrollHeight(),
			   position: 'absolute',
			   opacity: '0.5',
			   overflow: 'hidden',
			   top: '0px',
			   zIndex: '1500',
			   visibility: 'hidden'
			});
		
			if(!dataDiv){
				dataDiv = document.createElement('div');
				dataDiv.style.position = 'absolute';
				document.body.appendChild(dataDiv);
			}
		
			$(dataDiv).setStyles({
			   background: '#ffffff url(/charte/images/popup/bg.png) no-repeat',
			   width: '380px',
			   /*height: '310px',*/
			   position: 'absolute',
			   border: '1px solid #000',
			   top: '50%',
			   left: '50%',	   
			   marginLeft: '-150px',	   
			   marginTop: (getScrollTop()-150) + 'px',	   	   	   
			   zIndex: '1600',
			   visibility: 'hidden'
			});
		
			new Ajax(
			'/js/ajax/newsletter.php',
			{
				method: 'get',
				update: dataDiv,
				onSuccess: function(req) {
					$$(fondDiv).setStyles({visibility: 'visible' });
					$$('select').setStyles({visibility: 'hidden' });
					$$(dataDiv).setStyles({visibility: 'visible' });			
				},
				evalScripts: true
			}
		).request();
	}
	
}

//ouvre popup-div : agrandissement image galerie
function popupGalerie(chemin)
{
	if(!fondDiv){
		fondDiv = document.createElement('div');
		fondDiv.style.position = 'absolute';
		document.body.appendChild(fondDiv);
	}
	fondDiv.innerHTML = '';

	$(fondDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '100%',
	   height: getScrollHeight(),
	   position: 'absolute',
	   opacity: '0.6',
	   overflow: 'hidden',
	   top: '0px',
	   zIndex: '1500',
	   visibility: 'visible'
	});

	if(!dataDiv){
		dataDiv = document.createElement('div');
		dataDiv.style.position = 'absolute';
		document.body.appendChild(dataDiv);

	}

	$(dataDiv).setStyles({
		 color: '#ffffff',
		 textAlign: 'right',
	   backgroundColor: '#ffffff',
	   position: 'absolute',
//	   border: '0px solid #fff',
	   top: '50%',
	   left: '50%', 
	   marginLeft: '-400px',	   
	   marginTop: (getScrollTop()-300) + 'px',	   	   	   
	   zIndex: '1600',
	   visibility: 'visible'
	});
	
	$(dataDiv).innerHTML = '<a onClick="javascript:fondDiv.style.display=\'none\'; dataDiv.style.display=\'none\'; fondDiv=0; dataDiv=0; return false;" href="#">Fermer</a>';
	$(dataDiv).innerHTML += "<br /><img style='border:2px #fff solid;' id='img' width='800' src='"+chemin+"' alt='"+chemin+"'/>";
}

// Ajout au panier
function addPanier(idForm)
{
	if(!fondDiv){
		fondDiv = document.createElement('div');
		fondDiv.style.position = 'absolute';
		document.body.appendChild(fondDiv);
	}
	fondDiv.innerHTML = '';

	$(fondDiv).setStyles({
	   backgroundColor: '#000000',
	   width: '100%',
	   height: getScrollHeight(),
	   position: 'absolute',
	   opacity: '0.5',
	   overflow: 'hidden',
	   top: '0px',
	   zIndex: '1500',
	   visibility: 'hidden'
	});

	if(!dataDiv){
		dataDiv = document.createElement('div');
		dataDiv.style.position = 'absolute';
		document.body.appendChild(dataDiv);
	}

	$(dataDiv).setStyles({
	   background: '#ffffff url(/charte/images/popup/bg.png) no-repeat',
	   width: '380px',
	   height: '310px',
	   position: 'absolute',
	   border: '1px solid #000',
	   top: '50%',
	   left: '50%',	   
	   marginLeft: '-150px',	   
	   marginTop: (getScrollTop()-150) + 'px',	   	   	   
	   zIndex: '1600',
	   visibility: 'hidden'
	});

	new Ajax(
		'/js/ajax/panier-change.php',
		{
			method: 'get',
			update: dataDiv,
			data:$(idForm).toQueryString(),
			onSuccess: function(req) {

					$$(fondDiv).setStyles({visibility: 'visible' });
					$$('select').setStyles({visibility: 'hidden' });
					$$(dataDiv).setStyles({visibility: 'visible' });
	
					new Ajax(
						'/js/ajax/updatePanier.php',
						{
							update: $('panier')
						}
					).request();
			},
			evalScripts: true
		}
	).request();
}

function removeDivPanier()
{
	if(fondDiv){
		$(fondDiv).remove();
		fondDiv = false;
	}	
	if(dataDiv){
		$(dataDiv).remove();
		dataDiv = false;
	}
	
	$$('select').setStyles({visibility: 'visible' });		
}

function getTop(deKoi)
{
	var obj = deKoi;
	var curleft = 0;

	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetTop;
			obj = obj.offsetParent;
		}
	}
	else
	{
		if (obj.y)
			curleft += obj.y;
	}

	return (curleft);
}

function getLeftImg(deKoi)
{
	var obj = deKoi;
	var curleft = 0;

	if (obj.offsetParent)
	{
		while (obj.offsetParent)
		{
			curleft += obj.offsetLeft;
			obj = obj.offsetParent;
		}
	}
	else
	{
		if (obj.x)
			curleft += obj.x;
	}

	return (curleft);
}

function showPreviewBig_home(idProd,imglist)
{

	div = 'prod'+idProd;
	
	vartop=getTop(imglist)-getTop($('conteneur_body'));
	varleft=getLeftImg(imglist)-getLeftImg($('conteneur_body'));
		
	$(div).style.top=vartop-135+105 + 'px';
	$(div).style.left=varleft-135+110 + 'px';
	$(div).style.display='block';	
}

function showPreviewBig(idProd,imglist)
{

	div = 'prod'+idProd;
	
	vartop=getTop(imglist)-getTop($('conteneur_body'));
	varleft=getLeftImg(imglist)-getLeftImg($('conteneur_body'));
		
	$(div).style.top=vartop-135+85 + 'px';
	$(div).style.left=varleft-135+85 + 'px';

	$(div).style.display='block';	
}


function cachePrevisu(idProd)
{
	div = 'prod' + idProd;
	$(div).style.display='none';	
}

function affichePromocode() {
	var div = document.getElementById('promocode');
	
	if(div.style.display=='block') {
		div.style.display='none'
	}else{
		div.style.display='block'
	}
}
function afficheCheque() {
	var div = document.getElementById('bonachatcadeau');
	
	if(div.style.display=='block') {
		div.style.display='none'
	}else{
		div.style.display='block'
	}
}
if(!edz_zooms) var edz_zooms = false;

function show_ss_menu(id) {
	if(edz_zooms)
	{
		if(edz_zooms._zoomCur) edz_zooms._zoomCur._divLoupe.style.display='none';
	}
	
	var d = document.getElementById(id);
		for (var i = 1; i<=17; i++) {
			if(document.getElementById('smenu'+i)) document.getElementById('smenu'+i).style.display='none';
		}
		
		if (d && id) {d.style.display='block';}
		
}

var Interval;
//window.onload = wl;
var iScroll=0;
function defileBas(param_scroll) {
	if(param_scroll==1)	iScroll=param_scroll;
	if(iScroll)
	{
		$('listeMarque').scrollTop+=1;
		setTimeout(defileBas, 10);
	}
}

function defileHaut(param_scroll) {
	if(param_scroll==1)	iScroll=param_scroll;
	if(iScroll)
	{
		$('listeMarque').scrollTop-=1;
		setTimeout(defileHaut, 10);
	}	
}

function defilePause() {
	iScroll=0;
}


function hideSelectPay(inputValue) {
	document.getElementById('blocMX').style.display='none';
	document.getElementById('blocCH').style.display='none';
	if(inputValue=='MX')
		document.getElementById('blocMX').style.display='inline';
	if(inputValue=='CH')
		document.getElementById('blocCH').style.display='inline';
}

/////////////////////////////////////////////////////////////////////////////////////
// FONCTIONS APPELLEES PAR L'APPLI FLASH STICKER
function flash_select_couleur(id_rang, id_coul){
	$('couleur_id_'+id_rang).value = id_coul;
}

function flash_select_taille(id_taille, indice, valeur){
	$('produit_attribut_id').value = id_taille;
	$('produit_attribut_indice').value = indice;
	$('produit_attribut_valeur').value = valeur;
}

function flash_select_sens(id_sens, nom_sens){
	$('sens_id').value = id_sens;
	$('sens_nom').value = nom_sens;
}

function flash_change_qte(nv_qte){
	$('qte').value = nv_qte;
}

function flash_send_form(){
	document.getElementById('add_produit').submit();
}
/////////////////////////////////////////////////////////////////////////////////////


/////////////////////////////////////////////////////////////////////////////////////
/* SELECT FICHE PRODUIT */
function select_couleur(obj, cpt, id_rang, id_coul, nom_coul){
	$('couleur_id_'+id_rang).value = id_coul;
	
	$('choix_couleur_'+id_rang).innerHTML = nom_coul;
	
	$$('#list_coul'+cpt+' li.active').removeClass('active');
	$(obj).addClass('active');
}

function survol_couleur(obj, cpt, id_rang, id_coul, nom_coul){
/*	$('couleur_id_'+id_rang).value = id_coul;*/
	
	$('choix_couleurs_'+id_rang).innerHTML = nom_coul;
}

function quit_couleur(id_rang) {
	$('choix_couleurs_'+id_rang).innerHTML = $('choix_couleur_'+id_rang).innerHTML;
}

/* SELECT FICHE PRODUIT */
function select_taille(obj, id_att, nom_att, desc_att, px_att, px_ss_promo){
	$('produit_attribut_id').value = id_att;
	$('produit_attribut_indice').value = nom_att;
	$('produit_attribut_valeur').value = desc_att;
	
	$('choix_taille').innerHTML = nom_att+' ('+desc_att+' cm)';
	
	
	$('prix_total').value = parseFloat(px_att).toFixed(2);
	
	qte=$('qte').value;
	nv_px=px_att*qte;
	$('choix_px_tot').innerHTML = parseFloat(nv_px).toFixed(2)+' &euro;';
	
	if(document.getElementById('choix_px_sspromo')){
		$('choix_px_sspromo').innerHTML = parseFloat(px_ss_promo).toFixed(2)+' &euro;';
	}
	
	$$('#list_att li.active').removeClass('active');
	$(obj).addClass('active');
	
}

/* SELECT FICHE PRODUIT */
function select_sens(obj, sens_id, sens_nom){
	$('sens_id').value = sens_id;
	$('sens_nom').value = sens_nom;
	
	$('choix_sens').innerHTML = sens_nom;
	
	$$('#list_sens li.active').removeClass('active');
	$(obj).addClass('active');
	
}

function change_qte(nv_qte, px_tot){
	px_nv=nv_qte*px_tot;
	$('choix_px_tot').innerHTML = parseFloat(px_nv).toFixed(2)+' &euro;';
}


//MENU OFFRE
jQuery(document).ready(function(){
	jQuery("#offreBtn").hover(
	  function () {
	    jQuery('.offreLien').slideDown();
	    jQuery('.offreFleche').css('background','url("../media/offre/fleche_close.png") no-repeat');
	  }, 
	  function () {
	    jQuery('.offreLien').css('display','block');
	  }
	);
});

jQuery(document).ready(function(){
	jQuery("#offre").hover(
	  function () {}, 
	  function () {
	    jQuery('.offreLien').slideUp();
	    jQuery('.offreFleche').css('background','url("../media/offre/fleche_open.png") no-repeat');
	  }
	);
});



/*
//MENU OFFRE avec derniere version mootools
window.addEvent('domready', function(){
	$('offreHover').addEvents({
		'mouseenter': function(){
			$("offre_fleche").style.backgroundImage = 'url("../media/offre/fleche_close.png")';
			this.set('tween', {
				duration: 1000,
				//transition: Fx.Transitions.Bounce.easeOut // effet
			}).tween('height', '243px');
		},
		'mouseleave': function(){
			$("offre_fleche").style.backgroundImage = 'url("../media/offre/fleche_open.png")';
			this.set('tween', {}).tween('height', '43px');
		}
	});
});
*/