/*-----------------------------------------------------------------------------+
| Funções Gerais JavaScript                                                    |
+-----------------------------------------------------------------------------*/

function popup(url,w,h){
    var win = window.open(url,"","toobar=no,location=no,directories=no,maximize=no,menubar=no,scrollbars=yes,status=no,resizable=no,WIDTH="+w+",HEIGHT="+h+",top=0,left=50");
    if(win.focus)
        win.focus();
}

function roundNumber(preco) {
    var numberField = preco;
    var rlength = 2; // The number of decimal places to round to
    var newnumber = Math.round(numberField*Math.pow(10,rlength))/Math.pow(10,rlength);
    return newnumber;
}


function IsNumeric(sText){
   var ValidChars = "123456789 ";
   var IsNumber=true;
   var Char;


    for (i = 0; i < sText.length && IsNumber == true; i++){
        Char = sText.charAt(i);
        if (ValidChars.indexOf(Char) == -1){
            IsNumber = false;
        }
    }
    return IsNumber;
}

/******************************
 * SHOW / HIDE CONTENTS
 *****************************/

var activeElement = 0;

function handleElement(id){
    //hideElement(activeElement);
    showElement(id);

    return false;
}

function showElement(id){
    var el = document.getElementById(id);
    if(el){
        if(activeElement == id){
            hideElement(id);

            activeElement = 0;
        }else{
            if(el.style.visibility == 'visible'){
                el.style.visibility = 'hidden';
                el.style.display = 'none';

                activeElement = 0;
            }else{
                el.style.visibility = 'visible';
                el.style.display = 'block';

                activeElement = id;
            }
        }
    }
}

function hideElement(id){
    if(id == 0)
        id = activeElement;

    var el = document.getElementById(id);
    if(el){
        el.style.visibility = 'hidden';
        el.style.display = 'none';
    }
}

function activateElement(id){
    activeElement = id;
}

/******************************
 * SHOW / HIDE MENUS
 *****************************/

var activeMenu = 0;
var activeLink = 0;

function handleMenu(id, link_el){
    hideMenu(activeMenu, activeLink);
    showMenu(id, link_el);

    return false;
}

function showMenu(id, link_el){
    var el;
    el = document.getElementById(id);
    if(el){
        if(activeMenu == id){
            hideMenu(id);

            activeMenu = 0;
            activeLink = 0;
        }else{
            el.style.visibility = 'visible';
            el.style.display = 'block';

            activeMenu = id;
            activeLink = link_el;

            el = document.getElementById(link_el);
            if(el){
                el.className  = 'menu_links_activo';
            }
        }
    }
}

function hideMenu(id, link_el){
    var el;

    if(id == 0){
        id = activeMenu;
        link_el = activeLink;
    }

    el = document.getElementById(id);
    if(el){
        el.style.visibility = 'hidden';
        el.style.display = 'none';
    }

    el = document.getElementById(link_el);
    if(el != null){
        el.className = 'menu_links';
    }
}

function activateMenu(id, link_el){
    activeMenu = id;
    activeLink = link_el;
}

function changeVisibility(id) {
	obj = document.getElementById(id).style;
	
	if(obj.visibility == 'hidden') {
		obj.visibility = 'visible';
		obj.display    = 'block';
	} else {
		obj.visibility = 'hidden';
		obj.display    = 'none';
	}

	return false;
}

function changeVisibility_(id) {
	
	obj = document.getElementById(id).style;
	
	if(old == id){
		if(obj.visibility == 'hidden') {
		obj.visibility = 'visible';
		obj.display    = 'block';
		} else {
			obj.visibility = 'hidden';
			obj.display    = 'none';
		}
	} else {
		obj.visibility = 'visible';
		obj.display    = 'block';
	
		if(old != ""){
			obj_1 = document.getElementById(old).style;
			obj_1.visibility = 'hidden';
			obj_1.display    = 'none';
		}
	}
	old = id;

	return false;
}

