String.prototype.trim = function() {
	return this.replace(/^\s+|\s+$/g,"");
}
String.prototype.ltrim = function() {
	return this.replace(/^\s+/,"");
}
String.prototype.rtrim = function() {
	return this.replace(/\s+$/,"");
}

function $() {
	var elements = new Array();
	for (var i = 0; i < arguments.length; i++) {
		var element = arguments[i];
		if (typeof element == 'string')
			element = document.getElementById(element);
		if (arguments.length == 1)
			return element;
		elements.push(element);
	}
	return elements;
}

function toggle(obj,force)
{
    if(force != null)
        $(obj).style.display = force;
    else
    {
        if ( $(obj).style.display != 'none' )
            $(obj).style.display = 'none';
        else
            $(obj).style.display = '';
    }
}

function findPosX(obj) {
    var curleft = 0;
    if (obj.offsetParent) {
        while (1) {
            curleft+=obj.offsetLeft;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.x) {
        curleft+=obj.x;
    }
    return curleft;
}

function findPosY(obj) {
    var curtop = 0;
    if (obj.offsetParent) {
        while (1) {
            curtop+=obj.offsetTop;
            if (!obj.offsetParent) {
                break;
            }
            obj=obj.offsetParent;
        }
    } else if (obj.y) {
        curtop+=obj.y;
    }
    return curtop;
}


// Returns the index of the list item with given value.
function getIndex( obj, value ) {	
	for( i = 0; i < obj.length; i++ )
	{
		if( obj.options[i].value == value )
			return i;
	}	
	return -1;	
}

// Returns the first element with the given name.
function n( name ) {
	var elements = document.getElementsByName( name );
	return elements[0];
}

function m(str)
{
	var cap_cen = 		'Directorio de centros de capacitación.';
	var cap_reg = 		'Registrar un centro de capacitación.';
	var cap_mod = 		'Modificar los datos de su centro de capacitación.';
	var cap_newuser = 	'Agregar un nuevo usuario. Con una cuenta de usuario, podrá registrar su centro de capacitación.';
	var cap_newinst = 	'Agregar un nuevo centro de capacitación.';
	var cap_help = 		'Centro de soporte. Para todas sus preguntas, problemas y comentarios.';
	
	var d = $('menu_detail');
	var obj;
		
	if( str == '' ) {
		d.innerHTML = ' ';
		d.style.backgroundColor = '#FFFFFF';
		d.style.border = '2px solid #FFFFFF';
		d.style.display = 'none';
	} else {
		obj = $(str);
		d.style.display = 'block';
		d.style.backgroundColor = '#EEEEEE';
		d.style.border = '2px solid #CCCCCC';
		d.style.left = findPosX(obj) + 'px';
		d.style.top = findPosY(obj) + 32 + 'px';
		d.style.zIndex = 1;
		d.innerHTML = eval(str);
	}
}