//    Copyright (C) 1998   Zhong Yang  oops@beida.com V1.2
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    any later version.
//
//    This program is distributed in the hope that it will be useful,
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
//    GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License
//    along with this program; if not, write to the Free Software
//    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.                  

// Sources libres optimisés par Guy Capra, Créatique 1999 (www.creatique.com)
//
// Vous pouvez réutiliser ce code sous les termes de la licence GPL (Général Public Licence).
// En d'autres termes, vous pouvez l'utiliser personnellement et/ou commercialement 
// à la condition de transmettre aussi les droits d'accès et de modification aux sources,
// et de ne rien enlever ou modifier à l'entête (le présent texte).

function Inscrit(formul){
var entry=formul;
productbtp= entry.produit.value
chiffre=entry.duree.value
if (productbtp == "BORDEREAU GENERAL") {
chiffre="du "
}else if (productbtp == "CONSULTATION des VALEURS VENALES sur Internet") {
chiffre= "de "
}else{
  if (chiffre > 1) {
   		chiffre="de "+chiffre+ " exemplaires de "
   }else{				
		chiffre="de "+chiffre+ " exemplaire de "
}
}
alert('Votre commande '+chiffre+' '+productbtp+' a bien \u00e9t\u00e9 prise en compte. \n\nVous pouvez voir et modifier cette commande : \n1) en cliquant sur le bouton "Voir ma commande" en bas de cette page ou sur l\'image du caddie, \n2) en modifiant votre commande et en cliquant \u00e0 nouveau sur le bouton "Commander". \n\nVous pourrez ensuite confirmer cet achat \u00e0 partir de la page r\u00e9capitulative.')
}

function addto (form) { //add to cart but stay on the same page
  var entry=form;
  var a=0;
  boundry = new Array(entry.elements.length);
  boundry[0]=0;
  //vérifie si boutons identiques: radio
   for(x=0;x<entry.elements.length;x++){
	if(entry.elements[0].name==entry.elements[x].name)
         {
           a++;
           boundry[a]=x;  

         }
   }   

j=0;
for(i=1;i<=a;i++) {
  j=boundry[i];
// check to see if you are using <select>
//if(isNaN(entry.elements[j+1].value)){alert(entry.elements[j+1].length)
	 if (entry.elements[j+1].checked == true){
     var description=entry.elements[j+1].value;
	 }
//    } else {
//    if (entry.elements[j+1].checked == true){
     //var opindex=entry.elements[j+1];
//     var description=entry.elements[j+1].name;
	 }
 //}
 // var ind=j+2;
 // while(entry.elements[ind].name==entry.elements[ind-1].name)
 // {
    //if (entry.elements[ind].checked == true){
     //opindex=entry.elements[ind];
    // description = description+" "+entry.elements[ind].name;
   //	} 
	// ind++;
//}
  product_name =entry.elements[j].name;
  store_name=entry.produit.value;
  description=store_name;
  quantity=entry.duree.value;
  price=entry.prix.value;
  var num=parseInt(entry.prix.value)
  if(!isNaN(num) && num>=0 )
  {
  document.cookie ="site"+store_name+"+"+description
+ "+" + product_name + "=" + quantity +
"+" + document.referrer  +"+"+ price + 
"; path=/"+"";
 //  }     
 }

for(i=0;i<a;i++) {
if (entry.elements[i].checked==true){
 Inscrit(form)
}
 }
}

function  addtocart(form,page){ //add to cart and go to a new page
addto(form)
location.href=page;
}

function setform(form,page){
var formname=form;
formname.method='GET';
formname.action=page;
}

//---------------------------------------------------------------------||
// FUNCTION:    CKquantity                                             ||
// PARAMETERS:  Quantity to                                            ||
// RETURNS:     Quantity as a number, and possible alert               ||
// PURPOSE:     Make sure quantity is represented as a number          ||
//---------------------------------------------------------------------||
function CKquantity(checkString) {
   var strNewQuantity = "";

   for ( i = 0; i < checkString.length; i++ ) {
      ch = checkString.substring(i, i+1);
      if ( (ch >= "0" && ch <= "9") || (ch == '.') )
         strNewQuantity += ch;
   }

   if ( strNewQuantity.length < 1 )
      strNewQuantity = 0;
	
   return(strNewQuantity);
}
