function CalculAchat(t1, t2, t3, t4)
{
	var sms = document.getElementById('sms');
	var sms2 = document.getElementById('sms2');
	var sms3 = document.getElementById('sms3');
	var prix_unit = document.getElementById('aff_prix_unit');
	var tot_ht = document.getElementById('aff_tot_ht');
	var tot_ttc = document.getElementById('aff_tot_ttc');
	
	if (isNaN(parseInt(sms.value)))
	{
		sms.value = '';
		sms2.value = '';
		sms3.value = '';
		prix_unit.innerHTML = '';
		tot_ht.innerHTML = '';
		tot_ttc.innerHTML = '';
	}
	else
	{
		if(sms.value != '')
		{
			var val_sms = parseInt(sms.value);
			var val_pu = 0;
			
			if (val_sms >= 10 && val_sms <= 5000)
			{
				val_pu = t1;
			}
			else if (val_sms >= 5001 && val_sms <= 10000)
			{
				val_pu = t2;
			}
			else if (val_sms >= 10001 && val_sms <= 20000)
			{
				val_pu = t3;
			}
			else if (val_sms >= 20001)
			{
				val_pu = t4;
			}
			
			sms.value = sms.value;
			sms2.value = sms.value;
			sms3.value = Math.floor(sms.value/1.30);
			prix_unit.innerHTML = val_pu+" €";
			tot_ht.innerHTML = Math.round((sms.value*val_pu)*100)/100+" €";
			tot_ttc.innerHTML = Math.round(((sms.value*val_pu)*1.085)*100)/100+" €";
		}
		else
		{
			sms.value = '';
			sms2.value = '';
			sms3.value = '';
			prix_unit.innerHTML = 0;
			tot_ht.innerHTML = 0;
			tot_ttc.innerHTML = 0;
		} 
	}
}

function CalculAchat2(t1, t2, t3, t4)
{
	var sms = document.getElementById('sms');
	var sms2 = document.getElementById('sms2');
	var sms3 = document.getElementById('sms3');
	var prix_unit = document.getElementById('aff_prix_unit');
	var tot_ht = document.getElementById('aff_tot_ht');
	var tot_ttc = document.getElementById('aff_tot_ttc');
	
	if (isNaN(parseInt(sms2.value)))
	{
		sms.value = '';
		sms2.value = '';
		sms3.value = '';
		prix_unit.innerHTML = '';
		tot_ht.innerHTML = '';
		tot_ttc.innerHTML = '';
	}
	else
	{
		if(sms2.value != '')
		{
			var val_sms = parseInt(sms2.value);
			var val_pu = 0;
			
			if (val_sms >= 10 && val_sms <= 5000)
			{
				val_pu = t1;
			}
			else if (val_sms >= 5001 && val_sms <= 10000)
			{
				val_pu = t2;
			}
			else if (val_sms >= 10001 && val_sms <= 20000)
			{
				val_pu = t3;
			}
			else if (val_sms >= 20001)
			{
				val_pu = t4;
			}

			sms.value = sms2.value;
			sms2.value = sms.value;
			sms3.value = Math.floor(sms.value/1.30);
			prix_unit.innerHTML = val_pu+" €";
			tot_ht.innerHTML = Math.round((sms.value*val_pu)*100)/100+" €";
			tot_ttc.innerHTML = Math.round(((sms.value*val_pu)*1.085)*100)/100+" €";
		}
		else
		{
			sms.value = '';
			sms2.value = '';
			sms3.value = '';
			prix_unit.innerHTML = 0;
			tot_ht.innerHTML = 0;
			tot_ttc.innerHTML = 0;
		} 
	}
}

function CalculAchat3(t1, t2, t3, t4)
{
	var sms = document.getElementById('sms');
	var sms2 = document.getElementById('sms2');
	var sms3 = document.getElementById('sms3');
	var prix_unit = document.getElementById('aff_prix_unit');
	var tot_ht = document.getElementById('aff_tot_ht');
	var tot_ttc = document.getElementById('aff_tot_ttc');
	
	if (isNaN(parseInt(sms3.value)))
	{
		sms.value = '';
		sms2.value = '';
		sms3.value = '';
		prix_unit.innerHTML = '';
		tot_ht.innerHTML = '';
		tot_ttc.innerHTML = '';
	}
	else
	{
		if(sms3.value != '')
		{
			var val_sms = parseInt(Math.ceil(sms3.value*1.09));
			var val_pu = 0;
			
			if (val_sms >= 10 && val_sms <= 5000)
			{
				val_pu = t1;
			}
			else if (val_sms >= 5001 && val_sms <= 10000)
			{
				val_pu = t2;
			}
			else if (val_sms >= 10001 && val_sms <= 20000)
			{
				val_pu = t3;
			}
			else if (val_sms >= 20001)
			{
				val_pu = t4;
			}

			sms.value = Math.ceil(sms3.value*1.30);
			sms2.value = Math.ceil(sms3.value*1.30);
			sms3.value = sms3.value;
			prix_unit.innerHTML = val_pu+" €";
			tot_ht.innerHTML = Math.round((sms.value*val_pu)*100)/100+" €";
			tot_ttc.innerHTML = Math.round(((sms.value*val_pu)*1.085)*100)/100+" €";
		}
		else
		{
			sms.value = '';
			sms2.value = '';
			sms3.value = '';
			prix_unit.innerHTML = 0;
			tot_ht.innerHTML = 0;
			tot_ttc.innerHTML = 0;
		} 
	}
}

function generkey(nb_caract)
{
	var chaine = Array('a','b','c','d','e','f','g','h','i','j','k','m','n','o','p','q','r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y','Z','2','3','4','5','6','7','8','9');
	var pass = '';
	var nb, u;
	
	var cle = document.getElementById('cle');
	
	for (u = 1; u <= nb_caract; u++)
	{
		//nb = chaine.length;
		nb = Math.round(Math.random()*(chaine.length-1));
		
		//test += nb+"-";
		pass += chaine[nb];
	}
	//alert(test);
	cle.value = pass;
}

function type_client()
{
	var type = document.getElementById('cli_type');
	var societe = document.getElementById('cli_societe');
	var partie_societe = document.getElementById("partie_societe");
	
	if (type.value == 4)
	{
		partie_societe.style.display = "none";
		societe.value = "";
	}
	else
	{
		partie_societe.style.display = "table-row";
	}
}

function gereCase(form, mode)
{
	var blnEtat = null;
	var i = document.forms[form].getElementsByTagName("input");

	for ( var cpt = 0; cpt < i.length; cpt++)
	{
		blnEtat = (mode=='0') ? false : (mode=='1') ? true : (i[cpt].checked) ? false : true;	
		i[cpt].checked = blnEtat;
	}
}
