//------------------------------------------------
function IsFloat(fVal, strZone)
{
	if(fVal == null || fVal.length == 0)
	{
		strMsg += strZone + " : La zone doit contenir une valeur numérique\r\n";
		return false;
	}
	var str = fVal.toString();
	var Decimal = false;

	for(var i = 0; i < str.length; i++)
	{
		var c = str.charAt(i);
		if (c == "." && !Decimal)
		{
			Decimal = true;
			continue;	
		}
 		if(c < "0" || c > "9")
		{
			strMsg += strZone + " : La zone contient des caractères alphabétiques\r\n";
			return false;	
		}
	}
	return true;
}
//------------------------------------------------
function IsNull(strVal)
{
	if(strVal == null ||strVal.length == 0)
		return true;
	else
		return false;
}
//------------------------------------------------
function IsEmpty(strVal, strZone)
{
	if(strVal == null ||strVal.length == 0)
	{
		strMsg += strZone + " : La zone est obligatoire\r\n";
		return true;
	}
	return false;
}
//------------------------------------------------
function IsDate(strVal, strZone)
{
 if(strVal == null || strVal.length == 0)
	return false;

 var Delim = strVal.indexOf("/");
 var Delim1= strVal.lastIndexOf("/");
 var iValDD = 0;
 var iValMM = 0;
 var iValYYYY = 0;
 
 if (strVal.length < 10)
 {
  strMsg += strZone + " : La zone contient une date erronnée (Format JJ/MM/AAAA)\r\n";
  return false;
 }

 if(Delim != -1 && Delim1 == Delim)
 {
  strMsg += strZone + " : La zone contient des séparateurs invalides (Format JJ/MM/AAAA)\r\n";
  return false;
 }
 iValDD = strVal.substring(0, Delim);
 iValMM  = strVal.substring(Delim + 1, Delim1);
 iValYYYY  = strVal.substring(Delim1 + 1, strVal.length);
 Months = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
 Leap  = false;

 if (isNaN(iValDD) || isNaN(iValMM) || isNaN(iValYYYY))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if((iValYYYY % 4 == 0) && ((iValYYYY % 100 != 0) || (iValYYYY %400 == 0)))
  Leap = true;
 if((iValDD < 1) || (iValDD > 31) || (iValMM < 1) || (iValMM > 12) || (iValYYYY < 0))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if((iValDD > Months[iValMM-1]) && !((iValMM == 2) && (iValDD > 28)))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if(!(Leap) && (iValMM == 2) && (iValDD > 28))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if((Leap)  && (iValMM == 2) && (iValDD > 29))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n"
  return false;
 }

  return new Date(iValYYYY, iValMM - 1,  iValDD);
}


function IsDateMMAAAA(strVal, strZone)
{
 if(strVal == null || strVal.length == 0)
	return false;

 var Delim = strVal.indexOf("/");
 var iValMM = 0;
 var iValYYYY = 0;
 
 if (strVal.length < 7)
 {
  strMsg += strZone + " : La zone contient une date erronnée (Format MM/AAAA)\r\n";
  return false;
 }

 if(Delim == -1)
 {
  strMsg += strZone + " : La zone contient un séparateur invalide (Format MM/AAAA)\r\n";
  return false;
 }
 iValMM = strVal.substring(0, Delim);
 iValYYYY  = strVal.substring(Delim + 1, strVal.length);

 if (isNaN(iValMM) || isNaN(iValYYYY))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 if((iValMM < 1) || (iValMM > 12) || (iValYYYY < 0))
 {
  strMsg += strZone + " : La zone contient une date erronnée\r\n";
  return false;
 }
 return true;
}


//------------------------------------------------
function IsNumber(lVal, strZone)
{
	if(lVal == null || lVal.length == 0)
	{
		strMsg += strZone + " : La zone doit contenir une valeur numérique\r\n";
		return false;
	}

	var str = lVal.toString();

	for(var i = 0; i < str.length; i++)
	{
		var c = str.charAt(i);
		if(c < "0" || c > "9")
		{
			strMsg += strZone + " : La zone contient des caractères alphabétiques\r\n";
			return false;	
		}
	}
	return true;
}

function Ispolice(lVal, strZone)
{
	
	var reg = /^[a-z0-9._-]+\/[a-z0-9.-]+$/ 

	if(lVal == null || lVal.length == 0) {
		strMsg += strZone + " : La zone n'est pas valide (alphanumérique séparé par un /)\r\n";
		return false;
	}
	else
  	  if (reg.exec(lVal) == null){
		strMsg += strZone + " : La zone n'est pas valide (alphanumérique séparé par un /)\r\n";
		return false;
	  }
	return true;
}



//------------------------------------------------
function GetDay(strVal)
{
	return parseInt(strVal.substring(0, 2), 10);
}
//------------------------------------------------
function GetMonth(strVal)
{
	return 	parseInt(strVal.substring(3, 5), 10);
}
//------------------------------------------------
function GetYear(strVal)
{
	return parseInt(strVal.substring(6, strVal.length), 10);
}

function IsEmail(emailStr, strZone)
{
	var reg = /^[a-z0-9._-]+@[a-z0-9.-]{2,}[.][a-z]{2,3}$/i 
	
	if(emailStr == null || emailStr.length == 0) {
		strMsg += strZone + " : L'adresse email est obligatoire\r\n";
		return false;
	}
	else
  	  if (reg.exec(emailStr) == null){
		strMsg += strZone + " : L'adresse email n'est pas valide\r\n";
		return false;
	 }
			
	return true;
}
function isInteger(sValue)
{
	var digits= new Array(0,1,2,3,4,5,6,7,8,9)
	var i,j,bNonInt,iInc=-1
	for(i=0;i<=sValue.length;i++)
	{
		for(j=0;j<=digits.length;j++)
		if(sValue.charAt(i)!=digits[j])
			continue;
		else
		iInc++;
	}
	if (sValue.length>iInc)
		return false
	else
	return true
}


function isFloat(sValue)
{
var digits= new Array(0,1,2,3,4,5,6,7,8,9,'.',',')
var i,j,bNonInt,iInc=-1,iPointNb=0
for(i=0;i<=sValue.length;i++)
{
for(j=0;j<=digits.length;j++)
{
if(sValue.charAt(i)!=digits[j] || sValue.charAt(i)==' ')
continue;
else
{ 
iInc++;
if(sValue.charAt(i)=='.'||sValue.charAt(i)==',')
iPointNb++;
}
}
}
if (sValue.length>iInc || iPointNb>1)
return false
else
return true
}

function addToCart()
{ 
  ln=document.frm.idprd.length; 
  price_total = 0;
  poids_total = 0;
  qte_total = 0;
  cde = "";
  
  for (i=0;i<ln;i++)
  {
	  	monOption = "";
        eval("qtyUnit = document.frm.qty_" + document.frm.idprd[i].value + ".value")	
        eval("priceUnit = document.frm.price_" + document.frm.idprd[i].value + ".value")
        eval("poidsUnit = document.frm.poids_" + document.frm.idprd[i].value + ".value")
        eval("nomPdt = document.frm.nom_pdt_" + document.frm.idprd[i].value + ".value")
		if (document.frm.idprd[i].value<5 && qtyUnit>0) {
			if(document.frm.option1.checked) monOption+="<br />=> "+document.frm.option1.value;
			if(document.frm.option2.checked) monOption+="<br />=> "+document.frm.option2.value;
			if(document.frm.option3.checked) monOption+="<br />=> "+document.frm.option3.value;
			if(document.frm.option4.checked) monOption+="<br />=> "+document.frm.option4.value;
			if(document.frm.option5.checked) monOption+="<br />=> "+document.frm.option5.value;
			if(document.frm.option6.checked) monOption+="<br />=> "+document.frm.option6.value;
		} else if (document.frm.idprd[i].value>4 && document.frm.idprd[i].value<7 && qtyUnit>0) {			
			if(document.frm.option7.checked) monOption+="<br />=> "+document.frm.option7.value;
			if(document.frm.option8.checked) monOption+="<br />=> "+document.frm.option8.value;
			//if(document.frm.option9.checked) monOption+="<br />=> "+document.frm.option9.value;
			
		} else if (document.frm.idprd[i].value>6 && qtyUnit>0) {
			if(document.frm.option10.checked) monOption+="<br />=> "+document.frm.option10.value;
			if(document.frm.option11.checked) monOption+="<br />=> "+document.frm.option11.value;
			if(document.frm.option12.checked) monOption+="<br />=> "+document.frm.option12.value;
			if(document.frm.option13.checked) monOption+="<br />=> "+document.frm.option13.value;
			if(document.frm.option14.checked) monOption+="<br />=> "+document.frm.option14.value;
			if(document.frm.option15.checked) monOption+="<br />=> "+document.frm.option15.value;
		
		}

 		 if (isInteger(qtyUnit)){
						totLig = qtyUnit * priceUnit;
						poidsLig = qtyUnit * poidsUnit;
           // document.getElementById("ligprix_" + document.frm.idprd[i].value).innerHTML = totLig.toFixed(2);
            price_total += totLig;			
            poids_total += poidsLig;  
			qte_total += qtyUnit*1;
			if (qtyUnit>0) {
				
				cde += "<tr><td><div align=\"left\">"+nomPdt+monOption+"</div></td><td><div align=\"left\">"+qtyUnit+"</div></td><td><div align=\"left\">"+totLig.toFixed(2)+"</div></td></tr>";
			}
        }
  }
  document.getElementById("total").innerHTML = price_total.toFixed(2);
 
  //calcul des frais de transport !!!
  if (qte_total<=2){
	trans=10.00;
  } else if (qte_total>2){
	trans=12.00;
  } 
  
  
	document.getElementById("forfait").innerHTML = trans.toFixed(2);
	montotal = price_total + trans;
	montotal =  montotal.toFixed(2);
	document.getElementById("net").innerHTML = montotal;
	
	document.frm.cde.value = cde;
  	document.frm.monTotal.value = price_total.toFixed(2);
  	document.frm.monTransp.value = trans.toFixed(2);
  	document.frm.monTotalAPayer.value = montotal;
}

function bIsNetscape()
{
	return ( navigator.appName=="Netscape" )
}

function bIsExplorer()
{
	return ( navigator.appName=="Microsoft Internet Explorer" )
}

function bIsDigit (c)
{	return ( (c >= "0") && (c <= "9") )	}

function bIsControl(c)
{	return ( c < " " )		}

function ValRetIE(evt,test)
{
	if (test || (evt.keyCode == 13))
	{
		return evt.keyCode;
	}
	return test;
}

function Chiffre(evt)
{
	var car;

	if ( bIsNetscape() )
	{
		car = String.fromCharCode(evt.which);
		return ( bIsDigit(car) || bIsControl(car));
	}
	if ( bIsExplorer() )
	{
		car = String.fromCharCode(evt.keyCode);
		evt.returnValue = ValRetIE(evt,bIsDigit(car));
	}

	return true;
}


