/*
 *
 * TCBDB 2.0 - 2006
 * JavaScript Code.
 *
*/


// listToPage Function
function listRedirectToPage(list){
	
	var cList = document.getElementById(list);
	var cValue = cList.options[cList.selectedIndex].value;
	
	if (cValue != 0){
	  
	  location.href = cValue;
	  
	}else{
	  
	  alert("Redirection not implemented...");
	
	}
	
}



function confirmDelete(title, path){
	
			if (confirm(title)){
		
					window.location.href=path;
		
  		}
   		
}

function transfertItem(pFromList, pToList, pAssignedList,pSelectedItems){
	
	var fromList = document.getElementById(pFromList);
	var toList = document.getElementById(pToList);
	
	var newOption;
	var sizeList = fromList.options.length;
	
	for (i=0; i < sizeList; i++) { 
		
		if (fromList.options[i].selected){
			
			newOption = document.createElement("option");
			toList.options.add(newOption);
			newOption.innerText = fromList.options[i].text;
			newOption.value = fromList.options[i].value;
			
		}
		
	
	}
	
	for (i=(sizeList-1); i >= 0; i--){ if (fromList.options[i].selected) fromList.remove(i); }
	
	var assignedList = document.getElementById(pAssignedList)
	sizeList = assignedList.options.length;
	var itemList = "";
	for (i=0; i < sizeList; i++) { 
		if(itemList == ""){
			itemList = "" + assignedList.options[i].value + "";
		}else{
			itemList = itemList + ", " + assignedList.options[i].value + "";
		}
	}
	if(itemList != ""){
		itemList = itemList + ""
	}
	var selectCost = document.getElementById(pSelectedItems);
	selectCost.value = itemList;
	//alert(selectCost.Value);
}

function transfertItemWithHiddenField(pFromList, pToList, passignedList, pSelectedItems){
	var fromList = document.getElementById(pFromList);
	var toList = document.getElementById(pToList);
	var newOption;
	var sizeList = fromList.options.length;
	//adding the selected elements of the fromList to the toList
	for (i=0; i < sizeList; i++) { 
		
		if (fromList.options[i].selected){
			newOption = document.createElement("option");
			toList.options.add(newOption);
			newOption.innerText = fromList.options[i].text;
			newOption.value = fromList.options[i].value;
		}
	
	}
	//Removing the selected element from the fromList
	for (i=(sizeList-1); i >= 0; i--){ if (fromList.options[i].selected) fromList.remove(i); }
	//building the list of comma separeted Ids from the assigned list
	var assignedList = document.getElementById(passignedList)
	sizeList = assignedList.options.length;
	var itemList = "";
	for (i=0; i < sizeList; i++) { 
		if(itemList == ""){
			itemList = "" + assignedList.options[i].value + "";
		}else{
			itemList = itemList + ", " + assignedList.options[i].value + "";
		}
	}
	if(itemList != ""){
		itemList = itemList + ""
	}
	//Assigning the Ids to a hidden field for example. 
	var selectCost = document.getElementById(pSelectedItems);
	selectCost.value = itemList;
	//alert(selectCost.value);
}



function tsaPopup(path, width, height){
	
	var tsaP;
	
	settings = 'menubar=no,status=yes,toolbar=no,directories=no,location=no,resizable=yes,scrollbars=yes,width='+width+',height='+height+',left=20,top=20';	
	
	if ((!tsaP)|| (tsaP.closed)){ tsaP = window.open(path,"tsaPopup",settings); }
		
	tsaP.focus();
		
	return tsaP;
		
}