 /*--------------------------------------------------------------------------+
  | Module:      utils.js                                                    |
  | Location:    /scripts                                                    |
  | Description: Contains all kind of JavaScript utility functions.          |
  | Functions:                                                               |
  |   display_status_msg                                                     |
  |   pre_load_images                                                        |
  |   get_last_modified_date                                                 |
  *--------------------------------------------------------------------------*/

    function MM_swapImgRestore()
    {
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    }

    function MM_preloadImages()
    {
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
      var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
      if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    }

    function MM_findObj(n, d)
    {
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    }

    function MM_swapImage()
    {
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
      if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    }
  
   /**************************************************************************
    * Function:    display_status_msg.                                       *
    * Summary:     Display status message.                                   *
    * Input:       a_msg_str - a string withthe message to be dispalyed.     *
    * Output:      None.                                                     *
    * Description: Displays a message in the status bar of the browser's     *
    *              window. If no message has been passed to the function,    *
    *              document's title is displayed in the status bar.          *
    **************************************************************************/
    function display_status_msg( a_msgStr )
    {
      // Do we have a message to be displayed?
      if((a_msgStr != null) && (a_msgStr.length > 0))
      {
        // Yes, display it in the browser's status bar.
        status = a_msgStr
      } 
      else 
      {
        // No, display the document's title in the browser's status bar.
        status = document.title;
      }
      return true;
    }
    
   /**************************************************************************
    * Function:    get_last_modified_date.                                   *
    * Summary:     Get last modified date.                                   *
    * Input:       None.                                                     *
    * Output:      A string with the date when the document was last         *
    *              modified.                                                 *
    * Description: Returns the date when the document was last modified in   *
    *              the format dd/mm/yyyy.                                    *
    **************************************************************************/
    function get_last_modified_date()
    {
      // Get the document's last modification date.
      var modDate  = new Date(document.lastModified)
      // Extract the month.
      var modMonth = modDate.getMonth()+1
      // Extract the year.
      var modYear  = modDate.getYear()
      // Extract the day.
      var modDay   = modDate.getDate()
      // In case necessary give the day a leading zero.
      if( modDay < 10 )
        modDay = "0" + modDay;
      // In case necessary give the month a leading zero.
      if( modMonth < 10 )
        modMonth= "0" + modMonth;
      // In case the year is less than 1000, add 1900.
      if( modYear < 1000 )
        modYear+=1900;
      // Format the date and return it.
      var ret_val = "" + modDay + "/" + modMonth + "/" + modYear+"";
      return ret_val;
    }
