function writeEmailAddress()
{
    var username = "info";
    var hostname = "scholarselect.com";
    document.write("<a href=" + "mail" + "to:" + username + "@" + hostname + ">" + username + "@" + hostname + "</a>");
}

function hideElement(element_id)
{
    if ($(element_id))
	$(element_id).hide();
}

function updateElement(element_id, new_html) {
    if ($(element_id))
	$(element_id).innerHTML = new_html;	
}

function showElement(element_id)
{
    if ($(element_id))
	$(element_id).show();
}

function toggleElement(element_id)
{
    if ($(element_id))
	$(element_id).toggle();
}

function gotoPage(page)
{
	var elements = $$('div.page'); 
	for(i = 0; i < elements.length; i++)
	{
		hideElement(elements[i].id);
	}
	showElement('page_' + page);
}

function textareaKeyPress(e)
{
    var character = String.fromCharCode(e.keyCode);
    var target = (e.target) ? e.target : e.srcElement;
    if ( character.match(/./) ) {
        updateTextareaCharAndWordCounts(target.id);
    }
}

function updateTextareaCharAndWordCounts(id)
{
    var current_text = $(id);
    var charcount_span = $('char_count_' + id);
    var length = current_text.value.length;
    if ( length == 1 )
        charcount_span.innerHTML = length + " character";
    else
        charcount_span.innerHTML = length + " characters";

    if(Ext.isIE)
	var word_count = current_text.value.split(/\s+/);
    else
	var word_count = current_text.value.split(/\s+\w+/);

    if (word_count == "")
        length = 0;
    else
        length = word_count.length;

    charcount_span.innerHTML += ", " + length + " words";
}

function addTextareaKeypressEvent(id)
{
    $(id).observe('keyup', textareaKeyPress);
    updateTextareaCharAndWordCounts(id);
}
