var tempo = 0;
var imagefetch = 19;

function tempoEsperaHP()
{
	if (tempo < 1600)
	{
		tempo++;
		imagefetch++;

		if (imagefetch > 20) {
			imagefetch = 0;
			verificaStatusHP();
		}

		setTimeout("tempoEsperaHP()", 200);
	}
}

function openPopupHP(URL, Largura, Altura)
{
    var top  = parseInt((screen.availHeight-Altura)/2);
    var left = parseInt((screen.availWidth-Largura)/2);

   return window.open(URL, "_blank", 'width='+Largura+', height='+Altura+', scrollbars=no, top='+top+'px,left='+left+'px, status=no, r=no, resizable=yes, toolbar=no, location=yes, directories=no, menubar=no');
}

function verificaStatusHP()
{
 	var url = ServerName+"online_status.php?PIDGrupo="+PIDGrupo+"&PIDCidade="+PIDCidade;

    document.getElementById("divIMGStatusHP").src = url;
	imagefetch = 0;
}


function getTamanhoIMG(imagem)
{
    var myImage = new Image();
    myImage.name = "a";
    myImage.onload = getWidthAndHeight;
    myImage.src = imagem;

    var newImg = new Image();
    newImg.src = imagem;

}

var imgWidth;
var imgHeight;

function getWidthAndHeight()
{
    imgWidth = this.width;
    imgHeight = this.height;
}

//define a distancia do mouse em relação a imagem
var distancia = 180;
var mostraOcultaAviso = true

function mostraOcultaHint( acao )
{

    if( navigator.appName != 'Microsoft Internet Explorer' )
    {
          if( acao )
          {
                //document.getElementById("msg").style.display = 'block';
                document.getElementById("divInternoMSG").innerHTML = "<strong>Dúvidas?</strong> Então pergunte!";
                document.getElementById("divInternoMSG").style.textDecoration = 'none';
                mostraOcultaAviso = true;
          }
          else
          {
                //document.getElementById("msg").style.display = 'none';
                document.getElementById("divInternoMSG").style.textDecoration = 'blink';
                document.getElementById("divInternoMSG").innerHTML = "<strong>Clique para ser atendido!</strong>";
                mostraOcultaAviso = false;
          }
    }
}

function getPosicaoMouse( e )
{
    /* pega posicao do mouse */

    var x = 0;
    var y = 0;

    if( navigator.appName.indexOf('Internet Explorer') > 0 )
    {
        x = window.event.clientX;
        y = window.event.clientY;
    }
    else
    {
        x = e.clientX;
        y = e.clientY;
    }
    
    //document.getElementById("msg").innerHTML = x;
    
    /* pega posicao da imagem na tela */
    var topIMG  = getPosicaoElemento("divIMGStatusHP").top;
    var leftIMG = getPosicaoElemento("divIMGStatusHP").left;

    if( navigator.appName != 'Microsoft Internet Explorer' )
    {
        if( ( ( y > ( topIMG - distancia ) ) && ( y < ( topIMG + imgHeight + distancia ) ) ) && ( ( x > ( leftIMG - distancia ) ) && ( x < ( leftIMG + imgWidth + distancia ) ) ) )
        {
            if( mostraOcultaAviso )
            {
                document.getElementById("msg").style.display = 'block';
            }
        }
        else
        {
           document.getElementById("msg").style.display = 'none';
        }
    }
}

function getPosicaoElemento(elemID)
{
    var offsetTrail = document.getElementById(elemID);
    var offsetLeft = 0;
    var offsetTop = 0;
    
    while (offsetTrail)
    {
        offsetLeft += offsetTrail.offsetLeft;
        offsetTop += offsetTrail.offsetTop;
        offsetTrail = offsetTrail.offsetParent;
    }
    if (navigator.userAgent.indexOf("Mac") != -1 &&
    
        typeof document.body.leftMargin != "undefined")
        {
            offsetLeft += document.body.leftMargin;
            offsetTop += document.body.topMargin;
        }
    
    return {left:offsetLeft, top:offsetTop};
}

tempoEsperaHP();
var skin;
var PIDCidade;
document.write("<img id='divIMGStatusHP' onmouseout='mostraOcultaHint( true )' onmouseover='mostraOcultaHint( false )' name='divIMGStatusHP' src='"+ServerName+"online_status.php?PIDGrupo="+PIDGrupo+"&PIDCidade="+PIDCidade+"' style='cursor: pointer;' onclick=\"openPopupHP('"+ServerName+"index_chat.php?id="+PIDGrupo+"&skin="+skin+"&IDCidade="+PIDCidade+"', 500, 525);\"><div id='msg' style='position: absolute; display: none; background-image: url(http://"+ServerName+"/helpdesk/img/hint_topborder.gif); z-index: 10000; width: 180px; background-repeat: no-repeat; *left: 0px; *top: 0px; background-position: left top; padding: 14px 0 0 0; margin:  2px 0 0 10px; color: #000;'><div id='divInternoMSG' style='background-color: #fffbb8; border-left: 1px solid #ffc20d; border-right: 1px solid #ffc20d; border-bottom: 1px solid #ffc20d; padding: 4px; font-family:verdana,arial,times; font-size: 10px;'><strong>Dúvidas?</strong> Então pergunte!</div></div>");


//document.onmousemove = getPosicaoMouse;
//getTamanhoIMG(document.getElementById('divIMGStatusHP').src);




