var Event = {
	add: function(obj,type,fn) {
		if (obj.attachEvent) {
			obj['e'+type+fn] = fn;
			obj[type+fn] = function() { obj['e'+type+fn](window.event); }
			obj.attachEvent('on'+type,obj[type+fn]);
		} else
			obj.addEventListener(type,fn,false);
	},
	remove: function(obj,type,fn) {
		if (obj.detachEvent) {
			obj.detachEvent('on'+type,obj[type+fn]);
			obj[type+fn] = null;
		} else
			obj.removeEventListener(type,fn,false);
	}
}

function GetElementByID ( vElement ) {
	var vRetVal=vElement;
	if ( typeof ( vElement ) == 'string' ) {
		if ( document.getElementById )
			vRetVal=document.getElementById ( vElement );
		else if ( document.all )
			vRetVal=document.all [ vElement ];
		else
			vRetVal=null;
	}
	return vRetVal;
}

function GetIFRAMEDocumentByID ( vIFRAME ) {
	var oIFRAME=GetElementByID(vIFRAME), vRetVal;
	if ( oIFRAME.contentDocument ) { // DOM
	    vRetVal=oIFRAME.contentDocument;
	} else if ( oIFRAME.contentWindow ) { // IE win
	    vRetVal=oIFRAME.contentWindow.document;
	} else
		vRetVal=null;
	return vRetVal;
}

function expand_collapse_group ( tID ) {
	var i=1;
	while ( GetElementByID ( tID + '_' + i )) {
		expand_collapse ( tID + '_' + i );
		i ++;
	}
}

function expand_collapse_subgroup ( tID, nSubRow, tSuffix ) {
	var i=nSubRow;
	while ( GetElementByID ( tID + '_' + i + '_' + tSuffix )) {
		expand_collapse ( tID + '_' + i + '_' + tSuffix );
		i ++;
	}
}

function expand_collapse ( tID ) {
	if ( GetElementByID(tID).style.display == 'none' )
		GetElementByID(tID).style.display='';
	else
		GetElementByID(tID).style.display='none';
}

function add_row_to_table ( tTableID, nInsertAtRow ) {
	var oTable = GetElementByID(tTableID);
	
	if ( typeof nInsertAtRow == 'undefined' )
		var nInsertAtRow=oTable.rows.length;
	
	return ( oTable.insertRow(nInsertAtRow));
}

function insert_at_cursor( oField, tValue ) {
	if ( document.selection ) {		//IE support
		oField.focus();
		oRange=document.selection.createRange();
		oRange.text=tValue;
	} else if ( oField.selectionStart || oField.selectionStart == '0' ) {	//Mozilla/Firefox/Netscape 7+ support
		//Here we get the start and end points of the
		//selection. Then we create substrings up to the
		//start of the selection and from the end point
		//of the selection to the end of the field value.
		//Then we concatenate the first substring, myValue,
		//and the second substring to get the new value.
		var nStart=oField.selectionStart;
		var nEnd=oField.selectionEnd;
		oField.value=oField.value.substring(0,nStart)+tValue+oField.value.substring(nEnd,oField.value.length);
	} else {
		oField.value += tValue;
	}
}
