<!--
//(c) 2010 - ECOCERVED SCARL
//	- Sergio Spinato - 
	

	var ah=screen.availHeight; 
	var aw=screen.availWidth;
	var reply;
	var New_Win;
	var timeId;
	var pluginFound = false;
		
	if (!navigator.cookieEnabled)
	{
		location="nocookies.asp"
	}
	
//

function detectEcoWebSign() {
    var ret = false;
    if (navigator.userAgent.indexOf('MSIE') == -1) {
        if (detectPlugin()) {
			ret = detectPlugin('EcoWebSign');
        } 
    }

    return ret;
}


function detectPlugin() {
    var daPlugins = detectPlugin.arguments;
    var pluginFound = false;

    if (navigator.plugins && navigator.plugins.length > 0) {
		var pluginsArrayLength = navigator.plugins.length;

		for (pluginsArrayCounter=0; pluginsArrayCounter < pluginsArrayLength; pluginsArrayCounter++ ) {
			var numFound = 0;

			for (namesCounter = 0; namesCounter < daPlugins.length; namesCounter++) {
				if ((navigator.plugins[pluginsArrayCounter].name.indexOf(daPlugins[namesCounter]) >= 0) || 
					(navigator.plugins[pluginsArrayCounter].description.indexOf(daPlugins[namesCounter]) >= 0) ) {
						numFound++;
				}   
			}

			if(numFound == daPlugins.length) {
				pluginFound = true;
				break;
			}
		}
    }

    return pluginFound;
} // detectPlugin


// 06/03/2006 Lev - inizio
// F.ne per conferma pagamento via convenzione da archivio
function payConvByArch(nextPage,type)
{
	var strMessage;
	
	try
	{
		switch(type.toString())
		{
			case 'UNL':
				strMessage='Il sistema addebitera` l`importo alla disponibilita` della convenzione illimitata';
			break;
			case 'LIM':
				strMessage='Il sistema scalera` dal totale della convenzione l`importo dei diritti per questa dichiarazione';
			break;
		}
		strMessage=strMessage +'\n- OK per procedere';
		
		if(confirm(strMessage))
		{
			location=nextPage;
		}
	}
	catch(e)
	{
		//alert(e);
	}
}
// nuove F.ni per azioni con KO dalla banca
function banKODelete(nextPage)
{
	try
	{
		if(confirm('La cancellazione e` definitiva.\nCancellare questa dichiarazione ?\n\n- OK per cancellare'))
		{
			location=nextPage;			
		}
	}
	catch(e)
	{}
	
}

function banKOArchive(nextPage)
{
	try
	{
	if(confirm('La dichiarazione sara` archiviata e rimarra` in attesa di pagamento in archivio.\nArchiviare questa dichiarazione ?\n\n- OK per archiviare'))
		{
			location=nextPage;
		}
	}
	catch(e)
	{}


}

// inserite nuove funzioni per gestione messaggistica VFU
function askForVFUArchive()
{
	try
	{
		var strTest="L`operazione e` definitiva. Al termine riceverete una email di conferma\n- OK per procedere";
		if(confirm(strTest))
			return true;
		else
			return false;
	}
	catch(e)
	{
		//alert(e);
	}
}


// 06/03/2006 Lev - fine
	

	function fill_bar()
	{
		try
		{
			self_fill_bar();
			timeId=self.setInterval("self_fill_bar()",1000);
			
		}
		catch(e)
		{}
	}
	
	function self_fill_bar()
	{
		var i;
		var totCount=10;
		try
		{
			for (i=1; i<=totCount; i++)
			{
				add_bar(i);		
				self.setTimeout("",50);
			}
			
			self.setTimeout("sub_bar()",150);
				
				

		}
		catch(e)
		{}
		
	}		
		
	function sub_bar()
	{
		var k;
		try
		{
			for (k=10; k>0; k--)
			{
				document.getElementById(k).style.visibility ="hidden";
			}	
		}
		catch(e)
		{}
		
	}	
	
	function add_bar(i)
	{
		try
		{
			document.getElementById(i).style.visibility ="visible";
		
		}
		catch(e)
		{}
		
	}	

		
	function handle_descr(){
		var strdescr=new String();
		var diff;
		strdescr=document.frm_mud_pay.pay_notes.value;
		diff=249-strdescr.length;
		if (diff < 0){
			alert ('sono stati raggiunti i 250 caratteri');
			return false
		}
		window.status='Annotazioni : rimangono '+(diff)+' caratteri';
	}


	function CheckConvData()
	{
		var curImporto;
		var strUnLimited;
		var blReply=false;
		curImporto=document.frm_conv.totvalue.value;
		strUnLimited=document.frm_conv.UNLIMITED.checked;
		if (strUnLimited)
		{
			
			if (confirm('ATTENZIONE!\nSpuntando `Convenzione illimitata` non e` necessario impostare l`importo complessivo\n- OK per proseguire\n- Annulla per modificare'))
			{
				blReply=true;
				document.frm_conv.totvalue.value='0,00';
			}
			else
			{
				document.frm_conv.UNLIMITED.checked=false;
				document.frm_addValue.addvalue.focus();
				return false
			}
		}
		if (curImporto=='0,00' && !blReply)
		{
			alert('Impostare un importo complessivo diverso da zero');
			document.frm_addValue.addvalue.focus();
			return false
		}
			
	}
	
	
	function CheckDelDich(page)
	{
		var reply;
		var str=page;
		
		reply=confirm('Confermate la cancellazione definitiva di questa dichiarazione dal sistema ?\n- OK per cancellare')
		if (reply)
		{
			window.top.location=str;
		}
	}
	
	
	function pleaseWait()
	{
	    
		try
		{
			document.getElementById ("loading").style.visibility ="visible";	
			enableUploadButtons()		
		}
		catch(ExcOBJ)
		{
			self.setTimeout ("pleaseWait()",2000);

		}	
	}
	
	function DisableButton_Inline()
	{
		try
		{
			if (!document.frm_services.back.disabled)
			{
				document.frm_services.back.disabled=true;
			}
			if (!document.frm_services.annulla.disabled){
				document.frm_services.annulla.disabled=true;
			}
		}
		catch(e)	
		{
			self.setTimeout("DisableButton_Inline()",150);
		}
	}

		
	function ScaricaDistinta (page)
	{
		var strPage=page;
		ApriHelp(strPage,'chiudi')

	}

	function ChiudiFrame(page)
	{
		var reply;
		var strPage;
		strPage=page;
		reply=window.open(strPage,'chiudiframe','left=1,top=1,height=10,width=10,scrollbars=no,resizable=yes,status=no')
		reply.creator=top;
	}	
	
	
	
	function ApriHelp(file,tipo)
	{
		
		var strTipo=tipo;
		var strFile=file;
		var strNeWin;
		strFile=strFile+'&TIPO='+tipo
		strNeWin=window.open(strFile,'HELP_'+tipo,'left=1,top=1,width=10,height=10,scrollbars=no,resizable=yes,toolbar=no,status=no')
		strNeWin.Creator=self;
	}



	
	function CheckData_Rec_Sign(urlGET,urlPOST,target)
	{
		var strGET;
		var strPOST;
		strGET=urlGET;
		strPOST=urlPOST;
		strTarget=target;
		// disabilita i bottoni
		DisableButton()
		
		
	}
	
	function DisableButton()
	{
		if (!document.upload.sign.disabled)
		{
			document.upload.sign.disabled=true;
		}
		
		if (!document.upload.outline.disabled)
		{
			document.upload.outline.disabled=true;
		}
		
		if (!document.upload.download.disabled)
		{
			document.upload.download.disabled=true;
		}
		
		if (!document.upload.annulla.disabled)
		{
			document.upload.annulla.disabled=true;
		}
	}
	
	function DisableButton_Outline()
	{

		if (!document.upload.SendData.disabled)
		{
			document.upload.SendData.disabled=true;
			document.getElementById("wait").style.visibility="visible";
			document.getElementById("display").style.visibility="hidden";
		}
		
		
		if (!document.frm_download.download.disabled)
		{
			document.frm_download.download.disabled=true;
		}
		
	}
	
	function enableAccessButton()
	{
		nothing();
	}
	

	function EnableButtonInner()
	{
		if (document.upload.sign.disabled)
		{
			document.upload.sign.disabled=false;
		}
		
		if (document.upload.outline.disabled)
		{
			document.upload.outline.disabled=false;
		}
		
		if (document.upload.download.disabled)
		{
			document.upload.download.disabled=false;
		}
		
		if (document.upload.annulla.disabled)
		{
			document.upload.annulla.disabled=false;
		}
	}
	

	function enableUploadButtons()
	{
		
		try
		{
		
			document.upload.uploadFile.disabled=false;
			document.upload.SendData.disabled=false;
			document.getElementById ("wait").style.visibility ="hidden";
			document.getElementById("display").style.visibility="visible";
	
			if (document.getElementById ("loading")) 
				document.getElementById ("loading").style.visibility ="hidden";
		}	
		catch(e)
		{
			self.setTimeout ("enableUploadButtons()",200)
		}
	}

	function disableUploadButtons()
	{
		try
		{	
			if (! document.upload.uploadFile.disabled)
			{
				document.upload.SendData.disabled=true;
				//document.upload.reset.disabled=true;

				document.getElementById("wait").style.visibility="visible";
				document.getElementById("display").style.visibility="hidden";
				
			}
		}
		catch(ExcObj)
		{
			self.setTimeout ("disableUploadButtons()",200)
		}
	
	}
	

	function upload_MUD(file1,file2)	
	{
		var strFile1=file1;
		var strFile2=file2;
		var strTarget=target;

		enableUploadButtons();

	}
	
	


	function CheckUpload_Outline(item)
	{
		var strItem;
		strItem=item;
		
		try
		{
			if (strItem.length == 0)
			{
				
				alert('Invio non possibile\nSelezionare un file');
				enableUploadButtons();
				return false
			}else{
				DisableButton_Outline();
				return true;
			}
		}
		catch(e)
		{
			alert('Errori [Invio Distinta Fuorilinea] : ' + e)
			enableUploadButtons();
			return false
		}
		
	}

	


	function CheckUpload_MUD(item)
	{
		var strItem=item;
		try
		{
			disableUploadButtons();
			if (strItem.length == 0)
			{
				enableUploadButtons();
				alert('Invio non possibile\nSelezionare un file');
				return false
			}else{
				document.getElementById("textForWaiting").style.visibility='visible';
			
				return true
			}
		}
		catch(e)
		{
			enableUploadButtons();
			return false	
		}
	}
	
	function chiudi_popup()
	{
		try
		{
		
			self.clearInterval(timeId);
			self.setTimeout("",500);
			New_Win.close();
			
		}
		catch(ExcObj)
		{}
	}

	function disableAllButtons()
	{
		
		try
		{	
			if (! document.upload.uploadFile.disabled)
			{
				document.upload.uploadFile.disabled=true;
				document.upload.SendData.disabled=true;
			}
			document.getElementById("display").style.visibility="hidden";
			document.getElementById("wait").style.visibility="visible";
			
			
			try
			{
				if (document.frm_download.download)
				{
					document.frm_download.download.disabled=true;
					document.frm_services.annulla.disabled=true;
					document.frm_services.back.disabled=true;

				}
			}
			catch(ExcObj)
			{}

		}
		catch(ExcObj)
		{
			self.setTimeout ("disableAllButtons()",20)
		}
	}
	
	


	function nothing(){
	}

	function uscita (page){
		var risp=confirm("Si desidera uscire dall'Area Riservata ?\n- OK per uscire");
		var strPage;
		strPage=page;
		if(risp) {
			top.document.location =strPage;
		}	
	}
	
	function uscita_first (page){
		var risp=confirm("Chi non avesse ancora modificato le credenziali dovra` farlo al prossimo accesso\n- OK per uscire");
		var strPage;
		strPage=page;
		if(risp) {
			document.location =strPage;
		}	
	}
	
	function Apri(str){
		var NeWin
		NeWin=open(str,'popUp','width=10,height=10,scrollbars=yes,toolbar=no,resizable=yes')
		NeWin.creator=self;
	}
	
	function CheckData(uid,pwd){
	return true
	}

	function apri(pagina,nome){
		var NewFin;
		NewFin=window.open(pagina,nome,'height=50,width=50,toolbar=no,scrollbars=yes,resizable=yes');
		NewFin.creator=self;
	}
	
	function check_details(page){
		var strPAGE, reply;
		strPAGE=page;
		reply=confirm('Con questa scelta lasciate la sezione di Anagrafica Generale\n- OK per proseguire');
		if (reply){
			location=strPAGE;
		}
	}
	
	function check_adv_search(index,page){
		var strINDEX,strPage,ID_Page;
		strINDEX=index.selectedIndex;
		strPage=page;
		if (strINDEX==0){
			alert ('selezionare almeno una provincia');
			index.focus();
		}else{
			ID_Page=window.open(strPage,'comuni','toolbars=no,scrollbars=yes,statusbar=no')
			ID_Page.creator=self;
		}
	}
	
	function not_available(item){
		var strItem;
		alert ('momentaneamente non disponibile');
		if (item.checked){
			item.ckecked=false;
		}else{
			item.ckecked=true;
		}
	}
	
	
	function begin_reg(page){
		var reply;
		var strPage;
		strPage=page;
		reply=confirm('Si e` scelto di iniziare la procedura di registrazione e di lasciare l`Area Pubblica\n- OK per iniziare la registrazione');
		if (reply){
			location=strPage;
		}
	}
	
	
	function check_ateco_search(index,page){
		var strINDEX,strPage,ID_Page;
		strINDEX=index.selectedIndex;
		strPage=page;
		
		if (strINDEX==0){
			alert ('selezionare una provincia');
			index.focus();
		}else{
			ID_Page=window.open(strPage,'atteco','toolbars=no,scrollbars=yes,statusbar=no')
			ID_Page.creator=self;
		}
	}
	
	
	function loadurl(url){
		try{
		    top.creator.location=url;
		    //window.creator.location=url
		    window.close()
		}
		catch(e){}
		
				
	}
	
	
	function loadurl_close(url)
	{
	    try{
	        top.creator.location=url;
		    top.close();
	    }
		catch(e){}
		
	}

function checkComuni(href){
		if (document.NewUserPData.provincia.selectedIndex==0){
			alert('selezionare una provincia');
			document.NewUserPData.provincia.focus();
		}else{
			apri(href,'comuni');
		}
	}
	

function checkDataForRecover(str)
{
    var blOutput
    switch(str)
    {
        case "btnCC":
            blOutput=confirm('Confermare i dati per il pagamento\n- OK per confermare');
        break;
        case "btnA":
            blOutput=confirm('Confermare la richiesta per riportare il MUD in attesa di pagamento\n- OK per confermare');
        break;
        default:
            blOutput=false;
        break;
    }
    
    return blOutput;
}


//-->

// pagina per firma in linea
    function checkPlugin() {
        enableUploadButtons()
        var doc = document.getElementById("pluginriavvio");
        var div=document.getElementById("display");
        if (navigator.userAgent.indexOf('MSIE') == -1)
        {//calcola la presenza di ecowebsign
            if(detectEcoWebSign())
            {
                

        if (doc) {
                   div.innerHTML=div.innerHTML + '<div id="statofirma">Firma in linea disponibile.</div>';
                   document.getElementById("apririquadro").style.visibility = 'hidden';
                   document.getElementById("pluginsetup").style.visibility = 'hidden';
                   document.getElementById("chiudiriquadro").style.visibility = 'hidden';
                }
            }
            else
            {
                
                if(doc)
                {
                    doc.innerHTML=doc.innerHTML + '<div id="statofirma">Firma in linea non disponibile.</div>';
                    document.getElementById("statofirma").style.color='orange';
                    showBlock();
                }
                
        }
    }

    }

    function showBlock() {
        try {
            document.getElementById("pluginsetup").style.visibility = 'visible';
            document.getElementById("apririquadro").style.visibility = 'hidden';
            document.getElementById("chiudiriquadro").style.visibility = 'visible';
        }
        catch (e)
        { }
    }

    function hideBlock() {
        try {
            document.getElementById("apririquadro").style.visibility = 'visible';
            document.getElementById("pluginsetup").style.visibility = 'hidden';
            document.getElementById("chiudiriquadro").style.visibility = 'hidden';
        }
        catch (e)
        { }
    }

    function ChiudiFrame2(page) {
        var reply;
        var strPage;

        try {
            var strTesto = 'La distinta e` stata ricevuta e controllata dal sistema.\nChi sceglie di chiudere perde i dati MUD inviati.\n\nChiudendo sara` necessario inviare di nuovo il file MUD\n\n - OK per annullare e chiudere comunque';
            strPage = page;
            reply = confirm(strTesto);
            if (reply) {
                top.location = strPage;
            }
        }
        catch (e) { }
    }

    function nascondiRiquadro() {
    
        try{
            parent.principale.document.getElementById('testodamostrare').style.visibility = 'hidden';
            parent.principale.document.getElementById('firmainlinea').style.visibility = 'visible';
            
        }
        catch(e)
        {
            //alert('e: ' + e);
        }
    }

    function mostraRiquadro() {
        
        try{
            if(parent.principale.document.getElementById('firmainlinea'))
            {
                parent.principale.document.getElementById('firmainlinea').style.visibility = 'hidden';
            }

            if(parent.principale.document.getElementById('testodamostrare'))
            {
                parent.principale.document.getElementById('testodamostrare').style.visibility = 'visible';
            }
        }
        catch(e)
        {
            //alert('e: ' + e);
        } 
    }
    
    function initPlugin()
    {

       EnableButton_Inline();
        try {
            var obj = parent.basso.document.embeds[0];
            if (obj.toString() == '[EcoWebSign Plugin]') {
                parent.principale.document.getElementById('firmainlinea').style.visibility = 'visible';
                
                nascondiRiquadro();
                DisableButton_Inline();  
            }
        }
        catch (e) {
            mostraRiquadro();            

        }
    }
    
    function initActiveX()
    {
        EnableButton_Inline();
        try{
        
            var obj = new ActiveXObject("EcoWebSignCom.EcoWebSign");
            
            if (obj!=null) {
                parent.principale.document.getElementById('firmainlinea').style.visibility = 'visible';
                parent.principale.document.getElementById ("testodamostrare").innerHTML='';
                nascondiRiquadro();
                DisableButton_Inline();
            }
        }
        catch(e)
        {
            mostraRiquadro();    
        }
            
        }
    
    function EnableButton_Inline()
	{	
		try
		{
			parent.principale.document.getElementById ("loading").style.visibility ="hidden";
			
			if (parent.principale.document.frm_services.back.disabled)
			{
				
				parent.principale.document.frm_services.back.disabled=false;
				parent.principale.document.frm_services.annulla.disabled=false;
				
			}
		}
		catch(e)
		{
			self.setTimeout("EnableButton_Inline()",160);
		}
	}

	function DisplayErrorMessage()
	{
		try
		{
			parent.principale.document.getElementById ("errore").style.visibility ="visible";
		}
		catch(e)	
		{
			self.setTimeout("DisplayErrorMessage()",150);
		}
	}


	function sign_doc_NN(file,store,path)
	{
		var strUrl = file;
		var strPath=path;
		var strStore=store;
		try
		{

		    EnableButton_Inline();
		    var obj = document.embeds[0];
		    
		    if (obj.toString()=='[EcoWebSign Plugin]')
		    {
		        var resBool = obj.SignFile(strUrl,strStore,strPath);
                
		        if (!resBool)
		        {
			        EnableButton_Inline();
			        DisplayErrorMessage();

			        alert('per richiamare la firma in linea, aggiornare la pagina\n (premere F5)');
		        }	
		    }
		    else
		    {
		        mostraRiquadro();
		    }
		}
		catch(e)
		{
		    mostraRiquadro();
		    
			EnableButton_Inline();
			DisplayErrorMessage();
			
		}
		
	}

	function sign_doc(file,store,path)
	{
		var strUrl = file;
		var strPath=path;
		var strStore=store;
		try
		{
			EnableButton_Inline();
			nascondiRiquadro();
			var obj = document.getElementById ("Class1");
			var resBool = obj.SignFile (strUrl,strStore,strPath);
			
			if (!resBool)
			{
				EnableButton_Inline();
				DisplayErrorMessage();
				alert('per richiamare la firma in linea, aggiornare la pagina\n (premere F5)');
				
			}
		    else
		    {
		        //nascondiRiquadro();
                //mostraRiquadro();
                document.getElementById ("testodamostrare").innerHTML='';
                //testodamostrare
		    }
		}
		catch (e)
		{
		    mostraRiquadro();
			EnableButton_Inline();
			DisplayErrorMessage();
			
		}
	}



//--
