function loadImg(url) {var img = new Image(); img.src = url; return img;}

loadImg("i/anterior.gif");
loadImg("i/siguiente.gif");
loadImg("i/loading.gif");

function checkform(e)
{
  complete=true;
  for (n = 0; n<e.elements.length; n++)
  {
    a = e.elements[n];
    nombre = a.name
    if (nombre.substr(nombre.length-2)=='_r')
    {      
      if ((a.value=='')||(a.value=='Tengo el gusto de comunicarle '))
      {
        a.onfocus=new Function("this.style.backgroundColor='transparent'");
        a.style.backgroundColor='#FFEE54';
        complete=false;
      }
    }
  }
  if (!complete) alert("Faltan campos por rellenar");
  return complete;
}

function checkforme(e)
{
  complete=true;
  for (n = 0; n<e.elements.length; n++)
  {
    a = e.elements[n];
    nombre = a.name
    if (nombre.substr(nombre.length-2)=='_r')
    {      
      if ((a.value=='')||(a.value=='I would like to inform you that '))
      {
        a.onfocus=new Function("this.style.backgroundColor='transparent'");
        a.style.backgroundColor='#FFEE54';
        complete=false;
      }
    }
  }
  if (!complete) alert("Please fill all the fields");
  return complete;
}

function resize2(e)
{
  if (window.innerWidth || window.innerHeight) {width = window.innerWidth; height = window.innerHeight;}
  if (document.body.clientWidth || document.body.clientHeight) {width = document.body.clientWidth; height = document.body.clientHeight;}
  height-=40;

  le=(width-x[actual])/2; to=((height-y[actual])/2);

  if (to<10) to=10;
  if (y[actual]>(height-20))
  {
    if ((height-22)<1) height=23;
    e.style.width=(x[actual]+16)+'px';
    e.style.height=(height-20)+'px';
    document.getElementById('ventana2').style.width=(x[actual]+14)+'px';
    document.getElementById('ventana2').style.height=(height-22)+'px';
    document.getElementById('ventana2').style.overflow='auto';
    document.getElementById('xc').style.right='21px';
  }
  else
  {
    e.style.width=x[actual]+'px';
    e.style.height=y[actual]+'px';
    document.getElementById('ventana2').style.overflow='visible';
    document.getElementById('ventana2').style.width=(x[actual]-2)+'px';
    document.getElementById('ventana2').style.height=(y[actual]-2)+'px';
    document.getElementById('xc').style.right='5px';
  }

  e.style.left=le+'px';
  e.style.top=to+'px';
}

function resize()
{
  if (e=document.getElementById('ventana')) resize2(e);
}

function cerrar()
{
  if (e=document.getElementById('ventana')) document.body.removeChild(e);
  if (e=document.getElementById('fondo')) document.body.removeChild(e);
  if (e=document.getElementById('botones')) document.body.removeChild(e);
}

function abrir(id)
{
  if (window.innerWidth || window.innerHeight) {width = window.innerWidth; height = window.innerHeight;}
  if (document.body.clientWidth || document.body.clientHeight) {width = document.body.clientWidth; height = document.body.clientHeight;}
  height-=40;

  actual=id;
  document.getElementById('t'+id).className='thumb_v';

  if (e=document.getElementById('ventana')) document.body.removeChild(e);
  if (e=document.getElementById('fondo')) document.body.removeChild(e);
  if (e=document.getElementById('botones')) document.body.removeChild(e);

  c=document.createElement("div");
  c.setAttribute("id", "fondo");
  document.body.appendChild(c);

  c=document.createElement("div");
  c.setAttribute("id", "botones");
  c.style.width="100%";
  c.style.height="100%";
  c.style.position="absolute";
  c.style.left="0";
  c.style.top="0";

  ht=
  ht='<table cellpadding="0" cellspacing="0" width="100%" height="100%"><tr><td  style="border-bottom: 1px solid #A2A9A6;">&nbsp;</td></tr><tr height="39" valign="center"><td align="center" style="background-color: #fff">';
  ht+='<table cellpadding="0" cellspacint="0"><tr>';
  ht+='<td><a class="boton" href="#" onclick="abrir((actual+items-1)%items); return false;"><img border="0" src="i/anterior.gif"></a></td><td width="20"></td>';
  ht+='<td><a class="boton" href="#" onclick="abrir((actual+1)%items); return false;"><img border="0" src="i/siguiente.gif"></a></td>';
  ht+='</tr></table></td></tr></table>';
  c.innerHTML=ht;

  document.body.appendChild(c);

  c=document.createElement("div");
  c.setAttribute("id", "ventana");
  le=(width-x[actual])/2; to=((height-y[actual])/2);
  c.style.left=le+'px';
  c.style.top=to+'px';
  c.innerHTML='<div id="ventana1"><div id="ventana2" style="width: '+(x[id]-2)+'px; height: '+(y[id]-2)+'px">'+html[id]+'</div></div><a href="#" onclick="cerrar(); return false;" class="menu" id="xc" style="position: absolute; right: 5px; top: 0; font-size: 19px;"><b>x</b></a>';
  document.body.appendChild(c);
  resize(c);

}