function abrirFoto(w) {
	var le = (screen.width - 700) / 2;
  	var to = (screen.height - 500) / 2;
	newwindow=window.open(w,'_blank','height=500,width=700,left='+le+',top='+to+',resizable=no,scrollbars=no,toolbar=no,status=no');
}
function comprueba() {
	if (document.ficha.nombre.value=="") {
		alert ("Por favor, indique su nombre.");
		document.ficha.nombre.focus();
		return false;
	} else if (document.ficha.telefono.value=="") {
		alert ("Por favor, indique un tel&eacute;fono de contacto.");
		document.ficha.telefono.focus();
		return false;
	} else if (document.ficha.email.value=="") {
		alert ("Por favor, indique un email v&aacute;lido.");
		document.ficha.email.focus();
		return false;
	} else if (document.ficha.consulta.value=="") {
		alert ("Por favor, indique su consulta");
		document.ficha.consulta.focus();
		return false;
	}

}

var peticionMenu=0;
var peticionPagina=0;

function whenResponsePagina(){
	peticionPagina=1;
	div=document.getElementById("contenido");
	div.innerHTML = this.response;
	scripts=div.getElementsByTagName('script');
	for(i=0;i<scripts.length;i++)
		eval(scripts[i].text);
	/*if(peticionMenu==1){
		div=document.getElementById('cargando'); 
		div.style.visibility='hidden';
		div=document.getElementById('cuadro');
		div.style.visibility='hidden';
	}*/
}

function whenResponseMenu(){
	div=document.getElementById("menu");
	div.innerHTML = this.response;
	peticionMenu=1;
	/*if(peticionPagina==1){
		div=document.getElementById('cargando'); 
		div.style.visibility='hidden';
		div=document.getElementById('cuadro');
		div.style.visibility='hidden';
	}*/
}

function pide_pagina(menu,pagina,var1,value1,var2,value2){
	peticionMenu=0;
	peticionPagina=0;
	/*div=document.getElementById('cargando'); 
	div.style.visibility='visible';
	div=document.getElementById('cuadro');
	div.style.visibility='visible';*/
	if (menu!=-1){
		var peticion = new sack();
    	peticion.requestFile = "./paginas/menu.php";
    	peticion.method = "GET";
    	peticion.setVar('sec', menu);
		peticion.onCompletion = whenResponseMenu;
    	peticion.runAJAX();
	}else{
		peticionMenu=1;
	}
	//pagina
	var p_pagina = new sack();
    p_pagina.requestFile = pagina;
    p_pagina.method = "GET";
    if(var1!=null)
    	p_pagina.setVar(var1, value1);
    if(var2!=null)
    	p_pagina.setVar(var2, value2);
    p_pagina.onCompletion = whenResponsePagina;
	p_pagina.runAJAX();
}

function chequea(){
	//peticion
	var peticion = new sack(); //creamos peticion AJAX
	peticion.requestFile = "paginas/chequea.php"; //Archivo a pedir
	peticion.method = "POST"; //Tipo de peticion
	peticion.onCompletion = whenResponsePeticion; //Funcion a ejecutar cuando se complete
	peticion.runAJAX(); //Ejecutamos
	setTimeout(chequea,60000); //volvemos a ejecutar la funcion
}

var speed = 4;
var real = 0;
var zoom = 4;

function scaleIn()
{
  var myimg = this.getElementsByTagName('img')[0];
  this.style.zIndex = 20;
  myimg.src = myimg.smallSrc;
  var count = 0;
  var real = 0;
  intervalIn = window.setInterval(scaleStepIn, 1);
  return false;

  
function scaleStepIn(){
	var widthIn = parseInt(myimg.style['width']);
	var heightIn = parseInt(myimg.style['height']);
	var topIn = parseInt(myimg.style['top']);
	var leftIn = parseInt(myimg.style['left']);
	if(widthIn >= heightIn) {
	  widthIn += speed;
	  heightIn += Math.floor(speed * (3/4));
	  topIn -= (Math.floor(speed * (3/8)));
	  leftIn -= (speed/2);
	}
	else
	{
	  widthIn += Math.floor(speed * (3/4));
	  heightIn += speed;
	  topIn -= (speed/2);
	  leftIn -= (Math.floor(speed * (3/8)));
	}
	myimg.style['width'] = widthIn;
	myimg.style['height'] = heightIn;
	myimg.style['top'] = topIn;
	myimg.style['left'] = leftIn;
	count++;
	if (count >= zoom)
	  window.clearInterval(intervalIn);
  }			
}

function scaleOut(){
  window.clearInterval(intervalIn);
  var myimg = this.getElementsByTagName('img')[0];
  myimg.src = myimg.smallSrc;
  this.style.zIndex = 10;
  var mydiv = this;
  var interval = window.setInterval(scaleStepOut, 1);
  return false;

function scaleStepOut()
  {
	var width = parseInt(myimg.style['width']);
	var height = parseInt(myimg.style['height']);
	var top = parseInt(myimg.style['top']);
	var left = parseInt(myimg.style['left']);
	if(width >= height) {
	  width -= speed;
	  height -= Math.floor(speed * (3/4));
  	  if(width < myimg.smallWidth + 4) {
	    myimg.style['width'] = myimg.smallWidth;
	    myimg.style['height'] = myimg.smallHeight;
	    myimg.style['top'] = 0;
	    myimg.style['left'] = 0;
		mydiv.style['zIndex'] = 1;
		window.clearInterval(interval);
	  }
	  else{
	    myimg.style['width'] = width;
	    myimg.style['height'] = height;
	    myimg.style['left'] = left + (speed/2);
	    myimg.style['top'] = top + (Math.floor(speed * (3/8)));
	  }
	}
	else
	{
	  width -= Math.floor(speed * (3/4));
	  height -= speed;
	  if(real==1)
	  {
	    if(width < myimg.smallWidth + 4)
	    {
	      myimg.style['width'] = myimg.smallWidth;
	      myimg.style['height'] = myimg.smallHeight;
		  myimg.style['top'] = 0;
	      myimg.style['left'] = 0;
		  mydiv.style['zIndex'] = 1;
	      window.clearInterval(interval);
		}
		else{
		  myimg.style['width'] = width;
	      myimg.style['height'] = height;
	      myimg.style['top'] = top + (speed/2);
	      myimg.style['left'] = left + (Math.floor(speed * (3/8)));
		}
	  }
	  else
	  {
	  	if(height < myimg.smallWidth + 4)
	    {
	      myimg.style['width'] = myimg.smallHeight;
	      myimg.style['height'] = myimg.smallWidth;
		  myimg.style['top'] = 0;
	      myimg.style['left'] = 0;
		  mydiv.style['zIndex'] = 1;
	      window.clearInterval(interval);
		}
		else{
		  myimg.style['width'] = width;
	      myimg.style['height'] = height;
	      myimg.style['top'] = top + (speed/2);
	      myimg.style['left'] = left + (Math.floor(speed * (3/8)));
		}
	  }
	}	  
  }
}
