var stotal=0;
var count=1;
var str="Price::Qty::Code::Description::Flags|"
function view_cart(vartaux,devisetmp) {
   mycookies=new Array(30);
   var i=0;
     var startpoint=0;
   whole_len=document.cookie.length;
   while(whole_len!=startpoint && i< 30)
   {
     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();
	stotal = 0
    for (j=0;j<i;j++)
     {

	if((mycookies[j].substring(0,4)=="oops")||(mycookies[j].substring(0,5)==" oops"))
	   getCookie(mycookies[j]);
     }
	stotaldevise = (parseFloat(vartaux) * stotal);
	stotaldevise = price_format(stotaldevise);
	stotal=price_format(stotal);
	devise = devisetmp;
document.write("</table><center><table BORDER=0 COLS=1 WIDTH=90%><tr><td colspan=2><hr SIZE=1 WIDTH=100%></td></tr><tr><td align=left>&nbsp;<IMG SRC='images/carte.gif' BORDER=0></td><td align=right><b>Sous-total : "+stotal+"$&nbsp;(CDN)&nbsp;&nbsp;/&nbsp;&nbsp;"+stotaldevise+"&nbsp;"+devise+"&nbsp;</b><font FACE=ARIAL SIZE=-2></td></tr></table><INPUT TYPE='hidden' NAME='Products' VALUE="+str+"></FORM></center>")   
}


function getCookie (acookie) {
    clen = acookie.length;
    nlen= acookie.indexOf("=",0);
   
    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=cname.substring(sname_len+1,dlen)
    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="oops"+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);
    printcontent();
}

function putback(str1){
  document.cookie="oops"+str1+"=bb; expires=Saturday, 16-Sep-90 23:59:59 GMT; path=/"+""; 
}


function printtitle(){
tabletitle="<table border=0 width=90% bgcolor=#D0D0D0><tr align=center>\
<td>Produit(s)</td><td>Description(s)</td><td>Quantité(s)</td><td>Prix / unit.<font size=-2></font></td><td>Prix</td>\
<td>Enlever</td></tr>";
document.write(tabletitle);
}


function printcontent(){
 if (quant!=0)  {
    temp1=product.replace("@","'");
	temp6=descrip.replace("@","'");
	temp2=temp6.replace("Ï","''");
	temp3=quant*price
	temp3=price_format(temp3);
   	document.write("<tr align=center><td bgcolor=#EBEBEB valign=center>"+temp1+"</td><td bgcolor=#EBEBEB valign=center>");
    document.write(temp2+" ...</td><td bgcolor=#EBEBEB valign=center>"+quant+"</td><td bgcolor=#EBEBEB valign=center>");
    document.write(price+"$ (CDN)</td><td bgcolor=#EBEBEB valign=center>"+temp3+"$ (CDN)</td>");
    document.write("<td bgcolor=#EBEBEB><form><input type=submit value=Enlever "); 
    document.write("onClick=\"putback(\'"+store+"+"+descrip+"+"+product);
    document.write("\')\"></td></tr></form>");
	str=str+price+"::"+quant+"::"+temp2+"::"+temp3+"::"+"{GST}{PST}{HST}|"
	stotal=stotal+parseFloat(temp3);
	count=count+1;
	   }
}


function printcontent2(){
  if(quant!=0){
    document.write("<tr align=center><td>"+product+"</td><td>");
    document.write(descrip+"</td><td><form method=get ");
    document.write("action=view.asp><input type=text size=3");
    document.write(" name=quantity value="+quant+">");
    document.write("<input type=hidden name="+price);
    document.write(" value=\""+descrip+"\">");
    document.write("<input type=hidden name=\""+product);
    document.write("\" value=\""+store+"\"></td><td>");
    document.write(price+"</td><td>"+"<a href="+refer+">"+store+"</a>");
    document.write("</td><td><input type=submit value=update onClick=");
    document.write("addtocart(this.form,'view.asp')>");
    document.write("</form></td></tr>");
   }
}

function price_format(tmpprice){

   dot = tmpprice.toString().indexOf(".");
   if(dot!=-1)
      tmpprice=tmpprice.toString().substr(0,dot+4);
   tmpprice=Math.round(tmpprice*100)/100;

   dot = tmpprice.toString().indexOf(".");
   if(dot ==-1)
      tmpprice=tmpprice.toString()+".00";
   else if((tmpprice.toString().length-dot)==2)
      tmpprice=tmpprice.toString()+"0";
   return tmpprice;
}

