if(document.location.href.indexOf('.qntdev.com') < 0) // Se  sviluppo
    window.onerror = ShowErr;

function ShowErr(err,sURL,sLine)
{
    try 
    {
        var HtmlMsg = '';
        msgArray = new Array();
        urlArray = new Array();
        lnoArray = new Array();
        msgArray[msgArray.length] = err;
        urlArray[urlArray.length] = sURL;
        lnoArray[lnoArray.length] = sLine;
        var MsgErr = '';
        var Em = FindCtrl('ErrorMessage',false);
        if(Em!=null)
        {
            for (var i=0; i < msgArray.length; i++) 
            {
                MsgErr += 'Errore:[' + msgArray[i] + ']';
                MsgErr += '  nel File:[' + urlArray[i] + '] alla linea:[' + lnoArray[i] + ']';
            }

            MsgErr = MsgErr.replace("'","\'");
            HtmlMsg = '<image src="/utility/InvioEmailErrJs.aspx?ErrJs='+MsgErr+'" width="1" height="1" border="0" style="position:absolute;display:none">';
            Em.innerHTML += HtmlMsg;
        }
        else    // Html ancora non creato
        {
        }
        return true;
    }
    catch(er)
    {
        alert(err+'\nLinea:'+sLine+'\nin:'+sURL);
        return false;
    }
}

var IsIE = (document.all) ? true:false;
function FindCtrl(NomeId,ShowAlert)
{
    var Ret=null;
	if (IsIE) 
		Ret = eval('document.all.'+NomeId);
	else 
		Ret = document.getElementById(NomeId);
    if(Ret==null && ShowAlert)
        alert('Attenzione! Il controllo \''+NomeId+'\' non è stato trovato con document.'+IsIE?'all...':'getElementById(...');
    
    return Ret;
}

function OpenUrlDialogCenter(Dest, wi, hi)
{
   var top=(screen.height-hi)/2;
   var left=(screen.width/2)- (wi/2);
   //window.showModelessDialog(Dest,"","dialogHeight: '+hi+'; dialogWidth: '+wi+'px; edge: Sunken; center: Yes; help: No; resizable: No; status: No;");
   window.showModalDialog(Dest,"","dialogHeight: '+hi+'; dialogWidth: '+wi+'px; edge: Sunken; center: Yes; help: No; resizable: No; status: No;");
}

function OpenUrlCenter(Dest, Trg, wi, hi)
{
   window.open (Dest, Trg, 'toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,top=' + ((screen.height-hi)/2) + ',left=' + ((screen.width/2)- wi/2) + ',width=' + wi + ',height=' + hi);
}

function OpenUrlTop(Dest, Trg, wi, hi)
{
   window.open (Dest, Trg, "toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=0,left=" + ((screen.width/2)- wi/2) + ",width=" + wi + ",height=" + hi);
}


/* >>> TOOLTIPS */
var ViewToolTip = false;
var OldBackGround=null;
var OldSpan=null;

function CloseToolTips() 
{
    ViewToolTip = false;
    var SHOW_TOOLTIPS = FindCtrl('SHOW_TOOLTIPS');
    if(SHOW_TOOLTIPS!=null)
        SHOW_TOOLTIPS.style.display='none';
        
    if(OldSpan!=null && OldSpan.style!=null && OldBackGround!=null)
        OldSpan.style.background=OldBackGround==null?'':OldBackGround;
}

function ShowToolTips(Titolo,Txt,Obj)
{
    var SHOW_TOOLTIPS = FindCtrl('SHOW_TOOLTIPS');
//    if(document.all!=null)
//    {
        OldSpan=Obj;
        ViewToolTip = true;
	    var posx = 0;
	    var posy = 0;
	    var TitoloForm='';
	    var Img = '';
	    if (!e) var e = window.event;
	    if(e==null)
	        return false;
	    if (e.pageX || e.pageY)
	    {
		    posx = e.pageX;
		    posy = e.pageY;
	    }
	    else if (e.clientX || e.clientY)
	    {
		    posx = e.clientX + document.body.scrollLeft;
		    posy = e.clientY + document.body.scrollTop;
	    }
	    Img = '<img src="/images/icone/ico_tips.gif" align="absMiddle" hspace="4" vspace="4" width="16px" height="16px" border="0">';

        TitoloForm =Img+'<span style="font-weight:bold;">'+Titolo+'</span><br>';
        TitoloForm+='<img id="lineaToolTips" src="/images/spacer.gif" style="background-color:#996600;" vspace="1" width="300" height="1" border="0"><br>';
        
        var Tt = null;
        if(SHOW_TOOLTIPS!=null)
        {
            Tt=SHOW_TOOLTIPS;
            Tt.innerHTML = TitoloForm+Txt;
        }
        else
        {
            var txtDiv = '<div id="SHOW_TOOLTIPS" OnClick="CloseToolTips();" OnMouseOut="CloseToolTips();" ';
            txtDiv += 'style="';
            txtDiv += 'border: solid 1px #996600;background-color:#FFFFCC;';
            txtDiv += 'padding:0px 4px 4px 2px;';
            txtDiv += 'display:inline; position: absolute;z-index:10000;';
            txtDiv += 'filter: progid:DXimageTransform.Microsoft.dropshadow(OffX=4,OffY=4, Color=#88666633, Positive=true);';
            txtDiv += 'visibility:visible;';
            txtDiv += '">';
            txtDiv += TitoloForm+Txt;
            txtDiv += '</div>';
            document.forms[0].innerHTML += txtDiv;
            
            Tt = FindCtrl('SHOW_TOOLTIPS');
        }
                
        if(Obj!=null && Obj.style!=null)
        {
            OldBackGround=Obj.style.background;
            Obj.style.background='#FFFFAA';
        }
        
        if(Tt!=null)
        {
            if(ViewToolTip)
                Tt.style.display = 'block';
            else
                CloseToolTips();
            nX=posx+10;
            nY=posy+10;
            
            if(nX + Tt.clientWidth > document.width)
                nX = document.width - Tt.clientWidth;
                
            if(nY + Tt.clientHeight > document.height)
                nY = document.height - Tt.clientHeight;
            
            if(document.images && document.images.lineaToolTips)
                document.images.lineaToolTips.style.width=Tt.clientWidth-10;
                
            if(nX<0) nX=0;
            if(nY<0) nY=0;
            
            Tt.style.left = nX;
            Tt.style.top  = nY;
        }
}

/* <<< TOOLTIPS */

function setOpacity(Obj,value)
{
    if(Obj != null && Obj.style != null && Obj.style.opacity != null && Obj.style.filter != null)
    {
	    Obj.style.opacity = value/10;
	    Obj.style.filter = 'alpha(opacity=' + value*10 + ')';
    }
}

function ReplaceParamValueInUrl(Url,Parametro,Valore)
{
    if(Url != null && Url != '' && Parametro != null && Parametro != '')
    {
        var Ret;
        var StartPos;
        var EndPos
        Pos=-1;
        Ret = '';
        if((StartPos = Url.indexOf(Parametro))>-1)  // Elimina il parametro
        {
            Ret = Url.substring(0,StartPos-1);
            if( (EndPos = Url.indexOf('&',StartPos+1)) > -1 )
                Ret += Url.substring(EndPos);
        }
        else
            Ret = Url;
            
        if(Ret.indexOf('?')<0)      // Non trovato
            return Ret + '?' + Parametro + '=' + Valore;
        else
            return Ret + '&' + Parametro + '=' + Valore;
    }
}

function ResizeImg(img)
{
    var maxW = 300.00;
    var maxH = 300.00;
    var srcW = img.width;
    var srcH = img.height;
    var Scale1 = (maxW / srcW);
    var Scale2 = (maxH / srcH);
    var Scale = (Scale1 <= Scale2) ? Scale1 : Scale2;
    img.width = parseInt(srcW * Scale);
    img.height = parseInt(srcH * Scale);
}