var xHeight = 0;
var xWidth = 0;
var xDisplayed = 0;
var xLast = '';
var xDefaultTarget = '';

var marked_row = new Array;
var ismarked = '';
var CurrentLine = 0;

var Murls = new Array()
var Mactions = new Array()


var changedforms = new Array;

function Trim(TRIM_VALUE){
if(TRIM_VALUE.length < 1){
return"";
}
TRIM_VALUE = RTrim(TRIM_VALUE);
TRIM_VALUE = LTrim(TRIM_VALUE);
if(TRIM_VALUE==""){
return "";
}
else{
return TRIM_VALUE;
}
} //End Function

function RTrim(VALUE){
var w_space = String.fromCharCode(32);
var v_length = VALUE.length;
var strTemp = "";
if(v_length < 0){
return"";
}
var iTemp = v_length -1;

while(iTemp > -1){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(0,iTemp +1);
break;
}
iTemp = iTemp-1;

} //End While
return strTemp;

} //End Function

function LTrim(VALUE){
var w_space = String.fromCharCode(32);
if(v_length < 1){
return"";
}
var v_length = VALUE.length;
var strTemp = "";

var iTemp = 0;

while(iTemp < v_length){
if(VALUE.charAt(iTemp) == w_space){
}
else{
strTemp = VALUE.substring(iTemp,v_length);
break;
}
iTemp = iTemp + 1;
} //End While
return strTemp;
} //End Function


function getMouseX(e) {
  if (navigator.appName == "Microsoft Internet Explorer") { // grab the x-y pos.s if browser is IE
    tempX = event.clientX + document.body.scrollLeft
  } else {  // grab the x-y pos.s if browser is NS
    tempX = e.pageX
  }
  if (tempX < 0){tempX = 0}
  return tempX;
}

function getMouseY(e) {
  if (navigator.appName == "Microsoft Internet Explorer") { // grab the x-y pos.s if browser is IE
    tempY = event.clientY + document.body.scrollTop
  } else {  // grab the x-y pos.s if browser is NS
    tempY = e.pageY
  }
  // catch possible negative values in NS4
  if (tempY < 0){tempY = 0}
  // show the position values in the form named Show
  // in the text fields named MouseX and MouseY
  return tempY;
}

function selectColor(id)
{
  var color = window.showModalDialog("?id=getcolor",'ET',"dialogHeight:350px;dialogWidth:440px;resizable:0;status:0;scroll:0");
  if(color != null) {
    document.getElementById(id).value = color;
    document.getElementById(id).style.backgroundColor = color;
  }
}


function isNumber(field)
{

        var inputStr = field.value;

        inputStr = inputStr.replace(',','.');
        inputStr = inputStr.replace(' ','');


/*
	for(var i=0; i<inputStr.length; i++)
	{
		var charVal = inputStr.substring(i, i+1);
		if((charVal < "0" || charVal > "9") && charVal != "." && charVal != "-")
		{
			alert('See ei ole number ('+inputStr+')');
			field.value = '';
			return false;
		}
	}
	field.value = inputStr;
	return true;

*/

       if (parseFloat(inputStr,10)==(inputStr*1)) 
       {
           field.value = inputStr;
           return true;
       }
       else
       {
           alert('See ei ole number ('+inputStr+')');
	   field.value = '';
           return false;
       }
}


function ChangeToUpper(obj)
{
    obj.value = obj.value.toUpperCase();
}

function variable_exist(variable)
{
  if ( typeof( window[ variable ] ) != "undefined" )
  {
   return true;
  }
  else
  {
   return false;
  }
}


function OpenPopup(id,name,width,height)
{
         NewWindowResize(id, name, width, height, 'yes');
}


function sethl(id,txt,color, bgc)
{
   var mycolor = color;
   if (marked_row[id] == true)
   {
         mycolor = bgc;
   }

   if (document.layers)
   {
       document.layers[id].bgColor = mycolor;
       document.layers[id].border = '#000000';

       if (document.getElementById(id+'_2'))
       {
          document.layers[id+'_2'].bgColor = mycolor;
          document.layers[id+'_2'].border = '#000000';

       }
   }
   else
   {
       {
             document.getElementById(id).style.background = mycolor;
             if (document.getElementById(id+'_2'))
             {
                 document.getElementById(id+'_2').style.background = mycolor;
             }

       }
   }
   window.status = txt;
}

function unsethl(id,txt,color, bgc)
{
   var mycolor = color;
   if (marked_row[id] == true)
   {
         mycolor = bgc;
   }
   if(document.layers)
   {
       document.layers[id].bgColor = mycolor ;
       if (document.getElementById(id+'_2'))
       {
          document.layers[id+'_2'].bgColor = mycolor;

       }
   }
   else
   {
      {
         document.getElementById(id).style.background = mycolor;
         if (document.getElementById(id+'_2'))
         {
             document.getElementById(id+'_2').style.background = mycolor;

         }

      }
   }
   window.status = '';
}




function gotoParent(url,closewin)
{
//    alert(url);
    self.opener.location.href=url;

    if (closewin==1) window.close();
}


function gotoURL(url)
{
  self.location.href = url;
}

function FieldInfo(inputid,formname,fieldname)
{
     var k = event.keyCode;

     if (k==113)
     {
        var s = '<table border=0 cellspacing=1 cellpadding=3 bgcolor=#cccccc>';
        s = s + '<tr bgcolor=#ffffff><td>Form name:</td><td><b>' + formname + '</td></tr>';
        s = s + '<tr bgcolor=#ffffff><td>Field  name:</td><td><b>' + fieldname + '<br>';
        s = s + '<tr bgcolor=#ffffff><td>Input  type:</td><td><b>' + document.getElementById(inputid).type + '</td></tr>';
        s = s + '<tr bgcolor=#ffffff><td>Input  size:</td><td><b>' + document.getElementById(inputid).size + '</td></tr>';
        s = s + '<tr bgcolor=#ffffff><td>Input maxsize:</td><td><b>' + document.getElementById(inputid).maxLength + '</td></tr>';
        if (document.getElementById(inputid).type == 'text' || document.getElementById(inputid).type == 'checkbox')
        s = s + '<tr bgcolor=#ffffff><td>Default value:</td><td><b>' + document.getElementById(inputid).defaultValue + '</td></tr>';
        if (document.getElementById(inputid).readOnly)
        s = s + '<tr bgcolor=#ffffff><td>READONLY:</td><td><b>Yes\n</td></tr>';
        s = s + '</table>';

//        alert(s);
        InfoAreaText = s;
        InfoView(1);

        InfoDisplayed = 2;


     }
}


function viewSource()
{
  d=window.open('SOURCE','','menubar=no, scrollbars=yes');
  d.document.open('text/plain').write(document.documentElement.outerHTML);
}



function ChangeTab(form, tab, total,classaddon)
{
   var my = '';
   for (i=1; i<=total;i++)
   {
       my = 'frmgrp_'+form+'_'+i;
       my2 = 'cell_'+form+'_'+i;
       document.getElementById(my).style.display = 'none';
       document.getElementById(my2).className = 'tab_unactive' + classaddon;
   }
   my = 'frmgrp_'+form+'_'+tab;
   my2 = 'cell_'+form+'_'+tab;
   document.getElementById(my).style.display = '';
   document.getElementById(my2).className = 'tab_active' + classaddon;
}

function HideId(id, form)
{
//   document.getElementById(id).disabled = true;
/*
   if (document.getElementById(id))
      document.getElementById(id).style.visibility = 'hidden';

*/   var etype = '';

   for (i = 0; i < document.getElementById(form).elements.length; i++)
   {
       etype = document.getElementById(form).elements[i].type ;
       if (etype=='button' || etype=='submit' || etype=='reset')  document.getElementById(form).elements[i].style.display = 'none';
   }
}

function isNumberInt(field)
{
        var inputStr = field.value;
	for(var i=0; i<inputStr.length; i++)
	{
		var charVal = inputStr.substring(i, i+1);
		if((charVal < "0" || charVal > "9"))
		{
			alert('See ei ole täisarv ('+inputStr+')');
			field.value = '';
			return false;
		}
	}
	return true;
}

function checkEmailAddress(field)
{
      var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);

      if (goodEmail)
      {
           good = true
      }
      else
      {
            alert('Palun sisesta õige formaadiga e-mail!');
            field.select();
            field.focus();
            return false;
      }
}



        function checkusermenu()
        {

           if (typeof( window[ 'SubDisplayed' ] ) != 'undefined')
           {
              if (SubDisplayed == 1)
              {
                  document.getElementById('RightMenuSubID').style.visibility = 'hidden';
                  SubDisplayed = 0;
              }
           }



           if (typeof( window[ 'menudisplayed' ] ) != 'undefined')
           {
            if (menudisplayed)
            {
         	document.getElementById('RightMenuID').style.visibility = 'hidden';
         	menudisplayed = 0;
            }
           }
        }


        function PopupWindow(mypage, myname, wstyle, w, h, scroll) {
        if (wstyle == 0)
        {
            var winl = (screen.width - w) / 2;
            var wint = (screen.height - h) / 2;
        }
        if (wstyle == 1)
        {
            var winl = 10;
            var wint = 10;
        }
        if (wstyle == 2)
        {
            var winl = screen.width - w - 20;
            var wint = 10;
        }

        if (wstyle == 3)
        {
            var winl = 10;
            var wint = screen.height - h - 20;
        }

        if (wstyle == 4)
        {
            var winl = screen.width - w - 20;
            var wint = screen.height - h - 20;
        }


        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',notresizable'
        win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
        }


        function NewWindow(mypage, myname, w, h, scroll) {
        var winl = (screen.width - w) / 2;
        var wint = (screen.height - h) / 2;
        checkusermenu();
        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=no, status=no'
        win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
        }


        function NewWindowResize(mypage, myname, w, h, scroll) {

        var winl = (screen.width - w) / 2;
        var wint = (screen.height - h) / 2;

        checkusermenu();

//        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes,status=yes,menubar=yes'
        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizable=yes'
        win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
        }



        function NewWindowNext(mypage, myname, w, h, level, scroll) {
        var winl = (screen.width - w) / 2 + level * 30;
        var wint = (screen.height - h) / 2 + level * 30;

        checkusermenu();

        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',notresizable'
        win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
        }


        function NewWindowUR(mypage, myname, w, h, scroll) {
        var winl = (screen.width - w) - 50;
        var wint = 30;
        checkusermenu();

        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',resizible'
        win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
        }


        function NewWindowMenu(mypage, myname, w, h, scroll) {
        var winl = (screen.width - w) / 2;
        var wint = (screen.height - h) / 2;
        checkusermenu();
        winprops = 'height='+h+',width='+w+',top='+wint+',left='+winl+',scrollbars='+scroll+',notresizable,menubar=1'
        win = window.open(mypage, myname, winprops)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
        }


        function NewFullWindow(mypage,myname)
        {
        checkusermenu();
        win = window.open(mypage, myname)
        if (parseInt(navigator.appVersion) >= 4) { win.window.focus(); }
        }


        function closewindow(url)
        {
           opener.location.href = url;
           window.setTimeout('window.close()',1000);
        }

        function printit(){
        var NS = (navigator.appName == "Netscape");
        var VERSION = parseInt(navigator.appVersion);
        if (VERSION > 3) {

        if (NS) {
             window.print() ;
        } else {
                  var WebBrowser = '<OBJECT ID="WebBrowser1" WIDTH=0 HEIGHT=0 CLASSID="CLSID:8856F961-340A-11D0-A96B-00C04FD705A2"></OBJECT>';
                  document.body.insertAdjacentHTML('beforeEnd', WebBrowser);
                  WebBrowser1.ExecWB(6, 2);//Use a 1 vs. a 2 for a prompting dialog box    WebBrowser1.outerHTML = "";
          }
        }
}



function MoveTo(FM,page,ptarget,ftype,width,height,scroll)
{
     var a = document.forms[FM];

//     if (xDefaultTarget) xDefaultTarget = document.forms[FM].target;
//     else document.forms[FM].target = xDefaultTarget;

     if (xDisplayed == 1 && xLast) HideUserButtons(xLast);

     if (ftype == 3)
     {
          var myText = window.showHelp('?'+page);
          return;
     }

     if (FM && a)
     {

          var Attrib = '?' + page;
          switch(ftype)
          {
             case '1' : NewWindowResize('about:blank',ptarget,width,height,scroll);
                        break;
             case '2' : NewWindowResize('about:blank',ptarget,width,height,scroll);
                        break;
             case '3' : return;
          }
          document.forms[FM].setAttribute('ACTION',Attrib,0);
          if (ptarget)
          {
            document.forms[FM].target = ptarget;
          }
          else
          {
            ptarget = '';
            document.forms[FM].target = ptarget;
          }
          document.forms[FM].submit();
     }
     else
     {
          switch(ftype)
          {
             case '1' : NewWindowResize('?'+page,ptarget,width,height,scroll);
                        break;
             case '2' : NewWindowResize('?'+page,ptarget,width,height,scroll);
                        break;
             default  : self.location.href = '?'+page;
          }

     }

}


function JumpTo(p_id, p_idname, p_action, p_parm, p_mode)
{
     var link = '?id='+p_id+'&action='+p_action+'&'+p_idname+'='+p_parm;
     switch(p_mode)
     {
         case 1  : self.opener.location.href = link;
                   window.close();
                   break;
         default : self.location.href = link;
                   return false;
     }
}


function CheckInBody()
{
//   alert('ajee '+event.type+' '+event.keyCode);

//   alert(navigator.appName);
   if (navigator.appName == "Microsoft Internet Explorer" && event.type == 'keyup' && event.keyCode == '27')
   {

           if (xDisplayed == 1 && xLast) HideUserButtons(xLast);

           if (InfoDisplayed)
           {
                CloseInfoView();
                return;
           }

   	   if (SubDisplayed)
   	   {
                document.getElementById('RightMenuSubID').style.visibility = 'hidden';
         	SubDisplayed = 0;
           }
           else
           {

         	document.getElementById('RightMenuID').style.visibility = 'hidden';
//         	RightMenuID.style.visibility = 'hidden';
         	menudisplayed = 0;
           }
   }


   if (InfoDisplayed == 2 && event.keyCode != 123)
   {
                CloseInfoView();
                return;
   }


}


function CheckMouseInBody()
{
   if (InfoDisplayed == 2)
   {
                CloseInfoView();
                return;
   }
}


function SetBlockGrid(id, count)
{
     var mH = 0;
     var mW = 0;
     var lH = 0;
     var lW = 0;
     var pref = '';
     for (i = 1; i <= count;  i++)
     {
        pref = id + '_' + LineIds[i];
	lW = document.getElementById(pref).offsetWidth;
	if (lW > mW) mW = lW;
     }

     if (mW > 150) mW = 150;

     for (i = 1; i <= count; i++)
     {
        pref = id + '_' + LineIds[i];
	document.getElementById(pref).style.width = mW;
      }

     for (i = 1; i <= count;  i++)
     {
        pref = id + '_' + LineIds[i];
	lH = document.getElementById(pref).offsetHeight;
	if (lH > mH) mH = lH;
     }

     for (i = 1; i <= count; i++)
     {
        pref = id + '_' + LineIds[i];
	document.getElementById(pref).style.height = mH;
      }


}


function DisplayUserButtons(controlid, area)
{

     if (window.CloseMenu)
     {
         CloseMenu();
     }

     if (xLast)
         if (document.getElementById(xLast).style.visibility == 'visible')
         {
             if (xLast == area)
             {
                 HideUserButtons(xLast);
                 return;
             }
             else
             {
                 HideUserButtons(xLast);
             }
         }

     xLast = area;

     if (xHeight == 0)
     {
       xHeight = document.getElementById(controlid).offsetTop;
       xWidth = document.getElementById(controlid).offsetLeft;
     }
     document.getElementById(area).style.visibility = 'visible';
     document.getElementById(area).style.top = xHeight + 12;
     document.getElementById(area).style.left = xWidth ;
     xDisplayed = 1;

}

function ChangeDisplayStatus(pid,info)
{
    if (document.getElementById(pid))
    {
       var stat = document.getElementById(pid).style.display;
       if (stat == '') stat = 'none'; else stat = '';
//       alert(stat);
       document.getElementById(pid).style.display = stat;

       if (document.getElementById(info))
       {
          var tekst = document.getElementById(info).innerHTML.substring(1,100);
          if (stat == 'none') tekst = '+' + tekst;
          else tekst = '-' + tekst;
          document.getElementById(info).innerHTML = tekst;
//          alert(tekst);
       }


    }
}

function HideUserButtons(area)
{
     document.getElementById(area).style.visibility = 'hidden';
     xHeight = 0;
     xWidth = 0;
//     xLast = '';
     xDisplayed = 0;
}

function selectcheckboxes(form_name, checked)
{

    checkusermenu();
    if (xDisplayed == 1 && xLast) HideUserButtons(xLast);

    if (!document.forms[form_name])
    {
        return;
    }

    var a = document.forms[form_name];
    for (i = 0; i < a.elements.length; i++)
    {
       if (a.elements[i].type == 'checkbox')
         a.elements[i].checked = checked;
    }

}

var CheckStatus = false;

function SwapCheckboxes(form_name)
{
    CheckStatus = !CheckStatus;
    selectcheckboxes(form_name,CheckStatus);
}

function runform(form, action)
{
     if (document.forms[form].action) document.forms[form].action.value = action;
     document.forms[form].submit();
}

function OpenModal(url)
{
    var myTitle = "This is a custom title";
    var myText = showModalDialog(url+'&ismodal=on',
                                 myTitle,      // str or obj specified here can be read from dialog as "window.dialogArguments"
                                 "resizable: yes; help: no; status: no; scroll: yes; unadorned: yes;");


}

function OpenHelp(name)
{
    var myText = window.showHelp('?id=showhelp&name='+name);
}



function OpenModeless(url)
{
    var myTitle = "This is a custom title";
    var myText = showModelessDialog(url,
                                 myTitle,      // str or obj specified here can be read from dialog as "window.dialogArguments"
                                 "resizable: yes; help: no; status: no; scroll: no; ");
}


   function pleasewait()
   {
/*   	alert('Please wait, loading!');*/
   }


   function showalert(txt)
   {
   	alert(txt);
   }

   function redir_self(pge)
   {
   	if (pge != '')
      {
      	this.location.href = pge;
      }
   }

   function redirtotarget(pge,target)
   {
   	if (pge != '')
      {
          window.open(pge,target);
      }
   }


   function redir(pge,x,y,level,mname)
   {
       if (pge != '')
       {
   	 if (x==0)
       this.location.href = pge;
       else
       {
       	if (level == 0)
       	{
       		NewWindow(pge,mname,x,y,'yes');
       	}
         else
         {
            NewWindowNext(pge, mname, x, y, level, 'yes') ;
         }
       }
       }
       else alert('Sorry, function not available !!!');
   }



   function redirright(pge,x,y,level,mname)
   {
   	 if (event.button == 2)
   	 {
       if (pge != '')
       {
   	 if (x==0)
       this.location.href = pge;
       else
       {
       	if (level == 0)
       	{
       		NewWindow(pge,mname,x,y,'yes');
       	}
         else
         {
            NewWindowNext(pge, mname, x, y, level, 'yes') ;
         }
       }
       }
       else alert('Sorry, function not available !!!');
     }  
   }


   function infobox(p1,p2,p3,p4,p5,p6)
   {
   	if (p1 != '') this.document.CLICK.fld1.value = p1;
   	if (p2 != '') this.document.CLICK.fld2.value = p2;
   	if (p3 != '') this.document.CLICK.fld3.value = p3;
   	if (p4 != '') this.document.CLICK.fld4.value = p4;
   	if (p5 != '') this.document.CLICK.fld5.value = p5;
   	if (p6 != '') this.document.CLICK.fld6.value = p6;
   }

   function InitMenu()
   {
     var bar = menuBar.children

     for(var i=0;i < bar.length;i++)
        {
          var menu=eval(bar[i].menu)
          menu.style.visibility = "hidden"
          bar[i].onmouseover = new Function("ShowMenu("+bar[i].id+")")
          var Items = menu.children
          for(var j=0; j<Items.length; j++)
            {
              var menuItem = eval(Items[j].id)

                if(menuItem.menu != null)
                   {
                    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
                    var tmp = eval(menuItem.id+"_Arrow")
//                    tmp.style.pixelLeft = menu.getBoundingClientRect().Right - tmp.offsetWidth - 15
                    tmp.style.pixelLeft = 130

                    FindSubMenu(menuItem.menu)}

                 if(menuItem.cmd != null)
                   {
                   menuItem.onclick = new Function("Do("+menuItem.id+")") }

              menuItem.onmouseover = new Function("highlight("+Items[j].id+")")

            }

        }
   }
   function FindSubMenu(subMenu)
   {
         var menu=eval(subMenu)
         var Items = menu.children
          for(var j=0; j<Items.length; j++)
            {
              menu.style.visibility = "hidden"
              var menuItem = eval(Items[j].id)


              if(menuItem.menu!= null)
                 {
                    menuItem.innerHTML += "<Span Id="+menuItem.id+"_Arrow class='Arrow'>4</Span>"
                    // var tmp = eval(menuItem.id+"_Arrow")
                    var tmp = eval(menuItem.id+"_Arrow")
                    //tmp.style.pixelLeft = 35 //menuItem.getBoundingClientRect().right - tmp.offsetWidth - 15
                    tmp.style.pixelLeft = 130
                    FindSubMenu(menuItem.menu)
                 }

                 if(menuItem.cmd != null)
                   {
                   menuItem.onclick = new Function("Do("+menuItem.id+")") }

              menuItem.onmouseover = new Function("highlight("+Items[j].id+")")

            }
   }
   function ShowMenu(obj)
   {
     HideMenu(menuBar)
     var menu = eval(obj.menu)
     var bar = eval(obj.id)
     bar.className="barOver"
     menu.style.visibility = "visible"
     menu.style.pixelTop =  obj.getBoundingClientRect().top + obj.offsetHeight + Bdy.scrollTop - 3
     menu.style.pixelLeft = obj.getBoundingClientRect().left + Bdy.scrollLeft - 2
   }

   function highlight(obj)
   {
     var PElement = eval(obj.parentElement.id)
     if(PElement.hasChildNodes() == true)
     {  var Elements = PElement.children
       for(var i=0;i<Elements.length;i++)
       {
          TE = eval(Elements[i].id)
          TE.className = "menuItem"
       }
      }
     obj.className="ItemMouseOver"
     window.defaultStatus = obj.title
     ShowSubMenu(obj)
   }

   function Do(obj)
   {
    var cmd = eval(obj).cmd
    window.navigate(cmd)

   }

   function HideMenu(obj)
   {
          if(obj.hasChildNodes()==true)
              {
                 var child = obj.children

                 for(var j =0;j<child.length;j++)
                  {
                     if (child[j].className=="barOver")
                     {var bar = eval(child[j].id)
                      bar.className="Bar"}

                     if(child[j].menu != null)
                       {
                          var childMenu = eval(child[j].menu)
                          if(childMenu.hasChildNodes()==true)
                               HideMenu(childMenu)

                           childMenu.style.visibility = "hidden"
                         }
                  }

              }
   }
  function ShowSubMenu(obj)
  {
     PMenu = eval(obj.parentElement.id)
      HideMenu(PMenu)
     if(obj.menu != null)
     {
     var menu = eval(obj.menu)
     menu.style.visibility = "visible"
     menu.style.pixelTop =  obj.getBoundingClientRect().top + Bdy.scrollTop
     menu.style.pixelLeft = obj.getBoundingClientRect().right + Bdy.scrollLeft - 10
     if(menu.getBoundingClientRect().right > window.screen.availWidth )
       menu.style.pixelLeft = obj.getBoundingClientRect().left - menu.offsetWidth
    }
  }





 ///////////////////CascadedDropdown Menu/////////////////
 //Date : 08/09/2001               						//
 //Version : 1.0        								//
 //Author Mr.Arun N Kumar	                            //
 //EMail: n_arunk@hotmail.com							//
 /////////////////////////////////////////////////////////
 // Modifications on this code is not recomended
 // Suggestions are welcome




// Title: Tigra Calendar
// URL: http://www.softcomplex.com/products/tigra_calendar/
// Version: 3.2 (European date format)
// Date: 10/14/2002 (mm/dd/yyyy)
// Note: Permission given to use this script in ANY kind of applications if
//    header lines are left unchanged.
// Note: Script consists of two files: calendar?.js and calendar.html

// if two digit year input dates after this year considered 20 century.
var NUM_CENTYEAR = 30;
// is time input control required by default
var BUL_TIMECOMPONENT = false;
// are year scrolling buttons required by default
var BUL_YEARSCROLL = true;

var calendars = [];
var RE_NUM = /^\-?\d+$/;

function calendar1(obj_target) {

	// assing methods
	this.gen_date = cal_gen_date1;
	this.gen_time = cal_gen_time1;
	this.gen_tsmp = cal_gen_tsmp1;
	this.prs_date = cal_prs_date1;
	this.prs_time = cal_prs_time1;
	this.prs_tsmp = cal_prs_tsmp1;
	this.popup    = cal_popup1;

	// validate input parameters
	if (!obj_target)
		return cal_error("Error calling the calendar: no target control specified");
	if (obj_target.value == null)
		return cal_error("Error calling the calendar: parameter specified is not valid tardet control");
	this.target = obj_target;
	this.time_comp = BUL_TIMECOMPONENT;
	this.year_scroll = BUL_YEARSCROLL;

	// register in global collections
	this.id = calendars.length;
	calendars[this.id] = this;
}

function cal_popup1 (str_datetime) {
	this.dt_current = this.prs_tsmp(str_datetime ? str_datetime : this.target.value);
	if (!this.dt_current) return;

	var obj_calwindow = window.open(
		'?id=calendar&datetime=' + this.dt_current.valueOf()+ '&mid=' + this.id,
		'Calendar', 'width=200,height='+(this.time_comp ? 215 : 190)+
		',status=no,resizable=no,top=200,left=200,dependent=yes,alwaysRaised=yes'
	);
	obj_calwindow.opener = window;
	obj_calwindow.focus();
}

// timestamp generating function
function cal_gen_tsmp1 (dt_datetime) {
	return(this.gen_date(dt_datetime) + ' ' + this.gen_time(dt_datetime));
}

// date generating function
function cal_gen_date1 (dt_datetime) {
	return (
		(dt_datetime.getDate() < 10 ? '0' : '') + dt_datetime.getDate() + "."
		+ (dt_datetime.getMonth() < 9 ? '0' : '') + (dt_datetime.getMonth() + 1) + "."
		+ dt_datetime.getFullYear()
	);
}
// time generating function
function cal_gen_time1 (dt_datetime) {
	return (
		(dt_datetime.getHours() < 10 ? '0' : '') + dt_datetime.getHours() + ":"
		+ (dt_datetime.getMinutes() < 10 ? '0' : '') + (dt_datetime.getMinutes()) + ":"
		+ (dt_datetime.getSeconds() < 10 ? '0' : '') + (dt_datetime.getSeconds())
	);
}

// timestamp parsing function
function cal_prs_tsmp1 (str_datetime) {
	// if no parameter specified return current timestamp
	if (!str_datetime)
		return (new Date());

	// if positive integer treat as milliseconds from epoch
	if (RE_NUM.exec(str_datetime))
		return new Date(str_datetime);
		
	// else treat as date in string format
	var arr_datetime = str_datetime.split(' ');
	return this.prs_time(arr_datetime[1], this.prs_date(arr_datetime[0]));
}

// date parsing function
function cal_prs_date1 (str_date) {

	var arr_date = str_date.split('.');

	if (arr_date.length != 3)
        {
        	var arr_date = str_date.split('.');
   	        if (arr_date.length != 3)
   	        {
        	     return cal_error ("Invalid date format: '" + str_date + "'.\nFormat accepted is dd.mm.yyyy.");
        	}
        }
	if (!arr_date[0]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo day of month value can be found.");
	if (!RE_NUM.exec(arr_date[0])) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[1]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo month value can be found.");
	if (!RE_NUM.exec(arr_date[1])) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed values are unsigned integers.");
	if (!arr_date[2]) return cal_error ("Invalid date format: '" + str_date + "'.\nNo year value can be found.");
	if (!RE_NUM.exec(arr_date[2])) return cal_error ("Invalid year value: '" + arr_date[2] + "'.\nAllowed values are unsigned integers.");

	var dt_date = new Date();
	dt_date.setDate(1);

	if (arr_date[1] < 1 || arr_date[1] > 12) return cal_error ("Invalid month value: '" + arr_date[1] + "'.\nAllowed range is 01-12.");
	dt_date.setMonth(arr_date[1]-1);
	 
	if (arr_date[2] < 100) arr_date[2] = Number(arr_date[2]) + (arr_date[2] < NUM_CENTYEAR ? 2000 : 1900);
	dt_date.setFullYear(arr_date[2]);

	var dt_numdays = new Date(arr_date[2], arr_date[1], 0);
	dt_date.setDate(arr_date[0]);
	if (dt_date.getMonth() != (arr_date[1]-1)) return cal_error ("Invalid day of month value: '" + arr_date[0] + "'.\nAllowed range is 01-"+dt_numdays.getDate()+".");

	return (dt_date)
}

// time parsing function
function cal_prs_time1 (str_time, dt_date) {

	if (!dt_date) return null;
	var arr_time = String(str_time ? str_time : '').split(':');

	if (!arr_time[0]) dt_date.setHours(0);
	else if (RE_NUM.exec(arr_time[0]))
		if (arr_time[0] < 24) dt_date.setHours(arr_time[0]);
		else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed range is 00-23.");
	else return cal_error ("Invalid hours value: '" + arr_time[0] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[1]) dt_date.setMinutes(0);
	else if (RE_NUM.exec(arr_time[1]))
		if (arr_time[1] < 60) dt_date.setMinutes(arr_time[1]);
		else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid minutes value: '" + arr_time[1] + "'.\nAllowed values are unsigned integers.");

	if (!arr_time[2]) dt_date.setSeconds(0);
	else if (RE_NUM.exec(arr_time[2]))
		if (arr_time[2] < 60) dt_date.setSeconds(arr_time[2]);
		else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed range is 00-59.");
	else return cal_error ("Invalid seconds value: '" + arr_time[2] + "'.\nAllowed values are unsigned integers.");

	dt_date.setMilliseconds(0);
	return dt_date;
}

function cal_error (str_message) {
	alert (str_message);
	return null;
}


var TCP = new TColorPicker();

function TCPopup(field, palette) {
	this.field = field;
	this.initPalette = !palette || palette > 2 ? 0 : palette;
	var w = 194, h = 206,
	move = screen ?
		',left=' + ((screen.width - w) >> 1) + ',top=' + ((screen.height - h) >> 1) : '',
	o_colWindow = window.open('?id=picker', null, "help=no,status=no,scrollbars=no,resizable=no" + move + ",width=" + w + ",height=" + h + ",dependent=yes", true);
	o_colWindow.opener = window;
	o_colWindow.focus();
}

function TCBuildCell (R, G, B, w, h) {
	return '<td bgcolor="#' + this.dec2hex((R << 16) + (G << 8) + B) + '"><a href="javascript:P.S(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')" onmouseover="P.P(\'' + this.dec2hex((R << 16) + (G << 8) + B) + '\')"><img src="/img/pixel.gif" width="' + w + '" height="' + h + '" border="0"></a></td>';
}

function TCSelect(c) {
	this.field.value = '#' + c.toUpperCase();
	this.win.close();
}

function TCPaint(c, b_noPref) {
	c = (b_noPref ? '' : '#') + c.toUpperCase();
	if (this.o_samp) 
		this.o_samp.innerHTML = '<font face=Tahoma size=2>' + c +' <font color=white>' + c + '</font></font>'
	if(this.doc.layers)
		this.sample.bgColor = c;
	else {
		if (this.sample.backgroundColor != null) this.sample.backgroundColor = c;
		else if (this.sample.background != null) this.sample.background = c;
	}
}

function TCGenerateSafe() {
	var s = '';
	for (j = 0; j < 12; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i ++)
				s += this.bldCell(k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, i * 51, 8, 10);
		s += "</tr>";
	}
	return s;
}

function TCGenerateWind() {
	var s = '';
	for (j = 0; j < 12; j ++) {
		s += "<tr>";
		for (k = 0; k < 3; k ++)
			for (i = 0; i <= 5; i++)
				s += this.bldCell(i * 51, k * 51 + (j % 2) * 51 * 3, Math.floor(j / 2) * 51, 8, 10);
		s += "</tr>";
	}
	return s
}

function TCGenerateGray() {
	var s = '';
	for (j = 0; j <= 15; j ++) {
		s += "<tr>";
		for (k = 0; k <= 15; k ++) {
			g = Math.floor((k + j * 16) % 256);
			s += this.bldCell(g, g, g, 9, 7);
		}
		s += '</tr>';
	}
	return s
}

function TCDec2Hex(v) {
	v = v.toString(16);
	for(; v.length < 6; v = '0' + v);
	return v;
}

function TCChgMode(v) {
	for (var k in this.divs) this.hide(k);
	this.show(v);
}

function TColorPicker(field) {
	this.build0 = TCGenerateSafe;
	this.build1 = TCGenerateWind;
	this.build2 = TCGenerateGray;
	this.show = document.layers ? 
		function (div) { this.divs[div].visibility = 'show' } :
		function (div) { this.divs[div].visibility = 'visible' };
	this.hide = document.layers ? 
		function (div) { this.divs[div].visibility = 'hide' } :
		function (div) { this.divs[div].visibility = 'hidden' };
	// event handlers
	this.C       = TCChgMode;
	this.S       = TCSelect;
	this.P       = TCPaint;
	this.popup   = TCPopup;
	this.draw    = TCDraw;
	this.dec2hex = TCDec2Hex;
	this.bldCell = TCBuildCell;
	this.divs = [];
}

function TCDraw(o_win, o_doc) {
	this.win = o_win;
	this.doc = o_doc;
	var 
	s_tag_openT  = o_doc.layers ? 
		'layer visibility=hidden top=54 left=5 width=182' : 
		'div style=visibility:hidden;position:absolute;left:6px;top:54px;width:182px;height:0',
	s_tag_openS  = o_doc.layers ? 'layer top=32 left=6' : 'div',
	s_tag_close  = o_doc.layers ? 'layer' : 'div'
		
	this.doc.write('<' + s_tag_openS + ' id=sam name=sam><table cellpadding=0 cellspacing=0 border=1 width=181 align=center class=bd><tr><td align=center height=18><div id="samp"><font face=Tahoma size=2>sample <font color=white>sample</font></font></div></td></tr></table></' + s_tag_close + '>');
	this.sample = o_doc.layers ? o_doc.layers['sam'] :
		o_doc.getElementById ? o_doc.getElementById('sam').style : o_doc.all['sam'].style

	for (var k = 0; k < 3; k ++) {
		this.doc.write('<' + s_tag_openT + ' id="p' + k + '" name="p' + k + '"><table cellpadding=0 cellspacing=0 border=1 align=center>' + this['build' + k]() + '</table></' + s_tag_close + '>');
		this.divs[k] = o_doc.layers 
			? o_doc.layers['p' + k] : o_doc.all 
				? o_doc.all['p' + k].style : o_doc.getElementById('p' + k).style
	}
	if (!o_doc.layers && o_doc.body.innerHTML) 
		this.o_samp = o_doc.all 
			? o_doc.all.samp : o_doc.getElementById('samp');
	this.C(this.initPalette);
	if (this.field.value) this.P(this.field.value, true)
}




function avaakenkeskel(aadress, ekraaninimi, laius, korgus) {
	vasakult = (window.screen.width/2)-(laius/2);
	ylevalt = (window.screen.height/2)-(korgus/2);
	lisad = "status, height=";
	lisad += korgus;
	lisad += ", width=";
	lisad += laius;
	lisad += ",status=no,menubar=no,resize=no,left=";
	lisad += vasakult;
	lisad += ",top=";
	lisad += ylevalt;
	lisad += ",screenX=";
	lisad += vasakult;
	lisad += ",screenY=";
	lisad += ylevalt;
	lisad += ",scrollbars=yes";

	popupaken = window.open(aadress,ekraaninimi,lisad);
	popupaken.focus();
}

function avaaken(aadress, ekraaninimi, laius, korgus, left, top) {
	lisad = "status, height=";
	lisad += korgus;
	lisad += ", width=";
	lisad += laius;
	lisad += ",status=no,menubar=no,resize=no,left=";
	lisad += left;
	lisad += ",top=";
	lisad += top;
	lisad += ",scrollbars=no";

	popupaken = window.open(aadress,ekraaninimi,lisad);
	popupaken.focus();
}

function Modal(url)
{
                    var myTitle = "This is a custom title";
                    var myText = showModalDialog(url, myTitle, // str or obj specified here can be read from dialog as "window.dialogArguments"
                                                 "resizable: yes; help: no; status: no; scroll: no; ");
}

function RegisterChange(formid)
{
     changedforms[formid] = true;
//     alert(changedforms[formid]);
}

function CheckIsInput(form, url, question)
{
       var chg = changedforms['form_'+form];
//       alert(form + '   '+ changedforms['form_'+form]);
//       return false;
       if (chg != true)
       {
            self.location.href = url;
       }
       else if (confirm(question))
       {
            self.location.href = url;
       }
}

function SetInputClick(id, draw, wtype)
{
     if (document.getElementById(id))
     {
         if (document.getElementById('INPUTVALUE'))
         {
            if (draw == 1)
            {
               var tout = document.getElementById(id).value;
               tout = tout.replace(/(<([^>]+)>)/ig,"");
               var tlen = tout.length;
               if (tlen < 100)
               document.getElementById('INPUTVALUE').innerHTML =  tout;
               else
               {
                   tlen = document.getElementById(id).value.length;
                   document.getElementById('INPUTVALUE').innerHTML = '<i>Long text ('+tlen+' bytes</i>)';
               }
            }
            else
            {

                   if (wtype == 'Select')
                   {
                       document.getElementById('INPUTVALUE').innerHTML = document.getElementById(id).options(document.getElementById(id).selectedIndex).text;
                   }
                   else
                       document.getElementById('INPUTVALUE').innerHTML = '<i>' + wtype + '</i>';
            }
         }
     }
}
