function popList(file_types,target)
{
	clearcombo(target);
	//Arrays are generated using php code contained in the
	//doc_manager class.
	
	//Add the array containing the spirostar specsheet
	//to the combo box.
	if(file_types == 'SS')
	{
		cnt = SS_files.length;
		for (var i = 0; i < cnt; i++)
		{
    		addOption = new Option(URLDecode(SS_files[i][0]),SS_files[i][1]);
           	target.options[i] = addOption;
			target.options[i].selected = true;
        }	
	}
	//Add the array containing the flexdrill specsheet
	//to the combo box.
	if(file_types == 'FS')
	{
		cnt = FS_files.length;
		for (var i = 0; i < cnt; i++)
		{
    		addOption = new Option(URLDecode(FS_files[i][0]),FS_files[i][1]);
           	target.options[i] = addOption;
			target.options[i].selected = true;
        }	
	}
	//Add the array containing the Build Rates specsheet
	//to the combo box.
	if(file_types == 'BR')
	{
		cnt = BR_files.length;
		for (var i = 0; i < cnt; i++)
		{
    		addOption = new Option(URLDecode(BR_files[i][0]),BR_files[i][1]);
           	target.options[i] = addOption;
			target.options[i].selected = true;
        }	
	}
}

function selCurrent(id, target)
{
	for(var i=0; i < target.options.length; i++)
	{
		if(target.options[i].value == id) target.options[i].selected = true;
	}
}

function clearcombo(target){
  for (var i= target.options.length-1; i>=0; i--){
    target.options[i] = null;
  }
  target.selectedIndex = -1;
}

function move(f,bDir,sName) {
	 var el = f.elements[sName]
	 var idx = el.selectedIndex
	 if (idx==-1) 
	 	alert("You must first select the item to reorder.")
	
	 else {
		var nxidx = idx+( bDir? -1 : 1)
		if (nxidx<0) nxidx=el.length-1
		if (nxidx>=el.length) nxidx=0
		var oldVal = el[idx].value
		var oldText = el[idx].text
		el[idx].value = el[nxidx].value
		el[idx].text = el[nxidx].text
		el[nxidx].value = oldVal
		el[nxidx].text = oldText
		el.selectedIndex = nxidx
		
	 }
}

function sub(frm)
{
	var nOrder = '';	
	for(var i=0; i < frm.cmbOrder.options.length; i++)
	{
		if(i > 0) nOrder += "**||**";
		nOrder += frm.cmbOrder.options[i].value;	
	}
	frm.order.value = nOrder;		
}

function URLDecode(input)
{
   // Replace + with ' '
   // Replace %xx with equivalent character
   // Put [ERROR] in output if %xx is invalid.
   var HEXCHARS = "0123456789ABCDEFabcdef"; 
   var encoded = input;
   var plaintext = "";
   var i = 0;
   while (i < encoded.length) {
       var ch = encoded.charAt(i);
	   if (ch == "+") {
	       plaintext += " ";
		   i++;
	   } else if (ch == "%") {
			if (i < (encoded.length-2) 
					&& HEXCHARS.indexOf(encoded.charAt(i+1)) != -1 
					&& HEXCHARS.indexOf(encoded.charAt(i+2)) != -1 ) {
				plaintext += unescape( encoded.substr(i,3) );
				i += 3;
			} else {
				alert( 'Bad escape combination near ...' + encoded.substr(i) );
				plaintext += "%[ERROR]";
				i++;
			}
		} else {
		   plaintext += ch;
		   i++;
		}
	} // while
   return plaintext;
}
