/*
Copyright 2007 XOMBO, other contributors
This file is part of XOMBO.ORG Platform.

XOMBO.ORG Platform is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

XOMBO.ORG Platform is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with XOMBO.ORG Platform.  If not, see <http://www.gnu.org/licenses/>.
*/

/* For selecting all checkboxes in a tabular form */
function selectAll (formRef, value) {
	var e = formRef.elements;
	for ( var elem, i = 0; ( elem = e[i] ); i++ ) {
		if ( elem.type == 'checkbox' ) elem.checked = value;
	}
}

/* For setting a class for input text fields to make IE & FF consistent - CSS purposes */
function setClass(){
	try{
	var theinputs = document.getElementsByTagName("input");
	var i;
	for(i = 0; i < theinputs.length; i++)
	{
		if(theinputs[i].type == "text" || theinputs[i].type == "password")
		{
			theinputs[i].className = 'textField';
		}
	}
	}catch(e){}
}
window.onload = setClass;

/* For tabbing in textareas */
function HandleTabKeyDown(obj,evt) {
	try{
	var tabKeyCode = 9;
	var ieChar = evt.keyCode;
	var mozChar = evt.which;
	
	if(mozChar != null) { // Mozilla-compatible browser
		if(mozChar  == tabKeyCode) {
            var s = obj.selectionStart;
            var e = obj.selectionEnd;
            obj.value = obj.value.substring(0, s) + "\t" + obj.value.substr(e);
            obj.setSelectionRange(s + 1, s + 1);
            obj.focus();		
            return false;	
		}
	}else { // IE-compatible Browser
		if(ieChar == tabKeyCode) {
		      obj.selection = document.selection.createRange();
		      obj.selection.text = String.fromCharCode(tabKeyCode);
		      return false;
		}
	}
	}catch(e){}
	return true;
}

