var mnu = "";
var smnu = "";
var mnul = null;
var box1 = {};
var cabecera = "0";
var bmanterior= "";
/* Multibox */

/*		seleccionar automaticamente el texto     */
function selecciona_value(objInput) { 

	var valor_input = objInput.value;
	var longitud = valor_input.length;

	if (objInput.setSelectionRange) { 
		objInput.focus();
		objInput.setSelectionRange (0, longitud);
	}
	else if (objInput.createTextRange) {
		var range = objInput.createTextRange();
		range.collapse(true);
		range.moveEnd('character', longitud);
		range.moveStart('character', 0);
		range.select();
	}
}


window.addEvent('domready', function(){

    $(document.body).getElements('a').addEvents({
        'mouseover': function() { window.status = this.title ;return true;},
        'mouseout': function() { window.status = "";}
    });

	$$('div.botonm').each(function(bm){
        bm.addEvent('click', function(e){
            if (e) new Event(e).stop();
			if(bmanterior!="")
			bmanterior.removeClass('menu-act');
			bm.addClass('menu-act');
			bmanterior = bm;
			a = bm.getElement('a');
			loadContenido(a.href, 'contenido', a.rel, a.rev);
			//window.location="#alcontenido";
        });
    });

	$$('a.lnk').each(function(el){
        el.addEvent('click', function(e){
            if (e) new Event(e).stop();
			if(this.id="contenido-subcab"){
				if(bmanterior!="") bmanterior.removeClass('menu-act');
				loadContenido(this.href, 'contenido', this.rel, this.rev);
			}
        });
    });

	$$('a.milink').each(function(el){
        el.addEvent('click', function(e){
            if (e) new Event(e).stop();
			if(this.id="estelink"){
				//if(bmanterior!="") bmanterior.removeClass('menu-act');
				loadContenido(this.href, 'subcontenido', this.rel, this.rev);
			}
        });
    });

	$('inicio').fireEvent('click');

	var Tips2 = new Tips($$('.Tips2'), 
	{
		initialize:function(){
			this.fx = new Fx.Style(this.toolTip, 'opacity', {duration: 500, wait: false}).set(0);
		},
		onShow: function(toolTip) {
			this.fx.start(1);
		},
		onHide: function(toolTip) {
			this.fx.start(0);
		}
	});
});

var loadContenido = function(url, div, js, css){
	if($(div)!=null){
		if(!url.contains('?'))
			url=url+"?_=";
		$(div).addClass('loader');
		$(div).empty();
		
		new Ajax(url, {
			method: 'get',
			onFailure: function(e){
				alert("Error en despliegue #" + e.status);
			},
			onComplete:function(e) {
				$(div).removeClass('loader');
				$(div).setHTML(e);
				if(css!=null)
					if(css!="")
						new Asset.css(css, {id: 'sc'});
				if(js!=null)
					if(js!="")
						new Asset.javascript(js, {id: 'sc'});
				alert
				if(div=='contenido' && !url.contains('pag_internas/inicio/pagInicio.html'))
					scroll(0,580);
			}
		}).request();
	}
}
