var
  Titulo = '';
  NAparatos = 0;
  Fecha = '';
  NPres = 0;
  

function bDatos(Num, FEnt, Tipo, Marca, Modelo, Serie, sRef, Estado, Telefono, Presupuesto, Notas) {
  this.Numero = Num;
  this.FEntrada = FEnt;
  this.Tipo = Tipo;
  this.Marca = Marca;
  this.Modelo = Modelo;
  this.Serie = Serie;
  this.sRef = sRef;
  this.Estado = Estado;
  this.Telefono = Telefono;
  this.Presupuesto = Presupuesto;
  this.Nota = Notas;
  this.ImprimeItem = ImprimeItem;
}

function ImprimeItem(linea) {
 if ((Form1.Tel.value == this.Telefono) || 
      ((Form1.Tel.value == this.sRef) && (this.sRef !=''))) {
  NAparatos +=1;
  with (parent.body.document) {
    if (NAparatos % 2 == 0)  
      writeln('<tr BGCOLOR="#E5E5E5">') ;
    else 
      writeln('<tr BGCOLOR="#ffffff">');
    if (this.Nota != '')
      writeln('<td><A HREF="javascript:Notas(\''+this.Nota+'\')"><IMG ID="Picture1" HEIGHT=17 WIDTH=17 SRC="./assets/images/notas.gif" BORDER=0></A></td>');
    else
      writeln('<td></td>');
    if (this.Presupuesto == 'S')
      writeln('<td><small><A HREF="javascript:MuestraPresupuesto(\''+this.Numero+'\')">'+this.Numero+'</A></small></td>');
    else
      writeln('<td><small>'+this.Numero+'</small></td>');
    writeln('<td><small>'+this.FEntrada+'</small></td>');
    writeln('<td><small>'+this.Tipo+'</small></td>');
    writeln('<td><small>'+this.Marca+'</small></td>');
    writeln('<td><small>'+this.Modelo+'</small></td>');
    writeln('<td><small>'+this.Serie+'</small></td>');
    writeln('<td><small>'+this.sRef+'</small></td>');
    writeln('<td><small>'+this.Estado+'</small></td>');
    writeln('</tr>');
  }
 }
}

function ImprimeCabecera() {
  with (parent.body.document) {
    open();
    writeln('<HTML>');
    writeln('<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">');
    writeln('<HEAD>');
    writeln('<SCRIPT LANGUAGE="JavaScript1.2">');
    writeln('<!--');
    writeln('function MuestraPresupuesto(N) {');
    writeln('  parent.header.Form1.FNumero.value = N;');
    writeln('  parent.header.Form1.FNumero.select();');
    writeln('}');
    writeln('function Notas(N) {');
    writeln('  alert(N);');
    writeln('}');
    writeln('//-->');
    writeln('</SCRIPT>');
    writeln('<FONT FACE="Verdana,Tahoma,Arial,Helvetica,sans-serif">');
    writeln('<TITLE>INFORME DE APARATOS</TITLE>');
    writeln('</HEAD>');
    writeln('<TITLE>INFORME DE APARATOS</TITLE>');
    writeln('<BODY BGCOLOR="#FFFFFF" ALINK="#ff00ff" LINK="#0000ff" VLINK="#ff0000"');
    writeln('STYLE="height: 100%; width: 100%; background-attachment:fixed;background-repeat:repeat;"');
    writeln('BACKGROUND="fondo.jpg">');
    writeln('<h5 align=right>' + Fecha + '</h5>');
    writeln('<p>');
    writeln('<h3 align=center>' + Titulo + '</h3>');
    writeln('<table CELLSPACING=0  CELLPADDING=0 BORDER=0 COLS=9 WIDTH="100%">');
    writeln('<tr BGCOLOR="#3F3F3F">');
    writeln('<td align=center><b><FONT COLOR="#FFFFFF">*</FONT></b></td>');
    writeln('<td><small><b><FONT COLOR="#FFFFFF">Numero</FONT></b></small></td>');
    writeln('<td><small><b><FONT COLOR="#FFFFFF">F.Entrada</FONT></b></small></td>');
    writeln('<td><small><b><FONT COLOR="#FFFFFF">Tipo</FONT></b></small></td>');
    writeln('<td><small><b><FONT COLOR="#FFFFFF">Marca</FONT></b></small></td>');
    writeln('<td><small><b><FONT COLOR="#FFFFFF">Modelo</FONT></b></small></td>');
    writeln('<td><small><b><FONT COLOR="#FFFFFF">Serie</FONT></b></small></td>');
    writeln('<td><small><b><FONT COLOR="#FFFFFF">S/Ref</FONT></b></small></td>');
    writeln('<td><small><b><FONT COLOR="#FFFFFF">Estado</FONT></b></small></td>');
    writeln('</tr>');
  }
}


function PorNumero(a,b){
  return (a.Numero >= b.Numero) ? 1 : -1;
 }

function PorTipo(a,b){
  return (a.Tipo >= b.Tipo) ? 1 : -1;
 }

function PorMarca(a,b){
  return (a.Marca >= b.Marca) ? 1 : -1;
 }

function PorModelo(a,b){
  return (a.Modelo >= b.Modelo) ? 1 : -1;
 }

function PorSerie(a,b){
  return (a.Serie >= b.Serie) ? 1 : -1;
 }

function PorSerie(a,b){
  return (a.Serie >= b.Serie) ? 1 : -1;
 }

function PorsRef(a,b){
  return (a.sRef >= b.sRef) ? 1 : -1;
 }

function PorEstado(a,b){
  return (a.Estado >= b.Estado) ? 1 : -1;
 }

function OrdenaPorNumero() {
  bDtotal.sort(PorNumero);
  Titulo = 'Aparatos ordenados por número';
  ListaTodos();
}

function OrdenaPorTipo() {
  bDtotal.sort(PorTipo);
  Titulo = 'Aparatos ordenados por tipo';
  ListaTodos();
}

function OrdenaPorMarca() {
  bDtotal.sort(PorMarca);
  Titulo = 'Aparatos ordenados por marca';
  ListaTodos();
}

function OrdenaPorModelo() {
  bDtotal.sort(PorModelo);
  Titulo = 'Aparatos ordenados por modelo';
  ListaTodos();
}

function OrdenaPorSerie() {
  bDtotal.sort(PorSerie);
  Titulo = 'Aparatos ordenados por nº serie';
  ListaTodos();
}

function OrdenaPorsRef() {
  bDtotal.sort(PorsRef);
  Titulo = 'Aparatos ordenados por su referencia';
  ListaTodos();
}

function OrdenaPorEstado() {
  bDtotal.sort(PorEstado);
  Titulo = 'Aparatos ordenados por estado';
  ListaTodos();
}

function ListaTodos() {
  ImprimeCabecera();
  NAparatos = 0;
  for (i=0;i<bDtotal.length;i++) {
    bDtotal[i].ImprimeItem(i);
  }
  with (parent.body.document) {
    writeln('</table>');
    writeln('<p>');
    writeln('<h5 align=right>' + NAparatos + ' aparatos listados.</h5>');
    writeln('</FONT>');
    writeln('</BODY>');
    writeln('</HTML>');
    close();
  }
}

function consulta() {
  location='mailto:'+email+'?subject=Consulta reparación';
}