//---------------------------------------------------------------
// funkcja otwiera okno
//---------------------------------------------------------------
function AF_WindowOpen(url, win_name, width, height, resizeable)
{
	if(resizeable != 1)
		resizeable = 0;

	hWin = window.open(url, win_name, "width="+width+",height="+height+",toolbar=0,scrollbars="+resizeable+",resizeable="+resizeable);
	hWin.focus();
}


function doublemultilist_copyList(fromList, toList) {
  var sel = false;
  for (i=0;i<fromList.options.length;i++) {
    var current = fromList.options[i];
    if (current.selected) {
      sel = true;
      txt = current.text;
      val = current.value;
      toList.options[toList.length] = new Option(txt,val);
      fromList.options[i] = null;
      i--;
    }
  }
}

function clear_roleList(fromList, toList, hiddenField){
 	for (i=0;i<toList.options.length;i=i+1) {
    	var current = toList.options[i];
      	txt = current.text;
      	val = current.value;    	
        fromList.options[fromList.length] =  new Option(txt,val);
    }
    j=toList.options.length
	for(i=0;i<j;i++){
		toList.remove(0);}
    hiddenField.value='';	
}


/*
 * @param object lista z ktorej kopiujemy
 * @param object lista do ktorej kopiujemy
 */
function doublemultilist_getSelectedPositionIdList(chosenList) {
  var chosenIds = new Array();
  for (i=0;i<chosenList.options.length;i++) {
    var current = chosenList.options[i];
    if (current.selected) {
        chosenIds[chosenIds.length] = current.value;
    }
  }
  return chosenIds;
}


/*
 * @param object lista w ktorej zaznaczamy pozycje
 * @param array identyfikatory pozycji do zaznaczenia oddzielone przecinkami
 */
function doublemultilist_selectPositions(chosenList, positions) {
	  var sel = false;
	  for (i=0;i<chosenList.options.length;i++) {
	    var current = chosenList.options[i];
	    current.selected = false;
	  }
	  for (i=0;i<chosenList.options.length;i++) {
	    var current = chosenList.options[i];
	    if (in_array(current.value, positions)) {
	    	current.selected = true;
	    }
	  }
}

function in_array(zmienna, tablica) {
	for (j=0;j<tablica.length;j++) {
		if (tablica[j] == zmienna) {
			return true;
		}
	}
	return false;
}

/*
 * @param object lista z ktorej pobieramy identyfikatory
 * @param object pole do ktorego wprowadzamy wartosci
 */
function doublemultilist_solveHidden(chosenList, hiddenField) {
  var chosenIds = new Array();
  for (i=0;i<chosenList.options.length;i++) {
        chosenIds[chosenIds.length] = chosenList.options[i].value;
  }
  hiddenField.value = chosenIds.join(",");
}


function evalActiveForm() {
	return document.forms[document.forms.length-1];
}


function addToList(nazwa,kod)
{
  var items = document.getElementById('chooseCountry');
  var nazwa2 = nazwa.replace(/_/gi,' ');
  var div = document.getElementById(''+nazwa2+'_'+kod+'');
  var div_button = document.getElementById(''+nazwa2+'__'+kod+'');
  items.options[items.length] =  new Option(nazwa2,kod);
  if(kod=="00")items.disabled = false;
  var ile = div.childNodes.length;
  var ile_button = div_button.childNodes.length;

   div.parentNode.removeChild(div);
   div_button.parentNode.removeChild(div_button);
}

function removeItems()
{
  var items = document.getElementById('chooseCountry');
  var div = document.getElementById('selectedCountry');
  var div_button = document.getElementById('countryButton');
  var children = div.childNodes;
  var ile = children.length;


  while(div.firstChild)
  {
     var nodeId = div.firstChild.id;
     if(nodeId)
     {
       var country = nodeId.split("_");
       items.options[items.length] =  new Option(country[0],country[1]);
     }
     div.removeChild(div.firstChild);
     div_button.removeChild(div_button.firstChild);
  }
}