function ShowImage(nParamPicto){
	if( nParamPicto != nPictoEnCours ){
		var sHtml;
		
		//on charge la presentation
		sHtml = '<img src="/produit/image/produit/presentation-' + sProduit + '-' + nParamPicto + '.jpg" width="526" height="347" alt="' + aPictoSurvol[nParamPicto - 1] + '" title="' + aPictoSurvol[nParamPicto - 1] + '" />';
		document.getElementById("presentation_produit").innerHTML = sHtml;
		
		//on change les 2 pictos old/new et les handlers
		document.getElementById("picto_produit_" + nParamPicto).src = '/produit/image/produit/picto-' + sProduit + '-' + nParamPicto + '-on.jpg';
		document.getElementById("picto_produit_" + nPictoEnCours).src = '/produit/image/produit/picto-' + sProduit + '-' + nPictoEnCours + '-off.jpg';
		
		document.getElementById("picto_produit_" + nParamPicto).onmouseover = "";
		document.getElementById("picto_produit_" + nParamPicto).onmouseout = "";

		if( nPictoEnCours == 1 ){
			document.getElementById("picto_produit_1").onmouseover = function(){ShowImage(1);document.getElementById("picto_produit_1").src = "/produit/image/produit/picto-" + sProduit + "-1-on.jpg";};
			document.getElementById("picto_produit_1").onmouseout = function(){document.getElementById("picto_produit_1").src = "/produit/image/produit/picto-" + sProduit + "-1-off.jpg";};
		}
		else if( nPictoEnCours == 2 ){
			document.getElementById("picto_produit_2").onmouseover = function(){ShowImage(2);document.getElementById("picto_produit_2").src = "/produit/image/produit/picto-" + sProduit + "-2-on.jpg";};
			document.getElementById("picto_produit_2").onmouseout = function(){document.getElementById("picto_produit_2").src = "/produit/image/produit/picto-" + sProduit + "-2-off.jpg";};
		}
		else if( nPictoEnCours == 3 ){
			document.getElementById("picto_produit_3").onmouseover = function(){ShowImage(3);document.getElementById("picto_produit_3").src = "/produit/image/produit/picto-" + sProduit + "-3-on.jpg";};
			document.getElementById("picto_produit_3").onmouseout = function(){document.getElementById("picto_produit_3").src = "/produit/image/produit/picto-" + sProduit + "-3-off.jpg";};
		}
		else if( nPictoEnCours == 4 ){
			document.getElementById("picto_produit_4").onmouseover = function(){ShowImage(4);document.getElementById("picto_produit_4").src = "/produit/image/produit/picto-" + sProduit + "-4-on.jpg";};
			document.getElementById("picto_produit_4").onmouseout = function(){document.getElementById("picto_produit_4").src = "/produit/image/produit/picto-" + sProduit + "-4-off.jpg";};
		}
		else if( nPictoEnCours == 5 ){
			document.getElementById("picto_produit_5").onmouseover = function(){ShowImage(5);document.getElementById("picto_produit_5").src = "/produit/image/produit/picto-" + sProduit + "-5-on.jpg";};
			document.getElementById("picto_produit_5").onmouseout = function(){document.getElementById("picto_produit_5").src = "/produit/image/produit/picto-" + sProduit + "-5-off.jpg";};
		}
		else if( nPictoEnCours == 6 ){
			document.getElementById("picto_produit_6").onmouseover = function(){ShowImage(6);document.getElementById("picto_produit_6").src = "/produit/image/produit/picto-" + sProduit + "-6-on.jpg";};
			document.getElementById("picto_produit_6").onmouseout = function(){document.getElementById("picto_produit_6").src = "/produit/image/produit/picto-" + sProduit + "-6-off.jpg";};
		}
		else if( nPictoEnCours == 7 ){
			document.getElementById("picto_produit_7").onmouseover = function(){ShowImage(7);document.getElementById("picto_produit_7").src = "/produit/image/produit/picto-" + sProduit + "-7-on.jpg";};
			document.getElementById("picto_produit_7").onmouseout = function(){document.getElementById("picto_produit_7").src = "/produit/image/produit/picto-" + sProduit + "-7-off.jpg";};
		}

		nPictoEnCours = nParamPicto;
	}
}

//on deselectionne l'onglet en cours / on selectionne le nouveau et on remplace le calque affiché.
function HoverOnglet(nParamOnglet){	
	var nHeightFiche = 500;
	
	for(var i = 0; i < aOnglet.length; i++)
	{
		if(nOngletEnCours == i)
		{
			//deselection
			switch(i)
			{
				case 0 : 
					$("#onglet_presentation").css("background","url(/images/site/produit/bg-onglet-unselect.gif)");
					document.getElementById("onglet_presentation").className = "onglet_unselect";
					$("#presentation_contenu").css("display","none");
					break;
				case 1 : break;
				case 2 : break;
				case 3 : 
					$("#onglet_theme").css("background","url(/images/site/produit/bg-onglet-unselect.gif)");
					document.getElementById("onglet_theme").className = "onglet_unselect";
					$("#theme_contenu").css("display","none");
					break;
				case 4 : 
					$("#onglet_livraison").css("background","url(/images/site/produit/bg-onglet-unselect.gif)");
					document.getElementById("onglet_livraison").className = "onglet_unselect";
					$("#livraison_contenu").css("display","none");
					break;
				case 5 : 
					$("#onglet_tarifs").css("background","url(/images/site/produit/bg-onglet-unselect.gif)");
					document.getElementById("onglet_tarifs").className = "onglet_tarifs";
					document.getElementById('img_fleche').src = "/images/site/puce/puce_fleche_noire.gif";
					
					$("#tarifs_contenu").css("display","none");
					break;
			}
		}
		if(nParamOnglet == i)
		{
			//selection
			switch(i)
			{
				case 0 : 
					$("#onglet_presentation").css("background","url(/images/site/produit/bg-onglet-select.gif)");	
					document.getElementById("onglet_presentation").className = "onglet_select";
					$("#presentation_contenu").css("display","block");
					
					nHeightFiche += $("#presentation_contenu").height();
					document.getElementById("produit").style.height = nHeightFiche + "px";
					break;
				case 1 : break;
				case 2 : break;
				case 3 : 
					$("#onglet_theme").css("background","url(/images/site/produit/bg-onglet-select.gif)");
					document.getElementById("onglet_theme").className = "onglet_select";
					$("#theme_contenu").css("display","block");
					
					nHeightFiche += $("#theme_contenu").height();
					document.getElementById("produit").style.height = nHeightFiche + "px";
					break;
				case 4 : 
					$("#onglet_livraison").css("background","url(/images/site/produit/bg-onglet-select.gif)");
					document.getElementById("onglet_livraison").className = "onglet_select";
					$("#livraison_contenu").css("display","block");
					
					nHeightFiche += $("#livraison_contenu").height();
					document.getElementById("produit").style.height = nHeightFiche + "px";
					break;
				case 5 : 
					$("#onglet_tarifs").css("background","url(/images/site/produit/bg-onglet-select.gif)");
					document.getElementById("onglet_tarifs").className = "onglet_select";
					$("#tarifs_contenu").css("display","block");
					document.getElementById('img_fleche').src = "/images/site/puce/puce_fleche_blanche.gif";
					
					nHeightFiche += $("#tarifs_contenu").height();
					document.getElementById("produit").style.height = nHeightFiche + "px";
					break;
			}
		}
	}
	
	nOngletEnCours = nParamOnglet;
}

//on charge les éléments en ajax, et on construit le calque de livraison
function GetTableauLivraison(){	
	var sUrl = "/produit/ajax-get-info-livraison-fiche-produit.asp";
	var sData = "categorie=" + nCodeSousCategorie + '&zone=' + nCodeZone + '&code_produit=' + nCodeProduit + '&code_port=' + nCodePort ;
	var sCallback = "AfficheTableauLivraison";
	
	//alert("GetTableauLivraison\n/produit/ajax-get-info-livraison-fiche-produit.asp\nnCodeSousCategorie : " + nCodeSousCategorie + "\nnCodeZone : " + nCodeZone + "\nnCodeProduit : " + nCodeProduit + "\nnCodePort : " + nCodePort );
	
	SendData(sUrl, sData, sCallback);
}

function AfficheTableauLivraison(sParamValue){
	document.getElementById("tableau_livraison").innerHTML = sParamValue;
}

function ChangeCodeZone(sParamFrom){
	var nTmpCodeZone;
	
	if(sParamFrom == 'onglet')
	{
		nTmpCodeZone = $("#pays_livraison_onglet").val();
		//on selectionne le pays dans le calque port.
		document.getElementById("pays_livraison").options.selectedIndex = document.getElementById("pays_livraison_onglet").options.selectedIndex;
	}
	else
	{
		nTmpCodeZone = $("#pays_livraison").val();
		//on selectionne le pays dans le calque livraison.
		document.getElementById("pays_livraison_onglet").options.selectedIndex = document.getElementById("pays_livraison").options.selectedIndex;	
	}
	
	var nPays = document.getElementById("pays_livraison_onglet").options[document.getElementById("pays_livraison_onglet").options.selectedIndex].id;
	nCodePays = nPays.replace("onglet_pays_liv_", "");
		
	if(nCodeZone != nTmpCodeZone)
	{
		nCodeZone = nTmpCodeZone;
		GetTableauLivraison();
		getDivPort(nCodeZone);
	}
}

function OngletChangeFormat(){
	var aProduitChoisi = document.getElementById("code_produit").value.split("_");
	nCodeProduit = aProduitChoisi[0];
	nCodeSousCategorie = aProduitChoisi[1];
	document.getElementById("format").options.selectedIndex = document.getElementById("code_produit").options.selectedIndex;
	GetTableauLivraison();
	//OnChangeFormat();
}

function OnChangeFormat(){
	var aFormatChoisi = document.getElementById("format").value.split("_");
	nCodeProduit = aFormatChoisi[0];
	nCodePort = aFormatChoisi[1];
	sLibelleFormat = aFormatChoisi[2];		
	document.getElementById("code_produit").options.selectedIndex = document.getElementById("format").options.selectedIndex;
	//on recharge la liste des transporteurs correspondant au code port du produit
	if(nCodeProduit < 1301 || nCodeProduit > 1414) {
		ChargeTransporteur();
	}
	onValide();
}

function ChargeTransporteur(){
	var nIndex = 0;
	for(var i = 0; i < aCodeProduit.length; i++) {
		if( nCodeProduit == aCodeProduit[i])
			nIndex = i
	}
	
	var nPort = aCodePortXrefProduit[nIndex];
	
	var sHtml = '<strong>Sélectionnez le mode de livraison : </strong><select name="transporteur" id="transporteur" onchange="onValide();">';
	
	for(i = 0; i < aCodePort.length; i++)
	{
		if( nPort == aCodePort[i] )
			sHtml += '<option value="' + aCodeTransporteur[i] + '_' + aLibTransporteur[i] + '" id="transporteur_' + aCodeTransporteur[i] + '">' + aLibTransporteur[i] + '</option>';			
	}
	
	sHtml += '</select>';
	
	document.getElementById("td_transporteur").innerHTML =  sHtml;
}

function SelectTransporteur(nParamCodeTransporteur){
	try {
	document.getElementById("transporteur_" + nParamCodeTransporteur).selected = true;
	} 
	catch(err) { }
	
	onValide();
	GetPort();
}

//affichons le port en augmentant la taille du corps de la page.
function GetPort(){
	document.getElementById("port").style.display = "block";
	AfficheCache();
}

//fermons le port et reduisont la taille du corps de la page
function HidePort(){	
	document.getElementById("port").style.display = "none";
	CloseCache();
}

function onValide(){
	var aCodeTransporteur = document.getElementById("transporteur").value.split("_");
	var nCodeTransporteur = aCodeTransporteur[0];
	var sLibelleTransporteur = aCodeTransporteur[1];	
	var aCodeProduit = document.getElementById("format").value.split("_");
	var nCodeProduit = aCodeProduit[0];
	nCodePort = aCodeProduit[1];
	sLibelleFormat = aCodeProduit[2];
	
	if(nCodeProduit >= 1301 && nCodeProduit <= 1414)
	{
		if(nCodeProduit < 1400) {
			nCodeTransporteur = 8
			nCodePort = 6
		}
		else {
			nCodeTransporteur = 9
			nCodePort = 7
		}
	}
	
	var sUrl = "/produit/frais-de-port/ajax-frais-de-port.asp?produit=" + nCodeProduit + "&port=" + nCodePort + "&transp=" + nCodeTransporteur + "&lib_transp=" + sLibelleTransporteur + "&lib_format=" + sLibelleFormat + "&code_pays=" + nCodePays + "&num=" + Math.random();
	
	//alert("onValide\n/produit/frais-de-port/ajax-frais-de-port.asp\nnCodeProduit : " + nCodeProduit + "\nnCodePort : " + nCodePort + "\nnCodeTransporteur : " + nCodeTransporteur + "\nsLibelleTransporteur : " + sLibelleTransporteur + "\nsLibelleFormat : " + sLibelleFormat + "\nnCodePays : " + nCodePays);
	
	document.getElementById("id_tarifs_detail").style.display = "block";
	
	var xhr_object = null; 
	var sRetour;
	var sVerifZone;
	var i;
	 
	if(window.XMLHttpRequest)
		xhr_object = new XMLHttpRequest(); 
	else if(window.ActiveXObject)
		xhr_object = new ActiveXObject("Microsoft.XMLHTTP"); 
	else{
		return; 
	}
	
	xhr_object.open("GET", sUrl, true); 
	 
	xhr_object.onreadystatechange = function() { 
	   if(xhr_object.readyState == 4){ 
	   		sRetour = unescape(escape(xhr_object.responseText));
			sRetour = sRetour.replace(/&lt;/g,'<');
			sRetour = sRetour.replace(/&gt;/g,'>');
			sRetour = sRetour.replace(/&quot;/g,'"');
			sRetour = sRetour.replace(/&amp;agrave;/g,'&agrave;');
			sRetour = sRetour.replace(/&amp;euro;/g,'&euro;');
			sRetour = sRetour.replace(/&amp;eacute;/g,'&eacute;');
			sRetour = sRetour.replace(/&amp;ucirc;/g,'&ucirc;');			
			document.getElementById("id_tarifs_detail").innerHTML = sRetour; 
			
			//comptons les zones afin que l'afficahge des calques de zone ne bug pas
			sVerifZone = document.getElementById("lib-zone").innerHTML;
			var sTabVerifZone = sVerifZone.split("|")
			nCptZone = sTabVerifZone.length;
			getDivPort(nCodeZone);
		}
	}	
	xhr_object.send(null);
}
var nZone = 1;
function getDivPort(nParamCodeZone){
	
	if(document.getElementById("tab-" + nZone) != null)
		document.getElementById("tab-" + nZone).style.display = "none";
	
	nZone = nParamCodeZone;
	
	if(document.getElementById("tab-" + nZone) != null)
		document.getElementById("tab-" + nZone).style.display = "block";
}

// change l'image de présentation lorsqu'on clique sur un picto (couv & ruban)
function HoverPicto(nParamCodeSousCategorie, nParamCodePictoSelected){
	
	if(nParamCodePictoSelected == 0)
		nParamCodePictoSelected = nCodePictoDefaut;
	else
		document.getElementById("td-picto-" + nCodePictoDefaut).className = "picto-non-sel";

	document.getElementById("td-picto-" + nParamCodePictoSelected).className = "picto-sel";	
	nCodePictoDefaut = nParamCodePictoSelected;	
	
	var sImgPath = "";
	
	switch(nParamCodeSousCategorie)
	{		
		case 5 :
			sImgPath = "<img src=\"/produit/creatif/book/image/couverture/presentation-" + nParamCodePictoSelected + ".jpg\" width=\"286\" height=\"266\" />";
			break;
		case 15 :
			sImgPath = "<img src=\"/produit/creatif/album-poche/image/couverture/presentation-" + nParamCodePictoSelected + ".jpg\" width=\"390\" height=\"287\" />";
			break;
		case 25 :
			sImgPath = "<img src=\"/produit/creatif/agenda/image/couverture/presentation-" + nParamCodePictoSelected + ".jpg\" width=\"517\" height=\"299\" />";
			break;
		case 33 : 
			sImgPath = "<img src=\"/produit/creatif/livre-photo-elegance/image/presentation_details/presentation-" + nParamCodePictoSelected + ".jpg\" width=\"381\" height=\"299\" />";
			break; 
		case 44 :
			sImgPath = "<img src=\"/produit/creatif/livre-photo-molletonne/image/ruban/presentation-" + nParamCodePictoSelected + ".jpg\" width=\"253\" height=\"220\" />";
			break;
		case 53 :			
			sImgPath = "<img src=\"/produit/creatif/livre-photo-molletonne-30x30/image/ruban/presentation_" + nParamCodePictoSelected + ".jpg\" width=\"307\" height=\"283\" />";
			break;	
	}
	document.getElementById("td-presentation").innerHTML = sImgPath;
}

function GetSondage(){
	AfficheCache();	
	$("#visu_sondage").css("display", "block");
	
	//on positionne le sondage sur le bord droit du site
	var nLeft = document.getElementById("site").offsetLeft + $("#site").innerWidth() - $("#visu_sondage").innerWidth();
	
	$("#visu_sondage").css("left", nLeft + "px");
	$("#visu_sondage").css("top", $('#sondage').offset().top + "px");
}

function HideSondage(){
	CloseCache();	
	$("#visu_sondage").css("display", "none");
}

function GetArrayIndex(aParamArray, sParamValue){
	var nIndex = -1;	
	var sNavigator = navigator.appName;
	
	if(sNavigator == "Microsoft Internet Explorer")
	{
		for(var i = 0; i < aParamArray.length; i++)
		{
			if(aParamArray[i] == sParamValue)
			{
				nIndex = i;
				break;
			}
		}
	}
	else
	{
		nIndex = aParamArray.indexOf(sParamValue)
	}
	
	return nIndex;
}

function ViewPresentationTheme(nParamCodeTheme){
	document.getElementById("image_theme_" + nTheme).className = "theme_img"
	nTheme = nParamCodeTheme;
	document.getElementById("image_theme_" + nTheme).className = "theme_img_sel"
	
	var sLib = aLibTheme[GetArrayIndex(aCodeTheme,nParamCodeTheme)];
	document.getElementById("presentation_theme").innerHTML = '<img src="/produit/image/themes/' + sFolderTheme + '/presentation/' + nParamCodeTheme + '.jpg" alt="' + sLib + '" title="' + sLib + '" />';
}

function ViewFamille(nParamCodeFamille){
	var aTheme = new Array();
	var j;
	nCpt = 0;	
	document.getElementById("fam_" + nParamCodeFamille).checked = true;

	if(nParamCodeFamille == 0)
	{
		for( var i = 0; i < aFamCodeFamille.length; i ++)
		{			
			if( GetArrayIndex(aTheme, aFamCodeTheme[i]) == -1 )
			{
				aTheme[nCpt] = aFamCodeTheme[i];
				nCpt++;
			}
		}
	}
	else
	{
		for( var i = 0; i < aFamCodeFamille.length; i ++)
		{
			if(aFamCodeFamille[i] == nParamCodeFamille)
			{
				//on ajoute le theme s'il n'est pas deja present
				aTheme[nCpt] = aFamCodeTheme[i];
				nCpt++;
			}
		}
	}
	
	var sHtml = "";
	var sLib;
	
	for(var i = 0; i < aTheme.length; i ++)
	{
		sLib = aLibTheme[GetArrayIndex(aCodeTheme, aTheme[i])];
		
		if(i == 0)
			sHtml += '<img src="/produit/image/themes/' + sFolderTheme + '/' + aTheme[i] + '.jpg" height="71" width="71" alt="' + sLib + '" title="' + sLib + '" id="image_theme_' + aTheme[i] + '" onclick="ViewPresentationTheme(\'' + aTheme[i] + '\');" id="image_theme_' + aTheme[i] + '" class="theme_img_sel" />';
		else
			sHtml += '<img src="/produit/image/themes/' + sFolderTheme + '/' + aTheme[i] + '.jpg" height="71" width="71" alt="' + sLib + '" title="' + sLib + '" id="image_theme_' + aTheme[i] + '" onclick="ViewPresentationTheme(\'' + aTheme[i] + '\');" id="image_theme_' + aTheme[i] + '" class="theme_img" />';
		
		if(i % 4 == 3)
				sHtml += "<br />";
	}
	
	nTheme = aTheme[0];
	
	document.getElementById("liste_theme").innerHTML = sHtml;
	ViewPresentationTheme(aTheme[0]);
}
