function menubo(e,UrlCms) 
	{
		if ( (navigator.appName == 'Microsoft Internet Explorer' && e.button==2) ||  (navigator.appName == 'Netscape' && e.which == 3) )
			{
			//	alert(UrlCms);

			if ( confirm("Modificare l'elemento con il CMS ?") )
				{
					ApriModale('/portal/CMS/' + UrlCms,'JobWindow',800,700);
					return false;
				}
			}
		else
			{
			return true;
			}
	}
  function sortList(listId)
  {
  	// Get the ul object
  	var oUl = document.getElementById(listId);
  	/* Perform a Bubble Sort on the list items */
  	for(var i in oUl.childNodes)
  	{
  		var x = oUl.childNodes[i];
  		for(var j in oUl.childNodes)
  		{
  			var y = oUl.childNodes[j];
  			if((x.innerText != 'undefined' || y.innerText != 'undefined')  && x.innerText>y.innerText)
  			{
  				// Skip if x is already the first list item
  				if(oUl.firstChild!=x)
  					oUl.insertBefore(y,x);
  			}
  		}
  	}
  		
  }

  /* Define innerText for Mozilla based browsers */
  try {
      if ((typeof HTMLElement != 'undefined') && (HTMLElement.prototype.__defineGetter__ != 'undefined')) {
          HTMLElement.prototype.__defineGetter__("innerText", function () {
              var r = this.ownerDocument.createRange();
              r.selectNodeContents(this);
              return r.toString();
          });

      }
  }
  catch (ex) { }
  
  

 
function SincaCombo(mestesso,risultati) 
	{
        var stringa, lunghezza;
        var scorri = -1;

            stringa = mestesso.value;
            lunghezza = stringa.length;
            var exp = new RegExp(stringa);

            // SE LA STRINGA DA RICERCARE E' MAGGIORE DI ZERO ESEGUO LA ROUTINE
            if (lunghezza > 0) 
            	{
                    for (var i = 0; i < risultati.options.length; i++) {
                        // SE LA STRINGA E' PRESENTE RESTITUISCO UN RISULTATO AL VOLO
                        if (scorri == -1 && (risultati.options[i].text.toLowerCase().match(exp))) {   
                        //if (scorri == -1 && risultati.options[i].text.toLowerCase().substring(0, lunghezza) == stringa) {
                            scorri = i;
                            
                        }
                        else {
                            null;
                        }
                    }
                }
               else {  scorri = 0;   }

            // SCORRO LA SELECTBOX IN BASE AL VALORE RICHIESTO CON LA DIGITAZIONE
            risultati.selectedIndex = scorri;
  
    }


 
function DetectFrameEraseBussola() 
	{
 		var sPath = window.location.toString();
 		if (sPath=='') return;
 		var sPath2 = window.location.toString();
 		try {sPath2 = parent.window.location.toString();}	catch(e){sPath2 =''} 					  					
 		if (sPath !=sPath2) 
			{
				var bEliminaBussola = true;
				
				try { if (parent.window.ifrmApplicazioni.location.toString().length>0) bEliminaBussola =false}
					catch(e){ } 		
				try { if (parent.window.frameBussola.location.toString().length>0) bEliminaBussola =false}
					catch(e){ } 	
 
					 												 	 						 	 		 							
				if (bEliminaBussola)	
					{							 
					var objTmp;
					objTmp = document.getElementById('objTable');							  
					objTmp.style.visibility = 'hidden'; 					 
					objTmp.deleteRow(0);
					objTmp.deleteRow(0);
				 
					}
			}
	}
	
	
function gestisciConflitti(campo){
	if(campo.value=='Nessuno'){
		campo.disabled=false;
	}else{
		campo.value="";
		campo.disabled=true;		
	}
}

function checkTesto(){
	if (document.getElementById("txtsTestoRicerca").value.toLowerCase() == 'immetti qui il testo')
		document.getElementById("txtsTestoRicerca").value = '';	
	}			
function creaAttesa(){
	document.getElementById("myAttesa").style.height= '76';
	document.getElementById("myAttesa").style.width= '130';
	document.getElementById("myAttesa").style.visibility= 'visible';
	}	
function nascondiRisultati(){				
	//nascondo il Contact Center o i risultati ogni volta che lancio una nuova ricerca
	var myTable = document.getElementById("tableRisultati");
	var myTableContact = document.getElementById("tableContact");				
	if (myTableContact != null)
		{
			if (document.getElementById("tableContact").style.visibility=='visible')
					document.getElementById("tableContact").style.visibility="hidden";
		}
	if (myTable != null)
		{
			if (document.getElementById("tableRisultati").style.visibility=="visible")
					document.getElementById("tableRisultati").style.visibility="hidden";
		}
}
 
function PostBackRicerca(){
	var mytxtsTestoRicerca = document.getElementById("txtsTestoRicerca");
	document.getElementById("hTxtSoloPostBack").value ='1';
	var cmbTipoRicerca = document.getElementById("TipoRicerca");	 
	//if ((cmbTipoRicerca.value=='00011000') || (cmbTipoRicerca.value=='00010000') || (cmbTipoRicerca.value=='00001000'))
	//		mytxtsTestoRicerca.value='';			 
	 document.forms[0].submit();	 
	}
	
/*tolgo gli spazi */
function trim(sText)
{	
	return sText.replace(/^\s*|\s*$/g,'');
}
	
function goRicercaNew(){ 
 
	var txtsTestoRicerca = document.getElementById("txtsTestoRicerca");	
	var cmbTipoRicerca = document.getElementById("TipoRicerca");
	var cmbPeriodo   =document.getElementById("cmbPeriodo");
	var txtsAnnoCirc = document.getElementById('txtsAnnoCirc');
	var txtsDataCirc = document.getElementById('txtsDataCirc');
	var txtsNumCirc = document.getElementById('txtsNumCirc');
	var result ;
	var bTipoRicercaCircolariMessaggi;
	
	bTipoRicercaCircolariMessaggi = !(cmbTipoRicerca.value == '01000000'||cmbTipoRicerca.value == '11100000'||cmbTipoRicerca.value == '10100000' )
	
 
	if (bTipoRicercaCircolariMessaggi ) 
		{	// ric. circ e messaggi
		/*Controllo di formato sui parametri anno e Numero*/
			if (trim(txtsAnnoCirc.value) != "")
				{	
					var sFormatoAnno =/^[0-9]{4}/	
					if(!sFormatoAnno.test(txtsAnnoCirc.value) ||txtsAnnoCirc.value.length != 4 ||txtsAnnoCirc.value < 1960 ||txtsAnnoCirc.value > 2020)
						{
							alert('Parametro "Anno" errato');
							return false;		
						}
				}
			if (trim(txtsNumCirc.value) != "" )
				{			
					var sFormatoNumero = /^[0-9]+$/
					if (!sFormatoNumero.test(trim(txtsNumCirc.value)))
						{
							alert('Parametro "Numero" errato:='+trim(txtsNumCirc.value)+'basta');
							return false;
						} 		
				}
			
		/*Controllo di formato data gg/mm/aaaa*/
			if(trim(txtsDataCirc.value) != "")
				{
					var sFormatoData = /[0-9]{1,2}\/[0-9]{1,2}\/[0-9]{4}/;
					result = txtsDataCirc.value.match(sFormatoData);
					if (result == null)
						{
							alert('Parametro "Data" errato: corretto(gg/mm/aaaa)  ');
							return false;								
						}
					else 
						{
						//controllo i giorni mesi anni
						sFormatoData = /\//
						result = txtsDataCirc.value.split(sFormatoData);
						if (result[0] > 31 ||result[1]>12||result[2]<1950|| result[2]>2020)
							{
								alert('Parametro "Data" errato');
								return false;						
							}
						}	
				}
		}
				
	if (trim(txtsTestoRicerca.value) == '' || (txtsTestoRicerca.value == 'Immetti qui il testo')) {
				 
				if(cmbTipoRicerca.value == '01000000'||cmbTipoRicerca.value == '11100000'||cmbTipoRicerca.value == '10100000' ){	
						alert('Immettere un testo per effettuare la ricerca');
						return false;
					  }
				  else {//Circolari e/o messaggi, Testo puņ essere nullo
						if(txtsTestoRicerca.value == 'Immetti qui il testo'){							
							txtsTestoRicerca.value = ""; 
						}
							
						if(cmbPeriodo.value != 'Nessuno' && (txtsAnnoCirc.value !=''||txtsDataCirc.value!='')){
									alert('i parametri "Anno" "Periodo" e "Data" non vanno specificati insieme');
									return false;							
							}	
							if(trim(txtsAnnoCirc.value) !=''&&trim(txtsDataCirc.value)!=''){
									alert('i parametri "Anno" e "Data" non vanno specificati insieme');
									return false;								
							}
					
						//se il periodo č "Qualsiasi" o "Ultimo anno", serve un parametro ulteriore di ricerca
						if(cmbPeriodo.value == 'UltimoAnno' ||cmbPeriodo.value == 'Nessuno'){
							//se anche gli altri param (numero anno e data) sono vuoti lancia alert
							if(document.getElementById('txtsNumCirc').value ==''&&trim(txtsDataCirc.value) ==''&&trim(txtsAnnoCirc.value) ==''){
								alert('Immettere un parametro per effettuare la ricerca');
								return false;							
							}
						}
							try {
								if ((document.getElementById("myAttesa").style.visibility=='hidden')||(document.getElementById("myAttesa").style.visibility=='')) 
									{										
										creaAttesa();
										nascondiRisultati();
										document.getElementById("hTxtSoloPostBack").value ='2';
										//alert ("hTxtSoloPostBack="&document.getElementById("hTxtSoloPostBack").value);
										document.forms[0].submit();
									}
									else 
									return false;	
								}
							catch(ex)
								{}							
				  }	
			}
		else {
			if ((trim(txtsTestoRicerca.value)).length<3){
					alert('La Lunghezza del testo deve essere almeno 3 caratteri');
					return false;							
			}
			try {			
				if ((document.getElementById("myAttesa").style.visibility=='hidden')||(document.getElementById("myAttesa").style.visibility=='')) 
					{						
						creaAttesa();
						nascondiRisultati();						
						document.getElementById("hTxtSoloPostBack").value ='2';
						//alert ("hTxtSoloPostBack="&document.getElementById("hTxtSoloPostBack").value);
						document.forms[0].submit();
					}
					else 
					return false;	
				}
			catch(ex)
				{}
		}
}					
 
function goRicerca(){
	var txtsTestoRicerca = document.getElementById("txtsTestoRicerca");			
	if (txtsTestoRicerca.value == ''||(txtsTestoRicerca.value == 'Immetti qui il testo')) 
			return false;
		else {
			try {
				if ((document.getElementById("myAttesa").style.visibility=='hidden')||(document.getElementById("myAttesa").style.visibility=='')) 
					{
						creaAttesa();
						nascondiRisultati();
						document.forms[0].submit();
					}
					else 
					return false;	
				}
			catch(ex)
				{}
		}
	}					
		
		
var popup
function ApriModale(nomefile,nome,width,height)
{
	var nTop;
	var nLeft;
	nTop = 5 ;// ((screen.height/2)-(height/2)-0);
	nLeft = ((screen.width/2)-(width/2));
	{
	try {
		 	popup.close();		 
		}
	catch (e) {}
	 
	popup = window.open(nomefile,nome,'width=' + width + ',height=' + height + ',scrollbars=yes,menubar=no,resizable=no,location=no,screenX=0,screenY=0,top='+nTop+',left='+nLeft+'');
 
	return false;
	}
}		
 

function SetCookie(cookieName,cookieValue,nDays){
	var today = new Date();
	var expire = new Date();
	if (nDays==null || nDays==0) nDays=1;
	expire.setTime(today.getTime() + 3600000*24*nDays);
	document.cookie = cookieName+"="+escape(cookieValue)+ ";expires="+expire.toGMTString();
	} 
	
	
function ReadCookie(cookieName) {
		var theCookie=""+document.cookie;
		var ind=theCookie.indexOf(cookieName);
		if (ind==-1 || cookieName=="") return ""; 
		var ind1=theCookie.indexOf(';',ind);
		if (ind1==-1) ind1=theCookie.length; 
		return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
	}		
	
	
	
	
