var isDesignTime = false;

/* Utility */

function getNextSibling(n)
{
    n=n.nextSibling;
    while(n)
    {
        if(n.nodeType == 1)
            return n;
        else
            n=n.nextSibling;
    }
}

/* End Utility */

/* Event wiring */

function hsAddLoadEvent(loadFunc) 
{
  var oldFunc = window.onload;
  if (typeof window.onload != 'function') 
  {
    window.onload = loadFunc;
  } 
  else {
    window.onload = function() 
    {
      if (oldFunc) {
        oldFunc();
      }
      loadFunc();
    }
  }
}

/* End Event wiring */

/* User Data support */

function getDataCache()
{
    if (isDesignTime)
    {
        if (getWindowExternal())
        {
            if (window.external.IsInnovasysDesigner)
            {
                return window.external;
            }
        }
    }
    
    return documentElement("userDataCache");
}

function getWindowExternal()
{
    try
    {
        return window.external;
    }
    catch(e)
    {
    }
}

function load(key)
{
    var dataCacheObject;

    try
    {
        dataCacheObject = getDataCache();
        dataCacheObject.load("innSettings");
        var value = dataCacheObject.getAttribute(key);
        return value;
    }
    catch(e)
    {
    }
}

function save(key, value)
{
    var dataCacheObject;

    try
    {
        dataCacheObject = getDataCache();
        dataCacheObject.setAttribute(key, value);
        dataCacheObject.save("innSettings");
    }
    catch(e)
    {
    }
}

function removeAttribute(key)
{
    var dataCacheObject;

    try
    {
        dataCacheObject = getDataCache();
        dataCacheObject.removeAttribute(key);
        dataCacheObject.save("innSettings");
    }
    catch(e)
    {
    }
}

/* End User Data support */
