
function getSelectedValue(theSelectID){
    var theSelect = FindControl(theSelectID);
	return theSelect.options[theSelect.options.selectedIndex].value;
}

function getSelectedText(theSelect){
   //  var theSelect = FindControl(theSelectID);
	return theSelect.options[theSelect.options.selectedIndex].text;
}

//Returns false is no item is selected or if the value is an empty string
function isSelectedValue(theSelect){
	return (theSelect.options.selectedIndex != -1 && 
		theSelect.options[theSelect.options.selectedIndex].value.length > 0)
}

function PopulateInput(theSelect, theInputClientID){
	var theInput = FindControl(theInputClientID);
	if(theInput == null){
		throw new Error("Control '" + theInputClientID + "' not found.");
	}
	if(isSelectedValue(theSelect)){
		theInput.value = getSelectedText(theSelect);
		theInput.focus();
	}
}

function FindControl(clientID){
	return document.getElementById(clientID);
}

function openPopUp(url,name){
	if (url.indexOf('groupID=G0') == -1) {
		var popup = window.open(url, name, 'width=480, height=400, left=300, top=300, menubar=no, status=no, location=no, toolbar=no, scrollbars=yes, resizable=no');
		popup.focus();
		return false;
	} else {
		alert('This group cannot be edited. It is auto-generated by TextCaster.');
		return false;
	}
}


function CheckSelectedValue(theSelectID){
    var theSelect = FindControl(theSelectID);
	if(isSelectedValue(theSelect)){
		return true;
	} else {
		alert("Please select an item in the list.");
		return false;
	}
}

function insertText(clientID, text){
    var textBox = FindControl(clientID);
    if(textBox.value.charAt(textBox.value.length-1) != ' '){
        text = " " + text;
    }
    textBox.value = textBox.value + text;
}