//<!--
function Set_Content(link) {
    self.parent.frames['content'].document.location = link;
}

function Folder(folderDescription, hreference, icon)
{
  this.desc = folderDescription
  this.hreference = hreference
  this.id = -1
  this.navObj = 0
  this.iconImg = 0
  this.nodeImg = 0
  this.isLastNode = 0

  //dynamic data
  this.isOpen = true
  this.iconSrc = icon
  this.children = new Array
  this.nChildren = 0
  this.background = ""

  //methods
  this.initialize = initializeFolder
  this.setState = setStateFolder
  this.addChild = addChild
  this.createIndex = createEntryIndex
  this.hide = hideFolder
  this.display = display
  this.renderOb = drawFolder
  this.totalHeight = totalHeight
  this.subEntries = folderSubEntries
  this.outputLink = outputFolderLink

}

function setStateFolder(isOpen)
{
  var subEntries
  var totalHeight
  var fIt = 0
  var i=0

  if (isOpen == this.isOpen)
    return

  if (browserVersion == 2)
  {
    totalHeight = 0
    for (i=0; i < this.nChildren; i++)
      totalHeight = totalHeight + this.children[i].navObj.clip.height
      subEntries = this.subEntries()
    if (this.isOpen)
      totalHeight = 0 - totalHeight
    for (fIt = this.id + subEntries + 1; fIt < nEntries; fIt++)
      indexOfEntries[fIt].navObj.moveBy(0, totalHeight)
  }
  this.isOpen = isOpen
  propagateChangesInState(this)

}

function propagateChangesInState(folder)
{
  var i=0

  if (folder.isOpen)
  {
    if (folder.nodeImg)
      if (folder.isLastNode)
        folder.nodeImg.src = "/admin/images/dots1close.gif"
      else {
	    folder.nodeImg.src = "/admin/images/dots2close.gif"
		folder.background = "/admin/images/dots3.gif"
	  }
	folder.iconImg.src = folder.iconSrc; 
    for (i=0; i<folder.nChildren; i++)
      folder.children[i].display()
  }
  else
  {
    if (folder.nodeImg)
      if (folder.isLastNode)
        folder.nodeImg.src = "/admin/images/dots1open.gif"
      else {
	    folder.nodeImg.src = "/admin/images/dots2open.gif"
		folder.background = "/admin/images/dots3.gif"
	  }
	folder.iconImg.src = folder.iconSrc; 
    for (i=0; i<folder.nChildren; i++)
      folder.children[i].hide()
  }

}

function hideFolder()
{
  if (browserVersion == 1) {
    if (this.navObj.style.display == "none")
      return
    this.navObj.style.display = "none"
  } else {
    if (this.navObj.visibility == "hiden")
      return
    this.navObj.visibility = "hiden"
  }

  this.setState(0)
}

function initializeFolder(level, lastNode, leftSide)
{
var j=0
var i=0
var numberOfFolders
var numberOfDocs
var nc

  nc = this.nChildren


  this.createIndex()

  var auxEv = ""

  if (browserVersion > 0)
    auxEv = "<a href='javascript:clickOnNode("+this.id+")'>"
  else
    auxEv = "<a>"

  if (level>0)
    if (lastNode) //the last 'brother' in the children array
    {
      this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='/admin/images/dots1close.gif' border=0></a>")
      leftSide = leftSide + "<img src='/admin/images/blank.gif'>"
      this.isLastNode = 1
    }
    else
    {
      this.renderOb(leftSide + auxEv + "<img name='nodeIcon" + this.id + "' src='/admin/images/dots2close.gif' border=0></a>")
      leftSide = leftSide + "<img src='/admin/images/dots3.gif'>"
      this.isLastNode = 0
    }
  else
    this.renderOb("")


  if (nc > 0)
  {
    level = level + 1
    for (i=0 ; i < this.nChildren; i++)
    {
      if (i == this.nChildren-1)
        this.children[i].initialize(level, 1, leftSide)
      else
        this.children[i].initialize(level, 0, leftSide)
      }
  }
}

function drawFolder(leftSide)
{
  if (browserVersion == 2) {
    if (!doc.yPos)
	doc.yPos = FIRSTTOP
	doc.write("<layer id='folder" + this.id + "' top=" + doc.yPos + " visibility=hiden>")
  }

  doc.write("<table ")
  if (browserVersion == 1)
    doc.write(" id='folder" + this.id + "' style='position:block;' ")
  doc.write(" border=0 cellspacing=0 cellpadding=0>")
  doc.write("<tr><td" + this.background + ">")
  doc.write(leftSide)
  this.outputLink()
  doc.write("<img name='folderIcon" + this.id + "' ")
  doc.write("src='" + this.iconSrc+"' border=0></a>")
  doc.write("</td><td valign=middle nowrap class='nav'>")
  if (USETEXTLINKS)
  {
    this.outputLink()
    doc.write(this.desc + "</a>")
  }
  else
    doc.write(this.desc)
  doc.write("</td></tr>")
  doc.write("</table>")

  if (browserVersion == 2) {
    doc.write("</layer>")
  }

  if (browserVersion == 1) {
    this.navObj = doc.all["folder"+this.id]
    this.iconImg = doc.all["folderIcon"+this.id]
    this.nodeImg = doc.all["nodeIcon"+this.id]
  } else if (browserVersion == 2) {
    this.navObj = doc.layers["folder"+this.id]
    this.iconImg = this.navObj.document.images["folderIcon"+this.id]
    this.nodeImg = this.navObj.document.images["nodeIcon"+this.id]
    doc.yPos=doc.yPos+this.navObj.clip.height
  }
}


function outputFolderLink()
{
  if (this.hreference)
  {
    doc.write("<a href=" + this.hreference + " TARGET=\"" + TFRAME + "\" ")
    if (browserVersion > 0)
      doc.write("onClick='javascript:clickOnFolder("+this.id+")'")
    doc.write(">")
  }
}

function addChild(childNode)
{
  this.children[this.nChildren] = childNode
  this.nChildren++
  return childNode

//alert("function addChild(childNode="+childNode+"): nChildren="+this.nChildren+"");


}

function folderSubEntries()
{
  var i = 0
  var se = this.nChildren

  for (i=0; i < this.nChildren; i++){
    if (this.children[i].children) //is a folder
      se = se + this.children[i].subEntries()
  }

  return se
}


// Definition of class Item (a document or link inside a Folder)

function Item(itemDescription, itemLink, icon) // Constructor
{
  // constant data
  this.desc = itemDescription
  this.link = itemLink
  this.id = -1 //initialized in initalize()
  this.navObj = 0 //initialized in render()
  this.iconImg = 0 //initialized in render()
  this.iconSrc = icon
  this.background = ""

  // methods
  this.initialize = initializeItem
  this.createIndex = createEntryIndex
  this.hide = hideItem
  this.display = display
  this.renderOb = drawItem
  this.totalHeight = totalHeight
}

function hideItem()
{
  if (browserVersion == 1) {
    if (this.navObj.style.display == "none")
      return
    this.navObj.style.display = "none"
  } else {
    if (this.navObj.visibility == "hiden")
      return
    this.navObj.visibility = "hiden"
  }
}

function initializeItem(level, lastNode, leftSide)
{
  this.createIndex()

  if (level>0)
    if (lastNode) //the last 'brother' in the children array
    {
      this.renderOb(leftSide + "<img src='/admin/images/dots1.gif'>")
      leftSide = leftSide + "<img src='/admin/images/blank.gif'>"
    }
    else
    {
	  this.background = "/admin/images/dots3.gif"
      this.renderOb(leftSide + "<img src='/admin/images/dots2.gif'>")
      leftSide = leftSide + "<img src='/admin/images/dots3.gif'>"
    }
  else
    this.renderOb("")
}

function drawItem(leftSide)
{
  if (browserVersion == 2)
    doc.write("<layer id='item" + this.id + "' top=" + doc.yPos + " visibility=hiden>")

  doc.write("<table ")
  if (browserVersion == 1)
    doc.write(" id='item" + this.id + "' style='position:block;' ")
  doc.write(" border=0 cellspacing=0 cellpadding=0>")
  doc.write("<tr><td>")
  doc.write(leftSide)
  if (this.link)
      doc.write("<a href=" + this.link + ">")
  doc.write("<img id='itemIcon"+this.id+"' ")
  doc.write("src='"+this.iconSrc+"' border=0>")
  doc.write("</a>")
  doc.write("</td><td valign=middle nowrap class='nav'>")
  if (USETEXTLINKS && this.link)
    doc.write("<a href=" + this.link + ">" + this.desc + "</a>")
  else
    doc.write(this.desc)
  doc.write("</td></tr></table>")

  if (browserVersion == 2)
    doc.write("</layer>")

  if (browserVersion == 1) {
    this.navObj = doc.all["item"+this.id]
    this.iconImg = doc.all["itemIcon"+this.id]
  } else if (browserVersion == 2) {
    this.navObj = doc.layers["item"+this.id]
    this.iconImg = this.navObj.document.images["itemIcon"+this.id]
    doc.yPos=doc.yPos+this.navObj.clip.height
  }
}


// Methods common to both objects (pseudo-inheritance)

function display()
{
  if (browserVersion == 1)
    this.navObj.style.display = "block"
  else
    this.navObj.visibility = "show"
}

function createEntryIndex()
{
  this.id = nEntries
  indexOfEntries[nEntries] = this
  nEntries++
}

// total height of subEntries open
function totalHeight() //used with browserVersion == 2
{
  var h = this.navObj.clip.height
  var i = 0

  if (this.isOpen) //is a folder and _is_ open
    for (i=0 ; i < this.nChildren; i++)
      h = h + this.children[i].totalHeight()

  return h
}


// Events

function clickOnFolder(folderId)
{
  var clicked = indexOfEntries[folderId]

  if (!clicked.isOpen)
    clickOnNode(folderId)

  return

  if (clicked.isSelected)
    return
}

function clickOnNode(folderId)
{
  var clickedFolder = 0
  var state = 0

  clickedFolder = indexOfEntries[folderId]
  state = clickedFolder.isOpen

  clickedFolder.setState(!state) //open<->close
}


// Auxiliary Functions for Folder-Treee backward compatibility

function gFld(description, hreference, icon)
{
  folder = new Folder(description, hreference, icon)
  return folder
}

function gLnk(target, description, linkData, icon)
{
  fullLink = ""

  if (linkData)
   if (target==0)
     fullLink = "'"+linkData+"' target=\"" + TFRAME + "\""
   else
     fullLink = "'"+linkData+"' target=_blank"

  linkItem = new Item(description, fullLink, icon)
  return linkItem
}

function insFld(parentFolder, childFolder)
{
//alert("function insFld(parentFolder="+parentFolder.id+", childFolder="+childFolder+")");
  return parentFolder.addChild(childFolder)
}

function insDoc(parentFolder, document)
{
//	alert("function insDoc(parentFolder="+parentFolder+")"); 
  parentFolder.addChild(document)
}


function initializeDocument(tree)
{
  if (doc.all)
    browserVersion = 1 //IE4
  else
    if (doc.layers)
      browserVersion = 2 //NS4
    else
      browserVersion = 0 //other

  tree.initialize(0, 1, "")
  tree.display()

  if (browserVersion > 0)
  {
//    doc.write("<layer top="+indexOfEntries[nEntries-1].navObj.top+">&nbsp;</layer>")

    // close the whole tree
    clickOnNode(0)

    // open the root folder
    clickOnNode(0)

	// open Users folder
//	if (usernode != -1) clickOnNode(usernode.id)	

	// open Content folder
//	if (contentnode != -1) clickOnNode(contentnode.id)

  }
}
//------------------------------end of tree------------------------

function Set_Info(link) {
    self.parent.frames['content'].document.location = link;
}

function Show_Users() {
    self.parent.frames['content'].document.location = './content.phtml?theme=users&root=0';
}

function Show_NewUsers() {
    self.parent.frames['content'].document.location = './content.phtml?theme=users&root=0&newusers=1';
}

function Show_Administrators() {
    self.parent.frames['content'].document.location = './content.phtml?theme=users&root=10';
}

function Show_Companies() {
    self.parent.frames['content'].document.location = './content.phtml?theme=companies';
}

function Set_Status(caption) {
    window.status = caption;
    return true;
}

function Set_Content(link) {
    self.parent.frames['content'].document.location = link;
}

function ocMenu(objMenu,objImage,plus,minus)
{

if (navigator.userAgent.indexOf("MSIE")    != -1 &&
	navigator.userAgent.indexOf("Windows") != -1 &&
	navigator.appVersion.substring(0,1) > 3)
	{

        if (objMenu.style.display == "none")
			{
            objMenu.style.display = "";
            objImage.src='/admin/images/'+ minus;
			}
        else
			{
            objMenu.style.display = "none";
			objImage.src='/admin/images/'+ plus;
			}
	}
 else
	{

            objImage.src="/admin/images/sqbull.gif";
	}
}


function imgOpen2(url, title, wpic, hpic) {
w=screen.width-50;h=screen.height-70;
if (wpic > w) {left_w=20;wscroll=1;} else {left_w=((w-wpic)/2);w=wpic;wscroll=0;};
if (hpic > h) {top_w=5;wscroll=1;} else {top_w=((h-hpic)/2);h=hpic;if (!wscroll) wscroll=0;};
imgWindow=window.open("","imgw","width="+w+",height="+h+",status=no,toolbar=no,menubar=no,resizable=yes,scrollbars="+wscroll+",left="+left_w+",top="+top_w);
imgWindow.document.open();
imgWindow.document.write('<html><head><title>'+title+'</title><base href="http://asc.ru"></head><body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#000000" vlink="#000000" alink="#000000" bgcolor="#ffffff"><div align=center><a href="javascript:window.close();"><img src="http://'+location.host+url+'" border="0" alt="ЪБЛТЩФШ"></a></div></body></html>');
imgWindow.document.close();
imgWindow.focus;
}

function CheckSearchForm(testObj){
	var mForm = testObj;
	err = 0;
	s   = mForm.searchstr.value;
	if (s  == '')  err++;
		if (err != 0) {
			alert('Заполните строку поиска!');
	//		alert('Не заполнены обязательные поля');
			return false;
		}
		if (s.length <= 4) {
			alert('Строка поиска должна содержать более 4 символов!');
			return false;
		}
    	return true;
}

function windowOpener(windowHeight, windowWidth, windowName, windowUri)
{
var centerWidth=(window.screen.width-windowWidth)/2;
var centerHeight=(window.screenheight-windowHeight)/2;

newWindow=window.open(windowUri, windowName,'fullscreen=0,toolbar=0,location=0,directories=0,status=0,menubar=0,resizable=0,width='+windowWidth+',height='+windowHeight);
newWindow.blur();
newWindow.moveTo(centerWidth, centerHeight);
newWindow.focus();
return newWindow.name;
}

function view(wwidth, wheight, info, file_name, file_ext, desc){
	      var wnd;
						      		  
		  wnd = window.open('#', 'wnd_name', 'height=' + wheight + ', width=' + wwidth + ', menubar=0, resizable=0, scrollbars=0');
<!--		  wnd = window.open('#', 'wnd_name', 'menubar=0, resizable=1, scrollbars=1, fullscreen=1');-->
	      wnd.document.open();
	      wnd.document.write('<html><head><title>'+info+'</title></head><link rel="stylesheet" href="/main.css" type="text/css">');
	      wnd.document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
	      wheight -= 100;
	      wwidth  -= 40;
	      wnd.document.write('<div align=center><a href="#" onclick="self.close();"><img src="'+file_name+'" border="0"></a></div>');
	      wnd.document.write('<br><div align=center valign=center style="font-size : 13px; font-weight : 400 ; margin-left: 15px; margin-top: 7px; margin-bottom: 0px;"></dl>');
	      wnd.document.write('</body></html>');
	      wnd.document.close();
	      return false;
	   }


var wnd;
function imgOpen(file_name, info, wwidth, wheight){
	      
		  if (wnd) { wnd.close();}	      		  
		  wnd = window.open('#', 'wnd_name', 'height=' + wheight + ', width=' + wwidth + ', menubar=0, resizable=0, scrollbars=0');
<!--		  wnd = window.open('#', 'wnd_name', 'menubar=0, resizable=1, scrollbars=1, fullscreen=1');-->
	      wnd.document.open();
	      wnd.document.write('<html><head><title>'+info+'</title></head>');
	      wnd.document.write('<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" rightmargin="0" bottommargin="0" marginwidth="0" marginheight="0">');
	      wheight -= 100;
	      wwidth  -= 40;
	      wnd.document.write('<div align=center><a href="#" onclick="self.close();"><img src="'+file_name+'" border="0"></a></div>');
	      wnd.document.write('<br><div align=center valign=center style="font-size : 13px; font-weight : 400 ; margin-left: 15px; margin-top: 7px; margin-bottom: 0px;"></dl>');
	      wnd.document.write('</body></html>');
	      wnd.document.close();
	      return false;
	   }


function Checkst(id){if (id.className == "st_hide") id.className="st_show"; else id.className="st_hide";}

function Checkstrev(id, idhide)
{ 
 if (id.className == "st_hide") id.className="st_show"; else id.className="st_hide";
 for (var i=1; i<arguments.length; i++) arguments[i].className="st_hide";
}

function Checkst_all(fl, ids)
{ 
 if (fl) cmd="st_show"; else cmd="st_hide";
 if (fl) {
 	st_cmd_show.className="st_hide"; 
 	st_cmd_hide.className="st_show"; 
 } else {
 	st_cmd_show.className="st_show"; 
 	st_cmd_hide.className="st_hide"; 
 };

 for (var i=1; i<arguments.length; i++) arguments[i].className=cmd;
}

//-->