﻿function FriendList(){}

function getFriends(objectid,count){
       new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'numbertodisplay=' + count + '&action=getfriends', onSuccess:function(t){
        var obj = document.getElementById(objectid);
        ResetCookies();       
        obj.innerHTML =  t.responseText;  
        }, onFailure:function(t){
        alert(t.responseText);
    }});
}
 

function getBlockList(objectid,count){
       new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'numbertodisplay=' + count + '&action=getblocklist', onSuccess:function(t){
        var obj = document.getElementById(objectid);
        ResetCookies();       
        obj.innerHTML =  t.responseText;         
        }, onFailure:function(t){
        alert(t.responseText);
    }});
}

function getPlayerFriends(objectid,count,playerid,friendid){
       new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'friendid=' + friendid+ '&playerid=' + playerid + '&numbertodisplay=' + count + '&action=getplayerfriends', onSuccess:function(t){
        var obj = document.getElementById(objectid);
        ResetCookies();       
        obj.innerHTML =  t.responseText;         
        }, onFailure:function(t){
        alert(t.responseText);
    }});
}

function getBlockList(objectid,count){
       new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'action=getblocklist', onSuccess:function(t){
        var obj = document.getElementById(objectid);
        ResetCookies();       
        obj.innerHTML =  t.responseText;         
        }, onFailure:function(t){
        alert(t.responseText);
    }});
}


function deleteFriend(objectid, friendid){
    new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'friendid=' + friendid + '&action=deletefriend', 
    onSuccess:function(t){
    var obj = document.getElementById(objectid);
    ResetCookies();  
    
    //add by andrew 2008-5-20 start
    imgDiv_ajax_onSuccess("blockdelete_" + friendid);
    //add by andrew 2008-5-20 end
         
   // obj.innerHTML =  t.responseText;         
    }, 
    
    //add by andrew 2008-5-20 start
    onLoading:function(t)
    {
        imgDiv_ajax_onLoading(("blockdelete_" + friendid), "parblockdelete_" + friendid, "fill");
    },
    //add by andrew 2008-5-20 end
    
    onFailure:function(t){
    
    //add by andrew 2008-5-20 start
    imgDiv_ajax_onFailure("blockdelete_" + friendid);
    //add by andrew 2008-5-20 end
    
    alert(t.responseText);
    }});
}

function approveFriend(objectid, friendid){
    new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'friendid=' + friendid + '&action=approvefriend', onSuccess:function(t){
        var obj = document.getElementById(objectid);
        ResetCookies();      
        
        //add by andrew 2008-5-20 start
        imgDiv_ajax_onSuccess("approve_" + friendid);
        //add by andrew 2008-5-20 end
         
       // obj.innerHTML =  t.responseText;         
        }, 
        
        //add by andrew 2008-5-20 start
        onLoading:function(t)
        {
            imgDiv_ajax_onLoading(("approve_" + friendid), "parappprove_" + friendid, "fill");
        },
        //add by andrew 2008-5-20 end
        
        onFailure:function(t){
        
        //add by andrew 2008-5-20 start
        imgDiv_ajax_onFailure("approve" + friendid);
        //add by andrew 2008-5-20 end
        
        alert(t.responseText);
    }});
}


function addFriend(objectid,friendusername){
    if (!(isAjaxRunning((objectid + "_" + "friendusername"), "PlayerFriendsModule_ajaxParentDiv")))
    {
        new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'friendusername=' + friendusername + '&action=addfriend' + '&random=' + Math.random(), 
            onSuccess:function(t){
            var obj = document.getElementById(objectid);
            ResetCookies();       
            
            
            //add by luke 2008-5-20 start
            imgDiv_ajax_onSuccess(objectid + "_" + "friendusername");
            //add by luke 2008-5-20 end
                
            //obj.innerHTML =  t.responseText;         
            }, 
            
            //add by luke 2008-5-20 start
            onLoading:function(t)
            {
                imgDiv_ajax_onLoading((objectid + "_" + "friendusername"), "PlayerFriendsModule_ajaxParentDiv");
            },
            //add by luke 2008-5-20 end
            
            onFailure:function(t){
            //add by luke 2008-5-20 start
            imgDiv_ajax_onFailure(objectid + "_" + "friendusername");
            //add by luke 2008-5-20 end
            
            alert(t.responseText);
        }});
    }
}

function blockFriend(objectid,friendid){
    new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'friendid=' + friendid + '&action=blockfriend', onSuccess:function(t){
        var obj = document.getElementById(objectid);
        ResetCookies();  
        
        //add by andrew 2008-5-20 start
        imgDiv_ajax_onSuccess("blockdelete_" + friendid);
        //add by andrew 2008-5-20 end
             
        //obj.innerHTML =  t.responseText;         
        }, 
        
        //add by luke 2008-5-20 start
        onLoading:function(t)
        {
            imgDiv_ajax_onLoading(("blockdelete_" + friendid), "parblockdelete_" + friendid, "fill");
        },
        //add by andrew 2008-5-20 end
        
         onFailure:function(t){
        //add by andrew 2008-5-20 start
        imgDiv_ajax_onFailure("blockdelete_" + friendid);
        //add by andrew 2008-5-20 end
        
        alert(t.responseText);
    }});
}

function blockByUserName(objectid,username){
    if (!(isAjaxRunning((objectid + "_" + "username"), "PlayerFriendBlockListModule_ajaxParentDiv")))
    {
        new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'friendusername=' + username + '&action=blockbyusername', 
            onSuccess:function(t){
            var obj = document.getElementById(objectid);
            ResetCookies(); 
            
            //add by luke 2008-5-20 start
            imgDiv_ajax_onSuccess(objectid + "_" + "username");
            //add by luke 2008-5-20 end
            
            //obj.innerHTML =  t.responseText;         
            }, 
            
            //add by luke 2008-5-20 start
            onLoading:function(t)
            {
                imgDiv_ajax_onLoading((objectid + "_" + "username"), "PlayerFriendBlockListModule_ajaxParentDiv");
            },
            //add by luke 2008-5-20 end
            
            onFailure:function(t){
            
            //add by luke 2008-5-20 start
            imgDiv_ajax_onFailure(objectid + "_" + "username");
            //add by luke 2008-5-20 end
            
            alert(t.responseText);
        }});
    }
}

function unblockFriend(objectid,friendid){
    new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'friendid=' + friendid + '&action=unblockfriend', 
        onSuccess:function(t){
        var obj = document.getElementById(objectid);
        ResetCookies(); 
        
        //add by luke 2008-5-20 start
        imgDiv_ajax_onSuccess(objectid + "_" + friendid);
        //add by luke 2008-5-20 end
        
        //obj.innerHTML =  t.responseText;         
        }, 
        
         //add by luke 2008-5-20 start
        onLoading:function(t)
        {
            imgDiv_ajax_onLoading((objectid + "_" + friendid), "parunblock_" + friendid, "fill");
        },
        //add by luke 2008-5-20 end
        
        onFailure:function(t){
        
        //add by luke 2008-5-20 start
        imgDiv_ajax_onFailure(objectid + "_" + friendid);
        //add by luke 2008-5-20 end
        
        alert(t.responseText);
    }});
}


function inviteFriend(objectid, playerid,friendid){
    new Ajax.Request("/ajaxservices/friends/friends.aspx", {method:'get',parameters:'friendid=' + friendid + '&playerid=' + playerid + '&action=invitefriend', onSuccess:function(t){
        var obj = document.getElementById(objectid);
        ResetCookies(); 
        //obj.innerHTML =  t.responseText;                 
        }, onFailure:function(t){
        alert(t.responseText);
    }});
}


FriendList.prototype.getplayerfriends = getPlayerFriends;
FriendList.prototype.approvefriend = approveFriend;
FriendList.prototype.getfriends = getFriends;
FriendList.prototype.deletefriend = deleteFriend;
FriendList.prototype.addfriend = addFriend;
FriendList.prototype.invitefriend = inviteFriend;
FriendList.prototype.blockfriend = blockFriend;
FriendList.prototype.getblocklist = getBlockList;
FriendList.prototype.blockbyusername = blockByUserName;
FriendList.prototype.unblockfriend = unblockFriend;

