// JavaScript Document<script type="text/javascript">

var Tableau = new Array();

function montre(id) {
var d = document.getElementById(id);
	for (var i = 1; i<=10; i++) {
		if (document.getElementById('smenu'+i)) {document.getElementById('smenu'+i).style.display='none';}
	}
if (d) {d.style.display='block';}
}

function montre2(id,a) {
var id = id;
var a = a;
if (a==1){
	if (document.getElementById('gamme_roll'+id)) {document.getElementById('gamme_roll'+id).style.visibility='visible';}
}
else {if (document.getElementById('gamme_roll'+id)) {document.getElementById('gamme_roll'+id).style.visibility='hidden';}}
}

function change(a_item, b_item, c_item, d_item){
	var img = document.getElementById("zoomIDM");
	img.src = a_item;
	document.getElementById("accrocheIDM").innerHTML = b_item;
	document.getElementById("libelleIDM").innerHTML = c_item;
	document.getElementById("descriptionIDM").innerHTML = d_item;
}
function change2(a_item){
	var img = document.getElementById("zoomIDEE");
	img.src = a_item;
}

function validOption(nb,id_obj, id)
{	
	var nb = parseInt(optionAttente.value,10);
	nb++;
	optionAttente.value = nb.toString();
}

function ajouteItem(id_str,stock_nb, minCommande, priv, formu) 
{
	if(priv == 3 && minCommande > 0)
	{
		var i = minCommande;
	}
	else
	{
		var i = 1;
	}
	var idValue = formu['champ'+id_str].value;
	if(isNaN(parseInt(idValue))) idValue = 0;
	idValue = parseInt(idValue, 10) + i;
	formu['champ'+id_str].value = idValue;
	formu['q'+id_str].value = idValue;
	//testStock(document.formProd['champ'+id_str], stock_nb);
}

function retireItem(id_str,stock_nb, minCommande, priv, formu) 
{
	if(priv == 3 && minCommande > 0)
	{
		var i = minCommande;
	}
	else
	{
		var i = 1;
	}
	
	var idValue = formu['champ'+id_str].value;
	if(isNaN(idValue)) idValue = 0;
	if(idValue > 0) 
	{
		idValue = parseInt(idValue, 10) - i;
		if(idValue < 0)
		{
			idValue = 0 
		}
		formu['champ'+id_str].value = idValue;
		formu['q'+id_str].value = idValue;
		//testStock(document.formProd['champ'+id_str], stock_nb);
	}
}

function ajouteItem2(id_str,stock_nb,minCommande, priv) 
{
	if(priv == 3 && minCommande > 0)
	{
		var i = minCommande;
	}
	else
	{
		var i = 1;
	}
	var idValue = document.formProd['champ_'+id_str].value;
	if(isNaN(parseInt(idValue))) idValue = 0;
	idValue = parseInt(idValue,10) +i;
	document.formProd['champ_'+id_str].value = idValue;
	document.formProd['m_'+id_str].value = idValue;
	//testStock(document.formProd['champ'+id_str], stock_nb);
}

function retireItem2(id_str,stock_nb,minCommande, priv) 
{
	if(priv == 3 && minCommande > 0)
	{
		var i = minCommande;
	}
	else
	{
		var i = 1;
	}
	
	var idValue = document.formProd['champ_'+id_str].value;
	if(isNaN(idValue)) idValue = 0;
	if(idValue > 0) 
	{
		idValue = parseInt(idValue,10) -i;
		document.formProd['champ_'+id_str].value = idValue;
		document.formProd['m_'+id_str].value = idValue;
		//testStock(document.formProd['champ'+id_str], stock_nb);
	}
}

function ajouteItem3(id_str,stock_nb,minCommande, priv) 
{
	//if(priv == 3 && minCommande > 0)
	//{
	//	var i = minCommande;
	//}
	//else
	//{
	//	var i = 1;
	//}
	//var idValue = document.formProd['champ_'+id_str].value;
	//if(isNaN(parseInt(idValue))) idValue = 0;
	//idValue = parseInt(idValue,10) +i;
	document.formProd['champ_'+id_str].value = stock_nb;
	document.formProd['m_'+id_str].value = stock_nb;
	//testStock(document.formProd['champ'+id_str], stock_nb);
}

function retireItem3(id_str,stock_nb,minCommande, priv) 
{
	//if(priv == 3 && minCommande > 0)
	//{
	//	var i = minCommande;
	//}
	//else
	//{
	//	var i = 1;
	//}
	//
	//var idValue = document.formProd['champ_'+id_str].value;
	//if(isNaN(idValue)) idValue = 0;
	//if(idValue > 0) 
	//{
	//	idValue = parseInt(idValue,10) -i;
		document.formProd['champ_'+id_str].value = 0;
		document.formProd['m_'+id_str].value = 0;
		//testStock(document.formProd['champ'+id_str], stock_nb);
	//}
}

function verifCommandeRapide (a_idForm)
{
	var form_obj = document.getElementById(a_idForm)
	//console.log("ELEMENTS // "+form_obj.elements)
	var nbError = 0;
	var len = form_obj.elements.length
	for(var i=0; i<len; i++ )
	{
		var nomInput = form_obj.elements[i].name
		if(nomInput && nomInput.substr(0, 2) == "m_")
		{
			var nums = nomInput.substr(2)
			var qtmin = parseInt(form_obj["qtmin_" + nums].value, 10);
			var valueSaisie = parseInt(form_obj[nomInput].value, 10);
			if( (valueSaisie % qtmin) != 0 && valueSaisie >0)
			{
				nbError = 1
				break;
			}
		}
	}
	if(nbError > 0)
	{
		alert("Vérifiez vos saisies. Les quantités commandées doivent être un mutltiple du montant minimum de commande");
		return false;
	}
	else
	{
		form_obj.submit()
		return true;
	}
}


function changeQT(id_str) 
{
	var idValue = document.formProd['champ'+id_str].value;
	if(isNaN(parseInt(idValue))) idValue = 0;
	document.formProd['champ'+id_str].value = idValue;
	document.formProd['q'+id_str].value = idValue;
	//testStock(document.formProd['champ'+id_str], stock_nb);
}
var error_nb = 0;
function testStock(id_obj, stock2_nb)
{
	
	var qt_nb = id_obj.value;
	if(qt_nb > stock2_nb)
	{	
		id_obj.style.color = '#FFFFFF';
		id_obj.style.backgroundColor = '#CC0000';	
		error_nb ++;
	}
	else
	{
		id_obj.style.color = '#d43d74';
		id_obj.style.backgroundColor = '#FFFFFF';	
		error_nb --;
	}
	if(error_nb == 0)
	document.getElementById('infoStock').style.display = 'none';
	else
	document.getElementById('infoStock').style.display = 'block';
}

function format_entier(entier)
{
    var i;
    var has_virgule = 0;
    var res = '';
    entier = entier + '';
    for(i=0;i<entier.length;i++)
    {
       var c = entier.charAt(i);
       if ((c == '.') || (c == ','))
       {
          has_virgule = 1;
	  if (c == ',')
	  {
	     c = '.';	  
	  }
       }
       if (has_virgule >= 1)
       {
	  if (has_virgule < 4)
	  {
             res = res + c;
          }
          has_virgule++;
       }
       else
       {
           res = res + c;
       }
    }
    if (has_virgule == 0)
    {
        res = res + ".00";
    }
    if (has_virgule == 2)
    {
        res = res + "00";
    } 
    if (has_virgule == 3)
    {
        res = res + "0";
    } 
    return res;
}

function redirectBoutique(stnt1,session,cgibin){
	var cat = stnt1.substring(6,stnt1.length);
	var lien = ''+cgibin+"modele.pl?session="+session+"&modele=presentation&cat="+cat+"&action=set_session_tnt&stnt1="+stnt1
	document.location.href=lien;
}

function select_eight(arg){
	var total = arg;
	// tabSelect=document.getElementById("selection").getElementsByTagName("h1");
	for(var i = 0; i < total; i++){
	document.formProd['champ_'+Tableau[i]].value = 1;
	document.formProd['m_'+Tableau[i]].value = 1;
	}
}

function cherche9(form) {
	var ch_ch1 = form.manuel_ch_ch1.value;
	var ch_ch2 = form.manuel_ch_ch2.value;
	var ch_ch3 = form.manuel_ch_ch3.value;
	if (ch_ch1!=""){
		if (ch_ch2!=""){
			if (ch_ch3!=""){
			document.form.ch_ch.value = "+"+ch_ch1 +" +\""+ ch_ch2+"\" +"+ ch_ch3;
			}
			else{
			document.form.ch_ch.value = "+"+ch_ch1 +" +\""+ ch_ch2+"\"";
			}
		}
		else{
			if (ch_ch3!=""){
			document.form.ch_ch.value = "+"+ch_ch1 +" +"+ ch_ch3;
			}
			else{
			document.form.ch_ch.value = "+"+ch_ch1;
			}
		}
	}
	else{
		if (ch_ch2!=""){			
			if (ch_ch3!=""){
				document.form.ch_ch.value = "+"+"\""+ch_ch2+"\" +"+ ch_ch3;
			}
			else{
				document.form.ch_ch.value = "+"+"\""+ch_ch2+"\"";	
			}
		}
		else{
			if (ch_ch3!=""){
				document.form.ch_ch.value = "+"+ch_ch3;
			}
			else{
				alert('');
				return false;
			}
		}
	}
}
function cherche2(form) {
	var ch_ch = form.manuel_ch_ch.value;
	var caract = ch_ch.length;
	if (caract==9){
		var part1 = ch_ch.substr(0,3);
		var part2 = ch_ch.substr(3,6);		
		document.form2.ch_ch.value = "+"+part1+" +"+part2;
	}
	else
		document.form2.ch_ch.value = ch_ch;
		
}

function popupPrint(a_page_str){
	window.open(a_page_str,'print','width=625,height=500,scrollbars=yes');
	return false;
}	
function popupAmi(a_page_str){
	window.open(a_page_str,'ami','width=625,height=500,scrollbars=yes');
	return false;
}	