/* (C) Metaswitch Networks 2007 - 2009                                       */

/**
 * A class containing utility functions used to append a cache breaker string at the
 * end of Java Script or CSS paths.
 *
 * This file has no trace statments because it is intended to be included before trace.js
 * into the HTML page.
 *
 */
function Loader()
{
}

Loader.cacheString = "?ver=" + (new Date(document.lastModified)).getTime();

/**
 * Function to append a cache breaker string at the source path of the Java
 * Script files and write the resulting string to the document.
 *
 * This method takes a variable number of parameters.  The first parameter should be
 * the relative path to the scope of the Java Script files, and each subsequent one
 * should be a String containing the name of a JS file.
 */
Loader.writeScriptTag = function ()
{
  // Take the relative path at the first argument
  var path = arguments[0];
  var tag = "";

  // Iterates over the remaining parameters (JS file names)
  for (var i = 1; i < arguments.length; i++)
  {
    tag = "<script src='" + path + arguments[i] +
          Loader.cacheString +
          "' type='text/javascript'></script>";
    document.write(tag);
  }
}

/**
 * Function to append a cache breaker string at the path of CSS
 * files and write the resulting string to the document.
 *
 * This method takes a variable number of parameters.  The first parameter should be
 * the relative path to the scope of the CSS files, and each subsequent one
 * should be a String containing the name of a CSS file.
 */
Loader.writeStyleTag = function ()
{
  // Take the relative path at the first argument
  var path = arguments[0];
  var tag = "";

  // Iterates over the remaining parameters (CSS file names)
  for (var i = 1; i < arguments.length; i++)
  {
    tag = "<link rel='stylesheet' type='text/css' href='" +
          path + arguments[i] +
          Loader.cacheString + "'/>"
    document.write(tag);
  }
}

/**
 * Is this IE?  Checks user agent string for "MSIE".
 */
Loader.isIE = function()
{
  return navigator.userAgent.indexOf("MSIE") != -1;
};

