﻿var UserInformation = Class.create({

    initialize: function() {
    },

    CheckLogin: function(userName, password) {
        return this.setUserInformation('/User/login/' + userName + '/' + password);
    },

    GetByID: function() {
        return this.setUserInformation('/User/details/');
    },

    SendPassword: function(userName) {
        this.setUserInformation('/User/password/send/' + userName);
    },

    UpdatePassword: function(password) {
        this.setUserInformation('/User/password/update/' + password);
    },

    Register: function(userName, password, fullName, nickName, chid) {
        return this.setUserInformation('/User/create/?email=' + userName + '&password=' + password + '&fullname=' + fullName + "&nickname=" + nickName + "&chid=" + chid);
    },

    UpdateUserDetails: function(userName, fullName, nickName, gender, country, bd_day, bd_month, bd_year, homePage) {
        return this.setUserInformation('/User/update/?email=' + userName + '&fullname=' + fullName + "&nickname=" + nickName + "&gender=" + gender + "&country_id=" + country + "&day=" + bd_day + "&month=" + bd_month + "&year=" + bd_year + "&homepage=" + homePage);
    },

    GetChannels: function() {
        return this.setUserInformation('/User/channels/');
    },

    GetChannelHistory: function(channel) {
        return this.setUserInformation('/User/channelHis/' + channel);
    },

    GetChannelEmail: function(data) {
        return this.setUserInformation('/User/channelemail/?data=' + data);
    },

    SubscribeChanelToUser: function(channel, status) {
        return this.setUserInformation('/User/channel/' + channel + '/' + status);
    },

    GetRelatedVideos: function(domain, channel, page, sort, direction) {
    return this.setUserInformation('/User/videos/' + domain + '/' + channel + '/?page=' + page + '&sort=' + sort + '&direction=' + direction);
    },

    setUserInformation: function(url) {
        var objUserInfo;
        new Ajax.Request(url, {
            method: 'post',
            asynchronous: false,
            onSuccess: function(transport) {
                objUserInfo = transport.responseText.evalJSON();
            },
            onFailure: function(transport) {
                objUserInfo = null;
            }
        });
        return objUserInfo;
    }
});


