var ie = ((navigator.appName == "Microsoft Internet Explorer") && (navigator.userAgent.indexOf('Opera') == -1))?true:false;

window.onerror = ShowErr;
function ShowErr(err,sURL,sLine)
{
    if(sURL.indexOf('localhost')>=0) // Se  sviluppo
        alert(err+'\nLinea:'+sLine+'\nin:'+sURL);
    return true;
}

function FindCtrl(NomeId,ShowAlert)
{
    var Ret=null;
	if (ie) 
		Ret = eval('document.all.'+NomeId);
	else 
		Ret = document.getElementById(NomeId);
    if(Ret==null && ShowAlert)
        alert('Attenzione! Il controllo \''+NomeId+'\' non è stato trovato con document.'+ie?'all...':'getElementById(...');
    
    return Ret;
}

function ShowPreview(NomeTxt,NomeDiv)
{
    var Txt;
    var Div;
    Txt = FindCtrl(NomeTxt,false);
    Div = FindCtrl(NomeDiv,false);
    
    if(Txt != null && Div != null)
        Div.innerHTML = replaceAll(Txt.value, '\r', '<br>') ;
}

function ShowProd(IdProdotto)
{
    var wi = 850;
    var hi = 700;
    window.open ('/prodotto.aspx?IDP='+IdProdotto, 'Prodotto', 'toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,top=' + ((screen.height-hi)/3) + ',left=' + ((screen.width/2)- wi/2) + ',width=' + wi + ',height=' + hi);
}

function OpenUrlCenter(Dest, Trg, wi, hi)
{
   window.open (Dest, Trg, 'toolbar=no,status=no,menubar=no,scrollbars=no,resizable=no,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);
}

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 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 ShowZoom(FILE,WID,HEI)
{
    var LEFT = ((screen.width-WID)/2);
    var TOP = ((screen.height-HEI)/2);
	var wndParams = "scrollbars=no,resizable=no,location=no,menubar=no,status=no,width=" + WID + ",height=" + HEI;
	wndParams += ",left="+LEFT+",top="+TOP;
	var html = "<html><head><title>Italauto<\/title><\/head>";
	html += "<body onload='self.focus();' 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-repeat:no-repeat;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();
}