var NS4 = (document.layers)?true:false;
var IE4 = (document.all && !document.getElementById)?true:false;
var IE5 = (document.all && document.getElementById)?true:false;
var MZ1 = (!document.all && document.getElementById)?true:false;
var GKO = (document.getElementById && navigator.appName.indexOf("Netscape")>=0)?true:false;
var W3C = (document.getElementById)?true:false;

//alert(NS4+'-'+IE4+'-'+IE5+'-'+MZ1+'-'+GKO+'-'+W3C);

function sendOpenerData(openerpage,idfoto)
{
//    alert ('Openerpage:'+openerpage+' - IdFoto:'+idfoto);
    var mainform = window.opener.document.searchform;
    mainform.action.value ='addimg';
//    alert ('aaa'+window.opener.document.searchform.action);
    mainform.d_idfoto.value = idfoto;
//    mainform.d_idtipocarta.value = idfoto;
    var popupform = this.document.popupform;
//alert(popupform.d_tipofoto.length);
    mainform.d_idimmagine.value = popupform.d_idimmagine.value;
//alert (popupform.d_idtipocarta.length+'  '+popupform.d_idtipocarta.value+' - '+popupform.d_idtipocarta.checked);
//alert (popupform.d_idformato.length+'  '+popupform.d_idformato.value+' - '+popupform.d_idformato.checked);
    if (typeof(popupform.d_idtipocarta.length) == 'undefined')
    {
        if (popupform.d_idtipocarta.checked)
            mainform.d_idtipocarta.value = popupform.d_idtipocarta.value;
    }
    else
    {
        for (i=0; i < popupform.d_idtipocarta.length; i++)
        {
            if (popupform.d_idtipocarta[i].checked)
                mainform.d_idtipocarta.value = popupform.d_idtipocarta[i].value;
        }
    }
    if (typeof(popupform.d_tipofoto.length) == 'undefined')
    {
        if (popupform.d_tipofoto.checked)
            mainform.d_tipofoto.value = popupform.d_tipofoto.value;
    }
    else
    {
        for (i=0; i < popupform.d_tipofoto.length; i++)
        {
            if (popupform.d_tipofoto[i].checked)
                mainform.d_tipofoto.value = popupform.d_tipofoto[i].value;
        }
    }
    if (typeof(popupform.d_idformato.length) == 'undefined')
    {
        if (popupform.d_idformato.checked)
            mainform.d_idformato.value = popupform.d_idformato.value;
    }
    else
    {
        for (i=0; i < popupform.d_idformato.length; i++)
        {
            if (popupform.d_idformato[i].checked)
                mainform.d_idformato.value = popupform.d_idformato[i].value;
        }
    }
//    alert ('aaa'+mainform.action);
    
    mainform.submit();
    this.window.close();
    return;

}



/* popup */
function openPopup(urlpopup,nomepopup,w,h,settingspopup)
{
    var x=(screen.width-w)/2
    var y=(screen.height-h)/2-20
    if(x<0)x=0
    if(y<0)y=0
    if(w>screen.width)w=screen.width
    if(h>screen.height)h=screen.height
    var settings='top='+y+',left='+x+',width='+w+',height='+h+','+settingspopup
    var popup=window.open(urlpopup,nomepopup,settings)
    popup.focus()
}

function closePopup()
{
    window.close()
}
/*
function GetRef(hourdata){
  if (NS4){var o=eval('document.'+ 'popdata' + hourdata);}
  else if (IE5){var o=document.all['popdata' + hourdata];}
  else if (W3C||MZ1){var o=document.getElementById('popdata' + hourdata);}
  return o;
}
*/
function GetRef(hourdata){
  if (NS4){var o=eval('document.'+ hourdata);}
  else if (IE5){var o=document.all[ hourdata];}
  else if (W3C||MZ1){var o=document.getElementById(hourdata);}
  return o;
}
function showdiv(hourdata,evento)
{
//        alert(hourdata);

//        alert(msg);

        var layref = GetRef(hourdata);
//        var layref = window.document.all['popdata1_102'];

//        alert('Layref '+layref);
//        alert('Layref.ID '+layref.id);

        //alert(inizio);
        //layref.style.top = inizio;
        //layref.style.left = left;
        if (IE5)
        {
            //alert(document.body.pageXOffset);
            //alert(document.body.scrollTop);
            var y = evento.clientY + document.body.scrollTop ;
            var x = evento.clientX + document.body.scrollLeft ;
        }

        else if ( (MZ1) || (NS4) )
        {
            var y = evento.pageY;
            var x = evento.pageX;
        }

//        layref.style.top = y + 20 ;
//        layref.style.left = x - 95 ;

//alert(x+'-'+y);
        if (NS4){
//            layref.top = y +20;
            layref.top = y - 120;
//            layref.left = x - 95;
            layref.left = x + 15;
            layref.hidden=false
        }
        else if (IE5||MZ1)
        {
//            layref.style.top = y + 20 ;
            layref.style.top = y - 120 ;
            layref.top = y - 120 ;
//alert(layref.top+'-'+layref.style.top);
//alert(layref.style);
//            layref.style.left = x - 95 ;
            layref.style.left = x + 15;
            layref.left = x + 15;
            layref.style.visibility="visible";
//alert(layref.style.visibility);
        }
        //layref.style.visibility = "visible";

        //document.all['popdata' + hourdata].style.visibility = "visible";
        //alert('popdata' + hourdata);
}
/*
function showdiv(hourdata,evento,msg,wind)
{
    if (msg.length > 1 )
    {
        var layref = GetRef(hourdata);
        //alert(inizio);
        //layref.style.top = inizio;
        //layref.style.left = left;
        if (IE5)
        {
            //alert(document.body.pageXOffset);
            //alert(document.body.scrollTop);
            var y = evento.clientY + document.body.scrollTop ;
            var x = evento.clientX + document.body.scrollLeft ;
        }

        else if ( (MZ1) || (NS4) )
        {
            var y = evento.pageY;
            var x = evento.pageX;
        }

//        layref.style.top = y + 20 ;
//        layref.style.left = x - 95 ;

        if (NS4){
            layref.top = y +20;
            layref.left = x; // - 95;
            layref.hidden=false
alert ("NS4");
        }
        else if (IE5||MZ1)
        {
            layref.style.top = y + 20 ;
            layref.style.left = x ; //- 95 ;
            layref.style.visibility="visible";
//alert ("MZ1");
        }
        //layref.style.visibility = "visible";

        //document.all['popdata' + hourdata].style.visibility = "visible";
        //alert('popdata' + hourdata);
    }
}
*/

function hidediv(hourdata)
{
    var layref = GetRef(hourdata);
    if (NS4){layref.hidden=true}
    else if (IE5||W3C){layref.style.visibility="hidden"}
    //layref.style.visibility = "hidden";
}

function displayfield(fieldname, fieldcheck,rowname)
{
    var rowDisplayStyle = document.defaultView ? "table-row" : "block"; // table-row for Mozilla and Opera, block for MSIE
    var found = false;
//alert('Fieldname:'+fieldname+' - Rowname: '+rowname);
    var fieldval = this.window.document.getElementById(fieldname).value;
//alert('Fieldname:'+fieldname+' - Fieldval: '+fieldval+' - FieldCheck: '+fieldcheck+' - Rowname: '+rowname);


    if (fieldval == fieldcheck)
    {
        this.window.document.getElementById(rowname).style.display = rowDisplayStyle;
/*        this.window.document.getElementById(disabledrowname).style.display = 'none';            */
    }
    else
    {
        this.window.document.getElementById(rowname).style.display = 'none';
/*        this.window.document.getElementById(disabledrowname).style.display = rowDisplayStyle;        */
    }
    if (fieldval == 'true')
    {
        this.window.document.getElementById(fieldname).value = false;
    }
    else
        this.window.document.getElementById(fieldname).value = true;
//alert('Fieldname:'+fieldname+' - Fieldval: '+fieldval+' - Not Fieldval: '+!(fieldval)+' - Rowname: '+rowname+'--'+document.popupform.check_chisiamo.value);
//alert('Fieldname:'+fieldname+' - Fieldval: '+fieldval+' - Not Fieldval: '+!(fieldval)+' - Rowname: '+rowname+'--'+this.window.document.getElementById(fieldname).value);
}

function check_sped()
{
//    alert(this.window.document.searchform.d_tipopagamento[0].checked);
    var sped_type;
    for (i = 0; i < document.searchform.d_tipopagamento.length; i++)
    {
        if (document.searchform.d_tipopagamento[i].checked == true)
            sped_type = document.searchform.d_tipopagamento[i].value;
    }
//        alert(sped_type);

}
/*
function Disable() {
if (event.button == 2) 
{
alert("This action is not possible")
}
}
document.onmousedown=Disable;
*/

