/*
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ---- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
 AHDSS - Ajuste de ancho de columnas.
 version:  d01-m04-a07.
 -- -- -- -- -- -- -- -- --
 Mauricio F. Tolezano - Acuataller (www.acuataller.com)
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- ---- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
*/

org.mendezmende.partidas.AjusteColumnas = {	
	
	u 		: null,
	
	
	iniciar : function ()
	{
		if (!document.getElementById) return; //|| !document.cookie
		
		this.u = new com.acuataller.utiles.Utiles();
		this.u.setClaseBandera('dom');
		
		this.crearHTML();
		
		this.mostrarColumna( !this.getCookie() || this.getCookie()=='true' );
	},
	
	
	mostrarColumna : function (mostrar)
	{
		var body = document.getElementsByTagName('body')[0];

		
		if( mostrar ){
			this.u.eliminarEstilo( body, 'esconder-columna');			
		}else{
			
			this.u.asignarEstilo ( body, 'esconder-columna');
		}
		this.setCookie(mostrar);
	},
	
	
	crearHTML: function(etiquetaCerrarAmpliacion) 
	{		
		var _this = this;
		
		// Enlace esconder Ayuda.
		var esconderAyuda		= this.u.createElement('a');
		esconderAyuda.href		= '#';
		esconderAyuda.id		= 'lk-esconder-ayuda';
		esconderAyuda.title		= 'Esconder';
		
		esconderAyuda.appendChild( this.u.createTextNode('Esconder') );
		
		esconderAyuda.onclick=function() {
			_this.mostrarColumna(false);			
			return false;
		}
		
		var contenedorEsconder	= this.u.createElement('div'); // para IE 6-
		contenedorEsconder.appendChild(esconderAyuda);
		//document.getElementById('ayuda-busqueda').appendChild(contenedorEsconder);
		document.getElementById('ayuda-busqueda').insertBefore(contenedorEsconder, document.getElementById('ayuda-busqueda').firstChild);
		
		
		// Enlace esconder Solicitud.
		var esconderSolicitud		= this.u.createElement('a');
		esconderSolicitud.href		= '#';
		esconderSolicitud.id		= 'lk-esconder-solicitud';
		esconderSolicitud.title		= 'Esconder';
		esconderSolicitud.appendChild( this.u.createTextNode('Esconder') );
		
		esconderSolicitud.onclick=function() {
			_this.mostrarColumna(false);			
			return false;
		}
		
		var contenedorEsconder	= this.u.createElement('div'); // para IE 6-
		contenedorEsconder.appendChild(esconderSolicitud);
		document.getElementById('solicitud').insertBefore(contenedorEsconder, document.getElementById('solicitud').firstChild);
		
		
		
		// Mostrar ayuda
		var mostrarAyuda		= this.u.createElement('a');
		mostrarAyuda.href		= '#';
		mostrarAyuda.id			= 'lk-mostrar-ayuda';
		mostrarAyuda.title		= 'Mostrar Ayuda';
		mostrarAyuda.appendChild( this.u.createTextNode('Mostrar Ayuda') );
		
		mostrarAyuda.onclick=function() {
			_this.mostrarColumna(true);			
			return false;
		}
		document.getElementById('busqueda').appendChild(mostrarAyuda);
		
				
		// Mostrar Solicitud
		var mostrarSolicitud	= this.u.createElement('a');
		mostrarSolicitud.href	= '#';
		mostrarSolicitud.id		= 'lk-mostrar-solicitud';
		mostrarSolicitud.title	= 'Mostrar Solicitud';
		mostrarSolicitud.appendChild( this.u.createTextNode('Mostrar Solicitud') );
		
		mostrarSolicitud.onclick=function() {
			_this.mostrarColumna(true);			
			return false;
		}
		document.getElementById('busqueda').appendChild( mostrarSolicitud );
	},
	
	
	setCookie : function (value) 
	{
		document.cookie = 'AHDSS_partidas_ajusteColumnas='+value+'; path=/';
	},


	getCookie : function () 
	{
		var nameEQ = 'AHDSS_partidas_ajusteColumnas=';
		var ca = document.cookie.split(';');
		for(var i=0;i < ca.length;i++) {
			var c = ca[i];
			while (c.charAt(0)==' ') c = c.substring(1,c.length);
			if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
		}
		return null;
	}
	
}


ELO.functionsToCallOnload.push("org.mendezmende.partidas.AjusteColumnas.iniciar()");


