function open_image0(url, title)
{
  window.status=title;
  win=window.open('', '', 'top=2,left=2,width=800,height=600,menubar=no,resizable=yes,toolbar=no,scrollbars=yes');
  win.document.open();
    win.document.writeln('<html><head><title>'+ title + '</title></head>');
    win.document.writeln('<body bgcolor="#ffffff"><center>');
    win.document.writeln('<img src="'+url+'" border=0><br><p>');
    win.document.writeln('<p><a href="javascript:close()"><img src="images/tanca2.jpg" border=0 width=25 alt="cerrar"></a><br><p>');
    win.document.writeln(title);
    win.document.writeln('</center></body></html>');
    win.document.close();
  
}
function open_image(url, title)
{
  open_image_solo(url, title);
}  


function open_image_solo(url, title)
{
  window.status=title;
  win=window.open('', '', 'top=2,left=2,width=1024,height=768,menubar=no,resizable=yes,toolbar=no,scrollbars=yes');
  win.document.open();
  win.document.writeln('<HTML> ');
  win.document.writeln('<HEAD> ');
  win.document.writeln('<TITLE>'+ title+ '</TITLE> ');
  win.document.writeln('</HEAD> ');

  win.document.writeln('<BODY bgcolor="#000000"> ');
  win.document.writeln('<table width=100%> ');
  win.document.writeln('<tr><td align=center> ');
  win.document.writeln('<IMG src="'+url+'"  border=0> ');
  win.document.writeln('</td></tr></table> ');
  win.document.writeln('</BODY> ');
  win.document.writeln('</HTML>');
  win.document.close();
}

function open_image1(url, url1, title, hoff, voff,url1_width)
{
  window.status=title;
  win=window.open('', '', 'top=2,left=2,width=800,height=600,menubar=no,resizable=yes,toolbar=no,scrollbars=yes');
    win.document.open();
    win.document.writeln('<HTML>  ');
    win.document.writeln('<HEAD> ');
    win.document.writeln('<TITLE>'+ title + '</TITLE> ');
    win.document.writeln('<style>\n#primer\n{ position: relative; top: '+voff+'px; left: '+hoff+'px; visibility: show;\n}</style>');
    win.document.writeln('</HEAD> ');
    win.document.writeln(' ');
    win.document.writeln('<BODY bgcolor="#ffffff"> ');
    win.document.writeln('<table width="100%" ><tr><td  align=right>');
    win.document.writeln('<A href="javascript:close()">');
    win.document.writeln('<img src="images/tanca2.jpg" border=0 width=25 alt="cerrar"></A></td></tr></table>');
    win.document.writeln('<center>'+ title );
    win.document.writeln(' ');
    win.document.writeln('<P> ');
    win.document.writeln(' ');
    win.document.writeln('<A href="javascript:void(0)" ');
    win.document.writeln('  onmouseover="if ( document.all ){  primer.style.visibility=\'visible\';} else document.primer.visibility=\'show\'"');
    win.document.writeln('  onmouseout="if ( document.all ) primer.style.visibility=\'hidden\'; else document.primer.visibility=\'hidden\'">');
    win.document.writeln('<IMG src="'+url+'"  border=0></A>&nbsp; ');
    win.document.writeln('<div id="primer" name="primer">');
    win.document.writeln('<img src="'+url1+'" width='+url1_width+'> </div>');
    win.document.writeln('</CENTER> ');
    win.document.writeln('</BODY> ');
    win.document.writeln('</HTML>');

    win.document.close();
}

function show_div(layer_name)
{
  if ( document.all )
    cmd=layer_name+'.style.visibility="show"';
  else  
    cmd='document.'+layer_name+'.visibility="show"';
  eval(cmd);
}

function hide_div(layer_name)
{
  var cmd;
  if ( document.getElementById ) {
    var hid=document.getElementById(layer_name);
    if ( hid ) {
      hid.style.visibility="hidden";
    }
  }
  else if ( document.all )
    cmd=layer_name+'.style.visibility="hide"';
  else  
  cmd='document.'+layer_name+'.visibility="hidden"';
  eval(cmd);
}

function open_window(url, width, height)
{
  var win=window.open(url, "", "resizable=yes,scrollbars=yes,width="+width+",height="+height);
  win.focus();
}

function open_foto(i)
{
  if ( thumbnails_a && thumbnails_a[i] ) {
    title=thumbnails_a[i]["descripcio"];
    if ( typeof(dir_fotos) == "undefined" ) {
      dir_fotos=".";
    }
    url=dir_fotos+"/"+thumbnails_a[i]["nom_foto"];
    window.status=title;
    win=window.open('', 'foto', 'top=2,left=2,width=1024,height=768,menubar=no,resizable=yes,toolbar=no,scrollbars=yes');
    win.document.open();
    str ='<HTML> \n';
    str+='<HEAD> \n';
    str+='<TITLE>'+ title+ '</TITLE> \n';
    str+='<script>var this_i='+i+'; \n';
    str+='    function go_first()\n'+
'    {\n'+
'      this_i=0;\n'+
'      load();\n'+
'    }\n'+
'    function go_prev()\n'+
'    {\n'+
'      if ( this_i > 0 ) {\n'+
'        this_i--;\n'+
'      }\n'+
'      load();\n'+
'    }\n'+
'    function go_next()\n'+
'    {\n'+
'      if ( this_i < opener.thumbnails_a.length-1 ) {\n'+
'        this_i++;\n'+
'      }\n'+
'      load();\n'+
'    }\n'+
'    function go_last()\n'+
'    {\n'+
'      this_i = opener.thumbnails_a.length-1;\n'+
'      load();\n'+
'    }\n'+
'    \n'+
'    function  load()\n'+
'    {\n'+
'      var h;\n'+
'      if ( (h=document.getElementById("foto"))) {\n'+
'        var df=( typeof(opener.dir_fotos) != "undefined" ) ? opener.dir_fotos : ".";\n'+
'        //alert(h);\n'+
'	h.src=df+"/"+opener.thumbnails_a[this_i]["nom_foto"];\n'+
'      }\n'+
'      if ( (h=document.getElementById("titol"))) {\n'+
'        //alert(h);\n'+
'	h.innerHTML=opener.thumbnails_a[this_i]["descripcio"];\n'+
'      }\n'+
'    }\n';
    str+='</script>\n';
    str+='</HEAD> \n';

    str+='<BODY bgcolor="#ffffff"> \n';
    str+='<table width=100%> \n';
    str+='<tr><td align=center> \n';
    str+='<IMG id="foto" src="'+url+'"  border=0> \n';
    str+='</td></tr>\n';
    str+='<tr><td align=center> \n';
    str+='<span id="titol">'+title+'</span>\n';
    str+='</td></tr>\n';
    str+='<tr><td align=center> \n';
    str+='<input type="button" value="&lt;&lt;" onclick="go_first()">\n';
    str+='<input type="button" value="&lt;" onclick="go_prev()">\n';
    str+='<input type="button" value="tancar" onclick="self.close()">\n';
    str+='<input type="button" value="&gt;" onclick="go_next()">\n';
    str+='<input type="button" value="&gt;&gt;" onclick="go_last()">\n';
    str+='</td></tr>\n';
    str+='</table> \n';
    str+='</BODY> \n';
    str+='</HTML>\n';
    //alert(str);
    win.document.write(str);
    win.document.close();
    win.focus();
  }
}

function write_thumbnails()
{
  var str="<table  height=12 valign='top' cellpadding=5 border=0 cellspacing=1 ><tr>";
  for ( var i=0; i<thumbnails_a.length; i++ ) {
    var url=PHP_SELF+'&action=mostrar_pagina&counter_codi='+i;
    str+='<tr>';
    str+="<td><span class=\"subtitol\"> <font color=\"#CC0000\">"+data_str(thumbnails_a[i]["data"])+"</font></span></td><td><a href='"+url+"'>"+thumbnails_a[i]["titol"]+"</a></td>";
    str+='</tr>';
  }
  str+="</table>";

  return str;	
}
function write_fotos()
{
  var str="<table  height=12 valign='top' cellpadding=5 border=0 cellspacing=1 ><tr>";
  for ( var i=0; i<thumbnails_a.length; i++ ) {
    var url=PHP_SELF+'&action=fotos&codi_producto='+thumbnails_a[i]["codi_producto"];
    str+='<tr>';
    str+="<td><span class=\"subtitol\"> <font color=\"#CC0000\">"+data_str(thumbnails_a[i]["data"])+"</font></span></td><td><a href='"+url+"'>"+thumbnails_a[i]["titol"]+"</a></td>";
    str+='</tr>';
  }
  str+="</table>";

  return str;	
}

function write_peli()
{
  if ( typeof(thumbs_linea) == "undefined" ) {
    thumbs_linea=4;	
  }
  if ( typeof(thumbs_width) == "undefined" ) {
    thumbs_width=108;	
  }
  if ( typeof(thumbs_height) != "undefined" ) {
    height="height='"+thumbs_height+"' ";	
  }
  else {
    height="";
  }
  if ( typeof(dir_thumbs) == "undefined" ) {
    dir_thumbs=".";	
  }
  var str='  <TABLE cellSpacing=0 cellPadding=0 border=0>\n';
  for ( var i=0; i<thumbnails_a.length; i+=thumbs_linea ){
    str+='  <TR>\n';
    for ( var j=i; j-i<thumbs_linea && j< thumbnails_a.length; j++ ) {
      var nom_foto=thumbnails_a[j]["nom_foto"];
      var descripcio=thumbnails_a[j]["descripcio"];
      str+=
'    <TD>\n'+
'      <TABLE cellSpacing=0 cellPadding=0 border=0>\n'+
'        <TBODY>\n'+
'        <TR>\n'+
'          <TD vAlign=center align=middle width="'+thumbs_width+'">\n'+
'          <a href="#" onclick="open_foto('+j+')">\n'+
'          <img border="0" src="'+dir_thumbs+'/'+nom_foto+'" width="'+thumbs_width+'" '+height+'></a><BR></TD></TR>\n'+
'        <TR>\n'+
'          <TD vAlign=center align=middle width='+thumbs_width+' height=0 class="descripcio">'+descripcio+'&nbsp;</TD></TR></TBODY></TABLE></TD>\n';
    }
    str+='</TR>\n';
  }
  str+='</TABLE>\n';


  return str;	
}

function write_foto(descripcio, img_foto, fotos_dir, fotos_hr_dir)
{
  var str;
  if ( img_foto != "" ) {
    str='<table><tr><td><a href="#" onclick=\'open_image("'+fotos_hr_dir+'/'+img_foto+'", "'+descripcio+'")\'><img alt=\'asdfas\' src="'+fotos_dir+'/'+img_foto+'" width="400" border="0"></a></td></tr><tr><td>'+descripcio+'</td></tr></table>';
  }
  else {
    str='';
  }

  //alert(str);
  document.write(str);
}  
