function updateCharCount()
{
    maxCharacters = 115;
    count = questionTextBox.value.length;
    document.getElementById("characterCount").innerHTML = maxCharacters - count;
	
    if (count >= maxCharacters)
    {
        questionTextBox.value = questionTextBox.value.substring(0, maxCharacters - 1);
    }
}

function submitenter(myfield,e,button)
{
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else
		if (e) keycode = e.which;
	else 
		return true;

	if (keycode == 13)
	{
		button.click();
		return false;
	}
	else
		return true;
}

function dontsubmitenter(myfield,e)
{
	var keycode;
	if (window.event)
		keycode = window.event.keyCode;
	else
		if (e) keycode = e.which;
	else 
		return true;

	if (keycode == 13)
	{
		return false;
	}
	else
		return true;
}

function focusTextarea()
{
    var questionHelp = document.getElementById("questionHelp");
    
    questionHelp.style.display = 'none';
    questionTextBox.style.display = '';
    questionTextBox.value = '';
    questionTextBox.focus();
}

function SelectValueSet(SelectName, Value)
{
    var SelectObject = document.getElementById(SelectName);

    for(index = 0; index < SelectObject.length; index++)
    {
        if (SelectObject[index].value == Value)
        {
            SelectObject.selectedIndex = index;
        }
    }
}

var WindowObjectReferenceOfRequestedPopup, WindowObjectReferenceOfIntermediaryPopup;

function OpenRequestedPopup(strUrl, strTarget)
{
    var windowWidth, windowHeight, windowLeft, windowTop;

    windowWidth = 1020;
    windowHeight = 550;
    windowLeft = 60;
    windowTop = 40;

    /* The above code is just to define reasonable sizes and initial positions to the popup to be. */

    if (WindowObjectReferenceOfRequestedPopup == null || WindowObjectReferenceOfRequestedPopup.closed)
    {
        WindowObjectReferenceOfRequestedPopup = window.open(strUrl, strTarget, "top=" + windowTop + ",left=" + windowLeft + ",width=" + windowWidth + ",height=" + windowHeight + ",menubar,toolbar,location,resizable,scrollbars,status");
    }
    else
    {
        if(WindowObjectReferenceOfRequestedPopup.focus)
        {
        WindowObjectReferenceOfRequestedPopup.focus();
        };
    };

    /*
    The above 9 lines of code creates the popup; if the popup is already opened, then it is only brought on top. This feature is possible only if the user allows it via the setting Edit/Preferences.../category:Advanced/Scripts & Plugins/Allow webpages to:/Raise or lower windows
    */
}

function trim(s) {
    return s.replace(/^\s*/, "").replace(/[>]*$/, "").replace(/\s*$/, "");
}
