function getObjectPos( obj )
{
  var curleft = curtop = 0;

  if ( obj.offsetParent )
  {
    do
    {
      curleft += obj.offsetLeft;
      curtop += obj.offsetTop;

      obj = obj.offsetParent;
    }
    while ( obj );
  }

  return [curleft, curtop];
}
function getScrollLeft()
{
  if ( window.pageXOffset )
    return window.pageXOffset;

  if ( document.documentElement && document.documentElement.scrollLeft > 0 )
    return document.documentElement.scrollLeft;

  if ( document.body )
    return document.body.scrollLeft;

  return 0;
}
function getScrollTop()
{
  if ( window.pageYOffset )
    return window.pageYOffset;

  if ( document.documentElement && document.documentElement.scrollTop > 0 )
    return document.documentElement.scrollTop;

  if ( document.body )
    return document.body.scrollTop;

  return 0;
}
function getClientHeight()
{
  if ( window.innerHeight )
    return window.innerHeight;

  if ( document.documentElement && document.documentElement.clientHeight > 0 )
    return document.documentElement.clientHeight;

  if ( document.body )
    return document.body.clientHeight;

  return 0;
}
function getClientWidth()
{
  if ( window.innerWidth )
    return window.innerWidth;

  if ( document.documentElement && document.documentElement.clientWidth > 0 )
    return document.documentElement.clientWidth;

  if ( document.body )
    return document.body.clientWidth;

  return 0;
}
function onClick( obj, href )
{
  if ( href == null )
  {
    var subClass = "";
    var i;
    var divs;

    if ( obj.parentNode.className == "category" )
      subClass = "subcategories";
    else
      subClass = "categoryproducts";

    if ( obj.parentNode.className == "subcategory" )
    {
      var categoryDiv = obj.parentNode.parentNode;
      var subCategory = categoryDiv.firstChild;

      while ( subCategory != null )
      {
        if ( subCategory.nodeType != 3 && subCategory.className == "subcategory" )
        {
          if ( subCategory != obj.parentNode )
          {
            divs = subCategory.getElementsByTagName( "div" );

            for ( i = 0 ; i < divs.length ; i++ )
            {
              if ( divs[i].className == subClass )
                divs[i].style.display = "none";
            }
          }
        }

        subCategory = subCategory.nextSibling;
      }
    }

    divs = obj.parentNode.getElementsByTagName( "div" );

    for ( i = 0 ; i < divs.length ; i++ )
    {
      if ( divs[i].className == subClass )
        divs[i].style.display = divs[i].style.display != "block" ? "block" : "none";
    }

    if ( getObjectPos( obj.parentNode )[1] + obj.parentNode.clientHeight >
        ( getClientHeight() + getScrollTop() ) )
      obj.parentNode.scrollIntoView( false );

    var spans = document.getElementsByTagName( "span" );

    for ( i = 0 ; i < spans.length ; i++ )
    {
      if ( spans[i].className == "catproddesc" )
      {
        var height = addEllipsis( spans[i], 35, "#" );

        spans[i].style.marginTop = ( ( 50 - height ) / 2 ) + "px";
      }
    }
  }
  else
    window.location = href;
}
function ajax( url )
{
  var xmlhttp = null;

  if ( window.XMLHttpRequest )
  {
    // code for IE7+, Firefox, Chrome, Opera, Safari
    xmlhttp = new XMLHttpRequest();
  }
  else if ( window.ActiveXObject )
  {
    // code for IE6, IE5
    xmlhttp = new ActiveXObject( "Microsoft.XMLHTTP" );
  }
  else
  {
    // AJAX is not supported
    alert( "AJAX non è supportato" );
    return "";
  }

  xmlhttp.open( "GET", url + "&uid" + Math.floor( Math.random() * 10000 ), false );
  xmlhttp.send( null );

  return xmlhttp.responseText;
}
function getBody()
{
  return document.getElementsByTagName( "body" )[0]
}
function getPageSize()
{
  var body = getBody();

  return { width: body.offsetWidth, height: body.offsetHeight };
}
function popupProduct( link )
{
  try
  {
    window.open( link.href, "product", "scrollbars=1,width=1024,height=768,location=0" );
  }
  catch ( ex )
  {
    alert( ex );
  }

  return false;
}
function popupVideo( link )
{
  try
  {
    window.open( link.href, "video", "scrollbars=1,width=1024,height=768,location=0" );
  }
  catch ( ex )
  {
    alert( ex );
  }

  return false;
}
