﻿// http://bontragerconnection.com/ and http://www.willmaster.com/
// Version: July 28, 2007
var cX = 0; var cY = 0; var rX = 0; var rY = 0;
function UpdateCursorPosition(e){ cX = e.pageX; cY = e.pageY;}
function UpdateCursorPositionDocAll(e){ cX = event.clientX; cY = event.clientY;}
if(document.all) { document.onmousemove = UpdateCursorPositionDocAll; }
else { document.onmousemove = UpdateCursorPosition; }
function AssignPosition(d) {
if(self.pageYOffset) {
	rX = self.pageXOffset;
	rY = self.pageYOffset;
	}
else if(document.documentElement && document.documentElement.scrollTop) {
	rX = document.documentElement.scrollLeft;
	rY = document.documentElement.scrollTop;
	}
else if(document.body) {
	rX = document.body.scrollLeft;
	rY = document.body.scrollTop;
	}
if(document.all) {
	cX += rX; 
	cY += rY;
	}
d.style.left = (cX-0) + "px";
d.style.top = (cY-0) + "px";
}

function HideContent(d)
{
    if (d.length < 1)
        return;

    var dd = document.getElementById(d);
    if (dd != null)
        dd.style.display = "none";
}

function ShowContent(d)
{
    ShowContent(d, false);
}



function FormatMoney(field, evt, neg)
{
    var negativo = field.value.charAt(0) == "-";
    var v = (field.value.replace(/[^0-9]/g, ""));
    if (!isNaN(v)) {
        var l = v.length;
        if (l < 3) {
            var formatado = v;
            if (arguments[2] == null) {
                field.value = formatado;
            } else {
                if (negativo) formatado = "-" + formatado;
                field.value = formatado;
            }
        }
        else {
            var formatado = virgula(v.substr(0, l - 2)) + "," + v.substring(l - 2, l);
            if (arguments[2] != null) {
                if (negativo) formatado = "-" + formatado;
                field.value = formatado;
            } else {
                field.value = formatado;
            }
        }
    }
    
}

function virgula(str)
{
    var j = 0;
    var s = "";
    for (var i = str.length - 1; i >= 0; --i)
    {
        s = str.charAt(i) + s;
        j++;
        if (j % 3 == 0)
            s = "." + s;
    }
    if (s.charAt(0) == ".") s = s.substr(1);
    return s;
}

function ShowContent(d, screenCenter)
{
    if (d.length < 1) 
        return;
        
    var dd = document.getElementById(d);
    if (dd != null)
    {
        dd.style.display = "block";
        
        if (screenCenter)
            CenterScreenPosition(dd);
    }
}

function CenterScreenPosition(obj)
{
    //obj.style.top = (screen.availHeight / 2) + "px"; // - (obj.offsetHeight / 2) + "px";
    //obj.style.left = (screen.availWidth / 2) + "px"; //- (obj.offsetWidth / 2) + "px";
    //obj.style.top="10px";
    //obj.style.left ="15px";
    //alert("Posiciobado");
}

function ReverseContentDisplay(d)
{
    if(d.length < 1)
        return;
        
    var dd = document.getElementById(d);
    if (dd != null)
    {
        AssignPosition(dd);

        if (dd.style.display == "none")
            dd.style.display = "block";
        else
            dd.style.display = "none";
    }            
}
//-->

//Fecha o item do menu anterior (quardado em lastContent) e abre o novo
var lastContent = "";
function ReverseContentDisplayAndCloseLastContent(d)
{
    if(lastContent.length > 0 && lastContent != d)
        ReverseContentDisplay(lastContent);
    
    ReverseContentDisplay(d);
    
    if(lastContent != d)
        lastContent = d;
    else
        lastContent = "";
}
//-----------------------

//função onMouseOver				
function setVisibility(id, visibility) {
document.getElementById(id).style.display = visibility;
}

function WindowPopUp(url, titulo, width, height)
{
    window.open(url, titulo, 'toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=yes,width=' + width + ',height=' + height);
    return false;
}

function SaltaCampoData(campo, prox, tammax, teclapres)
{
    var tecla = teclapres.keyCode;
    var vr = campo.value;
    var tam = vr.length;

    // Desconsidera o [tab] e o [shift+tab]
    if  ((tecla != 9) && (tecla != 16))  
        if (campo.value.length >= tammax)
        {
            // Trunca o conteudo para o tamanho máximo, no caso de CTRL+V
            campo.value = campo.value.substring(0, tammax );
            
            // Muda o foco para o próximo componente
            prox.focus();
        }
        if (campo.value.length == 2 || campo.value.length == 5)
            campo.value += "/";     
}

function SaltaCampo(campo, prox, tammax, teclapres)
{
    var tecla = teclapres.keyCode;
    var vr = campo.value;
    var tam = vr.length;

    // Desconsidera o [tab] e o [shift+tab]
    if  ((tecla != 9) && (tecla != 16))  
        if (campo.value.length >= tammax)
        {
            // Trunca o conteudo para o tamanho máximo, no caso de CTRL+V
            campo.value = campo.value.substring(0, tammax );
            
            // Muda o foco para o próximo componente
            prox.focus();
        }
    }


function DateMask(e, campoData) {

    var tecla = e.keyCode ? e.keyCode : e.charCode;
    var data = campoData.value;

    if (data.length < 10 || (tecla == 8 || tecla == 46)) {

        if (tecla == 8 || tecla == 0 || tecla == 46)
            return true
            
        if ((tecla > 47 && tecla < 58)) 
        {
            if (data.length == 2) {
                data = data + '/';
                campoData.value = data;
            }
            if (data.length == 5) {
                data = data + '/';
                campoData.value = data;
            }
            return true;
        }
        else
            return false;
    }
    else
        return false;
}

function SomenteNumero(e) {

    var tecla = e.keyCode ? e.keyCode : e.charCode;
    
    if((tecla > 47 && tecla < 58)) 
        return true;
    else
    {
        if (tecla != 8 && tecla != 0) 
            return false;
        else 
            return true;
    }
}

//abas lateral

function AbreAba(nome_div)
		{
			var ajuda = document.getElementById("abas_principal");
			var layer = "";
			ajuda.innerHTML ='';

			if(nome_div=="div1")
			{
				layer += "<li class=selecionada><a href=# onclick=AbreAba('div1');>DETALHES</a></li>";
			}
			else
			{
				 layer += "<li><a href=# onclick=AbreAba('div1');>DETALHES</a></li>";
			}
			if(nome_div=="div2")
			{
				layer += "<li class=selecionada><a href=# onclick=AbreAba('div2');>NEGÓCIOS</a></li>";
			}
			else
			{
				 layer += "<li><a href=# onclick=AbreAba('div2');>NEGÓCIOS</a></li>";
			}
			if(nome_div=="div3")
			{
				layer += "<li class=selecionada><a href=# onclick=AbreAba('div3');>GRAFICO</a></li>";
			}
			else
			{
				 layer += "<li><a href=# onclick=AbreAba('div3');>GRAFICO</a></li>";
			}
			if(nome_div=="div4")
			{
				layer += "<li class=selecionada><a href=# onclick=AbreAba('div4');>OFERTAS</a></li>";
			}
			else
			{
				 layer += "<li><a href=# onclick=AbreAba('div4');>OFERTAS</a></li>";
			}

			    document.getElementById('div1').style.display = "none";
			    document.getElementById('div2').style.display = "none";
			    document.getElementById('div3').style.display = "none";
					document.getElementById('div4').style.display = "none";
			    ajuda.innerHTML = layer;
			    document.getElementById('div1').style.display = "none";
			    document.getElementById(nome_div).style.display = "block";
		}
		
		

// popUp compra e venda

x = 20;
y = 70;
function setVisible(obj)
{
	obj = document.getElementById(obj);
	obj.style.visibility = (obj.style.visibility == 'visible') ? 'hidden' : 'visible';
}

function placeIt(obj)
{
	obj = document.getElementById(obj);
	
	if (obj != null)
	{
	    if (document.documentElement)
	    {
		    theLeft = document.documentElement.scrollLeft;
		    theTop = document.documentElement.scrollTop;
	    }
	    else if (document.body)
	    {
		    theLeft = document.body.scrollLeft;
		    theTop = document.body.scrollTop;
	    }
	 
	    theLeft += x;
	    theTop += y;
	    obj.style.left = theLeft + 'px' ;
	    obj.style.top = theTop + 'px' ;
	 
	    setTimeout("placeIt('layer1')", 500);
	}
}


function keypresed() { return false; }

function disableKeyPress()
{
	document.onkeydown = keypresed;
	document.oncontextmenu = new Function("return false;")
}

function enableKeyPress()
{
	document.onkeydown = "";
	document.oncontextmenu = new Function("return true;")
}

function sL(id)
{
    document.getElementById(id).style.display = "block";
}

function hL(id)
{
    document.getElementById(id).style.display = "none";
}


function prelLoadMenu()
{
    if (document.images) {
        pic1= new Image(216,231);
        pic1.src = "/Site/Public/Image/MenuHome/menu-.gif";

        pic2 = new Image(216, 231);
        pic2.src = "/Site/Public/Image/MenuHome/menu.gif";

        pic3 = new Image(216, 231);
        pic3.src = "/Site/Public/Image/MenuHome/menu_over-.gif";

        pic4 = new Image(216, 231);
        pic4.src = "/Site/Public/Image/MenuHome/menu_over.gif"; 
    }
}

function closeBannerHexa() {
    document.getElementById("divHexa").style.display = 'none';
}
