function cart(){$("a[rel^='prettyPhoto']").prettyPhoto();this.totalItems=0;this.totalPrice=0;this.items=new Array();this.ItemColumns=["Name","Image","price","quantity","Total","max"];this.initialize=function(){this.setUpEvents();this.updatePageElements();this.updateNamePrice();return};this.checkOutEvent=function(){simpleCart.checkOut();return false};this.emptyEvent=function(){simpleCart.empty();return false};this.setUpEvents=function(){var a=0,b,c=getElementsByClassName("simpleCart_total");a=0;c=getElementsByClassName("simpleCart_checkout");for(a=0;a<c.length;a++){b=c[a];if(b.addEventListener){b.addEventListener("click",this.checkOutEvent,false)}else{if(b.attachEvent){b.attachEvent("onclick",this.checkOutEvent)}}}a=0;c=getElementsByClassName("simpleCart_empty");for(a=0;a<c.length;a++){b=c[a];if(b.addEventListener){b.addEventListener("click",this.emptyEvent,false)}else{if(b.attachEvent){b.attachEvent("onclick",this.emptyEvent)}}}return};this.add=function(){newItem=new item();var a=0;for(a=0;a<arguments.length;a++){temp=arguments[a];data=temp.split("=");newItem.addValue(data[0],data[1])}if(!newItem.getValue("name")||!newItem.getValue("price")){return false}isnew=true;this.totalItems=this.totalItems+newItem.getValue("quantity");a=0;for(a=0;a<this.items.length;a++){tempItem=this.items[a];if(tempItem.equalTo(newItem)){tempItem.addValue("quantity",(parseInt(tempItem.getValue("quantity"))+1));this.totalPrice=this.totalPrice+parseFloat(tempItem.getValue("price"));isnew=false}}if(!newItem.getValue("quantity")){newItem.addValue("quantity",1)}if(isnew){this.items[this.items.length]=newItem;this.totalPrice=this.totalPrice+parseFloat(newItem.getValue("price"))}this.updatePageElements();return};this.addItem=function(b){var a=0;for(a=0;a<this.items.length;a++){var c=this.items[a];if(c.equalTo(b)){c.addValue("quantity",parseInt(b.getValue("quantity"))+parseInt(c.getValue("quantity")));this.totalItems=this.totalItems+parseInt(b.getValue("quantity"));this.totalPrice=this.totalPrice+parseInt(b.getValue("quantity"))*parseFloat(b.getValue("price"));return}}this.items[this.items.length]=b;this.totalItems=this.totalItems+parseInt(b.getValue("quantity"));this.totalPrice=this.totalPrice+parseInt(b.getValue("quantity"))*parseFloat(b.getValue("price"));return};this.updateCookie=function(){cookieString=String(this.totalItems)+"&"+String(this.totalPrice);x=0;for(x=0;x<this.items.length;x++){tempItem=this.items[x];cookieString=cookieString+"&"+tempItem.cookieString()}cookieString=escape(cookieString);createCookie("simpleCart",cookieString,30)};this.updateNamePrice=function(){var a=window.location.href.split("/");for(x=0;x<this.items.length;x++){datas="conteur="+x+"&nom="+this.items[x].getValue("name")+"&language="+a[3];$.ajax({type:"POST",url:"/cart/ajaxUpdateCart.php",data:datas,success:function(c){var b=c.split("--");simpleCart.updateNamePriceSub(b[1],b[0])}})}};this.updateNamePriceSub=function(a,d){this.items[a].addValue("name",d);var c=0;for(var b=0;b<this.items.length;b++){c+=((this.items[b].getValue("price"))*(this.items[b].getValue("quantity")))}this.totalPrice=c;this.updatePageElements()};this.empty=function(){$("#PCresult").html("");this.items=new Array();this.totalItems=0;this.totalPrice=0;this.updatePageElements();produitDeleteAll();return false};this.deleteItem=function(b){found=false;produitDelete(b.getValue("id"));var a=new Array();for(x=0;x<this.items.length;x++){tempItem=this.items[x];if(tempItem.equalTo(b)){found=true;this.totalItems=this.totalItems-parseFloat(tempItem.getValue("quantity"));this.totalPrice=this.totalPrice-parseFloat(tempItem.getValue("price"))*tempItem.getValue("quantity")}if(found){if(x<(this.items.length-1)){a[x]=this.items[x+1]}}else{a[x]=this.items[x]}}this.items=a;this.updatePageElements();return false};this.options=function(){var a=0;for(a=0;a<this.items.length;a++){var b=this.items[a];if(b.optionList()){return true}}return false};this.updatePageElements=function(){var d=window.location.href.split("/");if(d[3]==""){d[3]="fr"}$("#PC").html("");$("#checkout").removeClass("active");var j=0,e,a=getElementsByClassName("simpleCart_total");var c;for(j=0;j<a.length;j++){e=a[j];e.innerHTML=this.returnTotalPrice()}j=0;a=getElementsByClassName("simpleCart_quantity");for(j=0;j<a.length;j++){e=a[j];e.innerHTML=String(this.totalItems)}a=getElementsByClassName("simpleCart_items");for(j=0;j<a.length;j++){cartTable=a[j];newRow=document.createElement("tr");var j=0,f=0;while(cartTable.childNodes[0]){cartTable.removeChild(cartTable.childNodes[0])}tempCell=document.createElement("th");if(d[3]=="fr"){tempCell.innerHTML="Produits"}else{if(d[3]=="en"){tempCell.innerHTML="Products"}}tempCell.className="td1";newRow.appendChild(tempCell);tempCell=document.createElement("th");if(d[3]=="fr"){tempCell.innerHTML="Prix unitaire"}else{if(d[3]=="en"){tempCell.innerHTML="Price"}}tempCell.className="td2";newRow.appendChild(tempCell);tempCell=document.createElement("th");if(d[3]=="fr"){tempCell.innerHTML="Quantité"}else{if(d[3]=="en"){tempCell.innerHTML="Quantity"}}tempCell.className="td3";newRow.appendChild(tempCell);tempCell=document.createElement("th");if(d[3]=="fr"){tempCell.innerHTML="Prix total"}else{if(d[3]=="en"){tempCell.innerHTML="Total Price"}}tempCell.className="td4";newRow.appendChild(tempCell);tempCell=document.createElement("th");tempCell.className="td5";newRow.appendChild(tempCell);newRow.className="thead";cartTable.appendChild(newRow);j=0;for(j=0;j<this.items.length;j++){tempItem=this.items[j];newRow=document.createElement("tr");f=0;c=document.createElement("tr");for(f=0;f<this.ItemColumns.length;f++){tempCell=document.createElement("td");if(this.ItemColumns[f]=="Image"){if(tempItem.getValue("image")){tempCell.innerHTML='<img src="'+tempItem.getValue("image")+'" width="50" height="30" />';newRow.appendChild(tempCell)}}if(this.ItemColumns[f]=="Name"){tempCell.className="td1";tempCell.innerHTML=tempItem.getValue("name");newRow.appendChild(tempCell);if(parseInt(tempItem.getValue("quantity"))>parseInt(tempItem.getValue("max"))&&parseInt(tempItem.getValue("max"))!=0){var b=document.createElement("div");b.className="alert";if(d[3]=="fr"||d[3]==""){b.innerHTML="Limit&eacute; &agrave; "+tempItem.getValue("max")+" par client"}if(d[3]=="en"){b.innerHTML="Limited to "+tempItem.getValue("max")+" per customer"}this.updateQuantity(tempItem.getValue("name"),tempItem.getValue("max"));tempCell.appendChild(b)}}else{if(this.ItemColumns[f]=="price"){tempCell.className="td2";tempCell.innerHTML=this.returnFormattedPrice(tempItem.getValue("price"));newRow.appendChild(tempCell)}else{if(this.ItemColumns[f]=="quantity"){tempCell.className="td3";tempCell.innerHTML='<input type="text" rel="'+tempItem.getValue("name")+'" size="1" onchange="simpleCart.updateQuantity($(this).attr(\'rel\'),this.value);simpleCart.updatePageElements();return false;" value="'+tempItem.getValue("quantity")+'" />';newRow.appendChild(tempCell)}else{if(this.ItemColumns[f]=="Total"){tempCell.className="td4";tempCell.innerHTML=this.returnFormattedPrice(tempItem.getValue("quantity")*tempItem.getValue("price"));newRow.appendChild(tempCell)}}}}}tempCell=document.createElement("td");tempCell.className="td5";tempCell.innerHTML="<span onclick='suppItem("+j+")'></span>";newRow.appendChild(tempCell);newRow.appendChild(tempCell);newRow.className="produit";cartTable.appendChild(newRow);$(b).slideDown("normal");setTimeout(function(){$(b).slideUp("normal")},3000)}newRow=document.createElement("tr");tempCell=document.createElement("td");tempCell.className="td1";newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td2";newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td3";newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td4";newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td5";newRow.appendChild(tempCell);newRow.className="break";cartTable.appendChild(newRow);newRow=document.createElement("tr");tempCell=document.createElement("td");tempCell.className="td1";newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td2";newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td3";if(d[3]=="fr"){tempCell.innerHTML="Sous-total"}else{if(d[3]=="en"){tempCell.innerHTML="Sub Total"}}newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td4";tempCell.innerHTML=this.returnTotalPrice();newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td5";newRow.appendChild(tempCell);newRow.className="totalRow";cartTable.appendChild(newRow);newRow=document.createElement("tr");tempCell=document.createElement("td");tempCell.className="td1";newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td2";newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td3";if(d[3]=="fr"){tempCell.innerHTML="Taxes"}else{if(d[3]=="en"){tempCell.innerHTML="Tax"}}newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td4";var h=false;var g=0;for(counter=0;counter<this.items.length;counter++){tempItem=this.items[counter];if(tempItem.getValue("id")=="member"){h=true;g=counter;break}}if(h){this.taxe=(this.totalPrice-this.items[g].getValue("price"))*0.05+2.28}else{this.taxe=this.totalPrice*0.05}tempCell.innerHTML=this.returnFormattedPriceWithCurrency(this.taxe);newRow.appendChild(tempCell);tempCell=document.createElement("td");tempCell.className="td5";newRow.appendChild(tempCell);newRow.className="taxesRow";cartTable.appendChild(newRow)}$("#PCTotal").html("");if($("#livraisonlist").val()!=null){PCGet()}loading=false;return false};this.updatePrices=function(){var a=0,b,c=getElementsByClassName("itemTotal");for(a=0;a<c.length;a++){b=c[a+1];tempItem=this.items[a];b.innerHTML=this.returnFormattedPrice(tempItem.getValue("quantity")*tempItem.getValue("price"))}return false};this.returnTotalPrice=function(){var b;var a=0;this.totalPrice=0;for(a=0;a<this.items.length;a++){tempItem=this.items[a];this.totalPrice=this.totalPrice+parseFloat(tempItem.getValue("price"))*parseInt(tempItem.getValue("quantity"))}return this.returnFormattedPriceWithCurrency(this.totalPrice)};this.returnFormattedPrice=function(a){var b=window.location.href.split("/");temp=Math.round(a*100);change=temp%100;if(change==0){change=".00"}else{if(change<10){change=String("0")+String(change)}change="."+String(change)}temp=String(Math.floor(temp/100));if(b[3]=="fr"||b[3]==""){return temp+change+"$"}else{if(b[3]=="en"){return"$"+temp+change}}};this.returnFormattedPriceWithCurrency=function(a){var b=window.location.href.split("/");temp=Math.round(a*100);change=temp%100;if(change==0){change=".00"}else{if(change<10){change=String("0")+String(change)}change="."+String(change)}temp=String(Math.floor(temp/100));if(b[3]=="fr"||b[3]==""){return temp+change+"$"}else{if(b[3]=="en"){return"$"+temp+change}}};this.updateQuantity=function(b,c){for(var d=0;d<this.items.length;d++){if(this.items[d].getValue("name")==b){var a=this.items[d]}}a.addValue("quantity",c);return false};this.checkOut=function(){if($("#checkout").hasClass("active")){var d=window.location.href.split("/");var b=0;var a="";tempItem=this.items[b];a+="shipping="+$("#livraisonlist").val();a+="&cp="+$("#cp").val();a+="&language="+d[3];a+="&pays="+$("#pays").val();a+="&currency="+$("#formDevise select").val();for(b=0;b<this.items.length;b++){tempItem=this.items[b];a+="&names[]="+tempItem.getValue("name")+"&quantities[]="+tempItem.getValue("quantity")}if(d[3]=="fr"||d[3]==""){var c="Le chargement de PayPal peut prendre quelques minutes"}else{var c="Paypal may take a moment to load..."}$.ajax({type:"POST",url:"/modules/checkout.php",data:a,success:function(e){if($.browser.msie||$.browser.safari){window.location=e}else{$.prettyPhoto.open(e+"&iframe=true&width=900&height=480","PayPal",c)}}})}}}function item(){this.names=new Array();this.values=new Array();this.addValue=function(c,d){if(c=="quantity"){if(d==1){this.addValue("price",this.getValue("price1"))}if(d>1){this.addValue("price",this.getValue("price2"))}if(d>4){this.addValue("price",this.getValue("price3"))}if(d>14){this.addValue("price",this.getValue("price4"))}if(d>24||parseInt(this.getValue("promo"))){this.addValue("price",this.getValue("price5"))}produitUpdate(this.getValue("id"),d)}if(this.names.length!=this.values.length){return false}found=false;for(var b=0;b<this.names.length;b++){if(this.names[b]==c){this.values[b]=d;return}}if(!found){this.names[this.names.length]=c;this.values[this.values.length]=d}return};this.getValue=function(a){var b=0;for(b=0;b<this.names.length;b++){if(a==this.names[b]){return this.values[b]}}return null};this.equalTo=function(a){var b=0;for(b=0;b<this.names.length;b++){if(this.names[b]!="quantity"&&this.names[b]!="price"&&(a.getValue(this.names[b])!=this.values[b])){return false}}return true};this.getSize=function(){return this.names.length};this.cookieString=function(){returnString="";var a=0;returnString=this.names[a]+"="+this.values[a];a=1;for(a=1;a<this.names.length;a++){returnString=returnString+","+this.names[a]+"="+this.values[a]}return returnString};this.functionString=function(){returnString="'";var a=0;returnString="'"+this.names[a]+"="+this.values[a];a=1;for(a=1;a<this.names.length;a++){returnString=returnString+"','"+this.names[a]+"="+this.values[a]}returnString=returnString+"'";return returnString};this.optionList=function(){returnString="";if(this.getSize()<4){return null}var a=0;for(a=0;a<this.names.length;a++){if(this.names[a]!="quantity"&&this.names[a]!="price"&&this.names[a]!="name"&&this.names[a]!="image"){returnString=returnString+this.names[a]+":"+this.values[a]+", "}}while(returnString.charAt(returnString.length-1)==","||returnString.charAt(returnString.length-1)==" "||returnString.charAt(returnString.length)==":"){returnString=returnString.substring(0,returnString.length-1)}return returnString}}function createCookie(c,d,e){if(e){var b=new Date();b.setTime(b.getTime()+(e*24*60*60*1000));var a="; expires="+b.toGMTString()}else{var a=""}document.cookie=c+"="+d+a+"; path=/"}function readCookie(b){var e=b+"=";var a=document.cookie.split(";");for(var d=0;d<a.length;d++){var f=a[d];while(f.charAt(0)==" "){f=f.substring(1,f.length)}if(f.indexOf(e)==0){return unescape(f.substring(e.length,f.length))}}return null}function eraseCookie(a){createCookie(a,"",-1)}var getElementsByClassName=function(b,a,c){if(document.getElementsByClassName){getElementsByClassName=function(j,m,h){h=h||document;var d=h.getElementsByClassName(j),l=(m)?new RegExp("\\b"+m+"\\b","i"):null,e=[],g;for(var f=0,k=d.length;f<k;f+=1){g=d[f];if(!l||l.test(g.nodeName)){e.push(g)}}return e}}else{if(document.evaluate){getElementsByClassName=function(o,r,n){r=r||"*";n=n||document;var g=o.split(" "),p="",l="http://www.w3.org/1999/xhtml",q=(document.documentElement.namespaceURI===l)?l:null,h=[],d,f;for(var i=0,k=g.length;i<k;i+=1){p+="[contains(concat(' ', @class, ' '), ' "+g[i]+" ')]"}try{d=document.evaluate(".//"+r+p,n,q,0,null)}catch(m){d=document.evaluate(".//"+r+p,n,null,0,null)}while((f=d.iterateNext())){h.push(f)}return h}}else{getElementsByClassName=function(r,u,q){u=u||"*";q=q||document;var h=r.split(" "),t=[],d=(u==="*"&&q.all)?q.all:q.getElementsByTagName(u),p,j=[],o;for(var i=0,e=h.length;i<e;i+=1){t.push(new RegExp("(^|\\s)"+h[i]+"(\\s|$)"))}for(var g=0,s=d.length;g<s;g+=1){p=d[g];o=false;for(var f=0,n=t.length;f<n;f+=1){o=t[f].test(p.className);if(!o){break}}if(o){j.push(p)}}return j}}}return getElementsByClassName(b,a,c)};function createCart(){simpleCart.initialize();return}function PCGet(){var c=window.location.href.split("/");var b=0;tempItem=simpleCart.items[b];var a="cp="+$("#cp").val();a+="&pays="+$("#pays").val();a+="&language="+c[3];for(b=0;b<simpleCart.items.length;b++){tempItem=simpleCart.items[b];a+="&names[]="+tempItem.getValue("name")+"&quantities[]="+tempItem.getValue("quantity")}$(".transport .td3 span").addClass("loading");loading=true;$.ajax({type:"POST",url:"/modules/ajaxPosteCanada.php",data:a,success:function(d){if(loading){if(d!=""){$("#checkout").addClass("active");$("#PC").html(d);PCTotal();if($("#PCTotal").html()!=""){$(".transport .td3 span").removeClass("loading")}}else{$(".transport .td3 span").removeClass("loading")}}}})}function PCGetCountry(){var c=window.location.href.split("/");var b=0;tempItem=simpleCart.items[b];var a="cp="+$("#cp").val();a+="&pays="+$("#pays").val();a+="&language="+c[3];for(b=0;b<simpleCart.items.length;b++){tempItem=simpleCart.items[b];a+="&names[]="+tempItem.getValue("name")+"&quantities[]="+tempItem.getValue("quantity")}$("#PC").html("");loading=true;$.ajax({type:"POST",url:"/modules/ajaxPosteCanada.php",data:a,success:function(d){if(loading){if(d!=""){$("#PC").html(d);PCTotal();if($("#PCTotal").html()!=""){}}else{$("#PC").html("")}}}})}function PCTotal(){var a=simpleCart.returnFormattedPriceWithCurrency((parseFloat(simpleCart.totalPrice+simpleCart.taxe)+parseFloat($("#livraisonlist").val())));a=a;$("#PCTotal").html(a)}var loading=false;var simpleCart=new cart();$(document).ready(function(){createCart()});function suppItem(a){var b=simpleCart.items[a];simpleCart.deleteItem(b)};