/************************************************************************************
FUNCIONES DE CONTROL DE FORMULARIOS
************************************************************************************/
function comenzarDescarga(archivo) {
  idl = -1;
  idl = location.search.indexOf("idl=n");
  if (idl < 0) document.write('<iframe height="0" width="0" src="'+archivo+'"></iframe>');
}
function formatearPorcentaje(num) {
	num = num.toString().replace(/\$|\,/g,'');
	if(isNaN(num)) num = "0";
	sign = (num == (num = Math.abs(num)));
	num = Math.floor(num*100+0.50000000001);
	cents = num%100;
	num = Math.floor(num/100).toString();
	if(cents<10) cents = "0" + cents;
	for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++) num = num.substring(0,num.length-(4*i+3))+','+
	num.substring(num.length-(4*i+3));
	return (((sign)?'':'-') + num + '.' + cents + ' %');
}
function formatearDecimal(signo,c) {
	c.value=c.value.replace(" ","");
	c.value=c.value.replace(".",",");
	str=signo+" ";
	a=new Array();
	for(i=0;i<c.value.length;i++){
		a[i]=c.value.charAt(i);
	}
	a=a.reverse();
	r=new Array();
	j=0;
	iniciado=false;
	if(c.value.indexOf(',')==-1){
		return formatear(signo,c);
	} else {
		for(i=0;i<a.length;i++){
			if(a[i]!="," && iniciado!=true) {
				r[j]=a[i];
				j++;
			}
			if(a[i]=="," && iniciado!=true) {
				ini=i;
				iniciado=true;
			}
			if (iniciado==true) {
				pos=i-ini;
				if(i<(a.length-1) && (pos)%3==0 && pos>1){
					r[j]="."+a[i];
				} else {
					r[j]=a[i];
				}
				j++;
			}
		}
	}
	r=r.reverse();
	for(i=0;i<r.length;i++){
		str+=r[i];
	}
	c.value=str;
}


function formatear(signo,c){
	c.value=limpiarCC(c.value);
	c.value=c.value.replace(" ","");
	str=signo+" ";
	a=new Array();
	for(i=0;i<c.value.length;i++){
		a[i]=c.value.charAt(i);
	}
	a=a.reverse();
	r=new Array();
	j=0;
	for(i=0;i<a.length;i++){
		if(i<(a.length-1) && (i+1)%3==0){
			r[j]="."+a[i];
		} else {
			r[j]=a[i];
		}
		j++;
	}
	r=r.reverse();
	for(i=0;i<r.length;i++){
		str+=r[i];
	}
	c.value=str;
}
function formatearEntero(signo,v){
	v=v.replace(" ","");
	str=signo+" ";
	a=new Array();
	for(i=0;i<v.length;i++){
		a[i]=v.charAt(i);
	}
	a=a.reverse();
	r=new Array();
	j=0;
	for(i=0;i<a.length;i++){
		if(i<(a.length-1) && (i+1)%3==0){
			r[j]="."+a[i];
		} else {
			r[j]=a[i];
		}
		j++;
	}
	r=r.reverse();
	for(i=0;i<r.length;i++){
		str+=r[i];
	}
	return str;
}
function setEliminar(f,id){
	if (confirm("Desea eliminar el registro actual?")){
		f.operacion.value="eliminar";
		f.id.value=id;
		f.submit();
		verProcesando();
	}
}
function habilitarCampo(b,c){
	if(b==true){
		c.disabled=false;
		//c.focus();
	}else{
		c.value='';
		c.disabled=true;
	}
}
function setOption(c,valor){
	for(i=0;i<=c.length;i++){
		if(c.options[i].value==valor) {
			c.options[i].selected=true;
			return;
		}
	}
}
function setChecked(c,valor) {
	if (valor=="t") c.checked=true;
	if (valor=="f") c.checked=false;
}
function checkCrear(valor, funcion){
	if (valor=="crear") {
		setTimeout(funcion,0);
	}
}
function limpiarCC(cc){
	cc=cc.replace(" ","");
	cc_limpia="";
	for(i=0;i<=cc.length;i++){
		if(isNaN(cc.charAt(i))==false) cc_limpia+=cc.charAt(i);
	}
	return cc_limpia;
}
function limpiarDecimal(vlr){
	vlr=vlr.replace(" ","");
	vlr_limpio="";
	for(i=0;i<=vlr.length;i++){
		if(isNaN(vlr.charAt(i))==false) vlr_limpio+=vlr.charAt(i);
		if(vlr.charAt(i)==".") vlr_limpio+=".";
	}
	return vlr_limpio;
}
function limpiarNumero(val){
	num="";
	for(i=0;i<=val.length;i++){
		if(isNaN(val.charAt(i))==false) num+=val.charAt(i);
	}
	return num;
}
function nada() {}
/************************************************************************************
FUNCIONES DE CHEQUEO DE TIPO DE CAMPOS
************************************************************************************/
function checkEmail(f){
	f.to.disabled=false;
	if(checkNmail(f.to,"Error: no ha sido cargado el e_mail al cual se dirigirá el mensaje. \nSi el e_mail existe en el formulario inicial y se produce este error, consulte con el administrador del sitema.")) {
		f.to.disabled=true;
		return;
	}
	f.to.disabled=true;
	if(checkVacio(f.nombre,"Error: no ha sido cargado el nombre del funcionario actual que escribirá el mensaje. \nConsulte con el administrador del sitema."))return;
	if(checkNmail(f.reply,"Ingrese la dirección de correo a la cual usted desea sea dirigida una respuesta."))return;
	if(checkVacio(f.asunto,"Ingrese el asunto del mensaje."))return;
	if(checkVacio(f.mensaje,"Ingrese el mensaje."))return;
	f.to.disabled=false;
	f.nombre.disabled=false;
	f.submit();
}
function checkNselect(c,msg){
	if(c[c.selectedIndex].value=="none" || c[c.selectedIndex].value=="crear"){
		alert(msg);
		c.focus();
		return true;
	}
}
function checkNradio(c,msg){
	for(i=0;i<c.length;i++) if(c[i].checked==true) return false;
	alert(msg);
	return true;
}
function checkVacio(c,msg){
	if(c.value=="" || c.value==null){
		alert(msg);
		if(c.type!="hidden") {
			c.focus();
			c.select();
		}
		return true;
	}
}
function checkNan(c,msg){
	if(c.value=="" || c.value==null || isNaN(c.value)==true){
		alert(msg);
		c.focus();
		c.select();
		return true;
	}
}
function checkNmail(c,msg){
	if(c.value=="" || c.value==null || c.value.indexOf('@')==-1 || c.value.indexOf('.')==-1){
		alert(msg);
		c.focus();
		c.select();
		return true;
	}
}
function checkNdate(c,msg){
	len=c.value.length;
	mes=Math.floor(c.value.substring(5,7));
	dia=Math.floor(c.value.substring(8,10));
	if(c.value=="" || c.value==null || len!=10){
		alert(msg);
		c.focus();
		c.select();
		return true;
	}
	if(isNaN(c.value.charAt(0))==true ||
		isNaN(c.value.charAt(1))==true ||
		isNaN(c.value.charAt(2))==true ||
		isNaN(c.value.charAt(3))==true){
		alert("El año no debe contener letras. "+msg);
		c.focus();
		c.select();
		return true;
	}
	if(isNaN(c.value.charAt(5))==true || isNaN(c.value.charAt(6))==true){
		alert("El mes no debe contener letras. "+msg);
		c.focus();
		c.select();
		return true;
	}
	if(isNaN(c.value.charAt(8))==true || isNaN(c.value.charAt(9))==true){
		alert("El día no debe contener letras. "+msg);
		c.focus();
		c.select();
		return true;
	}
	if(c.value.charAt(4)!="-" || c.value.charAt(7)!="-"){
		alert("El separador de fecha debe ser -. "+msg);
		c.focus();
		c.select();
		return true;
	}
	if(mes<1||mes>12){
		alert("Mes no válido. "+msg);
		c.focus();
		c.select();
		return true;
	}
	if(dia<1||dia>31){
		alert("Dia no válido. "+msg);
		c.focus();
		c.select();
		return true;
	}
}

/************************************************************************************
FUNCIONES DE CONTROL DE CAJAS DE DIÁLOGO
************************************************************************************/
var isIE=document.all?true:false;
var iframes = isIE?document.all.tags("IFRAME"):null;
function visibilidadIframes(v){
	if(!isIE)return;
	for(var i=0;i<iframes.length;i++)
		ocultarIframe(i,v);
}
function ocultarIframe(i,v){
	iframes[i].style.visibility=v?'hidden':'visible';
}
var zindextop;
function ponerOntop(caja){
	iframes[caja].style.zIndex=DIF_highestZIndex++;
	zindextop=DIF_highestZIndex;
}
function verCaja(caja,t,w,h,f,icon,msg) {
	if(icon=="" || icon==null) icon="../img/cajas/app.gif";
	if(msg=="" || msg==null) msg="";
	eval(caja+".titbar.document.all[\"titulo\"].innerHTML=t");
	eval(caja+".titbar.document.all[\"icono\"].src=icon;");
	eval(caja+".titbar.document.all[\"icono\"].title=msg;");
	eval("top."+caja+".titbar.document.caja.nombre.value='"+caja+"'");
	resizeCaja(caja,w,h);
	if(caja!="calendario"){
		eval(caja+".contenido.location=f");
	}
	iframes[caja].style.left=screen.width/2-w/2;
	iframes[caja].style.top=(screen.height)/2-h/2;
	ocultarCaja(caja,false);
	ponerOntop(caja);
	window.scroll(0,0);
}
function verCaja_(caja,t,w,h,f) {
	eval("var caja_"+caja+"=top.showModelessDialog(f,'','dialogHeight:'+h+'px; dialogWidth:'+w+'px;center:yes; edge:raised; help:no; resizable:no; scroll:no; status:no');");
	eval("caja_"+caja+".name='"+caja+"'");
	
}
function verObjeto(m){
	switch(m.style.visibility){
		case 'visible':
			m.style.visibility='hidden';
			break;
		case 'hidden':
			m.style.visibility='visible';
			break;
	}
}
function verObjeto2(m,v){
	switch(v){
		case 'si':
			m.style.visibility='visible';
			break;
		case 'no':
			m.style.visibility='hidden';
			break;
	}
}
function verProcesando(){
	var p=top.document.getElementById('procesa');
	switch(p.style.visibility){
		case 'visible':
			p.style.visibility='hidden';
			break;
		case 'hidden':
			p.style.zIndex=zindextop++;
			p.style.visibility='visible';
			break;
	}
}
function setCaja(caja) {
	//eval("top."+caja+".titbar.document.caja.nombre.value='"+caja+"'");
}
function ocultarCaja(caja,v) {
	ocultarIframe(caja, v);
	if(v==true){
		resizeCaja(caja,1,1);
		iframes[caja].style.left=0;
		iframes[caja].style.top=0;
	}
}
function ocultarCaja_(caja,v) {
	if(v==true){
		eval(""+caja+".close()");
	}
}
function resizeCaja(caja,w,h){
	iframes[caja].style.width=w;
	iframes[caja].style.height=h;
}
function cerrarSesion(){
	alert("Al cerrar (ALT+F4) o actualizar (F5) la ventana se eliminan los datos de su sesión.\n\nFinalizando sesión...");
	cerrar=window.open('close.php','cerrar','toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, width=200, height=150,top='+eval(screen.height/2-75)+', left='+eval(screen.width/2-100)+',resizable=no');
	top.close();
}

/************************************************************************************
FUNCIONES DE DISEÑO GRÁFICO DE INTERFAZ
************************************************************************************/
//Funciones de no selección de contenidos de la interfaz web
function disableselect(e){
return false
}
function reEnable(){
return true
}
//Funciones de color según estado del mouse
function botonOvr(src,clrOver) {
	src.style.cursor = 'hand';
	src.style.background = clrOver;
 }
function botonOut(src,clrIn) {
	src.style.cursor = 'default';
	src.style.background = clrIn;
}
function celdaOver(inp){
	inp.className="horario_celda_over";
}
function celdaOut(inp){
	inp.className="horario_celda";
}
var fila_seleccionada=0;
function filaOver(fila){
	if(fila_seleccionada!=fila.id){
		fila.className="filaover";
	}
}
function filaOut(fila){
	if(fila_seleccionada!=fila.id){
		fila.className="filaout";
	}
}
function filaClick(fila){
	id_anterior=fila_seleccionada;
	fila_seleccionada=fila.id;
	filaOut(eval(document.all[id_anterior]));
	fila.className="filaclick";
}
function filaClickId(fila_id){
	alert();
	id_anterior=fila_seleccionada;
	fila_seleccionada=fila_id;
	fila=(eval(document.all[fila_id]));
	fila.className="filaclick";
}
function overMenu(obj) {
	if (obj.className == "menus") {
		obj.style.border = "1px inset buttonhighlight";
		obj.style.cursor = "hand";
		obj.style.fontWeight = "normal";
	}
}
function outMenu(obj) {
	if (obj.className == "menus") {
		obj.style.border = "";
		obj.style.cursor = "default";
		obj.style.fontWeight = "normal";
	}
}
var clase_out="";
function enfocarCampo(obj,enfoco) {
	if (enfoco==true) {
		clase_out=obj.className;
		obj.className=clase_out+"_realzado";
	}
	else obj.className=clase_out;
}
var boton_out="";
function enfocarBoton(obj,enfoco) {
	if (enfoco==true) {
		boton_out=obj.className;
		obj.className=boton_out+"_realzado";
	}
	else obj.className=boton_out;
}

var icono_out="";
function enfocarIcono(obj,evento) {
	switch(evento) {
		case "over":
			icono_out=obj.className;
			obj.className=icono_out+"_over";
			break;
		case "out":
			obj.className=icono_out;
			break;
		case "down":
			obj.className=icono_out+"_down";
			break;
		case "up":
			obj.className=icono_out+"_over";
			break;
		default: break;
	}
}

/************************************************************************************
FUNCIONES DE MENU CONTEXTUAL
************************************************************************************/
var menuskin = "skin1";
var display_url = 0; // Mostrar URLs en barra de estado?1:0
function showmenuie5() {
	var rightedge = document.body.clientWidth-event.clientX;
	var bottomedge = document.body.clientHeight-event.clientY;
	if (rightedge < ie5menu.offsetWidth)
	ie5menu.style.left = document.body.scrollLeft + event.clientX - ie5menu.offsetWidth;
	else
	ie5menu.style.left = document.body.scrollLeft + event.clientX;
	if (bottomedge < ie5menu.offsetHeight)
	ie5menu.style.top = document.body.scrollTop + event.clientY - ie5menu.offsetHeight;
	else
	ie5menu.style.top = document.body.scrollTop + event.clientY;
	ie5menu.style.visibility = "visible";
	return false;
}
function hidemenuie5() {
	ie5menu.style.visibility = "hidden";
}
function highlightie(obj) {
	if (obj.className == "menuitems") {
		obj.style.backgroundColor = "highlight";
		obj.style.color = "HighlightText";
		//if (display_url) window.status = obj.url;
		//ponerMsgBarraEstado(event.srcElement.title);
	}
}
function lowlightie(obj) {
	if (obj.className == "menuitems") {
		obj.style.backgroundColor = "";
		obj.style.color = "MenuText";
		//window.status = "";
		//ponerMsgBarraEstado('&nbsp;');
	}
}
function jumptoie(obj) {
	if (obj.className == "menuitems") {
		if (obj.getAttribute("target") != null)
			window.open(obj.getAttribute("url"), obj.getAttribute("target"));
		else
			window.location = obj.getAttribute("url");
	}
}

/************************************************************************************
FUNCIONES DE GESTIÓN DE CADENAS
************************************************************************************/
function branl(c) {
	lineas=new Array();
	string=new String();
	lineas=c.value.split("<br /><br>");
	for(i=0;i<lineas.length;i++){
		if(lineas[i]!="") string+=lineas[i]+"\n";
	}
	lineas=string.split("<br>");
	string="";
	for(i=0;i<lineas.length;i++){
		if(lineas[i]!="") string+=lineas[i]+"\n";
	}
	c.value = string;
}

/************************************************************************************
FUNCIONES DE GESTIÓN DE FECHAS
************************************************************************************/
function escribirHoy(c) {
	cero="0";
	now=new Date();
	anio=now.getFullYear();
	mes=now.getMonth()+1;
	dia=now.getDate();
	if (mes<10) mes=cero.concat(mes);
	if (dia<10) dia=cero.concat(dia);
	hoy=anio+"-"+mes+"-"+dia;
	c.value=hoy;
}

function makeArray(n){
  this.length = n;
  for (i=1;i<=n;i++){
    this[i]=0;
  }
  return this;
}

function escribirHoyLargo() {
  var this_month = new makeArray(12);
  this_month[0]  = "Enero";
  this_month[1]  = "Febrero";
  this_month[2]  = "Marzo";
  this_month[3]  = "Abril";
  this_month[4]  = "Mayo";
  this_month[5]  = "Junio";
  this_month[6]  = "Julio";
  this_month[7]  = "Agosto";
  this_month[8]  = "Septiembre";
  this_month[9]  = "Octubre";
  this_month[10] = "Noviembre";
  this_month[11] = "Deciembre";

  var this_day_e = new makeArray(7);
  this_day_e[0]  = "Domingo";
  this_day_e[1]  = "Lunes";
  this_day_e[2]  = "Martes";
  this_day_e[3]  = "Miércoles";
  this_day_e[4]  = "Jueves";
  this_day_e[5]  = "Viernes";
  this_day_e[6]  = "Sábado";

  var today = new Date();
  var day   = today.getDate();
  var month = today.getMonth();
  var year  = today.getYear();
  var dia = today.getDay();
    if (year < 1000) {
       year += 1900; }
  return( " " + this_day_e[dia] + ", " + day + " de " + this_month[month] + " " + year);
}

/************************************************************************************
FUNCIONES DE CONSTRUCCIÓN DE ELEMENTOS DE INTERFAZ
************************************************************************************/
var nn=document.layers?true:false;
var N6=navigator.userAgent.toLowerCase().indexOf("gecko")!=-1?true:false
var op=navigator.userAgent.toLowerCase().indexOf("opera")!=-1?true:false
var menu_top=0;
var homekeylayer=null;
var menus = new Array();
function construirMenu(topmargin,leftmargin,menuwidth,inicio) {
	menu_top=topmargin;
	var MenuLength=menuwidth*voci.length+2*voci.length-18;
	var BrowserWidth=nn||op?window.innerWidth:N6?document.width:document.body.clientWidth;
	str_menu="<div id=barra  class=barramenu style='top:"+eval(topmargin)+";'></div>";
	str_menu+="<DIV ID='home' STYLE='position:absolute;top:"+eval(topmargin+2)+";left:"+eval(leftmargin-28)+";width:16;height:17;cursor:hand' CLASS='menuIEb'><a href=\""+inicio+"\"><img src=\"../img/tabhome1.gif\" title=\"INICIO\" border=0></a></DIV>";
	for (i=0; i<tabs.length; i++){
		str_menu+="<DIV ID='top_"+i+"' class='menus' STYLE='top:"+eval(topmargin+2)+";left:"+eval(leftmargin+i*menuwidth+0*i)+";width:"+menuwidth+";' onMouseOver=\"menus["+i+"].visibility='visible';overMenu(this);\" onMouseOut=\"menus["+i+"].visibility='hidden';outMenu(this);\"><span class='menuslabel'>"+tabs[i]+"</span></DIV>";
		str_menu+="<DIV ID='menu"+i+"' class='skinmenu' STYLE='position:absolute;top:"+eval(21+topmargin)+";left:"+eval(leftmargin+i*menuwidth+0*i)+";width:"+menuwidth+";visibility:hidden;z-index:10;' onMouseOver=\"menus["+i+"].visibility='visible';\" onMouseOut=\"menus["+i+"].visibility='hidden';\" >";
		for (j=0; j<voci.length; j++)
			if(voci[i][j]!=undefined) str_menu+="<div class=menuitems url=\"javascript:"+links[i][j]+"\" onMouseOver='highlightie(this);' onMouseOut='lowlightie(this);' onClick='jumptoie(this);' title=\""+ttt[i][j]+"\"><img src=\"../img/menu/"+icons[i][j]+"\" align=absmiddle>&nbsp;&nbsp;"+voci[i][j]+"</div>";
		str_menu+="</div>";
	}
	str_menu+="<DIV ID='homekey' STYLE='position:absolute;top:"+topmargin+";left:"+eval(leftmargin+i*menuwidth+12*i+menuwidth)+";width:16;height:17;cursor:hand;z-index:10' CLASS='menuIEb'></DIV>";
	document.write(str_menu);
	N6?setTimeout("LeggiLivelli()",50):LeggiLivelli();
}
function LeggiLivelli(){
	for (i=0; i<tabs.length; i++)
		N6?menus[i]=document.getElementById('menu'+i).style:menus[i]=eval(document.all["menu"+i].style);
	N6?homekeylayer=document.getElementById('homekey').style:homekeylayer=eval(document.all.homekey.style);
}
function construirToolbar(){
	document.write("<div id=toolbar class=toolbar style='top:"+eval(menu_top+25)+";'>");
	for (i=0; i<tabs.length; i++){
		for (j=0; j<voci.length; j++)
			if (toolbar[i][j]==1)
				document.write("<span class=icono onMouseOver=\"enfocarIcono(this,'over'); ponerMsgBarraEstado('"+ttt[i][j]+"');\" onMouseOut=\"enfocarIcono(this,'out'); ponerMsgBarraEstado('&nbsp;');\" onMouseDown=\"enfocarIcono(this,'down')\" onMouseUp=\"enfocarIcono(this,'up'); "+links[i][j]+"\"><img src=\"../img/menu/"+icons[i][j]+"\" hspace=2 title=\""+ttt[i][j]+"\" align=absmiddle border=0></span>")
		document.write("<img src='../img/hseparador.gif' hspace=5 align=absmiddle>");
	}
	document.write("</div>");
}
function confirmarSalir(){
	if (confirm("¿Desea salir de la aplicación?")){
		location.href="close.php?p=app";
	}
}
function confirmarCambioSesion(){
	if (confirm("¿Desea salir de la sesión actual e ingresar de nuevo con otro usuario?")){
		location.href="close.php?p=sesion";
	}
}
function checkCambiarAcceso(f){
	if(f.pass_old_2.value==""){
		alert ("Ingrese su contraseña actual.");
		f.pass_old_2.focus();
		return;
	} else {
		if(f.pass_old_2.value!=f.pass_old_1.value) {
			alert ("Su contraseña actual no coincide con la registrada en el sistema. Por favor ingrese de nuevo su contraseña actual.");
			f.pass_old_2.select();
			return;
		}
	}
	if(f.pass_new_1.value==""){
		alert ("Ingrese su contraseña nueva.");
		f.pass_new_1.focus();
		return;
	} else {
		if(f.pass_new_2.value!=f.pass_new_1.value) {
			alert ("Su contraseña nueva y su correspondiente confirmación no coinciden. Por favor ingrese de nuevo su contraseña nueva.");
			f.pass_new_2.value="";
			f.pass_new_1.value="";
			f.pass_new_1.focus();;
			return;
		}
	}
	f.submit();
}
function ponerMsgBarraEstado(msg) {
	document.all["statusbar"].innerHTML=msg;
}
/************************************************************************************
FUNCIONES DE CONTROL DE FICHAS DE TABPANE
************************************************************************************/
// This function is used to define if the browser supports the needed
// features
function hasSupport() {

	if (typeof hasSupport.support != "undefined")
		return hasSupport.support;
	
	var ie55 = /msie 5\.[56789]/i.test( navigator.userAgent );
	
	hasSupport.support = ( typeof document.implementation != "undefined" &&
			document.implementation.hasFeature( "html", "1.0" ) || ie55 )
			
	// IE55 has a serious DOM1 bug... Patch it!
	if ( ie55 ) {
		document._getElementsByTagName = document.getElementsByTagName;
		document.getElementsByTagName = function ( sTagName ) {
			if ( sTagName == "*" )
				return document.all;
			else
				return document._getElementsByTagName( sTagName );
		};
	}

	return hasSupport.support;
}

///////////////////////////////////////////////////////////////////////////////////
// The constructor for tab panes
//
// el : HTMLElement		The html element used to represent the tab pane
// bUseCookie : Boolean	Optional. Default is true. Used to determine whether to us
//						persistance using cookies or not
//
function WebFXTabPane( el, bUseCookie ) {
	if ( !hasSupport() || el == null ) return;
	
	this.element = el;
	this.element.tabPane = this;
	this.pages = [];
	this.selectedIndex = null;
	this.useCookie = bUseCookie != null ? bUseCookie : true;
	
	// add class name tag to class name
	this.element.className = this.classNameTag + " " + this.element.className;
	
	// add tab row
	this.tabRow = document.createElement( "div" );
	this.tabRow.className = "tab-row";
	el.insertBefore( this.tabRow, el.firstChild );

	var tabIndex = 0;
	if ( this.useCookie ) {
		tabIndex = Number( WebFXTabPane.getCookie( "webfxtab_" + this.element.id ) );
		if ( isNaN( tabIndex ) )
			tabIndex = 0;
	}
	this.selectedIndex = tabIndex;
	
	// loop through child nodes and add them
	var cs = el.childNodes;
	var n;
	for (var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab-page") {
			this.addTabPage( cs[i] );
		}
	}
}

WebFXTabPane.prototype.classNameTag = "dynamic-tab-pane-control";

WebFXTabPane.prototype.setSelectedIndex = function ( n ) {
	if (this.selectedIndex != n) {
		if (this.selectedIndex != null && this.pages[ this.selectedIndex ] != null )
			this.pages[ this.selectedIndex ].hide();
		this.selectedIndex = n;
		this.pages[ this.selectedIndex ].show();
		
		if ( this.useCookie )
			WebFXTabPane.setCookie( "webfxtab_" + this.element.id, n );	// session cookie
	}
};
	
WebFXTabPane.prototype.getSelectedIndex = function () {
	return this.selectedIndex;
};
	
WebFXTabPane.prototype.addTabPage = function ( oElement ) {
	if ( !hasSupport() ) return;
	
	if ( oElement.tabPage == this )	// already added
		return oElement.tabPage;

	var n = this.pages.length;
	var tp = this.pages[n] = new WebFXTabPage( oElement, this, n );
	tp.tabPane = this;
	
	// move the tab out of the box
	this.tabRow.appendChild( tp.tab );
			
	if ( n == this.selectedIndex )
		tp.show();
	else
		tp.hide();
		
	return tp;
};
	
WebFXTabPane.prototype.dispose = function () {
	this.element.tabPane = null;
	this.element = null;		
	this.tabRow = null;
	
	for (var i = 0; i < this.pages.length; i++) {
		this.pages[i].dispose();
		this.pages[i] = null;
	}
	this.pages = null;
};



// Cookie handling
WebFXTabPane.setCookie = function ( sName, sValue, nDays ) {
	var expires = "";
	if ( nDays ) {
		var d = new Date();
		d.setTime( d.getTime() + nDays * 24 * 60 * 60 * 1000 );
		expires = "; expires=" + d.toGMTString();
	}

	document.cookie = sName + "=" + sValue + expires + "; path=/";
};

WebFXTabPane.getCookie = function (sName) {
	var re = new RegExp( "(\;|^)[^;]*(" + sName + ")\=([^;]*)(;|$)" );
	var res = re.exec( document.cookie );
	return res != null ? res[3] : null;
};

WebFXTabPane.removeCookie = function ( name ) {
	setCookie( name, "", -1 );
};








///////////////////////////////////////////////////////////////////////////////////
// The constructor for tab pages. This one should not be used.
// Use WebFXTabPage.addTabPage instead
//
// el : HTMLElement			The html element used to represent the tab pane
// tabPane : WebFXTabPane	The parent tab pane
// nindex :	Number			The index of the page in the parent pane page array
//
function WebFXTabPage( el, tabPane, nIndex ) {
	if ( !hasSupport() || el == null ) return;
	
	this.element = el;
	this.element.tabPage = this;
	this.index = nIndex;
	
	var cs = el.childNodes;
	for (var i = 0; i < cs.length; i++) {
		if (cs[i].nodeType == 1 && cs[i].className == "tab") {
			this.tab = cs[i];
			break;
		}
	}
	
	// insert a tag around content to support keyboard navigation
	
	
	var a = document.createElement( "A" );
	this.aElement = a;
	a.href = "#";
	a.onclick = function () { return false; };
	while ( this.tab.hasChildNodes() )
		a.appendChild( this.tab.firstChild );
	this.tab.appendChild( a );

	
	// hook up events, using DOM0
	var oThis = this;
	this.tab.onclick = function () { oThis.select(); };
	this.tab.onmouseover = function () { WebFXTabPage.tabOver( oThis ); };
	this.tab.onmouseout = function () { WebFXTabPage.tabOut( oThis ); };
}

WebFXTabPage.prototype.show = function () {
	var el = this.tab;
	var s = el.className + " selected";
	s = s.replace(/ +/g, " ");
	el.className = s;
	
	this.element.style.display = "block";
};

WebFXTabPage.prototype.hide = function () {
	var el = this.tab;
	var s = el.className;
	s = s.replace(/ selected/g, "");
	el.className = s;

	this.element.style.display = "none";
};
	
WebFXTabPage.prototype.select = function () {
	this.tabPane.setSelectedIndex( this.index );
};
	
WebFXTabPage.prototype.dispose = function () {
	this.aElement.onclick = null;
	this.aElement = null;
	this.element.tabPage = null;
	this.tab.onclick = null;
	this.tab.onmouseover = null;
	this.tab.onmouseout = null;
	this.tab = null;
	this.tabPane = null;
	this.element = null;
};

WebFXTabPage.tabOver = function ( tabpage ) {
	var el = tabpage.tab;
	var s = el.className + " hover";
	s = s.replace(/ +/g, " ");
	el.className = s;
};

WebFXTabPage.tabOut = function ( tabpage ) {
	var el = tabpage.tab;
	var s = el.className;
	s = s.replace(/ hover/g, "");
	el.className = s;
};


// This function initializes all uninitialized tab panes and tab pages
function setupAllTabs() {
	if ( !hasSupport() ) return;

	var all = document.getElementsByTagName( "*" );
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var tabPageRe = /tab\-page/;
	var cn, el;
	var parentTabPane;
	
	for ( var i = 0; i < l; i++ ) {
		el = all[i]
		cn = el.className;

		// no className
		if ( cn == "" ) continue;
		
		// uninitiated tab pane
		if ( tabPaneRe.test( cn ) && !el.tabPane )
			new WebFXTabPane( el );
	
		// unitiated tab page wit a valid tab pane parent
		else if ( tabPageRe.test( cn ) && !el.tabPage &&
					tabPaneRe.test( el.parentNode.className ) ) {
			el.parentNode.tabPane.addTabPage( el );			
		}
	}
}

function disposeAllTabs() {
	if ( !hasSupport() ) return;
	
	var all = document.getElementsByTagName( "*" );
	var l = all.length;
	var tabPaneRe = /tab\-pane/;
	var cn, el;
	var tabPanes = [];
	
	for ( var i = 0; i < l; i++ ) {
		el = all[i]
		cn = el.className;

		// no className
		if ( cn == "" ) continue;
		
		// tab pane
		if ( tabPaneRe.test( cn ) && el.tabPane )
			tabPanes[tabPanes.length] = el.tabPane;
	}
	
	for (var i = tabPanes.length - 1; i >= 0; i--) {
		tabPanes[i].dispose();
		tabPanes[i] = null;
	}
}


// initialization hook up

// DOM2
if ( typeof window.addEventListener != "undefined" )
	window.addEventListener( "load", setupAllTabs, false );

// IE 
else if ( typeof window.attachEvent != "undefined" ) {
	window.attachEvent( "onload", setupAllTabs );
	window.attachEvent( "onunload", disposeAllTabs );
}

else {
	if ( window.onload != null ) {
		var oldOnload = window.onload;
		window.onload = function ( e ) {
			oldOnload( e );
			setupAllTabs();
		};
	}
	else 
		window.onload = setupAllTabs;
}



/*********************************************************************************************************
DRAG JS
*********************************************************************************************************/
function Browser() {
  var ua, s, i;
  this.isIE    = false;
  this.isNS    = false;
  this.version = null;
  ua = navigator.userAgent;
  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }
  // Treat any other "Gecko" browser as NS 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();
// Global object to hold drag information.
var dragObj = new Object();
dragObj.zIndex = 0;

function dragStart(event, id) {
  var el;
  var x, y;
  // If an element id was given, find it. Otherwise use the element being
  // clicked on.
  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;
    // If this is a text node, use its parent element.
    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }
  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  // Save starting positions of cursor and element.
  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);
  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;
  // Update element's z-index.
  dragObj.elNode.style.zIndex = ++dragObj.zIndex;
  // Capture mousemove and mouseup events on the page.
  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",	dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}
function dragGo(event) {
  var x, y;
  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  // Move drag element by the same amount the cursor has moved.
  dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
  dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";
  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}
function dragStop(event) {
  // Stop capturing mousemove and mouseup events.
  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",	dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,	true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}
/*********************************************************************************************************
AJAX XML/HTTP
*********************************************************************************************************/
var isIExp = false;
var req;
var div_contenedor;
function cargaXML(url) {
    if(url==''){return;}
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = processReqChange;
        req.open("GET", url, true);
        req.send(null);
    } else if (window.ActiveXObject) {
        isIExp = true;
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = processReqChange;
            req.open("GET", url, true);
            req.send();
        }
    }
}
function processReqChange(){
    var detalles = document.getElementById(div_contenedor);
    if(req.readyState == 4){
        detalles.innerHTML = req.responseText;
    } else {
        detalles.innerHTML = '<table cellpadding=0 cellspacing=0 border=1 width=100% height=100%><tr><td align=center valign=middle><img src="../img/cargando2.gif" align="absmiddle">Cargando...</td></tr></table>';
    }
}

/*********************************************************************************************************
RICO BOX
*********************************************************************************************************/
var saveHeight=new Array();
var showing=new Array();
var effectDone=new Array();
function rico_verCaja(event,caja,tit,w,h,f,ico,msg) {
	dragObj.elNode = document.getElementById(caja);
	dragObj.elNode.style.zIndex = ++dragObj.zIndex;
	toggleEffect(event,caja, -1, -1, w, h, 500, 30, msg);
	var icono=$(caja+'_icon');
	if(ico==undefined || ico==null || ico=="") ico="../img/cajas/app.gif";
	$(icono).src=ico;
	$(icono).title=tit;
	var titulo=$(caja+'_titulo');
	$(titulo).innerHTML=tit;
	var contenido=$(caja+'_detalles');
	$(contenido).style.height=h-27;
	div_contenedor=caja+'_detalles';
	cargaXML(f);
}
function rico_ocultarCaja(id){
	div_contenedor=id+'_detalles';
	cargaXML("blank.html")
	resetEffect(id);
}
function toggleFade(obj, a, ms, s) {
	new Rico.Effect.FadeTo(obj, a, ms, s);
}
function toggleEffect(event, obj, x, y, w, h, ms, s, msg) {
	// if ( !effectDone ) {
		startEffect(event, obj, x, y, w, h, ms, s, msg);
		effectDone[obj]=true;
		// effectDone = true;
	// } else {
		// resetEffect(obj);
	// }
}
function startEffect(event, obj, x, y, w, h, ms, s, msg) {
	// alert("CAJA: "+obj+" efecto: "+effectDone[obj]);
	if(effectDone[obj]==false){
		if(event==null || event==undefined || event==null){
			mx = screen.width/2;
			my = screen.height/2;
		} else {
			if (browser.isIE) {
				mx = window.event.clientX + document.documentElement.scrollLeft + document.body.scrollLeft;
				my = window.event.clientY + document.documentElement.scrollTop + document.body.scrollTop;
			}
			if (browser.isNS) {
				mx = event.clientX + window.scrollX;
				my = event.clientY + window.scrollY;
			}
		}
	} else {
			mx=$(obj).offsetLeft;
			my=$(obj).offsetTop;
	}
	$(obj).style.left=mx;
	$(obj).style.top=my;
	var contenido = $(obj+'_detalles');
	$(contenido).style.visibility= "visible";
	$(obj).style.visibility = "visible";
	if(x==-1) x=screen.width/2-w/2;
	if(y==-1) y=screen.height/2-h/2-70;
	new Rico.Effect.SizeAndPosition( $(obj), x, y, w, h, ms, s, {complete:function() {setStatus(msg,2000);}} );
	new Rico.Effect.FadeTo( obj, 1, ms, s, {complete:function() {setStatus(msg,2000);}} );
}
function setStatus(s,n) {
	if(s!="" && s!=null && s!=undefined){
		$('statusMsg').style.visibility = "visible";
		$('statusMsg').innerHTML = "&nbsp;&nbsp;&nbsp;"+s;
		roundCorners('statusMsg');
		setTimeout( "$('statusMsg').style.visibility = 'hidden';", n );
	}
}
function resetEffect(obj) {
	new Rico.Effect.SizeAndPosition( $(obj), 1, 600, 10, 10, 500, 30);
	new Rico.Effect.FadeTo( obj, 0, 200, 25);
	effectDone[obj]=false;
}
function toggleSlide(id, id_btn) {
	if (showing[id]){
		slideMenuUp(id, id_btn);
		showing[id]= false;
	} else {
		slideMenuDown(id, id_btn); 
		showing[id]= true; 
	}
}
function slideMenuUp(id, id_btn) {
	var menu = $(id);
	saveHeight[id] = menu.offsetHeight;
	menu.style.overflow = "hidden";
	new Rico.Effect.Size( menu, null, 26, 120, 8 );
	$(id_btn).innerHTML = "<img src='../img/desplegar.gif' title='desplegar' hspace=1 border=0>";
}
function slideMenuDown(id, id_btn) {
	var menu = $(id);
	new Rico.Effect.Size( menu, null, saveHeight[id], 120, 8, {complete:function() { $(menu).style.overflow = "visible"; }} );
	$(id_btn).innerHTML = "<img src='../img/replegar.gif' title='replegar' hspace=1 border=0>";
	var contenido = $(id+'_detalles');
	$(contenido).style.overflow = "auto";
}


