// GSK 5/7/02 - Users click item in select utilities box for their choices

function MoveOver(){
var boxLength  = document.thisform.lstSelected.length;
var selectedItem = document.thisform.lstUtil.selectedIndex;
var selectedText = document.thisform.lstUtil.options[selectedItem].text;
var selectedValue = document.thisform.lstUtil.options[selectedItem].value;
var i;
var isNew = true;
var thisItem = "";
		
	/* GSK 5/7/02 
	   Cleanup initial placeholder. Netscape older than 6 will not expand the list box
	   if empty, need the placeholder the first time 
	*/
	
	if (boxLength == 1){
		if (document.thisform.lstSelected.options[0].value == "none"){
			document.thisform.lstSelected.options[0] = null;
		}
	}
	
	boxLength = document.thisform.lstSelected.length;
	
	if (boxLength == 10){
		window.alert ("You can select only 10 utilities. Your limit has reached.");
		isNew = false;
		return false;
	}
	
	if (boxLength != 0) {
		for (i = 0; i < boxLength; i++){
			thisItem = document.thisform.lstSelected.options[i].text;
			if (thisItem == selectedText){
				isNew = false;
				break;
			}
		}
	}
	
	if (isNew) {
		newoption = new Option(selectedText, selectedValue, false, false);
		document.thisform.lstSelected.options[boxLength] = newoption;
	}
	document.thisform.lstSelected.selectedIndex = -1;
	document.thisform.lstUtil.selectedIndex = -1;

}



// GSK - Users click the selected box to remove the selected item 
function RemoveBack(){
var boxLength = document.thisform.lstSelected.length;
arrSelected = new Array();
var count = 0;
var i;
var x;
		
	for (i = 0; i < boxLength; i++) {
		if (document.thisform.lstSelected.options[i].selected){
			arrSelected[count] = document.thisform.lstSelected.options[i].value;
		}
		count++;
	}
	for (i = 0; i < boxLength; i++) {
		for (x = 0; x < arrSelected.length; x++){
			if (document.thisform.lstSelected.options[i].value == arrSelected[x]){
				document.thisform.lstSelected.options[i] = null;
			}
		}
	boxLength = document.thisform.lstSelected.length;
	}	
}

function lstUtil_onblur() {
var intIndex;
var strText = "";
var strValue = "";
var intSize;

	intSize = document.thisform.lstUtil.length;
	//thisform.lstUtil.options
	for (intIndex = 0; intIndex < intSize; intIndex++){
		if (document.thisform.lstUtil.options[intIndex].selected){
			if (strText == ""){
				strText = document.thisform.lstUtil.options[intIndex].text;
				strValue = document.thisform.lstUtil.options[intIndex].value;				
			}
			else{
				strText = strText + ", " + document.thisform.lstUtil.options[intIndex].text;
				strValue = strValue + ", " + document.thisform.lstUtil.options[intIndex].value;
			}				
		}
	}
	document.thisform.util_name.value = strText;
	document.thisform.util_id.value = strValue;
}


function lstMonth_onblur() {
var intIndex;
var strText = "";
var strValue = "";
var intSize;
	
	intSize = document.thisform.lstMonth.length;
	//thisform.lstMonth.options
	
	for (intIndex = 0; intIndex < intSize; intIndex++){
		if (document.thisform.lstMonth.options[intIndex].selected){
			if (strText == ""){
				strText = document.thisform.lstMonth.options[intIndex].text;
				strValue = document.thisform.lstMonth.options[intIndex].value;
			}
			else{
				strText = strText + "," + document.thisform.lstMonth.options[intIndex].text;
				strValue = strValue + "," + document.thisform.lstMonth.options[intIndex].value;
			}				
		}
	}	
	document.thisform.month_name.value = strText;
	document.thisform.month_id.value = strValue;
}


function lstYear_onblur() {
var intIndex;
var strText = "";
var strValue = "";
var intSize;
	
	intSize = document.thisform.lstYear.length;
	//thisform.lstMonth.options
	
	for (intIndex = 0; intIndex < intSize; intIndex++){
		if (document.thisform.lstYear.options[intIndex].selected){
			if (strText == ""){
				strText = document.thisform.lstYear.options[intIndex].text;
				strValue = document.thisform.lstYear.options[intIndex].value;
			}
			else{
				strText = strText + "," + document.thisform.lstYear.options[intIndex].text;
				strValue = strValue + "," + document.thisform.lstYear.options[intIndex].value;
			}				
		}
	}	
	document.thisform.year_id.value = strValue;
}


// GSK - Reset all the fields back to default
function ResetIt(){

	var boxLength = document.thisform.lstSelected.length;
	var i;
	// Reset Selected box
	for (i = boxLength; i >= 0; i--){
		document.thisform.lstSelected.options[i] = null;
	}
	newoption = new Option("----------   [NONE CURRENTLY SELECTED]   ----------", "none", false, false);
	document.thisform.lstSelected.options[0] = newoption;
		
	// Reset other boxes (list box set to 0 and then -1 go top list)
	document.thisform.optChart[0].checked = true;
	document.thisform.lstUtil.selectedIndex = 0;
	document.thisform.lstUtil.selectedIndex = -1;
	document.thisform.lstMonth.selectedIndex = 0;
	document.thisform.lstYear.selectedIndex = 0;	
	document.thisform.util_id.value = "";
	document.thisform.util_name.value = "";
	document.thisform.month_id.value = "";
	document.thisform.month_name.value = "";
	document.thisform.year_id.value = "";
}


// GSK - User pressed the submit button
function thisform_onsubmit() {
var strValue = "";
var strText = "";
var boxLength;	// = document.thisform.lstSelected.length;
var count = 0;
var i;

	/* GSK 5/7/02 
	   Cleanup initial placeholder. Netscape older than 6 will not expand the list box
	   if empty, need the placeholder the first time 
	*/
	
	if (document.thisform.lstSelected.options[0].value == "none")
	{
		window.alert ("You have not made any selections to specify utility");
		return false;
	}
	boxLength = document.thisform.lstSelected.length;
	
	if (boxLength != 0)
	{
		for (i = 0; i < boxLength; i++)
		{
			if (count == 0)
			{
				strValue = document.thisform.lstSelected.options[i].value;
				strText = document.thisform.lstSelected.options[i].text;
			}
			else 
			{
				strValue = strValue + "," + document.thisform.lstSelected.options[i].value;
				strText = strText + "," + document.thisform.lstSelected.options[i].text;
			}
		count++;
		} 
	}
	
	if (strValue.length == 0)
	{
		window.alert ("You have not made any selections to specify utility");
		return false;
	}
	else
	{
		document.thisform.util_id.value = strValue;
		document.thisform.util_name.value = strText;
		document.thisform.submit();
		return true;
	}
}
