/* $id: compare.js 15469 2008-12-19 06:34:44z testyang $ */ var compare = new object(); compare = { add : function(goodsid, goodsname, type) { var count = 0; for (var k in this.data) { if (typeof(this.data[k]) == "function") continue; if (this.data[k].t != type) { alert(goods_type_different.replace("%s", goodsname)); return; } count++; } if (this.data[goodsid]) { alert(exist.replace("%s",goodsname)); return; } else { this.data[goodsid] = {n:goodsname,t:type}; } this.save(); this.init(); }, relocation : function() { if (this.comparebox.style.display != "") return; var diffy = math.max(document.documentelement.scrolltop,document.body.scrolltop); var percent = .2*(diffy - this.lastscrolly); if(percent > 0) percent = math.ceil(percent); else percent = math.floor(percent); this.comparebox.style.top = parseint(this.comparebox.style.top)+ percent + "px"; this.lastscrolly = this.lastscrolly + percent; }, init : function(){ this.data = new object(); var cookievalue = document.getcookie("compareitems"); if (cookievalue != null) { this.data = $.evaljson(cookievalue); } if (!this.comparebox) { this.comparebox = document.createelement("div"); var submitbtn = document.createelement("input"); this.comparelist = document.createelement("ul"); this.comparebox.id = "comparebox"; this.comparebox.style.display = "none"; this.comparebox.style.top = "200px"; this.comparebox.align = "center"; this.comparelist.id = "comparelist"; submitbtn.type = "button"; submitbtn.value = "开始对比"; this.comparebox.appendchild(this.comparelist); this.comparebox.appendchild(submitbtn); submitbtn.onclick = function() { var cookievalue = document.getcookie("compareitems"); var obj = $.evaljson(cookievalue); var url = document.location.href; url = url.substring(0,url.lastindexof('/')+1) + "compare.php"; var i = 0; for(var k in obj) { if(typeof(obj[k])=="function") continue; if(i==0) url += "?goods[]=" + k; else url += "&goods[]=" + k; i++; } if(i<2) { alert(compare_no_goods); return ; } document.location.href = url; } document.body.appendchild(this.comparebox); } this.comparelist.innerhtml = ""; var self = this; for (var key in this.data) { if(typeof(this.data[key]) == "function") continue; var li = document.createelement("li"); var span = document.createelement("span"); span.style.overflow = "hidden"; span.style.width = "100px"; span.style.height = "20px"; span.style.display = "block"; span.innerhtml = this.data[key].n; li.appendchild(span); li.style.liststyle = "none"; var delbtn = document.createelement("img"); delbtn.src = "themes/xiaomi/images/drop.gif"; delbtn.classname = key; delbtn.onclick = function(){ document.getelementbyid("comparelist").removechild(this.parentnode); delete self.data[this.classname]; self.save(); self.init(); } li.insertbefore(delbtn,li.childnodes[0]); this.comparelist.appendchild(li); } if (this.comparelist.childnodes.length > 0) { this.comparebox.style.display = ""; this.timer = window.setinterval(this.relocation.bind(this), 50); } else { this.comparebox.style.display = "none"; window.clearinterval(this.timer); this.timer = 0; } }, save : function() { var date = new date(); date.settime(date.gettime() + 99999999); document.setcookie("compareitems", $.tojson(this.data)); }, lastscrolly : 0 }