/*
---------------------------------------------------------------------
File..........: ventanas.js
Author........: Victor Rivas Santos (vrivas@ujaen.es)
		Dpto. de Informática
		Universidad de Jaén
		EPS de Jaén, Avda de Madrid 35
		E23071, Jaen (Spain)
Date..........: 08-Nov-2000		
Description...: Some functions to draw windows in a web page.
MOdifications.:
============= 1 =============
  Author......:
  Date........:
  Description.:
---------------------------------------------------------------------
*/
var VENTANA_LINEA=0;
var VENTANA_LISTA=1;
var VENTANA_BR=2;
var VENTANA_PLANO=3;
var VENTANA_UNA_LINEA=4;
var VENTANA_CASCADA=5;
var VENTANA_CASCADA_2=6;
var VENTANA_TAB=7;
var VENTANA_DD=8;
var VENTANA_NO_VENTANA=9;

var VENTANA_SEPARADOR="SEPARATOR";

/**
* Redefinición de write
*/
function w( algo ) {
  document.write( algo );
}

/**
* Redefinición de writeln
*/
function wln( algo ) {
  document.writeln( algo );
}


/**
* Objeto seccion
*/
function Seccion( _texto, _url ) {
  this.texto=_texto;
  this.url=_url;
}

/**
* Objeto ventana
*/
function Ventana( _imagen, _img_width, _img_height,
	_titulo, 
	_url_titulo,
	_width, 
	_height, 
        _valign,
	_color_titulo,
	_fondo_titulo, 
	_color_secciones,
	_fondo_secciones,
	_cellpadding_titulo,
	_cellpadding_fondo ) {

  // Ventana's Properties

  this.imagen=_imagen;
  this.img_width=_img_width;
  this.img_height=_img_height;
  this.titulo=_titulo;
  this.url_titulo=_url_titulo;
  this.width=_width;
  this.height=_height;
  this.valign=_valign;
  this.color_titulo=_color_titulo;
  this.fondo_titulo=_fondo_titulo;
  this.color_secciones=_color_secciones;
  this.fondo_secciones=_fondo_secciones;
  this.cellpadding_titulo=_cellpadding_titulo;
  this.cellpadding_fondo=_cellpadding_fondo;
  this.secciones=new Array;
  this.urls=new Array;
  

  // Ventana's methods

  this.show=ventana_show;
  this.una_linea=ventana_una_linea;
  this.no_ventana=ventana_no_ventana;
  this.addSection=ventana_add_section;
  this.newSection=ventana_new_section;
  this.addSeparator=ventana_add_separator;
} // function ventana




/**
* Método Ventana_show
*/
function ventana_show( MODO ) {
  if ( MODO==VENTANA_UNA_LINEA ) {
	this.una_linea();
	return;
  }
  if ( MODO==VENTANA_NO_VENTANA ) {
  	this.no_ventana();
	return;
  }
  // 1. Creo la primera tabla
  w( "<TABLE CELLPADDING="+this.cellpadding_titulo+" CELLSPACING=0 BORDER=0" );
  if ( this.width!="" ) {
    w( " WIDTH="+this.width );
  }
  wln( ">" );


  // 2. Esta tabla tiene 2 TRs. Este es el primero
  wln( "<TR>" );
  if( this.fondo_titulo ) {
    wln( "<TD BGCOLOR='"+this.fondo_titulo+"'>" );
  } else {
    wln( "<TD>" );
  }
  wln( "<FONT COLOR="+this.color_titulo+">" );
  if( this.imagen ) {
    w( "<IMG SRC="+this.imagen+" WIDTH="+this.img_width+
         " HEIGHT="+this.img_height+" ALIGN=top>" );
  }
  wln( "<div style='margin-left: "+this.cellpadding_fondo+"px; margin-top: "+this.cellpadding_fondo+"px;"+
  	"margin-right: "+this.cellpadding_fondo+"px; margin-bottom: "+this.cellpadding_fondo+"px;'" );
  if ( this.url_titulo!="" ) {
    wln( this.titulo.link( this.url_titulo ) );
  } else {
    wln( this.titulo ); 
  }
  wln( "</DIV>" );
  wln( "</TD>" );
  wln( "</TR>" );
 
  // 3. Este es el segundo TR de la primera tabla.
  //    Este TR incluye otra tabla
  wln( "<TR>" );
  if( this.fondo_titulo ) {
    wln( "<TD BGCOLOR='"+this.fondo_titulo+"'>" );
  } else {
    wln( "<TD>" );
  }

  // 4. Comienza la 2ª tabla
  w( "<TABLE CELLPADDING="+this.cellpadding_fondo+" CELLSPACING=0 BORDER=0 WIDTH=100%" );
  if ( this.height!="" ) {
    w( " HEIGHT="+this.height );
  }
  wln( ">" );
  wln( "<TR>" );
  if( this.fondo_secciones ) {
    wln( "<TD BGCOLOR='"+this.fondo_secciones+"' " );
  } else {
    wln( "<TD " );
  }

  if ( this.valign!="" ) {
    w( " VALIGN="+this.valign );
  }
  wln( ">" );

  // Relleno de las opciones
  if ( MODO==VENTANA_LINEA) {
      show_options_as_LINEA( this,", " );
  } else if ( MODO==VENTANA_LISTA ) {
      show_options_as_LISTA( this );
  } else if ( MODO==VENTANA_PLANO ) {
      show_options_as_PLANO( this );
  } else if ( MODO==VENTANA_CASCADA ) {
      show_options_as_CASCADA( this );
  } else if ( MODO==VENTANA_CASCADA_2 ) {
      show_options_as_CASCADA_2( this );
  } else if ( MODO==VENTANA_TAB ) {
      show_options_as_TAB( this );
  } else if ( MODO==VENTANA_DD ) {
      show_options_as_DD( this );
  } else if ( MODO==VENTANA_BR ) {
      show_options_as_BR( this );
  }

  wln( "</TD>" );
 
  // 5. Fin de la segunda tabla
  wln( "</TR>" );
  wln( "</TABLE>" );

  // 6. Fin de la primera tabla
  wln( "</TD>" );
  wln( "</TR>" );
  wln( "</TABLE>" );
} // function ventana_show

/**
* Método ventana_una_linea:
* 	Muestra las opciones de la ventana en formato de una sola línea,
*	en el título
*/
function ventana_una_linea() {
  // 1. Creo la primera tabla
  w( "<TABLE CELLPADDING="+this.cellpadding_titulo+" CELLSPACING=0 BORDER=0" );
  if ( this.width!="" ) {
    w( " WIDTH="+this.width );
  }
  wln( ">" );


  // 2. Esta tabla tiene 2 TRs. Este es el primero
  wln( "<TR>" );
  wln( "<TD BGCOLOR='"+this.fondo_titulo+"'>" );
  wln( "<FONT COLOR="+this.color_titulo+">" );
  if( this.imagen ) {
    w( "<IMG SRC="+this.imagen+" WIDTH="+this.img_width+
         " HEIGHT="+this.img_height+" ALIGN=top>" );
  }
  if ( this.url_titulo!="" ) {
    wln( this.titulo.link( this.url_titulo ) );
  } else {
    wln( this.titulo ); 
  }
  if( this.secciones.length ) {
    wln( ":" );
  }
  wln( "</FONT>" );
 show_options_as_LINEA( this," - " )
  wln( "</TD>" );
  wln( "</TR>" );
  wln( "</TABLE>" );

} // ventana_UNA_LINEA

/**
* Método show_options_as_LINEA:
* 	Muestra las opciones de la ventana en formato de una sola línea,
*	separada por comas.	
*/
function show_options_as_LINEA( vent, _sep ) {
 for( var i=0; i<vent.secciones.length; ++i ) {
    w( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	w( "<BR>" );
    } else {
       if( vent.urls[i]!="" ) {
         w( vent.secciones[i].link( vent.urls[i] ) );
       } else {
         w( vent.secciones[i] );
       }
       if( i<vent.secciones.length-1 ) {
   	 w( _sep );
       }
       wln( "</FONT>" );
     }
  }
} // show_options_as_LINEA

/**
* Método show_options_as_LISTA:
* 	Muestra las opciones de la ventana en formato de varias líneas.
*/

function show_options_as_LISTA( vent ) {
  wln( "<FONT COLOR="+vent.color_secciones+">" );
  wln( "<UL>" );
  for( var i=0; i<vent.secciones.length; ++i ) {
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	wln( "<HR WIDTH=25% ALIGN=left NOSHADE>" );
    } else {
       wln( "<LI>" );
  	<!-- PASAR la PRIMERA A MAYUSCULAS -->
       var tmpCad=( vent.secciones[i].substr( 0,1 ) )+
		    vent.secciones[i].substr( 1, vent.secciones[i].length );
       if( vent.urls[i]!="" ) {
         w( tmpCad.link( vent.urls[i] ) );
       } else {
         w( tmpCad );
       }
       wln( "</LI>" );
    }
  }
  wln( "</FONT>" );
  wln( "</UL>" );

} // show_options_qlista


function show_options_as_LISTA2( vent ) {
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
  wln( "<UL>" );
  for( var i=0; i<vent.secciones.length; ++i ) {
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	wln( "<HR WIDTH=25% ALIGN=left NOSHADE>" );
    } else {
       wln( "<LI>" );
  	<!-- PASAR la PRIMERA A MAYUSCULAS -->
       var tmpCad=( vent.secciones[i].substr( 0,1 ) )+
		    vent.secciones[i].substr( 1, vent.secciones[i].length );
       if( vent.urls[i]!="" ) {
         w( tmpCad.link( vent.urls[i] ) );
       } else {
         w( tmpCad );
       }
       wln( "</LI>" );
    }
  }
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
  wln( "</UL>" );

} // show_options_as_lista2

/**
* Método show_options_as_PLANO:
* 	Muestra las opciones tal cuales.
*/
function show_options_as_PLANO( vent ) {
 for( var i=0; i<vent.secciones.length; ++i ) {
    w( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	w( "<BR><BR>" );
    } else {
       if( vent.urls[i]!="" ) {
         w( vent.secciones[i].link( vent.urls[i] ) );
       } else {
         w( vent.secciones[i] );
       }
       wln( "</FONT>" );
    }
  }
} // show_options_as_LINEA

/**
* Método show_options_as_CASCADA:
*   Muestra las opciones de la ventana en formato de varias líneas indentadas
*/

function show_options_as_CASCADA( vent ) {
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
  var cad=tabulador="&nbsp;&nbsp;";

  for( var i=0; i<vent.secciones.length; ++i ) {
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	wln( "<HR WIDTH=25% ALIGN=left NOSHADE>" );
    } else {
       wln( cad );
  	<!-- PASAR la PRIMERA A MAYUSCULAS -->
       var tmpCad=( vent.secciones[i].substr( 0,1 ) )+
		    vent.secciones[i].substr( 1, vent.secciones[i].length );
       if( vent.urls[i]!="" ) {
         w( tmpCad.link( vent.urls[i] ) );
       } else {
         w( tmpCad );
       }
       cad+=tabulador;

       wln( "<BR>");
    }
  }
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );


} // show_options_as_CASCADA

/**
* Método show_options_as_CASCADA_2:
*   Muestra las opciones de la ventana en formato de varias líneas indentadas
*/

function show_options_as_CASCADA_2( vent ) {
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
  var cad=tabulador="&nbsp;&nbsp;";
  for( var i=0; i<vent.secciones.length; ++i ) {
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	wln( "<HR WIDTH=25% ALIGN=left NOSHADE>" );
    } else {
       wln( cad );
  	<!-- PASAR la PRIMERA A MAYUSCULAS -->
       var tmpCad=( up_char( vent.secciones[i].substr( 0,1 ) ) )+
		    ( vent.secciones[i].substr( 1, vent.secciones[i].length ) );
       if( vent.urls[i]!="" ) {
         w( tmpCad.link( vent.urls[i] ) );
       } else {
         w( tmpCad );
       }
       cad+=cad;
       wln( "<BR>");
    }
  }
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );


} // show_options_as_CASCADA_2

/**
* Método show_options_as_TAB:
*   Muestra las opciones de la ventana en formato de varias líneas indentadas 
* con indentación fija
*/

function show_options_as_TAB( vent ) {
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
  var cad=tabulador="&nbsp;&nbsp;";
  for( var i=0; i<vent.secciones.length; ++i ) {
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	wln( "<HR WIDTH=25% ALIGN=left NOSHADE>" );
    } else {
      //wln( cad );
      wln( "<DIV class='tab'>" );
  	<!-- PASAR la PRIMERA A MAYUSCULAS -->
       var tmpCad=( up_char( vent.secciones[i].substr( 0,1 ) ) )+
		    ( vent.secciones[i].substr( 1, vent.secciones[i].length ) );
       if( vent.urls[i]!="" ) {
         w( tmpCad.link( vent.urls[i] ) );
       } else {
         w( tmpCad );
       }
      wln( "</DIV>" );
      //wln( "<BR>");
    }
  }
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );


} // show_options_as_TAB


/**
* Método show_options_as_BR:
*   Muestra las opciones de la ventana en formato de varias líneas indentadas 
* sin indentación 
*/

function show_options_as_BR( vent ) {
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
  var cad=tabulador="";
  for( var i=0; i<vent.secciones.length; ++i ) {
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	wln( "<HR WIDTH=25% ALIGN=left NOSHADE>" );
    } else {
       wln( cad );
  	<!-- PASAR la PRIMERA A MAYUSCULAS -->
       var tmpCad=( up_char( vent.secciones[i].substr( 0,1 ) ) )+
		    ( vent.secciones[i].substr( 1, vent.secciones[i].length ) );
       if( vent.urls[i]!="" ) {
         w( tmpCad.link( vent.urls[i] ) );
       } else {
         w( tmpCad );
       }

       wln( "<BR>");
    }
  }
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );


} // show_options_as_BR


/**
* Método show_options_as_DD:
*   Muestra las opciones de la ventana en formato de varias líneas indentadas 
* con indentación fija
*/

function show_options_as_DD( vent ) {
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );
  var cad=tabulador="&nbsp;&nbsp;";
  for( var i=0; i<vent.secciones.length; ++i ) {
    if( vent.secciones[i]==VENTANA_SEPARADOR ) { 
	wln( "<HR WIDTH=25% ALIGN=left NOSHADE>" );
    } else {
      wln( "<DD>" );
      <!-- PASAR la PRIMERA A MAYUSCULAS -->
      var tmpCad=( up_char( vent.secciones[i].substr( 0,1 ) ) )+
	 ( vent.secciones[i].substr( 1, vent.secciones[i].length ) );
      if( vent.urls[i]!="" ) {
	w( tmpCad.link( vent.urls[i] ) );
      } else {
	w( tmpCad );
      }
      wln( "</DD>");

    }
  }
  wln( "<FONT SIZE=-1 COLOR="+vent.color_secciones+">" );


} // show_options_as_DD


function ventana_no_ventana() {
  show_options_as_LISTA( this );
}

/**
* Método: ventana_new_section
* Añade un objeto de tipo Seccion
*/
function ventana_new_section( _section ) {
  this.secciones[this.secciones.length]=_section.texto;
  this.urls[this.urls.length]=_section.url;

}

/**
* Método: ventana_add_section
*/
function ventana_add_section( _section, _url ) {
  this.secciones[this.secciones.length]=_section;
  this.urls[this.urls.length]=_url;

}



/**
* Método: ventana_add_separator
*/
function ventana_add_separator() {
  this.secciones[this.secciones.length]=VENTANA_SEPARADOR;
  this.urls[this.urls.length]="";
}
