/****************************************** XMLHttpRequest Start *******************************/
/*

Cross-Browser XMLHttpRequest v1.2
=================================

Emulate Gecko 'XMLHttpRequest()' functionality in IE and Opera. Opera requires
the Sun Java Runtime Environment <http://www.java.com/>.

by Andrew Gregory
http://www.scss.com.au/family/andrew/webdesign/xmlhttprequest/

This work is licensed under the Creative Commons Attribution License. To view a
copy of this license, visit http://creativecommons.org/licenses/by-sa/2.5/ or
send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
94305, USA.

Attribution: Leave my name and web address in this script intact.

Not Supported in Opera
----------------------
* user/password authentication
* responseXML data member

Not Fully Supported in Opera
----------------------------
* async requests
* abort()
* getAllResponseHeaders(), getAllResponseHeader(header)

*/
// IE support
if (window.ActiveXObject && !window.XMLHttpRequest) {
  window.XMLHttpRequest = function() {
    var msxmls = new Array(
      'Msxml2.XMLHTTP.5.0',
      'Msxml2.XMLHTTP.4.0',
      'Msxml2.XMLHTTP.3.0',
      'Msxml2.XMLHTTP',
      'Microsoft.XMLHTTP');
    for (var i = 0; i < msxmls.length; i++) {
      try {
        return new ActiveXObject(msxmls[i]);
      } catch (e) {
      }
    }
    return null;
  };
}
// Gecko support
/* ;-) */
// Opera support
if (window.opera && !window.XMLHttpRequest) {
  window.XMLHttpRequest = function() {
    this.readyState = 0; // 0=uninitialized,1=loading,2=loaded,3=interactive,4=complete
    this.status = 0; // HTTP status codes
    this.statusText = '';
    this._headers = [];
    this._aborted = false;
    this._async = true;
    this._defaultCharset = 'ISO-8859-1';
    this._getCharset = function() {
      var charset = _defaultCharset;
      var contentType = this.getResponseHeader('Content-type').toUpperCase();
      val = contentType.indexOf('CHARSET=');
      if (val != -1) {
        charset = contentType.substring(val);
      }
      val = charset.indexOf(';');
      if (val != -1) {
        charset = charset.substring(0, val);
      }
      val = charset.indexOf(',');
      if (val != -1) {
        charset = charset.substring(0, val);
      }
      return charset;
    };
    this.abort = function() {
      this._aborted = true;
    };
    this.getAllResponseHeaders = function() {
      return this.getAllResponseHeader('*');
    };
    this.getAllResponseHeader = function(header) {
      var ret = '';
      for (var i = 0; i < this._headers.length; i++) {
        if (header == '*' || this._headers[i].h == header) {
          ret += this._headers[i].h + ': ' + this._headers[i].v + '\n';
        }
      }
      return ret;
    };
    this.getResponseHeader = function(header) {
      var ret = getAllResponseHeader(header);
      var i = ret.indexOf('\n');
      if (i != -1) {
        ret = ret.substring(0, i);
      }
      return ret;
    };
    this.setRequestHeader = function(header, value) {
      this._headers[this._headers.length] = {h:header, v:value};
    };
    this.open = function(method, url, async, user, password) {
      this.method = method;
      this.url = url;
      this._async = true;
      this._aborted = false;
      this._headers = [];
      if (arguments.length >= 3) {
        this._async = async;
      }
      if (arguments.length > 3) {
        opera.postError('XMLHttpRequest.open() - user/password not supported');
      }
      this.readyState = 1;
      if (this.onreadystatechange) {
        this.onreadystatechange();
      }
    };
    this.send = function(data) {
      if (!navigator.javaEnabled()) {
        alert("XMLHttpRequest.send() - Java must be installed and enabled.");
        return;
      }
      if (this._async) {
        setTimeout(this._sendasync, 0, this, data);
        // this is not really asynchronous and won't execute until the current
        // execution context ends
      } else {
        this._sendsync(data);
      }
    }
    this._sendasync = function(req, data) {
      if (!req._aborted) {
        req._sendsync(data);
      }
    };
    this._sendsync = function(data) {
      this.readyState = 2;
      if (this.onreadystatechange) {
        this.onreadystatechange();
      }
      // open connection
      var url = new java.net.URL(new java.net.URL(window.location.href), this.url);
      var conn = url.openConnection();
      for (var i = 0; i < this._headers.length; i++) {
        conn.setRequestProperty(this._headers[i].h, this._headers[i].v);
      }
      this._headers = [];
      if (this.method == 'POST') {
        // POST data
        conn.setDoOutput(true);
        var wr = new java.io.OutputStreamWriter(conn.getOutputStream(), this._getCharset());
        wr.write(data);
        wr.flush();
        wr.close();
      }
      // read response headers
      // NOTE: the getHeaderField() methods always return nulls for me :(
      var gotContentEncoding = false;
      var gotContentLength = false;
      var gotContentType = false;
      var gotDate = false;
      var gotExpiration = false;
      var gotLastModified = false;
      for (var i = 0; ; i++) {
        var hdrName = conn.getHeaderFieldKey(i);
        var hdrValue = conn.getHeaderField(i);
        if (hdrName == null && hdrValue == null) {
          break;
        }
        if (hdrName != null) {
          this._headers[this._headers.length] = {h:hdrName, v:hdrValue};
          switch (hdrName.toLowerCase()) {
            case 'content-encoding': gotContentEncoding = true; break;
            case 'content-length'  : gotContentLength   = true; break;
            case 'content-type'    : gotContentType     = true; break;
            case 'date'            : gotDate            = true; break;
            case 'expires'         : gotExpiration      = true; break;
            case 'last-modified'   : gotLastModified    = true; break;
          }
        }
      }
      // try to fill in any missing header information
      var val;
      val = conn.getContentEncoding();
      if (val != null && !gotContentEncoding) this._headers[this._headers.length] = {h:'Content-encoding', v:val};
      val = conn.getContentLength();
      if (val != -1 && !gotContentLength) this._headers[this._headers.length] = {h:'Content-length', v:val};
      val = conn.getContentType();
      if (val != null && !gotContentType) this._headers[this._headers.length] = {h:'Content-type', v:val};
      val = conn.getDate();
      if (val != 0 && !gotDate) this._headers[this._headers.length] = {h:'Date', v:(new Date(val)).toUTCString()};
      val = conn.getExpiration();
      if (val != 0 && !gotExpiration) this._headers[this._headers.length] = {h:'Expires', v:(new Date(val)).toUTCString()};
      val = conn.getLastModified();
      if (val != 0 && !gotLastModified) this._headers[this._headers.length] = {h:'Last-modified', v:(new Date(val)).toUTCString()};
      // read response data
      var reqdata = '';
      var stream = conn.getInputStream();
      if (stream) {
        var reader = new java.io.BufferedReader(new java.io.InputStreamReader(stream, this._getCharset()));
        var line;
        while ((line = reader.readLine()) != null) {
          if (this.readyState == 2) {
            this.readyState = 3;
            if (this.onreadystatechange) {
              this.onreadystatechange();
            }
          }
          reqdata += line + '\n';
        }
        reader.close();
        this.status = 200;
        this.statusText = 'OK';
        this.responseText = reqdata;
        this.readyState = 4;
        if (this.onreadystatechange) {
          this.onreadystatechange();
        }
        if (this.onload) {
          this.onload();
        }
      } else {
        // error
        this.status = 404;
        this.statusText = 'Not Found';
        this.responseText = '';
        this.readyState = 4;
        if (this.onreadystatechange) {
          this.onreadystatechange();
        }
        if (this.onerror) {
          this.onerror();
        }
      }
    };
  };
}
// ActiveXObject emulation
if (!window.ActiveXObject && window.XMLHttpRequest) {
  window.ActiveXObject = function(type) {
    switch (type.toLowerCase()) {
      case 'microsoft.xmlhttp':
      case 'msxml2.xmlhttp':
      case 'msxml2.xmlhttp.3.0':
      case 'msxml2.xmlhttp.4.0':
      case 'msxml2.xmlhttp.5.0':
        return new XMLHttpRequest();
    }
    return null;
  };
}

/****************************************** XMLHttpRequest ENDS *******************************/


var winMainWin= null;
function NavigateLogin(pagina)
{
	if (winMainWin != null)
	{
		winMainWin.close();
	} 
	else 
	{
		location.replace("about:blank");
	}
	winMainWin = window.open(pagina, 'MainWindow',"fullscreen=yes,toolbar=no,status=no,titlebar=no");
	winMainWin.focus();
}

function TextBoxCopyTo(source, dest)
{
  document.getElementById(dest).value = document.getElementById(source).value;
}

function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function

function CampoObbligatorio(messaggio , idCampo)
{
	if (Trim(document.getElementById(idCampo).value) != '')
	{
		return true; 
	} 
	else 
	{
		alert(messaggio);
		return false; 
	}
}

function IsFloat(messaggio , idCampo)
{
	var valore = Trim(document.getElementById(idCampo).value);
	//alert(valore);
	var retVal = CheckIsFloat(valore);
	//alert(retVal);
	if (retVal)
	{
		alert(messaggio);
		return false;
	}else
		return true; 
}

function IsIntIntervallo(messaggio , idCampo, left, right)
{
	var valore = Trim(document.getElementById(idCampo).value);
	var retVal = isNaN(valore);
	// primo controllo č numerico
	if (retVal)
	{
		alert(messaggio);
		return false;
	}
	var val = parseInt(valore);
	if (val >=left && val <= right)
		return true; 
	else 
	{
		alert(messaggio);
		return false;
	}
}

function ControllaConversioneLead(radiolist, idnascosto)
{
	var selezionato = document.getElementById("radioButtonListConversione_3").checked;
	var valore = document.getElementById("_soc_id");
	if (selezionato && (valore.value == '' || valore.value=='0')){
		alert("E' necessario specificare l'azienda a cui associare la persona che verra' creata");
		return false; 
	}else{
		return true;
	}
}
var fConverti = null; 
function ApriConversioneLead(url)
{
	if (fConverti != null) fConverti.close();
	fConverti = window.open(url, 'fConverti',"status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes, width=550, height=300,top=100,left=100");
	fConverti.focus();
}

function dettaglioGruppo(url)
{
	if (fConverti != null) fConverti.close();
	fConverti = window.open(url, 'fConverti',"status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes, width=600, height=400,top=100,left=100");
	fConverti.focus();
}





function _ManageOpenCloseLayer(rigaNascondere, idImmagine, hiddenValue,root,sezione, store)
{
	var divC = document.getElementById(rigaNascondere);
	var imageC = document.getElementById(idImmagine);
	var hiddenAValue = document.getElementById(hiddenValue);
	var nomeImg = imageC.src.toLowerCase();
	var open = true;
	if (nomeImg.indexOf("elementplus.jpg") != -1)
	{
		divC.style.display = '';
		imageC.src = imageC.src.toLowerCase().replace("elementplus.jpg","elementminus.jpg");
		if (hiddenAValue != null && hiddenAValue != 'undefined')
			hiddenAValue.value = 'aperto';
	} 
	else 
	{
		open = false;
		divC.style.display = 'none';
		imageC.src = imageC.src.toLowerCase().replace("elementminus.jpg","elementplus.jpg");
		if (hiddenAValue != null && hiddenAValue != 'undefined')
			hiddenAValue.value = 'chiuso';
	}
	if (store != null && store != 'undefined'
		&& sezione != null && sezione != 'undefined'
		&& root != null && root != 'undefined')
	{
		if (open)
			StoreOpenClose(root,sezione, 'aperto');
		else
			StoreOpenClose(root,sezione, 'chiuso');
	}
	
}

function ConfermaEliminazione()
{
	var retVal = confirm('Sei sicuro di eliminare il lead corrente?');
	window.event.cancelBubble = retVal;
	return retVal;
}
			
// funzione che apre una finestra
var popUp2 = null;  
function apriFinestra(url)
{
	if (popUp2 != null) popUp2.close();
	popUp2 = window.open(url, 'name',"resizable=true,statusbar=false,locationbar=false,scrollbars=true,toolbar=false, width=650, ,height=550,top=100");
}


var ____win = null;
function ApriCategory(anchorName, news_id, tipo,writeMode)
{
	if (!writeMode)
	{
		alert('Attenzione, non si dispone dei diritti necessari. Operazione non possibile.');
		return false;
	}
	if (anchorName == 'aRegioni')
	{
		alert("Attenzione, una eventuale modifica delle regioni comporta automaticamente l'azzeramento delle Provincie e dei Comuni inseriti.");
	}
	if (____win != null)
		____win.close();
	____win = window.open("./PopUp/PopUpCategory.aspx?news_id="+news_id+"&tipo="+tipo, "_popUp", "menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,width=630px,height=600px");
}
function ApriProvincie(anchorName, news_id,writeMode)
{
	if (!writeMode)
	{
		alert('Attenzione, non si dispone dei diritti necessari. Operazione non possibile.');
		return false;
	}
	alert("Attenzione, una eventuale modifica delle provincie comporta automaticamente l'azzeramento dei Comuni inseriti");
	if (____win != null)
		____win.close();
	____win = window.open("./PopUp/PopUpProvincie.aspx?news_id="+news_id, "_popUp", "menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,width=810px,height=600px");
}
function ApriComuni(anchorName, news_id,writeMode)
{
	if (!writeMode)
	{
		alert('Attenzione, non si dispone dei diritti necessari. Operazione non possibile.');
		return false;
	}
	if (____win != null)
		____win.close();
	____win = window.open("./PopUp/PopUpComuni.aspx?news_id="+news_id, "_popUp", "menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,width=810px,height=600px");
}
function ApriContattiSocieta(news_id, writeMode)
{
	if (!writeMode)
	{
		alert('Attenzione, non si dispone dei diritti necessari. Operazione non possibile.');
		return false;
	}
	if (____win != null)
		win.close();
	____win = window.open("./PopUp/PopUpContattiSocieta.aspx?news_id="+news_id, "_popUp", "menubar=no,location=no,resizable=yes,scrollbars=yes,status=yes,width=450px,height=300px");
}

function GetContenutoItemValue(names,urls,ids,images)
{
   var collector;
   var topTable ="<table border='0' class='tabellaSottoMenu'>";
   var bottomTable ="</table>";
   var genericItem="<tr ><td onclick=javascript:location.replace('$$URL$$') style='cursor:pointer' Class='sottoMenuItem' onmouseover='javascript:SelezionaItem(this, __CssClassOver);' onmouseout='javascript:DeSelezionaItem(this, __CssClassNormale);'><img src='$$IMAGE$$' align='absbottom' border='0' />&nbsp;$$LABEL$$</td></tr>";
   var genericItem2="<tr ><td onclick='$$URL$$' style='cursor:pointer' Class='sottoMenuItem' onmouseover='javascript:SelezionaItem(this, __CssClassOver);' onmouseout='javascript:DeSelezionaItem(this, __CssClassNormale);'><img src='$$IMAGE$$' align='absbottom' border='0' />&nbsp;$$LABEL$$</td></tr>";
   
   collector =topTable;
   for(i=0;i<urls.length;i++)
   {
		var temp;
		var tmp = urls[i]; 
		//alert(tmp);
		if (tmp.indexOf('javascript:') != -1)
			temp = genericItem2.replace("$$URL$$",urls[i]);
		else
			temp = genericItem.replace("$$URL$$",urls[i]);
		
		temp = temp.replace("$$URL$$",urls[i]);
        temp = temp.replace("$$ID$$",ids[i]);
        temp = temp.replace("$$LABEL$$", names[i]);
        temp = temp.replace("$$LABEL$$", names[i]);
        temp = temp.replace("$$IMAGE$$", images[i]);
        temp = temp.replace("$$IMAGE$$", images[i]);
        if (urls[i].toLowerCase().indexOf("http://") != -1)
		{
			temp = temp.replace("$$TARGET"," target=_blank ");
			temp = temp.replace("$$TARGET"," target=_blank ");
		} 
		else 
		{
			temp = temp.replace("$$TARGET"," ");
			temp = temp.replace("$$TARGET"," ");
		}
		collector += temp;
   }
   return (collector+bottomTable);
}


// Crea un windows pop-up di dimensione passata
function showLicenza(width,height,utente,server,versione,numeroUtentiConnessi, numeroUtentiLicenza, dataScadenza, release)
{
	var oPopup = window.createPopup();
	var oPopupBody = oPopup.document.body;
	var oPopupHead = oPopup.document.head;
	
	xposition = event.clientX;
	yposition = event.clientY;
	// l'elemento contiene il contenuto
	oPopupBody.innerHTML = "<table style='{border:solid 1px orange; overflow:auto;}' ><tr><td style='{color: #9E8F8F;	font: bold 10px/15px Verdana, Geneva, Arial, Helvetica, sans-serif; word-spacing:4px; }'>&nbsp;&nbsp;Utente: <font color=#0033ff>"+utente+"</font></td></tr><tr><td style='{color: #9E8F8F;	font: bold 10px/15px Verdana, Geneva, Arial, Helvetica, sans-serif; word-spacing:4px; }'>&nbsp;&nbsp;Server: <font color=#0033ff>"+server+"</font></td></tr><td style='{color: #9E8F8F;	font: bold 10px/15px Verdana, Geneva, Arial, Helvetica, sans-serif; word-spacing:4px; }'>&nbsp;&nbsp;Versione: <font color=#0033ff>"+versione+"</font></td></tr><tr><td style='{color: #9E8F8F;	font: bold 10px/15px Verdana, Geneva, Arial, Helvetica, sans-serif; word-spacing:4px; }'>&nbsp;&nbsp;Utenti Connessi: <font color=#0033ff>"+numeroUtentiConnessi+"</font></td></tr><tr><td style='{color: #9E8F8F;	font: bold 10px/15px Verdana, Geneva, Arial, Helvetica, sans-serif; word-spacing:4px; }'>&nbsp;&nbsp;Max Utenti concorrenti: <font color=#0033ff>"+numeroUtentiLicenza+"</font></td></tr><tr><td style='{color: #9E8F8F;	font: bold 10px/15px Verdana, Geneva, Arial, Helvetica, sans-serif; word-spacing:4px; }'>&nbsp;&nbsp;Scadenza Licenza: <font color=#0033ff>"+dataScadenza+"</font></td></tr><tr><td style='{color: #9E8F8F;	font: bold 10px/15px Verdana, Geneva, Arial, Helvetica, sans-serif; word-spacing:4px; }'>&nbsp;&nbsp;Release: <font color=#0033ff>"+release+"</font></td></tr></table>";
	oPopup.show(xposition-20, yposition+2, width, height, document.body);

}

// Funzioni di utilitā per la gestione della sessione
var intervalloID;
var infoCenterRoot; 

function SessionReload(icRoot)
{
	//alert(icRoot);
	window.clearInterval(intervalloID);
	intervalloID = window.setInterval(ReloadSession, 100000); // < di 5 minuti 
	infoCenterRoot = icRoot;
}

function ReloadSession()
{
	//alert(infoCenterRoot);
	var SessionIframe = document.getElementById("SessionAlive");
	SessionIframe.src = infoCenterRoot+"/reload.aspx";
}


function navigaSocieta(pagina, societa_id, nomePagina)
{
	if (pagina.indexOf('?') > 0)
		location.replace(pagina+"&par_id="+societa_id+"&nomePagina="+nomePagina);
	else
		location.replace(pagina+"?par_id="+societa_id+"&nomePagina="+nomePagina);
}

function navigaContatto(pagina, societa_id, nomePagina)
{
	if (pagina.indexOf('?') > 0)
		location.replace(pagina+"&par_id="+societa_id+"&nomePagina="+nomePagina);
	else
		location.replace(pagina+"?par_id="+societa_id+"&nomePagina="+nomePagina);
}


/* Find in javascript */
var NS4 = (document.layers);
var IE4 = (document.all);

var win = this;
var n   = 0;

function findInPage(str) {
 var thewindow = window;
 var txt, i, found;
 if (str == "")
  return false;
 if (NS4) {
  if (!thewindow.find(str))
   while(thewindow.find(str, false, true))
    n++;
  else
   n++;
  if (n == 0) alert(str + " was not found on this page.");
  }
 if (IE4) {
  txt = thewindow.document.body.createTextRange();
  for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
   txt.moveStart("character", 1);
   txt.moveEnd("textedit");
   }
  if (found) {
   txt.moveStart("character", -1);
   txt.findText(str);
   txt.select();
   txt.scrollIntoView();
   n++;
   }
  else {
   if (n > 0) {
    n = 0;
    findInPage(str);
    }
   else
    alert(str + " was not found on this page.");
   }
  } return false;
}

var __fFinestraContenuto = null; 
function FinestraContenuto(url)
{
	if (__fFinestraContenuto != null)
		__fFinestraContenuto.close();
	__fFinestraContenuto = window.open(url,null,"height=600,width=800,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/4 +",left="+(window.screen.width)/4);
}

function Open_Suggerimenti(url)
{
	if (__fFinestraContenuto != null)
		__fFinestraContenuto.close();
	__fFinestraContenuto = window.open(url,null,"height=544,width=472,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/4 +",left="+(window.screen.width)/4);
}


var __fFinestraEditor = null; 
function FinestraEditor(url)
{
	if (__fFinestraEditor != null)
		__fFinestraEditor.close();
	__fFinestraEditor = window.open(url,null,"height=680,width=840,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/4 +",left="+(window.screen.width)/4);
}

var __fPopUpDati = null; 
function PopUpDati(url)
{
	if (__fPopUpDati != null)
		__fPopUpDati.close();
	__fPopUpDati = window.open(url, 'name',"resizable=true,statusbar=false,locationbar=false,scrollbars=true,toolbar=false, width=620,height=550,top="+(window.screen.height)/4 +",left="+(window.screen.width)/4);
}

function cambiaCss(tabella, selezionato, idTitolo)
{
	var titoloTabella = document.getElementById(idTitolo);
	if (selezionato)
	{
		tabella.className = 'tabellaContattoSelezionato';
		titoloTabella.className = 'ContattoTitoloSelezionato';
	} 
	else 
	{
		tabella.className = 'tabellaContatto';
		titoloTabella.className = 'ContattoTitoloNormale';

	}
}


function togliCheck(nome)
{
	var elemento = document.getElementById(nome);
	//alert(elemento);
	elemento.checked = false;
}

function azzeraData(check, testo)
{
	var elemento = document.getElementById(testo);
	if (check.checked)
	{
		elemento.value = "";
	} else 
	{
		elemento.focus();
	}
}


function settaID(ch, cont_id)
{
	var elemento = document.getElementById("contattiSelezionati");
	//alert(elemento.value);
	if (ch.checked){
		if (elemento.value.indexOf(cont_id) == (-1))
		{
			elemento.value = elemento.value + cont_id + "|";
		}
	} 
	else 
	{
		if (elemento.value.indexOf(cont_id) != (-1))
		{
			elemento.value = elemento.value.replace(cont_id + "|", "");
		}
	}
}

function SettaDimensioneSchermo()
{
	var dimensionex = screen.width;
	var dimensioney = screen.height;
	document.forms[0].dimensionex.value = dimensionex;
	document.forms[0].dimensioney.value = dimensioney;
}

function pressioneTasto(){
	if (event != undefined){
		if (event.keyCode != 9 ){ 
			elemento = document.getElementById("LeftPane1_Ricerca1_FiltroRicerca"); 
			elemento.focus();
		}
		if (event.keyCode == 13 || event.KeyCode == 10 ){ 
			elemento = document.getElementById("LeftPane1_Ricerca1_BtnRicerca"); 
			elemento.focus(); 
		}
	}
}

function pressioneTastoIn(elemento){
	var elemento; 
	if (event != undefined){
		if (event.keyCode != 9 && event.srcElement.tagName != 'INPUT'){ 
			elemento = document.getElementById(elemento); 
			elemento.focus();
		}
		if (event.keyCode == 13 || event.KeyCode == 10 ){ 
			elemento = document.getElementById("LeftPane1_Ricerca1_BtnRicerca"); 
			elemento.focus(); 
		}
	}
}

function pressioneTastoXX(elemento, btn){
	var elemento; 
	if (event != undefined){
		if (elemento != null)
		{
			if (event.keyCode != 9 && event.srcElement.tagName != 'INPUT'){ 
				elemento = document.getElementById(elemento); 
				elemento.focus();
			}
		}
		if (event.keyCode == 13 || event.KeyCode == 10 ){ 
			elemento = document.getElementById(btn); 
			elemento.focus(); 
		}
	}
}

function pressioneTasto2(){
	var elemento2; 
	if (event != undefined){
	
		/*if (event.keyCode != 9 ){ 
			elemento2 = document.getElementById("txtBoxSearch"); 
			elemento2.focus();
		} */
		if (event.keyCode == 13 || event.KeyCode == 10 ){ 
			elemento2 = document.getElementById("btnSearch"); 
			elemento2.focus(); 
		}
	}
}


function scrolla(anchorName)
{
	var elemento = document.getElementById(anchorName); 
	elemento.click();
}

function caricaFoto()
{
	var elemento = document.getElementById("campoNascostoFoto"); 
	elemento.value = "yes";
	document.forms[0].submit(); 
}


/************************** gestione pop-up creazione e modifica azienda *************************/
var _winGenericPopUp =null;
var _winGenericPopUp2 =null;
function GenericPopUp(url,width,height)
{	
	if (_winGenericPopUp != null)
		_winGenericPopUp.close();
	_winGenericPopUp = window.open(url,'myGenericPopUp',"height="+height+",width="+width+",status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/6 +",left="+(window.screen.width)/6);
	_winGenericPopUp.focus();
}


function CercaGenerica(url,element_id,element_nome,element_prezzo,element_iva)
{	
	if (element_prezzo == null) element_prezzo ='';
	if (element_iva == null) element_iva ='';
	if (url.indexOf("?") != -1)
	{
		if (element_iva == null)
			url += "&element_id="+element_id+"&element_nome="+element_nome+"&element_prezzo="+element_prezzo;
		else
			url += "&element_id="+element_id+"&element_nome="+element_nome+"&element_prezzo="+element_prezzo+"&element_iva="+element_iva;
	} 
	else
	{
		if (element_iva == null)
			url += "?element_id="+element_id+"&element_nome="+element_nome+"&element_prezzo="+element_prezzo;
		else
			url += "?element_id="+element_id+"&element_nome="+element_nome+"&element_prezzo="+element_prezzo+"&element_iva="+element_iva;
	}
	if (_winGenericPopUp != null)
		_winGenericPopUp.close();
	_winGenericPopUp = 	window.open(url,'myNew',"height=620,width=430,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/6 +",left="+(window.screen.width)/6);
	_winGenericPopUp.focus();
}

function SaveCercaGenerica(id, nome, element_id, element_nome,element_prezzo,element_iva,prezzo,iva)
{	
	var cont_id = window.opener.document.getElementById(element_id);
	var nomeCont =  window.opener.document.getElementById(element_nome);
	if (element_prezzo != null && element_prezzo != 'undefined')
	{
		window.opener.document.getElementById(element_prezzo).value=prezzo;
	}
	if (element_iva != null && element_iva != 'undefined')
	{
		window.opener.document.getElementById(element_iva).value=iva;
	}
	cont_id.value =id;
	nomeCont.value = nome;
	window.close();
}

function cercaSocieta(root,element_id,element_nome)
{	
	var url = null;
	if ((element_id == undefined) || (element_nome == undefined))
	{
		url = root+"/GestioneAziende/cercaSocieta.aspx?element_id=az_fk_soc_id&element_nome=txtBoxAssociataAMod" ;
	} else
	{
		url = root+"/GestioneAziende/cercaSocieta.aspx?element_id=" + element_id +"&element_nome=" + element_nome;
	}
	if (_winGenericPopUp2 != null)
		_winGenericPopUp2.close();
	_winGenericPopUp2 = 	window.open(url,'myNewSocieta',"height=620,width=430,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/6 +",left="+(window.screen.width)/6);
	_winGenericPopUp2.focus();
}

function cercaLead(root,element_id, element_nome)
{	
	var url = null;
	url = root+"/icon/cercaLead.aspx?element_id=" + element_id +"&element_nome=" + element_nome;
	if (_winGenericPopUp != null)
		_winGenericPopUp.close();
	_winGenericPopUp = window.open(url,'myNew',"height=620,width=430,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/6 +",left="+(window.screen.width)/6);
	_winGenericPopUp.focus();
}

function cercaContatto(root,element_id, element_nome, element_societa)
{	
	var url = null;
	url = root+"/icon/cercaContatto.aspx?element_id=" + element_id +"&element_nome=" + element_nome;
	if(element_societa!=null)
		url += "&element_societa=" + element_societa;
	if (_winGenericPopUp != null)
		_winGenericPopUp.close();
	_winGenericPopUp =	window.open(url,'myNew',"height=620,width=430,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/6 +",left="+(window.screen.width)/6);
	_winGenericPopUp.focus();
}

function cercaCampagna(root,element_id,element_nome)
{	
	var url = null;
	url = root+"/iNews/cercaCampagna.aspx?element_id=" + element_id +"&element_nome=" + element_nome;
	if (_winGenericPopUp != null)
		_winGenericPopUp.close();
	_winGenericPopUp = 	window.open(url,'myNew',"height=620,width=430,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/6 +",left="+(window.screen.width)/6);
	_winGenericPopUp.focus();
}


function cercaUfficio(root,element_nome)
{	
	var url = null;
	url = root+"/iCon/cercaUfficio.aspx?element_nome=" + element_nome;
	if (_winGenericPopUp != null)
		_winGenericPopUp.close();
	_winGenericPopUp = window.open(url,'myNew',"height=550,width=430,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top="+(window.screen.height)/6 +",left="+(window.screen.width)/6);
	_winGenericPopUp.focus();
}

function cercaCommessa(url)
{	
	var win = new PopupWindow(); 
	win.autoHide(); 
	win.setUrl(url);
	win.setSize("410px","640px");
	win.showPopup('posizione');
}

function saveRisultatiContatto(id, nome, element_id, element_nome, element_societa,societa)
{	
	var cont_id = window.opener.document.getElementById(element_id);
	var nomeCont =  window.opener.document.getElementById(element_nome);
	
	cont_id.value =id;
	nomeCont.value = nome;
	var socCont;
	if(societa!=null && societa != 'undefined')
	{
		socCont =  window.opener.document.getElementById(element_societa);
		socCont.innerText = societa;
	}
	window.close();
}


function saveRisultatiCampagna(id, nome, element_id, element_nome)
{	
	var cont_id = window.opener.document.getElementById(element_id);
	var nomeCont =  window.opener.document.getElementById(element_nome);
	cont_id.value =id;
	nomeCont.value = nome;
	window.close();
}

function saveRisultatoUfficio(nome, element_nome)
{	
	var nomeCont =  window.opener.document.getElementById(element_nome);
	nomeCont.value = nome;
	window.close();
}


function salvaRisultatiCercaSocieta(id, nome, element_id, element_nome )
{	
	//alert("inizio");
	var soc_id = window.opener.document.getElementById(element_id);
	//alert(soc_id);
	var nomeSoc =  window.opener.document.getElementById(element_nome);
	//alert(nomeSoc);
	soc_id.value =id;
	nomeSoc.value = nome;
	//alert(soc_id.value);
	window.close();
}

function salvaRisultatiCercaSocieta2(id, nome)
{	
	salvaRisultatiCercaSocieta(id,nome,'az_fk_soc_id','CreaContatto1_txtBoxAssociataAMod');
}


function salvaRisultatiCercaCommessa(id, nome)
{	
	//alert("inizio");
	var soc_id = window.opener.document.getElementById("rep_com_fk_com_id");
	//alert(soc_id);
	var nomeSoc =  window.opener.document.getElementById("txtBoxCommessa");
	//alert(nomeSoc);
	soc_id.value =id;
	nomeSoc.value = nome;
	//alert(soc_id.value);
	window.close();
}



function salvaRisultatiCercaContatto(id, nome)
{	
	//alert("inizio");
	var soc_id = window.opener.document.getElementById("pren_fk_cont_id");
	//alert(soc_id);
	var nomeSoc =  window.opener.document.getElementById("NuovaPrenotazione1_txtBoxContatto");
	if (nomeSoc == null || nomeSoc == 'undefined')
		nomeSoc =  window.opener.document.getElementById("txtBoxContatto");
	//alert(nomeSoc);
	soc_id.value =id;
	nomeSoc.value = nome;
	//alert(soc_id.value);
	window.close();
}
/************************************* fine *******************************************************/

// funzione che apre una finestra
var popUpEditor=null;  
function apriEditor(url)
{
	if (popUpEditor != null)
		popUpEditor.close();
	popUpEditor = window.open(url, 'editorWin',"status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes, width=1024, ,height=768,top=10");
}

var popUp=null; 
function apriConsensi(url)
{
	if (popUp != null)
		popUp.close();
	popUp = window.open(url, 'name',"resizable=true,statusbar=false,locationbar=false,scrollbars=true,toolbar=false, width=650, ,height=550,top=100");
}


function RicaricaPadre()
{
	var parent_location = opener.parent.location.href; 
	/*if (parent_location.indexOf('?pp')>0)
	{
		parent_location = parent_location.replace("?pp=","?");
	}*/
	if (parent_location.indexOf('force')>0)
	{ 
		parent_location = parent_location.replace("&force=true", "");
		parent_location = parent_location.replace("?force=true", "");
	} 
	else 
	{
		if (parent_location.indexOf('?')>0)
		{
			parent_location =  parent_location +"&force=true";
		}
		else 
		{
			parent_location =  parent_location +"?force=true";
		}
	}
	opener.parent.location.replace(parent_location);
}

var fApriCercaAzienda = null; 
function ApriCercaAzienda()
{
	if (fApriCercaAzienda != null) fApriCercaAzienda.close();
	fApriCercaAzienda = window.open('cercaazienda.aspx', 'ffApriCercaAzienda',"status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes, width=600, height=800,top=100,left=100");
	fApriCercaAzienda.focus();
}


var finestraFattura = null; 
function ApriFattura(a)
{
	if (finestraFattura != null) finestraFattura.close();
	finestraFattura = window.open("dettaglioFattura.aspx?fat_id="+a,null,"height=910,width=780,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top=0,left=20");
	finestraFattura.focus();
}

function GeneraParametro(root,isFile)
{
	var win = new PopupWindow(); 
	win.autoHide(); 
	win.setUrl(root+"/developer/InserisciParametro.aspx?file="+isFile);
	win.setSize("440px","360px");
	win.showPopup('posizione');
}



var finestraDettaglio = null; 
function ApriDocs(strUrl, posizione)
{
	if (finestraDettaglio != null) finestraDettaglio.close();
	finestraDettaglio = window.open(strUrl,"ApriDocs","height=630,width=760,status=yes,toolbar=no,menubar=no,location=no,resizable=yes,scrollbars=yes,top=50,left=50");
	finestraDettaglio.focus();
}


function checkMail(emailField)
{
	var x = document.getElementById(emailField).value;
	x = Trim(x);
	if (x != '')
	{
		var filter  = /^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
		if (!filter.test(x))
		{
			alert("Attenzione controllare l'Indirizzo Email.\n\r\n\r"+x+" e' in formato NON VALIDO.");
			return false; 
		}
	} 
	return true; 
	
}

function ControllaOpportunita(titolo,redditotarget,numeroProdotti)
{
	if (!CampoObbligatorio("Il titolo della opportunitā č obbligatorio",titolo))
		return false;
	val = Trim(document.getElementById(redditotarget).value);
	if (CheckIsFloat(val))
	{
		alert('Il reddito target ha un valore non corretto');
		return false;
	}
	val = Trim(document.getElementById(numeroProdotti).value);
	if (CheckIsFloat(val))
	{
		alert('Il numero di prodotti target ha un valore non corretto');
		return false;
	}
	return true;
}

function CheckIsFloat(val)
{
	val = val.replace('.','').replace(',','.');
	return isNaN(val);
}

function CliccaSu(campo)
{
	document.getElementById(campo).click();
}


function ControllaAzienda(titolo,numeroDipendenti,fatturato, email)
{
	if (!CampoObbligatorio("Il nome azienda č obbligatorio",titolo))
		return false;
	val = Trim(document.getElementById(numeroDipendenti).value);
	if (!checkMail(email))
		return false;
	if (CheckIsFloat(val))
	{
		alert('Il numero dei dipendenti ha un valore non corretto');
		return false;
	}
	val = Trim(document.getElementById(fatturato).value);
	if (CheckIsFloat(val))
	{
		alert('Il fatturato ha un valore non corretto');
		return false;
	}
	return true;
}

function ControllaContatto(nome, cognome, email)
{
	val = document.getElementById(nome).value + document.getElementById(cognome).value;
	if (Trim(val) == '')
	{
		alert("Il Nome o il Cognome sono obbligatori.");
		return false; 
	}
	if (!checkMail(email))
		return false;
}


function ControllaCreazioneLead(nome,cognome,societa,redditoPrevisto, email)
{
	var n = document.getElementById(nome).value;
	var s = document.getElementById(cognome).value;
	var c = document.getElementById(societa).value;
	if (   n == '' 
		&& s == '' 
		&& c == ''
		)
	{
		alert("Attenzione, per creare un Lead č necessario inserire almeno un campo tra:\n\r- Nome\n\ro\rn\n- Cognome\n\ro\r\n- Azienda");
		return false;
	}
	if (!checkMail(email))
		return false;
	val = Trim(document.getElementById(redditoPrevisto).value);
	if (CheckIsFloat(val))
	{
		alert('Il reddito previsto ha un valore non corretto');
		return false;
	}	
	return true;	
}

function NonAbilitata()
{
	alert("Funzione non abilitata");
}


function SelezionaCampoRicerca(nomeCampo)
{
	campo = document.getElementById(nomeCampo);
	if (campo != 'undefined' && campo != null && campo != undefined)
	{
		if (Trim(campo.value) == '')
		{
			campo.select();
			campo.focus();	
		}
	}
}


/*******************************  Gestione Scadenza Sessione *******************************/
var TimeOutToLogin = null;
var IsFromPopUp = false; 
function ScadenzaSessione(root)
{
	window.focus();
	document.getElementById("_session_div").style.display ='block';
	document.getElementById("_session_div").top = ((window.screenY/2)- 50);
	document.getElementById("_session_div").left = ((window.screenX/2)- 50);
	TimeOutToLogin = window.setTimeout("ScadutoToLogin('"+root+"')",28000);
}

function ScadutoToLogin(root)
{
	window.focus();
	Cerca_Chisura_PopUP();
	location.href= root+"/login.aspx?sessiontimeout=true&tourl="+tourl;
}

var xmlhttpSessione =null;
var rootToReloadTimeOut = null;
function OK_PopUp_Sessione(root)
{
	rootToReloadTimeOut = root;
	xmlhttpSessione =  new XMLHttpRequest();
	xmlhttpSessione.onreadystatechange = state_reload_sessione;
	xmlhttpSessione.open("GET",root+"/Reload.aspx",true);
	xmlhttpSessione.send(null);
	document.getElementById('_session_div').style.display='none';
}

function state_reload_sessione()
{
	if (xmlhttpSessione.readyState == 4)
	{
		window.clearTimeout(TimeOutToLogin);
		window.setTimeout("ScadenzaSessione('"+rootToReloadTimeOut+"')",timeOutSessione);
	}
}

function Cerca_Chisura_PopUP()
{
	if (fConverti != null)
		fConverti.close();
	if (popUp2 != null)
		popUp2.close();
	if (____win != null)
		____win.close();
	if (__fFinestraContenuto != null)
		__fFinestraContenuto.close();
	if (__fFinestraEditor != null)
		__fFinestraEditor.close();
	if (__fPopUpDati != null)
		__fPopUpDati.close();
	if (_winGenericPopUp != null)
		_winGenericPopUp.close();
	if (popUpEditor != null)
		popUpEditor.close();
	if (popUp != null)
		popUp.close();
	if (fApriCercaAzienda != null)
		fApriCercaAzienda.close();
	if (finestraFattura != null)
		finestraFattura.close();
	if (finestraDettaglio != null)
		finestraDettaglio.close();
	if (_winGenericPopUp2 != null)
		_winGenericPopUp2.close();
		
	fConverti = null;
	popUp2 = null;
	____win = null;
	__fFinestraContenuto = null;
	__fFinestraEditor = null;
	__fPopUpDati = null;
	_winGenericPopUp = null;
	popUpEditor = null;
	popUp = null;
	fApriCercaAzienda = null;
	finestraFattura = null;
	finestraDettaglio = null;
}
/********************************* Fine Gestione Scadenza Sessione ****************************/
		

function ClickLink(nameLink)
{
	document.getElementById(nameLink).click();
	return false;
}

function CliccaQuiSeTastoEnter(e,dove)
{
	if(e.keyCode == 10 || e.keyCode == 13)
	{
		ClickLink(dove);
		e.cancelBubble = true;
	}
	return false;
}