﻿// -------------------------------------------------------------
//
// FILENAME		: functions.js
// COPYRIGHT	: © 2003 - 2008 Espen Andersson
// WWW			: http://ebascripts.com/
//
// -------------------------------------------------------------

function increment_rows(id, incr) {
	minVal = 7;

	if(!incr) {
		incr = 3;
	}

	elem = document.getElementById(id);

	if( (elem.rows + incr) >= minVal) {
		elem.rows += incr;
	}
}

function getSel(field) {
	if (document.selection) {
		return document.selection.createRange().text;
	}

	if (field.selectionStart || field.selectionStart == 0) {
		return field.value.substring(field.selectionStart, field.selectionEnd);
	}

	return '';
}

function replaceSel(field, txt) {
	if (document.selection) {
		field.focus();
		document.selection.createRange().text = txt;
	} else if (field.selectionStart || field.selectionStart == 0) {
		field.value = field.value.substring(0, field.selectionStart) + txt
		+ field.value.substring(field.selectionEnd, field.value.length);
	} else {
		field.value += txt;
	}

	field.focus();
}

function attributeTag(fieldId, tag) {
	field = document.getElementById(fieldId);
	selection = getSel(field);
	replaceSel(field, '[' + tag + '=' + selection + ']' + selection + '[/' + tag + ']');
}

function addtag(fieldId, tag) {
	field = document.getElementById(fieldId);
	selection = getSel(field);
	replaceSel(field, '[' + tag + ']' + selection + '[/' + tag + ']');
}

function insert(fieldId, txt) {
	field = document.getElementById(fieldId);
	replaceSel(field, txt);
}

// Thanks to H1rik_L
function allClick(ch) {
	var ref = document.getElementById('MsgList').getElementsByTagName('input');

	for(var i = 0; ref.length > i; i++) {
		ref.item(i).checked = ch;
	}
}

// Thanks to H1rik_L
function disablesubmitbutton() {
	var ref = document.getElementById('MsgList').getElementsByTagName('input');

	for(var i = 0; ref.length > i; i++) {
		if(ref.item(i).checked) {
			document.getElementById('delete_selected_items').disabled = false;
			return;
		}
	}

	document.getElementById('delete_selected_items').disabled = true;
}

/*
function changeable(elem, state) {
	for(var i = 0; i < elem.length; i++) {
		if ( (state) && (elem.item(i).value != 'moderate') && (html_links == 0) ) {
			elem.item(i).disabled = state;
		} else {
			elem.item(i).disabled = state;
		}
	}
}

function enable_current_pwd() {
	var current_pwd = document.getElementById('current_pwd').value;
	var new_pwd = document.getElementById('new_pwd');

	if (current_pwd.length > 0) {
		new_pwd.disabled = false;
	}
}
*/