function toSourceDest(source, destination){
	var source = document.getElementById(source);
	var destination = document.getElementById(destination);
	for (var i = 0; i < source.length; i++) {
	if (source.options[i].selected == true) {
	var option = source.options[i];
	destination.appendChild(option);
	i--; // kuna 1 visati v2lja juba.
	}
	}
}

function fillComboFrom2dArray(array, combo,removeFrom)
{
	   if(!removeFrom){
	   	removeFrom=0;
	   }

	   if(!array){
	   	return null;
	   }

	   for ( var i = combo.options.length; i >= removeFrom; i-- )
	   {
           combo.options[i] = null;
       }

       for ( var i = removeFrom; i < array.length; i++ )
	   {
           if(array[i][1] != ''){
		   	combo.options[combo.options.length] = new Option(array[i][1], array[i][0], false, false);
		   }
       }
}


function kustuta(teade)
{
	var teade2="Kas ikka soovid kustutada?";

	if(teade){
	teade2=teade;
	}

	if (confirm(teade2))
	{
		return true;
	}
	else {
		return false;
	}
}


function tagasta()
{
	if (confirm('Kas ikka soovid tagastada?'))
	{
		return true;
	}
	else {
		return false;
	}
}

function wopen(piccode,name,winwidth,winheight)
{
	winheight=winheight*1;
	winwidth=winwidth*1;
    SW=screen.width;
    SH=screen.height;

    SLeft=5;
    STop=5;

	//window.open('openpic.php?show='+piccode,'test','width='+winwidth,'height='+winheight,'left=5','top=5');

	var mywin=window.open('','','width='+winwidth+',height='+winheight+',left='+SLeft+',top='+STop+',scrolling=no');

	mywin.document.write('<html><head><title>'+name+'</title></head><body rightmargin="0" bottommargin="0" topmargin="0" leftmargin="0"><img src="?showpic='+piccode+'"></body></html>');
}

function wopenfile(filepath,name,winwidth,winheight)
{
	winheight=winheight*1;
	winwidth=winwidth*1;
    SW=screen.width;
    SH=screen.height;

    SLeft=5;
    STop=5;

	//window.open('openpic.php?show='+piccode,'test','width='+winwidth,'height='+winheight,'left=5','top=5');

	var mywin=window.open('','','width='+winwidth+',height='+winheight+',left='+SLeft+',top='+STop+',scrolling=no');

	mywin.document.write('<html><head><title>'+name+'</title></head><body rightmargin="0" bottommargin="0" topmargin="0" leftmargin="0"><img src="'+filepath+'"></body></html>');
}


function mywindow(filepath,title,winwidth,winheight)
{
	winheight=winheight*1;
	winwidth=winwidth*1;
    SW=screen.width;
    SH=screen.height;

    SLeft=5;
    STop=5;

	//window.open('openpic.php?show='+piccode,'test','width='+winwidth,'height='+winheight,'left=5','top=5');

	window.open(filepath,title,'width='+winwidth+',height='+winheight+',left='+SLeft+',top='+STop+',scrolling=yes');

	//mywin.document.write(''+filepath+'');
}

function lahkus()
{
	if (confirm('Kas oled kindel?'))
	{
		return true;
	}
	else {
		return false;
	}
}


function makeTableRows(table_id)
{
   var oTBody = document.getElementById(table_id).getElementsByTagName("TBODY").item(0);
   var element = document.getElementById(table_id).rows[1].cells[0].innerHTML;
   // Note: we subtract one from the row count to
   // account for the header row.
   var intLoop = document.getElementById(table_id).rows.length - 1;
   var bResult = AddRow(oTBody, element);
}

function AddRow(oTBody, element)
{
 	  var oCell;
  	  var oRow;
      oRow = document.createElement("TR");
      oTBody.appendChild(oRow);

      oCell = document.createElement("TD");
      oCell.innerHTML = element;
      oCell.align = 'center';
	  oRow.appendChild(oCell);

	  oCell = document.createElement("TD");
      oCell.innerHTML = element;
	  oCell.align = 'center';
      oRow.appendChild(oCell);

	  oCell = document.createElement("TD");
      oCell.innerHTML = element;
      oCell.align = 'center';
	  oRow.appendChild(oCell);
}


function KillRow(rowid, tableid) {
		  var oTBody = document.getElementById(tableid).getElementsByTagName("TBODY").item(0);
		  oTBody.removeChild(document.getElementById(rowid));
}



function passStatus(status)
{
if(status == true)//pass genereeritakse automaatselt
{
document.getElementById('domain[newpass]').disabled = true;
document.getElementById('domain[newpass]').style.backgroundColor="#F3F3F3";
} else {
document.getElementById('domain[newpass]').disabled = false;
document.getElementById('domain[newpass]').style.backgroundColor="#FFFFFF";
}
}

function checkDomainForm()
{
if(document.getElementById('domain[newpass]').value || document.getElementById('domain[genpass]').checked == true){
return true;
} else {
return warnInvalid(document.getElementById('domain[newpass]'), "Üks valikutest peab olema määratud");
}
}

function IsNumeric(strString)
   {
   var strValidChars = "0123456789";
   var strChar;
   var blnResult = true;

   if (strString.length == 0) return false;

   for (i = 0; i < strString.length && blnResult == true; i++)
      {
      strChar = strString.charAt(i);
      if (strValidChars.indexOf(strChar) == -1)
         {
         blnResult = false;
         }
      }
   return blnResult;
   }


function isEmpty(s) {
	return ((s == null) || (s.length == 0));
}



function explodeArray(item,delimiter) {
//teeb CSL-ist array, sisendiks on csl ning eraldaja mille järgi eraldatakse

  tempArray=new Array(1);
  var Count=0;
  var tempString=new String(item);

  while (tempString.indexOf(delimiter)>0) {
    tempArray[Count]=tempString.substr(0,tempString.indexOf(delimiter));
    tempString=tempString.substr(tempString.indexOf(delimiter)+1,tempString.length-tempString.indexOf(delimiter)+1);
    Count=Count+1
  }

  tempArray[Count]=tempString;
  return tempArray;
}


/*==================================================*
 $Id: filterlist.js,v 1.3 2003/10/08 17:13:49 pat Exp $
 Copyright 2003 Patrick Fitzgerald
 http://www.barelyfitz.com/webdesign/articles/filterlist/

 This program is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 the Free Software Foundation; either version 2 of the License, or
 (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 *==================================================*/

function filterlist(selectobj) {

  //==================================================
  // PARAMETERS
  //==================================================

  // HTML SELECT object
  // For example, set this to document.myform.myselect
  this.selectobj = selectobj;

  // Flags for regexp matching.
  // "i" = ignore case; "" = do not ignore case
  // You can use the set_ignore_case() method to set this
  this.flags = 'i';

  // Which parts of the select list do you want to match?
  this.match_text = true;
  this.match_value = false;

  // You can set the hook variable to a function that
  // is called whenever the select list is filtered.
  // For example:
  // myfilterlist.hook = function() { }

  // Flag for debug alerts
  // Set to true if you are having problems.
  this.show_debug = false;

  //==================================================
  // METHODS
  //==================================================

  //--------------------------------------------------
  this.init = function() {
    // This method initilizes the object.
    // This method is called automatically when you create the object.
    // You should call this again if you alter the selectobj parameter.

    if (!this.selectobj) return this.debug('selectobj not defined');
    if (!this.selectobj.options) return this.debug('selectobj.options not defined');

    // Make a copy of the select list options array
    this.backupselect = this.selectobj.cloneNode(true);
  }

  //--------------------------------------------------
  this.reset = function() {
    // This method resets the select list to the original state.
    // It also unselects all of the options.

    this.set('');
  }


  //--------------------------------------------------
  this.set = function(pattern) {

    // This method removes all of the options from the select list,
    // then adds only the options that match the pattern regexp.
    // It also unselects all of the options.

    var loop=0, index=0, regexp, e;

    if (!this.selectobj) return this.debug('selectobj not defined');
    if (!this.selectobj.options) return this.debug('selectobj.options not defined');

    // Clear the select list so nothing is displayed
    //this.selectobj.options.length = 0;
    var len = this.selectobj.childNodes.length-1;
    for (var i=len; i>=0; i--){
        this.selectobj.removeChild(this.selectobj.childNodes.item(i));
    }

    // Set up the regular expression.
    // If there is an error in the regexp,
    // then return without selecting any items.
    try {

      // Initialize the regexp
      regexp = new RegExp(pattern, this.flags);

    } catch(e) {

      // There was an error creating the regexp.

      // If the user specified a function hook,
      // call it now, then return
      if (typeof this.hook == 'function') {
        this.hook();
      }

      return;
    }

    //muudatus optgruppide pärast et kui valik on tühi tuleks kogu select uuesti ära täita
    if(pattern == ""){
		  var len = this.backupselect.childNodes.length;
          for (var i=0; i<len; i++){
            this.selectobj.appendChild(this.backupselect.childNodes.item(i).cloneNode(true));
		  }
        return;
    }


    var len = this.backupselect.childNodes.length;
    for (var i=0; i<len; i++){

        if(this.backupselect.childNodes.item(i).nodeName == 'OPTGROUP'){
           var optlen = this.backupselect.childNodes.item(i).childNodes.length;

           var subcount=0;
           for (var j=0; j<optlen; j++){
            var tmpopt = this.backupselect.childNodes.item(i).childNodes.item(j);

            if ((this.match_text && regexp.test(tmpopt.text)) ||
              (this.match_value && regexp.test(tmpopt.value))) {
               if(subcount == 0){
                 var optgroup = this.backupselect.childNodes.item(i).cloneNode(false);
                 this.selectobj.appendChild(optgroup);
               }
               subcount++;
               optgroup.appendChild(tmpopt.cloneNode(true));
            }
           }
        } else {
            if ((this.match_text && regexp.test(this.backupselect.childNodes.item(i).text)) ||
              (this.match_value && regexp.test(this.backupselect.childNodes.item(i).value))) {
               this.selectobj.appendChild(this.backupselect.childNodes.item(i).cloneNode(true));
            }
        }
	}

    // If the user specified a function hook,
    // call it now
    if (typeof this.hook == 'function') {
      this.hook();
    }

  }


  //--------------------------------------------------
  this.set_ignore_case = function(value) {
    // This method sets the regexp flags.
    // If value is true, sets the flags to "i".
    // If value is false, sets the flags to "".

    if (value) {
      this.flags = 'i';
    } else {
      this.flags = '';
    }
  }


  //--------------------------------------------------
  this.debug = function(msg) {
    if (this.show_debug) {
      alert('FilterList: ' + msg);
    }
  }


  //==================================================
  // Initialize the object
  //==================================================
  this.init();

}