//得到cookie中的值
function CookieValue(name)
{
var new_arg=name+"=";
var clen=document.cookie.length;
if (document.cookie.indexOf(new_arg)!=-1)
{
vstr=document.cookie.indexOf(new_arg)+new_arg.length;
if (document.cookie.indexOf(";",vstr)==-1)
vend=document.cookie.length;
else
vend=document.cookie.indexOf(";",vstr);
return document.cookie.substring(vstr,vend);
}
return "0";
}
//隐藏漂浮对比篮
function hide(){
obj=document.getElementById("float");
obj.style.display='none';
}
//通过点击button删除产品
function DelCookieValById(id,checkbox)
{
eval("var cBox=document.compForm."+checkbox);
var exp=new Date();
exp.setTime(exp.getTime()-1000);
var vstart = -1;
var vend = -1;
var vlength = 0;
var Cookie=CookieValue("CompNew");
vlength = Cookie.length;
if(id)
{
var new_arg = "&&&";
if((vstart = Cookie.indexOf(id)) != -1)
{
if((vend = Cookie.indexOf(new_arg,vstart)) != -1)
{
vend += new_arg.length;
document.cookie = "CompNew="+Cookie.substring(0,vstart) + Cookie.substring(vend, vlength);
redraw();
document.cookie = "productid_" + id + "=0;expires=" + exp.toGMTString();
}
}
}
if(cBox!=null&&cBox.checked==true){
cBox.checked=false;
}
}
//通过取消复选框删除产品
function DelCookieVal(pid,name,checkbox)
{
var Cookie=CookieValue("CompNew");
var names=pid+"|"+name+"|"+checkbox;
if(names)
{
var new_arg=names+"&&&";
if (Cookie.indexOf(new_arg)!=-1)
{
vstr=Cookie.indexOf(new_arg);
if (Cookie.indexOf(";",vstr)==-1)
vend=Cookie.length;
else
vend=Cookie.indexOf(";",vstr);
document.cookie="CompNew="+Cookie.substring(0,vstr)+Cookie.substring(vstr+new_arg.length,vend);
redraw();
return 1;
}
}
return "0";
}
//显示提示信息
var oldtext="加速变量";
function document.onmousemove(){
try{
if(event.srcElement.getAttribute('caution'))
{
if(showdiv.style.display=='none')
{
showdiv.style.left=event.x+6;
showdiv.style.top=event.y+document.body.scrollTop;
}
if(event.srcElement.caution!=oldtext)
{
oldtext=event.srcElement.caution;
showdiv.innerText=oldtext;
showdiv.style.backgroundColor="#F5FFEB"
};
if(showdiv.style.display=='none') showdiv.style.display=''
}
else
{
if(showdiv.style.display=='') showdiv.style.display='none';
}
}catch(e){}
}
//用指定的字符串div切开str字符串后返回一个数组
function stringToArray(str,div){
objArr=str.split(div);
return objArr;
}
//点击checkbox时触发的事件,向cookie中添加或删除值
function updCompCom(Com,check,obj)
{
//alert(document.cookie);
//alert(Com);
var Cookie=CookieValue("CompNew");
//检查数组的个数(即选择产品的个数)
tmp_arr=stringToArray(document.cookie,"&&&");
namearray=Com.split("|");
var new_arg=Com+"&&&";
//alert(namearray[0]);
if (Cookie.indexOf(new_arg)==-1
&& tmp_arr.length<5
)
//if (document.cookie.indexOf(new_arg)==-1)
{
if(check)
{
if (CookieValue("CompNew")!=0)
document.cookie="CompNew="+CookieValue("CompNew")+new_arg;
else
document.cookie="CompNew="+new_arg;
}
//alert(document.cookie);
}
else
{
if (Cookie.indexOf(new_arg)==-1&&check==true)
{
obj.checked=false;
alert("对不起,您只能选择4个车型进行比较!!!");
}
else if(!check)
return DelCookieVal(namearray[0],namearray[1],namearray[2]);
}
redraw();
return 1;
}
if (document.cookie.indexOf("CompNew")==-1)
{
document.cookie="CompNew=0";
if (document.cookie.indexOf("CompNew")==-1)
alert("车型对比功能要用到您的浏览器的Cookie属性,/n请在您浏览器的internet属性中打开您的");
}
function ocTR(theTR,theMethod){
document.all(theTR).style.display=theMethod;
}
function StartComp()
{
var exp=new Date();
exp.setTime(exp.getTime() + (3600 * 1000));
var temp=CookieValue("CompNew");
//document.cookie = "CompNew=0;expires=" + exp.toGMTString() + ";path=/;domain=;domain=.allfang.com";
var namearray = temp.split("&&&");
for(i = 0; i < namearray.length; i++)
{
temparray = namearray[i].split("|");
if(temparray[0] != '') {
document.cookie="productid_" + temparray[0] + "=0;expires=" + exp.toGMTString();
}
}
return 1;
}
function SubmitComp()
{
StartComp();var ids = "";
var Cookie=CookieValue("CompNew");
//alert("cookie==" + Cookie);
var temp = Cookie.split("&&&");
for(i = 0; i< temp.length; i++){
temparray = temp[i].split("|");
if(temparray[0]!='' && temparray[0] != '0'){
ids += temparray[0] + ",";
}
}
//alert("ids===" + ids);
if(ids==""){
alert("请您选择车型,最多为4个");
return;
}
if(ids.indexOf(",")==ids.length-1){
alert("请您最少选择2种车型");
return;
}
document.compForm.action="Contrast.asp?mid=" + ids;
document.compForm.target="_blank";
document.compForm.submit();
redraw();
//document.location.reload();
return 1;
}
//清空cookie
function empty()
{
var exp=new Date();
exp.setTime(exp.getTime()-1000);
var temp=CookieValue("CompNew");
var namearray = temp.split("&&&");
for(i = 0; i < namearray.length; i++)
{
temparray = namearray[i].split("|");
if(temparray[0] != '') {
document.cookie="productid_"+temparray[0]+"=0;expires="+exp.toGMTString();
}
}
document.cookie="CompNew=0;expires="+exp.toGMTString();
//alert(document.cookie);
document.location.reload();
}
lastScrollY = 0;
function heartBeat()
{
diffY = document.body.scrollTop;
//alert(diffY);
percent =.1*(diffY-lastScrollY);
if(percent>0) percent = Math.ceil(percent);
else percent = Math.floor(percent);
document.all.float.style.pixelTop+= percent;
lastScrollY = lastScrollY+percent;
}
window.setInterval("heartBeat()",1);
//重画漂浮对比篮
function redraw()
{
if(document.getElementById("float")==null){
alert("您的浏览器可能屏蔽了浮动对比框,/n请您关掉浏览器的屏蔽功能,/n然后重新打开此页,进行车型对比");
return ;
}
obj=document.getElementById("float");
obj.style.display='';
var pid,names;
heartBeat();
tmp=CookieValue("CompNew");
//alert(tmp);
item_arr=tmp.split("&&&");
floatstr = "<table height=100% width=100% bgcolor=#FFFFFF border=1 cellpadding=0 cellspacing=0><tr><td>"
+"<table height=100% width=100% bgcolor=#FFFFFF>"+
//"<form action=comp.php method=get name=formComp >"+
"<tr><td align=center><a href='javascript:void(0)' οnclick='empty()'><font color='blue'>清空</font></a> <a href='javascript: ;' οnclick='hide()'><font color='blue'>隐藏</font></a><br>";
for(key in item_arr) {
if (key){
//元素形如:2132|我的产品测试
tmp_info_arr=item_arr[key].split("|");
pid = tmp_info_arr[0];
names= tmp_info_arr[1];
checkbox= tmp_info_arr[2];
if (pid && names){
ft = "<font color=blue size=1>◆</font><br><input type=button name=names value='"+names+"' onClick=DelCookieValById('"+pid+"','"+checkbox+"') caution='删除此车型' style='border:1px solid;border-color:blue ;background-color:white;height:24;width:110;cursor:hand;color:'black';'><br>";
//ft = names+"<br>";
//<input type=button name=name value='"+names+"' οnclick=/"DelCookieVal('"+pid+"','"+names+"')/" style='border:1px solid;border-color:red ;background-color:white;height:24;width:150;cursor:hand;color:'black';'><br>";
floatstr = floatstr+ft;
}
}
}
//floatstr =floatstr + "<input type='hidden' name=CompNewCode value=''>";
floatstr = floatstr + "<input type='hidden' name='CompNewCode' value='"+"'>"
+"<br><input type='button' value='车型对比' name='submits'"+
"οnclick='SubmitComp()' style='cursor:hand;'></td></tr><tr><td height=5></td></tr>";
floatstr = floatstr +"</td></tr></table></td></tr></table>";
//alert(floatstr);
document.all.float.innerHTML = floatstr;
}
redraw();
//