﻿/////////////////////////////////////////////////////////////////////////////////////
//                                                                                 //
//  Grupo de Soluciones Informáticas                                               //
//  ********************************                                               //
//                                                                                 //
//  Nombre: subscriber.js                                                          //
//  Contiene funciones para el comportamiento de los contactos en la web.          //
//                                                                                 //
//  Nombre del Autor: Abel Pérez Martínez                                          //
//  Fecha de creación: 07/03/2010                                                  //
//                                                                                 //
/////////////////////////////////////////////////////////////////////////////////////

Type.registerNamespace("Subscriber");

Subscriber.Form = function (visibleEmail, visibleMovil, movilId, mailId) {
    this._visibleEmail = visibleEmail;
    this._visibleMovil = visibleMovil;
    this._movilId = movilId;
    this._mailId = mailId;
}

Subscriber.Form.prototype = {

    getVisibleEmail: function () {
        return this._visibleEmail;
    },

    getVisibleMovil: function () {
        return this._visibleMovil;
    },

    getMovilId: function () {
        return this._movilId;
    },

    getMailId: function () {
        return this._mailId;
    },

    //    getEmptyValidate: function (Id) {

    //        var div = document.getElementById(Id + "_textEmptyValidator");

    //        if (this.getVisibleEmail() == true && this.getVisibleMovil() == true) {

    //            var movil = document.getElementById(this.getMovilId()).value;
    //            var mail = document.getElementById(this.getMailId()).value;


    //            if (mail == '' && movil == '') {
    //                div.style.display = '';
    //                return false;
    //            }
    //            else {
    //                div.style.display = 'none';
    //                return true;
    //            }
    //        }
    //        else if (this.getVisibleEmail() == true) {

    //            var mail = document.getElementById(this.getMailId()).value;
    //            if (mail == '') {
    //                div.style.display = '';
    //                return false;
    //            }
    //            else {
    //                div.style.display = 'none';
    //                return true;
    //            }
    //        }
    //        else {
    //            var movil = document.getElementById(this.getMovilId()).value;

    //            if (movil == '') {
    //                div.style.display = '';
    //                return false;
    //            }
    //            else {
    //                div.style.display = 'none';
    //                return true;
    //            }
    //        }
    //    },

    Subscribe: function (idcontrol, TituloResult, WebAppID, WebName, ListNameEMail, ListNameMovil, EnableConfirmation, TextoResultOK, TextoResultError, RedirectURL, ln, PathAndQuery) {

        //        var a = this.getEmptyValidate(idcontrol);
        //        var b = Page_ClientValidate(idcontrol + "_subscribergroup");

        //        if (a && b) {

        var emailValue = "";
        var movilValue = "";

        if (this.getVisibleEmail())
            emailValue = document.getElementById(this.getMailId()).value;

        if (this.getVisibleMovil())
            movilValue = document.getElementById(this.getMovilId()).value;

        //var PathAndQuery = document.location.href;

        GSI.CRM.Contacts.SubscribeServices.Subscribe(TituloResult, PathAndQuery, this.getVisibleEmail(), this.getVisibleMovil(), WebAppID, WebName, ListNameEMail, ListNameMovil, movilValue, emailValue, EnableConfirmation, TextoResultOK, TextoResultError, RedirectURL, ln, SucceededCallback, errorCallback);
        //        }
    },

    ClientValidate: function () {

        var isValid = true;

        if (this.getVisibleEmail() == true && this.getVisibleMovil() == true) {

            var movil = document.getElementById(this.getMovilId()).value;
            var mail = document.getElementById(this.getMailId()).value;

            if (mail == '' && movil == '') {
                isValid = false;
            }
            else
                isValid = true;
        }
        else if (this.getVisibleEmail() == true) {

            var mail = document.getElementById(this.getMailId()).value;
            if (mail == '') {
                isValid = false;
            }
            else
                isValid = true;
        }
        else {
            var movil = document.getElementById(this.getMovilId()).value;
            if (movil == '') {
                isValid = false;
            }
            else
                isValid = true;
        }

        return isValid;
    }
}

function SucceededCallback(result) {
    document.location.href = result;
}

function errorCallback(error) {
    alert(error.get_message());
}

Subscriber.Form.registerClass('Subscriber.Form', null, Sys.IDisposable);

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();

if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();