function SetToolTips(imageid,img){
    new Ext.ToolTip({
        target: imageid,
        anchor: 'left',
        renderTo: document.body,
        html: null,
        listeners: {beforeshow:function(){this.body.dom.innerHTML='<p align="justify">'+HTMLEncode(img.alt)+'</p>'}}
    });
}
function showmessage(titolo,messaggio,durata){
 if (!durata)
    {Ext.example.msg(titolo, messaggio,"1");}
 else
    {Ext.example.msg(titolo, messaggio,durata);}
}

function ShowWarningMessage(messaggio){
    Ext.MessageBox.show({
           title: 'Attenzione...',
           msg: messaggio,
           buttons: Ext.MessageBox.OK,
           icon:  Ext.MessageBox.WARNING
       });
}

function ShowInfoMessage(titolo,messaggio){
    Ext.MessageBox.show({
           title: titolo,
           msg: messaggio,
           buttons: Ext.MessageBox.OK,
           icon:  Ext.MessageBox.INFO
       });
}

function HTMLEncode(str) {
    var div = document.createElement('div');
    var text = document.createTextNode(str);
    div.appendChild(text);
    text=div.innerHTML;
    text=text.replace(/"/g,"&quot;");
    // Lettere accentate -------------
    text=text.replace(/à/g,"&agrave;");
    text=text.replace(/è/g,"&egrave;");
    text=text.replace(/é/g,"&eacute;");
    text=text.replace(/ì/g,"&igrave;");
    text=text.replace(/ù/g,"&ugrave;");
    text=text.replace(/ò/g,"&ograve;");
    //--------------------------------
    //-------Fix Safari problem-------
    text=text.replace(/</g,"&lt;");
    text=text.replace(/>/g,"&gt;");
    //--------------------------------
    return text;
}


function waitform(testo){
    if(testo != "")
    {
        Ext.Msg.wait(HTMLEncode(testo),'Attendere...');
    }
    else
    {
        Ext.Msg.hide();
    }
}

function showmessage(titolo,messaggio,durata){
 if (!durata)
    {Ext.example.msg(titolo, messaggio,"1");}
 else
    {Ext.example.msg(titolo, messaggio,durata);}
}

function pause(millisecondi){
    var now = new Date();
    var exitTime = now.getTime() + millisecondi;
    while(true){
        now = new Date();
        if(now.getTime() > exitTime) return;
    }
}
        //.ajaxStart(function(){ ShowWait(); })
    	//.ajaxStop(function(){ HideWait(); });


    function ValidateEmail(email) {
		var at = email.lastIndexOf("@");

		// Make sure the at (@) sybmol exists and
		// it is not the first or last character
		if (at < 1 || (at + 1) === email.length)
			return false;

		// Make sure there aren't multiple periods together
		if (/(\.{2,})/.test(email))
			return false;

		// Break up the local and domain portions
		var local = email.substring(0, at);
		var domain = email.substring(at + 1);

		// Check lengths
		if (local.length < 1 || local.length > 64 || domain.length < 4 || domain.length > 255)
			return false;

		// Make sure local and domain don't start with or end with a period
		if (/(^\.|\.$)/.test(local) || /(^\.|\.$)/.test(domain))
			return false;

		// Check for quoted-string addresses
		// Since almost anything is allowed in a quoted-string address,
		// we're just going to let them go through
		if (!/^"(.+)"$/.test(local)) {
			// It's a dot-string address...check for valid characters
			if (!/^[-a-zA-Z0-9!#$%*\/?|^{}`~&'+=_\.]*$/.test(local))
				return false;
		}

		// Make sure domain contains only valid characters and at least one period
		if (!/^[-a-zA-Z0-9\.]*$/.test(domain) || domain.indexOf(".") === -1)
			return false;

		return true;
	}



function trim(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 showdatetime(elid)
{
var date = new Date();
var d  = date.getDate();
var day = (d < 10) ? '0' + d : d;
var m = date.getMonth() + 1;
var month = (m < 10) ? '0' + m : m;
var yy = date.getYear();
var year = (yy < 1000) ? yy + 1900 : yy;
var nhours=date.getHours();
var nmins=date.getMinutes();
var nsecn=date.getSeconds();
var AorP=" ";
if (nhours>=12)
    AorP="PM";
else
    AorP="AM";
if (nhours>=13)
    nhours-=12;
if (nhours==0)
 nhours=12;
if (nsecn<10)
 nsecn="0"+nsecn;
if (nmins<10)
 nmins="0"+nmins;
document.getElementById(elid).innerHTML = day + "/" + month + "/" + year + " " + nhours+":"+nmins+":"+nsecn+" "+AorP;
}

function animate_element(el){
    el.frame("c22a27", 2,{ duration: .30 });
    setTimeout(function(){el.frame("c22a27", 3,{ duration: .1 });},3000);
    setTimeout(function(){el.ghost('b', { duration: 1 });},3000);
}

function setInnerText(el,msg){
    if (Ext.isGecko){
        el.textContent=msg;
    } else {
        el.innerText=msg;
    }
}

		function ControllaPIVA(pi){
			var 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 ControllaCF(cf){
			var validi, i, s, set1, set2, setpari, setdisp;
			cf = cf.toUpperCase();
			validi = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
			for( i = 0; i < 16; i++ ){
				if( validi.indexOf( cf.charAt(i) ) == -1 )
						return false;
			}
			set1 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			set2 = "ABCDEFGHIJABCDEFGHIJKLMNOPQRSTUVWXYZ";
			setpari = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
			setdisp = "BAKPLCQDREVOSFTGUHMINJWZYX";
			s = 0;
			for( i = 1; i <= 13; i += 2 )
				s += setpari.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
			for( i = 0; i <= 14; i += 2 )
				s += setdisp.indexOf( set2.charAt( set1.indexOf( cf.charAt(i) )));
			if( s%26 != cf.charCodeAt(15)-'A'.charCodeAt(0) )
				return false;
			return true;
		}

if (typeof(Sys) !== "undefined") Sys.Application.notifyScriptLoaded();


