﻿Type.registerNamespace('DDTI.Web.Map.Toolbox');

DDTI.Web.Map.Toolbox.DTBufferControl = function(element) { 
    DDTI.Web.Map.Toolbox.DTBufferControl.initializeBase(this, [element]);
}

DDTI.Web.Map.Toolbox.DTBufferControl.prototype = {
    initialize : function() {
        DDTI.Web.Map.Toolbox.DTBufferControl.callBaseMethod(this, 'initialize');
        this._onclickHandler = Function.createDelegate(this, this._onClick);
        $addHandlers ( this.get_element(), { 'click' : this._onClick }, this );
    },

    dispose : function() {
        $clearHandlers(this.get_element());
        DDTI.Web.Map.Toolbox.DTBufferControl.callBaseMethod(this, 'dispose');
    },

    _onClick : function(e) {
        DDTI.Web.Map.Toolbox.DTToolboxComponent.prototype.set_activeTool(DDTI.Web.Map.Toolbox.DTToolTypes.Buffer);
    },
    
    doBuffer : function() {
        var w = DDTI.Web.Map.Viewer.DTViewerComponent.prototype.get_width();
        var h = DDTI.Web.Map.Viewer.DTViewerComponent.prototype.get_height();
        var r = parseInt(document.getElementById('ctl00_ContentPlaceHolder1_MainToolBox_Buffer_BufferRadius').value);
        if (isNaN(r) || r == '') {
            alert('Please enter a distance in the \'Buffer Distance\' textbox');
            return;
        }
        if (r > 5280) {
            alert('Please enter a distance less than 5280 feet (1 mile).');
        }
        DDTI.Web.Map.Viewer.DTViewerComponent.prototype.set_imageUrl('Default.mapx?Todo=Buffer&Radius=' + r + '&Width=' + w + '&Height=' + h + '&Random=' + Math.floor(Math.random()*1000000));
    }
}

DDTI.Web.Map.Toolbox.DTBufferControl.registerClass('DDTI.Web.Map.Toolbox.DTBufferControl', Sys.UI.Control);

if (typeof(Sys) !== 'undefined') Sys.Application.notifyScriptLoaded();
if(typeof(Sys)!=='undefined')Sys.Application.notifyScriptLoaded();