
var favoriteAjax=null;
var delAjax = null;
var isLoaded = false;

function initBindProductAjax()
{
    favoriteAjax=new Ajax("../FriendShip/ToFavorite.aspx");
    delAjax = new Ajax("../FriendShip/ToDel.aspx");
    isLoaded = true;
}

function ToFavorite(pid,ptype,islogin)
{
    if(islogin==0)
    {
       alert("请登陆后进行收藏!");
       return false;
    }
    favoriteAjax.OnReading
    (
        function()
        {
            isLoaded = false;
        }
    );
     favoriteAjax.OnSucceed
    (
	    function(result)
	    {
	        isLoaded = true;
		    if(result!=null && result==1 )
            {
                alert("收藏成功!");
　　        }
　　        else if(result==2)
　　        {
　　            alert("您已经收藏过!");
　　        }
            else
            {
            	alert("收藏失败!");
            }
	    }
    );
     favoriteAjax.OnTimeout
    (
	    function()
	    {
		    alert("网络连接超时！");
		    return false;
	    }
    );
    var sendData="pID="+pid+"&pType="+ptype;
    favoriteAjax.invokeServer(sendData,'POST');    
}
function ToDel(objBtn,pid,ptype)
{
    delAjax.OnReading
    (
        function()
        {
            isLoaded = false;
        }
    );
     delAjax.OnSucceed
    (
        
	    function(result)
	    {
	        isLoaded = true;
		    if(result!=null && result==1 )
            {
                var trObj = objBtn.parentNode.parentNode;//get current row
                var tbodyObj = trObj.parentNode;//get tr's parent(tbody)
                var currentIndex = trObj.rowIndex;//get current tr's rowIndex
                var pNameIndex = currentIndex-2;// get productname's tr's rowIndex
                var pPriceIndex = currentIndex-1;// get productprice's tr's rowIndex
                var lineIndex = currentIndex+1;// get line's tr's rowIndex
                var currentTr = tbodyObj.children[currentIndex];
                var pNameTr = tbodyObj.children[pNameIndex];
                var pPriceTr = tbodyObj.children[pPriceIndex];
                var lineTr = tbodyObj.children[lineIndex];
                tbodyObj.removeChild(lineTr);
                tbodyObj.removeChild(currentTr);
                tbodyObj.removeChild(pPriceTr);
                tbodyObj.removeChild(pNameTr);
                return true;
　　        }
            else
            {
            	alert("清空失败!");
            }
	    }
    );
     delAjax.OnTimeout
    (
	    function()
	    {
		    alert("网络连接超时！");
		    return false;
	    }
    );
    var sendData="pID="+pid+"&pType="+ptype;
    delAjax.invokeServer(sendData,'POST');    
}

