﻿Type.registerNamespace("Xanga.Utils");
Xanga.Utils.Date = new function() {
    this.getDisplayDate = function(jsDate) {
        var returnedDate = "";
        var culture;
        
        var dateFormat = $('shortDateFormat').value;
        for( var x = 0; x < 3 ; x++ )
        {
            if( dateFormat.charAt(0) == "d" )
                returnedDate += jsDate.getDate();
            else if( dateFormat.charAt(0) == "M" )
                returnedDate += (jsDate.getMonth()+1)
            else if( dateFormat.charAt(0) == "y" )
                returnedDate += jsDate.getFullYear();
            if( x != 2 )
            {
                returnedDate += dateFormat.charAt(dateFormat.lastIndexOf( dateFormat.charAt(0) ) + 1);
                dateFormat = dateFormat.substring( dateFormat.lastIndexOf( dateFormat.charAt(0) ) + 2 );
            }
        }
        
        
        return returnedDate;
    }
}

Type.registerNamespace("Xanga.Socnet.Webui.Client.Objects");
Xanga.Socnet.Webui.Client.Objects.Connection = function(connFacade) {
    var _connFacade = connFacade;
    var _groups = new Array();

    // Getters
    this.getUserID       = function() { return _connFacade.UserID2; }
    this.getUsername     = function() { return _connFacade.Username; }
    this.getUsernameDisplay = function() { return _connFacade.UsernameDisplay; }
    this.getSiteUrl      = function() { return _connFacade.SiteUrl; }
    this.getConnectDate  = function() { return Xanga.Utils.Date.getDisplayDate(_connFacade.DateAdd); }
    this.getFirstName    = function() { return _connFacade.FirstName; }
    this.getFriendsCount = function() { return _connFacade.FriendsCount; }
    this.getLastUpdate   = function() { return Xanga.Utils.Date.getDisplayDate(_connFacade.LastUpdate); }
    this.getGroups       = function() { return _groups; }
    this.getMask         = function() { return _connFacade.Mask; }
    this.getFacade       = function() { return _connFacade; }
    this.getConnectDateLong = function() { return _connFacade.DateAdd; }
    this.getLastUpdateLong  = function() { return _connFacade.LastUpdate; }
    this.getImageURL = function() {
        if (_connFacade.ImgUrl == null || _connFacade.ImgUrl == "")
            return "http://s.xanga.com/profile/images/nopic.gif";
        return _connFacade.ImgUrl;
    }

    // Determines if a user is a member of the given group
    this.isMemberOf = function(group) {
        return ((group.getMask() & _connFacade.Mask) > 0);
    }

    // Used for groups that a user is a member of
    this.member = function(group) {
        if (Array.contains(_groups,group)) return;

        _groups.push(group);
        group.member(this);
    }

    // Used to add a user to a new group
    this.addToGroup = function(group) {
        _connFacade.Mask = _connFacade.Mask | group.getMask();
        this.member(group);
    }

    // Used to remove a user from a group
    this.removeFromGroup = function(group) {
        // Make sure we haven't already added this group
        for (var i = 0; i < _groups.length; i++) {
            if (_groups[i] == group) {
                _groups.splice(i, 1);
                break;
            }
        }
        
        _connFacade.Mask = _connFacade.Mask & ~group.getMask();
    }
}
Xanga.Socnet.Webui.Client.Objects.Connection.registerClass('Xanga.Socnet.Webui.Client.Objects.Connection', null, Sys.IDisposable);

Xanga.Socnet.Webui.Client.Objects.PublicConnection = function(publicConnFacade) {
    var _connFacade = publicConnFacade;

    // Getters
    this.getUsername    = function() { return _connFacade.Username; }
    this.getUsernameDisplay = function() { return _connFacade.UsernameDisplay; }
    this.getSiteUrl      = function() { return _connFacade.SiteUrl; }
    this.getFirstName   = function() { return _connFacade.FirstName; }
    this.getFriendCount = function() { return _connFacade.FriendCount; }
    this.getLastUpdate  = function() { return Xanga.Utils.Date.getDisplayDate(_connFacade.LastUpdate); }
    this.getImageURL    = function() { return _connFacade.ImgUrl; }
    this.getFacade      = function() { return _connFacade; }
    this.getLastUpdateLong = function() { return _connFacade.LastUpdate; };
    
    this.getMetroName = function() {
        if (_connFacade.MetroID != 0) return _connFacade.MetroName;
        return $("noMetro").value;
    }
}
Xanga.Socnet.Webui.Client.Objects.PublicConnection.registerClass('Xanga.Socnet.Webui.Client.Objects.PublicConnection', null, Sys.IDisposable);

Xanga.Socnet.Webui.Client.Objects.Group = function(group) {
    var _deleted = false;
    var _group = group;
    var _count = 0;
    var _members = new Array();
    
    // Getters
    this.getGroup   = function() { return _group; }
    this.getName    = function() { return _group.GroupName; }
    this.getMask    = function() { return _group.GroupMask; }
    this.getCount   = function() { return _count; }
    this.getMembers = function() { return _members; }
    this.isDeleted  = function() { return _deleted; }
    
    // For users who are already members
    this.member = function(user) {
        if (Array.contains(_members,user)) return;
        _members.push(user);
    }
}
Xanga.Socnet.Webui.Client.Objects.Group.registerClass('Xanga.Socnet.Webui.Client.Objects.Group', null, Sys.IDisposable);

Xanga.Socnet.Webui.Client.Objects.InboundRequest = function(inboundReq) {
    var _inboundReq = inboundReq;

    // Getters
    this.getID          = function() { return _inboundReq.ID; }
    this.getUsername    = function() { return _inboundReq.Username; }
    this.getUsernameDisplay = function() { return _inboundReq.UsernameDisplay; }
    this.getSiteUrl      = function() { return _inboundReq.SiteUrl; }
    this.getFirstName   = function() { return _inboundReq.FirstName; }
    this.getDateCreated = function() { return Xanga.Utils.Date.getDisplayDate(_inboundReq.Created); }
    this.getDateCreatedLong = function() { return _inboundReq.Created; };
    this.getStatus      = function() { return _inboundReq.Status; }
    this.getType        = function() { return _inboundReq.Type; }
    this.getFacade      = function() { return _inboundReq; }
    this.getImageURL = function() {
        if (_inboundReq.ImgUrl == null || _inboundReq.ImgUrl == "")
            return "http://s.xanga.com/profile/images/nopic.gif";
        return _inboundReq.ImgUrl;
    }
}
Xanga.Socnet.Webui.Client.Objects.InboundRequest.registerClass('Xanga.Socnet.Webui.Client.Objects.InboundRequest', null, Sys.IDisposable);

Xanga.Socnet.Webui.Client.Objects.OutboundRequest = function(outboundReq) {
    var _outboundReq = outboundReq;
    
    // Getters
    this.getID          = function() { return _outboundReq.ID; }
    this.getUsername    = function() { return _outboundReq.Username; }
    this.getUsernameDisplay = function() { return _outboundReq.UsernameDisplay; }
    this.getSiteUrl      = function() { return _outboundReq.SiteUrl; }
    this.getFirstName   = function() { return _outboundReq.FirstName; }
    this.getEmail       = function() { return _outboundReq.Email; }
    this.getDateCreated = function() { return Xanga.Utils.Date.getDisplayDate(_outboundReq.Created); }
    this.getDateCreatedLong = function() { return _outboundReq.Created; };
    this.getStatus      = function() { return _outboundReq.Status; }
    this.getType        = function() { return _outboundReq.Type; }
    this.getFacade      = function() { return _outboundReq; }
    this.getImageURL = function() {
        if (_outboundReq.ImgUrl == null || _outboundReq.ImgUrl == "")
            return "http://s.xanga.com/profile/images/nopic.gif";
        return _outboundReq.ImgUrl;
    }
    this.getIdentifier = function() {
        if (_outboundReq.FirstName != null) return _outboundReq.FirstName;
        if (_outboundReq.Username != null) return _outboundReq.Username;
        return _outboundReq.Email;
    }
}
Xanga.Socnet.Webui.Client.Objects.OutboundRequest.registerClass('Xanga.Socnet.Webui.Client.Objects.OutboundRequest', null, Sys.IDisposable);