function
compareObject(compareObject_name)
{
//
init
document.domain
=
"
360buy.com
"
;
this
.initScrollY
=
0
;
this
.proIDs
=
new
Array();
this
.myName
=
compareObject_name;
}
compareObject.prototype
=
{
compare:
function
()
{
if
($(
"
#compare
"
).get(
0
)
==
null
)
{
$(
"
body
"
).append(
"
<div id=\"compare\" class=\"compare\"><div class=\"mt\"><h5>商品比较</h5><div class=\"extra\" onclick=\"
"
+
this
.myName
+
"
.clearCompare()\"></div></div><div class=\"comPro\"><ul class=\"mc\" id=\"comProlist\"></ul><div class=\"mb\"><input type=\"button\" value=\"对比所选商品\" class=\"btn\" id=\"compareImg\" onclick=\"
"
+
this
.myName
+
"
.openCompare()\"></div></div></div>
"
);
$(
"
#compare
"
).css(
{
position:
"
absolute
"
,top:
"
190px
"
,right:
"
0px
"
}
);
this
.isCoo()
}
if
($.browser.msie)
{
var
defaultY
=
document.documentElement.scrollTop;
var
perceH
=
0.3
*
(defaultY
-
this
.initScrollY);
if
(perceH
>
0
)
{
perceH
=
Math.ceil(perceH)
}
else
{
perceH
=
Math.floor(perceH)
}
$(
"
#compare
"
).get(
0
).style.top
=
parseInt($(
"
#compare
"
).get(
0
).style.top)
+
perceH
+
"
px
"
;
this
.initScrollY
=
this
.initScrollY
+
perceH;
setTimeout(
this
.myName
+
"
.compare()
"
,
50
)
}
else
{
window.onscroll
=
function
()
{
$(
"
#compare
"
).get(
0
).style.top
=
parseInt($(
"
#compare
"
).get(
0
).style.top)
+
"
px
"
;
$(
"
#compare
"
).get(
0
).style.position
=
"
fixed
"
}
}
},
clearCompare:
function
()
{
$(
"
#comProlist
"
).empty();
$(
"
#compare
"
).hide();
this
.createCookie(
"
compare
"
,
""
);
this
.proIDs
=
new
Array();
},
callback1:
function
(data){alert(data.name);}
get_ms:
function
(checkid1) {
var
url
=
"
http://www.360buy.com/lishiset.aspx?id=
"
+
checkid1
+
"
&callback=callback1
"
;
$.getJSON(url,
this
.callback1)
},
addToCompare:
function
(checkobj,checkid,checkProName)
{
var
checkProName
=
this
.get_ms(checkid);
$(
"
#compare
"
).show();
$(
"
.comPro
"
).show();
var
proIDsTemp
=
this
.proIDs.join(
"
.
"
);
if
(proIDsTemp.indexOf(checkid)
==-
1
)
{
if
(
this
.proIDs.length
<
3
)
{
var
checkProName
=
"
http://www.360buy.com/lishiset.aspx?id=
"
+
this
.checkid
+
"
&callback=
"
+
jdRecent.get_ms;
this
.proIDs.push(checkid);
$(
"
#comProlist
"
).append(
"
<li id='check_
"
+
checkid
+
"
'><a title='删除' class='close' onclick='
"
+
this
.myName
+
"
.reduceCompare(
"
+
checkid
+
"
)'></a>
"
+
checkProName
+
"
</li>
"
);
this
.writeCompare(checkid,checkProName)
}
else
{
alert(
"
对不起,最多可以选择三种商品进行对比!
"
)
}
}
else
{
alert(
"
对不起,您已经选择此商品!
"
);
return
}
},
reduceCompare:
function
(checkid)
{
$(
"
#check_
"
+
checkid).remove();
$.each(
this
.proIDs,
function
(i,n)
{
if
(checkid
==
n)
{
this
.proIDs.splice(i,
1
)
}
}
);
var
coo
=
this
.readCookie(
"
compare
"
);
var
idindexstart
=
coo.indexOf(checkid);
var
idindexend
=
coo.indexOf(
"
|||
"
,idindexstart)
+
3
;
var
delStr
=
coo.substring(idindexstart,idindexend);
var
innerStr
=
coo.replace(delStr,
""
);
this
.createCookie(
"
compare
"
,innerStr);
if
(
this
.proIDs.length
==
0
)
{
$(
"
.comPro
"
).hide()
}
},
openCompare:
function
()
{
switch
(
this
.proIDs.length)
{
case
1
:alert(
"
对不起,最少选择两种商品进行对比!
"
);
break
;
case
2
:window.open(
"
http://www.360buy.com/pcompare.aspx?s1=
"
+
this
.proIDs[
0
]
+
"
&s2=
"
+
this
.proIDs[
1
]);
break
;
case
3
:window.open(
"
http://www.360buy.com/pcompare.aspx?s1=
"
+
this
.proIDs[
0
]
+
"
&s2=
"
+
this
.proIDs[
1
]
+
"
&s3=
"
+
this
.proIDs[
2
]);
break
;
default
:alert(
"
请选择2-3件商品进行对比!
"
);
return
}
},
writeCompare:
function
(checkid,checkProName)
{
var
compareList
=
this
.readCookie(
"
compare
"
);
if
(compareList
==
null
)
{
compareList
=
""
}
compareList
+=
checkid
+
"
||
"
+
escape(checkProName)
+
"
|||
"
;
this
.createCookie(
"
compare
"
,compareList)
},
isCoo:
function
()
{
var
coo
=
this
.readCookie(
"
compare
"
);
if
(coo)
{
var
cootemp
=
coo.split(
"
|||
"
);
var
compareListTemp
=
""
;
for
(
var
i
=
0
;i
<
cootemp.length
-
1
;i
++
)
{
compareListTemp
+=
"
<li id='check_
"
+
cootemp[i].split(
"
||
"
)[
0
]
+
"
'><a title='删除' class='close' onclick='
"
+
this
.myName
+
"
.reduceCompare(
"
+
cootemp[i].split(
"
||
"
)[
0
]
+
"
)'></a>
"
+
unescape(cootemp[i].split(
"
||
"
)[
1
])
+
"
</li>
"
;
this
.proIDs.push(cootemp[i].split(
"
||
"
)[
0
])
}
$(
"
#comProlist
"
).html(compareListTemp);
$(
"
#compare
"
).show();
$(
"
.comPro
"
).show()
}
},
createCookie:
function
(name,value,days,Tdom)
{
var
Tdom
=
(Tdom)
?
Tdom:
"
/
"
;
if
(days)
{
var
date
=
new
Date();
date.setTime(date.getTime()
+
(days
*
24
*
60
*
60
*
1000
));
var
expires
=
"
; expires=
"
+
date.toGMTString()
}
else
{
var
expires
=
""
}
document.cookie
=
name
+
"
=
"
+
value
+
expires
+
"
; path=
"
+
Tdom
},
readCookie:
function
(name)
{
var
nameEQ
=
name
+
"
=
"
;
var
ca
=
document.cookie.split(
'
;
'
);
for
(
var
i
=
0
;i
<
ca.length;i
++
)
{
var
c
=
ca[i];
while
(c.charAt(
0
)
==
'
'
)
{
c
=
c.substring(
1
,c.length)
}
if
(c.indexOf(nameEQ)
==
0
)
{
return
c.substring(nameEQ.length,c.length)
}
}
return
null
}
}