
//Version JPH pour passing 21/4/2000
	
function checkout() {
   mycookies=new Array(20);
   var i=0;
   subtotal=0;    //jph
   quant=0;
   totquant=0;   //jph
   var startpoint=0;
   whole_len=document.cookie.length;
   while(whole_len!=startpoint && i< 20)
   {
     if ((temlen=document.cookie.indexOf(";",startpoint))!=-1)
     {
	mycookies[i]=document.cookie.substring(startpoint,temlen);
	i++;
	startpoint=temlen+1
     }
     else if (startpoint != whole_len)
     {
        mycookies[i]=document.cookie.substring(startpoint,whole_len);
        i++;
	startpoint=whole_len;
     }
   }
    printtitle();
    for (j=0;j<i;j++)
     {
	//filter out cookies that are not used by cart
	if((mycookies[j].substring(0,4)=="srmp")||(mycookies[j].substring(0,5)==" srmp"))
	   subtotal=getCookie(mycookies[j]);
	   //totquant+=eval(quant); //jph
	   totquant+=quant*1; // louis 03/03
     }
   document.write("</table>");
   subtotal=price_format(subtotal);
   //document.write("<input type=hidden name=TotalTTC value="+subtotal+">");
   //document.write("<input type=hidden name=exemplaires value="+totquant+">"); //jph
   document.write("<TABLE WIDTH=90% BORDER=0 ALIGN=CENTER> \
   <COL><TR><TD WIDTH=100% BGCOLOR=#000000 ALIGN=CENTER><FONT FACE=Arial SIZE=2 COLOR=#FFFFFF><B> \
Total du panier Toutes Taxes Comprises&nbsp;&nbsp;"+subtotal+"&nbsp;&euro;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Nombre de livres&nbsp; "+totquant+"&nbsp;</B></FONT></TD></TR></TABLE>");
}

function getCookie (acookie) {
    clen = acookie.length;
    nlen= acookie.indexOf("=",0);
    // take out the "srmp" at the beginning of the line
    if(acookie.substring(0,1)==" ")
       cname=acookie.substring(5,nlen);
    else
       cname= acookie.substring(4,nlen);
    bname= acookie.substring(nlen+1,clen);
    sname_len=cname.indexOf("+",0);
    store=cname.substring(0,sname_len);
    dlen=cname.indexOf("+",sname_len+1);
    descrip=unescape(cname.substring(sname_len+1,dlen)) //jph
    edescrip=cname.substring(sname_len+1,dlen) //jph
    product=cname.substring(dlen+1,nlen);
	
    qlen=bname.indexOf("+",0);
    rlen=bname.indexOf("+",qlen+1);
    quant=bname.substring(0,qlen);
    if(quant==0)
	 document.cookie="srmp"+cname+"=bb; expires=Saturday, 16-Sep-90 23:59:59 GMT; path=/"+"";

    refer=bname.substring(qlen+1,rlen);
    price=bname.substring(rlen+1,clen-nlen);
    price=price_format(price);
    if(quant !=0 ){
      subtotal+=price*quant;
    }
    printcontent();
    return subtotal;
}

function putback(str1){
  document.cookie="srmp"+str1+"=bb; expires=Saturday, 16-Sep-90 23:59:59 GMT; path=/"+""; 
}

function checkout2() {
   mycookies=new Array(20);
   var i=0;
   var startpoint=0;
   whole_len=document.cookie.length;
   while(whole_len!=startpoint && i< 20)
   {
     if ((temlen=document.cookie.indexOf(";",startpoint))!=-1)
     {
	mycookies[i]=document.cookie.substring(startpoint,temlen);
	i++;
	startpoint=temlen+1
     }
     else if (startpoint != whole_len)
     {
        mycookies[i]=document.cookie.substring(startpoint,whole_len);
        i++;
	startpoint=whole_len;
     }
   }
    for (j=0;j<i;j++)
     {
	//filter out cookies that are not used by cart
	if((mycookies[j].substring(0,4)=="srmp")||(mycookies[j].substring(0,5)==" srmp"))
	   subtotal=getCookie2(mycookies[j]);
     }
   
}


function getCookie2 (acookie) {
    clen = acookie.length;
    nlen= acookie.indexOf("=",0);
    // take out the "srmp" at the beginning of the line
    if(acookie.substring(0,1)==" ")
       cname=acookie.substring(5,nlen);
    else
       cname= acookie.substring(4,nlen);
    bname= acookie.substring(nlen+1,clen);
    sname_len=cname.indexOf("+",0);
    store=cname.substring(0,sname_len);
    dlen=cname.indexOf("+",sname_len+1);
    descrip=unescape(cname.substring(sname_len+1,dlen)) //jph
    edescrip=cname.substring(sname_len+1,dlen) //jph
    product=cname.substring(dlen+1,nlen);
	
    qlen=bname.indexOf("+",0);
    rlen=bname.indexOf("+",qlen+1);
    quant=bname.substring(0,qlen);
    if(quant==0)
	document.cookie="srmp"+cname+"=bb; expires=Saturday, 16-Sep-90 23:59:59 GMT; path=/"+"";

    refer=bname.substring(qlen+1,rlen);
    price=bname.substring(rlen+1,clen-nlen);
    price=price_format(price);
    
    printcontent2();
}



// There's no need to touch anything above this line
// You can use "store","descrip","product","quant","price"
// and "refer" in the code below




function printtitle(){
tabletitle="<TABLE WIDTH=90% BORDER=0 ALIGN=CENTER><tr> \
  <TD WIDTH=10% BGCOLOR=#000000><FONT SIZE=2 FACE=Arial COLOR=#FFFFFF><B>R&eacute;f&eacute;rence</B></FONT></td> \
  <TD WIDTH=65% BGCOLOR=#000000><FONT SIZE=2 FACE=Arial COLOR=#FFFFFF><B>Titre et auteur</B></FONT></td> \
  <TD WIDTH=5% BGCOLOR=#000000 ALIGN=LEFT><FONT SIZE=2 FACE=Arial COLOR=#FFFFFF><B>Qt&eacute;</B></FONT></td> \
  <TD WIDTH=10% BGCOLOR=#000000 ALIGN=LEFT><FONT SIZE=2 FACE=Arial COLOR=#FFFFFF><B>PU TTC</B></FONT></td> \
  <td> </td></tr>";
document.write(tabletitle);
}

function printcontent(){
  if(quant!=0){
    document.write("<tr align=LEFT><TD WIDTH=10% BGCOLOR=#FFFFFF VALIGN=TOP><FONT SIZE=2 FACE=Arial><B>"+product+"</B></FONT></td><TD WIDTH=65% BGCOLOR=#FFFFFF VALIGN=TOP><FONT SIZE=2 FACE=Arial><B>");
    document.write(descrip+"</B></FONT></td><TD WIDTH=5% BGCOLOR=#FFFFFF Align=CENTER VALIGN=TOP><FONT SIZE=2 FACE=Arial><B>"+quant+"</B></FONT></td><TD WIDTH=10% BGCOLOR=#FFFFFF align=RIGHT VALIGN=TOP><FONT SIZE=2 FACE=Arial><B>");
    document.write(price+"</B></FONT></td>");
    document.write("<TD><form><input type=submit value=Supprimer "); 
    document.write("onClick=\"putback(\'"+store+"+"+edescrip+"+"+product+"\')\"></form></td></tr>");
   }
}

function printcontent2(){
  if(quant!=0){
    passing=("\n<input type=hidden name="+product+"  value="+edescrip+ "+"+ quant + "+"+ price +">");
    document.write(passing);
   }
}

function price_format(tmpprice){
// get rid off the extra digits behind "."
   dot = tmpprice.toString().indexOf(".");
   if(dot!=-1)
      tmpprice=tmpprice.toString().substr(0,dot+4);
   tmpprice=Math.round(tmpprice*100)/100;
// add "0" if necessary
   dot = tmpprice.toString().indexOf(".");
   if(dot ==-1)
      tmpprice=tmpprice.toString()+".00";
   else if((tmpprice.toString().length-dot)==2)
      tmpprice=tmpprice.toString()+"0";
   return tmpprice;
}

