if( typeof cAutoEdit == 'undefined' )
{
	cAutoEdit = new Object()
}
cAutoEdit.nId = 0

cAutoEdit.onInit = function( hItem )
{
	return true
}

cAutoEdit.onEndEdit = function( hContext )
{
	return true
}

cAutoEdit.onEditClick = function( hEvent )
{
	cAutoEdit.doEdit( this )
}

cAutoEdit.doEdit = function( hItem )
{
	var hEdit = document.createElement( 'input' )
	hEdit.className = 'shortEdit'
	hEdit.value = hItem.innerHTML
	hEdit.style.width = ( hItem.offsetWidth + 10 ) + 'px'
	hEdit.forElement = hItem.id
	hItem.style.display = 'none'
	hItem.parentNode.insertBefore( hEdit, hItem )
	cDomEvent.addEvent2( hEdit, 'blur', cAutoEdit.onEditBlur )
	cDomEvent.addEvent2( hEdit, 'keydown', cAutoEdit.onEditKeyDown )
	hEdit.select()
}

cAutoEdit.onEditBlur = function( hEvent )
{
	cAutoEdit.endEdit( this )
}

cAutoEdit.onEditKeyDown = function( hEvent )
{
	//hEvent = cDomEvent.getEvent( hEvent )
	var bCancel = false
	if( hEvent.keyCode == 13 || hEvent.keyCode == 27 )
	{
		if( hEvent.keyCode == 27 )
		{
			bCancel = true
		}
		cAutoEdit.endEdit( this, bCancel )
		cDomEvent.cancelEvent( hEvent )
		return false
	}
}


cAutoEdit.endEdit = function( hInput, bCancel )
{
	if( typeof bCancel == 'undefined' )
	{
		bCancel = false
	}
	var hItem = document.getElementById( hInput.forElement )
	if( !bCancel )
	{
		hItem.replaceChild( document.createTextNode( hInput.value ), hItem.childNodes[ 0 ] )
	}
	hItem.style.display = 'inline'
	hInput.parentNode.removeChild( hInput )
	hItem.focus()

	
	var hContext = {}
	hContext[ 'input' ] = hInput
	hContext[ 'item' ] = hItem
	hContext[ 'cancel' ] = bCancel 
	if( hItem.getAttribute('onendedit') )
	{
		eval(hItem.getAttribute('onendedit'))
	}
	else
	{
		cAutoEdit.onEndEdit( hContext )
	}
}

cAutoEdit.init = function( hItem )
{
	if( !hItem.id )
	{
		hItem.id = 'autoedititem' + ( cAutoEdit.nId++ )
 	}
	cDomEvent.addEvent2( hItem, 'click', cAutoEdit.onEditClick )
	cAutoEdit.onInit( hItem )
}

cDomExtensionManager.register( new cDomExtension( document, [ "a[class*=autoedit]" ], cAutoEdit.init ) ) 
