/**
 * @version   1.0.1 - 15 Marzo 2010
 * @author 	  Daniel Ramirez <daniel@ensitech.com>
 * @copyright Ensitech S.C.
 * 
 * Componentes para manipulacion del carrito via Ajax.
 * Compilado con Google Closure - ADVANCED_OPTIMIZATIONS
 * 
 * Original Size:	29.07KB (8.39KB gzipped) 
 * Compiled Size:	10.87KB (3.61KB gzipped)
 * Saved 62.62% off the original size (57.01% off the gzipped size)
 * 
 * Incluye Simple inheritance de John Resig, http://ejohn.org/blog/simple-javascript-inheritance/ 
 */
(function (){
var e,j=j||{};j.c=j.c||{};
(function(a){var b=false,c=/xyz/.test("function () { xyz; } ")?/\b_super\b/:/.*/;a.h=function(){};a.h.extend=function(d){var f=this.prototype;b=true;var g=new this;b=false;for(var h in d)g[h]=typeof d[h]=="function"&&typeof f[h]=="function"&&c.test(d[h])?function(l,m){return function(){var o=this._super;this._super=f[l];var u=m.apply(this,arguments);this._super=o;return u}}(h,d[h]):d[h];a.h=function(){!b&&this.init&&this.init.apply(this,arguments)};a.h.prototype=g;a.h.constructor=a.h;a.h.extend=arguments.callee;
return a.h}})(j);Function.prototype.f=function(a){if(arguments.length<2&&arguments[0]===void 0)return this;var b=this;return function(){return b.apply(a,arguments)}};function k(a,b,c){total=a.length;c=c||null;for(var d=0;d<total;d++)typeof a[d]==="function"&&a[d].apply(b,[c])}function n(a,b){for(var c=a.length,d=0;d<c;d++)b.call(self,a[d])}
function p(a){if(isNaN(a))return"0.00";a=parseFloat(a);var b=a<0?"-":"";a=parseInt((Math.abs(a)+0.0050)*100,10)/100;s=a+"";if(s.indexOf(".")<0)s+=".00";if(s.indexOf(".")==s.length-2)s+="0";return s=b+s}j.c.d=j.h.extend({});
j.c.d.prototype.init=function(){this.r="Store";this.g={};this.s=this.V="";this.D=0;this.u=-1;this.p={add:[],remove:[],get:[]};this.C=this.n="";this.B=true;this.e=typeof Prototype!=="undefined"?"prototype":typeof jQuery!=="undefined"?"jquery":"";if(this.e==="")throw"Se requiere de Prototype o jQuery para el uso del Panel del Carrito";q(this)};j.c.d.prototype.load=function(a){for(var b in a)if(a.hasOwnProperty(b))this.g[a[b].id]=a[b];return this};
function q(a){function b(c){var d=1,f=a.e==="jquery"?"jQuery":"$$";try{d=window[f](".cart_item_amount[rel="+c+"]")[0].value||1}catch(g){r(a,g.message)}a.l(c,d)}if(a.e==="prototype")document.observe("dom:loaded",function(){$$(".cart_add").each(function(c){$(c).observe("click",function(d){b(this.getAttribute("rel"));Event.stop(d)})});$$(".cart_multiple_add").each(function(c){$(c).observe("click",function(d){var f=[],g=[];$$(".cart_item_id").each(function(h){if(h.checked){g.push(h.value);var l=1;try{l=
$$(".cart_item_amount[rel="+h.value+"]")[0].value}catch(m){r(a,m.message)}f.push(l);h.checked=false}});g.length>0&&a.l(g,f);Event.stop(d)})});$$(".cart_delete").each(function(c){$(c).observe("click",function(d){try{a.removeItem(this.getAttribute("rel"))}catch(f){}Event.stop(d)})})});else a.e==="jquery"&&jQuery(window).load(function(){jQuery(".cart_add").click(function(c){b(jQuery(this).attr("rel"));c.preventDefault()});jQuery(".cart_delete").click(function(c){a.removeItem(jQuery(this).attr("rel"));
c.preventDefault()});jQuery.each(jQuery(".cart_multiple_add"),function(){jQuery(this).click(function(c){var d=[],f=[];jQuery.each(jQuery(".cart_item_id"),function(){if(this.checked){f.push(this.value);var g=1;try{g=jQuery(".cart_item_amount[rel="+this.value+"]")[0].value}catch(h){r(a,h.message)}d.push(g);this.checked=false}});f.length>0&&a.l(f,d);c.preventDefault()})})})}function r(a,b){if(typeof console!=="undefined")console[typeof b=="string"?"log":"dir"](b)}
function t(a,b){if(a.e==="jquery")return typeof b==="string"?jQuery.parseJSON(b):b;else if(a.e==="prototype")return b.evalJSON(true);try{return eval("("+b+")")}catch(c){r(a,c.message);return{}}}
function v(a,b){if(typeof b.parameters.module==="undefined"||typeof b.parameters.action==="undefined")throw"Se requiere el modulo y accion a usar";if(a.s=="")throw"Se requiere inicializar el path del cual se obtendra la informacion del carrito";var c=b.onCreate||function(){},d=b.onComplete||function(){};b.onCreate=function(f){if(a.n!=""){try{document.getElementById(a.n).style.display="block"}catch(g){r(a,g.message)}c(f)}};b.onComplete=function(f){if(a.n!=""){try{document.getElementById(a.n).style.display=
"none"}catch(g){r(a,g.message)}d(f)}};b.parameters.format="json";if(a.e==="jquery"){b.async=b.asynchronous||true;b.complete=b.onComplete;b.success=function(f){(b.onSuccess||jQuery.noop)({responseText:f})};b.error=function(f,g,h){(b.onException||jQuery.noop)(f,h)};b.beforeSend=b.onCreate;b.type=b.method||"POST";b.type=b.type.toUpperCase();b.url=a.s;b.data=b.parameters;jQuery.ajax(b)}else a.e==="prototype"&&new Ajax.Request(a.s,b)}
function w(a,b){if(a.B!==false){a=a.C;a=(a!=""?document.getElementById(a):null)||null;str="";total=b.length;for(i=0;i<total;i++)str+="- "+b[i]+"\n"+(a===null?"":"<br />");if(a===null)alert(str);else a.innerHTML=str}}e=j.c.d.prototype;e.R=function(a){if(typeof a!=="boolean")throw"Se espera un boolean de parametro en setDisplayErrors";this.B=a;return this};
e.F=function(a){if(typeof a!=="string")throw"Se espera un string de identificador para el contenedor de errores, se recibio: "+typeof a;this.C=a;return this};e.H=function(a){if(typeof a!=="string")throw"Se espera string como url para script_path";this.s=a;return this};e.U=function(a){if(isNaN(a))throw"Se espera un umero como tiempo de cache de actualizacion de items";this.u=a;return this};
e.T=function(a){if(typeof a!=="string")throw"Se espera string como url para la imagen de progreso de peticiones";this.n=a;return this};e.v=function(){var a=0;for(var b in this.g)this.g.hasOwnProperty(b)&&a++;return a};e.G=function(a){if(typeof a!=="string")throw"Se espera string como modulo a usar";this.r=a;return this};
e.M=function(){var a=Math.abs(((new Date).getTime()/1E3).floor()-this.D)/60,b=this,c=this.r;if(this.g.length===0||a>this.u||this.u===-1)v(this,{parameters:{module:c,action:"AjaxShowCart"},asynchronous:false,onSuccess:function(d){d=t(b,d.responseText);if(d.error.length===0){this.I=d;this.g=d.items;this.D=((new Date).getTime()/1E3).floor()}else w(this,d.error)}.f(this),onException:function(d,f){r(b,f.message)}});k(b.p.get,b,this.I);return this.g};
e.l=function(a,b){b=b||1;v(this,{parameters:{module:this.r,action:"AjaxAddToCart","item_id[]":a,"amount[]":b},onSuccess:function(c){c=t(this,c.responseText);c.error.length>0?w(this,c.error):n(c.items,function(d){this.g[d.id]=d}.f(this));k(this.p.add,this,c)}.f(this),onException:function(c,d){r(this,d.message)}.f(this)})};
e.removeItem=function(a){var b=this;v(this,{parameters:{module:this.r,action:"AjaxDeleteCartItem",item_id:a},onSuccess:function(c){c=t(b,c.responseText);c.error.length===0&&n(c.items,function(d){var f={};for(var g in this.g)if(this.g.hasOwnProperty(g)&&g!=d)f[g]=this.g[g];this.g=f;try{delete this.g[d]}catch(h){}}.f(this));k(b.p.remove,b,c)}.f(this),onException:function(c,d){r(this,d.message)}.f(this)})};
e.w=function(a,b){if(typeof b!=="function")throw"iwt.store.Cart: Error al establecer handler de tipo: "+a+", el segundo parametro debe e ser una funcion";this.p[a].push(b);return this};
j.c.d.L=function(a,b,c){if(typeof window.iwt.store.o==="undefined"){a=a||"";b=b||"Store";a=a+"Cart";if(typeof window.iwt.store[a]==="undefined")throw"Tipo de Interfaz de carrito inexistente";c=c||location.protocol+"//"+location.hostname+"/apps/"+b.toLowerCase()+"/idem.php";window.iwt.store.o=new window.iwt.store[a];window.iwt.store.o.H(c);window.iwt.store.o.G(b)}return window.iwt.store.o};
j.c.i=j.c.d.extend({init:function(a,b){this._super();this.q=a||"cart_container";this.F(b||"cart_error_container");this.m="cart_count";this.w("add",function(c){if(c.error.length===0){this.q!==""&&n(c.items,function(f){var g=f.id,h=document.getElementById("cart_row_"+g)||null,l={prototype:{update:"replace",insert:"insert"},jquery:{update:"replaceWith",insert:"append"}}[this.e][h==null?"insert":"update"];window[this.e==="prototype"?"$":"jQuery"](h==null?(this.e==="jquery"?"#":"")+this.q:h)[l](f.html);
try{var m=function(){this.removeItem(g);return false}.f(this);document.getElementById("delete_row_"+g).onclick=m}catch(o){r(this,o.message)}}.f(this));this.z(c.summary);if(this.m!="")try{document.getElementById(this.m).innerHTML=this.v()}catch(d){r(this,d.message)}}}.f(this));this.w("remove",function(c){if(c.error.length===0){this.q!==""&&n(c.items,function(f){f=document.getElementById("cart_row_"+f);f.parentNode.removeChild(f)}.f(this));this.z(c.summary);if(this.m!="")try{document.getElementById(this.m).innerHTML=
this.v()}catch(d){r(this,d.message)}}}.f(this))}});j.c.i.prototype.z=function(a){for(var b in a){var c=document.getElementById("cart_"+b)||null;if(c!==null)c.innerHTML=isNaN(a[b])?a[b]:p(a[b])}};j.c.i.prototype.N=function(a){this.q=a;return this};j.c.i.prototype.O=function(a){this.m=a;return this};j.c.t=j.c.i.extend({init:function(){this._super();this.j=this.k=""}});
j.c.t.prototype.S=function(a,b){if(typeof a!=="string")throw"Se espera un string como identificador de la zona de drop para el carrito";if(a==="")return this;x(this,b);if(this.k!==""){try{Droppables.remove(this.k)}catch(c){}try{jQuery("#"+this.k).droppable("destroy")}catch(d){}}this.k=a;if(this.e==="prototype")document.observe("dom:loaded",function(){Droppables.add(this.k,{accept:this.j,hoverclass:"hover",onDrop:function(f){$(this.k).highlight();f=f.getAttribute("rel");var g=1;try{g=$$(".cart_item_amount[rel="+
f+"]")[0].value||1}catch(h){r(this,h.message)}this.l(f,g)}.f(this)})}.f(this));else this.e==="jquery"&&jQuery(window).load(function(){var f=this;jQuery("#"+this.k).droppable({accept:"."+this.j,hoverClass:"hover",drop:function(g,h){g=h.draggable.attr("rel");h=1;try{h=jQuery(".cart_item_amount[rel="+g+"]")[0].value||1}catch(l){r(this,l.message)}f.l(g,h)}})}.f(this));return this};
function x(a,b){if(typeof b!=="string")throw"Se espera un string como identificador de clase para los objetos que seran arrastrados";if(b==="")return a;if(a.j!=="")if(a.e==="prototype")$$("."+a.j).each(function(c){try{c.J.W()}catch(d){}});else a.e==="jquery"&&jQuery("."+a.j).draggable("destroy");a.j=b;if(a.e==="prototype")document.observe("dom:loaded",function(){$$("."+this.j).each(function(c){c.J=new Draggable(c,{revert:true,ghosting:true})})}.f(a));else a.e==="jquery"&&jQuery(window).load(function(){jQuery("."+
this.j).draggable({revert:true})}.f(a));return a}window.iwt=j;window.iwt.Class=j.h;window.iwt.Class.extend=j.h.extend;window.iwt.store=j.c;window.iwt.store.Cart=j.c.d;window.iwt.store.Cart.types={PANEL:"Panel",DROP:"Drop"};window.iwt.store.Cart.prototype.setDisplayErrors=j.c.d.prototype.R;window.iwt.store.Cart.prototype.setErrorContainer=j.c.d.prototype.F;window.iwt.store.Cart.prototype.setPath=j.c.d.prototype.H;window.iwt.store.Cart.prototype.setUpdateTime=j.c.d.prototype.U;
window.iwt.store.Cart.prototype.setLoadingImage=j.c.d.prototype.T;window.iwt.store.Cart.prototype.getCount=j.c.d.prototype.v;window.iwt.store.Cart.prototype.getItems=j.c.d.prototype.M;window.iwt.store.Cart.prototype.addItem=j.c.d.prototype.l;window.iwt.store.Cart.prototype.removeItem=j.c.d.prototype.removeItem;window.iwt.store.Cart.prototype.setHandler=j.c.d.prototype.w;window.iwt.store.Cart.prototype.setModule=j.c.d.prototype.G;window.iwt.store.Cart.getInstance=j.c.d.L;
window.iwt.store.PanelCart=j.c.i;window.iwt.store.PanelCart.prototype.updateSummary=j.c.i.prototype.z;window.iwt.store.PanelCart.prototype.setCartContainer=j.c.i.prototype.N;window.iwt.store.PanelCart.prototype.setCountContainer=j.c.i.prototype.O;window.iwt.store.DropCart=j.c.t;window.iwt.store.DropCart.prototype.setDroppable=j.c.t.prototype.S;
} )();

