// --------------------------------------------------------
//  Browser help functions
//  ver 2.0.1
//
//  Copyright (c) 2000-2003 by KIEV2000.com Production
//  All Rights Reserved
// --------------------------------------------------------

var DlgParam = "RESIZABLE=NO,SCROLLBARS=NO,MENUBAR=NO,STATUS=NO,DIRECTORIES=NO,LOCATION=NO,TOOLBAR=NO"

function MakeDlgParam (w, h, Param)
{
  return "WIDTH=" + w + "px,HEIGHT=" + h + "px,LEFT=" + ((window.screen.width - w) / 2) + "px" + "px,TOP=" + ((window.screen.height - h) / 2) + (Param ? Param : DlgParam)
}

function isspace (ch)
{
  return ((ch == " ") || (ch == "\r") || (ch == "\n") || (ch == "\t") || (ch == "\x00") || (ch == '\xA0'))
}

function isnum (ch)
{
  return ("0" <= ch) && (ch <= "9")
}

function IsNumStr (str)
{
  for (var i = 0 ; i < str.length ; i++)
    if (!isnum (str.charAt (i)))
      return false
  return true
}

function IsEMail (str)
{
  var i
  if ((str.indexOf ("@", 0) != -1) && (str.indexOf (".", 0) != -1))
  {
    i = str.length - str.lastIndexOf (".") - 1
    if (i && (i <= 3) && (str.indexOf ("@", 0) != 0) && ((str.indexOf ("@", 0) + 1) < str.lastIndexOf (".")))
      return true
  }
  return false
}

function TruncSpace (str)
{
  str = String (str)
  var i, j
  for (i = 0 ; (i < str.length) && isspace (str.charAt (i)) ; i++) ;
  for (j = str.length - 1 ; (j > i) && isspace (str.charAt (j)) ; j--) ;
  return str.substring (i, j + 1)
}

function TagCheck (str)
{
  var i, j
  for (i = str.indexOf ("<", 0) ; i != -1 ; i = str.indexOf ("<",0))
  {
    j = str.indexOf (">", i)
    if (j == -1)
      j = str.length
    else 
      j++
    str = str.substring (0, i) + str.substring (j, str.length)
  }
//  for (i = 0 ; i < str.length ; i++)
//    if (str.charAt (i) == "'")
//      str = str.substring (0,i) + "\"" + str.substring (i + 1, str.length)
  return str
}

function CheckStr (str)
{
  return TagCheck (TruncSpace (str))
}

function EditTruncSpace (edit)
{
  edit.value = TruncSpace (edit.value)
}

function EditTagCheck (edit)
{
  edit.value = TagCheck (edit.value)
}

function EditCheckStr (edit)
{
  edit.value = CheckStr (edit.value)
}

function EditCheckNumKey ()
{
  if ((event.keyCode < 48) || (event.keyCode > 57))
    event.returnValue = 0
}

function FormArray (str, delim)
{
  str = String (str)
  var ret = new Array ()
  var i, j
  for (i = 0, j = str.indexOf (delim) ; j != -1 ; i = j + 1 , j = str.indexOf (delim, i))
    ret[ret.length] = str.substring (i, j)
  if (i < str.length)
    ret[ret.length] = str.substr (i)
  return ret
}

function Random (max)
{
  return Math.ceil (Math.random () * (max + 1)) - 1
}

function GenPassword (l)
{
  var ret = ""
  if (isNaN (l = parseInt (l))) 
    l = 8
  for (var i = 0 ; i < l ; i++)
  {
    if (Random (2))
      ret += String.fromCharCode ((Random (1) ? 65 : 97) + Random (25))
    else
      ret += Random (9)
  }
  return ret
}

function GetBRStr (str)
{
  var ret = ""
  var i, j, ch, b
  for (i = 0, j = 0 ; i < str.length ; i++)
    if (((b = ((ch = str.charAt (i)) == "\r")) && (str.charAt (i + 1) == "\n")) || (ch == "\n"))
    {
      ret += str.substring (j, i) + "<BR>"
      i++
      if (b)
        j = i + 1
      else
        j = i
    }
  return ret + str.substring (j, i)
}

function SetCookie (Name, Value, ExpireMonth)
{
  dt = new Date ()
  dt.setMonth (dt.getMonth () + (ExpireMonth ? ExpireMonth : 3))
  document.cookie = Name + "=" + escape (Value) + "; expires=" + dt.toGMTString ()
}

function GetCookie (Name)
{
  var Cookie = document.cookie.split ("; ")
  for (var i = 0 ; i < Cookie.length ; i++)
  {
    var Crumb = Cookie[i].split ("=")
    if (Name == Crumb[0]) 
      return unescape (Crumb[1])
  }
  return null
}

function DelCookie (Name)
{
  document.cookie = Name + "=;expires=Fri, 31 Dec 1999 23:59:59 GMT"
}
