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 MsOverMn(Obj,Sopra)
{
	if( Obj.style )
	{
		if(Sopra == true)
		{
			Obj.style.backgroundColor='#deb887';
			Obj.style.fontColor='#000000';
		}
		else
		{
			Obj.style.backgroundColor='';
			Obj.style.fontColor='#000000';
		}
	}
}
*/

var OldNumMenu=-1;
var MouseOverMenu=false;

function ShowMenu(NumMenu,Stato,Ypos)
{
	if(Stato == true)
	{
	    setTimeout("ChkMenuOpen()",  2000);

		if(OldNumMenu>=0)
		    ShowMenu(OldNumMenu,false);

		if(NumMenu>=0)
		{
			eval('document.all.Menu' + NumMenu + '.className="visibile"');
			eval('document.all.Menu' + NumMenu + '.style.top='+Ypos);
			eval('document.all.Menu' + NumMenu + '.style.left=150');
			OldNumMenu = NumMenu;
		}
	}
	else
	{
		if( NumMenu >= 0)
		    OldNumMenu = NumMenu;
		    
		if( OldNumMenu >= 0)
		    eval('document.all.Menu' + OldNumMenu + '.className="nascosto"');
		    
		OldNumMenu = -1;
		SetMouseOver(false);
	}
}
function ChkMenuOpen()
{
    if(MouseOverMenu==true)
        setTimeout("ChkMenuOpen()",  2000);
    else
        ShowMenu(OldNumMenu,false);
}

function SetMouseOver(Stato)
{
    MouseOverMenu=Stato;
}


function SelTab(Obj,Sopra)
{
	if( Obj.style )
	{
		if(Sopra == true)
		{
			Obj.style.backgroundColor='#deb887';
			Obj.style.fontColor='#000000';
		}
		else
		{
			Obj.style.backgroundColor='99ccff';
			Obj.style.fontColor='#000000';
		}
	}
}

function MenuAltoOver(Obj,Sopra)
{
	if(Sopra == true)
	{
		Obj.className="SelMenuAltoOver";
	}
	else
	{
		Obj.className="SelMenuAltoOut";
	}
}

function ShowMenuAlto(NumMenu,Stato,Xpos)
{
	if(Stato == true)
	{
	    setTimeout("ChkMenuOpen()",  2000);
	    
		if(OldNumMenu>=0)
		    ShowMenuAlto(OldNumMenu,false);

		/*eval('document.all.Menu' + NumMenu + '.className="visibile"');
		eval('document.all.Menu' + NumMenu + '.style.top=45');
		eval('document.all.Menu' + NumMenu + '.style.left='+Xpos);*/
		OldNumMenu = NumMenu;
	}
	else
	{
		if( NumMenu >= 0)
		    OldNumMenu = NumMenu;
		    
		if( OldNumMenu >= 0)
		    eval('document.all.Menu' + OldNumMenu + '.className="nascosto"');
		    
		OldNumMenu = -1;
		SetMouseOver(false);
	}
}
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 OpenHelp(CodHelp)
{
    wi=600;//screen.height/1.5;
    hi=screen.height/1.5;
    win=window.open ('/help/help.aspx?Main=Si&CodHelp='+CodHelp, 'WinHelp', 'toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=0,left=' + (screen.width-wi-10) + ',width=' + wi + ',height=' + hi);
    win.focus();
}

function Stampa(Param)
{
    var wi=830;
    var hi=screen.height-100;
    
    //window.open ("/utility/stampa/stampa_loading.aspx?"+Param,"PREVIEW_STAMPA_OUC", "toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,top=0,left=" + ((screen.width/2)- wi/2) + ",width=" + wi + ",height=" + hi);
    window.open ("/utility/stampa/stampa.aspx?"+Param,"PREVIEW_STAMPA_OUC", "toolbar=no,status=no,menubar=no,scrollbars=no,resizable=yes,top=0,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);
}

function SelezionaTesto(ObjTxt,Valore) //NomeTxt)
{
   if(Valore == ObjTxt.value)
        ObjTxt.value = "";
}

/*****************************************
	Controllo della Partita I.V.A.
	Linguaggio: JavaScript
******************************************/
function IsPartitaIVA(pi)
{
	if( pi == '' )
	{
		return true;
	}

	if( pi.length != 11 )
	{
		return false;
	}

	validi = "0123456789";
	for( i = 0; i < 11; i++ ){
		if( validi.indexOf( pi.charAt(i) ) == -1 )
		{
			return false;
	    }
	}
	s = 0;
	for( i = 0; i <= 9; i += 2 )
		s += pi.charCodeAt(i) - '0'.charCodeAt(0);
	for( i = 1; i <= 9; i += 2 ){
		c = 2*( pi.charCodeAt(i) - '0'.charCodeAt(0) );
		if( c > 9 )  c = c - 9;
		s += c;
	}
	if( ( 10 - s%10 )%10 != pi.charCodeAt(10) - '0'.charCodeAt(0) )
	{
		return false;
	}
	return true;
}

function OpenSetColor(Preview,NomeCampo,Titolo)
{
   wi = 450;
   hi = 300;
   window.open('/utility/scegli_colore.aspx?Preview='+Preview+'&Campo='+NomeCampo+'&Titolo='+Titolo,'SetColor','toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,top=100,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;
        }
}

/*
var oPopup = window.createPopup();
function ShowToolTips(Titolo,Txt,Obj)
{
    var oPopBody = oPopup.document.body;
    oPopBody.style.backgroundColor = "lightyellow";
    oPopBody.style.border = "solid black 1px";
    oPopBody.innerHTML = Txt;
    oPopup.show(event.x, event.y, 300, 250, document.body);
}*/
/* <<< TOOLTIPS */



function OpenTrad(Param)
{
    var wi=760;
    var hi=400;
    var Trg='EDIT_TRADUZIONI';
    var Dest = '/ControlliUtente/TraduzioneOggetti/edit_traduzione_oggetti.aspx?'+Param;
    window.open (Dest, Trg, 'toolbar=no,status=no,menubar=no,scrollbars=yes,resizable=yes,top=' + ((screen.height-hi)/2) + ',left=' + ((screen.width/2)- wi/2) + ',width=' + wi + ',height=' + hi);
}

function TradResize()
{
    var Width = 760
    var Height = screen.height-100;
    var Left = ((screen.width/2)- Width/2);
    var Top = 0;
    
    self.moveTo(Left,Top);
    self.resizeTo(Width,Height);
}

function ShowHideAvanzate(Oggetto)
{
	var Obj = (document.all) ? eval('document.all.' + Oggetto) : document.getElementById(Oggetto);
    if(Obj.className == HideClass)
    {
        Obj.className = ShowClass;
        Obj.style.position='relative';
    }
    else
    {
		Obj.className = HideClass;
		if(document.all==null)
		    Obj.style.position='absolute';
    }
}

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 replaceAll(sString, sReplaceThis, sWithThis) 
{ 
    if (sReplaceThis != "" && sReplaceThis != sWithThis) 
    { 
        var counter = 0; 
        var start = 0; 
        var before = ""; 
        var after = ""; 
        while (counter<sString.length) 
        { 
            start = sString.indexOf(sReplaceThis, counter); 
            if (start == -1) 
            { 
                break; 
            } 
            else 
            { 
                before = sString.substr(0, start); 
                after = sString.substr(start + sReplaceThis.length, sString.length); 
                sString = before + sWithThis + after; 
                counter = before.length + sWithThis.length; 
            } 
        } 
    } 
    return sString; 
} 


var wndZoom = null;
function MostraIngrandimento(FILE,WID,HEI)
{
	var wndParams = "scrollbars=no,resizable=no,location=no,menubar=no,status=no,width=" + WID + ",height=" + HEI;
	var html = "<html><head><title>LaLocandina.it<\/title><\/head>";
	html += "<body style=\"margin-top: 0px; margin-bottom: 0px; margin-left: 0px; margin-right: 0px;\">";
	html += "<table cellpadding=\"0\" cellspacing=\"0\" style=\"width: 100%; height:100%;\"><tr style=\"cursor:pointer;cursor:hand;\">";
	html += "<td style=\"background-image: url(" + FILE + ");\" onclick=\"self.close();\">";
	html += "<img src=\"/images/spacer_trasp.gif\" border=\"0\" width=\"" + WID + "\" height=\"1\">";
	html += "<\/td><\/tr><\/table><\/body><\/html>";
	if(wndZoom) { if(!wndZoom.closed) { wndZoom.close(); }}
	wndZoom = open('', 'Zoom', wndParams);
	wndZoom.document.write(html);
	wndZoom.document.close();
}

function ShowHideAvanzate(Oggetto)
{
    var Obj = FindCtrl(Oggetto);
    if(Obj.className == 'ShowObj')
        Obj.className = 'HideObj';
    else
        Obj.className = 'ShowObj';
}


function SelectFromListboxToTextbox(NomeListbox, NomeTxtbox, bolAppend) // ByValue
{
    ObjList = FindCtrl(NomeListbox);
    ObjTxt = FindCtrl(NomeTxtbox);
    if(ObjList!=null && ObjTxt!=null)
    {
        if(ObjList.selectedIndex!=null && ObjList.selectedIndex>=0)
        {
            if(bolAppend)
                ObjTxt.value += ObjList.options[ObjList.selectedIndex].value;
            else
                ObjTxt.value = ObjList.options[ObjList.selectedIndex].value;
            ObjTxt.focus();
            ObjTxt.selectionEnd = ObjTxt.textLength;
        }
    }
}

function SelectFromListboxToTextboxByText(NomeListbox, NomeTxtbox, bolAppend)
{
    ObjList = FindCtrl(NomeListbox);
    ObjTxt = FindCtrl(NomeTxtbox);
    if(ObjList!=null && ObjTxt!=null)
    {
        if(ObjList.selectedIndex!=null && ObjList.selectedIndex>=0)
        {
            if(bolAppend)
                ObjTxt.value += ObjList.options[ObjList.selectedIndex].text;
            else
                ObjTxt.value = ObjList.options[ObjList.selectedIndex].text;
            ObjTxt.focus();
            ObjTxt.selectionEnd = ObjTxt.textLength;
        }
    }
}

