// block user profile
function $BlockUser(URL){
    GameSpace.UI.WebService.UserProfile.CheckBlockUser(URL, $OnBlockUser, $OnTimeOut, $OnError);
    return false;
}

function $OnBlockUser(args){      
    for (var row in args){
        switch(args[row]['Result']){
            case "-1":
                alert("You need to login to block this person.");
                location.href = args[row]['LocationURL'];
                break;
            case "0":
                alert("You can not block yourselves.");
                break;
            case "1":
                alert("This person is an admin.\nYou can not block an administrator.");
                break;
            case "2":
                alert("This person was already blocked.");
                break;
            case "3":
                location.href = args[row]['LocationURL'];
                break;
        }        
    } 
    return false;
}

// add user to my friend list
function $AddFriend(URL){
    if(URL != "")
        GameSpace.UI.WebService.UserProfile.CheckFriend(URL, $OnAddToFriend, $OnTimeOut, $OnError);
    else
        alert("Invalid user!");
    return false;
}

function $OnAddToFriend(args){      
    for (var row in args){
        switch(args[row]['Result']){
            case "-1":
                alert("You need to login to add this person.");
                location.href = args[row]['LocationURL'];
                break;
            case "0":
                alert("You can not add yourselves.");
                break;
            case "1":
                alert("This person was already added.");
                break;
            case "2":
                location.href = args[row]['LocationURL'];
                break;
        }        
    } 
    return false;
}

// add user to my favorite
function $AddFavorite(URL){
    GameSpace.UI.WebService.UserProfile.CheckFavorite(URL, $OnAddToFavorite, $OnTimeOut, $OnError);
    return false;
}

function $OnAddToFavorite(args){    
    for (var row in args){
        switch(args[row]['Result']){
            case "-1":
                alert("You need to login to add this person.");
                location.href = args[row]['LocationURL'];
                break;
            case "0":
                alert("You can not add yourselves.");
                break;
            case "1":
                alert("This person was already added to favorite.");
                break;
            case "2":
                location.href = args[row]['LocationURL'];
                break;
        }        
    } 
    return false;
}

// set profile comment spamer
function $ProfileCommentSpamer(UserId, Spamer, CommentID){
    GameSpace.UI.WebService.UserProfile.ThisIsAProfileCommentSpamer(UserId, Spamer, CommentID, $OnProfileCommentSpamer, $OnTimeOut, $OnError);
    return false;
}

function $OnProfileCommentSpamer(args){    
    return false;
}


// block user profile
function $RearrangeFriendList(TopFriend){
    GameSpace.UI.WebService.UserProfile.RearrangeFriendList(TopFriend, $OnRearrangeFriendList, $OnTimeOut, $OnError);
    return false;
}

function $OnRearrangeFriendList(args){
    return false;
}

function $OnTimeOut(args){    
    alert("Timeout calling service method.");  
    if(typeof(ShowIndicators) == 'function'){
        ShowIndicators(false);
    }
    return false;
}

function $OnError(args){
    alert("Error calling service method.");  
    if(typeof(ShowIndicators) == 'function'){
        ShowIndicators(false);
    }
    return false;
}

function GameProp(){ }
var runMe = new Object();
var ProfileService = {
    init: function(){
        this.tabSet;
        this.tabName;
        this.container;
    },

    onTimeOut: function(args){    
        alert("Timeout calling service method.");  
        return false;
    },
    
    onError: function(args){
        alert("Error calling service method.");  
        return false;
    },
    
    SceneNews: {
        init: function(){
            this.GameProp = new GameProp();
            this.Game = "ALL";
        },
        
        getSceneNews: function(Game, Theme){
            if(!ProfileService.SceneNews.GameProp[Game])
            {      
                this.Game = Game;
                GameSpace.UI.WebService.UserProfile.GetSceneNews(Game, Theme, ProfileService.SceneNews.onGetSceneNews, ProfileService.onTimeOut, ProfileService.onError);
            }
            return false;
        }, 
        
        onGetSceneNews: function(args){ 
            ProfileService.SceneNews.GameProp[ProfileService.SceneNews.Game] = true;
            document.getElementById("td"+ProfileService.SceneNews.Game).innerHTML = args;
            return false;
        }
    },
    
    UserProfile: {
        
        setProfilePhoto: function(ImageFile){
            GameSpace.UI.WebService.UserProfile.SetProfilePhoto(ImageFile, ProfileService.UserProfile.onUserProfile, ProfileService.onTimeOut, ProfileService.onError);
        }, 
        
        onUserProfile: function(args){
            alert("Photo has been successfully set to profile photo.");
	        return false;
        },
        
        VisitorFriend: {
            init: function(){
                this.container1;
                this.container2;
                this.tabContainer;
                this.showAjaxImage = true;
                runMe.visitor = true;
            },
            
            getVisitors: function(tabName, id){
                ProfileService.tabName = tabName;
                this.tabContainer = document.getElementById("td"+tabName);
                if(document.getElementById("tbodyVisitorViewAll") != null){
                    if(this.showAjaxImage){
	                    ToolTipContainer.showAjaxWaiting(this.tabContainer, 'Arrows');
	                    this.showAjaxImage = false;
	                }  
	                GameSpace.UI.WebService.UserProfile.GetLatestVisitor(id, ProfileService.UserProfile.VisitorFriend.onVisitorFriend);    	    
	            }
	            return false;
	        },
    	    
	        getOnlineFriends: function(tabName, id){ 
                ProfileService.tabName = tabName;
                this.tabContainer = document.getElementById("td"+tabName);
                if(document.getElementById("tbodyFriendViewAll") != null){
                    if(this.showAjaxImage){
	                    ToolTipContainer.showAjaxWaiting(this.tabContainer, 'Arrows');
	                    this.showAjaxImage = false;
	                }  
	                GameSpace.UI.WebService.UserProfile.GetProfileOnlineFriend(id, ProfileService.UserProfile.VisitorFriend.onVisitorFriend);    	    
    	        }
    	        return false;
    	    },
        
            onVisitorFriend: function(args){
                ProfileService.UserProfile.VisitorFriend.tabContainer.innerHTML = args["Report"];
                document.getElementById("spanOnlineFriendCount").innerHTML = args["RecordCount"];
                
                if(ProfileService.tabName == "Visitor"){
                    document.getElementById("tbodyVisitorViewAll").style.display = "block";     
                }
                document.getElementById("tbodyFriendViewAll").style.display = args["RecordCount"] == 0 ? "none" : "block";   
                
                return false;
            }
        },
        
        BasicInfo: {
            init: function(){
                this.basicInfoContainer;
                this.userId;
                this.tipPanel;
                this.tipEmptyPanel;
                this.tipPanelStyle = "profilePanel";
                this.summary = new Object();
            },
            
            getProfileSummary: function(userId){
                this.userId = userId;
                if(!this.summary[userId] || (MAXX.Util.Trim(this.summary[userId]) == '')){
                    GameSpace.UI.WebService.UserProfile.GetProfileSummary(userId, this.onCompleteProfileSummary, ProfileService.UserProfile.BasicInfo.onTimeOut, ProfileService.UserProfile.BasicInfo.onError);
                }
                else{
                    this.setContainer();
                }
                return false;
            },

            onTimeOut: function(args){
                ProfileService.UserProfile.BasicInfo.hideTip();
                alert("Timeout calling service method.");  
                return false;
            },
            
            onError: function(args){
                ProfileService.UserProfile.BasicInfo.hideTip();
                alert("Error calling service method.");  
                return false;
            },
            
            onCompleteProfileSummary: function(args){
                ProfileService.UserProfile.BasicInfo.summary[ProfileService.UserProfile.BasicInfo.userId] = args["Profile Summary"];  
                ProfileService.UserProfile.BasicInfo.setContainer();
            },
            
            setContainer: function(){
                this.tipEmptyPanel.innerHTML = this.summary[this.userId];
            },
            
            showProfileTip: function(obj, userId){
                this.tipPanel = document.getElementById(ToolTipContainer.panel);
                this.tipEmptyPanel = document.getElementById(ToolTipContainer.emptyPanel);
                this.tipPanel.className = this.tipPanelStyle;
                ToolTipContainer.showAjaxWaiting(this.tipEmptyPanel, 'Arrows');
                MAXX.Util.MoveToCoordinate(obj, this.tipPanel);
                this.showTip();
                this.getProfileSummary(MAXX.Util.Trim(userId).toUpperCase());
            },
            
            showTip: function(){
                MAXX.Util.ShowHideObject(this.tipPanel, true);
            },
            
            hideTip: function(){
                MAXX.Util.ShowHideObject(this.tipPanel, false);
            }
        }
        
    }    
}
ProfileService.init();
ProfileService.SceneNews.init();
ProfileService.UserProfile.VisitorFriend.init();
ProfileService.UserProfile.BasicInfo.init();
