
//browser detection

if (navigator.appName == "Netscape")var isNetscape = true;
if (navigator.appName == "Microsoft Internet Explorer") var isExplorer = true;
if (window.opera) var isOpera = true;
if (navigator.userAgent.toLowerCase().indexOf("safari") != -1) var isSafari=true;

//OS detection
if (navigator.appVersion.indexOf("Win") != -1) var isWin = true;
if (navigator.appVersion.indexOf("Mac") != -1) var isMac = true;
if (navigator.appVersion.indexOf("X11") != -1) var isUnix = true;
if (navigator.appVersion.indexOf("Linux") != -1) var isLinux = true;

//Version detection
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);
var version = navigator.appVersion.substring(0, 1);

//windowDimensionDetection
var winWidth,winHeight;

function obj(objId) {
  return document.getElementById(objId);
}

function createEl(theEl) {
  return document.createElement(theEl);
}

function selectAllCheckBoxes(formId) {
  var f = obj(formId);
  for (var k = 0; k < f.elements.length; k++) {
    var e = f.elements[k];
    if (e.type.toLowerCase() == 'checkbox')
      e.checked = 'true';
  }
}

function getWindowDimensionH() {
  if (isNetscape) {
    winHeight = top.window.innerHeight;
  }
  if (isExplorer) {
    winHeight = document.documentElement.offsetHeight;
  }
  return winHeight;
}

function getWindowDimensionW() {
  if (isNetscape) {
    winWidth = top.window.innerWidth;
  }
  if (isExplorer) {
    winWidth = document.documentElement.offsetWidth-20;
  }
  return winWidth;
}

function sendWindowResizeMessage() {

  obj("commander").src = "/commons/tools/command.jsp?_VP_V_ID=9933393&CM=UPDATEWINSIZE&PAGE_HEIGHT=" + getWindowDimensionH() + "&PAGE_WIDTH=" + getWindowDimensionW();
}

function truebody(){
  return (!window.opera && document.compatMode && document.compatMode!="BackCompat")? document.documentElement : document.body;
}

function getEvent(){
  return window.event;
}

//mouse position detection
if (!isExplorer) document.captureEvents(Event.MOUSEMOVE)
document.onmousemove = getMouseXY;
var mouseX = 0;
var mouseY = 0;
function getMouseXY(e) {
  if (isExplorer) {
    mouseX = event.clientX + truebody().scrollLeft;
    mouseY = event.clientY + truebody().scrollTop;
  } else {
    mouseX = e.pageX;
    mouseY = e.pageY;
  }
  if (mouseX < 0) {
    mouseX = 0;
  }
  if (mouseY < 0) {
    mouseY = 0;
  }
  return true;
}

function showHideDiv(divId) {
  if (obj(divId))
    if (obj(divId).style.visibility == 'hidden') {
      obj(divId).style.visibility = 'visible';
    } else {
      obj(divId).style.visibility = 'hidden';
    }
}

function showHideSpan(spanId) {
  if (obj(spanId))
    if (obj(spanId).style.display == 'none') {
      obj(spanId).style.display = '';
    } else {
      obj(spanId).style.display = 'none';
    }
}
function showHide(id) {
  if (obj(id))
    if (obj(id).style.display == 'none') {
      obj(id).style.display = 'block';
    } else {
      obj(id).style.display = 'none';
    }
}

function displayDiv(divId) {
  if (obj(divId))
    obj(divId).style.display = '';
  var i=0;
}

function displayNoneDiv(divId) {
  if (obj(divId))
    obj(divId).style.display = 'none';
}

function hideDiv(divId) {
  if (obj(divId))
    obj(divId).style.visibility = 'hidden';
}

function showDiv(divId) {
  if (obj(divId))
    obj(divId).style.visibility = 'visible';
}

function centerPopup(url, nome, w, h, scroll, resiz) {
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  if(!resiz)
    resiz=true;
  winprops = 'height=' + h + ',width=' + w + ',top=' + wint + ',left=' + winl + ',scrollbars=' + scroll + ',resizable='+resiz+', toolbars=false, status=false, menubar=false';
  //alert (winprops);
  win = window.open(url, nome, winprops)
  if (parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
}

function openCenteredWindow(url, target, winprops) {

  var prop_array=winprops.split(",");
  var i=0;
  var w=800;
  var h=600;
  while (i < prop_array.length) {
    if (prop_array[i].indexOf('width')>-1) {
      s = prop_array[i].substring(prop_array[i].indexOf('=')+1);
      w = parseInt(s);
    } else if (prop_array[i].indexOf('height')>-1) {
      s = prop_array[i].substring(prop_array[i].indexOf('=')+1);
      h = parseInt(s);
    }
    i+=1;
  }
  var winl = (screen.width - w) / 2;
  var wint = (screen.height - h) / 2;
  winprops = winprops + ",top="+wint+",left="+winl;
  win = window.open(url, target, winprops)
  if (parseInt(navigator.appVersion) >= 4) {
    win.window.focus();
  }
}

//----------------------------------positioning------------------------------------------------------

// to determinate the real x position of the element
function getAbsoluteLeft(el) {
  xPos = el.offsetLeft;
  tempEl = el.offsetParent;
  while (tempEl != null) {
    xPos += tempEl.offsetLeft;
    tempEl = tempEl.offsetParent;
  }
  return xPos;
}

// to determinate the real y position of the element

function getAbsoluteTop(el) {
  yPos = el.offsetTop;
  tempEl = el.offsetParent;
  while (tempEl != null) {
    yPos += tempEl.offsetTop;
    tempEl = tempEl.offsetParent;
  }
  return yPos;
}

function getAbsoluteLeftWin(el) {
  if (isExplorer)
    xPos = window.screenLeft + getAbsoluteLeft(el);
  else
    xPos = window.screenX + getAbsoluteLeft(el);
  return xPos;
}

function getAbsoluteTopWin(el) {
  if (isExplorer)
    yPos = window.screenTop + getAbsoluteTop(el);
  else
    yPos = window.screenY + getAbsoluteTop(el);
  return yPos;
}


function positionIt(where, theObj) {

  //if (!distanceY) distanceY = 0;
  //if (!distanceX) distanceX = 0;

  var el = document.all ? document.all(where) : obj ? obj(where) : null;
  var target = document.all ? document.all(theObj) : obj ? obj(theObj) : null;
  if (el) {
    trueX = getAbsoluteLeft(el);
    //trueX += distanceX;
    trueY = getAbsoluteTop(el);
    var h = el.offsetHeight;
    elHeight = parseFloat(h);
    trueY += parseFloat(elHeight); //+ distanceY;
    target.style.left = trueX;
    target.style.top = trueY;
  }
}

function nearBestPosition(where, theObj) {

  var el = document.all ? document.all(where) : obj ? obj(where) : null;
  var target = document.all ? document.all(theObj) : obj ? obj(theObj) : null;
  if (el) {
    trueX = getAbsoluteLeft(el);
    trueY = getAbsoluteTop(el);
    var h = el.offsetHeight;
    elHeight = parseFloat(h);
    trueY += parseFloat(elHeight);
    target.style.left = trueX;
    target.style.top = trueY;
    barHeight=(isExplorer)?45:35;
    barWidth=(isExplorer)?20:0;
    if (getAbsoluteLeft(target)>=(getWindowDimensionW()-target.offsetWidth)){
      target.style.left=getWindowDimensionW()-target.offsetWidth-barWidth;
    }
    if (getAbsoluteTop(target)+target.offsetHeight>=(getWindowDimensionH()-barHeight)){
      target.style.marginTop=((getAbsoluteTop(target)-((getWindowDimensionH()-barHeight)-el.offsetHeight)))+"px";
    }
  }
}


/*
     // if the subMenu is out of the window then reposition it
        tableMenuEl= obj('table'+theId);
        targetWidth= tableMenuEl.offsetWidth;
        targetHeight =tableMenuEl.offsetHeight;
        windowHeight=getWindowDimensionH()
        windowWidth = getWindowDimensionW();

        if (getAbsoluteLeft(theSubMenuEl)>=(windowWidth-targetWidth)){
            theSubMenuEl.style.marginLeft=-((obj(relativeTo).offsetWidth+targetWidth)+(subMenuMarginLeft*2));
        }
        barHeight=(isExplorer)?45:35;
        if (getAbsoluteTop(theSubMenuEl)+targetHeight>=(windowHeight-barHeight)){
            theSubMenuEl.style.marginTop=-((getAbsoluteTop(theSubMenuEl)-((windowHeight-barHeight)-targetHeight)))+"px";
        }

*/


function centerObject(objId) {
  if (obj(objId)) {
    var theObject = obj(objId)
    theObject.style.position = "absolute";
    theObject.style.top = (document.body.clientHeight - parseFloat(theObject.offsetHeight)) / 2;
    theObject.style.left = (document.body.clientWidth - parseFloat(theObject.offsetWidth)) / 2;
    //alert("H:"+theObject.offsetHeight+" W:"+theObject.offsetWidth);
  }
}


//END positioning



function fadeIn(objId,opac){
  subj=obj(objId);
  //opac=parseInt(subj.getAttribute("opac"));
  if (opac<100){
    opac=opac+5;
    //subj.setAttribute("opac",opac)
    //distinguere moz da ie
    if (isExplorer)
      subj.style.filter="alpha(opacity="+opac+")";
    else
      subj.style.opacity=opac/100;
    setTimeout("fadeIn('"+objId+"',"+opac+")",100)
  }
}

function fadeOut(objId,opac){
  subj=obj(objId);
  //opac=parseInt(subj.getAttribute("opac"));
  if (opac>0){
    opac=opac-5;
    //subj.setAttribute("opac",opac)
    //distinguere moz da ie
    if (isExplorer)
      subj.style.filter="alpha(opacity="+opac+")";
    else
      subj.style.opacity=opac/100;
    setTimeout("fadeOut('"+objId+"',"+opac+")",100)
  }
}

// event handling START -------------------------------

function getTarget(e) {
  if (isExplorer) {
    return e.srcElement;
  }
  if (isNetscape) {
    return e.target;
  }
}

function getKeyCode(e) {
  if (isExplorer) {
    return e.keyCode;
  }
  if (isNetscape) {
    return e.which;
  }
}



function stopBubble(e){
  if (isNetscape)
    e.stopPropagation();
  e.cancelBubble = true;
  return false;
}


// event handling END -------------------------------




//START AJAX --

//var xmlHttpRequestObject;
function getXMLObj() {
  //if (xmlHttpRequestObject) {
  //  return xmlHttpRequestObject;
  //} else {
  // branch for native XMLHttpRequest object
  if (window.XMLHttpRequest) {
    try {
      req = new XMLHttpRequest();
    } catch(e) {
      req = false;
    }
    // branch for IE/Windows ActiveX version
  } else if (window.ActiveXObject) {
    try {
      req = new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e) {
      try {
        req = new ActiveXObject("Microsoft.XMLHTTP");
      } catch(e) {
        req = false;
      }
    }
  }
  //xmlHttpRequestObject = req;
  return req;
  //}
}

function getContent(href) {
  ret="";
  req = getXMLObj();
  req.open('GET', href, false);
  req.send(null);
  if (req.status == 200) {
    ret = req.responseText;
  }
  return ret;
}

function loadSyncroContent  (href, objId) {
  obj(objId).innerHTML = getContent(href);
}

function loadSyncroTextContent(href, objId) {
  obj(objId).value = getContent(href);
}

function loadSyncroPortletContent(href, objId) {
  var ext = getFileExtension(href);
  var contenuto = replacePortletPreviewContent(href)
  obj(objId).innerHTML = contenuto;

}

function replacePortletPreviewContent(href) {
  var contenuto = getContent(href);
  contenuto = bodyCleaner (contenuto);
  return contenuto;
}

function replaceTemplatePreviewContent(divId) {
  var contenuto = obj(divId).innerHTML;
  contenuto = bodyCleaner (contenuto);
  obj(divId).innerHTML = contenuto;
}

function bodyCleaner (contenuto) {
  contenuto = contenuto.replace('<form','<disabled');
  contenuto = contenuto.replace('</form','</disabled');
  contenuto = contenuto.replace(/required/g,'disabled');
  contenuto = contenuto.replace(/<link/g,'<disabled');
  contenuto = contenuto.replace(/onclick/g,'disabled');
  contenuto = contenuto.replace(/onClick/g,'disabled');
  contenuto = contenuto.replace(/onchange/g,'disabled');
  contenuto = contenuto.replace(/onChange/g,'disabled');
  contenuto = contenuto.replace(/onkeyup/g, 'disabled');
  contenuto = contenuto.replace(/optgroup/g,'disabled');
  contenuto = contenuto.replace(/submit/g,'disabled');
  contenuto = contenuto.replace(/href/g,'disabled');
  contenuto = contenuto.replace(/input/g,'input disabled');
  contenuto = contenuto.replace(/pointer/g,'default');
  contenuto = contenuto.replace(/obj/g, 'disabled');
  contenuto = contenuto.replace(/select/g,' select disabled');
  contenuto = contenuto.replace(/SELECT/g,'select disabled');
  return contenuto;
}

function getI18n(stringToTranslate){
  return getContent("<%=request.getContextPath()%>/commons/js/i18n_js.jsp?I18NENTRY="+stringToTranslate);
}

function  getFileExtension(stringa){
  var ext;
  ext = stringa.substring( stringa.length, stringa.lastIndexOf(".")+1 );
  return ext;
}

function fileExtentionInspector(ext) {
  var ok = ( ext=="jpg" || ext=="JPG" || ext=="gif" || ext=="GIF" || ext=="png" || ext=="PNG" || ext=="jpeg" || ext=="JPEG" );
  return ok;
}


// start asynchronous part

/**
*load obj.outerHtml with content of href asynchronously
*if objId is null call the href but do not refresh
*/
function loadAsyncroContent  (href, objId) {
  ajax = getXMLObj();
  ajax.open('GET', href, true);
  //  alert('loadasynch::  ' + href)
  ajax.setRequestHeader("connection", "close");
  ajax.onreadystatechange =
  function() {
    if(ajax.readyState === 4) {
      window.status ="Ajax loading...";
      if(ajax.status == 200) {
        if (objId)
          obj(objId).outerHTML=req.responseText;
        window.status = "";
      } else{
        alert("Error opening:[" + href+"] status:"+ajax.status);
      }
    }
  };

  ajax.send(null);
}

function reloadPageAfterAjaxSubmit (formId) {
  var f;
  f=obj(formId);
  var url='';
  first=true;
  var actualUrl=self.location.href;
  var parametersInUrl = false;
  if (actualUrl.indexOf('?')>-1) {
    parametersInUrl = true;
  }

  var byPassParameter='';
  var firstParam = true;
  for (i=0;i<f.elements.length;i++) {
    el=f.elements[i];
    if (el.value !=null && el.value!=""){
      url=url+(first ? '' : '&')+el.name+'='+escape(el.value);

      // to intercept invalid login in CDC wp_login
      var priorUlr = self.location.href;
      if(priorUlr.indexOf("INVALIDLG")==-1 && ( el.value.indexOf('LG')>-1 || el.name.indexOf('FLD_LOGIN_NAME')>-1) ) {
        if(el.value.indexOf('LG')>-1) {
          byPassParameter = byPassParameter + (firstParam && !parametersInUrl ? '?' : '&' ) + 'INVALIDLG='+el.value;
        }
        firstParam = false;
      }
    }
    first=false;
  }

  if (!parametersInUrl) {
    url=f.action+"?"+url;
  } else {
    url=f.action+"&"+url;
  }

  ajax = getXMLObj();
  ajax.open('GET', url, true);
  ajax.setRequestHeader("connection", "close");
  ajax.onreadystatechange =
  function() {
    if(ajax.readyState === 4) {
      window.status ="Ajax loading...";
      if(ajax.status == 200){
        //self.location.href = self.location.href;
        self.location.href = self.location.href + byPassParameter;
        // receptronics
        //self.location.href = url;
        // cdc //self.location.href = self.location.href + byPassParameter;
        window.status ="";
      } else{
        alert("Error opening:[" + href+"] status:"+ajax.status);
      }
    }
  };
  ajax.send(null);
}


function ajaxSubmit(formId, domIdToReload){
  var f;
  f=obj(formId);
  var url='';
  first=true;
  for (i=0;i<f.elements.length;i++){
    el=f.elements[i];
    if (el.value !=null && el.value!="")
      url=url+(first ? '' : '&')+el.name+'='+escape(el.value);
    first=false;
  }
  url=f.action+"?"+url;
  loadAsyncroContent (url,domIdToReload);
}

// missing firefox function emulation

function emulateHTMLModel() {
  HTMLElement.prototype.__defineSetter__("outerHTML", function (sHTML) {
    var r = this.ownerDocument.createRange();
    r.setStartBefore(this);
    var df = r.createContextualFragment(sHTML);
    this.parentNode.replaceChild(df, this);

    return sHTML;
  });

  HTMLElement.prototype.__defineGetter__("canHaveChildren", function () {
    switch (this.tagName) {
      case "AREA":
      case "BASE":
      case "BASEFONT":
      case "COL":
      case "FRAME":
      case "HR":
      case "IMG":
      case "BR":
      case "INPUT":
      case "ISINDEX":
      case "LINK":
      case "META":
      case "PARAM":
        return false;
    }
    return true;
  });

  HTMLElement.prototype.__defineGetter__("outerHTML", function () {
    var attr, attrs = this.attributes;
    var str = "<" + this.tagName;
    for (var i = 0; i < attrs.length; i++) {
      attr = attrs[i];
      if (attr.specified)
        str += " " + attr.name + '="' + attr.value + '"';
    }
    if (!this.canHaveChildren)
      return str + ">";

    return str + ">" + this.innerHTML + "</" + this.tagName + ">";
  });

}

// END AJAX ----------------------------------------------------------------------------

// END xmlHttpRequestObject -------------------------------------------



// debugger ----------------------------------------------------------------------------

var debugPopup;
var str = "";
function scriptDebugger() {
  str = str + "<br>";
  for (i = 0; i < arguments.length; i++) {
    str += arguments[i] + "<br>-------------------------------------------------------------<br>";
  }
  if (!debugPopup)
    debugPopup = window.open("", "debugWin", "width=300,height=200,resizable"); // a window object
  debugPopup.document.open("text/html", "replace");
  debugPopup.document.write("<HTML><HEAD><TITLE>New Document</TITLE></HEAD><BODY>" + str + "</BODY></HTML>");
  debugPopup.document.close();
}

// isRequired ----------------------------------------------------------------------------

function findTab(theEl){
  while ((theEl.getAttribute('isTabSetDiv')!="true")) {
    if(theEl.nodeName=='BODY') return "";
    theEl =isNetscape ? theEl.parentNode: theEl.parentElement;
  }
  return theEl.id;
}

var theRequiredTabset="";
var theOldtabSelId;
var allDiv;

function canSubmitForm(idForm) {
  var canSubmit=true;
  //var alertMessage=""
  elementsq= obj(idForm).elements.length;
  for (h=0;h<=elementsq; h++){
    theElement= obj(idForm).elements[h];
    if (theElement && theElement.className=="formElementsError")
      theElement.className="formElements";
    if (theElement && (theElement.value=="" || theElement.value.length==0) && theElement.getAttribute('required')=="true" && theElement.type!="hidden"){
      theElement.className="formElementsError";
      //alertMessage+= theElement.name +'\n';
      canSubmit=false;
      if (theRequiredTabset=="")
        theRequiredTabset=findTab(theElement);
    }
  }




  /*

   for (h=0;h<=elementsq; h++){
           theElement= obj(idForm).elements[h];
             if (theElement.className && theElement.className=="formElementsError")
                theElement.className="formElements";

             //if (theElement && !(theElement.value==''))
             //  alert(theElement.name)

             if (theElement &&
                  (theElement.value=="" || theElement.value.length==0) &&
                  theElement.getAttribute('required')=="true" &&
                  (theElement.type!="hidden")){
                theElement.className="formElementsError";
                //alertMessage+= theElement.name +'\n';
                canSubmit=false;
                 if (theRequiredTabset=="")
                  theRequiredTabset=findTab(theElement);
          }
     }
  */
  //if (alertMessage!="")
  //   alert(alertMessage+"campi obbligatori")

  if (canSubmit==false)  {
    if (theRequiredTabset!=""){
      theSuffix="div_tabset_";
      therequiredTabLinkId=theRequiredTabset.substring(theSuffix.length, theRequiredTabset.length);
      allTabLabel= document.getElementsByTagName('TD');
      if (allTabLabel.length>0){
        for (i=0;i<=allTabLabel.length;i++){
          if (allTabLabel[i] && allTabLabel[i].className=="tabSelected"){
            allTabLabel[i].className="tabUnselected";
            //alert(allTabLabel[i].id+"   class=  "+allTabLabel[i].className)
          }
        }
      }
      obj(therequiredTabLinkId).className="tabSelected";

      if(obj(theOldtabSelId)) obj(theOldtabSelId).className="tabUnselected";
      allDiv= document.getElementsByTagName('DIV');
      if (allDiv.length>0){
        for (i=0;i<=allDiv.length;i++){
          if (allDiv[i] && allDiv[i].id!=theRequiredTabset && allDiv[i].getAttribute('isTabSetDiv')=="true") allDiv[i].style.display="none";
          obj(theRequiredTabset).style.display="";
        }
      }
      theRequiredTabset=""
    }
  }


  return canSubmit;
}


var muteAlertOnChange=false;

function alertOnUnload() {
  if (!muteAlertOnChange) {
    for (i=0; i<document.forms.length; i++) {
      var currForm = document.forms[i];
      if ('true'==''+currForm.getAttribute('alertOnChange')) {
        for (j=0; j<currForm.elements.length; j++) {
          anInput = currForm.elements[j];
          oldValue = anInput.getAttribute("oldValue");
          if (anInput.attributes.getNamedItem("oldValue") && (anInput.value.replace(/\r/g,"")!=oldValue.replace(/\r/g,"")))
            if (isExplorer)
              event.returnValue = "You have some unsaved data on the page!";
            else {
              return "You have some unsaved data on the page!";
            }
        }
      }
    }
  }
}

if (!isExplorer) {
  window.onbeforeunload = alertOnUnload;
}





function addEvent(obj,event_name,func_name){
  if (obj.attachEvent){
    obj.attachEvent("on"+event_name, func_name);
  }else if(obj.addEventListener){
    obj.addEventListener(event_name,func_name,true);
  }else{
    obj["on"+event_name] = func_name;
  }
}

// Removes an event from the object
function removeEvent(obj,event_name,func_name){
  if (obj.detachEvent){
    obj.detachEvent("on"+event_name,func_name);
  }else if(obj.removeEventListener){
    obj.removeEventListener(event_name,func_name,true);
  }else{
    obj["on"+event_name] = null;
  }
}

// Stop an event from bubbling up the event DOM
function stopEvent(evt){
  evt || window.event;
  if (evt.stopPropagation){
    evt.stopPropagation();
    evt.preventDefault();
  }else if(typeof evt.cancelBubble != "undefined"){
    evt.cancelBubble = true;
    evt.returnValue = false;
  }
  return false;
}

// Get the obj that starts the event
function getElement(evt){
  if (window.event){
    return window.event.srcElement;
  }else{
    return evt.currentTarget;
  }
}
// Get the obj that triggers off the event
function getTargetElement(evt){
  if (window.event){
    return window.event.srcElement;
  }else{
    return evt.target;
  }
}
// For IE only, stops the obj from being selected
function stopSelect(obj){
  if (typeof obj.onselectstart != 'undefined'){
    addEvent(obj,"selectstart",function(){ return false;});
  }
}

/*    Caret Functions     */

// Get the end position of the caret in the object. Note that the obj needs to be in focus first
function getCaretEnd(obj){
  if(typeof obj.selectionEnd != "undefined"){
    return obj.selectionEnd;
  }else if(document.selection&&document.selection.createRange){
    var M=document.selection.createRange();
    var Lp=obj.createTextRange();
    Lp.setEndPoint("EndToEnd",M);
    var rb=Lp.text.length;
    if(rb>obj.value.length){
      return -1;
    }
    return rb;
  }
}
// Get the start position of the caret in the object
function getCaretStart(obj){
  if(typeof obj.selectionStart != "undefined"){
    return obj.selectionStart;
  }else if(document.selection&&document.selection.createRange){
    var M=document.selection.createRange();
    var Lp=obj.createTextRange();
    Lp.setEndPoint("EndToStart",M);
    var rb=Lp.text.length;
    if(rb>obj.value.length){
      return -1;
    }
    return rb;
  }
}
// sets the caret position to l in the object
function setCaret(obj,l){
  obj.focus();
  if (obj.setSelectionRange){
    obj.setSelectionRange(l,l);
  }else if(obj.createTextRange){
    m = obj.createTextRange();
    m.moveStart('character',l);
    m.collapse();
    m.select();
  }
}
// sets the caret selection from s to e in the object
function setSelection(obj,s,e){
  obj.focus();
  if (obj.setSelectionRange){
    obj.setSelectionRange(s,e);
  }else if(obj.createTextRange){
    m = obj.createTextRange();
    m.moveStart('character',s);
    m.moveEnd('character',e);
    m.select();
  }
}

/*    Escape function   */
String.prototype.addslashes = function(){
  return this.replace(/(["\\\.\|\[\]\^\*\+\?$\(\)])/g, '\$1');
}
String.prototype.trim = function () {
  return this.replace(/^\s*(\S*(\s+\S+)*)\s*$/, "$1");
};
/* --- Escape --- */

/* Offset position from top of the screen */
function curTop(obj){
  toreturn = 0;
  while(obj){
    toreturn += obj.offsetTop;
    obj = obj.offsetParent;
  }
  return toreturn;
}
function curLeft(obj){
  toreturn = 0;
  while(obj){
    toreturn += obj.offsetLeft;
    obj = obj.offsetParent;
  }
  return toreturn;
}
/* ------ End of Offset function ------- */

/* Types Function */

// is a given input a number?
function isNumber(a) {
  return typeof a == 'number' && isFinite(a);
}

/* Object Functions */

function replaceHTML(obj,text){
  while(el == obj.childNodes[0]){
    obj.removeChild(el);
  };
  obj.appendChild(document.createTextNode(text));
}


function addToFavorites(favoriteTitle){
  if(!favoriteTitle)favoriteTitle=document.title;
  if( window.sidebar && window.sidebar.addPanel ) {
    //Gecko (Netscape 6 etc.) - add to Sidebar
    window.sidebar.addPanel( favoriteTitle ? favoriteTitle:document.title, document.location.href, '' );
  } else if( window.external && ( navigator.platform == 'Win32' ||
                                  ( window.ScriptEngine && ScriptEngine().indexOf('InScript') + 1 ) ) ) {
    //IE Win32 or iCab - checking for AddFavorite produces errors in
    //IE for no good reason, so I use a platform and browser detect.
    //adds the current page page as a favourite; if this is unwanted,
    //simply write the desired page in here instead of 'location.href'
    window.external.AddFavorite( location.href, favoriteTitle ? favoriteTitle:document.title );
  } else if( window.opera && window.print ) {
    //Opera 6+ - add as sidebar panel to Hotlist
    return true;
  } else if( document.layers ) {
    //NS4 & Escape - tell them how to add a bookmark quickly (adds current page,
    //not target page)
    window.alert( 'Please click OK then press Ctrl+D to create a bookmark' );
  } else {
    //other browsers - tell them to add a bookmark (adds current page, not target page)
    window.alert( 'Please use your browser\'s bookmarking facility to create a bookmark' );
  }
  return false;
}

/*
// PRINT START
*/
function stampa(relativePathToCss, printableTagId, siteHeader, urlLogo) {
  var testo = "<html><head>" + relativePathToCss + "</head>";
  testo += "<body id=\"fo\" style=\"background-color:white\">"
  var drawSiteHeader = (siteHeader && siteHeader!=null && siteHeader!='null');
  var drawUrlLogo = (urlLogo && urlLogo!=null && urlLogo!='null');
  if ( drawSiteHeader || drawUrlLogo ) {
    testo += "<table><tr><td class='siteHeader'>";
    if(drawUrlLogo)
      testo += "<img src='"+urlLogo+"'><br><br>";
    if(drawSiteHeader)
      testo += "<h7>" + siteHeader + "</h7>";
    testo += "</td></tr></table>";
  }
  if (isExplorer)
    testo += obj(printableTagId).outerHTML;
  else
    testo += obj(printableTagId).innerHTML;

  testo += "</body></html>";
  var ident_finestra = window.open("","printWindow","width=750,height=450, menubar=no, scrollbars=yes");
  ident_finestra.document.open();
  ident_finestra.document.write(testo);
  ident_finestra.document.close();
  ident_finestra.print();
  ident_finestra.close();
}

/*
// centralized onload system
*/

var setQA,setStart,setDrop, setInitTree, setInitSizeTree;
init= function(){
  if (setStart==true) start();
  if (setQA==true) quickAccessPos();
  if (setDrop==true) dropInit();
  if (setInitTree==true) inittree();
  if (setInitSizeTree==true) initSizeTree();
  if (isNetscape) emulateHTMLModel();
}

window.onload=init;