
//Soma de um array
Array.prototype.sum = function(){
	for(var i=0,sum=0;i<this.length;sum+=this[i++]);
	return sum;
}
//N.º Máximo de um array
Array.prototype.max = function(){
	return Math.max.apply({},this)
}
//N.º Minimo de um array
Array.prototype.min = function(){
	return Math.min.apply({},this)
}
/******************************************************************************
Converção de um texto para número
******************************************************************************/
function subform(frm,url)
{
    frm.action = url;
    frm.submit();
}
//*****************************************************************************
/******************************************************************************
Converção de um texto para número
******************************************************************************/
function CNum(ref)
{
    var i = 0;
    var total = 0;
    num=parseFloat(ref);
    if(isNaN(num) || (num+'')!=ref){
 	    re = ",";
   	    num = ref;
   	    num2 = num.replace(re,".");
        num=parseFloat(num2);
        if(isNaN(num))
        {
           num=0;
        }
    }
    return num;
}

function BRS(Str) {
    var L = Str.length, P = Str.indexOf("."), Q;
    if (P < 0) {
        return Str + ".00";
    }
    if (P == L - 2) {
        return Str + "0";
    }
    if (P == L - 3) {
        return Str;
    }
    if (Str.charAt(0) == "-") {
        return "-" + BRS(Str.substring(1));
    }
    Q = Str.substring(P + 3);
    if (Q < "5") {
        return Str.substring(0, P + 3);
    }
    if (Q > "5") {
        return BRS(String(0.0125 + +Str.substring(0, P + 3)));
    }
    Q = Str.charCodeAt(P + 2) % 2 ? 0.001 : -0.001;
    return BRS(String(Q + +Str));
}
//******************************************************************************

//Abertura de um popUP
function openfile(file,w,h) {
    window.open(file ,"","left=20,top=20,width=" + w + ",height=" + h + ",scrollbars");
    void(0);
}

function showObject(object,text) {
	myLayer = document.getElementById(object);
	myLayer.innerHTML = text;
	
	w = parseInt(myLayer.style.width);
	h = parseInt(myLayer.style.height);

    x = e.pageX;
    y = e.pageY;
    browserX = window.innerWidth - 35;
	
	x1 = x + 20;		// Move out of mouse pointer
	y1 = y + 20;

	// Keep box from going off screen
	if (x1 + w > browserX)
		x1 = browserX - w;
	
  
    myLayer.style.left = parseInt(x1)+ "px";
    myLayer.style.top = parseInt(y1) + "px";
	myLayer.style.visibility = "visible";
}

