// JavaScript Document

function enviarform(archivo, comentarios)
{
	//alert (comentarios);
	if (comentarios == "") {
		alert ("Rellene campo Comentarios");
	} else {
	document.formulario.action = "/php/"+archivo+".php";
	document.formulario.submit();
	}
}


function favoritos(url,name){
   if ((navigator.appName=="Microsoft Internet Explorer") && 
         (parseInt(navigator.appVersion)>=4)) {
      window.external.AddFavorite(url,name);
   } else { 
      if(navigator.appName == "Netscape") 
         alert("Crtl+D para añadir esta página a favoritos."); 
   }
}

function mostrar(ref) {
	//alert(_img_grande.width);
	//alert(_img_grande.height);
	
	if (_img_grande.width<20) 
	_img_grande.width = 300;
	if (_img_grande.height<20) 
	_img_grande.height = 400;
	
	//alert(_img_grande.width);
	//alert(_img_grande.height);
	var ops = "top=" + ((screen.height - _img_grande.height) / 2);
	ops += ",left=" + ((screen.width - _img_grande.width) / 2);
	ops += ",width=" + _img_grande.width + ",height=" + _img_grande.height;
	var contenido = "<html>\n<head>\n<title>Foto "+ref+"</title>\n<body style='background-image: url(" + _img_grande.src + ")'></body></html>";
	var ventana = window.open("", "", ops);
	
	ventana.document.open();
	ventana.document.write(contenido);
	ventana.document.close();  //caricatos
}

function cargando(ref) {
	if (_img_grande.complete) mostrar(ref);
	else setTimeout("cargando()", 200);
}

function abrir(urlfoto,titulo)	{
	_img_grande = new Image();
	_img_grande.src = urlfoto;
	cargando(titulo);
}

/* Funcions lightbox */

function showBox(num){
    $('overlay'+num).show();
    center('box'+num);
    return false;
}

function hideBox(num){
    $('box'+num).hide();
    $('overlay'+num).hide();
    return false;
}

function center(element){
    try{
        element = $(element);
    }catch(e){
        return;
    }

    var my_width  = 0;
    var my_height = 0;

    if ( typeof( window.innerWidth ) == 'number' ){
        my_width  = window.innerWidth;
        my_height = window.innerHeight;
    }else if ( document.documentElement && 
             ( document.documentElement.clientWidth ||
               document.documentElement.clientHeight ) ){
        my_width  = document.documentElement.clientWidth;
        my_height = document.documentElement.clientHeight;
    }
    else if ( document.body && 
            ( document.body.clientWidth || document.body.clientHeight ) ){
        my_width  = document.body.clientWidth;
        my_height = document.body.clientHeight;
    }

    element.style.position = 'absolute';
    element.style.zIndex   = 99;

    var scrollY = 0;

    if ( document.documentElement && document.documentElement.scrollTop ){
        scrollY = document.documentElement.scrollTop;
    }else if ( document.body && document.body.scrollTop ){
        scrollY = document.body.scrollTop;
    }else if ( window.pageYOffset ){
        scrollY = window.pageYOffset;
    }else if ( window.scrollY ){
        scrollY = window.scrollY;
    }

    var elementDimensions = Element.getDimensions(element);

    var setX = ( my_width  - elementDimensions.width  ) / 2;
    var setY = ( my_height - elementDimensions.height ) / 2 + scrollY;

    setX = ( setX < 0 ) ? 0 : setX;
    setY = ( setY < 0 ) ? 0 : setY;

    element.style.left = setX + "px";
    element.style.top  = setY + "px";

    element.style.display  = 'block';
}
/* FI -- Funcions lightbox */
