
function CheckForm(form,maxCommentLength)
{
  var yourComment = Trim(form.txtComment.value);
  var yourCommentLength = Len(yourComment);
  if ( yourCommentLength == 0 )
  {
    alert("You have not written any comment !");
    return false;
  };
  if ( yourCommentLength <= 2 )
  {
    alert("You do not appear to have written a valid comment !");
    return false;
  };

  var yourName = Trim(form.txtName.value);
  var yourHomePage = Trim(form.txtHomePage.value);

  if ( Lcase(Left(yourHomePage,7)) == 'http://' )
  {
    yourHomePage = Trim(Right(yourHomePage,-7));
    if ( yourHomePage != '' )
    {
      if ( yourName == '' )
      {
        alert("You cannot specify a home page without supplying your name");
        return false;
      };
    };
    yourHomePage = 'http://'+yourHomePage;
  }
  else
  {
    if ( Lcase(Left(yourHomePage,7)) == 'mailto:' )
    {
      yourHomePage = Trim(Right(yourHomePage,-7));
      if ( yourHomePage != '' )
      {
        if ( yourName == '' )
        {
          alert("You cannot specify a mail address without supplying your name");
          return false;
        };
      };
      if ( ! EmailAddressIsValid(address) )
      {
        alert( address+" - is not a valid email address");
        return false;
      };
      yourHomePage = 'mailto:'+yourHomePage;
    }
    else
    {
      yourHomePage = Trim(yourHomePage);
      yourHomePage = 'http://'+yourHomePage;
    };
  };

  if ( Len(yourComment) > maxCommentLength )
  {
    alert("Your comment is too long");
    return false;
  };

  form.txtComment.value = yourComment;
  form.txtName.value = yourName;
  form.txtHomePage.value = yourHomePage;
  form.txtTitle.value = document.title;

  return true;

};

function EmailAddressIsValid(str)
{
  // are regular expressions supported?
//  var supported = 0;
//  if ( window.RegExp )
//  {
//    var tempStr = "a";
//    var tempReg = new RegExp(tempStr);
//    if (tempReg.test(tempStr))
//    {
//      supported = 1;
//    };
//  };
//  if ( ! supported )
//  {
//    return (str.indexOf(".") > 2) && (str.indexOf("@") > 0);
//  };
  var r1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(^\\.)");
  var r2 = new RegExp("^.+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
  return ( ! r1.test(str) && r2.test(str) );
};

// Text handling ...

function Len(t)
{
  if ( t == null )
  {
    return ( 0 );
  }
  else
  {
    return ( t.length );
  };
};

function Trim(t)
{
  return ( Ltrim(Rtrim(t)) );
};

function Ltrim(t)
{
  var alpha = t;
  while
  (
    Left(alpha,1) == " "  ||
    Left(alpha,1) == "\r" ||
    Left(alpha,1) == "\n"
  )
  {
    alpha = Right(alpha,-1);
  };
  return ( alpha );
};

function Rtrim(t)
{
  var alpha = t;
  while
  (
    Right(alpha,1) == " "  ||
    Right(alpha,1) == "\r" ||
    Right(alpha,1) == "\n"
  )
  {
    alpha = Left(alpha,-1);
  };
  return ( alpha );
};

function Left(t,n)
{
  if ( n >=0 )
    return ( t.substring(0,n) )
  else
    return ( Left(t,Len(t)+n) )
}

function Right(t,n)
{
  if ( n >=0 )
    return ( t.substring(Len(t)-n,Len(t)) )
  else
    return ( Right(t,Len(t)+n) )
}

function Lcase(t)
{
   return ( t.toLowerCase() )
}

function Val(t)
{
  return ( parseFloat(t) )
}

// Cookie handling ...

function ReadCookie(name)
{
  var nameEQ = name+"=";
  var cookieArray = document.cookie.split(";");
  for(var i=0;i < cookieArray.length;i++)
  {
    var cookie = cookieArray[i];
    while ( cookie.charAt(0) == " " )
    {
      c = cookie.substring(1,cookie.length);
    };
    if ( cookie.indexOf(nameEQ) == 0 )
    {
      return cookie.substring(nameEQ.length,cookie.length);
    };
  };
  return null;
};

function DeleteCookie(name)
{
  CreateCookie(name,"",-1);
};

function CreateCookie(name,value,days)
{
  if (days)
  {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    document.cookie = name+"="+value+expires+"; path=/";
  }
  else
  {
    document.cookie = name+"="+value+"; path=/";
  };
};

function IpExplain()
{
  t = "Everyone is allocated an IP Address when they connect to the internet. ";
  t=t+"This is a unique identifying number so when you ask for a web page the holder ";
  t=t+"of that web page knows who to send it back to.\n\nSome ISP's re-allocate IP ";
  t=t+"Addresses dynamically, so you may have been given an IP Address of someone who ";
  t=t+"posted a comment earlier.";
  alert( t );
};

