<!--
  /**
    @file
    @author Dario Santillo
    @created 2005-05-10
    @updated 2005-05-15
    @version 1.1
    @description General-purpose JavaScript routines for ENEP Project.
    @note All this code is freely reusable and redistributable.
          If you want to use it you MUST only specify the full name of the
          author of this software and send him a notice via E-Mail at
          santillo@email.it.
  */

  /**
    Setting client's default Status Bar text
  */
  window.defaultStatus="EFAEP ENEP - European Network of Environmental Professionals";

  /**
    BROWSER DETECTION CONDITIONS
    Conditions for client's browser type sniffing using DOM's properties.
    USAGE: check the boolean status of variables ie, w3c and ns
    @return Internet Explorer = ie:true OR Netscape Navigator = ns:true OR W3C-compliant = w3c:true
  */
  var ns = (document.layers)? true:false;
  var ie = (document.all)? true:false;
  var w3c = (document.getElementById)?true:false;
  if(ns)
  {
    alert("ATTENTION!!!\nYour browser is WIDELY OBSOLETE.\nSerious visualization problems may occur if you continue using this.\n\nThe following W3C-standards compliant browsers are recommended:\n\n- Netscape Navigator Ver. >= 6.x\n- Mozilla Firefox Ver. >= 1.x\n- Microsoft Internet Explorer Ver. >= 5.0\n- Konqueror Ver. >= 3.0.4");
  }

  /**
    Insert an HTML string in a document
    @param what Text to insert.
    @return None.
  */
  function put(what)
  {
   document.writeln(what);
  }

  /**
    Sets the message displayed client's status bar.
    NOTE: After recalling this function a "return true;" statement must be performed.
    @param mesg The message to display.
    @return True always.
  */
  function setStatus(mesg)
  {
    window.status = mesg;
    return true;
  }

  /**
    Makes an hardcopy of an HTML page
    @return None.
  */
  function printit()
  {  
    if (ns || w3c)
      window.print();
    else
    {
      var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
      document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
      WebBrowser1.ExecWB(6,2); //Use a 1 vs. a 2 for a prompting dialog box
      WebBrowser1.outerHTML = "";  
    }
  }

  /**
    Checks if an E-Mail address has a correct syntax.
    @example: <username>@<sec_domain>.<pri_domain>
    @param email E-Mail address to check.
    @return True if the E-Mail addres syntax is correct; otherwise False.
  */
  function checkEmailSyntax(email)
  {
    len = email.length;
    at = email.indexOf("@");
    dot = email.lastIndexOf(".");
    return ( (len > 0) &&
             (at >= 1) && 
             (at < dot) &&
             (dot < len-1) ) ;
  }

  /**
    Checks if a given date is semantically correct.
    @note Requres a dat in ISO 8601 format
    @example: checkDate("2005-06-23");
    @param sDate The date to verify
    @return True if the date syntax is correct; otherwise False.
  */
  function checkDate(sDate)
  {
    yy = sDate.substr(0,4);
    mm = sDate.substr(5,2);
    dd = sDate.substr(8,2);    
    date = dd + "/" + mm + "/" + yy;
    _pattern=/^(((((0[1-9])|(1\d)|(2[0-8]))\/((0[1-9])|(1[0-2])))|((31\/((0[13578])|(1[02])))|((29|30)\/((0[1,3-9])|(1[0-2])))))\/(([0-9][0-9][0-9][0-9]))|(29\/02\/[0-9][0-9](([02468][048])|([13579][26]))))$/;    
    return _pattern.test(date);
  }

  /**
    Prints the last save date of the document.
    @return None.
  */
  function lastMod()
  {
   lastModDate = new Date(document.lastModified);
   lastString = Date.parse(document.lastModified);
   if (lastString == 0)
   {
    put('<small><b>Last update date not available</b></small>');
   }
   else
   {
    lastModDay = lastModDate.getDate();
    lastModMonth = lastModDate.getMonth() + 1;
    lastModYear = lastModDate.getFullYear();
    lastString = lastModYear + '.' + lastModMonth + '.' + lastModDay;
    put('<small>Last update: <b>' + lastString + '</b></small>');
   }
  }

  /**
    Prints the current system date in ISO8601 format (Day, DD Month YYY).
    @return None.
  */
  function showDate()
  {
    var days=new Array(8);
    days[1] = "Sun";
    days[2] = "Mon";
    days[3] = "Tue";
    days[4] = "Wed";
    days[5] = "Thu";
    days[6] = "Fri";
    days[7] = "Sat";
    var months=new Array(13);
    months[1] = "Jan";
    months[2] = "Feb";
    months[3] = "Mar";
    months[4] = "Apr";
    months[5] = "May";
    months[6] = "Jun";
    months[7] = "Jul";
    months[8] = "Aug";
    months[9] = "Sep";
    months[10] = "Oct";
    months[11] = "Nov";
    months[12] = "Dec";
    var dateObj=new Date();
    var wday=days[dateObj.getDay() + 1];
    var lmonth=months[dateObj.getMonth() + 1];
    var ayear=dateObj.getFullYear();
    var date=dateObj.getDate();
    put(wday + ", " + date + " " + lmonth + " " + ayear);
  }

  /**
    Disables right-click context menu in the active window.
    @return None.
  */
  
  function disablemouse_right()
  {
    message = "Sorry, the right mouse click was disabled\nfor security reasons!!!";
    
    document.oncontextmenu = function()
    {
      alert(message);
      return false;
    }
    if(ns)
    { 
      window.captureEvents(Event.MOUSEDOWN); 
      window.onmousedown = function(e)
      { 
        if(e.target==document)
        {
          alert(message);
          return false;
        }
      } 
    } 
  }

  /**
    Opens a window at "addr" URL specified in the parameters.
    @param addr URL of target window;
    @param type Identification string of target window (ex. '_blank');
    @param wid Width of the window;
    @param heig Height of the window.
    @return None.
  */
  function openInfo(addr,type,wid,heig)
    {
      inf = window.open(addr,type,
      'scrollbars=yes,resizable=yes,' +
      'width=' + wid +
      ',height=' + heig +
      ',status=no,location=no,toolbar=no');
      // inf.moveTo(0,20);
    }

  /**
    Closes a window opened with die openInfo() function.
    @param inf Identification string of target window (ex. '_blank');
    @return None.
  */
  function closeInfo(inf)
    {
      inf.close();
    }

  /**
    Sets a client cookie.
    @param name Name of cookie;
    @param value Value of cookie;
    @param expire Expiration date of cookie.
    @return None.
  */
  function setCookie(name, value, expire)
  {
    document.cookie = name + "=" + escape(value) + ((expire == null) ? "" : ("; expires=" + expire.toGMTString()));
  }

  /**
    Returns a cookie's value.
    @param name Name of cookie.
    @return Cookie's value.
  */
  function getCookie(Name)
  {
   var search = Name + "=";
   if (document.cookie.length > 0)
   {
    // if there are any cookies
    offset = document.cookie.indexOf(search);
    if (offset != -1)
    {
      // if cookie exists 
     offset += search.length;
     // set index of beginning of value
     end = document.cookie.indexOf(";", offset);
     // set index of end of cookie value
     if (end == -1)
      end = document.cookie.length;
     return unescape(document.cookie.substring(offset, end));
    } 
   }
  }


//-->

