var RecentlyItems = { items : [], cookieValue : "", readCookie : function(qty) { var cookieValue = ""; var recentItems = []; var ck = document.cookie; if(ck.indexOf("SCRITEMS") != -1) { ck = ck.split("SCRITEMS")[1].substring(1); var items = ck.split("SCRECENTLY"); for(var a = 1; a <= qty && a < items.length; a++) { var atts = items[a].split("/////"); var newItem = { id : unescape(atts[0]), name : unescape(atts[1]), url : unescape(atts[2]), thumbnail : unescape(atts[3]), price : unescape(atts[4]), brief : unescape(atts[5]) }; recentItems.push(newItem); cookieValue += "SCRECENTLY" + atts[0] + "/////" + atts[1] + "/////" + atts[2] + "/////" + atts[3] + "/////" + atts[4] + "/////" + atts[5]; } } else { return; } this.items = recentItems; this.cookieValue = cookieValue; }, save : function(id, name, url, thumbnail, price, brief) { this.readCookie(4); var addToRecent = true; var its = this.items; for( var i = 0; i < its.length; i++ ) { if( id == its[i].id ) { addToRecent = false; } } if( addToRecent ) { this.readCookie(3); document.cookie = "SCRITEMS=;path=/;expires=Thu, 01-Jan-1970 00:00:01 GMT"; var newItem = { id : id, name : name, url : url, thumbnail : thumbnail, price : price, brief : brief }; this.items.unshift(newItem); var expires = new Date(); expires.setTime( expires.getTime() + (60*24*60*60*1000) ); expires = expires.toGMTString(); var c = "SCRITEMS=SCRECENTLY" + escape(id) + "/////" + escape(name) + "/////" + escape(url) + "/////" + escape(thumbnail) + "/////" + escape(price) + "/////" + escape(brief) + this.cookieValue + "SCRITEMS" + ";path=/;expires=" + expires; document.cookie = c; } }, show : function(target, template) { target = document.getElementById(target); this.readCookie(4); var its = this.items; var j = its.length; if(j == 0) { target.style.display = "none"; return; } for(var a = 0; a < j; a++) { var itemHTML = template; itemHTML = itemHTML.replace(//gi, its[a].id); itemHTML = itemHTML.replace(//gi, its[a].name.replace( "/'/", '"' ) ); itemHTML = itemHTML.replace(//gi, its[a].url); itemHTML = itemHTML.replace(//gi, its[a].thumbnail); itemHTML = itemHTML.replace(//gi, its[a].price); itemHTML = itemHTML.replace(//gi, its[a].brief.replace( "/'/", '"' ) ); target.innerHTML += itemHTML; } } }