// called when you want add a critic

function VisorAddCritica(url){
  if ( window.frames['iframe_visor'] ) {
    window.frames['iframe_visor'].location = url;
    var lyr = document.getElementById? document.getElementById('VisorListado'): document.all? document.all['VisorListado']: null;
    if ( lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = '<div id="visorAjax"><img src="/imgfiles/visorAjax.gif" alt="cargando"><br>Loading...</div>';
    }
    return false;
  }
  return true; // other browsers follow link  
}
function VisorViewCritica(url){
  if ( window.frames['iframe_visor'] ) {
    window.frames['iframe_visor'].location = url;
    var lyr = document.getElementById? document.getElementById('VisorListado'): document.all? document.all['VisorListado']: null;
    if ( lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = '<div id="visorAjax"><img src="/imgfiles/visorAjax.gif" alt="cargando"><br>Loading...</div>';
    }
    return false;
  }
  return true; // other browsers follow link  
}
function loadExternal(url) {
  if ( window.frames['iframe_visor'] ) {
    window.frames['iframe_visor'].location = url;
    var lyr = document.getElementById? document.getElementById('visorIframe'): document.all? document.all['visorIframe']: null;
    if ( lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = '<div id="visorAjax"><img src="/imgfiles/visorAjax.gif" alt="cargando"><br>Loading...</div>';
    }
    return false;
  }
  return true; // other browsers follow link
}

function loadListado(url) {
  if ( window.frames['iframe_visor'] ) {
    window.frames['iframe_visor'].location = url;
    var lyr = document.getElementById? document.getElementById('VisorListado1'): document.all? document.all['VisorListado1']: null;
    if ( lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = '<div id="visorAjax"><img src="/imgfiles/visorAjax.gif" alt="cargando"><br>Loading...</div>';
    }
    return false;
  }
  return true; // other browsers follow link
}
function loadObra(url) {
  if ( window.frames['iframe_visor'] ) {
    window.frames['iframe_visor'].location = url;
    var lyr = document.getElementById? document.getElementById('VisorObra'): document.all? document.all['VisorObra']: null;
    if ( lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = '<div id="visorAjax"><img src="/imgfiles/visorAjax.gif" alt="cargando"><br>Loading...</div>';
    }
    return false;
  }
  return true; // other browsers follow link
}
// called when documents loaded into iframe (from their body's onload attribute)
function displayExternal() {
  var lyr = document.getElementById? document.getElementById('visorIframe'): document.all? document.all['visorIframe']: null;
    if ( window.frames['iframe_visor'] && lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = window.frames['iframe_visor'].document.body.innerHTML;
    }
}
function displayListado() {
  var lyr = document.getElementById? document.getElementById('VisorListado'): document.all? document.all['VisorListado']: null;
    if ( window.frames['iframe_visor'] && lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = window.frames['iframe_visor'].document.body.innerHTML;
    }
}
function displayObra() {
  var lyr = document.getElementById? document.getElementById('VisorObra'): document.all? document.all['VisorObra']: null;
    if ( window.frames['iframe_visor'] && lyr && typeof lyr.innerHTML != "undefined" ) {
      lyr.innerHTML = window.frames['iframe_visor'].document.body.innerHTML;
    }
}


function cerrarVisor(){
if (popVisor.visible){
	frameVisor.hide();
    popVisor.hide();
    maskara.hide();
    
    var slide = document.getElementById('slide');
  
    if(slide){
    	slide.style.visibility = 'visible';
    }
  }
}

function cerrarVisorYRecargar(){
  if (popVisor.visible){
	frameVisor.hide();
    popVisor.hide();
    maskara.hide();
    self.parent.location.reload();
  }
}

function lanzarVisor(idObra,idGaleria,idColeccionista){
  var slide = document.getElementById('slide');
  
  if(slide){
  	slide.style.visibility = 'hidden';
  }

  document.body.scrollLeft = 0;
  document.body.scrollTop = 0;
  maskara.moveTo(0,5);
  maskara.resizeTo(document.body.scrollWidth, document.body.scrollHeight);
  maskara.setBgColor('#000000');
  maskara.setOpacity(0.97);

  maskara.maximizeZ();
  maskara.show();

  document.getElementById('visorIframe').innerHTML='';
  document.getElementById('visorIframe').style.display='block';

  popVisor.maximizeZ();
  popVisor.show();

  var url = '/galerias.visor?idObra='+idObra+'&idGaleria='+idGaleria+'&idColeccionista='+idColeccionista;
  ajaxCaller.getPlainText(url,pinta_visor);
}

function lanzarVisorCritica(idObra,idGaleria,idColeccionista){

  document.body.scrollLeft = 0;
  document.body.scrollTop = 0;
  maskara.moveTo(0,5);
  maskara.resizeTo(document.body.scrollWidth, document.body.scrollHeight);
  maskara.setBgColor('#000000');
  maskara.setOpacity(0.97);

  maskara.maximizeZ();
  maskara.show();

  document.getElementById('visorIframe').innerHTML='';
  document.getElementById('visorIframe').style.display='block';

  popVisor.maximizeZ();
  popVisor.show(); 

  var url = '/Critica.visor?idObra='+idObra+'&idGaleria='+idGaleria+'&idColeccionista='+idColeccionista;
  ajaxCaller.getPlainText(url,pinta_visor);
}

function pinta_visor(json) {
  var all = eval('('+json+')');
  for(var i in all){ 
   loadExternal(all[i].HREF);
 }
}
function lanzarVisorListado(idObra,idGaleria,idColeccionista,pag,TipoPag){

  var url = '/galerias.nomObra?idObra='+idObra;
  ajaxCaller.getPlainText(url,pinta_nomObra);

  var url = '/galerias.visor?idObra='+idObra+'&idGaleria='+idGaleria+'&idColeccionista='+idColeccionista+'&Paginador='+pag+'&TipoPag='+TipoPag;
  ajaxCaller.getPlainText(url,pinta_visorListado);
}
function pinta_visorListado(json) {
  var all = eval('('+json+')');
  for(var i in all){ 
   loadObra(all[i].HREF);
 }
}
function pinta_nomObra(json) {
  var all = eval('('+json+')');
  for(var i in all){ 
    var div1 = document.getElementById('nomObra');
    div1.innerHTML='';
    var txt1=document.createTextNode(all[i].nomObra);
    div1.appendChild(txt1);
    var span1=document.createElement('span');
    //alert(all[i].nomAnyo);
    if(all[i].nomAnyo!='')
    {
     span1.className='nomYear';
     var txt2=document.createTextNode(' ('+all[i].nomAnyo+')');
     span1.appendChild(txt2);
    }
    div1.appendChild(span1);

    var div1 = document.getElementById('nomColeccion');
    div1.innerHTML='';
    var txt1=document.createTextNode(all[i].nomColec);
    div1.appendChild(txt1);

    var div1 = document.getElementById('nomGaleria');
    div1.innerHTML='';
    var txt1=document.createTextNode(all[i].nomGaler);
    div1.appendChild(txt1);

    var div1 = document.getElementById('nomAutor');
    div1.innerHTML='';
    var txt1=document.createTextNode(all[i].nomAutor);
    div1.appendChild(txt1);
    
 }
}

function llamaGuardarCritica(idClick,idGaleria,idColeccion) {
   var idTipo = document.getElementById('idTipo').value;
   var tituloCritica = document.getElementById('tituloCritica').value;
   var texto = document.getElementById('texto').value;
   var url = '/Critica.GuardarCritica?idTipo='+idTipo+'&idClick='+idClick+'&tituloCritica='+tituloCritica+'&texto='+texto+'&idGaleria='+idGaleria+'&idColeccion='+idColeccion;
   ajaxCaller.getPlainText(url,guardarCritica);
}

function guardarCritica(json) {
  var all = eval('('+json+')');
  for(var i in all){ 
    VisorViewCritica(all[i].HREF);
  }
}

