function twdCount(field,cntfield,maxlimit) {
if (field.value.length > maxlimit)
field.value = field.value.substring(0, maxlimit);
else
cntfield.value = maxlimit - field.value.length;
}

function countNoticeBoard() {
	twdCount(document.getElementById('new-noticeboard-entry'),document.getElementById('twd1'),160)
}

function countDescription() {
	twdCount(document.getElementById('my-description'),document.getElementById('twd1'),6000)
}

function countLookingfor() {
	twdCount(document.getElementById('looking-for-other-text'),document.getElementById('twd1'),255)
}

function initGuestbook() {
	document.getElementById('new-guestbook-entry').focus();
}

function initInvitation() {
	document.getElementById('invite-address').focus();
}

function initCompose() {
	document.getElementById('to-name').focus();
}

function initComposeProfile() {
	document.getElementById('message-subject').focus();
}

function initLookingfor() {
	twdCount(document.getElementById('looking-for-other-text'),document.getElementById('twd1'),255)
}

function initNoticeBoard() {
	document.getElementById('new-noticeboard-entry').focus();
	twdCount(document.getElementById('new-noticeboard-entry'),document.getElementById('twd1'),160)
}

function initDescription() {
	document.getElementById('my-description').focus();
	twdCount(document.getElementById('my-description'),document.getElementById('twd1'),6000)
}

function initReply() {
	setCursorPosition(document.getElementById('message-body'),0,0)
}

function initSearch() {
	document.getElementById('search-text').focus();
}


function setCursorPosition(oInput,oStart,oEnd) {
    oInput.focus();
    if( oInput.setSelectionRange ) {
        oInput.setSelectionRange(oStart,oEnd);
    } else if( oInput.createTextRange ) {
        var range = oInput.createTextRange();
        range.collapse(true);
        range.moveEnd('character',oEnd);
        range.moveStart('character',oStart);
        range.select();
    }
}


function ToggleAll(selected)
{
	elements = document.getElementsByName('id');
	for (i=0; i < elements.length; i++)
	{
		elements[i].checked = selected;
	}
	elements = document.getElementsByName('selectAll');
	for (i=0; i < elements.length; i++)
	{
		elements[i].checked = selected;
	}
}