﻿lastScrollYs=0;
function heartBeat(name)
{ 
    var diffY;

    document.getElementById(name).style.left=""+(document.body.clientWidth-document.getElementById(name).clientWidth-10)+"px";

    if (document.documentElement && document.documentElement.scrollTop)
    {
        diffY = document.documentElement.scrollTop;
    }
    else if (document.body)
    {
        diffY = document.body.scrollTop
    }
    
    percent=.1*(diffY-lastScrollYs); 
    
    if(percent>0)
    {
        percent=Math.ceil(percent); 
    }
    else
    {
        percent=Math.floor(percent); 
    }

    document.getElementById(name).style.top=parseInt(document.getElementById(name).style.top)+percent+"px";
    
    lastScrollYs=lastScrollYs+percent;
}

function hidead(name,strDisplay)
{
    document.getElementById(name).style.display = strDisplay;
}



var objCheckbox;

function SelectCompareGood(obj,nCatID,nGoodsID)
{
    var strOpetation = "";
    objCheckbox=obj;
    if(obj!=null)
    {
        if(obj.checked)
        {
            strOpetation = "add";
        }else
        {
           strOpetation = "del";
        }
    }
    else
    {
        strOpetation = "del";
        if(document.getElementById("checkbox"+nGoodsID)!=null)
        {
            document.getElementById("checkbox"+nGoodsID).checked=false;
        }
    }
    
    var url  = topUrl+"/AjaxCommon.aspx";
    var pars = "RequestType=SelectCompareGood&CatID="+nCatID+"&GoodsID="+nGoodsID+"&O="+strOpetation;
 
 
    var wRequest =  new Sys.Net.WebRequest();  
    wRequest.set_url(url); 
    wRequest.set_httpVerb("post");
    wRequest.set_body(pars);
    wRequest.add_completed(GetDIVCompareGoodItem);
    wRequest.invoke();
}

function SelectCompareGoodsList(nCatID)
{
    var url  = topUrl+"/AjaxCommon.aspx";					
    var pars = "RequestType=SelectGoodsCompareList&CatID="+nCatID;
    
    var wRequest =  new Sys.Net.WebRequest();  
    wRequest.set_url(url); 
    wRequest.set_httpVerb("post");
    wRequest.set_body(pars);
    wRequest.add_completed(GetDIVCompareGoodItem);
    wRequest.invoke();
    hidead("MainDiv","block");
}

function GetDIVCompareGoodItem(executor, eventArgs)
{
    if(executor.get_responseAvailable()) 
    {
	    var nRoot = executor.get_xml().documentElement;
	    if(nRoot.childNodes.length>0 && nRoot.childNodes[0].firstChild.nodeValue == "overstep")
        {
            alert("对不起，最多只能比较6个商品");
            if(objCheckbox!=null)
            {
                objCheckbox.checked=false;
            }
            return;
        }
        document.getElementById("divCompareGood").innerHTML="";
	    if(nRoot.childNodes.length>0)
	    {
            for(var i = 0 ; i < nRoot.childNodes.length ; i ++ )
            {
                //创建DIV
                var objDIV =document.createElement("div");
                //创建Table
                var objTABLE=document.createElement("table");
                //创建TR
                var objTR = document.createElement("tr");          		
	            //创建TD1
	            var objTD_Title1= document.createElement("td");
	            //创建TD2
	            var objTD_Title2= document.createElement("td");
	            //创建IMG
	            var objIMG= document.createElement("img");
	            

	            if (document.all)
	            {
	                //IE
	                
	                //DIV加样式
	                objDIV.setAttribute( "class ", "db-c-d01");
	                //Table加样式
	                objTABLE.setAttribute( "class ", "db-c-txt");
                    objTABLE.setAttribute( "width ", "100%");
                    objTABLE.setAttribute( "border ", "0");
                    objTABLE.setAttribute( "cellspacing ", "0");
                    objTABLE.setAttribute( "cellpadding ", "0");
                    //TD1加样式
                    objTD_Title1.setAttribute( "width ", "91%"); 
	                objTD_Title1.setAttribute( "valign ", "top"); 
    	            //TD2加样式
	                objTD_Title2.setAttribute( "width ", "9%"); 
	                objTD_Title2.setAttribute( "align ", "center");
	                objTD_Title2.setAttribute( "valign ", "top"); 
	                //IMG加样式
	                objIMG.setAttribute( "src ", topUrl+"/images/del01.gif"); 
	                objIMG.setAttribute( "width ", "8");
	                objIMG.setAttribute( "height ", "7"); 
	            }
	            else
	            {
	                //firefox
	                
	                //DIV加样式
	                objDIV.className="db-c-d01";
	                //Table加样式
	                objTABLE.className="db-c-txt";
                    objTABLE.width="100%";
                    objTABLE.border="0";
                    objTABLE.cellspacing="0";
                    objTABLE.cellpadding="0";
                    //TD1加样式
                    objTD_Title1.width="91%";
	                objTD_Title1.valign="top";
    	            //TD2加样式
	                objTD_Title2.width="9%";
	                objTD_Title2.align="center";
	                objTD_Title2.valign="top";
	                //IMG加样式
	                objIMG.src=topUrl+"/images/del01.gif";
	                objIMG.width="8";
	                objIMG.height="7";
	            }
    		    
	            if(nRoot.childNodes[i].firstChild.nodeValue!=null)
	            {
	                var nRootArr = nRoot.childNodes[i].firstChild.nodeValue.split("/,/");
                    objTD_Title1.innerHTML = nRootArr[2];
                    objTD_Title2.innerHTML = "<img src=\""+topUrl+"/images/del01.gif\" width=\"8\" height=\"7\" onclick=\"SelectCompareGood(null,"+nRootArr[0]+","+nRootArr[1]+")\" style=\"cursor:pointer\" />";
                    objTR.appendChild(objTD_Title1);
                    objTR.appendChild(objTD_Title2);
                    objTABLE.appendChild(objTR);
                    objDIV.appendChild(objTABLE)
                    document.getElementById("divCompareGood").appendChild(objDIV);
                    if (document.all)
                    {
                        //IE
                        document.getElementById("divCompareGood").innerHTML=document.getElementById("divCompareGood").innerHTML;
                    }
                }
             }
             hidead("MainDiv","block");
         }
    }
    else
    {
        if (executor.get_timedOut())
            alert("Timed Out");
        else
            if (executor.get_aborted())
                alert("Aborted");
    }
}


function InitCompareGoodsList(nCatID)
{
    var url  = topUrl+"/AjaxCommon.aspx";					
    var pars = "RequestType=InitGoodsCompareList&CatID="+nCatID;
    
    var wRequest =  new Sys.Net.WebRequest();
    wRequest.set_url(url); 
    wRequest.set_httpVerb("post");
    wRequest.set_body(pars);
    wRequest.add_completed(GetDIVCompareGoodItem);
    wRequest.invoke();
}