﻿// JScript 文件

var ajax=new AJAXRequest;
//添加
function AddCompare(c,id,name)
{
    if(c==true)
    {
        ajax.get
        (
          "/Ajax/Compare.aspx?type=add&id="+id+"&name="+encodeURI(name),
          function(obj)
            {
                if(obj.responseText=="0")
                    alert("最多只能选择5件商品做对比");
                 GetCompare();
	        }
        );
    }
    else
    {
        ajax.get
        (
          "/Ajax/Compare.aspx?type=del&id="+id+"&name="+encodeURI(name),
          function(obj)
            {
                 GetCompare();
	        }
        );
    }
}
//读取
window.onload = function GetCompare()
{
    ajax.get
    (
        "/Ajax/Compare.aspx",
        function(obj)
        {
            var _text = obj.responseText.split('$');
            if(_text[0]>"0")
            {
                ShowCompare();
                if(_text[0]=="6")
                    alert("最多只能选择5件商品做对比");
                document.getElementById("compareproduct").innerHTML = _text[1];
            }
            else
                document.getElementById("compareproduct").innerHTML = "";
        }
    );
}
//删除
function DelCompare(id,name)
{
    ajax.get
    (
      "/Ajax/Compare.aspx?type=del&id="+id+"&name="+encodeURI(name),
      function(obj)
        {
             document.URL=location.href;
	    }
    );
}
function DeleteCompare(id,name)
{
    ajax.get
    (
      "/Ajax/Compare.aspx?type=del&id="+id+"&name="+encodeURI(name),
      function(obj)
        {
            GetCompare();
	    }
    );
}
//清空
function CancelCompare()
{
    ajax.get
    (
        "/Ajax/Compare.aspx?type=cancel",
        function(obj)
        {
            document.getElementById("compareproduct").innerHTML = "";
        }
    );
}
//显示
function ShowCompare()
{
    document.getElementById("compareli").style.display = "";
}
//隐藏
function NoneCompare()
{
    document.getElementById("compareli").style.display = "none";
}

var lastScrollY1=0;
function heartBeat1(){ 
var diffY;
if (document.documentElement && document.documentElement.scrollTop)
	diffY = document.documentElement.scrollTop;
else if (document.body)
	diffY = document.body.scrollTop
else
    {/*Netscape stuff*/}
	
//alert(diffY);
percent=.1*(diffY-lastScrollY1); 
if(percent>0)percent=Math.ceil(percent); 
else percent=Math.floor(percent); 
document.getElementById("compare_li").style.top=parseInt(document.getElementById

("compare_li").style.top)+percent+"px";
document.getElementById("compareli").style.top=parseInt(document.getElementById

("compare_li").style.top)+percent+"px";

lastScrollY1=lastScrollY1+percent; 
//alert(lastScrollY1);
}
suspendcode0="<DIV id=\"compare_li\" style='left:2px;POSITION:absolute;TOP:180px; width;0; height:50px;'></div>"
suspendcode1="<DIV id=\"compareli\" class='compare_li' style='display:none;'><ul><li class='title'><img src='/images/Compare_close.jpg' onclick='NoneCompare();' title='关闭对比' /></li></ul><ul id='compareproduct'></ul><ul><li><a href='/product/ProductCompare.aspx' target='_blank'><img src='/images/Compare_but1.jpg' /></a> <img src='/images/Compare_but2.jpg' onclick='CancelCompare();' /></li></ul></div>"
document.write(suspendcode0); 
document.write(suspendcode1); 
window.setInterval("heartBeat1()",1);

