var cod;		

function visualizzaControlloPec(){
	//nascondiCampo("linkPec");
	//visualizzaCampo("noLinkPec");
	visualizzaCampo("captcha");
	visualizzaCampo("testo");
	nascondiCampo("ritesto");
	resetValueCampo("textfieldcaptcha");
	focusCampo("textfieldcaptcha");
}

function refresh()
{
    window.location.reload( true );
}

function trim2(stringa)
{
   while (stringa.substring(0,1) == ' '){
		stringa = stringa.substring(1, stringa.length);
		}
   while (stringa.substring(stringa.length-1, stringa.length) == ' '){
   		stringa = stringa.substring(0,stringa.length-1);
   		}
return stringa;
}

function VerificaCaptcha(codiceCaptcha,codiceCaptchaCriptato,pecCriptata,urlErrore){
	cod=trim2(codiceCaptcha);	
	url="/impr/ricerca/captcha.jsp?codiceCaptcha="+codiceCaptcha+"&codiceCaptchaCriptato="+codiceCaptchaCriptato+"&pecCriptata="+pecCriptata;	
	new Ajax.Request(url, { 
	method:'get', onSuccess: function(transport){       
	var response = transport.responseText || "no response text";  
        if(response.substring(0,response.indexOf(",")).match(cod+'_OK') != null) {		       
        	pecRet=response.substring(response.indexOf(",")+1);
       		document.getElementById("pec").innerHTML=pecRet;
  			nascondiCampo("captcha");
       	}else{
			url = document.location.href;
			url = url.substr(0,url.length-1);
			document.location.href =url+"&ricaricaPec=si";       	
       	}        
    }, 
    onFailure: function(){ document.location.href=urlErrore; } 
  });
 }

function visualizzaCampo(id){
	document.getElementById(id).style.display="block";
	
}

function resetValueCampo(id){
	document.getElementById(id).value="";
	
}

function focusCampo(id){
	document.getElementById(id).focus();
	
}
 
function nascondiCampo(id){
	document.getElementById(id).style.display="none";
} 

function nascondiControlloPec(){
	visualizzaCampo("linkPec");
	nascondiCampo("noLinkPec");
	nascondiCampo("captcha");
	resetValueCampo("textfieldcaptcha");
} 


function addEvent(obj,ev,fn){
	if(obj.addEventListener) {
		// metodo w3c
		obj.addEventListener(ev, fn, false);
	} else if(obj.attachEvent) {
	// metodo IE
		obj.attachEvent('on'+ev, fn);
	} else {
		// se i suddetti metodi non sono applicabili
		// se esiste gia' una funzione richiamata da quel gestore evento
		if(typeof(obj['on'+ev])=='function'){
			alert("5");
	
			// salvo in variabile la funzione gia' associata al gestore
			var f=obj['on'+ev];
			// setto per quel gestore una nuova funzione 
			// che comprende la vecchia e la nuova
			obj['on'+ev]=function(){if(f)f();fn()}
		}
		// altrimenti setto la funzione per il gestore
		else obj['on'+ev]=fn;
	}
}


