// Abrir um popup de uma imagem
// http://www.therotunda.net/code/autosized-popup-window.html


function viewPic(img,titulo)
{ 	
    picfile = new Image(); 
    picfile.src =(img); 
    fileCheck(img,titulo); 
}


function fileCheck(img,titulo)
{ 	
    if( (picfile.width!=0) && (picfile.height!=0) )
    { 
        makeWindow(img,titulo); 
    }
    else 
    {
        funzione="fileCheck('"+img+"')"; 
        intervallo=setTimeout(funzione,50); 
    }
}


function makeWindow(img,titulo)
{ 	
    ht = picfile.height;
    wd = picfile.width;
    
    //So funciona bem para as imagens dos mapas (estrilhava com o IE), 
    //se for para meter outras imagens, meter um parametro com o tamanho das imagens
    if(ht>wd){
        ht=400;
        wd=300;
    }
    else{
        ht=300;
        wd=400;
    }
    

    var args= "height=" + (ht+12) + ",innerHeight=" + ht;
    args += ",width=" + (wd+12) + ",innerWidth=" + wd;
    if (window.screen) 
    { 
        var avht = screen.availHeight; 
        var avwd = screen.availWidth;
        var xcen = (avwd - wd) / 2; 
        var ycen = (avht - ht) / 2;
        args += ",left=" + xcen + ",screenX=" + xcen;
        args += ",top=" + ycen + ",screenY=" + ycen + ",resizable=no"; 	
    }
    popwin=window.open("","_blank",args);
    popwin.document.open();
    popwin.document.write('<html><head><title>'+titulo+'</title></head><body bgcolor=white scroll=no topmargin=0 leftmargin=0 rightmargin=0 bottomargin=0 marginheight=0 marginwidth=0> <div style="position: absolute; top:5px;left:5px;"><a href="javascript:window.close()"><img src="'+img+'" width="'+wd+'" height="'+ht+'" style="border-width:1px;border-style:solid;border-color:black;" ></a></div></body></html>')
    return popwin.document.close();

} 

