var RPC_PATH='/rpc/cart/';var cartAddItem=function(item_id,item_type,item_qty,item_bill_period_months,onSuccessCallback){item_bill_period_months=item_bill_period_months||0;show_working_dialog('Adding Item to Cart');new Request.JSON({url:RPC_PATH+'addItem.php',onSuccess:function(d){hide_working_dialog();if(d=='Success'){cartRefresh();newShowPopout('cart');if(typeof onSuccessCallback=='function'){onSuccessCallback();}}else{efalert('E.Factor Cart',d);}},onFailure:function(){hide_working_dialog();}}).post({id:item_id,type:item_type,qty:item_qty,bill_period_months:item_bill_period_months});};var cartRemoveItem=function(item_id,item_type){new Request.JSON({url:RPC_PATH+'removeItem.php',onSuccess:function(d){hide_working_dialog();if(d=='Success'){cartRefresh();}else{efalert('E.Factor Cart',d);}},onFailure:function(){hide_working_dialog();},onRequest:function(){show_working_dialog('Removing Item from Cart');}}).post({id:item_id,type:item_type});};var cartClear=function(){};var cartRefresh=function(){new Request.JSON({url:RPC_PATH+'getAll.php',onSuccess:function(cart){var _new_list=new Element('ul');if(cart.items.length>0){cart.items.each(function(item){var _new_list_i=new Element('li');var tmpa=new Element('a',{'class':'left','href':'#','onclick':"cartRemoveItem('"+item.id+"','"+item.type+"');return false;"});new Element('img',{'src':WS_IMAGES+'close_small.gif'}).inject(tmpa);tmpa.inject(_new_list_i);var trunc_length=30;if(item.name.length>trunc_length){item.name=item.name.substring(0,trunc_length)+'...';}
new Element('span',{'class':'item','html':item.name}).inject(_new_list_i);var qty_desc;switch(item.bill_period_months){case'1':qty_desc='1 Month';break;case'3':qty_desc='3 Months';break;case'12':qty_desc='1 Year';break;default:qty_desc='1';}
new Element('span',{'class':'qty','html':'x '+qty_desc}).inject(_new_list_i);new Element('span',{'class':'amt','html':item.price}).inject(_new_list_i);_new_list_i.inject(_new_list);});}else{new Element('li',{'html':'You have no items in your cart.'}).inject(_new_list);}
var cartChildren=$('cart').getChildren('ul');cartChildren.each(function(cartitem){_new_list.replaces(cartitem);});cartUpdateTotal(cart.total,cart.currency);},onFailure:function(){}}).get();};var cartUpdateTotal=function(total,currency){if($chk(total)&&$chk(currency)){var tots=$('control_cart').getElements('.cart_total');tots.each(function(t){t.set('html',currency+' '+total);});}else{new Request.JSON({url:RPC_PATH+'getTotalCost.php',onSuccess:function(info){var tots=$('control_cart').getElements('.cart_total');tots.each(function(t){t.set('html',info.currency+' '+info.total);});total=info.total;},onFailure:function(){}}).get();}
$('control_cart').reveal();};window.addEvent('domready',function(){cartRefresh();});