// CH2DD.JS - Rubes
 
// double drop down LISTBOX -----------------------------
var intitem2select = 0
function ch2DD( xSource, xTarget, xMatrix){
 var xList;
 var pos,n,m,i;
 var id,naziv;
 var x_opt;
 var intindex2select = 0;
 xTarget.selectedIndex = 0;
 xTarget.options.length = 0;

if (xSource.selectedIndex > 0){
   xList = xMatrix[xSource.options[xSource.selectedIndex].value];
   if (xList!=null) {
     pos = 0;
     i = 1;
	 n = xList.indexOf(';',pos);

     while (n > 0) {
       m = xList.indexOf(',',pos);
       id = xList.substr(pos, m-pos);
       naziv = xList.substr(m+1,n-m-1);
	   x_opt = new Option( naziv, id);
	   if(parseInt(id, 10) == intitem2select) intindex2select = i;
       i++;
	   xTarget.options[xTarget.options.length] = x_opt;
       pos = n + 1;
       n = xList.indexOf(';',pos);
     }
   }
   xTarget.selectedIndex = intindex2select;
   xTarget.focus();
}else{xTarget.options[0] =new Option( "...", "");xSource.focus();}
};

function ch2DD_ini( xSource, xTarget, xMatrix,vs){
 var pos,n,m,ii;
 var id,naziv;
 var x_opt;
 var c_1=0;
 var c_2=0;
 var c_go=true;
 var go_1=0;
 var go_2=0;

for (i=0;i<xMatrix.length;i++){
	if ((xMatrix[i]!=null)&&(c_go)){
        c_1++;
	     pos = 0;
    	 ii = 1;
		 n = xMatrix[i].indexOf(';',pos);
    	 while (n > 0) {
		   m = xMatrix[i].indexOf(',',pos);
		   id = xMatrix[i].substr(pos, m-pos);
		   naziv = xMatrix[i].substr(m+1,n-m-1);
		   if(parseInt(id, 10) == vs){
			   go_1=c_1;
			   go_2=ii-1;
			   c_go=false;
	       }
    	   ii++;
	       pos = n + 1;
		   n = xMatrix[i].indexOf(';',pos);
	     }
	}
}
xSource.selectedIndex=go_1;
ch2DD(xSource, xTarget, xMatrix)
xTarget.selectedIndex=go_2;
}

