function addEvent(elem,event,name_function) {

	if(document.all) elem.attachEvent("on"+event,name_function);
	else elem.addEventListener(event,name_function,false);

}

function delEvent(elem,event,name_function) {

	if(document.all) elem.detachEvent("on"+event,name_function);
	else elem.removeEventListener(event,name_function,false);

}

function showmodal(produit_id){
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById('modbox');
	var cmodbox = document.getElementById('cmodbox');
	var panmodbox = document.getElementById('panmodbox');
	var shad = document.getElementById('shad');
	document.body.style.overflow='hidden';
	
	cmodbox.innerHTML='';
	panmodbox.innerHTML = '';
	
	modbox.style.marginTop = (actualposition-260)+"px";
	shad.style.display="block"; 
	modbox.style.display="block"; 
	document.getElementsByTagName("html")[0].style.overflow = "hidden"; 
	
	window.scrollTo(0,actualposition);		
	
}
function newshowmodal(produit_designation, nb_panier, type, path_web){
	var elname = 'modbox';
	
	if (type == 'err') {
		
		elname = 'errbox';
		
	}
	
	//Gestion probleme FF2 avec le menu qui passe sur la popup
	if(navigator.userAgent.indexOf('Firefox/2') != -1) {
		var tab_menu = document.getElementsByClassName('child');
		for(var i = 0 ; i<tab_menu.length ; i++){
			tab_menu[i].style.position = "static";
		}
	}
	
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById(elname);
	var cmodbox = document.getElementById('cmodbox');
	var panmodbox = document.getElementById('panmodbox');
	var shad = document.getElementById('shad');
	//document.body.style.overflow='hidden';
	
	array_produit_designation = produit_designation.split(' - ');
	
	if (type != 'err') {
		var popup_label = '<b>' + array_produit_designation[0];
		
		if ( array_produit_designation[2] ) {
		
			popup_label += ' ' + array_produit_designation[2];
			 
		}
		
		if ( array_produit_designation[1] ) {
		
			popup_label +=  '<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;' + array_produit_designation[1] + '</b>';
		
		}
			 
		cmodbox.innerHTML = popup_label;
		
		if (nb_panier == '1') {
			
			panmodbox.innerHTML = nb_panier + ' ' + ajax_file(path_web+'ajax_sprintf.php?arg1=one_article');
			
		} else {
			
			panmodbox.innerHTML = nb_panier + ' ' + ajax_file(path_web+'ajax_sprintf.php?arg1=2_article');
		}
	}
	shad.style.display="block"; 
	modbox.style.display="block"; 
	
	window.scrollTo(0,actualposition);		
}
function showsendfriendmodal(product_id, path_web){
	var elname = 'sendfriendbox';
	
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById(elname);
	var shad = document.getElementById('shad');
	//document.body.style.overflow='hidden';
	
	
	//Gestion probleme FF2 avec le menu qui passe sur la popup
	if(navigator.userAgent.indexOf('Firefox/2') != -1) {
		var tab_menu = document.getElementsByClassName('child');
		for(var i = 0 ; i<tab_menu.length ; i++){
			tab_menu[i].style.position = "static";
		}
	}
	
	document.getElementById('product_sendfriend_nok').innerHTML='';
	document.getElementById('product_sendfriend_ok').innerHTML='';
	document.getElementById('product_sendfriend_nok').style.display='none';
	document.getElementById('product_sendfriend_ok').style.display='none';
	
	prodGetProductDisplay( product_id, path_web );
	
	shad.style.display="block"; 
	modbox.style.display="block"; 
	
	addEvent(shad,'click',closesendfriendmodal);
	
	window.scrollTo(0,actualposition);		
}
function closesendfriendmodal() {
	var modbox = document.getElementById('sendfriendbox');
	var shad = document.getElementById('shad');
	modbox.style.marginLeft='';
	shad.style.display="none"; 
	modbox.style.display="none"; 
	document.body.style.overflow='';
	document.getElementsByTagName("html")[0].style.overflow = ""; 
	
	delEvent(shad,'click',closesendfriendmodal);
	
	if ( navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('6.') != -1 ) {
		
		var svn=document.getElementsByTagName("SELECT");
		for (a=0;a<svn.length;a++){
			svn[a].style.visibility="visible";
		}
		
	}
	
	//Gestion probleme FF2 avec le menu qui passe sur la popup
	if(navigator.userAgent.indexOf('Firefox/2') != -1) {
		var tab_menu = document.getElementsByClassName('child');
		for(var i = 0 ; i<tab_menu.length ; i++){
			tab_menu[i].style.position = "relative";
		}
	}
}

function closesendfriendmodalfromconfirm() {
	var modbox = document.getElementById('sendfriendbox');
	var shad = document.getElementById('shad');
	modbox.style.marginLeft='';
	shad.style.display="none"; 
	modbox.style.display="none"; 
	document.body.style.overflow='';
	document.getElementsByTagName("html")[0].style.overflow = ""; 
	document.getElementById('sendfriend_prodinfos').style.display="block";
	document.getElementById('sendfriend_form_to').style.display="block";
	document.getElementById('sendfriend_form_froms').style.display="block";
	document.getElementById('sendfriend_form_buttons').style.display="block";
	document.getElementById('sendfriend_form_needed').style.display="block";
	document.getElementById('sendfriend_alert_mail').innerHTML="";
	
	delEvent(shad,'click',closesendfriendmodal);
	
	if ( navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('6.') != -1 ) {
		
		var svn=document.getElementsByTagName("SELECT");
		for (a=0;a<svn.length;a++){
			svn[a].style.visibility="visible";
		}
		
	}
	
	//Gestion probleme FF2 avec le menu qui passe sur la popup
	if(navigator.userAgent.indexOf('Firefox/2') != -1) {
		var tab_menu = document.getElementsByClassName('child');
		for(var i = 0 ; i<tab_menu.length ; i++){
			tab_menu[i].style.position = "relative";
		}
	}
		
}
function closemodal() {
	var modbox = document.getElementById('modbox');
	var errbox = document.getElementById('errbox');
	var cmodbox = document.getElementById('cmodbox');
	var shad = document.getElementById('shad');
	cmodbox.innerHTML='';
	modbox.style.marginLeft='';
	shad.style.display="none"; 
	modbox.style.display="none"; 
	errbox.style.display="none"; 
	document.body.style.overflow='';
	document.getElementsByTagName("html")[0].style.overflow = ""; 
	
	if ( navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('6.') != -1 ) {
		
		var svn=document.getElementsByTagName("SELECT");
		for (a=0;a<svn.length;a++){
			svn[a].style.visibility="visible";
		}
		
	}
	
	//Gestion probleme FF2 avec le menu qui passe sur la popup
	if(navigator.userAgent.indexOf('Firefox/2') != -1) {
		var tab_menu = document.getElementsByClassName('child');
		for(var i = 0 ; i<tab_menu.length ; i++){
			tab_menu[i].style.position = "relative";
		}
	}
	
}
/*
function addToBasket(produit_id, suff, isAssoc, basket_id, page_name, path_web, enable_omniture) {
	var panier_id = basket_id;
	
	var array_panier = newUpdatePanier(produit_id, suff, panier_id, document.getElementById('prixU').value, isAssoc, path_web);
	
	if (array_panier != false) {
		var type = '';
		
		
		if (array_panier[1] == 'false' || array_panier.length == 0) {
			
			type = 'err';
			
		}
		
		omnitureEvent = '';
		
		if (array_panier[1] == 0) {
			
			document.getElementById('panier_prix').innerHTML = ajax_file(path_web+'ajax_sprintf.php?arg1=basket_empty');
			document.getElementById('panier_prix').style.paddingTop='0px';
			document.getElementById('panier_prix').style.paddingLeft='12px';
			omnitureEvent = '';
			
		} else if (array_panier[1] == 1) {
			
			document.getElementById('panier_prix').innerHTML = ajax_file(path_web+'ajax_sprintf.php?arg1=basket_content_1&arg2=panier_prix&arg3=' + path_web + '&arg4=panier_txt&arg5=' + array_panier[1]);
			/*document.getElementById('panier_prix').style.paddingTop='10px';
			document.getElementById('panier_prix').style.paddingLeft='0px';*/
		/*	omnitureEvent = 'scOpen,scAdd'; // le premier produit ajouté au panier 
			
		} else {
			
			document.getElementById('panier_prix').innerHTML = ajax_file(path_web+'ajax_sprintf.php?arg1=basket_content_2&arg2=panier_prix&arg3=' + path_web + '&arg4=panier_txt&arg5=' + array_panier[1]);
			/*document.getElementById('panier_prix').style.paddingTop='10px';
			document.getElementById('panier_prix').style.paddingLeft='0px';*/
		/*	omnitureEvent = 'scAdd'; // il y a déjà un produit au panier
			
		}
		
		if (array_panier[1] > 0 && enable_omniture == true) {
			
			void(s.t());
			s.pageName	= "'" + page_name + "'";
            s.products	= ";" + produit_id;
            s.events	= omnitureEvent;				
			void(s.t());				
			
		}
		
		
		document.getElementById('total_euros_panier').innerHTML = ajax_file(path_web+'ajax_sprintf.php?arg1=total') + ' ' + array_panier[2];
	
		newshowmodal(array_panier[0], array_panier[1], type, path_web);
	}
	
	return false;
	
}*/

function addToBasket(produit_id, suff, isAssoc, panier_id, titreObjet, idTaille, lastTaille, idCouleur, lastCouleur, idQte, toEval, page_name, path_web, enable_omniture) {
	//var panier_id = basket_id;
	var array_panier = newUpdatePanier(produit_id, suff, panier_id, document.getElementById('prixU').value, isAssoc, path_web, titreObjet, idTaille, lastTaille, idCouleur, lastCouleur, idQte);
	
	if (array_panier != false) {
		var type = '';
		
		
		if (array_panier[1] == 'false' || array_panier.length == 0) {
			
			type = 'err';
			
		}
		
		omnitureEvent = '';
		
		if (array_panier[1] == 0) {
			
			document.getElementById('panier_prix').innerHTML = ajax_file(path_web+'ajax_sprintf.php?arg1=basket_empty');
			document.getElementById('panier_prix').style.paddingTop='0px';
			document.getElementById('panier_prix').style.paddingLeft='12px';
			omnitureEvent = '';
			
		} else if (array_panier[1] == 1) {
			
			document.getElementById('panier_prix').innerHTML = ajax_file(path_web+'ajax_sprintf.php?arg1=basket_content_1&arg2=panier_prix&arg3=' + path_web + '&arg4=panier_txt&arg5=' + array_panier[1]);
			//document.getElementById('panier_prix').style.textAlign = 'left';
			omnitureEvent = 'scOpen,scAdd'; // le premier produit ajouté au panier 
			
		} else {
			
			document.getElementById('panier_prix').innerHTML = ajax_file(path_web+'ajax_sprintf.php?arg1=basket_content_2&arg2=panier_prix&arg3=' + path_web + '&arg4=panier_txt&arg5=' + array_panier[1]);
			//document.getElementById('panier_prix').style.textAlign = 'left';
			omnitureEvent = 'scAdd'; // il y a déjà un produit au panier
			
		}
		
		if (array_panier[1] > 0 && enable_omniture == true) {
			
			void(s.t());
			s.pageName	= "'" + page_name + "'";
            s.products	= ";" + produit_id;
            s.events	= omnitureEvent;				
			void(s.t());				
			
		}
		
		
		document.getElementById('total_euros_panier').innerHTML = ajax_file(path_web+'ajax_sprintf.php?arg1=total')+'&nbsp;'+array_panier[2]+'&nbsp;&euro;';

		newshowmodal(array_panier[0], array_panier[1], type, path_web);
	}
	
	eval(toEval);
	
	if (array_panier != false) {
		if ( navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('6.') != -1 ) {
		
			var svn=document.getElementsByTagName("SELECT");
			for (a=0;a<svn.length;a++){
				svn[a].style.visibility="hidden";
			}
			
		}
	
	}
	
	return false;
	
}
function displayOnglet ( pDiv ){
	
	if ( pDiv == "ongletSavoirPlus" ) {
		if ( document.getElementById('ongletCaracteristiques') )
			document.getElementById('ongletCaracteristiques').style.display ='none';
		if ( document.getElementById('ongletGammes') )
			document.getElementById('ongletGammes').style.display ='none';
		if ( document.getElementById('ongletAssociations') )
			document.getElementById('ongletAssociations').style.display ='none';
	}
	
	if ( pDiv == "ongletCaracteristiques" ) {
		if ( document.getElementById('ongletSavoirPlus') )
			document.getElementById('ongletSavoirPlus').style.display ='none';
		if ( document.getElementById('ongletGammes') )
			document.getElementById('ongletGammes').style.display ='none';
		if ( document.getElementById('ongletAssociations') )
			document.getElementById('ongletAssociations').style.display ='none';
	}
	
	if ( pDiv == "ongletGammes" ) {
		if ( document.getElementById('ongletCaracteristiques') )
			document.getElementById('ongletCaracteristiques').style.display ='none';
		if ( document.getElementById('ongletSavoirPlus') )
			document.getElementById('ongletSavoirPlus').style.display ='none';
		if ( document.getElementById('ongletAssociations') )
			document.getElementById('ongletAssociations').style.display ='none';
	}
	
	if ( pDiv == "ongletAssociations" ) {
		if ( document.getElementById('ongletCaracteristiques') )
			document.getElementById('ongletCaracteristiques').style.display ='none';
		if ( document.getElementById('ongletSavoirPlus') )
			document.getElementById('ongletSavoirPlus').style.display ='none';
		if ( document.getElementById('ongletGammes') )
			document.getElementById('ongletGammes').style.display ='none';
	}
			
		
	document.getElementById(pDiv).style.display ='block';					
	
}

function displayZoom ( picture, product_ref, path_web, picture_medium, picture_mini, photo_path, photo_list ){
	
	var so = new SWFObject(path_web + "zoom.swf", "zoom", "405", "610", "8", "#FFFFFF");
	so.addParam("wmode", "transparent");
	so.addParam("allowScriptAccess", "always");
	so.addVariable("produit_id", product_ref);
	so.addVariable("url", path_web);

	so.addVariable("photo_path_medium", picture_medium);
	so.addVariable("photo_path_mini", picture_mini);

	so.addVariable("photo_path", photo_path);

	so.addVariable("photo_list", photo_list);
	so.addVariable("img_defaut", picture);
	so.write("flashVisuel");

}

function zoom( picture, product_ref, path_web, picture_medium, picture_mini, photo_path, photo_list ){
	
	displayZoom( picture, product_ref, path_web, picture_medium, picture_mini, photo_path, photo_list );
	
}

function productSendFriendForm( path_web, request_uri ) {
	
	document.getElementById("product_sendfriend_ok").style.display = 'block';
	document.getElementById("product_sendfriend_nok").style.display = 'block';
	
	//var content = "<p style=\"margin: 0px;padding: 0px;\">L'e-mail n'a pas pu être envoyé à votre ami.</p>";
	var content_id = "product_sendfriend_nok";
	
	if ( document.getElementById('sendFriendToMails') && document.getElementById('sendFriendToMessage') && document.getElementById('sendFriendYourName') && document.getElementById('sendFriendYourMail') && document.getElementById('sendFriendCopy') ) {
		document.getElementById('sendFriendToMails').style.border="";
		document.getElementById('sendFriendToMessage').style.border="";
		document.getElementById('sendFriendYourName').style.border="";
		document.getElementById('sendFriendYourMail').style.border="";
		var response = ajax_file( path_web + 'ajax_send_friend_form.php?url=' + request_uri + '&to_mails=' + document.getElementById('sendFriendToMails').value + '&to_message=' + document.getElementById('sendFriendToMessage').value + '&your_name=' + document.getElementById('sendFriendYourName').value + '&your_mail=' + document.getElementById('sendFriendYourMail').value + '&copy=' + document.getElementById('sendFriendCopy').checked );
		
		if ( response.split(',')[0] == 'ok' ) {
			
			var s_adresse = response.substr(3);
			
			var sing = (response.split(',').length>2)? 'sendfriend_ok_plur' : 'sendfriend_ok_sing';
			
			var content = '<div style="color:#75088D;text-align:center;margin-bottom:10px;margin-top:15px;">'+ajax_file(path_web+'ajax_sprintf.php?arg1='+sing)+'</div>';
			content += '<p style=\"margin: 0px;padding:0;text-align:center;\">'+s_adresse+'</p>';
			
			var content_id = "sendfriend_alert_mail";
			document.getElementById('product_sendfriend_nok').innerHTML="";
			document.getElementById('sendfriend_prodinfos').style.display="none";
			document.getElementById('sendfriend_form_to').style.display="none";
			document.getElementById('sendfriend_form_froms').style.display="none";
			document.getElementById('sendfriend_form_buttons').style.display="none";
			document.getElementById('sendfriend_form_needed').style.display="none";
			
		} else if (response == '1' ) {
			
			var content = "<p style=\"margin: 0px;padding: 0px;\">" + ajax_file(path_web+'ajax_sprintf.php?arg1=sendfriend_error_no_mail_friends') + "</p>";
			document.getElementById('sendFriendToMails').style.border="1px #AA0000 solid";
			
		} else if (response == '2' ) {
			
			var content = "<p style=\"margin: 0px;padding: 0px;\">" + ajax_file(path_web+'ajax_sprintf.php?arg1=sendfriend_error_mail_friends_invalid') + "</p>";
			document.getElementById('sendFriendToMails').style.border="1px #AA0000 solid";
			
		} else if (response == '3' ) {
			
			var content = "<p style=\"margin: 0px;padding: 0px;\">" + ajax_file(path_web+'ajax_sprintf.php?arg1=sendfriend_error_no_message') + "</p>";
			document.getElementById('sendFriendToMessage').style.border="1px #AA0000 solid";
			
		} else if (response == '4' ) {
			
			var content = "<p style=\"margin: 0px;padding: 0px;\">" + ajax_file(path_web+'ajax_sprintf.php?arg1=sendfriend_error_no_name') + "</p>";
			document.getElementById('sendFriendYourName').style.border="1px #AA0000 solid";
			
		} else if (response == '5' ) {
			
			var content = "<p style=\"margin: 0px;padding: 0px;\">" + ajax_file(path_web+'ajax_sprintf.php?arg1=sendfriend_error_name_invalid') + "</p>";
			document.getElementById('sendFriendYourName').style.border="1px #AA0000 solid";
			
		}
		else{
			var sing = (response.split(',').length>2)? 'sendfriend_ok_plur' : 'sendfriend_ok_sing';
			
			var content = '<div style="color:#75088D;text-align:center;margin-bottom:10px;margin-top:15px;">'+ajax_file(path_web+'ajax_sprintf.php?arg1='+sing)+'</div>';
			var content_id = "sendfriend_alert_mail";
			content += '<p style="margin:0;padding-top:20px;text-align:center;"><a onclick="closesendfriendmodalfromconfirm()" href="#"><img class="no_border" src="'+path_web+'img/bt_fermer.gif" /></a><p>';
			
			document.getElementById('product_sendfriend_nok').innerHTML="";
			document.getElementById('sendfriend_prodinfos').style.display="none";
			document.getElementById('sendfriend_form_to').style.display="none";
			document.getElementById('sendfriend_form_froms').style.display="none";
			document.getElementById('sendfriend_form_buttons').style.display="none";
			document.getElementById('sendfriend_form_needed').style.display="none";
		}
		
	}
	document.getElementById(content_id).innerHTML = content;
	document.getElementById(content_id).style.display = 'block';
	
	return false;
}
function prodGetProductDisplay( id, path_web ) {
	
	var response = ajax_file( path_web + 'ajax_get_infos_send_friend.php?product_id=' +id );
	document.getElementById('sendfriend_prodinfos').innerHTML = response;
	
	if ( navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('6.') != -1 ) {
			
		var svn=document.getElementsByTagName("SELECT");
		for (a=0;a<svn.length;a++){
			svn[a].style.visibility="hidden";
		}
		
	}
	
}
function zoomImg( photo ){

	var elname = 'zoomBox';
	
	var actualposition = document.documentElement.scrollTop ;
	var modbox = document.getElementById(elname);
	var shad = document.getElementById('shad');
	
    modbox.style.position = "absolute";
	shad.style.display="block";
	modbox.style.display="block";
	
	modbox.innerHTML = '<img class="no_border" onClick="closeZoom()" style="cursor:pointer;border:7px solid #fff;" alt="" src="'+photo+'" id="photo_zoom" />';

	var el_zoom_pic = document.getElementById('photo_zoom');

	var myImage = new Image();
	myImage.src = photo;

    myImage.onload = function()
    {
       var el_zoom_pic_width = myImage.width;
       el_zoom_pic_width_demi = (el_zoom_pic_width)/ 2;
  	   modbox.style.marginTop = "-170px";
       modbox.style.marginLeft = "-" + el_zoom_pic_width_demi + "px";
    }
      
	window.scrollTo(0,actualposition);
	
	addEvent(shad,'click',closeZoom);
	addEvent(modbox,'click',closeZoom);
	
	if ( navigator.userAgent.indexOf('MSIE') != -1 && navigator.userAgent.indexOf('6.') != -1 ) {		
		var svn=document.getElementsByTagName("SELECT");
		for (a=0;a<svn.length;a++){
			svn[a].style.visibility="hidden";
		}		
	}
}

function closeZoom(){

	var elname = 'zoomBox';
	var modbox = document.getElementById(elname);
	var shad = document.getElementById('shad');
	modbox.style.display="";
	
	delEvent(shad,'click',closeZoom);
	delEvent(modbox,'click',closeZoom);
	
	closemodal();
	
}

/*
function updateSrc() {

	var tmp_string = document.getElementById('img_large').src;
	tmp_string = tmp_string.replace(/medium/,"large");
	
	document.getElementById('loupe').href = 'javascript:zoomImg(\''+tmp_string+'\');';

}*/

function defilImg(sens) {
	
	if(sens == 'gauche') {
		if(cpt_img!=0) cpt_img--;
		else cpt_img = tab_js.length-1;
	}
	else {
		if(cpt_img<tab_js.length-1) cpt_img++;
		else cpt_img = 0;
	}
	
	changeVisu('img_large',tab_js[cpt_img][0],tab_js[cpt_img][1]);
	updateSrc();
	
}

function updateSrc(dest) {

	var tmp_string = document.getElementById('img_large').src;
	tmp_string = tmp_string.replace(/medium/,"large");
	
	document.getElementById('loupe').href = 'javascript:zoomImg(\''+tmp_string+'\');';
	document.getElementById('img_large').setAttribute('jqimg',tmp_string);
	
	
	if(dest=='vue') {
		
		var i = 0;
		var trouve = false;
		while (i<tab_js.length && !trouve) {
			
			trouve = (tab_js[i][0].substring(tab_js[i][0].lastIndexOf('/')+1)==tmp_string.substring(tmp_string.lastIndexOf('/')+1));
			i++;
		
		}
		
		cpt_img = (i-1);
		
	}

}