/* 
Web-Innova select field scripts
Copyright 2006 - Web-Innova, LLC
select_field.js
10/2006
*/

//<!--
function initialize(first,area,field) {
	var NewExpertise = "";
	var ExpLength = 0;
	
	document.getElementById(area).style.display = 'block';
			
}

function get_sizer() {
	return new Option("-----------------------------------","null");
}
		
function update_object_list(theForm) {
	//Get the original length of the object pulldown
	origItemCount = theForm.object_list.options.length;
			
	//Set pindex to the selected value of the class pulldown
	pindex = theForm.class_list.options[theForm.class_list.options.selectedIndex].value;
	itemCount = object_array[pindex].length;
						
	//Add new items to the object pulldown
	for(var i = 0; i < itemCount; i++)	{
		theForm.object_list.options[i] = new Option(object_array[pindex][i].text, object_array[pindex][i].value);
	}
			
	//Add sizer item			
	theForm.object_list.options[i] = get_sizer();
			
	//Remove excess old items from the object pulldown
	for(var i = itemCount + 1; i < origItemCount; i++)	{
		theForm.object_list.options[itemCount] = null;
	}
			
	//document.forms[0].object_list.options[0].selected = true;
	theForm.object_list.options[0].selected = true;
}
		
function copy_item(theForm,theField) {
	//Get the selected value and text of the object pulldown
	item_value = theForm.object_list.options[theForm.object_list.options.selectedIndex].value;
						
	//Check for dupe first
	for(var i = 0; i < theForm[theField].options.length - 1; i++)	{
		if(theForm[theField].options[i].value == item_value)	{
			alert("You have already selected that option.");
			return false;
		}			
	}
		
	item_text = theForm.object_list.options[theForm.object_list.options.selectedIndex].text;
			
	//Error check: User can not copy value of "null"
	if (item_value == "null") { alert("Sorry, not a valid selection.  Please choose one of the other options."); return; }
			
	//Error check: User can only copy up to seven objects
	//if (theForm.user_list.options.length > 7) { alert("Sorry, you can only list up to 7 areas of expertise."); return; }
			
	last_index = theForm[theField].options.length - 1;
			
	//Set the last item, the sizer, to null
	theForm[theField].options[last_index] = null;
			
	//Add the object, and the sizer, to the user's list
	theForm[theField].options[last_index] = new Option(item_text,item_value);
	theForm[theField].options[++last_index] = get_sizer();
			
	theForm[theField].options[0].selected = true;
}
		
function remove_user_item(theForm,theField) {
	
	//Error check: User can not remove value of "null"
	if (theForm[theField].options[theForm[theField].options.selectedIndex].value == "null") { 
		alert("Sorry, not a valid selection"); return; }
		
		var theValue = theForm[theField].options[theForm[theField].options.selectedIndex].value;
		var theIndex = theForm[theField].options.selectedIndex
		//var theText = theForm.user_list.options[theForm.user_list.options.selectedIndex].text;
	
		theForm[theField].options[theIndex] = null;
		theForm[theField].options[0].selected = true;
		
}
		
function set_multiT(theForm,theField,endField) {
	//theForm[endField].value = "";
	
	/*for(var i = 0; i < theForm[theField].options.length - 1; i++)	{
		if (theForm[endField].value != "") {
			theForm[endField].value = theForm[endField].value + ", " + theForm[theField].options[i].value;
		} else {
			theForm[endField].value = theForm[endField].value + " " + theForm[theField].options[i].value;
		}
	}*/
	field = document[theForm][theField];
	for(var i = 0; i < field.options.length - 1; i++)	{
		if (field.value != "") {
			field.value = field.value + ", " + field.options[i].value;
		} else {
			field.value = field.value + " " + field.options[i].value;
		}
	}
}
	
function set_multi(theForm,theField,endField) {
	theForm[endField].value = "";
	
	for(var i = 0; i < theForm[theField].options.length - 1; i++)	{
		if (theForm[endField].value != "") {
			theForm[endField].value = theForm[endField].value + ", " + theForm[theField].options[i].value;
		} else {
			theForm[endField].value = theForm[endField].value + " " + theForm[theField].options[i].value;
		}
	}
}
	//-->

