function enviarAmigo( url )
{
    newwindow = window.open(url,'','height=450,width=600');
    if (window.focus)
      newwindow.focus() 
    return false;
}
function popUp(URL) {
  day = new Date();
  id = day.getTime();
  eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=1,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=1,width=400,height=350,left = 440,top = 337');");
}
function pU( url )
{
    var x = (screen.width - 600) / 2;
    var y = (screen.height - 500) / 2;
    newwindow = window.open(url,'','height=600,width=800,left='+x+',top='+y);
    if (window.focus)
      newwindow.focus() 
    return false;
}
window.addEvent('domready', function() {

  document.getElements('img.btbuscador').addEvents({
    'click': function(){
      var frm = this.getParent()
      while( frm.submit == undefined )
        frm = frm.getParent()
      frm.submit()
    }
  });
  
  document.getElements('div.buscador input').addEvents({
    'click': function(){
      if(this.value == this.title)
        this.value = "";
      this.select()
    },
    'blur': function(){
      if(this.value == "")
        this.value = this.title
    }
  });
	
	if(!Browser.Engine.trident) 
		document.getElements('div.botonera div.sup div').each(
			function(c){
				c.setStyle('opacity',.5)
				c.addEvents({
					'mouseover': function(){
						this.setStyle('opacity',1)
					},
					'mouseout': function(){
						c.setStyle('opacity',.5)
					}
				});
			}
		);

  if ( $('hospitalvp') != undefined)
  {
    $('hospEnviar').addEvent('click',function(e){
      if( $('polPriv').checked )
      {
        this.set('disabled','disabled')
        $('hospform').submit()
      }
      else
        alert('Debes aceptar la Política de Privacidad')
    });
    $('hostAtras').addEvent('click',function(e){
      $('vpForm').setStyle('display','none')
      $('toHostp').setStyle('display','block')
    });
    function Validar (e){
      ext = this.value;
      ext = ext.substring(ext.length-3,ext.length);
      ext = ext.toLowerCase();
      if(ext != 'jpg' && ext != 'gif' && ext != 'png') {
        alert('Solo se permiten archivos JPG, GIF y PNG');
        var elem = new Element('input', {'class':'ifile', 'name': this.name , 'type': 'file' , 'size': 70 });
        this.getParent().insertBefore(elem, this.getParent().firstChild);
        elem.addEvent('change',Validar)
        return this.dispose();
      }
    }
    $$('input.ifile').addEvent('change',Validar)
    $('hospitalvp').addEvent('click',function(e){
      e.stop()     
      $('toHostp').setStyle('display','none')
      
      if($('hospform').getElement('select').selectedIndex > 0)
        $('vpForm').getElement('h4').set('html','Tema <span>' + $('hospform').getElement('select')[$('hospform').getElement('select').selectedIndex].text + '</span>')
      else
        $('vpForm').getElement('h4').set('html','Sin Tema')
      if($('hospform').getElement('textarea').value.length > 0)
        $('vpForm').getElement('p').set('html','Consulta <span>' + $('hospform').getElement('textarea').value + '</span>')
      else
        $('vpForm').getElement('p').set('html','Sin Consulta')

      if($('hospform').getElement('.tipo2').value.length > 0)
        $('vpForm').getElement('h3').set('html','Asunto <span>' + $('hospform').getElement('.tipo2').value + '</span>')
      else
        $('vpForm').getElement('h3').set('html','Sin Asunto')
      
      $$('input.ifile').each(function(el,i){
        if(el.value.length > 0)
          $('vpForm').getElement('div').getElements('p')[i].set('html',el.value)
        else
          $('vpForm').getElement('div').getElements('p')[i].set('html','')
      }) 
      
      if($('video').value.length > 0)
        $('vpForm').getElement('div').getElements('p')[3].set('html',$('video').value)
      else
        $('vpForm').getElement('div').getElements('p')[3].set('html','')
      
      $('vpForm').setStyle('display','block')
    })
  }
  if ( $('hospital') != undefined)
    new Accordion($('hospital'), 'div.txtlistado', 'div.lista', {
      opacity: !(Browser.Engine.trident) ,
      onActive: function(toggler, element){
        toggler.addClass('activo')
      },
      onBackground: function(toggler, element){
        toggler.removeClass('activo')
      }
    }); 
  calendario = $$('div.calendario div.iconos div')
  if ( calendario != undefined)
    var act = 0;
    calendario.addEvent('mouseover', function(e){
      k = this.className.split('el')[1];
      if( k == act)
        return
      $('tx'+act).setStyle('display','none');
      act=k;
      $('tx'+act).setStyle('display','block');
    });
});
