// JavaScript Document
// product_info.js
//
// DAMART - 02/03/2007

// variable et fonction sp?cifique a la page des coordonnees
var popUpMDP, popUpAdresse, popUpFond;
var prefixe,silhouettePrice=0;
window.onload = function(){
	popUpFond = new fx.Opacity('popUpFond');
}

function popupWindow(url) {
  window.open(url,'popupWindow','toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=yes,copyhistory=no,width=100,height=100,screenX=150,screenY=150,top=150,left=150')
}

function changePrice(pref) {
	//si pref==null on est dans une fiche produit normal
	if(pref == null)pref='';
	prefixe=pref;
	// Changement du prix
	
	// R?cup?ration infos produit
	products_id = $F(pref+'proto_products_id');
	
	color_id = $F(pref+'id[1]');
	size_id = $F(pref+'id[2]');
	support_id = $F(pref+'support_id'); 	
	
	// Appel AJAX
	var url = 'ajax_tepspec_get_products_price.php';
	var pars = 'products_id=' + products_id + '&color_id=' + color_id + '&size_id=' + size_id + '&support_id=' + support_id;
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: showResponse_products_price
		});

}

function showResponse_products_price(originalRequest)
{
	//put returned XML in the textarea
	if(originalRequest.responseText == -1){
		
		$(prefixe+'products_price').innerHTML = '&nbsp;';
		if(prefixe != ''){
			document.getElementById(prefixe+"chkbox").checked=false;
			document.getElementById(prefixe+"chkbox").disabled=true;
			set_dispo_to_epuise();
			majPrixSil();
			}
		else {move_cart_button(0); }
	}
	else
	{
	var res = originalRequest.responseText;
    var reg=new RegExp(";+", "g");
	res = res.split(reg);	
	if(document.getElementById('img_decote')){
	decoteSrc = document.getElementById('img_decote').src;
	third_part = decoteSrc.split("/");
	chaineATraiter = third_part[third_part.length-1];
	if(isNaN(res[2]))
		res[2] = '';
	nouvName = chaineATraiter.substr(0,5)+res[2]+'.gif';
	
	if(res[2] != '')
		document.getElementById('products_decote').style.display = 'block';
	else document.getElementById('products_decote').style.display = 'none';	
	
	third_part[third_part.length-1] = nouvName;

	cpt = 0;
	nouvSrc='';
	while(cpt<third_part.length){
		nouvSrc = nouvSrc + third_part[cpt] + '/';
		cpt++;
	}

	nouvSrc = nouvSrc.substr(0,nouvSrc.length-1);
	document.getElementById('img_decote').src = nouvSrc;
	}
	
	if(res[1] != '' && res[1] != 0 && res[1] != null){
	}
	else{
	res[1]='';
	}
	// 15 = longueur d'un prix type 35,90 ?
	
	if(res[0].length <= 15){
	$(prefixe+'products_price').innerHTML = res[0];
	$(prefixe + 'products_price_barre').innerHTML = res[1];
	}
	else{
	if(res[1] != ''){
	if($(prefixe + 'products_price_barre'))
		$(prefixe + 'products_price_barre').innerHTML = res[0];
	if($(prefixe+'products_price'))
     	$(prefixe+'products_price').innerHTML = res[1];		
     	}
     
     else{
      $(prefixe+'products_price').innerHTML = res[0];
	  if($(prefixe + 'products_price_barre'))
		$(prefixe + 'products_price_barre').innerHTML = '';
      }	
	}
		
	if(prefixe !=''){
		document.getElementById(prefixe+"chkbox").disabled=false;
		checkDisponibility_sil(prefixe);
		majPrixSil();
		}
	else 	{move_cart_button(1);checkDisponibility(prefixe);}
}

	

}





function redimImage_width(inImg, inMW, inMH)
{
  // Cette function recoit 3 parametres
  // inImg : Chemin relatif de l'image
  // inMW  : Largeur maximale
  // inMH   : Hauteur maximale
  var maxWidth = inMW;
  var maxHeight = inMH;
  // Declarations des variables "Nouvelle Taille"
  var dW = 0;
  var dH = 0;
  // Declaration d'un objet Image
  var oImg = new Image();
  // Affectation du chemin de l'image a l'objet
  oImg.src = inImg;
  // On recupere les tailles reelles
  var h = dH = oImg.height;
  var w = dW = oImg.width;
  // Si la largeur ou la hauteur depasse la taille maximale
  if ((h >= maxHeight) || (w >= maxWidth)) {
    // Si la largeur et la hauteur depasse la taille maximale
    if ((h >= maxHeight) && (w >= maxWidth)) {
      // On cherche la plus grande valeur
      if (h > w) {
        dH = maxHeight;
        // On recalcule la taille proportionnellement
        dW = parseInt((w * dH) / h, 10);
      } else {
        dW = maxWidth;
        // On recalcule la taille proportionnellement
        dH = parseInt((h * dW) / w, 10);
      }
    } else if ((h > maxHeight) && (w < maxWidth)) {
      // Si la hauteur depasse la taille maximale
      dH = maxHeight;
        // On recalcule la taille proportionnellement
      dW = parseInt((w * dH) / h, 10);
    } else if ((h < maxHeight) && (w > maxWidth)) {
      // Si la largeur depasse la taille maximale
      dW = maxWidth;
        // On recalcule la taille proportionnellement
      dH = parseInt((h * dW) / w, 10);
    }
  }
  // On ecrit l'image dans le document
  //document.writeln("<img src=\"" + inImg + "\" width=\"" + dW + "\" height=\"" + dH + "\" border=\"0\">");
  return dW; 
};

function redimImage_height(inImg, inMW, inMH)
{
  // Cette function recoit 3 parametres
  // inImg : Chemin relatif de l'image
  // inMW  : Largeur maximale
  // inMH   : Hauteur maximale
  var maxWidth = inMW;
  var maxHeight = inMH;
  // Declarations des variables "Nouvelle Taille"
  var dW = 0;
  var dH = 0;
  // Declaration d'un objet Image
  var oImg = new Image();
  // Affectation du chemin de l'image a l'objet
  oImg.src = inImg;
  // On recupere les tailles reelles
  var h = dH = oImg.height;
  var w = dW = oImg.width;
  // Si la largeur ou la hauteur depasse la taille maximale
  if ((h >= maxHeight) || (w >= maxWidth)) {
    // Si la largeur et la hauteur depasse la taille maximale
    if ((h >= maxHeight) && (w >= maxWidth)) {
      // On cherche la plus grande valeur
      if (h > w) {
        dH = maxHeight;
        // On recalcule la taille proportionnellement
        dW = parseInt((w * dH) / h, 10);
      } else {
        dW = maxWidth;
        // On recalcule la taille proportionnellement
        dH = parseInt((h * dW) / w, 10);
      }
    } else if ((h > maxHeight) && (w < maxWidth)) {
      // Si la hauteur depasse la taille maximale
      dH = maxHeight;
        // On recalcule la taille proportionnellement
      dW = parseInt((w * dH) / h, 10);
    } else if ((h < maxHeight) && (w > maxWidth)) {
      // Si la largeur depasse la taille maximale
      dW = maxWidth;
        // On recalcule la taille proportionnellement
      dH = parseInt((h * dW) / w, 10);
    }
  }
  // On ecrit l'image dans le document
  //document.writeln("<img src=\"" + inImg + "\" width=\"" + dW + "\" height=\"" + dH + "\" border=\"0\">");
  return dH; 
};



function majPrixSil(){
		cpt = 0;
		pId='';
		racine = 'upload_dmrt/product_info/';
		racine2 = 'images/languages/french/buttons/';
		price=0;
		check = false;
		while(pId != null){
			pId = document.getElementById('arr_id['+cpt+']');
			if(pId != null){
				//checkDisponibility_sil(pId.value);
				if(document.getElementById(pId.value+"chkbox").checked){
				check = true;
				if(document.getElementById(pId.value+"products_price").innerHTML != '' 
				&& document.getElementById(pId.value+"products_price").innerHTML != null 
				&& document.getElementById(pId.value+"products_price").innerHTML != '&nbsp;'){
					str = document.getElementById(pId.value+"products_price").innerHTML.split(" ");
					strFin = str[str.length-2].replace(",",".");
					str = parseFloat(strFin);
					
					price= (price*1)+(str*document.getElementById(pId.value+"quantity").value*1);
				
					price = price.toFixed(2);
					
					}
					
					document.getElementById(pId.value).className = 'blocComposeSilhouetteON';

					document.getElementById(pId.value+'_1').src = racine + 'num1rose.gif';
					document.getElementById(pId.value+'_1').height = redimImage_height(racine + 'num1rose.gif', '50', '50');
					document.getElementById(pId.value+'_1').width = redimImage_width(racine + 'num1rose.gif', '50', '50');
					
					document.getElementById(pId.value+'_2').src = racine + 'num2rose.gif';
					document.getElementById(pId.value+'_2').height = redimImage_height(racine + 'num2rose.gif', '50', '50');
					document.getElementById(pId.value+'_2').width = redimImage_width(racine + 'num2rose.gif', '50', '50');
										
					document.getElementById(pId.value+'_3').src = racine + 'num3rose.gif';
					document.getElementById(pId.value+'_3').height = redimImage_height(racine + 'num3rose.gif', '50', '50');
					document.getElementById(pId.value+'_3').width = redimImage_width(racine + 'num3rose.gif', '50', '50');
					
					if(document.getElementById(pId.value+'_4')!= null){
						document.getElementById(pId.value+'_4').src = racine + 'num4rose.gif';
						document.getElementById(pId.value+'_4').height = redimImage_height(racine + 'num4rose.gif', '50', '50');
						document.getElementById(pId.value+'_4').width = redimImage_width(racine + 'num4rose.gif', '50', '50');
					}

					document.getElementById(pId.value+'plus').src = racine2 + 'bt-plusRose.gif';
					document.getElementById(pId.value+'moins').src = racine2 + 'bt-moinsRose.gif';
					document.getElementById(pId.value+'fleche').src = racine + 'fleche-blanche.gif';
					
				
				}
				else {
					if(document.getElementById(pId.value+"col").value == 0 && document.getElementById(pId.value+"tail").value == 0)
					document.getElementById(pId.value+"products_price").innerHTML = '';
					
					document.getElementById(pId.value).className = 'blocComposeSilhouette'; 
								
					document.getElementById(pId.value+'_1').src = racine + 'numero1.gif';	
					document.getElementById(pId.value+'_1').height = '28';
					document.getElementById(pId.value+'_1').width = '18';
									
					document.getElementById(pId.value+'_2').src = racine + 'numero2.gif';	
					document.getElementById(pId.value+'_2').height = '27';
					document.getElementById(pId.value+'_2').width = '18';
									
					document.getElementById(pId.value+'_3').src = racine + 'numero3.gif';	
					document.getElementById(pId.value+'_3').height = '28';
					document.getElementById(pId.value+'_3').width = '18';
									
					if(document.getElementById(pId.value+'_4')!= null){
						document.getElementById(pId.value+'_4').src = racine + 'numero4.gif';
						document.getElementById(pId.value+'_4').height = '18';
						document.getElementById(pId.value+'_4').width = '17';
					}

					document.getElementById(pId.value+'plus').src = racine2 + 'button_qtt_more.gif';
					document.getElementById(pId.value+'moins').src = racine2 + 'button_qtt_less.gif';
										document.getElementById(pId.value+'fleche').src = racine + 'fleche-marron.gif';
					}
  			}
 		cpt++;
		}		
		if(!check){
			document.getElementById("button_add_cart_product_indisponible").style.display="block";
			document.getElementById("button_add_cart").style.display="none";
			
		}
		else {
		//on active le bouton d'envoi au panier
					document.getElementById("button_add_cart_product_indisponible").style.display="none";
					document.getElementById("button_add_cart").style.display="block";
			}
		if(price == 0){
			 price = '0,00';
			 }
		$('price_sil').innerHTML = price.toString().replace(".",",");
	
}

function changeProductsRef(pref) {
	//si pref==null on est dans une fiche produit normal

	if(pref == null)pref='';
	prefixe=pref;

	// Changement ref

	// R?cup?ration infos produit
	products_id = $F(pref+'proto_products_id');
	color_id = $F(pref+'id[1]');

	// Appel AJAX
	var url = 'ajax_tepspec_get_products_ref.php';
	var pars = 'products_id=' + products_id + '&color_id=' + color_id;
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: showResponse_products_ref
		});

}

function showResponse_products_ref(originalRequest)
{
	//put returned XML in the textarea
	$(prefixe+'products_ref').innerHTML = originalRequest.responseText;
	
}


function changeDisponibility(pref) {
	//si pref==null on est dans une fiche produit normal
	if(pref == null)pref='';
	prefixe=pref;

	// Changement ref

	// R?cup?ration infos produit
	products_id = $F(pref+'proto_products_id');
	color_id = $F(pref+'id[1]');
	size_id = $F(pref+'id[2]');
	if(color_id != 0 && size_id != 0){
	// Appel AJAX
	var url = 'ajax_tepspec_get_products_disponibility.php';
	var pars = 'products_id=' + products_id + '&color_id=' + color_id + '&size_id=' + size_id;
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: showResponse_products_disponibility
		});
		checkDisponibility_sil(prefixe);		
	}else{
		$(prefixe+'products_disponibility').innerHTML = '';
		cacher_bouton();
	}
}


function showResponse_products_disponibility(originalRequest)
{
	//put returned XML in the textarea
	$(prefixe+'products_disponibility').innerHTML = originalRequest.responseText;
	checkDisponibility(prefixe);	
	changePrice(prefixe);
}


function checkDisponibility(pref) {

	//si pref==null on est dans une fiche produit normal
	if(pref == null)pref='';
	prefixe=pref;
	

	// R?cup?ration infos produit
	products_id = $F(pref+'proto_products_id');
	color_id = $F(pref+'id[1]');
	size_id = $F(pref+'id[2]');
	
	// Appel AJAX
	var url_dispo_product = 'ajax_tepspec_get_products_disponibility_code.php';
	var pars_dispo_product = 'products_id=' + products_id + '&color_id=' + color_id + '&size_id=' + size_id;
	
	var myAjax = new Ajax.Request(
    	url_dispo_product, 
		{
			method: 'get', 
			parameters: pars_dispo_product, 
			onComplete: show_button_add_cart
		});
}


function show_button_add_cart(originalRequest)
{value = originalRequest.responseText;

if(value.lastIndexOf('EPUISE') != -1){
	document.getElementById("button_add_cart_product_indisponible").style.display="block";
	document.getElementById("button_add_cart").style.display="none";
	if(document.getElementById("lk_wishlist"))
	document.getElementById("lk_wishlist").style.visibility="hidden";
	}
	else{
    document.getElementById("button_add_cart_product_indisponible").style.display="none";
	document.getElementById("button_add_cart").style.display="block";
	if(document.getElementById("lk_wishlist"))
	document.getElementById("lk_wishlist").style.visibility="visible";
	}
	//on modifie le prix apres avoir verifi? les dispo car
	//si il n'y a pas de prix on doit pouvoir modifier la dispo a ?puis?

	//changePrice();
}

function checkDisponibility_sil(pref) {
	//si pref==null on est dans une fiche produit normal
	if(pref == null)pref='';
	prefixe=pref;

	// R?cup?ration infos produit
	products_id = $F(pref+'proto_products_id');
	color_id = $F(pref+'id[1]');
	size_id = $F(pref+'id[2]');

	// Appel AJAX
	var url_dispo_product = 'ajax_tepspec_get_products_disponibility_code.php';
	var pars_dispo_product = 'products_id=' + products_id + '&color_id=' + color_id + '&size_id=' + size_id;
	
	var myAjax = new Ajax.Request(
    	url_dispo_product, 
		{
			method: 'get', 
			parameters: pars_dispo_product, 
			onComplete: show_check_box
		});
}

function show_check_box(originalRequest)
{

	if( $(prefixe+'products_disponibility').innerHTML != "" ){

		if((originalRequest.responseText).lastIndexOf('EPUISE') != -1 || 
			($(prefixe+'products_price').innerHTML == '' && $(prefixe + 'products_price_barre').innerHTML == '')){
			document.getElementById(prefixe+"chkbox").checked=false;
			document.getElementById(prefixe+"chkbox").disabled=true;
		}
		else{	
			//document.getElementById(prefixe+"chkbox").checked=false;
			document.getElementById(prefixe+"chkbox").disabled=false;
		}
		
	}
	
}

//Ajout de fonctions pour calque de modification de ligne
function display(idPopUp){
		document.getElementById('popUpFond').style.height = document.getElementById('container').offsetHeight+"px";
		document.getElementById('popUpFond').style.width = "100%";
		
		popUpFond = new fx.Opacity('popUpFond');
		var popUpMDP = idPopUp;
		
		afficheModModifLigne(idPopUp);
		document.getElementById(idPopUp).style.display="block";
		
}

function afficheModModifLigne(text){
  popUpMDP= new fx.Opacity(text);
  //switchListeCombo(0);
  afficheFauxPopup(text,'popUpFond', 200, popUpMDP, popUpFond, text);
}

function afficheFauxPopup(elt, eltprin, valtop, fader1, fader2, text){
	scrolling=Position.realOffset($(elt))[1];
	$(elt).style.top=(scrolling)+valtop;
	fader1.now=0;
	fader1.toggle();
	fader2.now=0;
	fader2.custom(0, 0.35);
	$(eltprin).style.left=0;
	$(eltprin).style.top=0;
	//$(eltprin).style.height=document.body.scrollHeight+1000;
	
	if(document.getElementById('arr_id[0]')){
	cpt = 0;
	pId='';
	while(pId != null){
		pId = document.getElementById('arr_id['+cpt+']');
		if(pId != null){
			document.getElementById(pId.value+'id[1]').style.display="none";
			document.getElementById(pId.value+'id[2]').style.display="none";
			if(document.getElementById(pId.value+'id[3]'))
			document.getElementById(pId.value+'id[3]').style.display="none";
		}
	cpt++;	
	}	
	}
	else{
	document.getElementById('id[1]').style.display="none";
	document.getElementById('id[2]').style.display="none";
	if(document.getElementById('id[3]'))
	document.getElementById('id[3]').style.display="none";
	}
//	document.getElementById('text').innerHTML = text;
}
//popUpMDP, popUpFond
function fermerFauxPopUp(fader1, fader2){
	if(fader1.now>0 && fader2.now>0){
		fader1.custom(fader1.now, 0);
	    fader2.custom(fader2.now, 0);
	}
}

function fermerModMDP(){

  fermerFauxPopUp(popUpMDP, popUpFond);
  if(document.getElementById('arr_id[0]')){
	cpt = 0;
	pId='';
	while(pId != null){
		pId = document.getElementById('arr_id['+cpt+']');
		if(pId != null){
			document.getElementById(pId.value+'id[1]').style.display="block";
			document.getElementById(pId.value+'id[2]').style.display="block";
			if(document.getElementById(pId.value+'id[3]'))
			document.getElementById(pId.value+'id[3]').style.display="block";
		}
	cpt++;	
	}	
	}
	else{
  document.getElementById('id[1]').style.display="block";
  document.getElementById('id[2]').style.display="block";
  if(document.getElementById('id[3]'))
  document.getElementById('id[3]').style.display="block";  
}
}


function checkmodel(pForm){	
	//si pref==null on est dans une fiche produit normal
	document.getElementById('col_tail').style.display='none';
	document.getElementById('no_taille').style.display='none';
	if (document.getElementById("id[1]") != null && document.getElementById("id[1]").selectedIndex == '0' &&
		document.getElementById("id[2]") != null && document.getElementById("id[2]").selectedIndex == '0'){
		document.getElementById('col_tail').style.display='block';
		}
	else if (document.getElementById("id[1]") != null && document.getElementById("id[1]").selectedIndex == '0'
		){
		document.getElementById('col_qtt').style.display='block';
		}	
		
	else if (document.getElementById("id[1]") != null && document.getElementById("id[1]").selectedIndex == '0'){
		document.getElementById('no_couleur').style.display='block';
	}
	else if (document.getElementById("id[2]") != null && document.getElementById("id[2]").selectedIndex == '0'){
		document.getElementById('no_taille').style.display='block';
	}
	else if(!checkQuantity()){}	
	else{
		pForm.submit();
		}
}

function checkmodel_sil(pForm){
cpt = 0;
pId='';
err=false;
nb_check=0;
block_display = false;
while(pId != null){
pId = document.getElementById('arr_id['+cpt+']');
if(pId != null){
if(document.getElementById(pId.value+"chkbox").checked){nb_check++;
if(document.getElementById(pId.value+"id[3]") != null && document.getElementById(pId.value+"id[3]").selectedIndex == '0' &&
   document.getElementById(pId.value+"id[1]") != null && document.getElementById(pId.value+"id[1]").selectedIndex == '0' && 
   document.getElementById(pId.value+"id[2]") != null && document.getElementById(pId.value+"id[2]").selectedIndex == '0'){
		pId=null;err=false;
		// modele + couleur + taille
			document.getElementById('mod_col_tail').style.display='block';
			block_display = true;
	}else if (document.getElementById(pId.value+"id[1]") != null && document.getElementById(pId.value+"id[1]").selectedIndex == '0' &&
			  document.getElementById(pId.value+"id[2]") != null && document.getElementById(pId.value+"id[2]").selectedIndex == '0'){
		pId=null;err=false;
		//couleur + taille
		document.getElementById('col_tail').style.display='block';
		block_display = true;
	}
	else if (document.getElementById(pId.value+"id[2]") != null && document.getElementById(pId.value+"id[2]").selectedIndex == '0' &&
			 document.getElementById(pId.value+"id[3]") != null && document.getElementById(pId.value+"id[3]").selectedIndex == '0'){
		pId=null;err=false;
		//taille + modele
		document.getElementById('mod_tail').style.display='block';
		block_display = true;
	}
		else if (document.getElementById(pId.value+"id[1]") != null && document.getElementById(pId.value+"id[1]").selectedIndex == '0' &&
				 document.getElementById(pId.value+"id[3]") != null && document.getElementById(pId.value+"id[3]").selectedIndex == '0'){
		pId=null;err=false;
		//couleur + modele
			document.getElementById('col_mod').style.display='block';
			block_display = true;
	}else if (document.getElementById(pId.value+"id[1]") != null && document.getElementById(pId.value+"id[1]").selectedIndex == '0'){
		pId=null;err=false;
		//couleur
			document.getElementById('no_couleur').style.display='block';
			block_display = true;
	}
	else if (document.getElementById(pId.value+"id[2]") != null && document.getElementById(pId.value+"id[2]").selectedIndex == '0'){
		pId=null;err=false;
		//taille
			document.getElementById('no_taille').style.display='block';
			block_display = true;
	}
	else if (document.getElementById(pId.value+"id[3]") != null && document.getElementById(pId.value+"id[3]").selectedIndex == '0'){
		pId=null;err=false;
		//modele
			document.getElementById('no_modele').style.display='block';
			block_display = true;
	}
	else if(!checkQuantity(pId.value)){pId=null;err=false;}	
	else {err=true;}
  }
  }
 cpt++;
}
if(nb_check==0 && block_display == false)
	document.getElementById('no_prod_sel').style.display='block';
else if(err==true){
pForm.submit();
}
}


function checkQuantity(pref){
//si pref==null on est dans une fiche produit normal
	if(pref == null)pref='';
	prefixe=pref;

	if(isNaN(document.getElementById( pref+'quantity').value) || document.getElementById( pref+'quantity').value*1 < 1){
		document.getElementById(pref +'quantity').value=1;
		document.getElementById('bad_quantity').style.display='block';
	return false;
	}
return true;	
}


function incremanteQuantity(pref){
//si pref==null on est dans une fiche produit normal
	if(pref == null)pref='';
	prefixe=pref;

if(!checkQuantity(pref)){}
else {
if(document.getElementById( pref+'quantity').value*1<99)
document.getElementById( pref+'quantity').value=document.getElementById( pref+'quantity').value*1+1;}
}

function decremanteQuantity(pref){
//si pref==null on est dans une fiche produit normal
	if(pref == null)pref='';
	prefixe=pref;

if(!checkQuantity(pref)){}
else {
if(document.getElementById(pref+'quantity').value*1>1)
document.getElementById(pref+'quantity').value=document.getElementById(pref+'quantity').value*1-1;}
}

function loadImg(idImg,idImg2, idProduct, racineImage){

 var oldUrl = document.getElementById(idImg2).src;
  var idImgTmp = idImg;
 if(idImgTmp > 0){
 	prefImg = "_A" + idImgTmp;
 	prefDirImg = "a" + idImgTmp + "_";
 }
 else {
 	prefImg = '';
 	prefDirImg = '';
 }
 var sourceMoyen = racineImage + prefDirImg + "z/" + idProduct + prefImg + "_Z.jpg";
 document.getElementById(idImg2).src = sourceMoyen;
}

function loadImg2(idImg,idImg2){

 //var oldUrl = document.getElementById(idImg2).src;
 //Source de la grande image
 document.getElementById(idImg2).src =  document.getElementById(idImg).src;
 //document.getElementById(idImg).src = oldUrl;
}

//met a jour la liste des couleurs correspondantes au mod?le choisi
function changeColorList(pref) {
//si pref==null on est dans une fiche produit normal

	if(pref == null){
		pref='';
		type = '&type=0';	
	}
	else type = '&type=1';	
	prefixe=pref;

	// R?cup?ration infos produit
	modele_id = $F(pref+"id[3]");	
	products_id = $F(pref+'proto_products_id');
	

	// Appel AJAX
	var url = 'ajax_tepspec_get_color_by_model_code.php';
	var pars = 'modele_id=' + modele_id + '&products_id=' + products_id + type;
	
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: change_color_list
		});
		
}

function change_color_list(originalRequest){
	
    $(prefixe+'col').innerHTML = originalRequest.responseText;

	/*changeDisponibility(prefixe);
    changeProductsRef(prefixe);*/
}



function changeSizeList(pref) {
	//si pref==null on est dans une fiche produit normal
	if(pref == null){
		pref='';
		type = '&type=0';	
	}
	else type = '&type=1';	
	prefixe=pref;


	// Changement sizeList

	// R?cup?ration infos produit
	//Attention on recupere la valeur du premier select, donc si l'ordre change il faudra modier getElementsByTagName("select")[0].value;
	//modele_id = document.getElementById( ).getElementsByTagName("select")[0].value;
	modele_id = $F(pref+'id[3]');
	products_id = $F(pref+'proto_products_id');

	// Appel AJAX
	var url = 'ajax_tepspec_get_size_by_model_code.php';
	var pars = 'modele_id=' + modele_id + '&products_id=' + products_id + type;

	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: change_size_list
		});
}

//met a jour la liste des tailles correspondantes au modele choisi
function change_size_list(originalRequest){
//    document.getElementById().getElementsByTagName("select")[2].innerHTML = originalRequest.responseText;
	$(prefixe+'tail').innerHTML = originalRequest.responseText;
	changePrice(prefixe);
	changeDisponibility(prefixe);
}

//modifie la valeur d'un champ cach? pour l'ajout ? la wishlist
function adding_wishlist(){
document.getElementById('adding_whishlist').value='yes';

}

//change le bouton d'ajout au panier avec celui d'impossibilit? d'ajout au panier
// value = 1 : possibilit? d'ajout au panier
// value = 0 : impossibilit? d'ajout au panier
function move_cart_button(value){
	if(value == '0' ){
   		cacher_bouton();
	// Appel AJAX
	var url = 'ajax_tepspec_get_products_disponibility.php';
	var pars = 'products_id=1&color_id=1&size_id=1';
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: showResponse_products_disponibility_without_price
		});
	}
	else{
		if(document.getElementById("id[1]").selectedIndex != '0' && document.getElementById("id[2]").selectedIndex != '0'){
			montrer_bouton();
		}
		else{
			cacher_bouton();
		}
	}
}

function cacher_bouton(){
	document.getElementById("button_add_cart_product_indisponible").style.display="block";
	document.getElementById("button_add_cart").style.display="none";
	if(document.getElementById("lk_wishlist"))
	document.getElementById("lk_wishlist").style.visibility="hidden";
}

function montrer_bouton(){
	document.getElementById("button_add_cart_product_indisponible").style.display="none";
	document.getElementById("button_add_cart").style.display="block";
	if(document.getElementById("lk_wishlist"))
	document.getElementById("lk_wishlist").style.visibility="visible";
}

function showResponse_products_disponibility_without_price(originalRequest){

	//put returned XML in the textarea
	$(prefixe+'products_disponibility').innerHTML = originalRequest.responseText;
	//checkDisponibility(prefixe);	
	if(prefixe != '')
		return

}

//modifie la disponibilit? ? epuis?e si il n'y a pas de prix pour le produit d'une silhouette
// value = 1 : possibilit? d'ajout au panier
// value = 0 : impossibilit? d'ajout au panier
function set_dispo_to_epuise(){

    // Appel AJAX
	var url = 'ajax_tepspec_get_products_disponibility.php';
	var pars = 'products_id=1&color_id=1&size_id=1';
	var myAjax = new Ajax.Request(
		url, 
		{
			method: 'get', 
			parameters: pars, 
			onComplete: showResponse_products_disponibility_without_price
		});
	
	
}

//fonction qui bloque la validation d'un formulaire par la 
//saisie de la touche entree sur un champs de saisie
function blockEntrer(e) {
	var touche = window.event ? e.keyCode : e.which;
	if(touche==13) {
		return false;
	}
}
