// Removes leading whitespaces
function LTrim( value ) {
	var re = /\s*((\S+\s*)*)/;
	return value.replace(re, "$1");
}

// Removes ending whitespaces
function RTrim( value ) {
	var re = /((\s*\S+)*)\s*/;
	return value.replace(re, "$1");
}

// Removes leading and ending whitespaces
function trim( value ) {
	return LTrim(RTrim(value));
}

function openSubMenu(divName, exceptDiv, id, link) {
    var text;
    if(link == '') link = '/cms/view/id/';
    
    link += id;
    
    text = '';
    
    text = $(divName).innerHTML;
    
    text = LTrim(text);
    text = RTrim(text);
    text = trim(text);
    
    // verifica se o menu contem filhos
    if (text != '') {
        closeAll(myDivs, divName, exceptDiv);
        
        // fechar se estiver aberto
        if (($(divName).style.visibility == '') || ($(divName).style.visibility == 'hidden')) {
            $(divName).style.visibility = 'visible';
            $(divName).style.overflow   = 'visible';
            $(divName).style.position   = 'relative';
        }
    } else {
        window.location= link;
    }
}

function justOpen(divName) {
    var text;
    text = '';
    
    text = $(divName).innerHTML;
    
    text = LTrim(text);
    text = RTrim(text);
    text = trim(text);
    
    if (text != '') {
        $(divName).style.visibility = 'visible';
        $(divName).style.overflow   = 'visible';
        $(divName).style.position   = 'relative';
    }
    return true;
}

function closeSubMenu(divName) {
    $(divName).style.visibility = 'hidden';
    $(divName).style.overflow   = 'hidden';
    $(divName).style.position   = 'absolute';    
}

function closeAll(myDivs, divName, exceptDiv) {
    var i, j;
    j = myDivs.length;
    for (i = 0; i < j; i++) {
        if (exceptDiv != myDivs[i]) {
            closeSubMenu(myDivs[i]);
        }
    }
}



