lastScrollY = 0;
function heartBeat(){
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-lastScrollY);
if(percent>0)percent=Math.ceil(percent);
else percent=Math.floor(percent);
document.getElementById("rightDiv").style.top = parseInt(document.getElementById("rightDiv").style.top)+percent+"px";
lastScrollY=lastScrollY+percent;
}
//下面这段删除后，对联将不跟随屏幕而移动。
window.setInterval("heartBeat()",1);
refreshCompareProductList(); //初始加载显示列表
//-->
//关闭按钮
function close_right1(){
    rightDiv.style.display='none';
}
function open_right1(){
    rightDiv.style.display='block';
}
/*删除已添加*/
function delCompareProduct(productId){
  var itemCompayList = document.getElementById("itemCompayList");
  if(itemCompayList != null){
    var comPareId = document.getElementById("comPareId"+productId);
    if(comPareId != null ){
      itemCompayList.removeChild(comPareId);
    }
  }
   //ajax删除
   refreshCompareProductDel(productId);
}
/*添加到比较*/
function addCompareProductHTML(id,title){
  open_right1(); 
  var itemCompayList = document.getElementById("itemCompayList");
  if(itemCompayList != null){
    var html=itemCompayList.innerHTML;
        html += "<div id='comPareId"+id+"' class='tdItemCompay'><a href=\"javascript:delCompareProduct('"+id+"');\"><img src='"+bascCompareUrl()+"/sys/lib/compare/drop.gif' width='9' height='9' border='0'/></a> <a href='"+bascCompareUrl()+"/product/productDetail/"+id+".html' target='_blank'>"+title+"</a></div>";
    itemCompayList.innerHTML = html;
  }
}

//==================================================添加入列表=================================================== 
	var XMLHttpReqCompareProductAdd;
 	//创建XMLHttpRequest对象       
    function createXMLHttpRequestCompareProductAdd() {
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			XMLHttpReqCompareProductAdd = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) { // IE浏览器
			try {
				XMLHttpReqCompareProductAdd = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReqCompareProductAdd = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
	}
	//发送匹配请求函数
    function addCompareProduct(productId,title) {
          if(productId != "" && title != ""){
            open_right1(); 
            createXMLHttpRequestCompareProductAdd();         
            var url=bascCompareUrl()+"/ajax/compareProduct.do";
                 url+="?type=1&productId="+productId+"&title="+URLEncode(title);
            XMLHttpReqCompareProductAdd.open("GET", url, true);
            XMLHttpReqCompareProductAdd.onreadystatechange = function(){processResponseCompareProductAdd(productId,title)};//指定响应函数
            XMLHttpReqCompareProductAdd.send(null); // 发送请求
           } 
    }
	// 处理返回匹配信息函数
    function processResponseCompareProductAdd(id,title) {
    	if (XMLHttpReqCompareProductAdd.readyState == 4) { // 判断对象状态
        	if (XMLHttpReqCompareProductAdd.status == 200) { // 信息已经成功返回，开始处理信息
        	   var resValue = XMLHttpReqCompareProductAdd.responseXML.getElementsByTagName("value");
        	   var value = "0";
        	   if(resValue != null){
        	      if(resValue[0] != null){
        	      value = resValue[0].firstChild.nodeValue;
        	      }
        	   }
        	   if(value == "1"){
        	     alert("您已经选择了该产品！");
        	   }else if(value == "2"){
        	     alert("您最多只能比较20件产品！");
        	   }else{
        	     addCompareProductHTML(id,title);
        	   }
            } 
        }
    }

//================================================= 从列表中删除 =================================================== 
	var XMLHttpReqCompareProductDel;
 	//创建XMLHttpRequest对象       
    function createXMLHttpRequestCompareProductDel() {
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			XMLHttpReqCompareProductDel = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) { // IE浏览器
			try {
				XMLHttpReqCompareProductDel = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReqCompareProductDel = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
	}
	//发送匹配请求函数
    function refreshCompareProductDel(productId) {
          if(productId != ""){
            createXMLHttpRequestCompareProductDel();         
             var url=bascCompareUrl()+"/ajax/compareProduct.do";
                 url+="?type=2&productId="+productId;
            XMLHttpReqCompareProductDel.open("GET", url, true);
            XMLHttpReqCompareProductDel.onreadystatechange = processResponseCompareProductDel;//指定响应函数
            XMLHttpReqCompareProductDel.send(null); // 发送请求
           } 
    }
	// 处理返回匹配信息函数
    function processResponseCompareProductDel() {
    	if (XMLHttpReqCompareProductDel.readyState == 4) { // 判断对象状态
        	if (XMLHttpReqCompareProductDel.status == 200) { // 信息已经成功返回，开始处理信息
                //alert("删除成功！");
            }else { //页面不正常
                //window.alert("您所请求的页面有异常。");
            }
        }
    }
//==================================================取出比较列表用于回显=================================================== 
	var XMLHttpReqCompareProductList;
 	//创建XMLHttpRequest对象       
    function createXMLHttpRequestCompareProductList() {
		if(window.XMLHttpRequest) { //Mozilla 浏览器
			XMLHttpReqCompareProductList = new XMLHttpRequest();
		}
		else if (window.ActiveXObject) { // IE浏览器
			try {
				XMLHttpReqCompareProductList = new ActiveXObject("Msxml2.XMLHTTP");
			} catch (e) {
				try {
					XMLHttpReqCompareProductList = new ActiveXObject("Microsoft.XMLHTTP");
				} catch (e) {}
			}
		}
	}
	//发送匹配请求函数
    function refreshCompareProductList() {
            createXMLHttpRequestCompareProductList();         
             var url=bascCompareUrl()+"/ajax/compareProduct.do";
                 url+="?type=3";
            XMLHttpReqCompareProductList.open("GET", url, true);
            XMLHttpReqCompareProductList.onreadystatechange = processResponseCompareProductList;//指定响应函数
            XMLHttpReqCompareProductList.send(null); // 发送请求
    }
	// 处理返回匹配信息函数
    function processResponseCompareProductList() {
    	if (XMLHttpReqCompareProductList.readyState == 4) { // 判断对象状态
        	if (XMLHttpReqCompareProductList.status == 200) { // 信息已经成功返回，开始处理信息
                var resProductId = XMLHttpReqCompareProductList.responseXML.getElementsByTagName("productId");
                var resTitle = XMLHttpReqCompareProductList.responseXML.getElementsByTagName("title");
                getCompareProductList(resProductId,resTitle);
            }else { //页面不正常
                //window.alert("您所请求的页面有异常。");
            }
        }
    }

function getCompareProductList(resProductId,resTitle){
  var itemCompayList = document.getElementById("itemCompayList");
  if(itemCompayList != null){
    var html=itemCompayList.innerHTML;
    if(resProductId != null && resProductId.length>0){
     open_right1(); //有信息时，把层显示
    }
    for(var i=0;i<resProductId.length;i++){
	  var id = resProductId[i].firstChild.nodeValue;
	  var title = resTitle[i].firstChild.nodeValue;
	  if(id != "" && title != ""){
	    html += "<div id='comPareId"+id+"' class='tdItemCompay'><a href=\"javascript:delCompareProduct('"+id+"');\"><img src='"+bascCompareUrl()+"/sys/lib/compare/drop.gif' width='9' height='9' border='0'/></a> <a href='"+bascCompareUrl()+"/product/productDetail/"+id+".html' target='_blank'>"+title+"</a></div>";
	  }
    }
	itemCompayList.innerHTML = html;    
  }   
	    
}



//==================================================通用转码方法=================================================== 
//ajax中文转码方法
 function URLEncode(Str){
  if(Str==null||Str=="")
    return "";
   var newStr="";
  function toCase(sStr){
    return sStr.toString(16).toUpperCase();
  }
  for(var i=0,icode,len=Str.length;i<len;i++){
    icode=Str.charCodeAt(i);
    if( icode<0x10)
      newStr+="%0"+icode.toString(16).toUpperCase();
    else if(icode<0x80){
      if(icode==0x20)
        newStr+="+";
      else if((icode>=0x30&&icode<=0x39)||(icode>=0x41&&icode<=0x5A)||(icode>=0x61&&icode<=0x7A))
        newStr+=Str.charAt(i);
      else
        newStr+="%"+toCase(icode);
      }
    else if(icode<0x800){
      newStr+="%"+toCase(0xC0+(icode>>6));
      newStr+="%"+toCase(0x80+icode%0x40);
      }
    else{
      newStr+="%"+toCase(0xE0+(icode>>12));
      newStr+="%"+toCase(0x80+(icode>>6)%0x40);
      newStr+="%"+toCase(0x80+icode%0x40);
      }
    }
   return newStr;
 }

 