/************************************************************************************
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 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();
	}
}
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';
}
function ponerOntop(caja){
	iframes[caja].style.zIndex=DIF_highestZIndex++;
}
function verCaja(caja,t,w,h,f) {
	eval(caja+".titbar.document.all[\"titulo\"].innerHTML=t");
	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 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() {
	if (event.srcElement.className == "menus") {
		event.srcElement.style.border = "1 inset buttonhighlight";
		event.srcElement.style.cursor = "hand";
	}
}
function outMenu() {
	if (event.srcElement.className == "menus") {
		event.srcElement.style.border = "";
		event.srcElement.style.cursor = "default";
	}
}
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 highlightie5() {
	if (event.srcElement.className == "menuitems") {
		event.srcElement.style.backgroundColor = "highlight";
		event.srcElement.style.color = "HighlightText";
		if (display_url) window.status = event.srcElement.url;
		//ponerMsgBarraEstado(event.srcElement.title);
	}
}
function lowlightie5() {
	if (event.srcElement.className == "menuitems") {
		event.srcElement.style.backgroundColor = "";
		event.srcElement.style.color = "MenuText";
		window.status = "";
		//ponerMsgBarraEstado('&nbsp;');
	}
}
function jumptoie5() {
	if (event.srcElement.className == "menuitems") {
		if (event.srcElement.getAttribute("target") != null)
			window.open(event.srcElement.url, event.srcElement.getAttribute("target"));
		else
			window.location = event.srcElement.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;
	document.writeln("<div id=barra style='position:absolute;top:"+eval(topmargin)+";left:0;width:100%;height:25;' class=barramenu></div>");
	document.writeln("<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 in tabs){
		document.writeln("<DIV ID='top"+tabs[i]+"' STYLE='position:absolute;top:"+eval(topmargin+2)+";left:"+eval(leftmargin+i*menuwidth+0*i)+";width:"+menuwidth+";' onMouseOver=\"menus["+i+"].visibility='visible';overMenu();\" onMouseOut=\"menus["+i+"].visibility='hidden';outMenu();\" CLASS='menus'>"+tabs[i]+"</DIV>");
		document.writeln("<DIV ID='menu"+i+"' STYLE='position:absolute;top:"+eval(21+topmargin)+";left:"+eval(leftmargin+i*menuwidth+0*i)+";width:"+menuwidth+";visibility:hidden;z-index:10;' CLASS='skinmenu'  onMouseOver=\"menus["+i+"].visibility='visible';highlightie5();\" onMouseOut=\"menus["+i+"].visibility='hidden';lowlightie5();\" onClick=\"jumptoie5();\">");
		for (j in voci[i])
			document.writeln("<div class=menuitems url=\"javascript:"+links[i][j]+"\" title=\""+ttt[i][j]+"\"><img src=\"../img/menu/"+icons[i][j]+"\" align=absmiddle>&nbsp;&nbsp;"+voci[i][j]+"</div>")
		document.writeln("</div>")
	}
	document.writeln("<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>");
	N6?setTimeout("LeggiLivelli()",50):LeggiLivelli();
}
function LeggiLivelli(){
	for (i in tabs)
		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.writeln("<span id=toolbar style='position:absolute;top:"+eval(menu_top+25)+";left:0;width:100%;' class=toolbar>");
	for (i in tabs){
		for (j in voci[i])
			if (toolbar[i][j]==1)
				document.writeln("<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')\" onClick=\"javascript:"+links[i][j]+"\"><img src=\"../img/menu/"+icons[i][j]+"\" vspace=6 title=\""+ttt[i][j]+"\"></span>")
		document.writeln("<img src=\"../img/hseparador.gif\">");
	}
	document.writeln("</span>");
}
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;
}