function IdeaCart(){this.productCount=0;this.products=new Hash;if($("hiddenCart")){this.cartTemplate=new Template("")}else{this.cartTemplate=new Template('<table width=100% border=0 cellspacing=0 cellpadding=0><tr><td height=16><img src="images/arrowblack.gif" width=7 height=8><b> #{product}</b></td><td rowspan=2 align=right valign=top><a href="JavaScript:ideacart1.RemoveFromCart(\'#{pid}\')"><img src="images/xx.gif" border=0></a></td></tr><tr><td height=17><b>#{amount}</b> #{stockTypeLabel} <b style="color:#FF0000; padding-left:10px;">#{price} #{curr}</b></td></tr></table>')}this.lastUpdate="";this.lastId=new Hash}if(noDrag==undefined)var noDrag=0;var pdrags=new Hash;var DDS=new Array;var totalAmount=0;IdeaCart.prototype.AddToCartBasic=function(a,b,c,d,e,f,g,h,j,k,l){b=unescape(b);j=unescape(j);if(DDS.length>0&&this.lastId.toArray().length==0&&this.productCount>0){this.products.each(function(a){if(ideacart1.lastId[a.value.pid]==undefined)ideacart1.lastId[a.value.pid]=0;if(a.value.ext>parseInt(ideacart1.lastId[a.value.pid]))ideacart1.lastId[a.value.pid]=a.value.ext})}temp2="";if(DDS.length>0){var m=new Array;for(i=0;i<DDS.length;i++){var n=DDS[i].id;optionLabel=$(n).value;if(optionLabel!="")m.push(optionLabel)}temp2=m.join("/")}if(temp2!=""){b=b+" "+temp2}b=b.replace(/[^0-9a-zA-ZğüşıiöçĞÜŞIİÖÇ\n\t\s\.\*\+&#;,=\[\]{}\(\)\/\\%\$\^\?'"@:<>\-_!€~]/gi,"");if(b.indexOf("}")>0){b=b.replace(/}/gi,"}")}if(b.indexOf("{")>0){b=b.replace(/{/gi,"{")}pid2=a;if(this.lastId[a]&&this.products["pr_"+a+"_"+this.lastId[a]]){exist=false;index=0;for(i=1;i<=this.lastId[a];i++){if(!this.products["pr_"+a+"_"+i])continue;currentel=this.products["pr_"+a+"_"+i]["product"].toString();if(b.toLowerCase()==currentel.toLowerCase()){exist=true;index=i}}if(exist){ext=index}else{this.lastId[a]++;ext=this.lastId[a]}}else{ext=1;this.lastId[a]=1}a=a+"_"+ext;if($("quantity_"+pid2)!=null){if(isNaN(parseFloat($("quantity_"+pid2).value))){alert("Lütfen Stok Adedini Doğru Giriniz.");$("quantity_"+pid2).value=1;return}if(parseFloat($("realamount_"+pid2).value)<parseFloat($("quantity_"+pid2).value)){$("quantity_"+pid2).value=parseInt($("realamount_"+pid2).value)}}if($("cartItem_"+a)!=null){if(this.products["pr_"+a]["amount"]>=parseFloat($("realamount_"+pid2).value)){this.quantityWarn();return}var o=1;if($("quantity_"+pid2)!=null){o=parseFloat($("quantity_"+pid2).value);this.products["pr_"+a]["amount"]=parseFloat(this.products["pr_"+a]["amount"])+o;if(this.products["pr_"+a]["amount"]>=parseFloat($("realamount_"+pid2).value)){this.products["pr_"+a]["amount"]=parseFloat($("realamount_"+pid2).value);this.quantityWarn()}else{if($("hiddenCart")){var p=parseInt($("hiddenCart").value);p=p+parseFloat($("quantity_"+pid2).value);$("hiddenCart").value=p;$("hiddenCartContainer").innerHTML="("+p+")"}}}else{this.products["pr_"+a]["amount"]=parseFloat(this.products["pr_"+a]["amount"])+1;if($("hiddenCart")){var p=parseInt($("hiddenCart").value);p=p+1;$("hiddenCart").value=p;$("hiddenCartContainer").innerHTML="("+p+")"}}pr=parseFloat(this.products["pr_"+a]["price"]);if(f!=0&&g==1||g==0){if(g==0){pr=f}else{pr=pr*(100-f)/100}}pr=pr*(100+e)/100;pr=pr.toFixed(2);total=parseFloat(pr)*parseFloat(this.products["pr_"+a]["amount"]);total=total.toFixed(2);$("cartItem_inner_"+a).innerHTML=this.cartTemplate.evaluate({product:this.products["pr_"+a]["product"].truncate(22,"..."),amount:this.products["pr_"+a]["amount"],pid:a,price:total,curr:d,tax:e,rebate:f,rebateType:g,bt:h,stockTypeLabel:j,rootProduct:l});totalAmount+=parseFloat(ideacurr1.Convert(pr*o,d,ideacurr1.DefaultCurr));totalAmount=parseFloat(totalAmount.toFixed(2))}else{if(parseFloat($("realamount_"+pid2).value)==0)return;this.productCount++;this.products["pr_"+a]=new Hash;if($("quantity_"+pid2)!=null){this.products["pr_"+a]["amount"]=parseFloat($("quantity_"+pid2).value);if(this.products["pr_"+a]["amount"]>=parseFloat($("realamount_"+pid2).value)){this.products["pr_"+a]["amount"]=parseFloat($("realamount_"+pid2).value);this.quantityWarn()}if($("hiddenCart")){var p=parseInt($("hiddenCart").value);p=p+parseFloat($("quantity_"+pid2).value);$("hiddenCart").value=p;$("hiddenCartContainer").innerHTML="("+p+")"}}else{this.products["pr_"+a]["amount"]=1;if($("hiddenCart")){var p=parseInt($("hiddenCart").value);p=p+1;$("hiddenCart").value=p;$("hiddenCartContainer").innerHTML="("+p+")"}}this.products["pr_"+a]["price"]=c;this.products["pr_"+a]["product"]=b;this.products["pr_"+a]["pid"]=pid2;this.products["pr_"+a]["curr"]=d;this.products["pr_"+a]["tax"]=e;this.products["pr_"+a]["rebate"]=f;this.products["pr_"+a]["rebateType"]=g;this.products["pr_"+a]["bt"]=h;this.products["pr_"+a]["ext"]=ext;this.products["pr_"+a]["stockTypeLabel"]=j;this.products["pr_"+a]["rootProduct"]=l;var q=document.createElement("div");Element.extend(q);q.hide();q.id="cartItem_"+a;var r=document.createElement("div");Element.extend(r);r.addClassName("productOnCart");pr=c;if(f!=0&&g==1||g==0){if(g==0){pr=f}else{pr=pr*(100-f)/100}}pr=pr*(100+e)/100;pr=pr.toFixed(2);total=parseFloat(pr)*parseFloat(this.products["pr_"+a]["amount"]);total=total.toFixed(2);totalAmount+=parseFloat(ideacurr1.Convert(pr,this.products["pr_"+a]["curr"],ideacurr1.DefaultCurr))*parseFloat(this.products["pr_"+a]["amount"]);totalAmount=parseFloat(totalAmount.toFixed(2));r.innerHTML=this.cartTemplate.evaluate({product:this.products["pr_"+a]["product"].truncate(22,"..."),amount:this.products["pr_"+a]["amount"],pid:a,price:total,curr:d,stockTypeLabel:j});r.id="cartItem_inner_"+a;q.appendChild(r);if(this.productCount==1)$("CartContainer").innerHTML="";$("CartContainer").appendChild(q);Effect.Appear("cartItem_"+a,{duration:1})}if($("totalCartAmount")){$("totalCartAmount").innerHTML="<b>Toplam :</b> <b style='color:red;'>"+totalAmount+" "+ideacurr1.DefaultCurr+"</b>"}if(DDS.length==0){if(this.products["pr_"+a]["amount"]>=parseFloat($("realamount_"+pid2).value)){if($("addtocart_product")!=null){$("cartPic_"+pid2).src="themes/"+buttonsDir+"/nostock_product.gif"}else{$("cartPic_"+pid2).src="themes/"+buttonsDir+"/nostock.gif"}if(pdrags[pid2])pdrags[pid2].destroy()}var s=document.createElement("div");Element.extend(s);if($("Item_"+pid2)){itemDiv=$("Item_"+pid2)}else if($("Row_"+pid2)){itemDiv=$("Row_"+pid2)}s.innerHTML=itemDiv.innerHTML;document.body.appendChild(s);s.setStyle({position:"absolute",width:itemDiv.getWidth(),overflow:"hidden",backgroundColor:"#FFFFFF"});pos=Position.cumulativeOffset(itemDiv);s.style.left=pos[0]+"px";s.style.top=pos[1]+"px";cartpos=Position.cumulativeOffset($("CartContainer"));new Effect.Parallel([new Effect.MoveBy(s,cartpos[1]-pos[1],cartpos[0]-pos[0],{sync:true}),new Effect.Opacity(s,{sync:true,to:0,from:1,afterFinish:function(a){a.element.remove()}})],{duration:1})}if(k){if(SaveCart(escape(this.products.inspect()),"type=r"))window.location="index.php?do=catalog/order"}else{SaveCart(escape(this.products.inspect()),"type=r")}if($("cartPromotion")!=null){jQuery.get("index.php?do=catalog/ajax&ref=getPromotions",function(a){if(a.length>0){$("cartPromotion").innerHTML=a;$("cartPromotion").show()}else{$("cartPromotion").innerHTML="";$("cartPromotion").hide()}})}};IdeaCart.prototype.AddToCart=function(a,b,c,d,e,f,g,h,i,j,k,l){if(!k){new Ajax.Request("index.php?do=catalog/hasOption&pid="+a,{method:"get",onSuccess:function(k){if(k.responseText=="1"){window.location="index.php?do=catalog/product&pid="+a;return false}else{ideacart1.AddToCartBasic(a,b,c,d,e,f,g,h,i,j,l)}}})}else{ideacart1.AddToCartBasic(a,b,c,d,e,f,g,h,i,j,l)}};IdeaCart.prototype.RemoveFromPage=function(a){Element.extend(a);a.remove()};IdeaCart.prototype.TruncateCart=function(a){this.productCount=0;if($("totalCartAmount"))$("totalCartAmount").innerHTML="";this.products=new Hash;this.FreeCart();SaveCart(escape(this.products.inspect()),"type=e,method=post")};IdeaCart.prototype.FreeCart=function(a){if($("hiddenCart")){$("CartContainer").innerHTML=""}else{$("CartContainer").innerHTML="<center><br/>Alışveriş sepetinizde <br/> ürün bulunmamaktadır.<br/><br/></center>"}};IdeaCart.prototype.RemoveFromCart=function(a){if(this.products["pr_"+a]==undefined)return;pid2=this.products["pr_"+a]["pid"];if(this.products["pr_"+a]){if(this.products["pr_"+a]["amount"]>1){this.products["pr_"+a]["amount"]=this.products["pr_"+a]["amount"]-1;rebate=ideacart1.products["pr_"+a]["rebate"];rebateType=ideacart1.products["pr_"+a]["rebateType"];tax=ideacart1.products["pr_"+a]["tax"];pr=parseFloat(this.products["pr_"+a]["price"]);if(rebate!=0&&rebateType==1||rebateType==0){if(rebateType==0){pr=rebate}else{pr=pr*(100-rebate)/100}}pr=pr*(100+tax)/100;pr=pr.toFixed(2);total=parseFloat(pr)*parseFloat(this.products["pr_"+a]["amount"]);total=total.toFixed(2);totalAmount-=parseFloat(ideacurr1.Convert(pr,ideacart1.products["pr_"+a]["curr"],ideacurr1.DefaultCurr));totalAmount=parseFloat(totalAmount.toFixed(2));curr=this.products["pr_"+a]["curr"];$("cartItem_inner_"+a).innerHTML=this.cartTemplate.evaluate({product:this.products["pr_"+a]["product"].truncate(22,"..."),amount:this.products["pr_"+a]["amount"],pid:a,price:total,curr:this.products["pr_"+a]["curr"],stockTypeLabel:this.products["pr_"+a]["stockTypeLabel"]})}else{curr=this.products["pr_"+a]["curr"];rebate=ideacart1.products["pr_"+a]["rebate"];rebateType=ideacart1.products["pr_"+a]["rebateType"];tax=ideacart1.products["pr_"+a]["tax"];pr=parseFloat(this.products["pr_"+a]["price"]);if(rebate!=0&&rebateType==1||rebateType==0){if(rebateType==0){pr=rebate}else{pr=pr*(100-rebate)/100}}pr=pr*(100+tax)/100;total=parseFloat(pr)*parseFloat(this.products["pr_"+a]["amount"]);total=total.toFixed(2);totalAmount-=parseFloat(ideacurr1.Convert(pr,this.products["pr_"+a]["curr"],ideacurr1.DefaultCurr));totalAmount=parseFloat(totalAmount.toFixed(2));this.products.remove("pr_"+a);this.productCount--;new Effect.Fade("cartItem_"+a,{duration:1,afterFinish:function(a){ideacart1.RemoveFromPage(a.element);if(ideacart1.productCount<1){ideacart1.productCount=0;ideacart1.FreeCart()}}})}if($("cartPic_"+pid2)!=undefined){if($("addtocart_product")!=null){$("cartPic_"+pid2).src="themes/"+buttonsDir+"/addtocart_product.gif"}else{$("cartPic_"+pid2).src="themes/"+buttonsDir+"/addtocart.gif"}if(!noDrag)pdrags[a]=new Draggable("Item_"+pid2,{revert:true,ghosting:false,zindex:1003})}if(this.productCount<1){totalAmount=0}if($("totalCartAmount")){$("totalCartAmount").innerHTML=totalAmount>0?"<b>Toplam :</b> <b style='color:red;'>"+totalAmount+" "+ideacurr1.DefaultCurr+"</b>":"";SaveCart(escape(this.products.inspect()),"type=r,method=post")}}if($("cartPromotion")!=null){jQuery.get("index.php?do=catalog/ajax&ref=getPromotions",function(a){if(a.length>0){$("cartPromotion").innerHTML=a;$("cartPromotion").show()}else{$("cartPromotion").innerHTML="";$("cartPromotion").hide()}})}};IdeaCart.prototype.CompleteRemoveFromCart=function(a){this.products.remove("pr_"+a);this.productCount--;ideacart1.RemoveFromPage($("cartItem_"+a));ideacart1.lastId=new Hash;this.products.each(function(a){ideacart1.lastId[a.value.pid]=a.value.ext});if(ideacart1.productCount<1){ideacart1.productCount=0;ideacart1.FreeCart()}};IdeaCart.prototype.ReloadCart=function(){this.productCount=0;$("CartContainer").innerHTML="";var a=0;var b="";totalAmount=0;this.products.each(function(c){pid=c.key.substring(3);var d=document.createElement("div");Element.extend(d);d.id="cartItem_"+pid;var e=document.createElement("div");Element.extend(e);e.addClassName("productOnCart");pr=parseFloat(ideacart1.products["pr_"+pid]["price"]);rebate=ideacart1.products["pr_"+pid]["rebate"];rebateType=ideacart1.products["pr_"+pid]["rebateType"];tax=ideacart1.products["pr_"+pid]["tax"];if(rebate!=0){if(rebateType==0){pr=rebate}else{pr=pr*(100-rebate)/100}}pr=pr*(100+tax)/100;total=parseFloat(pr)*parseFloat(ideacart1.products["pr_"+pid]["amount"]);if($("hiddenCart")){a=a+parseFloat(ideacart1.products["pr_"+pid]["amount"]);$("hiddenCart").value=a;$("hiddenCartContainer").innerHTML="("+a+")"}total=total.toFixed(2);b=ideacart1.products["pr_"+pid]["curr"];totalAmount+=parseFloat(ideacurr1.Convert(total,b,ideacurr1.DefaultCurr));e.innerHTML=ideacart1.cartTemplate.evaluate({product:ideacart1.products["pr_"+pid]["product"].truncate(22,"..."),amount:ideacart1.products["pr_"+pid]["amount"],pid:pid,price:total,curr:ideacart1.products["pr_"+pid]["curr"],stockTypeLabel:ideacart1.products["pr_"+pid]["stockTypeLabel"]});e.id="cartItem_inner_"+pid;d.appendChild(e);ideacart1.productCount++;$("CartContainer").appendChild(d)});totalAmount=parseFloat(totalAmount.toFixed(2));if(ideacart1.productCount==0){if($("hiddenCart")){$("CartContainer").update("");totalAmount=0}else{$("CartContainer").update("<center><br>Alışveriş sepetinizde <br> ürün bulunmamaktadır.<br><br></center>");$("totalCartAmount").update="";totalAmount=0}}else{if($("totalCartAmount")){$("totalCartAmount").innerHTML="<b>Toplam :</b> <b style='color:red;'>"+totalAmount+" "+ideacurr1.DefaultCurr+"</b>"}}};IdeaCart.prototype.quantityWarn=function(){if($("quantityWarn")!=null){quantityWarning=quantityWarning.replace("(arg0)",parseFloat($("realamount_"+pid2).value));$("quantityWarn").update(quantityWarning);Effect.Appear("quantityWarn",{queue:{position:"front",scope:"myscope",limit:2},duration:1});Effect.Fade("quantityWarn",{queue:{position:"end",scope:"myscope",limit:2},duration:1})}else{quantityWarning=quantityWarning.replace("(arg0)",parseFloat($("realamount_"+pid2).value));alert(quantityWarning)}}

