// Common

var d=document;
var BASE_URL='http://www.spider146.net/';
var IMAGES_URL=BASE_URL+'images/';
var COMMON_URL=BASE_URL+'common/';
var SECTION_URL='';

var XH=null;

function removeAllChild(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  while(obj.firstChild)
    {obj.removeChild(obj.firstChild);}
}

function setEvent(obj,ev,fnc)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  if(BROWSER=='Internet Explorer')
    {obj[ev]=new Function(fnc);}
  else
    {obj.setAttribute(ev,fnc);}
}

function setVisibility(e,f,v)
{
  if(typeof(e)=='string')
    {e=d.getElementById(e);}

  if(e)
  {
    if(f=='visibility')
      {e.style.visibility=v;}
    else if(f=='display')
      {e.style.display=v;}
  }
}

function getVisibility(e,f)
{
  if(typeof(e)=='string')
    {e=d.getElementById(e);}

  if(e)
  {
    if(f=='visibility')
      {return e.style.visibility;}
    else if(f=='display')
      {return e.style.display;}
  }
}

function getXPos(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  if(obj)
  {
    var curleft=0;
    if(obj.offsetParent)
    {
      while(obj.offsetParent)
      {
        curleft+=obj.offsetLeft
        obj=obj.offsetParent;
      }
    }
    else if (obj.x)
      curleft+=obj.x;
    return curleft;
  }
  else
    {return -1;}
}

function getYPos(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  if(obj)
  {
    var curtop=0;
    if(obj.offsetParent)
    {
      while(obj.offsetParent)
      {
        curtop+=obj.offsetTop
        obj=obj.offsetParent;
      }
    }
    else if (obj.y)
      curtop+=obj.y;
    return curtop;
  }
  else
    {return -1;}
}

function getInnerWindowWidth()
{
  if (!window.innerWidth)
    {return d.documentElement.clientWidth;}
  else
    {return window.innerWidth;}
}

function getInnerWindowHeight()
{
  if(!window.innerHeight)
    {return d.documentElement.clientHeight;}
  else
    {return window.innerHeight;}
}

function windowCenterX()
{
  if(d.documentElement.scrollLeft>=0)
    {return getInnerWindowWidth()/2+d.documentElement.scrollLeft;}
  else
    {return getInnerWindowWidth()/2+window.pageXOffset;}
}

function windowCenterY()
{
  return getInnerWindowHeight()/2+pageScrollTop();
}

function pageScrollTop()
{
  if(d.documentElement.scrollTop>=0)
    {return d.documentElement.scrollTop;}
  else
    {return window.pageYOffset;}
}

function setFullScreenHeight(obj)
{
  if(typeof(obj)=='string')
    {obj=d.getElementById(obj);}

  obj.style.height=(d.getElementById('dBody').offsetHeight>getInnerWindowHeight())?d.getElementById('dBody').offsetHeight+'px':getInnerWindowHeight()+'px';
}

function loadArray(s,d)
{
  return s.split(d);
}

function showLoadingOverlay()
{
  setFullScreenHeight('loadingOverlay');
  setVisibility('loadingOverlay','visibility','visible');
}

function hideLoadingOverlay()
{
  setVisibility('loadingOverlay','visibility','hidden');
}

function onLoad()
{
  getBrowser();
  hideLoadingOverlay();
  SECTION_URL=BASE_URL+SECTION+'/';
  if(typeof(onLoadPage)=='function')
    {onLoadPage();}
}

function onUnload()
{
  showLoadingOverlay();
  if(typeof(onUnloadPage)=='function')
    {onUnloadPage();}
}

function createXMLHttpRequest()
{
  if (window.ActiveXObject)
    {return new ActiveXObject("Microsoft.XMLHTTP");}
  else if (window.XMLHttpRequest)
    {return new XMLHttpRequest();}
}




// Browser Detection

var BROWSER='';
var BROWSER_VERSION='';
var BROWSER_VERSION_NUMBER='';

function getBrowser()
{
  var uA=navigator.userAgent;
  if(uA.indexOf('Opera')!=-1)
  {
    BROWSER='Opera';
    var s=uA.indexOf('Opera')+6;
    var e=uA.indexOf(' ',s);
    if(e>0)
      {BROWSER_VERSION=uA.substr(s,e-s);}
    else
      {BROWSER_VERSION=uA.substr(s);}
  }
  else if (uA.indexOf('MSIE')!=-1)
  {
    BROWSER='Internet Explorer';
    var s=uA.indexOf('MSIE ')+4;
    var e=uA.indexOf(';',s);
    BROWSER_VERSION=uA.substr(s,e-s);
  }
  else if (uA.indexOf('Firefox')!=-1)
  {
    BROWSER='Firefox';
    BROWSER_VERSION=uA.substr(uA.indexOf('Firefox/')+8);
  }
  else if (uA.indexOf('safari')!=-1)
  {
    BROWSER='Safari';
    BROWSER_VERSION=uA.substr(uA.indexOf('safari/')+7);
  }
  else if ((uA.indexOf('mozilla/5.0')!=-1) && (uA.indexOf('rv:')!=-1) && (uA.indexOf('gecko/')!=-1))
  {
    BROWSER='Mozilla';
    var s=uA.indexOf('rv:')+3;
    var e=uA.indexOf(')',s);
    if(e>0)
      {BROWSER_VERSION=uA.substr(s,e-s);}
    else
      {BROWSER_VERSION=uA.substr(s);}
  }
}

if(BROWSER_VERSION!='')
{
  var fp=true;
  var index=0;
  for(var i=0;i<BROWSER_VERSION.length;i++)
  {
    if(BROWSER_VERSION[i]>=0)
      {index=i;}
    else if(BROWSER_VERSION[i]=='.' && fp)
    {
      index=i;
      fp=false;
    }
    else
      {break;}
  }
  BROWSER_VERSION_NUMBER=substr(BROWSER_VERSION,0,index+1);

  if(!(BROWSER_VERSION_NUMBER>0))
    {BROWSER_VERSION_NUMBER='';}
}

function openMap()
{
  window.open('../common/mappa.php','mappa','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=800,height=700');
}

function moreInfo()
{
  window.open('../common/maggioriinfo.php','maggioriinfo','location=no,menubar=no,toolbar=no,status=no,scrollbars=yes,resizable=yes,width=550,height=700');
}