function imposeMaxLength(Object, MaxLen)
{
	return (Object.value.length <= MaxLen);
}

function checkNewPost() {
	if (document.getElementById("post_title").value == "")
	{
		alert("Post title cannot be empty string!");
		return false;
	}

	if (document.getElementById("post_message").value == "")
	{
		alert("Post message cannot be empty string!");
		return false;
	}
	return true;
}

function checkNewTopic() {
	if (document.getElementById("topic_title").value == "")
	{
		alert("Topic title cannot be empty string!");
		return false;
	}

	if (document.getElementById("topic_message").value == "")
	{
		alert("Topic message cannot be empty string!");
		return false;
	}
	return true;
}

function checkNewVote() {
	if (document.getElementById("vote_title").value == "")
	{
		alert("Vote title cannot be empty string!");
		return false;
	}

	if (document.getElementById("vote_question").value == "")
	{
		alert("Vote question cannot be empty string!");
		return false;
	}
	return true;
}

function displayOff(nr){
	if (document.all) 
	{
		document.all[nr].style.display = 'none';
	}
	else if (document.getElementById)
		document.getElementById(nr).style.display = 'none';
}

function displayOn(nr){
	if (document.all)
		document.all[nr].style.display = 'block';
	else if (document.getElementById)
		document.getElementById(nr).style.display = 'block';
}

// the following method inverts the current mode
// i.e. turns displayed to hidden and vice-versa
function displayToggle(nr){
	if (document.all)
		document.all[nr].style.display = (document.all[nr].style.display == 'none') ? 'block' : 'none';
	else if (document.getElementById)
		document.getElementById(nr).style.display = (document.getElementById(nr).style.display == 'none') ? 'block' : 'none';
}

function toggleHighlight(nr,state) {
	if (state == 'on')
		state = 'tblBlueHdr';
	else
		state = 'tblBlueHdr2';
	if (document.all)
		document.all[nr].className = state;
	else if (document.getElementById)
		document.getElementById(nr).className = state;
}

function removeFile(id) {
    id = 'filerow' + id;
    table = document.getElementById('imgfile');
    row = document.getElementById(id);
    table.tBodies[0].removeChild(row);                
}

function addMoreFile(no) {
    table = document.getElementById('imgfile');
    /* remove the row that holds 'Add More Files' */
    table.deleteRow(table.rows.length-1);
    
    /* add another 'upload file' row */
    row = document.createElement("tr");
    row.setAttribute('id', 'filerow' + (no+1));
    cell = document.createElement("td");
    
    var newupload = document.createElement('input');
    newupload.setAttribute('type', 'file');
    newupload.setAttribute('name', 'file' + (no+1));
    newupload.setAttribute('id', 'file' + (no+1));
    newupload.setAttribute('size', '50');
	newupload.className = 'btnfile';
    
    var adddelete = document.createElement('input');
    adddelete.setAttribute('type', 'button');
    adddelete.setAttribute('value', 'remove');
    adddelete.setAttribute('onclick', 'javascript:removeFile(' + (no+1) + ')');
	adddelete.className = 'btnfile';
    
    cell.appendChild(newupload);
    cell.appendChild(document.createTextNode(" "));
    cell.appendChild(adddelete);
    row.appendChild(cell);
	table.tBodies[0].appendChild(row);
	
    /* add 'Add More Files' row again */
    row = document.createElement("tr");
    cell = document.createElement("td");

    var addmore = document.createElement('a');
    addmore.setAttribute('type', 'file');
    addmore.setAttribute('name', 'addmorefile');
    addmore.setAttribute('id', 'addmorefile');
    addmore.setAttribute('href', 'javascript:addMoreFile(' + (no+1) + ')');
    addmore.appendChild(document.createTextNode('Upload More Pictures'));
    
    cell.appendChild(addmore);
    row.appendChild(cell);
	table.tBodies[0].appendChild(row);
}

function tag(myValue) {
    url = '';
    if (myValue == 'IMGLINK') {
        url = prompt('URL Address of the Image?', 'http://');
    } else if (myValue == 'IMG') {
        url = prompt('The file name of the image you\'re uploading? Only .jpg, .gif and .png\nMaximum picture size is 300x300.', '');
    } else if (myValue == 'EMAIL') {
        url = prompt('Email address?', '');
    } else if (myValue == 'URL') {
        url = prompt('Enter a URL address?', 'http://');
    }
    if (url == null) return;

    myValue = '[' + myValue + ']' + url + '[/' + myValue + ']';
    myField = document.getElementById('topic_message');
    if (myField == null)
        myField = document.getElementById('post_message');
    //IE support
    if (document.selection) {
        myField.focus();
        sel = document.selection.createRange();
        sel.text = myValue;
    }
    //MOZILLA/NETSCAPE support
    else if (myField.selectionStart || myField.selectionStart == '0') {
        var startPos = myField.selectionStart;
        var endPos = myField.selectionEnd;
        myField.value = myField.value.substring(0, startPos)
        + myValue
        + myField.value.substring(endPos, myField.value.length);
    } else {
        myField.value += myValue;
    }
}
