COMStorage=(function(){var VERSION='0.1.0',B64,P,B,esc,init,empty,ec;ec=(function(){var EPOCH='Thu, 01-Jan-1970 00:00:01 GMT',RATIO=1000*60*60*24,KEYS=['expires','path','domain'],esc=escape,un=unescape,doc=document,me;var get_now=function(){var r=new Date();r.setTime(r.getTime());return r;};var cookify=function(c_key,c_val){var i,key,val,r=[],opt=(arguments.length>2)?arguments[2]:{};r.push(esc(c_key)+'='+esc(c_val));for(i=0;i<KEYS.length;i++){key=KEYS[i];if(val=opt[key])r.push(key+'='+val);}
if(opt.secure)r.push('secure');return r.join('; ');};var alive=function(){var k='__EC_TEST__',v=new Date();v=v.toGMTString();this.set(k,v);this.enabled=(this.remove(k)==v);return this.enabled;};me={set:function(key,val){var opt=(arguments.length>2)?arguments[2]:{},now=get_now(),expire_at,cfg={};if(opt.expires){opt.expires*=RATIO;cfg.expires=new Date(now.getTime()+opt.expires);cfg.expires=cfg.expires.toGMTString();}
var keys=['path','domain','secure'];for(i=0;i<keys.length;i++)
if(opt[keys[i]])cfg[keys[i]]=opt[keys[i]];var r=cookify(key,val,cfg);doc.cookie=r;return val;},has:function(key){key=esc(key);var c=doc.cookie,ofs=c.indexOf(key+'='),len=ofs+key.length+1,sub=c.substring(0,key.length);return((!ofs&&key!=sub)||ofs<0)?false:true;},get:function(key){key=esc(key);var c=doc.cookie,ofs=c.indexOf(key+'='),len=ofs+key.length+1,sub=c.substring(0,key.length),end;if((!ofs&&key!=sub)||ofs<0)return null;end=c.indexOf(';',len);if(end<0)end=c.length;return un(c.substring(len,end));},remove:function(k,d,p){var r=me.get(k),opt={expires:EPOCH};if(d)opt.domain=d;if(p)opt.path=p;doc.cookie=cookify(k,'',opt);return r;},keys:function(){var c=doc.cookie,ps=c.split('; '),i,p,r=[];for(i=0;i<ps.length;i++){p=ps[i].split('=');r.push(un(p[0]));}
return r;},all:function(){var c=doc.cookie,ps=c.split('; '),i,p,r=[];for(i=0;i<ps.length;i++){p=ps[i].split('=');r.push([un(p[0]),un(p[1])]);}
return r;},version:'0.2.1',enabled:false};me.enabled=alive.call(me);return me;}());B64=function(){var keyStr="ABCDEFGHIJKLMNOP"+"QRSTUVWXYZabcdef"+"ghijklmnopqrstuv"+"wxyz0123456789+/"+"=";this.encode=function(input){input=escape(input);var output="";var chr1,chr2,chr3="";var enc1,enc2,enc3,enc4="";var i=0;do{chr1=input.charCodeAt(i++);chr2=input.charCodeAt(i++);chr3=input.charCodeAt(i++);enc1=chr1>>2;enc2=((chr1&3)<<4)|(chr2>>4);enc3=((chr2&15)<<2)|(chr3>>6);enc4=chr3&63;if(isNaN(chr2)){enc3=enc4=64;}else if(isNaN(chr3)){enc4=64;}output=output+keyStr.charAt(enc1)+keyStr.charAt(enc2)+keyStr.charAt(enc3)+keyStr.charAt(enc4);chr1=chr2=chr3="";enc1=enc2=enc3=enc4="";}while(i<input.length);return output;};this.decode=function(input){var output="";var chr1,chr2,chr3="";var enc1,enc2,enc3,enc4="";var i=0;var base64test=/[^A-Za-z0-9\+\/\=]/g;if(base64test.exec(input)){alert("There were invalid base64 characters in the input text.\n"+"Valid base64 characters are A-Z, a-z, 0-9, '+', '/',and '='\n"+"Expect errors in decoding.");}input=input.replace(/[^A-Za-z0-9\+\/\=]/g,"");do{enc1=keyStr.indexOf(input.charAt(i++));enc2=keyStr.indexOf(input.charAt(i++));enc3=keyStr.indexOf(input.charAt(i++));enc4=keyStr.indexOf(input.charAt(i++));chr1=(enc1<<2)|(enc2>>4);chr2=((enc2&15)<<4)|(enc3>>2);chr3=((enc3&3)<<6)|enc4;output=output+String.fromCharCode(chr1);if(enc3!=64){output=output+String.fromCharCode(chr2);}if(enc4!=64){output=output+String.fromCharCode(chr3);}chr1=chr2=chr3="";enc1=enc2=enc3=enc4="";}while(i<input.length);return unescape(output);};};B64=new B64;empty=function(){};esc=function(str){return'PS'+str.replace(/_/g,'__').replace(/ /g,'_s');};C={search_order:['localstorage','whatwg_db','globalstorage','ie','cookie'],name_re:/^[a-z][a-z0-9_ -]+$/i,methods:['init','get','set','remove','load','save'],sql:{version:'1',create:"CREATE TABLE IF NOT EXISTS persist_data (k TEXT UNIQUE NOT NULL PRIMARY KEY, v TEXT NOT NULL)",get:"SELECT v FROM persist_data WHERE k=?",set:"INSERT INTO persist_data(k, v) VALUES (?, ?)",remove:"DELETE FROM persist_data WHERE k=?"},flash:{div_id:'_persist_flash_wrap',id:'_persist_flash',path:'persist.swf',size:{w:1,h:1},args:{autostart:true}}};B={whatwg_db:{size:200*1024,test:function(){var name='PersistJS Test',desc='Persistent database test.';if(!window.openDatabase)return false;if(!window.openDatabase(name,C.sql.version,desc,B.whatwg_db.size))return false;return true;},methods:{transaction:function(fn){if(!this.db_created){var sql=C.sql.create;this.db.transaction(function(t){t.executeSql(sql,[],function(){this.db_created=true;});},empty);}
this.db.transaction(fn);},init:function(){var desc,size;desc=this.o.about||"Persistent storage for "+this.name;size=this.o.size||B.whatwg_db.size;this.db=openDatabase(this.name,C.sql.version,desc,size);},get:function(key,fn,scope){var sql=C.sql.get;if(!fn)return;scope=scope||this;this.transaction(function(t){t.executeSql(sql,[key],function(t,r){if(r.rows.length>0)fn.call(scope,true,r.rows.item(0)['v']);else fn.call(scope,false,null);});});},set:function(key,val,fn,scope){var rm_sql=C.sql.remove,sql=C.sql.set;this.transaction(function(t){t.executeSql(rm_sql,[key],function(){t.executeSql(sql,[key,val],function(t,r){if(fn)fn.call(scope||this,true,val);});});});return val;},remove:function(key,fn,scope){var get_sql=C.sql.get;sql=C.sql.remove;this.transaction(function(t){if(fn){t.executeSql(get_sql,[key],function(t,r){if(r.rows.length>0){var val=r.rows.item(0)['v'];t.executeSql(sql,[key],function(t,r){fn.call(scope||this,true,val);});}else{fn.call(scope||this,false,null);}});}else{t.executeSql(sql,[key]);}});}}},globalstorage:{size:5*1024*1024,test:function(){return(window.globalStorage&&globalStorage[this.o.domain])?true:false;},methods:{key:function(key){return esc(this.name)+esc(key);},init:function(){this.store=globalStorage[this.o.domain];},get:function(key,fn,scope){key=this.key(key);if(fn)fn.call(scope||this,true,this.store.getItem(key));},set:function(key,val,fn,scope){key=this.key(key);this.store.setItem(key,val);if(fn)fn.call(scope||this,true,val);},remove:function(key,fn,scope){var val;key=this.key(key);val=this.store[key];this.store.removeItem(key);if(fn)fn.call(scope||this,(val!==null),val);}}},localstorage:{size:-1,test:function(){return window.localStorage?true:false;},methods:{key:function(key){return esc(this.name)+esc(key);},init:function(){this.store=localStorage;},get:function(key,fn,scope){key=this.key(key);if(fn)fn.call(scope||this,true,this.store.getItem(key));},set:function(key,val,fn,scope){key=this.key(key);this.store.setItem(key,val);if(fn)fn.call(scope||this,true,val);},remove:function(key,fn,scope){var val;key=this.key(key);val=this.getItem(key);this.store.removeItem(key);if(fn)fn.call(scope||this,(val!==null),val);}}},ie:{prefix:'_persist_data-',size:64*1024,test:function(){return window.ActiveXObject?true:false;},make_userdata:function(id){var el=document.createElement('div');el.id=id;el.style.display='none';el.addBehavior('#default#userData');document.body.appendChild(el);return el;},methods:{init:function(){var id=B.ie.prefix+esc(this.name);this.el=B.ie.make_userdata(id);if(this.o.defer)this.load();},get:function(key,fn,scope){var val;key=esc(key);if(!this.o.defer)this.load();val=this.el.getAttribute(key);if(fn)fn.call(scope||this,val?true:false,val);},set:function(key,val,fn,scope){key=esc(key);this.el.setAttribute(key,val);if(!this.o.defer)this.save();if(fn)fn.call(scope||this,true,val);},load:function(){this.el.load(esc(this.name));},save:function(){this.el.save(esc(this.name));}}},cookie:{delim:':',size:4000,test:function(){return P.Cookie.enabled?true:false;},methods:{key:function(key){return this.name+B.cookie.delim+key;},get:function(key,fn,scope){key=this.key(key);val=ec.get(key);if(fn)fn.call(scope||this,val!=null,val);},set:function(key,val,fn,scope){key=this.key(key);ec.set(key,val,this.o);if(fn)fn.call(scope||this,true,val);},remove:function(key,val,fn,scope){var val;key=this.key(key);val=ec.remove(key);if(fn)fn.call(scope||this,val!=null,val);}}},flash:{test:function(){if(!window.SWFObject||!deconcept||!deconcept.SWFObjectUtil)return false;var major=deconcept.SWFObjectUtil.getPlayerVersion().major;return(major>=8)?true:false;},methods:{init:function(){if(!B.flash.el){var o,key,el,cfg=C.flash;el=document.createElement('div');el.id=cfg.div_id;document.body.appendChild(el);o=new SWFObject(this.o.swf_path||cfg.path,cfg.id,cfg.size.w,cfg.size.h,'8');for(key in cfg.args)
o.addVariable(key,cfg.args[key]);o.write(el);B.flash.el=document.getElementById(cfg.id);}
this.el=B.flash.el;},get:function(key,fn,scope){var val;key=esc(key);val=this.el.get(this.name,key);if(fn)fn.call(scope||this,val!==null,val);},set:function(key,val,fn,scope){var old_val;key=esc(key);old_val=this.el.set(this.name,key,val);if(fn)fn.call(scope||this,true,val);},remove:function(key,fn,scope){var val;key=esc(key);val=this.el.remove(this.name,key);if(fn)fn.call(scope||this,true,val);}}}};var init=function(){var i,l,b,key,fns=C.methods,keys=C.search_order;if(!Array.prototype.indexOf)Array.prototype.indexOf=function(c,b){var a;b||(b=0);for(a=b;a<this.length;a++)if(this[a]==c)return a;return-1;};for(i=0,l=fns.length;i<l;i++)
P.Store.prototype[fns[i]]=empty;P.type=null;P.size=-1;for(i=0,l=keys.length;!P.type&&i<l;i++){b=B[keys[i]];try{var test_b=b.test();}catch(e){test_b=false;}
if(test_b){P.type=keys[i];P.size=b.size;for(key in b.methods)
P.Store.prototype[key]=b.methods[key];}}
P._init=true;};P={VERSION:VERSION,type:null,size:0,add:function(o){B[o.id]=o;C.search_order=[o.id].concat(C.search_order);init();},remove:function(id){var ofs=C.search_order.indexOf(id);if(ofs<0)return;C.search_order.splice(ofs,1);delete B[id];init();},Base64:B64,Cookie:ec,Store:function(name,o){if(!C.name_re.exec(name))throw new Error("Invalid name");if(!P.type)throw new Error("No suitable storage found");o=o||{};this.name=name;o.domain=o.domain||location.hostname||'localhost.localdomain';this.o=o;o.expires=o.expires||365*2;o.path=o.path||'/';this.init();}};init();return P;})();


if(!this.JSON){this.JSON={}}(function(){function f(n){return n<10?'0'+n:n}if(typeof Date.prototype.toJSON!=='function'){Date.prototype.toJSON=function(key){return isFinite(this.valueOf())?this.getUTCFullYear()+'-'+f(this.getUTCMonth()+1)+'-'+f(this.getUTCDate())+'T'+f(this.getUTCHours())+':'+f(this.getUTCMinutes())+':'+f(this.getUTCSeconds())+'Z':null};String.prototype.toJSON=Number.prototype.toJSON=Boolean.prototype.toJSON=function(key){return this.valueOf()}}var cx=/[\u0000\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,escapable=/[\\\"\x00-\x1f\x7f-\x9f\u00ad\u0600-\u0604\u070f\u17b4\u17b5\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufeff\ufff0-\uffff]/g,gap,indent,meta={'\b':'\\b','\t':'\\t','\n':'\\n','\f':'\\f','\r':'\\r','"':'\\"','\\':'\\\\'},rep;function quote(string){escapable.lastIndex=0;return escapable.test(string)?'"'+string.replace(escapable,function(a){var c=meta[a];return typeof c==='string'?c:'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})+'"':'"'+string+'"'}function str(key,holder){var i,k,v,length,mind=gap,partial,value=holder[key];if(value&&typeof value==='object'&&typeof value.toJSON==='function'){value=value.toJSON(key)}if(typeof rep==='function'){value=rep.call(holder,key,value)}switch(typeof value){case'string':return quote(value);case'number':return isFinite(value)?String(value):'null';case'boolean':case'null':return String(value);case'object':if(!value){return'null'}gap+=indent;partial=[];if(Object.prototype.toString.apply(value)==='[object Array]'){length=value.length;for(i=0;i<length;i+=1){partial[i]=str(i,value)||'null'}v=partial.length===0?'[]':gap?'[\n'+gap+partial.join(',\n'+gap)+'\n'+mind+']':'['+partial.join(',')+']';gap=mind;return v}if(rep&&typeof rep==='object'){length=rep.length;for(i=0;i<length;i+=1){k=rep[i];if(typeof k==='string'){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}else{for(k in value){if(Object.hasOwnProperty.call(value,k)){v=str(k,value);if(v){partial.push(quote(k)+(gap?': ':':')+v)}}}}v=partial.length===0?'{}':gap?'{\n'+gap+partial.join(',\n'+gap)+'\n'+mind+'}':'{'+partial.join(',')+'}';gap=mind;return v}}if(typeof JSON.stringify!=='function'){JSON.stringify=function(value,replacer,space){var i;gap='';indent='';if(typeof space==='number'){for(i=0;i<space;i+=1){indent+=' '}}else if(typeof space==='string'){indent=space}rep=replacer;if(replacer&&typeof replacer!=='function'&&(typeof replacer!=='object'||typeof replacer.length!=='number')){throw new Error('JSON.stringify');}return str('',{'':value})}}if(typeof JSON.parse!=='function'){JSON.parse=function(text,reviver){var j;function walk(holder,key){var k,v,value=holder[key];if(value&&typeof value==='object'){for(k in value){if(Object.hasOwnProperty.call(value,k)){v=walk(value,k);if(v!==undefined){value[k]=v}else{delete value[k]}}}}return reviver.call(holder,key,value)}text=String(text);cx.lastIndex=0;if(cx.test(text)){text=text.replace(cx,function(a){return'\\u'+('0000'+a.charCodeAt(0).toString(16)).slice(-4)})}if(/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,'@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,']').replace(/(?:^|:|,)(?:\s*\[)+/g,''))){j=eval('('+text+')');return typeof reviver==='function'?walk({'':j},''):j}throw new SyntaxError('JSON.parse');}}}());function COMFicha(pg_info){this.id=pg_info.id;this.p=pg_info.p;this.u=pg_info.u;this.t=pg_info.t;this.n=pg_info.n;this.v=pg_info.v;this.getId=function(){return this.id;};this.getUrl=function(){return this.u;};this.getTitulo=function(){return this.n;};this.getProducto=function(){return this.p;};this.getLastVisited=function(){return this.t;};this.getNumVisitas=function(){return this.v;};this.getLi=function(){var li=document.createElement('li');var a=document.createElement('a');a.href=this.getLiHref();a.title=this.getLiTitle();a.innerHTML=this.getLiText();li.appendChild(a);return li;};this.getLiHref=function(){return this.getUrl();};this.getLiTitle=function(){return this.getTitulo();};this.getLiText=function(){return'<span class="bold">'+this.getTitulo()+'</span>';};}
function RESFicha(pg_info){this.inheritFrom=COMFicha;this.inheritFrom(pg_info);this.getLiText=function(){var maxlength=45;var titulo=this.getTitulo().replace(/ - Atrapalo.com/,"");var partes_titulo=titulo.split(" ");var t="";for(var i in partes_titulo){if(typeof(partes_titulo[i])=="string"&&i>0){t+=partes_titulo[i]+" ";}}
if(t.length>maxlength)
t=t.substring(0,maxlength-3)+'...';return'<span class="bold">'+t+'</span>';}}
function ESPFicha(pg_info){this.inheritFrom=COMFicha;this.inheritFrom(pg_info);}
function COMHistorial(conf){var that=this;var histData={};var histIndex=[];var limit=10;var saveTitle=true;function getUrlFicha(){var canurl,linkNodes=document.getElementsByTagName('link');for(var i=0;i<linkNodes.length;i++){if(linkNodes[i].rel=='canonical'&&linkNodes[i].href!='')canurl=linkNodes[i].href;}
if(canurl!=null)return canurl;else return window.location.href;}
function zeroFill(n,w){w-=n.toString().length;if(w>0)return new Array(w+(/\./.test(n)?2:1)).join('0')+n;return n;}
this.getTitle=function(){var t=document.getElementById('meta_ficha_titulo');if(t){return t.content;}
return document.title;}
this.getHistIndex=function(){return histIndex;}
this.getHistData=function(){return histData;}
this.setLimit=function(l){if(l>0)limit=l;};this.toJSON=function(){return histData;};this.updIndex=function(f,c){if(f==null)f='t';if(typeof c!='function')c=(function(a,b){return(b[1]-a[1]);});var tmpData={};histIndex=[];for(var k in histData){histIndex.push([k,histData[k][f]]);}
histIndex.sort(c);};this.purge=function(l){var lim=l>0?l:limit;that.updIndex();if(histIndex.length>lim)for(var i=lim;i<histIndex.length;i++){delete histData[histIndex[i][0]];delete histIndex[i];}};this.length=function(){return histIndex.length;};this.mark=function(){var meta_ficha=document.getElementById('meta_ficha').content;var hoy=new Date();var s_hoy=''+hoy.getFullYear()+zeroFill(hoy.getMonth()+1,2)+zeroFill(hoy.getDate(),2)+zeroFill(hoy.getHours(),2)+zeroFill(hoy.getMinutes(),2)+zeroFill(hoy.getSeconds(),2);var pg_info={'id':parseInt(meta_ficha.substr(3)),'p':meta_ficha.substr(0,3),'u':getUrlFicha(),'t':parseInt(s_hoy),'n':this.getTitle(),'v':0};var key=pg_info.p+'-'+pg_info.id.toString(16);if(!saveTitle)pg_info.n=null;if(histData[key]!=null)histData[key].t=s_hoy;else histData[key]=pg_info;histData[key].v++;that.purge();};this.clear=function(){histData={};histIndex=[];};this.load=function(data){if(data!=null)histData=data;else return;that.updIndex();};this.find=function(f,val,l){var rs={},c=0,i,k;for(i in histIndex){k=histIndex[i][0];if(typeof(histData[k])=='object'&&histData[k][f]==val){rs[k]=histData[k];c++;};if(l>0&&c>=l)break;};return new COMHistorial({'data':rs,'limit':l});};this.getByProducto=function(v,l){return that.find('p',v,l);};this.getFichasData=function(){var arr=[],v,k;for(k in histIndex){v=histData[histIndex[k][0]];if(typeof(v)=='object')arr.push(v);}
return arr;}
if(conf!=null&&typeof conf=='object'){if(conf.data!=null)this.load(conf.data);this.setLimit(conf.limit);if(conf.title==false)this.saveTitle=false;}}
function RESHistorial(){this.getFichas=function(){try{historial.updIndex();var fichasData=historial.getFichasData();var arr=[];var v;for(var i in fichasData){v=fichasData[i];if(typeof(v)=='object')arr.push(new RESFicha(v));}}catch(e){}
return arr;}
this.getUlFichas=function(limit){var arrFichas=this.getFichas();if(arrFichas.length>0){var ul=document.createElement('ul');ul.className='bullets mid';var f;var j=0;for(i in arrFichas){f=arrFichas[i];if(typeof(f)=='object'){var li=f.getLi();if(j+1==limit){li.setAttribute('class','padbot0');}
ul.appendChild(li);if(++j>=limit)break;}}
return ul;}
return null;}}
function ESPHistorial(){this.getFichas=function(){try{historial.updIndex();var fichasData=historial.getFichasData();var arr=[];var v;for(var i in fichasData){v=fichasData[i];if(typeof(v)=='object')arr.push(new ESPFicha(v));}}catch(e){}
return arr;}
this.getEnlacesFichas=function(limit){var arrFichas=this.getFichas();var espEnlaces=[];if(arrFichas.length>0){arrFichas=arrFichas.slice(0,limit);var f;for(i in arrFichas){f=arrFichas[i];if(typeof(f)=='object'){espEnlaces.push(f.getLi());}}}
return espEnlaces;}}
var store=null;var historial=null;function initHistorial(){if(historial!=null)return;var meta_ficha=document.getElementById('meta_ficha');var meta_historial=document.getElementById('meta_historial');var opt={};try{opt={path:'/'+new String(document.location).split('/')[3]};}catch(e){}
try{if(meta_ficha!=null||meta_historial!=null){var hist_data;if(meta_historial)cod=meta_historial.content.substr(0,3);else if(meta_ficha)cod=meta_ficha.content.substr(0,3);else return;if(cod=='ESP'||cod=='ACT')COMStorage.remove('ie');store=new COMStorage.Store('atr_usu_data',opt);store.get('hst_'+cod,function(ok,val){hist_data=(ok&&val!=null&&typeof val=='string')?val:null;});if(hist_data!=null)try{hist_data=JSON.parse(COMStorage.Base64.decode(hist_data));}catch(e){hist_data=null;}
if(typeof hist_data!='object'){hist_data=null;return;}
historial=new COMHistorial({'data':hist_data,'limit':((COMStorage.type!='cookie')?5:4)});}
if(meta_ficha!=null){historial.mark();var cdata=COMStorage.Base64.encode(JSON.stringify(historial));store.set('hst_'+cod,cdata);}}catch(e){}}
if(typeof $j!='undefined'){$j(document).ready(initHistorial);}
else{YAHOO.util.Event.onDOMReady(initHistorial);}
