// Programado por Manuel Miranda Melian
// Departamento Técnico y Programación
// JadaCom NetWorks (c) 2002
// Puedes hacer lo que te de la gana con este código, siempre y cuando dejes instactas esta y las anteriores lineas de código.
// Version 0.56

//Rutina que inserta una imagen que cambia cuando se le pasa el cursor por arriba.
function imgcambia(imga,imgb) {
  var cosa = "'"
  document.write('<IMG Src='+imga+' Border=0 OnMouseOver="document.images['+document.images.length+'].src='+cosa+imgb+cosa+'" OnMouseOut="document.images['+document.images.length+'].src='+cosa+imga+cosa+'">');
}

//Rutina que ejecuta un sonido cuando es llamada
//requiere de un frame con nombre "fsonido".
function sonido(archivo) {
  top.fsonido.document.close();
  top.fsonido.document.write('<HTML><HEAD></HEAD><BODY>');
  top.fsonido.document.write('<BGSOUND Src="'+archivo+'" loop=false>');
  top.fsonido.document.write('</BODY></HTML>');
}

function sonido2(archivo,loop) {
  top.fsonido.document.close();
  top.fsonido.document.write('<HTML><HEAD></HEAD><BODY>');
  if (archivo != "") {
    top.fsonido.document.write('<BGSOUND Src="'+archivo+'" loop=');
    if (loop != "") { top.fsonido.document.write(loop); } else  { top.fsonido.document.write('false'); }
    top.fsonido.document.write('>');
  }
  top.fsonido.document.write('</BODY></HTML>');
}



//rutina que cambia una imagen cuando pasamos el cursor por arriba y ejecuta un sonido.
function imgcamsnd(imga,imgb,sond) {
  var cosa = "'"
  precargara=new Image();
  precargara.src=imga;
  precargarb=new Image();
  precargarb.src=imgb;
  document.writeln('<IMG Src='+imga+' Border=0 OnMouseOver="document.images['+document.images.length+'].src='+cosa+imgb+cosa+'; sonido(sond);" OnMouseOut="document.images['+document.images.length+'].src='+cosa+imga+cosa+';">');
}

//Rutina que crea una ventana con la pagina dada, de las dimensiones pasadas... y la centra en pantalla.
function ventana(pagina) {
  vventana=open(pagina,"nombre","resizable=0, menubar=0, toolbar=0, location=0, personalbar=0, status=0, width=690, height=480");
  vventana.moveTo((screen.availWidth - 690)/2,(screen.availHeight - 480)/2);
}

//Rutina que crea una ventana con la pagina dada, de las dimensiones pasadas... y la centra en pantalla.
function ventanac(pagina,ancho,alto) {
  vventana=open(pagina,"","resizable=0, menubar=0, toolbar=0, location=0, personalbar=0, status=1, scrollbars=1, width="+ancho+", height="+alto);
  vventana.moveTo((screen.availWidth - ancho)/2,(screen.availHeight - alto)/2);
}

function ventanad(pagina,ancho,alto) {
  vventana=open(pagina,"nombre","resizable=1, menubar=0, toolbar=0, location=0, personalbar=0, status=1, width="+ancho+", height="+alto);
  vventana.moveTo((screen.availWidth - ancho)/2,(screen.availHeight - alto)/2);
}


//idem a la anterior, pero la ventana no tiene bordes ni titulo.
function ventanab(pagina,ancho,alto) {
  vventana=open(pagina,'nombre',"fullscreen");
  vventana.moveTo((screen.availWidth-ancho)/2,(screen.availHeight-alto)/2);
  vventana.resizeTo(ancho,alto);
}


if (navigator.appName == "Microsoft Internet Explorer") {
  nv=false;
} else {
  nv=true;
}

//var nv = window.Event ? true : false;


function nokey(tecla) {
  if (nv) {
    return false;
  } else {
    window.event.keyCode=0;
  }
}

function onlyreal(tecla) {
  var key = nv ? tecla.which : tecla.keyCode;
  if ((key < 48 || key > 57) && (key != 43) && (key != 46) && (key != 45) && (key!=8) && (key!=13) && (key!=9)) {
    return nokey(tecla);
  }
}

function onlynumber(tecla) {
  var key = nv ? tecla.which : tecla.keyCode;
  if ((key < 48 || key > 57) && (key!=8) && (key!=13) && (key!=9) && (key!=0)) { return nokey(tecla); }
}


     function sienter(tecla,funcion,parametro) {
       if (nv) {
         key = tecla.which;
       } else {
         key = window.event.keyCode;
       }
       if (key == 13) {
         eval(funcion+"("+parametro+")");
       }
     }

     function soloarchivos(objeto, etiquetas) {
       temp=objeto.value.split(".");
       etiqueta=temp[temp.length-1].toLowerCase();

       temp=etiquetas.split(" ");
       correcto=0;
       for(cont=0;cont<temp.length;cont++) {
         if (temp[cont] == etiqueta) {
           correcto=1;
        }
       }
        if (! correcto) {
          return true;
       }
       return false;
     }

     function formnovacio(objeto) {
       eval('temp=document.formulario.'+objeto+'.value');
       if (temp=='') {
        eval('document.formulario.'+objeto+'.style.background="#FFEEEE"');
        eval('document.formulario.'+objeto+'.focus()');
      } else {
        eval('document.formulario.'+objeto+'.style.background="#FFFFFF"');
      }
      return temp;
    }

     function formnovacio2(formu,objeto) {
       eval('temp=document.'+formu+'.'+objeto+'.value');
       if (temp=='') {
        eval('document.'+formu+'.'+objeto+'.style.background="#FFEEEE"');
        eval('document.'+formu+'.'+objeto+'.focus()');
        return 1;
      } else {
        eval('document.'+formu+'.'+objeto+'.style.background="#FFFFFF"');
        return 0;
      }
    }


    function novacio(campos,formu) {
      camp=campos.split(" ");
      vacio=0;
      for (cont=0;cont<camp.length;cont++) {
        vacio=vacio | formnovacio2(formu,camp[cont]);
      }
      if (vacio) { alert('los campos resaltados son obligatorios'); }
      return vacio;
    }

      function addopt(form,nombre,texto,valor) {
        var obj=eval('window.document.'+form+'.'+nombre);
        obj.length++;
        obj.options[obj.length-1].text=texto;
        obj.options[obj.length-1].value=valor;
      }

      function mdis_jserror(obj) {
        t=obj.name;
        switch (t) {
          default:
            v=document.getElementById(t).parentNode.parentNode;
          break;
          case 'tiporeserva':
            v=document.getElementById(t).parentNode.parentNode.parentNode.parentNode;
          break;
          case 'pa_nombre':
          case 'pa_municipio':
          case 'pa_direccion':
          case 'pa_cp':
            v=document.getElementById(t).parentNode;
          break;
        }
        v.style.background="#ffaaaa";
      }
  
      function mdis_jsok(obj) {
        t=obj.name;
        switch (t) {
          default:
            v=document.getElementById(t).parentNode.parentNode;
          break;
          case 'tiporeserva':
            v=document.getElementById(t).parentNode.parentNode.parentNode.parentNode;
          break;
          case 'pa_nombre':
          case 'pa_municipio':
          case 'pa_direccion':
          case 'pa_cp':
            v=document.getElementById(t).parentNode;
          break;
        }
        v.style.background="#ffffff";
      }


function mktime() {
    // Get UNIX timestamp for a date  
    // 
    // version: 901.2514
    // discuss at: http://phpjs.org/functions/mktime
    // +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: baris ozdil
    // +      input by: gabriel paderni 
    // +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   improved by: FGFEmperor
    // +      input by: Yannoo
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +      input by: jakes
    // +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
    // +   bugfixed by: Marc Palau
    // *     example 1: mktime(14, 10, 2, 2, 1, 2008);
    // *     returns 1: 1201871402
    // *     example 2: mktime(0, 0, 0, 0, 1, 2008);
    // *     returns 2: 1196463600
    // *     example 3: make = mktime();
    // *     example 3: td = new Date();
    // *     example 3: real = Math.floor(td.getTime()/1000);
    // *     example 3: diff = (real - make);
    // *     results 3: diff < 5
    // *     example 4: mktime(0, 0, 0, 13, 1, 1997)
    // *     returns 4: 883609200
    // *     example 5: mktime(0, 0, 0, 1, 1, 1998)
    // *     returns 5: 883609200
    // *     example 6: mktime(0, 0, 0, 1, 1, 98)
    // *     returns 6: 883609200
    
    var no, ma = 0, mb = 0, i = 0, d = new Date(), argv = arguments, argc = argv.length;

    if (argc > 0){
        d.setHours(0,0,0); d.setDate(1); d.setMonth(1); d.setYear(1972);
    }
 
    var dateManip = {
        0: function(tt){ return d.setHours(tt); },
        1: function(tt){ return d.setMinutes(tt); },
        2: function(tt){ var set = d.setSeconds(tt); mb = d.getDate() - 1; return set; },
        3: function(tt){ var set = d.setMonth(parseInt(tt)-1); ma = d.getFullYear() - 1972; return set; },
        4: function(tt){ return d.setDate(tt+mb); },
        5: function(tt){ return d.setYear(tt+ma); }
    };
    
    for( i = 0; i < argc; i++ ){
        no = parseInt(argv[i]*1);
        if (isNaN(no)) {
            return false;
        } else {
            // arg is number, let's manipulate date object
            if(!dateManip[i](no)){
                // failed
                return false;
            }
        }
    }

    return Math.floor(d.getTime()/1000);
}

var MiPopup = new Class({
   initialize: function(miHtml,ancho,alto,titulo){
      this.titulo=titulo;
      this.tamanoBody = window.getScrollSize();
      this.posScroll = window.getScroll();
      this.espacioDisponibleVentana = window.getSize();
      this.capaSombra = new Element("div", {'id': 'capasombra', 'style': 'width: ' + this.tamanoBody.x + 'px; height: ' + this.tamanoBody.y + 'px; ' });
      this.capaSombra.inject(document.body);
      var myFx = new Fx.Tween(this.capaSombra,{'duration': 300});
      myFx.start('opacity',0,0.8);
      
      this.contenido = new Element("div", {'id': 'contenidopopup'});
      this.contenido.set('html', "<div class=cuerpotextopopup>" + miHtml + "</div>");
      var titulo = new Element("div", {'id': 'titulopopup'});
      titulo.set('html', this.titulo);
      var cerrar = new Element("div", {'id': 'cerrarpopup'});
      cerrar.addEvent('click', function(){
         this.cerrar();
      }.bind(this));
      cerrar.inject(titulo,'top');
      titulo.inject(this.contenido,'top');
            
      this.capaPopup = new Element("div", {'id': 'capapopup', 'style': 'margin-left:-' + ancho/2 +'px; top:' + (this.posScroll.y + (this.espacioDisponibleVentana.y/2) - (alto/2)-15) +'px'});
      this.capaPopup.inject(this.capaSombra,'after');
      
      var myFx2 = new Fx.Tween(this.capaPopup,{'duration': 700});
      myFx2.start('width',4,ancho);
      myFx2.addEvent('complete', function(){
         var myFx3 = new Fx.Tween(this.capaPopup,{'duration': 700});
         myFx3.start('height',4,alto+30);
         myFx3.addEvent('complete', function(){
            this.contenido.inject(this.capaPopup);
            this.contenido.setStyle('opacity', 0);
            this.contenido.setStyle('display', 'block');
            var myFx4 = new Fx.Tween(this.contenido,{'duration': 600});
            myFx4.start('opacity',0,1);
         }.bind(this));
      }.bind(this));
      
      this.capaSombra.addEvent('click', function(){
            this.cerrar();
         }.bind(this)
      );
   },
   
   cerrar: function(){
      var myFx = new Fx.Tween(this.capaPopup,{'duration': 500});
      myFx.start('opacity',1,0);
      myFx.addEvent('complete', function(){
         var myFx2 = new Fx.Tween(this.capaSombra,{'duration': 500});
         myFx2.start('opacity',0.8,0);
         myFx2.addEvent('complete', function(){
            this.capaSombra.destroy();
            this.capaPopup.destroy();
         }.bind(this));
      }.bind(this));
   }
}); 


