// window per richiesta conferma operazione da link

    function confirmSubmit(msg)
    {
    
      if (msg == null || msg == ''){
        msg = "Are you sure you wish to continue?";
      }
      var agree=confirm(msg);
      if (agree){
      	return true ;
      }else{
      	return false ;
      }
    }
    

    function confirmandgo(msg,url,tgt)
    {
      var agree = true;
      if (!(msg == null || msg == '')){
        agree=confirm(msg);
      }
      if (agree){
        var a = wopennew(url,tgt);
      	// parent.location.href = url
      }else{
      	return false ;
      }
      
    }

// funzioni per treeview

      function expandNode(level, levelStatus) {
        var elem = document.getElementById(level + levelStatus);
        var imgElem = document.getElementById('img' + level + levelStatus);
        if (elem.style.display == 'none') {
          elem.style.display='inline';
          document.cookie=level+levelStatus+ '=inline;';
          if (imgElem != null) {
            imgElem.src='Resources/minus.gif';
          }
        } else {
          elem.style.display='none';
          document.cookie=level+levelStatus+ '=none;'
          if (imgElem != null) {
            imgElem.src='Resources/plus.gif';
          }
        }  
      }  

      function writeDisplay(level, levelStatus) {
        var elem = document.getElementById(level + levelStatus);
        var imgElem = document.getElementById('img' + level + levelStatus);

        tempArray = document.cookie.split(';');

        finalArray = new Array();
        i = 0;
        for (aCookie in tempArray) {
          finalArray[i] = tempArray[aCookie].split('=');
          i++;
        }
        
        for (j = 0; j < finalArray.length; j++) {
          if (xtrim(finalArray[j][0]) == (level+levelStatus)) {
            elem.style.display=finalArray[j][1];
            if (imgElem != null) {
              if (finalArray[j][1] == 'inline') {
                imgElem.src='Resources/minus.gif';
              } else if (finalArray[j][1] == 'none') {
                imgElem.src='Resources/plus.gif';
              }
            }
          }
        }        
      }
      function xtrim(s) {
        while (s.substring(0,1) == ' ') {
          s = s.substring(1,s.length);
        }
        while (s.substring(s.length-1,s.length) == ' ') {
          s = s.substring(0,s.length-1);
        }
        return s;
      }
      
    function contextMenu(level)
    {
        var oPopup = window.createPopup();
        var elem = document.getElementById('octx'+level);
        var trelem = document.getElementById('TRC'+level);
        var maxlen = 0;
        if(elem != null){
          // The variables "lefter" and "topper" store the X and Y coordinates
          // to use as parameter values for the following show method. In this
          // way, the popup displays near the location the user clicks. 
          var lefter = event.clientX+10;
          var topper = event.clientY+10;
          var oPopBody = oPopup.document.body;
          oPopBody.style.backgroundColor = "lightyellow";
          oPopBody.style.border = "solid black 1px";
          oPopBody.innerHTML = elem.innerHTML; 

          if (elem.children.length > 0) {
            oPopup.show(lefter, topper, 300, (20 * elem.children.length), document.body);
          
          }
          // trelem.style.backgroundColor = "lightblue"
           // document.getElementById('zuppo').parentElement.all[5].outerHTML
        
        }
    }

     function newcontextMenu(level,links){
        var novis = "";
        var prot = "";
        var linkcur = "";
        var elem = document.getElementById('octx'+level);
        var enovis = document.getElementById('ehivetprot');
        var eprot = document.getElementById('ehivetnovis');
        var trelem = document.getElementById('TRC'+level);
        var maxlen = 0;
        var strin = ""
        vsplit = links.split("|");
        if(links != ""){
          // The variables "lefter" and "topper" store the X and Y coordinates
          // to use as parameter values for the following show method. In this
          // way, the popup displays near the location the user clicks. 
          var lefter = event.clientX+10;
          var topper = event.clientY+10;
          var oPopBody = oPopup.document.body;
          oPopBody.style.backgroundColor = "lightyellow";
          oPopBody.style.border = "solid black 1px";
          // strin = strin + "<DIV ID=\"octx"+level +"\" STYLE=\"display:none;width: 350px; background-color: #cc9;border: 5px dotted #333; padding: 5px;margin: 0px auto\">";
          for (j = 0; j < vsplit.length - 1; j=j+5) {
          
          
              if (enovis != null) {
                  novis = enovis.innerHTML;
                  if (prot.indexOf(vsplit[j+2],novis) == -1 ) {
                      strin = strin + "<DIV onmouseout=\"this.style.background='#e4e4e4';this.style.cursor='default'\" onmouseover=\"this.style.background='gold';this.style.cursor='hand'\">";
                      if (eprot != null) {
                            prot = eprot.innerHTML;
                            if (prot.indexOf(vsplit[j+2],prot) == -1 ) {
                                //if(vsplit[j+3] != ""){
                                  strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"return parent.confirmandgo('"+vsplit[j+3]+"','"+vsplit[j]+"','"+vsplit[j+4]+"');\">";
                                //}else{
                                //  strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"parent.location.href='" + vsplit[j]+"'\">";
                                //}
                            }else{
                                strin = strin + "<SPAN>";
                            }
                            strin = strin + vsplit[j+1];
                            strin = strin + "</SPAN></DIV>";
                      }else{
                      //if(vsplit[j+3] != ""){
                          strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"return parent.confirmandgo('"+vsplit[j+3]+"','"+vsplit[j]+"','"+vsplit[j+4]+"');\">";
                      //  strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"return parent.confirmandgo('"+vsplit[j+3]+"','"+vsplit[j]+"');\">";
                      //}else{
                      //  strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"parent.location.href='" + vsplit[j]+"'\">";
                      //}
                        strin = strin + vsplit[j+1];
                        strin = strin + "</SPAN></DIV>";                      
                      }
                  }                                 
              }else{
                strin = strin + "<DIV onmouseout=\"this.style.background='#e4e4e4';this.style.cursor='default'\" onmouseover=\"this.style.background='gold';this.style.cursor='hand'\">";
                if (eprot != null) {
                      prot = eprot.innerHTML;
                      if (prot.indexOf(vsplit[j+2],prot) == -1 ) {
                          //if(vsplit[j+3] != ""){
                              strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"return parent.confirmandgo('"+vsplit[j+3]+"','"+vsplit[j]+"','"+vsplit[j+4]+"');\">";
                          //  strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"return parent.confirmandgo('"+vsplit[j+3]+"','"+vsplit[j]+"');\">";
                          //}else{
                          //  strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"parent.location.href='" + vsplit[j]+"'\">";
                          //}
                      }else{
                          strin = strin + "<SPAN>";
                      }
                      strin = strin + vsplit[j+1];
                      strin = strin + "</SPAN></DIV>";
                }else{
                    //if(vsplit[j+3] != ""){
                        strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"return parent.confirmandgo('"+vsplit[j+3]+"','"+vsplit[j]+"','"+vsplit[j+4]+"');\">";
                    //  strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"return parent.confirmandgo('"+vsplit[j+3]+"','"+vsplit[j]+"');\">";
                    //}else{
                    //  strin = strin + "<SPAN STYLE='font:normal 10pt Verdana' onclick=\"parent.location.href='" + vsplit[j]+"'\">";
                    //}
                    strin = strin + vsplit[j+1];
                    strin = strin + "</SPAN></DIV>";                      
                }
              
              }
          }
          //strin = strin + "</DIV>";

          oPopBody.innerHTML = strin; 

          if (links != "") {
            oPopup.show(lefter, topper, 300, (20 * (vsplit.length/4)), document.body);
          
          }
          // trelem.style.backgroundColor = "lightblue"
           // document.getElementById('zuppo').parentElement.all[5].outerHTML
        
        }
    }



/*
function GetCookie(name){ 
   var biscotti = document.cookie.split("; ");  // separo i blocchi di informazioni con il punto e virgola
   var valore = null;
   for (i=0; i < biscotti.length; i++) {
      briciola = biscotti[i].split("="); // divido l'informazione name dal suo valore
      if (briciola[0] == name) { // cerca il cookie con il nome appena definito
        valore = briciola[1]; // memorizza il codice in una variabile
        return valore;   // restituisco il valore in uscita
      }
   }
   return valore;
}
*/

function Set_Cookie( namecok, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = namecok + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}


// this fixes an issue with the old method, ambiguous values 
// with this test document.cookie.indexOf( name + "=" );
function Get_Cookie( check_name, bstart ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	
	for (var i = 0; i < a_all_cookies.length; i++ )
	{
		// now we'll split apart each name=value pair
		a_temp_cookie = a_all_cookies[i].split( '=' );
		
		
		// and trim left/right whitespace while we're at it
		cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
	
		// if the extracted name matches passed check_name
		if (bstart){
			if (cookie_name.indexOf(check_name)== 0){
				b_cookie_found = true;		
			}
		}else{
			if (cookie_name == check_name){
					b_cookie_found = true;
			}
		}
		
		if (b_cookie_found)
		{
			// we need to handle case where cookie has no value but exists (no = sign, that is):
			if ( a_temp_cookie.length > 1 )
			{
				cookie_value = unescape( a_temp_cookie[1].replace(/^\s+|\s+$/g, '') );
			}
			// note that in cases where cookie is initialized but no value, null is returned
			return cookie_value;
			break;
		}
		a_temp_cookie = null;
		cookie_name = '';
	}
	if ( !b_cookie_found )
	{
		return null;
	}
}				
				

// this deletes the cookie when called
function Del_Cookie( namecok, path, domain ) {
var tmp = namecok + "=NaN" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
if ( Get_Cookie( namecok ) ) document.cookie = tmp;
}


function Del_AllCookie( check_name,path,domain ) {
	// first we'll split this cookie up into name/value pairs
	// note: document.cookie only returns name=value, not the other components
	var a_all_cookies = document.cookie.split( ';' );
	var a_temp_cookie = '';
	var cookie_name = '';
	var cookie_value = '';
	var b_cookie_found = false; // set boolean t/f default f
	var curnames = check_name.split(';');	
		for (var i = 0; i < a_all_cookies.length; i++ )
		{
			// now we'll split apart each name=value pair
			a_temp_cookie = a_all_cookies[i].split( '=' );
			
			
			// and trim left/right whitespace while we're at it
			cookie_name = a_temp_cookie[0].replace(/^\s+|\s+$/g, '');
		
			// if the extracted name begin with passed check_name[j]
			b_cookie_found = false;
			for ( j = 0; j < curnames.length; j++ )
			{
				if (curnames[j] != '') {
					if (cookie_name.indexOf(curnames[j])== 0){
						Del_Cookie(cookie_name, path, domain);
					}
				}
			}
	
			
			a_temp_cookie = null;
			cookie_name = '';
		}

	return b_cookie_found;
}





















//comboboxGearchiche
function loadAllOptions(){
  var sele = document.all.tags("select");
  var onchg = "";
  var child = null ;
    for ( var i=0 ; i<sele.length ; i++)
    {
      child = document.all(sele[i].name);
      onchg = child.getAttribute("onchange");
      
      if (onchg != null) {
        if (onchg.toString().indexOf("swapOptions") > 0 ) {
          swapOptions(child)
        }
      }
    }
}



function swapOptions(FldGes){
 
gesCampo(FldGes,"");


  }

function gesCampo(cbo,filt){
  
  var cboval = ""
  if (cbo.selectedIndex != - 1){
    cboval = cbo.options[cbo.selectedIndex].value
  } else {
    cboval = ""  
  }
  for(c=0; c <cadrive.length; c=c+2)
  {
      if (cadrive[c] == "*" + cbo.name ) {
          if (filt != "") {
            loadOptions(cbo, filt);        
          }
          afigli = cadrive[(c +1)].split("|");
          for(y=0; y <afigli.length; y++)
          {
            if (cboval != "") {
              loadOptions(document.all(afigli[y]),cbo.options[cbo.selectedIndex].value);
              gesCampo(document.all(afigli[y]),cbo.options[cbo.selectedIndex].value);
            } else {
              document.all(afigli[y]).options.length = 0;
              gesCampo(document.all(afigli[y]),"");
            }
          
          }         
      
      }
  }
}

function loadOptions(curcbo,curfilt){
  addoptl = new Array();
  addoptv = new Array();
  var tmp1 = "";
  i = 0;
  for(x=0; x<curcbo.options.length; x=x+1){
    if(curcbo.options[x].value =="" || parseInt(curcbo.options[x].value) < 1){
      
          addoptl[i] = curcbo.options[x].text;
          addoptv[i] = curcbo.options[x].value;
          i++;
    }
  }

    //curfilt = curfilt.replace('\'','_');
  curcbo.options.length = 0;

  for(x=0; x<addoptl.length; x=x+1){
      opt = new Option(addoptl[x],addoptv[x]);
      curcbo.options.add(opt);                
  }
  
  for(x=0; x <cavalori.length; x=x+4)
  {
    if (cavalori[x] == curcbo.name ) {
        aoid = cavalori[(x+1)].split("|");          
        alab = cavalori[(x+2)].split("|");          
        afat = cavalori[(x+3)].split("|");          
        for(z=0; z <afat.length; z++)
        {
            if ( ((afat[z] == curfilt && curfilt !="") || curfilt == "") ) {
                tmp1 = alab[z].replace('_','\'');

                opt = new Option(tmp1,aoid[z]);
                curcbo.options.add(opt);                
            }
        }    
    }


  }
}


//Collapsed UnitFrame

function outliner()
{
  var srcElement = event.srcElement;
  if (event.srcElement.tagName != "TH")
  {
    srcElement = event.srcElement.parentElement;
  }
  var child = srcElement.parentElement.parentElement.all[srcElement.getAttribute("child",false)];
  if (null != child)
  {
    child.className = (child.className == "COLLAPSED" ? "EXPANDED" : "COLLAPSED");
    if (event.srcElement.tagName == "INPUT")
    {
    event.srcElement.value = (child.className == "COLLAPSED" ? "+" : "-");
    }
  else
  {
  
    for ( var i=0 ; i<event.srcElement.all.length ; i++)
    {
      if (event.srcElement.all[i].tagName == "INPUT")
      {
        event.srcElement.all[i].value = (child.className == "COLLAPSED" ? "+" : "-");
      }
    }
  }
  }
}
function expandCollapseAll(fromState,toState,image)
{
var th = document.all.tags("TH");
for ( var i=0 ; i<th.length ; i++)
{
var child = th[i].parentElement.parentElement.all[th[i].getAttribute("child",false)];
if ((null != child) && (child.className == fromState))
{
child.className = toState;
for ( var j=0 ; j<th[i].all.length ; j++)
{
if (th[i].all[j].tagName == "INPUT")
{
th[i].all[j].value = image;
}
}
}
}
}
function OnDocumentLoad()
{
// Get IE version.
var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
var bUpdateTables = false;
if (msie)
{
var str = new String( ua.substring(msie+5, ua.indexOf(".",msie) + 2) );
if (str >= 5.5)
{
// Make tables fixed when using IE5.5+.
bUpdateTables = true;
}
}
if (bUpdateTables)
{
var tbl = document.all.tags("TABLE");
for ( var i=0 ; i<tbl.length ; i++)
{
tbl[i].style.tableLayout = "fixed";
}
}
}

function dynalandmark(elemx,evis){

// elem e' l'elemento che scatena il click
// evis e' l'elemento che bisogna cambiare la visibility
	//lndvals = new Array();
	//lndelem = new Array();
	var okelem = false // true se presente l'elemento nella pagina
	var okvis = false // true l'elemento e' visualizzabile
	var targetelem = null;
	var sourceelem = null;
	var valueelem = null;
	
	
	lndelem = elemx.split("|");
	lndelem.pop();
	//targetelem = document.getElementsById(evis);
	targetelem = getElementsById(evis);
	if (targetelem != null){
		for (y = 0; y < targetelem.length; y++) {
			for (z = 0; z < lndelem.length; z++) {
				// provo prima con _valore
				tmp = lndelem[z].split(":");
				valueelem = tmp[1];
				sourceelem = document.getElementById(tmp[0]+"_"+tmp[1]); // fld650_locale:7 -> fld650_locale_7
				// se == null provo a vedere se esiste il nome senza _valore (il caso delle select e dei field normali)
				if (sourceelem == null){
						sourceelem = document.getElementById(tmp[0]);
				}
				if (sourceelem == null){
						okvis = okvis || (Get_Cookie(evis)=="visible"); 
				}else{
				//alert(sourceelem.tagName); // SELECT,INPUT
				//alert(sourceelem.type);// select-one,checkbox,text
						if (sourceelem.tagName=="INPUT" && (sourceelem.type == "checkbox" || sourceelem.type == "radio")){
							// multibox or radio
								okvis = okvis || sourceelem.checked;
						}else if(sourceelem.tagName=="SELECT" && (sourceelem.type =="select-one" || sourceelem.type =="select-multiple")){
							// multiselect or select
							for (i = 0; i < sourceelem.options.length; i++) {
								if (sourceelem.options[i].value == valueelem){
									okvis = okvis || sourceelem.options[i].selected;
								} 
	    				}
						}else if (sourceelem.tagName=="INPUT" && sourceelem.type == "text"){
									okvis = okvis || (sourceelem.value == valueelem);	
						}else if (sourceelem.tagName=="INPUT" && sourceelem.type == "hidden"){
									okvis = okvis || (sourceelem.value == valueelem);								
						}else{ 
							alert("dynalandmark tag non previsto="+sourceelem.tagName+ " tipo="+sourceelem.type);
						}
				}
				
			}	
		
			if (okvis){
					Set_Cookie( evis, 'visible', '', '/', '', '' );
					targetelem[y].parentNode.style.visibility = "visible";			
			}else{
					Del_Cookie(evis, '/', '');
					targetelem[y].parentNode.style.visibility = "hidden";			
			}				
	
		}	
	
	}
}
	
 function getElementsById(sId)
 {
    var outArray = new Array();	
	if(typeof(sId)!='string' || !sId)
	{
		return outArray;
	};
	
	if(document.evaluate)
	{
		var xpathString = "//*[@id='" + sId.toString() + "']"
		var xpathResult = document.evaluate(xpathString, document, null, 0, null);
		while ((outArray[outArray.length] = xpathResult.iterateNext())) { }
		outArray.pop();
	}
	else if(document.all)
	{
		if (typeof(document.all[sId]) == 'undefined') {
			return null;
		}
		if (typeof(document.all[sId].length) == 'undefined') {
			outArray[0] =  document.all[sId];
		}else{
			for(var i=0,j=document.all[sId].length;i<j;i+=1){
			outArray[i] =  document.all[sId][i];}		
		}

		
	}else if(document.getElementsByTagName)
	{
	
		var aEl = document.getElementsByTagName( '*' );	
		for(var i=0,j=aEl.length;i<j;i+=1){
		
			if(aEl[i].id == sId )
			{
				outArray.push(aEl[i]);
			};
		};	
		
	};
	
	return outArray;
 }



//----------------------------------------------------------------------------
