

      //Detect browser type (4+ required)
      var ie4 = document.all;
      var ns = document.layers;
      var gh_dom = document.getElementById;
      
     //BEGIN CROSS BROWSER DOM VARIABLE CREATION
     var doc =  gh_dom ? "document.getElementById('" :ie4 ? "document.all." : "document."
     var sty = gh_dom ? "').style" : ie4 ? ".style" : ""
     var vis = ".visibility="
     var bgcol = ie4 ? ".backgroundColor" : ".backgroundColor"
     //(not correct yet) var fgcol = ie4 ? ".Color" : ".Color"
     
     //Used for getting width & height of a layer
     var getwidth  = gh_dom? ".width" :ie4 ? ".pixelWidth"  : ".clip.width"
     var getheight = gh_dom? ".height" :ie4 ? ".pixelHeight" : ".clip.height"
     
     //used for the differences in showing and hiding a layer
     var show = (ie4||gh_dom) ? "'visible'" : "'show'"
     var hide = (ie4||gh_dom) ? "'hidden'"  : "'hide'"
 //END CROSS BROWSER DOM VARIABLE CREATION
 
 
 

     function togglelayer(lyrname, togval)
     {   
         var togval2 = (togval == 0) ? hide : show
         eval(doc+lyrname+sty+vis+togval2)
     }
     
    

     function positionlayer(lyrname, topval, leftval)
     {
       eval(doc+lyrname+sty+".top="+topval)
	   eval(doc+lyrname+sty+".left="+leftval)
	   return;
     }
	 
	 

     function getlyrpos(lyrname, toporleft)
     {
    	 var toporleft = (toporleft == 'top') ? '.top' : '.left'
       //alert(doc+lyrname+sty+toporleft);
       //alert((eval(doc+lyrname+sty+toporleft)));




         return parseInt(eval(doc+lyrname+sty+toporleft))
     }


    function slidelayer2(lyrname, newtop, newleft, step, sendtoback)
    {
      if (sendtoback == "") { sendtoback="no"; }//alert('lyrname=['+lyrname+']\nTOP=['+newtop+']\nLEFT=['+newleft+']\nSTEP=['+step+']')
      //status=1;
      jumprange     = 30; //a SNAP-TO pixel area
      completed     = 0;
      var lyrtop    = 191//getlyrpos(''+lyrname, 'top');
		var lyrleft   = getlyrpos(''+lyrname, 'left');
      //alert('[current]\nlyrtop='+lyrtop+'\nlyrleft='+lyrleft);
      //alert('[destination]\nnewtop='+newtop+'\nnewleft='+newleft);
          //----------- TOP ------------------------------
          //new
          var topdiff = Math.abs(lyrtop-newtop)
          //alert(topdiff);
          if(topdiff <= jumprange) { lyrtop = newtop; }
          
            if (lyrtop < newtop)   { lyrtop += step }
            else
            {
              if (lyrtop > newtop) { lyrtop -= step }
              else { completed++ }
            }
            //move the layer TOP pixels
            eval(doc+lyrname+sty+".top="+lyrtop)
          //---------- LEFT ------------------------------ 
          //new
          var leftdiff = Math.abs(lyrleft-newleft)
          //alert(leftdiff);
          if(leftdiff <= jumprange) { lyrleft = newleft; }
          
            if (lyrleft < newleft)   { lyrleft += step }
            else
            {
              if (lyrleft > newleft) { lyrleft -= step }
              else { completed++ }
            }
            //move the layer LEFT pixels
            eval(doc+lyrname+sty+".left="+lyrleft)
      if (completed < 2) { var repeat = setTimeout( "slidelayer2('"+lyrname+"', "+newtop+", "+newleft+", "+step+", '"+sendtoback+"')",1); }
      else
           {
              clearTimeout(repeat)
              //if (sendtoback=="yes") { newzindex(lyrname, 2); }
              //alert('status is now zero');
              //status = 0;
              //return true;
           }
    }

    
      function getscreendimension(whichdim)
      {  
         if ((document.all)&&(navigator.userAgent.indexOf('Opera')==-1))//if IE, but not Opera
         { //alert('here in document.all, where I shouldn\'t be.')
           var screendim = (whichdim=='width') ? "document.body.clientWidth" : "document.body.clientHeight"
           return parseInt(eval(screendim))
         }
         else
         {  //alert('here')
           var screendim = (whichdim=='width') ? "window.innerWidth" : "window.innerHeight"
           return parseInt(eval(screendim))
           //onResize='history.go(0)'
         }
     }

   
    
      
    //custom functions
   
  var presentbutton="";  //just an initialization value
  var presentpopup =""
  var spFlag=false;
   
  function getoffset(){ //function to find out how far from the edge the centered table is
   browserwidth=getscreendimension("width");
  // alert('browser width=' + browserwidth)
      if (browserwidth<=750) { browserwidth=750;
      return 0; }
      else{
        var tableoffset=Math.floor((browserwidth-750)/2);
        //alert(tableoffset);
        if(ns)
        {tableoffset=tableoffset-8}
        if ((navigator.userAgent.indexOf('Gecko')!=-1)&&(spFlag))
          {tableoffset=tableoffset-6}
        if ((document.layers)&&(spFlag))
          {tableoffset=tableoffset-1}
        return tableoffset;}
   }
   function adjustPosition()//function to adjust the position of a visible sublink layer if the window is resized.
   {
    if (spFlag)
      {       
       popupHeight=117
       popupLeft=542
       }
    else
      {
       popupHeight=160
       popupLeft=543
      }
    if (presentbutton!="")//ie, if one is shown
      {
       positionlayer(presentbutton +"2", 161, 3 + getoffset())
       }
    positionlayer('sitesearchdiv', popupHeight, popupLeft + getoffset())
    positionlayer('clientlogindiv', popupHeight, popupLeft + getoffset())
   }
   
   function exitstage(layername)   //a function to put a layer back offstage
   {
   togglelayer(layername,0);
   positionlayer(layername, 161, 0)
   }
   
   
   function slidesub(buttonname)//function to rollover the image button, turn off all others, and slide in the sublinks
   {
   //turn off the other buttons
   
   
   if (presentbutton!=buttonname){
  
     imgOff('clienti'); exitstage('clienti2',0) //turn off the previous button/layer
     imgOff('servizi');exitstage('servizi2',0)
     imgOff('azienda');exitstage('azienda2',0)
     imgOff('news');//exitstage('news2',0)
     imgOff('contatti');//exitstage('contatti2',0)  no div for contact at present
    
     
     imgOn(buttonname);
       if (buttonname =="contatti") {presentbutton=""; return} //no slidey for contact at present
       if (buttonname =="news") {presentbutton=""; return} //no slidey for news at present
     
       var slidespeed=30
       if ((navigator.userAgent.indexOf('Gecko')!=-1)|| (navigator.userAgent.indexOf('Mac')!=-1))
          {
           slidespeed=50
          }
      
       var thislayer=buttonname + "2";
       positionlayer(thislayer, 161, 750 + getoffset())
       togglelayer(thislayer,1);
       var destination=3
       switch(thislayer)
          {
           case 'clienti2' : destination = 1;break;
           case 'servizi2': destination = 110;break;
           case 'azienda2' : destination = 215;break;
           case 'news2' : destination = 412;break;
           case 'contatti2' : destination = 412;break;
          }
       
       slidelayer2(thislayer, 161, destination + getoffset(), slidespeed)
       presentbutton=buttonname;
       
      
       }
     
   }
  

  function toggleForm(divname,xcoord)
    { 
      if (spFlag)
        {popupHeight=117}
      else
        {popupHeight=160}
     
      positionlayer(divname, popupHeight, xcoord + getoffset())
      if (divname==presentpopup)//if we're passed the name of the presently on popup, turn it off, and clear the popup name
         {
          togglelayer(divname,0)
          presentpopup=""
          if (divname=='sitesearchdiv')//attend to the rollovers
             {
             imgOff('sitesearch')
             }
          else
             {
             imgOff('login')
             }
         }
       else if (presentpopup=="")//if not, and if the popup is empty, turn it on, and save the name
         {
          togglelayer(divname,1)
          presentpopup=divname;
         }
         else//else the other one is on, turn it off, turn its image off, and turn on the new one
            {
             togglelayer(presentpopup,0)
             togglelayer(divname,1)
             if (presentpopup=='sitesearchdiv')//attend to the rollovers
                 {
                 imgOff('sitesearch')
                 }
              else
                 {
                 imgOff('login')
                 }
             presentpopup=divname;
            }
    //alert(presentpopup)
    if (presentpopup!="")
       {
        var thisformname=""
        if (presentpopup=='sitesearchdiv')
           {
            var thisformname="sitesearchform.terms";
           }
        else thisformname="clientlogin.username";
        
        if (ns)
           {
            eval('document.' + presentpopup + '.document.' + thisformname + '.focus()')
            }
         else
           {
            thisformobj=eval('document.' + thisformname)
            //alert(thisformobj.name)
            thisformobj.select()
            thisformobj.focus()
          
           }
        
       }
    
    } 
   
   function popUpFormOff(divname)
     {
     if (divname=='sitesearchdiv')//attend to the rollovers
         {
         imgOff('sitesearch')
         }
      else
         {
         imgOff('login')
         }
      togglelayer(divname,0); //turn off the popup
      presentpopup="" //clear out the storage variable
     }
  
   
   
   
   
   function submitForm(formName, divName)
     {
     if (ns)
       {
        eval('document.' + divName + '.document.' + formName + '.submit()')
        }
     else
       {
        eval('document.' + formName + '.submit()')
       }
     }
     
     //function to popup a window.  Either pass it just the url, and take the default size, or 
     //pass it the url, width, height, windowname, and scrolling/non scrolling (default is non)
     function popWindow(url, width, height, windowName, scrollb) {
      // default width and height for window
      if (!width) { width  = 439; }
      if (!height) { height = 325; }
      if (!scrollb) {scrollb = "no"}
      // positioning of pop-up window
      { leftpos=0
        if (screen) {
        leftpos = screen.width-(width+230)}
     
      //alert("myX=" + myX + "\nmyY=" + myY);
      
      // default window name if not passed to function
      if (!windowName) { windowName = "bxPopup"; }
      wref = window.open (url, windowName,
            "toolbar=no,width=" + width + ",height=" + height + ",directories=no,status=no,scrollbars=" +scrollb + ",resizable=yes,menubar=no,top=50,left="+leftpos);
      wref.focus();
    }
    } 
    
    //gallery-specific popup function
    var daughter = false
    function loadwin(client)
    { leftpos=0
    if (screen) {
    leftpos = screen.width-520}
     newWindow3 = window.open(client,"demo","width=500,height=316,scrollbars=no,left="+leftpos);
    newWindow3.focus(); 
    daughter = true;
    }
   function closewin()
    {
       if ((daughter) && (!newWindow3.closed))
      { newWindow3.close(); }
    }
    
    
    
    
    function searchresults(search_string)
    {
       toggleForm('sitesearchdiv',542);
       if (ns)
       { var formobj=document.sitesearchdiv.document.sitesearchform; }
       else
       { var formobj=document.sitesearchform; }
       formobj.search_string.value=search_string;
    }


      
    //toggleMultiField(this,'database_list,database_setup',true)
    function toggleMultiField(radiobj,fieldlist,state)
      {
        if (document.all || document.getElementById)
        {
          var parentForm = radiobj.form
          var fieldArray = fieldlist.split(",")
          var bgcolor = "#FFFFFF"
          if (state)
            {
             bgcolor = "#EEEEEE"
            }
          for (var i=0;i<fieldArray.length;i++)
          
            {
              var fieldname = fieldArray[i]
              var thisField = parentForm.elements[fieldname]
              thisField.disabled = state
              if (document.getElementById) 
                {               
                //alert(fieldname)
                var thisElem = document.getElementById(fieldname)
                }
              else var thisElem = document.all[fieldname] 
             // alert(thisElem)              
              thisElem.style.background = bgcolor;
            }
          }
      
      }