//bNS4 = (document.layers) ? true : false
//bNS6 = (!document.all && document.getElementById) ? true : false
//bIE4 = (document.all && !document.getElementById) ? true : false
//bIE5 = (document.all && document.getElementById) ? true : false
//bIE = document.all ? true : false ;
//bNS = document.layers ? true : false ;

var DlgParam = "RESIZABLE=NO,SCROLLBARS=NO,MENUBAR=NO,STATUS=NO,DIRECTORIES=NO,LOCATION=NO,TOOLBAR=NO" ;
function isspace(ch){return ((ch==" ")||(ch=="\r")||(ch=="\n")||(ch=="\t"));}
function TruncSpace(str){var i;for(i=0;(i<str.length)&&isspace(str.charAt(i));i++);str=str.substring(i,str.length);for(i=str.length-1;(i>0)&&isspace(str.charAt(i));i--);str=str.substring(0,i+1);return str;}
function TagCheck(str){var tmp;var i;var j;for(i=str.indexOf("<",0);i!=-1;i=str.indexOf("<",0)){j=str.indexOf(">",i);if(j==-1)j=str.length;else j++;tmp=str.substring(0,i);str=tmp+str.substring(j,str.length);}for(i=0;i<str.length;i++)if(str.charAt(i)=="'"){tmp=str.substring(i+1,str.length);str=str.substring(0,i)+"\""+tmp;}return str;}
function CheckStr(Edit){TagCheck(Edit);TruncSpace(Edit);}
function EditTruncSpace(edit){edit.value=TruncSpace(edit.value);}
function EditTagCheck(edit){edit.value=TagCheck(edit.value);}
function EditCheckStr(Edit){EditTagCheck(Edit);EditTruncSpace(Edit);}
function EditCheckNumKey(){if((event.keyCode<48)||(event.keyCode>57))event.returnValue=0;}
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 1;}return 0;}
function IsNum(str){for(var i=0;i<str.length;i++)if((str.charAt(i)<"0")||(str.charAt(i)>"9"))return 0;return 1;}
function FormArray(Str,Delim){Str=String(Str);var ret=new Array();var i,j;for(i=j=0;i<Str.length;i++)if(Str.charAt(i)==Delim){ret[ret.length]=Str.substring(j,i);j=i+1;}if(i>j)ret[ret.length]=Str.substring(j,i);return ret;}
function Random(Max){return Math.ceil(Math.random()*(Max+1))-1;}
function GenPassword(Len){var ret="";Len=parseInt(Len);if(isNaN(Len))Len=8;for(var i=0;i<Len;i++){if(Random(2))ret+=String.fromCharCode((Random(1)?65:97)+Random(25));else ret+=Random(9);}return ret;}
function SetLang(Lang){var dt=new Date();dt.setYear(dt.getYear()+1);document.cookie="LNG="+Lang+";expires="+dt.toGMTString()+";path=/";window.location.reload();}

function MakeDlgParam (x, y, Param)
{
  return "WIDTH=" + x + "px,HEIGHT=" + y + "px,LEFT=" + ((window.screen.width - x) / 2) + "px" + "px,TOP=" + ((window.screen.height - y) / 2) + (Param ? Param : DlgParam)
}

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 ExpandLI (obj)
{
  var id = obj.id.substr (2)
  var li = document.getElementById ("li" + id)
  var ul = document.getElementById ("ul" + id)

  if (ul.style.display == "")
  {
    obj.src = "/images/tree/c.gif"
    ul.style.display = "none"
  }
  else
  {
    obj.src = "/images/tree/o.gif"
    ul.style.display = ""
  }
}

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"
}

function ExpandFirst()
{
  id = ulinf0.childNodes(0).id.substr (5)
  if (document.getElementById ("aainf"+id))
    ExpandLI(document.getElementById ("aainf"+id));
  for (i = 0; i < ulinf0.childNodes.length - 1; i++)
  {
    id = ulinf0.childNodes(i+1).id.substr (5)
    if (document.getElementById ("aainf"+id))
      ExpandLI(document.getElementById ("aainf"+id));
  }
}

function InitTree (pre, id)
{
  var ul, li
  if (id)
  {
    li = document.getElementById ("li" + pre + id)
    if (li)
      for (ul = li.parentNode ; ul && ul.tagName == "UL" ; ul = ul.parentNode.parentNode)
      {
        if (ul.style.display == "none")
        {
          document.getElementById ("aa" + pre + ul.id.substr (2 + pre.length)).src = "/images/tree/o.gif"
          ul.style.display = ""
        }
      }
  }
}

function LocationChangeAdd(loc,name,value)
{
  loc = String(loc);
  if (loc.search(name+"=") != -1)
  {
    var res = "";
    name = String(name);
    var i = loc.search(name+"=");
    var res = loc.substring(0,i)+name+"="+escape(value);
    i = i+name.length+1
    var temploc = loc.substring(i);
    var i = temploc.search("&");
    if (i != -1)
      res += temploc.substring(i);
    return res;
  }
  else
  {
    return loc+"&"+name+"="+value;
  }
}

function Sort(row,order)
{
  var loc = String(window.location);
  loc = LocationChangeAdd(loc,"row",row)
  loc = LocationChangeAdd(loc,"order",order)
  window.location = loc;
}

function SetPage (N) 
{
  loc = String(window.location);
  loc = LocationChangeAdd(loc,"Page",N)
  window.location = loc;
}
