﻿jQuery.cookie=function(name,value,options){if(typeof value!="undefined"){options=options||{};if(value===null){value="";options.expires=-1;}var expires="";if(options.expires&&(typeof options.expires=="number"||options.expires.toUTCString)){var date;if(typeof options.expires=="number"){date=new Date();date.setTime(date.getTime()+(options.expires*24*60*60*1000));}else{date=options.expires;}expires="; expires="+date.toUTCString();}var path=options.path?"; path="+(options.path):"";var domain=options.domain?"; domain="+(options.domain):"";var secure=options.secure?"; secure":"";document.cookie=[name,"=",encodeURIComponent(value),expires,path,domain,secure].join("");}else{var cookieValue=null;if(document.cookie&&document.cookie!=""){var cookies=document.cookie.split(";");for(var i=0;i<cookies.length;i++){var cookie=jQuery.trim(cookies[i]);if(cookie.substring(0,name.length+1)==(name+"=")){cookieValue=decodeURIComponent(cookie.substring(name.length+1));break;}}}return cookieValue;}};

if(!this.COOKIEDB2){serialize_rec=function(o_map){if(0==o_map.length){return"";}var o_string=o_map.join(",");return"["+o_string+"]";};unserialize_rec=function(o_string){var arr_ret=[];if(o_string.length==0){return arr_ret;}o_string=o_string.substring(1,o_string.length-1);if(o_string.indexOf(",")==0){o_string=o_string.substring(1);}arr_ret=o_string.split(",");return arr_ret;};

COOKIEDB2=function(){var o_data_map=[];var cookie_db_max=0;var return_tmp={set_max_items:function(vmax){cookie_db_max=vmax;},
add:function(data1,f_overwrite){bFound=false;i_found=-1;for(var i=0;i<o_data_map.length;i++){if(o_data_map[i]==data1){bFound=true;i_found=i;break;}}if(bFound){if(i_found==o_data_map.length-1){return 3;}for(var i=i_found;i<o_data_map.length-1;i++){o_data_map[i]=o_data_map[i+1];}o_data_map[o_data_map.length-1]=data1;return 3;}if(o_data_map.length<cookie_db_max){o_data_map[o_data_map.length]=data1;return 1;}if(!f_overwrite){return 9;}o_data_map.shift();o_data_map.push(data1);return 2;},
remove:function(vk1){bFound=false;for(var i=0;i<o_data_map.length;i++){if(bFound){o_data_map[i]=o_data_map[i+1];}else{bFound=(o_data_map[i]==vk1);if(bFound){o_data_map[i]=o_data_map[i+1];}}}if(bFound){o_data_map.length=o_data_map.length-1;}return false;},remove_all:function(){o_data_map=[];return true;},get_val:function(){return o_data_map;},
save:function(table,ttl,path,domain){var s_token=table;var s_all=serialize_rec(o_data_map);var opt={expires:ttl*1000,path:path,domain:domain};jQuery.cookie(s_token,s_all,opt);},
read:function(table){var s_token=table;
var s_all=jQuery.cookie(s_token);if(!s_all||0==s_all.length){o_data_map=[];return;}o_data_map=unserialize_rec(s_all);},
get_length:function(){return o_data_map.length;}};return return_tmp;};}js_loader_datas={"js_list":[]};function js_loader(js_url){var iLoadAction=arguments.length>1?arguments[1]:2;var u=js_url;if(1==iLoadAction){var o_list=js_loader_datas["js_list"];for(var i=0;i<o_list.length;i++){if(js_url==o_list[i]){return 0;}}o_list[i]=js_url;}else{if(2==iLoadAction){nowtime=Math.random();u+="&_nocache="+nowtime;}}

var oHead=document.getElementsByTagName("HEAD").item(0);var oScript=document.createElement("script");oScript.type="text/javascript";oScript.encoding="utf-8";oScript.src=u;oHead.appendChild(oScript);return 1;}function setval_g(form1,item1,value1){document.forms[form1].elements[item1].value=value1;}function setval_check(form1,item1,value1){document.forms[form1].elements[item1].checked=value1;}

var n_max_items_compare=4;

function add_draw_cmp(id1,name1,url1){
var s_show='<li id="cmp_'+id1+'"><span class="dbDivUlSc"><a href="javascript:remove_cmp('+id1+')" class="opt-link">删除</a></span><div class="dbDivUlText"><a href="'+url1+'">'+name1+"</a></div></li>";document.getElementById("cmp_items_show").innerHTML+=s_show;
}

var o_db2=new COOKIEDB2();
o_db2.read("product_compare");
o_db2.set_max_items(n_max_items_compare);

function add_cmp(id1,name1,url1){
block("duibiDiv");
s_tip="";switch(o_db2.add(id1)){case 9:alert("对不起，对比栏只能容纳 "+n_max_items_compare+" 个产品供对比");return;case 3:alert("您选择的产品已在对比栏中 ");return;}o_db2.save("product_compare",4*60*60);add_draw_cmp(id1,name1,url1);return;var s_show='<li id="cmp_'+id1+'"><span class="dbDivUlSc"><a href="javascript:remove_cmp('+id1+')" class="opt-link">删除</a></span><div class="dbDivUlText"><a href="'+url1+'">'+name1+"</a></div></li>";jQuery("#cmp_items_show")[0].innerHTML+=s_show;}

function remove_cmp(id1){o="#cmp_"+id1;jQuery(o).remove();o_db2.remove(id1);o_db2.save("product_compare",24*60*60);}

function do_compare(){var i_items=o_db2.get_length();if(i_items<2){alert("请至少选择两款产品进行对比!");}else{arr_id=o_db2.get_val();arr_s=[];for(var i=0;i<arr_id.length;i++){arr_s[arr_s.length]="id="+arr_id[i];}var u="compare.aspx?"+arr_s.join("&");open(u);}}

function clear_history(){if(confirm("确实要清空对比记录么？")){var opt={expires:1*1000,path:"/",domain:document.domain};jQuery.cookie("product_compare","",opt);jQuery("#cmp_items_show")[0].innerHTML="";}document.cookie= "product_compare=; expires=Fri, 31 Dec 1999 23:59:59 GMT;";}
