﻿/// <reference name="MicrosoftAjax.js"/>

var objDS1;

var xshowdebug="n";
function sdebug(value) {
  if ( xshowdebug == "y" )
     alert(value);
}

// --------------------

Sys.Application.add_init(initApplicationX);
Sys.Application.add_load(loadApplicationX);

function initApplicationX() {
    MakeDS1();
}

function loadApplicationX() {
    //objDS1.set_WebService(Service1);
}

function MakeDS1() {
    objDS1 = $create(Stema.DataService1, { DgbuttonC: 'ds1buttonC' },
                 null, null, $get('dataservice1')
    );
    objDS1.set_WebService(Service1);
}
function showModalPopupDS1(value) {
    var modalPopupBehavior = $find('objModalPopupBehavior1');
    modalPopupBehavior.show();
    objDS1.set_Isbn(value);
}
function hideModalPopupDS1() {
    var modalPopupBehavior = $find('objModalPopupBehavior1');
    modalPopupBehavior.hide();
    //objDS1.set_Isbn("xxx");
}

// --------------------

Type.registerNamespace("Stema");

// --------------------

Stema.DataService1 = function(element) {
    Stema.DataService1.initializeBase(this,[element]);
    this._WebService = null;
    this._ClickDelegateC = null;
    this._DgbuttonC = null;
    this._Isbn = null;
}
Stema.DataService1.prototype = {
    initialize: function() {
        sdebug('initialize:1a');
        Stema.DataService1.callBaseMethod(this, 'initialize');
        var element = this.get_element();
        if (this._DgbuttonC != null) {
            this._DgbuttonC = $get(this._DgbuttonC);
        }
        if (this._DgbuttonC != null && this._ClickDelegateC == null) {
            this._ClickDelegateC = Function.createDelegate(this, this._ClickHandlerC);
            Sys.UI.DomEvent.addHandler(this._DgbuttonC, 'click', this._ClickDelegateC);
        }
        this.add_ClickC(this.EventClickC);
        sdebug('initialize:1b');
    },

    get_WebService: function() {
        return this._WebService;
    },
    set_WebService: function(value) {
        sdebug("set_WebService:" + value);
        this._WebService = value;
    },

    get_DgbuttonC: function() {
        return this._DgbuttonC;
    },
    set_DgbuttonC: function(value) {
        sdebug("set_DgbuttonC:" + value);
        this._DgbuttonC = value;
    },

    get_Isbn: function() {
        return this._Isbn;
    },
    set_Isbn: function(value) {
        sdebug("set_Isbn:" + value);
        this._Isbn = value;
    },

    add_ClickC: function(handler) {
        sdebug("add_clickc");
        this.get_events().addHandler('clickc', handler);
    },
    remove_ClickC: function(handler) {
        this.get_events().removeHandler('clickc', handler);
    },
    _ClickHandlerC: function(event) {
        var h = this.get_events().getHandler('clickc');
        if (h) h(this, Sys.EventArgs.Empty);
    },

    EventClickC: function(sender, args) {
        var param = null;
        var srv = sender.get_WebService();
        param = $get("ds1text01");
        var userid = param.value;
        param = $get("ds1text02");
        var passid = param.value;
        var isbn = sender.get_Isbn();
        srv.NotifyDisponibile(userid, passid, isbn, sender.OnCallOk1,
                       sender.OnCallNo1, this);
    },

    OnCallOk1: function(result, userContext, methodName) {
        //alert("** OK **");
        $get("ds1message").innerHTML = result;
    },

    OnCallNo1: function(result, userContext, methodName) {
        alert("** error **");
    },

    SetStyle: function(value) {
        var element = this.get_element();
        element.className = value;
    },

    Clear: function() {

    },

    dispose: function() {
        sdebug('dispose:1');
        var element = this.get_element();
        if (this._DgbuttonC != null && this._ClickDelegateC != null) {
            Sys.UI.DomEvent.removeHandler(this._DgbuttonC, 'click', this._ClickDelegateC);
            delete this._ClickDelegateC;
        }
        Stema.DataService1.callBaseMethod(this, 'dispose');
    }
}
Stema.DataService1.registerClass('Stema.DataService1', Sys.UI.Control);

// --------------------

if (typeof (Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();


