var Util = new Class({
    options: {
        'base_url': '',
        'site_url': '',
        'default_method': 'get'
    },

    vazio: function(){},

    call: function(uri, data, response, method)
    {
        var url = uri;

        if(url.indexOf("?") == -1)
            url+= '?';

        for ( var key in data )
            url+= '&' + key + '=' + escape(data[key]);

        method = method==null ?this.options.default_method :method;
        
        response = response==null ?this.vazio :response;

        // new Json.Remote(url, {'onComplete': response,'method': method}).send(data);

        new Request.JSON({
            url: url,
            method: method,
            onComplete: response,
            data: data
        }).send();
    },

    busca: function()
    {
        document.buscaForm.submit();
    },

    showModalMessageAndRedirect: function(message, url)
    {
        this.showModalMessage(message, null, null, url);
    },

    showModalMessageVerdeAndRedirect: function(message, url)
    {
        this.showModalMessageVerde(message, null, null, url);
    },

    showModalMessageVerde: function(message, width, height, url)
    {
        //371
        //132

        if ( url != null )
            url = new Util().options.base_url + url;

        width = (width!=null) ?width :371;
        height = (height!=null) ?height :0;
        
        var content2222 = '' +
        '<div style="width:' + width + 'px; height:' + height + 'px">' +
        '<div  class="tp">' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_01-verde.gif" width="5" height="5" /></div>' +
        '<div style="height:5px; width:' + (width-10) + 'px; background-color:#2ccc00">&#160;</div>' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_03-verde.gif" width="5" height="5" /></div>' +
        '</div>' +

        '<div style="width:' + (width-40) + 'px; background-color:#2ccc00; padding:20px; text-align:center" class="Lpd10 Rpd10 w ft14">' +
        '<p class="b" style="font-size:15px">' +
        message +
        '<br /></p>' +
        '<div class="Tmg10" style="width:150px; padding-left:154px">' +
        '<div class="bot_laranja_esq"></div>' +
        '<div class="bot_laranja_back">' +
        '<a' + ( (url!=null) ?' href="' + url + '" ' :' href="javascript:new Util().vazio()" onClick="closeMessage()" ' ) + 'class="bot_laranja_text b">OK</a>' +
        '</div>' +
        '<div class="bot_laranja_dir"></div>' +
        '</div>' +
        '</div>' +
        '<div  class="tp">' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_07-verde.gif" width="5" height="5" /></div>' +
        '<div style="height:5px; width:' + (width-10) + 'px; background-color:#2ccc00">&#160;</div>' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_09-verde.gif" width="5" height="5" /></div>' +
        '</div>' +
        '</div>';
    
        var content = '' +
        '<div style="width:' + width + 'px' + ( (height > 0) ?';height:' + height + 'px' :'' ) + '">' +
        '<div  class="tp">' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_01.gif" width="5" height="5" /></div>' +
        '<div style="height:5px; width:' + (width-10) + 'px; background-color:#66CDCC">&#160;</div>' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_03.gif" width="5" height="5" /></div>' +
        '</div>' +
        '<div style="width:' + (width-40) + 'px; background-color:#66CDCC; padding:20px;" class="Lpd10 Rpd10 w ft14">' +
        '<span>' + message + '</span><br />' +
        '<div class="Tmg10" style="width:100%">' +
        '<div class="bot_laranja_esq"></div>' +
        '<div>' +
        '<input type="button" value="OK" class="buttom_submit_orange" onClick="' + ( (url!=null) ?'location.href=\'' + url + '\'' :'closeMessage()' ) + ';">' +
        '</div>' +
        '<div class="bot_laranja_dir"></div>' +
        '</div>' +
        '</div>' +
        '<div  class="tp">' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_07.gif" width="5" height="5" /></div>' +
        '<div style="height:5px; width:' + (width-10) + 'px; background-color:#66CDCC">&#160;</div>' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_09.gif" width="5" height="5" /></div>' +
        '</div>' +
        '</div>';


        displayStaticMessage(content, width, 0);
    },

    showModalMessage: function(message, width, height, url)
    {
        width = (width!=null) ?width :371;
        height = (height!=null) ?height :0;
       
        var content = '' +
        '<div style="width:' + width + 'px' + ( (height > 0) ?';height:' + height + 'px' :'' ) + '">' +
        '<div  class="tp">' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_01.gif" width="5" height="5" /></div>' +
        '<div style="height:5px; width:' + (width-10) + 'px; background-color:#66CDCC">&#160;</div>' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_03.gif" width="5" height="5" /></div>' +
        '</div>' +
        '<div style="width:' + (width-40) + 'px; background-color:#66CDCC; padding:20px;" class="Lpd10 Rpd10 w ft14">' +
        '<span>' + message + '</span><br />' +
        '<div class="Tmg10" style="width:100%">' +
        '<div class="bot_laranja_esq"></div>' +
        '<div>' +
        '<input type="button" value="OK" class="buttom_submit_orange" onClick="' + ( (url!=null) ?'location.href=\'' + url + '\'' :'closeMessage()' ) + ';">' +
        '</div>' +
        '<div class="bot_laranja_dir"></div>' +
        '</div>' +
        '</div>' +
        '<div  class="tp">' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_07.gif" width="5" height="5" /></div>' +
        '<div style="height:5px; width:' + (width-10) + 'px; background-color:#66CDCC">&#160;</div>' +
        '<div><img src="' + util.options.base_url + 'images/margem_quadroaviso_09.gif" width="5" height="5" /></div>' +
        '</div>' +
        '</div>';

        displayStaticMessage(content, width, 0);
    },
    verifica: function(obj, id, MaxLength )
    {         	      
        var contador = $(id);

        if (MaxLength !=0)
        {
            if (obj.value.length > MaxLength)
            {
                obj.value = obj.value.substring(0, MaxLength);	           		                     			

            }
        }
        contador.innerHTML = MaxLength - obj.value.length;
    },

    expand: function(){
        if($('my_select'))
            $('my_select').style.width = '170px';
    },

    contract: function(){
        if($('my_select'))
            $('my_select').style.width = '122px';
    }
});