// Set the horizontal and vertical position for the popup

PositionX = 100;
PositionY = 100;

// Set these value approximately 20 pixels greater than the
// size of the largest image to be used (needed for Netscape)

defaultWidth  = 500;
defaultHeight = 500;

// Set autoclose true to have the window close automatically
// Set autoclose false to allow multiple popup windows

var AutoClose = true;

// Set autopos true to have the window positioned automatically
// Set autopos false to allow custom window position

var AutoPos = true;

// finestra popup foto
var imgWin = null;

// ================================
if (parseInt(navigator.appVersion.charAt(0))>=4){
var isNN=(navigator.appName=="Netscape")?1:0;
var isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}
var optNN='scrollbars=no,width='+defaultWidth+',height='+defaultHeight+',left='+PositionX+',top='+PositionY;
var optIE='scrollbars=no,width=150,height=100,left='+PositionX+',top='+PositionY;
function toggleTitle(imageTitle){
	re = /\"/g;
	var r = imageTitle.replace(re, '\'');
	return(r);
}
function popImage(imageURL,imageTitle){
if (isNN){imgWin=window.open('about:blank','',optNN);}
if (isIE){imgWin=window.open('about:blank','',optIE);}
with (imgWin.document){
writeln('<html><head><title>Loading...</title><style>body{margin:0px;}</style>');writeln('<sc'+'ript>');
writeln('var isNN,isIE;');writeln('if (parseInt(navigator.appVersion.charAt(0))>=4){');
writeln('isNN=(navigator.appName=="Netscape")?1:0;');writeln('isIE=(navigator.appName.indexOf("Microsoft")!=-1)?1:0;}');
writeln('function reSizeToImage(){');writeln('if (isIE){');writeln('window.resizeTo(250,200);');
writeln('width=250-(document.body.clientWidth-document.images[0].width);');
writeln('height=200-(document.body.clientHeight-document.images[0].height);');
writeln('window.resizeTo(width,height); if (width > screen.width || height > screen.height) { document.body.scroll = "yes"; }}');writeln('if (isNN){');       
writeln('window.innerWidth=document.images["PM"].width;');writeln('window.innerHeight=document.images["PM"].height; if (document.images["PM"].width > screen.width || document.images["PM"].height > screen.height) { document.body.scroll = "yes"; }}}');
if (AutoPos) writeln('function reMoveToImage(){ window.moveTo(((screen.width - document.getElementById("PM").width) / 2),((screen.height - document.getElementById("PM").height) / 2)); }')
else writeln('function reMoveToImage(){ return; }');
writeln('function doTitle(){document.title="'+toggleTitle(imageTitle)+'";}');writeln('</sc'+'ript>');
if (!AutoClose) writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();reMoveToImage();doTitle();self.focus()">')
else writeln('</head><body bgcolor=000000 scroll="no" onload="reSizeToImage();reMoveToImage();doTitle();self.focus()" onblur="self.close()">');
writeln('<center><img name="PM" id="PM" src='+imageURL+'></center></body></html>');
close();		
}}
function setImage(imageURL,imageTitle,imageID){
	document.getElementById('imgSource').src = imageURL;
	document.getElementById('imgSource').title = imageTitle;
	if (document.getElementById('photo_title')) { document.getElementById('photo_title').value = imageTitle; }
	if (document.getElementById('photo_id')) { document.getElementById('photo_id').value = imageID; }
}
function setGalleryImage(imageName,imageURL,imageTitle,imageID,IDName){
	document.getElementById(imageName).src = imageURL;
	document.getElementById(imageName).title = imageTitle;
	document.getElementById(IDName).value = imageID;
}
function popupPhoto(photo_dir,photo_name,photo_id,photo_lastid){
	if (isNN){imgWin=window.open('photo.php?photo_dir='+photo_dir+'&photo_name='+photo_name+'&photo_id='+photo_id+'&photo_lastid='+photo_lastid,'',optNN);}
	if (isIE){imgWin=window.open('photo.php?photo_dir='+photo_dir+'&photo_name='+photo_name+'&photo_id='+photo_id+'&photo_lastid='+photo_lastid,'',optIE);}
}
function popupClose(){
	if (imgWin && !imgWin.closed) {
		imgWin.close();
	}
}
String.prototype.trim = function() {
  var x=this;
  x=x.replace(/^\s*(.*)/, "$1");
  x=x.replace(/(.*?)\s*$/, "$1");
  return x;
}

/******************************************************************************
* papamoto e-mail
******************************************************************************/

var sep = "@";
var ext_sep = ".";
var pta_descr = "mailto";
function WriteEM(nome_u, nome_d, ext_d, l_descr) {
	var pta = nome_u + sep + nome_d + ext_sep + ext_d;
	var ind = pta_descr + ":" + pta;
	var descr = ((l_descr!="") ? l_descr : pta);
	document.write(descr.link(ind));
}

/******************************************************************************
* Functions To Check an EMail Address syntax validity
******************************************************************************/

function checkMailAddress(emailStr)
{
	emailStr = emailStr.trim();
    var emailPat=/^(.+)@(.+)$/;
    var specialChars="\\(\\)<>@,;:\\\\\\\"\\.\\[\\]";
    var validChars="\[^\\s" + specialChars + "\]";
    var quotedUser="(\"[^\"]*\")";
    var ipDomainPat=/^\[(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})\]$/;
    var atom=validChars + '+';
    var word="(" + atom + "|" + quotedUser + ")";
    var userPat=new RegExp("^" + word + "(\\." + word + ")*$");
    var domainPat=new RegExp("^" + atom + "(\\." + atom +")*$");
    var matchArray=emailStr.match(emailPat);
    if (matchArray==null)
    {
        //alert("L'indirizzo email non sembra corretto. Controlla.")
        return false;
    }
    var user=matchArray[1];
    var domain=matchArray[2];

    if (user.match(userPat)==null)
    {
        //alert("Il nome utente non sembra corretto.")
        return false;
    }
    
    var IPArray=domain.match(ipDomainPat);
    if (IPArray!=null)
    {
        for (var i=1;i<=4;i++)
        {
            if (IPArray[i]>255)
            {
                //alert("L'IP di destinazione non è corretto.")
                return false;
            }
        }
        return true;
    }
    
    var domainArray=domain.match(domainPat);
    if (domainArray==null)
    {
        //alert("Il nome del dominio non sembra valido.")
        return false;
    }
    
    var atomPat=new RegExp(atom,"g");
    var domArr=domain.match(atomPat);
    var len=domArr.length;
    if (domArr[domArr.length-1].length<2 || domArr[domArr.length-1].length>3)
    {
        /*alert("L'indirizzo email deve terminare con un 
        dominio di tre lettere (.com, .net, etc...) o con due lettere 
        per i domini nazionali (.it, .fr, etc..).")*/
        return false;
    }
    
    if (len<2)
    {
        //var errStr="Questo indirizzo non presenta il nome dell'host!"
        //alert(errStr)
        return false;
    }

	var Filtro = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-]{2,})+\.)+([a-zA-Z0-9]{2,})+$/;
	return Filtro.test(emailStr);

}

//
//********************************************
//
