var idMenuObrasAnt = "";

function abreMenuObras(idMenu) {
	var objMenu = document.getElementById("DIVSubMenuObras_" + idMenu);
	var objIMG	= document.getElementById("IMGSubMenuObras_" + idMenu);

	if (idMenuObrasAnt != "") {
		fechaMenuObras(idMenuObrasAnt);
		idMenuObrasAnt = "";
	}
	objMenu.style.position = "relative";
	objMenu.style.visibility = "visible";

	objIMG.src = "/img/imgSetaBaixo.gif"

	idMenuObrasAnt = idMenu;
}

function abreMenuObrasAndamento(idMenu) {
	var objMenu = document.getElementById("DIVSubMenuObras_" + idMenu);
	var objIMG	= document.getElementById("IMGSubMenuObras_" + idMenu);

	if (idMenuObrasAnt != "") {
		fechaMenuObras(idMenuObrasAnt);
		idMenuObrasAnt = "";
	}
	objMenu.style.position = "relative";
	objMenu.style.visibility = "visible";

	objIMG.src = "/img/imgSetaBaixo.gif"

	idMenuObrasAnt = idMenu;
}

function fechaMenuObras(idMenu) {
	var objMenu = document.getElementById("DIVSubMenuObras_" + idMenu);
	var objIMG	= document.getElementById("IMGSubMenuObras_" + idMenu);

	objMenu.style.position = "absolute";
	objMenu.style.visibility = "hidden";

	objIMG.src = "/img/imgSetaEsquerda.gif"
}

function trocaFoto(sFoto) {
	var objFoto = document.getElementById("DIVFotosDetalheObra");
	var objLink = document.getElementById("objLinkLightBox");

	objFoto.style.background = "url('" + sFoto + "') no-repeat 50% 50%";
	objLink.href = sFoto;
}

function trocaFotoDestaque(sFoto) {
	var objFoto = document.getElementById("DIVFotosDestaqueObra");
	var objLink = document.getElementById("objLinkLightBox");

	objFoto.style.background = "url('" + sFoto + "') no-repeat 50% 50%";
	objLink.href = sFoto;
}

function mostraMenu1(objImg, iIndice) {
	var srcOrigem = objImg.src
	var srcDestino = (srcOrigem.substring(0, srcOrigem.length - 5)) + iIndice + ".gif"

	objImg.src = srcDestino
}

function PopUpFoto(Obj)
{
	var sSrc;

	sSrc = Obj.src.replace("_pq", "")
	sSrc = sSrc.replace("/thumbs", "/fotos")

	PopUp(sSrc, 300, 250)
}

function TrocaSrc(Obj)
{
	var sSrc;

	sSrc = Obj.src.replace("_pq", "")
	ObraFoto.src = sSrc.replace("/thumbs", "/fotos")
}

function TrocaSrc2(Img)
{
	var sSrc;

	sSrc = Img.replace("_pq", "")
	ObraFoto.src = sSrc.replace("/thumbs", "/fotos")
}

function TrocaClass(Lim, NumObj)
{
	for(i=0; i<=Lim; i++){
		eval('Foto' + i).style.color='#737373'; 
	}
	eval('Foto' + NumObj).style.color='cc3300'; 
}

function ScrollTop()
{
	if (parseInt(document.body.scrollLeft))
	{
		parent.TableHeader.style.left = (parseInt(document.body.scrollLeft) * -1) + 2
	}
	else
	{
		parent.TableHeader.style.left = 2
	}
}

function PopUp(Janela, iLargura, iAltura)
{
	window.open(Janela, "", "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=auto, resizable=yes, copyhistory=no, width=" + iLargura + ", height=" + iAltura);
}

function PopUp2(Janela, iLargura, iAltura)
{
	window.open(Janela, "", "toolbar=no, location=no, directories=no, status=yes, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, width=" + iLargura + ", height=" + iAltura);
}

function PopUp3(Janela, iLargura, iAltura, LeftPos, TopPos)
{
	window.open(Janela, "", "toolbar=no, location=no, directories=no, status=no, menubar=no, scrollbars=no, resizable=yes, copyhistory=no, top=" + TopPos + ", left=" + LeftPos + ", width=" + iLargura + ", height=" + iAltura);
}

function FormatNumber(num,decimalNum,bolLeadingZero,bolParens,bolCommas)
/**********************************************************************
	IN:
		NUM - the number to format
		decimalNum - the number of decimal places to format the number to
		bolLeadingZero - true / false - display a leading zero for
										numbers between -1 and 1
		bolParens - true / false - use parenthesis around negative numbers
		bolCommas - put commas as number separators.
 
	RETVAL:
		The formatted number!
 **********************************************************************/
{ 
        if (isNaN(parseInt(num))) return "NaN";

	var tmpNum = num;
	var iSign = num < 0 ? -1 : 1;		// Get sign of number
	
	// Adjust number so only the specified number of numbers after
	// the decimal point are shown.
	tmpNum *= Math.pow(10,decimalNum);
	tmpNum = Math.round(Math.abs(tmpNum))
	tmpNum /= Math.pow(10,decimalNum);
	tmpNum *= iSign;					// Readjust for sign
	
	
	// Create a string object to do our formatting on
	var tmpNumStr = new String(tmpNum);

	// See if we need to strip out the leading zero or not.
	if (!bolLeadingZero && num < 1 && num > -1 && num != 0)
		if (num > 0)
			tmpNumStr = tmpNumStr.substring(1,tmpNumStr.length);
		else
			tmpNumStr = "-" + tmpNumStr.substring(2,tmpNumStr.length);
		
	// See if we need to put in the commas
	if (bolCommas && (num >= 1000 || num <= -1000)) {
		var iStart = tmpNumStr.indexOf(".");
		if (iStart < 0)
			iStart = tmpNumStr.length;

		iStart -= 3;
		while (iStart >= 1) {
			tmpNumStr = tmpNumStr.substring(0,iStart) + "," + tmpNumStr.substring(iStart,tmpNumStr.length)
			iStart -= 3;
		}		
	}

	// See if we need to use parenthesis
	if (bolParens && num < 0)
		tmpNumStr = "(" + tmpNumStr.substring(1,tmpNumStr.length) + ")";

	return tmpNumStr;		// Return our formatted string!
}