var W3CDOM = (document.createElement && document.getElementById);
//debe estar definida la variable largomax
if (!largomax) var largomax=800;
function getElement(id){
	return W3CDOM?document.getElementById(id):document.all[id];
}
function taLimit(objeto,perlargomax)
{
	var finlargomax=largomax;
	if (perlargomax>0) finlargomax=perlargomax
	if (objeto.value.length>=finlargomax) return false;
}
function taCount(objeto, visCnt, perlargomax) {
	var od = getElement(visCnt);

	var finlargomax=largomax;
	if (perlargomax>0) finlargomax=perlargomax

	if (objeto.value.length>finlargomax) objeto.value=objeto.value.substring(0,finlargomax);
	if (od) od.innerHTML=finlargomax-objeto.value.length;
}
function abreventana(url,nombre,caracteristicas) { //v2.0
  window.open(url,nombre,caracteristicas);
}
function visibleobj(id,tipo,idimg,ida)
{
	if (tipo)
	{
		if(id) document.getElementById(id).style.visibility='visible';
		if(id) document.getElementById(id).style.display='block';
		if(idimg) document.getElementById(idimg).src="img/menos_r.gif";
		if(ida) document.getElementById(ida).href="javascript:visibleobj('"+id+"',0,'"+idimg+"','"+ida+"')";
	}
	else
	{
		if(id) document.getElementById(id).style.visibility='hidden';
		if(id) document.getElementById(id).style.display='none';
		if(idimg) document.getElementById(idimg).src="img/mas_r.gif";
		if(ida) document.getElementById(ida).href="javascript:visibleobj('"+id+"',1,'"+idimg+"','"+ida+"')";
	}
}

function confirmar()
{
	if (confirm('¿Estás seguro que deseas eliminar el elemento seleccionado?'))
		return true;
	else
		return false;
}


function objtabulador()
{
	//numero total de pestañas
	this.tab_pestanas=0;

	//imagen pestaña
	this.tab_img='';

	//imagen pestaña seleccionada
	this.tab_img_seleccion='';

	//nombre pestaña (div, span) html de tabuladores (tabs, tab)
	//por defecto 'tabs'
	//nombres div en html deben quedar como matriz
	//Ej. las pestañas son <div id='tabs[0]'>Tab0</div>, <div id='tabs[1]'>Tab1</div>
	this.tab_nombre='tabs';

	//nombre etiqueta html que contiene los datos (pags, pag, etc)
	//por defecto 'pags'
	//nombres div en html deben quedar como matriz
	//Ej. Las páginas de contenido son <div id='pags[0]'>datos 1</div>, <div id='pags[1]'>datos 2</div>
	this.tab_nombre_pag='pags';

	//desabilitar la tabulación completa (0 no; 1 si)
	this.tab_deshabilitar=0;

	//invisible los deshabilitados
	this.tab_invisible_deshabilitar=0;

	//color de fuente de pestañas
	this.tab_color='#000'

	//color de fuente de pestaña seleccionada
	this.tab_color_seleccionada='#000';

	//indica o define el tabulador actual
	this.tab_actual=0;

	//visibilidad de la pestaña
	//se despliegan u ocultan las pestañas (0 visible, 1 invisible)
	//individualmente en la accion tabular e inicializar
	this.tab_invisible_individual=new Array();

	//funciones ligadas a cada click en pestaña
	//Las funciones ligadas se ejecutan despues de tabular
	//y se ejecuta sólo la funcion ligada a la pestaña seleccionada
	//Ej. objtab.tab_funcion[0]='alert("Hola mundo")';
	//Se envía el mensaje 'Hola mundo' al hacer click en la pestaña 0 [tabs[0]]
	this.tab_funcion=new Array();

	//funciones gatillo ligadas a cada click en pestaña
	//Las funciones gatillo ligadas se ejecutan antes o despues de tabular
	//y se ejecuta sólo la funcion ligada a la pestaña seleccionada
	//Ej. objtab.tab_funcion[0]='retorna_booleano("Hola mundo");';
	//Se activa la pestaña seleccionada sólo se la funcion "retorna_booleano" devuelve TRUE
	this.tab_funcion_pregatillo=new Array();
	this.tab_funcion_posgatillo=new Array();

	//Deshabilitacion individual de tabs  (0 no; 1 si)
	//Nota: No tabula ni ejecuta función individual
	//Ej. objtab.tab_deshabilitar_individual[0]=1;
	// se deshabilita la pestaña 0 (tabs[0])
	this.tab_deshabilitar_individual=new Array();



	//Mensaje deshabilitado general
	//Envía un mensaje al hacer click sobre cualquier pestaña
	//deshabilitada
	this.tab_mensaje=0;

	//Mensaje deshabilitado individual
	//Envía un mensaje al hacer click sobre una pestaña
	//deshabilitada
	this.tab_mensaje_individual=new Array();

	//Ancho de tabuladores general e individual
	//Dimensiona el ancho de las pestañas
	this.tab_ancho='';
	this.tab_ancho_individual=new Array();

	this.validar_objeto= function()
	{
		if(!this.tab_nombre) {alert('Error: Objeto tabulador no tiene nombre'); return false;}
		if(!this.tab_pestanas) {alert('Error: Objeto tabulador no tiene maximo de pestañas'); return false;}
		if(!this.tab_nombre_pag) {alert('Error: Objeto tabulador no tiene definido las etiquetas tabuladoras contenedoras de datos'); return false;}
		return true;
	}

	this.ajustar_seleccion= function(id_seleccion)
	{
		//pestaña seleccionada
		var idaux=this.tab_nombre+'['+id_seleccion+']';
		//pagina contenedora seleccionada
		var idauxpag=this.tab_nombre_pag+'['+id_seleccion+']';

		//indicamos tabulador actual
		this.tab_actual=id_seleccion;

		if (document.getElementById(idaux)) document.getElementById(idaux).style.display='';

		//fuente en negrita
		document.getElementById(idaux).style.fontWeight='bold';

		//si se configuro el ancho de pestañas o el ancho individual
		if (this.tab_ancho_individual[id_seleccion])
		{
			document.getElementById(idaux).style.width=this.tab_ancho_individual[id_seleccion]+'px';
		}
		else if (this.tab_ancho)
		{
			document.getElementById(idaux).style.width=this.tab_ancho+'px';
		}

		//si se configuro el color de fuente le damos el color determinado
		//si no, por defecto le damos el color negro
		if (!this.tab_color_seleccionada)
			document.getElementById(idaux).style.color='#000';
		else
			document.getElementById(idaux).style.color=this.tab_color_seleccionada;

		//si existe imagen para la pestaña seleccionada
		//cambiamos la imagen y la alineamos a la derecha
		if (this.tab_img_seleccion)
		{
			document.getElementById(idaux).style.background='url('+this.tab_img_seleccion+')  no-repeat';
			document.getElementById(idaux).style.backgroundPosition='top right';
		}

		//hacemos visible el contenedor correspondiente a la pestaña i
		if (document.getElementById(idauxpag)) document.getElementById(idauxpag).style.display='';
	}

	this.ajustar_deseleccion= function(id)
	{

		//pestaña seleccionada
		var idaux=this.tab_nombre+'['+id+']';
		//pagina contenedora seleccionada
		var idauxpag=this.tab_nombre_pag+'['+id+']';

		//fuente en normal
		document.getElementById(idaux).style.fontWeight='normal';

		//si se configuro el ancho de pestañas o el ancho individual
		if (this.tab_ancho_individual[id])
		{
			document.getElementById(idaux).style.width=this.tab_ancho_individual[id]+'px';
		}
		else if (this.tab_ancho)
		{
			document.getElementById(idaux).style.width=this.tab_ancho+'px';
		}

		//alert(document.getElementById(idaux).style.display);
		//verificamos si el tabulador esta deshabilitado
		// si es asi, le damos un color plomo a la fuente
		//en caso contrario verificamos si se configuro el color para pestañas
		//no seleccionadas, si es asi le damos el color determinado, de lo contrario,
		//el color negro por defecto
		if (this.tab_deshabilitar || this.tab_deshabilitar_individual[id]==1)
		{
			document.getElementById(idaux).style.color='#999999';
			if (this.tab_invisible_deshabilitar==1)
			{
				if (document.getElementById(idaux)) document.getElementById(idaux).style.display='none';
			}
			else
			{
				if (document.getElementById(idaux))
				{
					if (this.tab_invisible_individual[id]==1)
						document.getElementById(idaux).style.display='none';
					else
						document.getElementById(idaux).style.display='';
				}
			}
		}
		else
		{
			if (!this.tab_color)
				document.getElementById(idaux).style.color='#000';
			else
				document.getElementById(idaux).style.color=this.tab_color;

			if (document.getElementById(idaux))
			{
				if (this.tab_invisible_individual[id]==1)
					document.getElementById(idaux).style.display='none';
				else
					document.getElementById(idaux).style.display='';
			}

		}

		//alert(document.getElementById(idaux).style.display);

		//si se configuro la imagen para pestañas no seleccionadas
		//se la asignamos y alineamos a la derecha
		if (this.tab_img)
		{
			document.getElementById(idaux).style.background='url('+this.tab_img+')  no-repeat';
			document.getElementById(idaux).style.backgroundPosition='top right';
		}

		//hacemos invisible el contenedor correspondiente a la pestaña i
		if (document.getElementById(idauxpag)) document.getElementById(idauxpag).style.display='none';
	}

	this.ejecutar_funciones=function(tabfuncion)
	{
		if (this.tab_funcion[this.tab_actual]) eval(this.tab_funcion[this.tab_actual]);
		if (tabfuncion) eval(tabfuncion);
	}
	this.tabular=function(tabid,tabfuncion)
	{
		var idx_tab=-1;
		var retorno;
		for(var j=0; j<this.tab_pestanas ; j++)
		{
			if(this.tab_nombre+'['+j+']'==tabid) idx_tab=j;
		}

		if (idx_tab<0) return false;

		if (idx_tab==this.tab_actual) return true;

		//ejecutamos la funcion de gatillo posterior
		if (this.tab_funcion_posgatillo[this.tab_actual])
		{
			eval('retorno='+this.tab_funcion_posgatillo[this.tab_actual]);
			if (!retorno) return;
		}

		//ejecutamos la funcion de gatillo anterior
		if (this.tab_funcion_pregatillo[idx_tab])
		{
			eval('retorno='+this.tab_funcion_pregatillo[idx_tab]);
			if (!retorno) return;
		}

		if (!this.tab_deshabilitar)
		{

			if (idx_tab<0) return false;
			//recorrer pestañas
			for(var i=0; i<this.tab_pestanas ; i++)
			{

				//pestaña seleccionada
				var idaux=this.tab_nombre+'['+i+']';
				//pagina contenedora seleccionada
				var idauxpag=this.tab_nombre_pag+'['+i+']';

				//verificamos si existe la pestaña i
				if (document.getElementById(idaux))
				{
					//cambiamos el puntero del mouse dependiendo de la opcion tab_deshabilitar
					if (this.tab_deshabilitar || this.tab_deshabilitar_individual[i]==1)
						document.getElementById(idaux).style.cursor='default';
					else
						document.getElementById(idaux).style.cursor='pointer';

					//verificamos si la pestaña i es igual a la pestaña seleccionada
					if (idaux==tabid)
					{
						if (!this.tab_deshabilitar_individual[idx_tab]==1)
							this.ajustar_seleccion(i);
						else
							if (this.tab_mensaje_individual[idx_tab]) if (idx_tab!=this.tab_actual) alert(this.tab_mensaje_individual[idx_tab]);
					}
					else
					{
						if (!this.tab_deshabilitar_individual[idx_tab]==1) this.ajustar_deseleccion(i);
					}
				}
			}
			if (!this.tab_deshabilitar_individual[idx_tab]==1) this.ejecutar_funciones(tabfuncion);
		}
		else if (this.tab_mensaje) if (idx_tab!=this.tab_actual) alert(this.tab_mensaje);
	}

	this.tabularnum=function(numid)
	{
		this.tabular(this.tab_nombre+'['+numid+']');
	}

	this.inicializar = function(tabfuncion)
	{
		if (this.validar_objeto())
		{
			//recorrer pestañas
			for(var i=0; i<this.tab_pestanas ; i++)
			{
				//pestaña seleccionada
				var idaux=this.tab_nombre+'['+i+']';
				//pagina contenedora seleccionada
				var idauxpag=this.tab_nombre_pag+'['+i+']';

				//verificamos si existe la pestaña i
				if (document.getElementById(idaux))
				{
					//cambiamos el puntero del mouse dependiendo de la opcion tab_deshabilitar
					if (this.tab_deshabilitar || this.tab_deshabilitar_individual[i]==1)
						document.getElementById(idaux).style.cursor='default';
					else
						document.getElementById(idaux).style.cursor='pointer';

					//verificamos si la pestaña i es igual a la pestaña seleccionada
					if (i==this.tab_actual)
						this.ajustar_seleccion(i);
					else
						this.ajustar_deseleccion(i);
				}
			}
		}
		this.ejecutar_funciones(tabfuncion);
	}

	this.fztabular=function(tabid,tabfuncion)
	{
		var idx_tab=-1;
		var retorno;
		for(var j=0; j<this.tab_pestanas ; j++)
		{
			if(this.tab_nombre+'['+j+']'==tabid) idx_tab=j;
		}

		if (idx_tab<0) return false;

		if (idx_tab==this.tab_actual) return true;

		//ejecutamos la funcion de gatillo posterior
		if (this.tab_funcion_posgatillo[this.tab_actual])
		{
			eval('retorno='+this.tab_funcion_posgatillo[this.tab_actual]);
			if (!retorno) return;
		}

		//ejecutamos la funcion de gatillo anterior
		if (this.tab_funcion_pregatillo[idx_tab])
		{
			eval('retorno='+this.tab_funcion_pregatillo[idx_tab]);
			if (!retorno) return;
		}

		this.tab_actual=idx_tab;

		this.inicializar(tabfuncion);
	}

	this.fztabularnum=function(numid,tabfuncion)
	{
		this.fztabular(this.tab_nombre+'['+numid+']',tabfuncion);
	}
}

function tabulador(tabid,objtab,tabfuncion)
{
	if (!objtab instanceof objtabulador) {alert('Error: Objeto tabulador no definido'); return false;}
	objtab.validar_objeto();
	objtab.tabular(tabid,tabfuncion)
}
function buscar_estandar(mision_buscar,pagina, variables)
{
	var valor;
	var msgespera='<center style="font-size: 7pt;"><img src="imagenes/cargando.gif" border=0 align="absmiddle">Buscando..</center>';
	if (!variables) variables=new Array();
	querystr='ptexto_busca='+document.getElementById('ptexto_busca').value;
	querystr+='&mision='+mision_buscar;
	for(var x=0;x<variables.length;x++)
	{
		if(variables[x].c&&variables[x].v)
		{
			querystr+='&'+variables[x].c+'='+variables[x].v;
		}
	}
	traerDatos(pagina,querystr,'resultado',msgespera);
}
function editar_estandar(num_frame, id,id_tab,pagina,mision)
{
	if (window.parent.document.getElementById('f'+num_frame))
	{
		window.parent.document.getElementById('f'+num_frame).src='blank.php';
		window.parent.objtab.tab_actual=id_tab;
		window.parent.objtab.inicializar();
		window.parent.document.getElementById('f'+num_frame).src=pagina + '?gmision='+mision+'&gid='+id;
	}
}
function eliminar_estandar(nombreid,id,pagina,funcion)
{
	var querystr='';
	if (!confirm('¿Estás seguro que deseas eliminar?')) return;

	querystr=nombreid + '='+id;
	querystr+='&mision=0XHel4';
	traerScript(pagina,querystr,funcion);
}
function FixCalcX(el)
{
    if(typeof(el.offsetParent) == "undefined")
        return [70, 4000];
	var a = new Array(0, -70);
	while(el)
	{
		a[0] += el.offsetLeft || 0;
		a[1] += el.offsetTop || 0;
		el = el.offsetParent || null;
	}
	return a[0];
}
function FixCalcY(el)
{
    if(typeof(el.offsetParent) == "undefined")
        return [70, 4000];
	var a = new Array(0, -70);
	while(el)
	{
		a[0] += el.offsetLeft || 0;
		a[1] += el.offsetTop || 0;
		el = el.offsetParent || null;
	}
	return a[1];
}

function FixCalcXY(el)
{
    if(typeof(el.offsetParent) == "undefined")
        return [70, 4000];
	var a = new Array(0, -70);
	while(el)
	{
		a[0] += el.offsetLeft || 0;
		a[1] += el.offsetTop || 0;
		el = el.offsetParent || null;
	}
	return a;
}



