//##############################################################################
//<!-- Title:  Static Tree menu -->
//<!-- Author:  A.Bagdonas (sveplas@yahoo.com) -->
//<!-- Web Site:  http://www.ieskau.lt -->
//<!-- Begin
//##############################################################################
function StaticTree () {

hTree = new Array();
this.node       = 0;
this.connection = -1;

this.AddTreeNode= function (index, parent, text) {
  hNode = new Array(index, parent, text);
  hTree[hTree.length] = hNode;
  for (i=1;i<hTree.length;i++)
   if (hTree[i-1][0] > hTree[i][0])
     {
      hNode      = hTree[i-1];
      hTree[i-1] = hTree[i];
      hTree[i]   = hNode;
     }
  //document.write('AddTreeNode('+index+','+parent+','+text+');'+'<br>');
}

hList = new Array();
this.AddListNode = function (index, offset, text) {
  hNode = new Array(index, offset, text);
  hList[hList.length] = hNode;
  if (hList.length > 1)
    {
     this.node++;
     diff = hList[hList.length-1][1] - hList[hList.length-2][1];
     if (diff >= 1)
        {
         hList[hList.length-1][1] = hList[hList.length-2][1] + 1; //correcting, only increment +1 allowed
         this.connection = hTree.length-1;
         this.AddTreeNode(this.node, this.connection, text);           //new
        }
     else if (diff == 0)
        {
         this.connection = hTree[hTree.length-1][1];
         this.AddTreeNode(this.node, this.connection, text);      //old
        }
     else
        {
         i = hList.length-2;
         while ((hList[hList.length-1][1] != hList[i][1])&&(i>=0))
            i--;
         if (hList[hList.length-1][1] == hList[i][1])
            {
             this.connection = hTree[i][1];
             this.AddTreeNode(this.node, this.connection, text);
            }
         else
           {
            hList[hList.length-1][1] = 0; //correcting, only value 0 allowed
            this.connection = 0;
            this.AddTreeNode(this.node, 0, text); //correcting, only value -1 allowed
           }
        }
    }
  else
    {
     this.node = 0; this.connection = -1;
     this.AddTreeNode(this.node, this.connection, text);
    }
}

index = 0;
count = 0;
images = new Array();

function FindFirstNode() {
  if (hTree.length == 0) 
    return false;
  index = 0;
  count = 0;
  images[0] = "line3.gif";
  return true;
}

function GetNodeImage() {
  for (i=hTree[index][1]+1;i<hTree.length;i++)
   if (hTree[i][1] == hTree[hTree[index][1]][1])
     {
      return "line1.gif";
     }
  return "blank.gif";
}

function GetLastImage() {
  for (i=index+1;i<hTree.length;i++)
   if (hTree[i][1] == hTree[index][1])
     {
      return "line3.gif";
     }
  return "line2.gif";
}

function FindNextNode() {
  //search a sub node
  for (i=0;i<hTree.length;i++)
   if (hTree[i][1] == index)
     {
      index = i;
      images[count] = GetNodeImage();
      count++;
      images[count] = GetLastImage();
      return true;
     }
  
  //search for the next node
  for (i=index+1;i<hTree.length;i++)
   if (hTree[i][1] == hTree[index][1])
     {
      index = i;
      images[count] = GetLastImage();
      return true;
     }
  
  //the last item was found:
  if (hTree[index][1] == -1) return false;
  
  //leave sub node
  do {
      count--;
      olditem = hTree[index][1];
      for (i=olditem+1;i<hTree.length;i++)
        if (hTree[i][1] == hTree[olditem][1])
          {
           index = i;
           images[count] = GetLastImage();
           return true;
          }
      index = olditem;
     } while (hTree[index][1] != -1)
  return false;
}
this.DrawTreeTable=function ()
  {
   if (FindFirstNode())
     {
      document.write('<table class="MenuEditorTable">');
      do {
        document.write('<tr><td><p class="MenuEditorLine">');
        for (i=0;i<=count;i++)
           document.write('<img class="MenuEditorImg" src="images/'+images[i]+'">');
        document.write('<img class="MenuEditorImg" src="images/editopen.gif"> ');
        document.write(hTree[index][2]);
        document.write('</p></td></tr>');
      } while (FindNextNode());
      document.write('</table>');
     }  
  }
this.getLastListItemID=function ()
  {
   if (hList.length > 0)
     return hList[hList.length-1][0];
   else
     return 0;
   
  }
}
//##############################################################################
//##############################################################################
//##############################################################################
//  ########  TRACKS MOUSE POSITION FOR POPUP PLACEMENT
var isNav = (navigator.appName.indexOf("Netscape") !=-1);
function handlerMM(e){
x = (isNav) ? e.pageX : event.clientX + document.body.scrollLeft;
y = (isNav) ? e.pageY : event.clientY + document.body.scrollTop;
}
if (isNav){document.captureEvents(Event.MOUSEMOVE);}
document.onmousemove = handlerMM;


function GetBrowser()
{
	this.ver=navigator.appVersion
	this.agent=navigator.userAgent.toLowerCase()
	this.dom=document.getElementById?1:0
	this.ns4=(!this.dom && document.layers)?1:0;
	this.op=window.opera 
	this.moz=(this.agent.indexOf("gecko")>-1 || window.sidebar)
	this.ie=this.agent.indexOf("msie")>-1 && !this.op
	if(this.op){
		this.op5=(this.agent.indexOf("opera 5")>-1 || this.agent.indexOf("opera/5")>-1)
		this.op6=(this.agent.indexOf("opera 6")>-1 || this.agent.indexOf("opera/6")>-1)
		this.op7=this.dom&&!this.op5&&!this.op6 //So all higher opera versions will use it
	}else if(this.moz) this.ns6 = 1
	else if(this.ie){
		this.ie4 = !this.dom && document.all
  	this.ie5 = (this.agent.indexOf("msie 5")>-1)
  	this.ie55 = (this.ie5 && this.agent.indexOf("msie 5.5")>-1)
  	this.ie6 = this.dom && !this.ie4 && !this.ie5 && ! this.ie55
	}
	this.mac=(this.agent.indexOf("mac")>-1)
	this.detected=(this.ie6 || this.ie5 || this.ie4 || this.ns4 || this.ns6 || this.op5 || this.op6 || this.op7)
        this.usedom= this.ns6||this.op7//Use dom creation
        this.reuse = this.ie||this.op7||this.usedom //Reuse layers
        this.px=this.dom&&!this.op5?"px":""
	return this
}




function Set_Cookie( name, value, expires, path, domain, secure ) 
{
// set time, it's in milliseconds
var today = new Date();
today.setTime( today.getTime() );

/*
if the expires variable is set, make the correct 
expires time, the current script below will set 
it for x number of days, to make it for hours, 
delete * 24, for minutes, delete * 60 * 24
*/
if ( expires )
{
expires = expires * 1000 * 60 * 60 * 24;
}
var expires_date = new Date( today.getTime() + (expires) );

document.cookie = name + "=" +escape( value ) +
( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + 
( ( path ) ? ";path=" + path : "" ) + 
( ( domain ) ? ";domain=" + domain : "" ) +
( ( secure ) ? ";secure" : "" );
}



// this function gets the cookie, if it exists
function Get_Cookie( name ) {
	
var start = document.cookie.indexOf( name + "=" );
var len = start + name.length + 1;
if ( ( !start ) &&
( name != document.cookie.substring( 0, name.length ) ) )
{
return null;
}
if ( start == -1 ) return null;
var end = document.cookie.indexOf( ";", len );
if ( end == -1 ) end = document.cookie.length;
return unescape( document.cookie.substring( len, end ) );
}




// this deletes the cookie when called
function Delete_Cookie( name, path, domain ) {
if ( Get_Cookie( name ) ) document.cookie = name + "=" +
( ( path ) ? ";path=" + path : "") +
( ( domain ) ? ";domain=" + domain : "" ) +
";expires=Thu, 01-Jan-1970 00:00:01 GMT";
}


function InvalidPhone (field) {
  if (field == null)
    return false;
  else { //patikrinti ar numeris prasideda "+", jei ne klaida
    var str= field.value;
    if (str.length>0)
       return (str.charAt(0) != '+');
    else
       return false;
  }
}


// Email Validation Javascript
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.

function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('email address is mandatory');
   return false;
}
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('email address contains invalid characters');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("email address contains non ascii characters.");
      return false;
   }
}

var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert('email address must contain an @');
   return false;
}
if (atPos == 0) {
   if (db) alert('email address must not start with @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('email address must contain only one @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('email address must contain a period in the domain name');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('period must not immediately follow @ in email address');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('period must not immediately precede @ in email address');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('two periods must not be adjacent in email address');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('invalid primary domain in email address');
   return false;
}
return true;
}





function InvalidEmail(field) { 
if (field == null)
    return false;
else {
    var eAddr= field.value;
    if (eAddr.length == 0)
       return false;
    else
       return !validateEmail(eAddr,false,false);
}
}

function OptionSelectItem (element, value) {


    for (i = 0; i < element.length; i++) 
      if (element.options[i].value == value)
          element.options[i].selected = true;
}

function OptionSelectItem_text (element, value) {


    for (i = 0; i < element.options.length; i++) 
      if (element.options[i].text == value)
          element.options[i].selected = true;          
}

function CheckBoxSelect(element,value, constant){
    element.checked = value == constant;
}


function ValidateForm (form) {

 if (InvalidEmail(form.str_elpastas)) {
     alert('Neteisingai ivestas e-mail adresas');
     return false;
 }

 if (InvalidEmail(form.str_elpastas1)) {
     alert('Neteisingai ivestas e-mail adresas');
     return false;
 }

 if (InvalidEmail(form.str_skelbelpastas)) {
     alert('Neteisingai ivestas e-mail adresas');
     return false;
 }

 if (InvalidPhone(form.str_mob))
   if (!confirm('Mobilaus telefono numeris neteisingame formate\n pvz.: +37078798666\nTesti?'))
     return false;

 if (InvalidPhone(form.str_tel1))
   if (!confirm('Telefono (1) numeris neteisingame formate\n pvz.: +37078798666\nTesti?'))
     return false;

 if (InvalidPhone(form.str_tel2))
   if (!confirm('Telefono (2) numeris neteisingame formate\n pvz.: +37078798666\nTesti?'))
     return false;

 if (InvalidPhone(form.str_faksas))
   if (!confirm('Fakso numeris neteisingame formate\n pvz.: +37078798666\nTesti?'))
     return false;

 return true;
}




function AddRecordFormOnClick (form) {

 return ValidateForm(form);
}

function SearchFormOnClick (form) {

  if (form.str_vietove.selectedIndex != null) { 
    if (Get_Cookie('vietove') != null)    {
       Delete_Cookie('vietove');
    }
    Set_Cookie( 'vietove', form.str_vietove.selectedIndex+'', 1, '/', '', '');
    //alert(form.str_vietove.selectedIndex+'');
    }

 return ValidateForm(form);
}


function SearchFormUpdate(form) {

 if ((form.str_vietove != null) && ( Get_Cookie('vietove') != null)) {
   //alert(Get_Cookie('vietove'));
   form.str_vietove.options[1*Get_Cookie('vietove')].selected=true;
 }
}



function ShowPicture (img, src) {
 if ((img != null) && (src != "empty.gif") && (src != "") && (src != null))
    {
     img.src = src;
    }
}


//By George Chiang (www.javascriptkit.com) JavaScript site.
//Modified By Fabio Pintore (f.pintore@tiscalinet.it)
//you can find an example in (http://www.shooney.com/htm/examples/treemenu/default.htm)  

ns6_index=0

function change(e){

  if(!document.all&&!document.getElementById)
     return

  if (!document.all&&document.getElementById)
    ns6_index=1

  var source=document.getElementById&&!document.all? e.target:event.srcElement
  if (source.className=="folding"){
    var source2=document.getElementById&&!document.all? source.parentNode.childNodes:source.parentElement.all
    if (source2[2+ns6_index].style.display=="none"){
       source2[0].src="images/btnminus.gif"
       source2[2+ns6_index].style.display=''
     }
    else{
       source2[0].src="images/btnplus.gif"
       source2[2+ns6_index].style.display="none"
       // aClick.push("Pippo") 
    }
   }
}

function ClickCheck(nameOfBox, text) {
  var box       = document.getElementById("_"+nameOfBox);
  var box_value = document.getElementById(nameOfBox);
  if (box.checked)
    box_value.value = text;
  else
    box_value.value = "";
}

document.onclick=change

