var AtalhosHabilitados = true;
window.onscroll = PosicionarDivProgress;

function HabilitarAtalhos(valor)
{
    AtalhosHabilitados = valor;
}

function PosicionarDivProgress()
{
    var Div = $('PnlDivAjaxProgress');
    
    if(Div)
    {
        var ScrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
        var ScrollLeft = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft;
        
        Div.style.left=ScrollLeft+'px';
        Div.style.top=ScrollTop+'px';
    }
}

function MostrarDivProgress()
{
    PosicionarDivProgress();
    $('PnlDivAjaxProgress').innerHTML = "<span class='LblAguarde'>Processando...</span>";
    $('PnlDivAjaxProgress').style.display="block";
}

function MostrarDivProgressMsg(Msg)
{
    var DivProgress = $('PnlDivAjaxProgress');
    
    if(DivProgress)
    {
        PosicionarDivProgress();
        $('PnlDivAjaxProgress').innerHTML = "<span class='LblAguarde'>" + Msg.toString() + "</span>";
        $('PnlDivAjaxProgress').style.display="block";
    }
}

function OcultarDivProgress()
{
    var DivProgress = $('PnlDivAjaxProgress');
    if(DivProgress)
        $('PnlDivAjaxProgress').style.display="none";
}

function AdicionarItemLst(IdLstOrigem, IdLstDestino, IdViewState) {
	
	var LstOrigem = document.getElementById(IdLstOrigem);	
	var LstDestino = document.getElementById(IdLstDestino);	
	var ObjVs = document.getElementById(IdViewState);
	ObjVs.value = "";
	
	for(i = 0; i<LstOrigem.options.length; i++) 
	{
		
			if (LstOrigem.options[i].selected) 
			{
				if(LstDestino.options.length > 0 ) 
				{
					LstDestino.options[LstDestino.options.length] = new Option(LstOrigem.options[i].text,LstOrigem.options[i].value);
					LstOrigem.options[i] = null;
				} 
				else 
				{
					LstDestino.options[0] = new Option(LstOrigem.options[i].text,LstOrigem.options[i].value);
					LstOrigem.options[i] = null;
				}				
			} 
	}
	
	for(i=0;i<LstDestino.options.length;i++)
	{
	    ObjVs.value += ";" + LstDestino.options[i].value;
	}
	ObjVs.value = ObjVs.value.substring(1);
}


function RemoverItemLst(IdLstOrigem, IdLstDestino, IdViewState) {
	
	var LstOrigem = document.getElementById(IdLstOrigem);	
	var LstDestino = document.getElementById(IdLstDestino);	
	var ObjVs = document.getElementById(IdViewState);
	ObjVs.value = "";
	
	if(LstDestino.options.length == 0 ) 
	{
		return false;
	}
	
	for(i = 0; i<LstDestino.options.length; i++) 
	{	
		if( LstDestino.options[i].selected  ) 
		{
			if(LstOrigem.options.length > 0 ) 
			{
				LstOrigem.options[LstOrigem.options.length] = new Option(LstDestino.options[i].text,LstDestino.options[i].value);
				LstDestino.options[i] = null;
			} 
			else 
			{
				LstOrigem.options[0] = new Option(LstDestino.options[i].text,LstDestino.options[i].value);
				LstDestino.options[i] = null;	
			}		
		} 
	}
	
	for(i=0;i<LstDestino.options.length;i++)
	{
	    ObjVs.value += ";" + LstDestino.options[i].value;
	}	
	ObjVs.value = ObjVs.value.substring(1);
	if(ObjVs.value.length==0)
	{
	    ObjVs.value = "|";
	}
}

function GContextMenu(LinhaGrid, evento, IdColuna, Arg)
{
    try
    {
        GDesselecionarTodosRegistros();
        GSelecionarLinha(LinhaGrid.parentNode);
        
        var evt;
        if(evento) { evt=evento; } else { evt = window.event; }
        var Div = $("DivContextMenu");
        
        var ScrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
        var ScrollLeft = document.body.scrollLeft ? document.body.scrollLeft : document.documentElement.scrollLeft;
        
        if(Arg!=null)
        {
            Div.innerHTML = GObterContextMenu(IdColuna).replace("[ID]",GObterID(LinhaGrid)).replace("Arg", Arg);
        }
        else
        {
            Div.innerHTML = GObterContextMenu(IdColuna).replace("[ID]",GObterID(LinhaGrid));
        }
        
        var LinhaBaixo = document.body.parentNode.clientHeight;
        var LinhaDireita = document.body.parentNode.clientWidth;
        
        Div.style.left = (evt.clientX + ScrollLeft - 10) + "px";
        Div.style.top = (evt.clientY + ScrollTop - 10) + "px";
                
        /*if(Div.style.width.toString()=="")
        {
            Div.style.width = Div.clientWidth.toString() + "px";
        }*/
        
        if((parseInt(Div.style.top) + Div.clientHeight - ScrollTop + 5)>LinhaBaixo)
        {
            Div.style.top = (evt.clientY + ScrollTop + 10 - Div.clientHeight) + "px";
        }
        /*if((parseInt(Div.style.left) + Div.clientWidth - ScrollLeft + 5)>LinhaDireita)
        {
            Div.style.left = (evt.clientX + ScrollLeft + 10 - Div.clientWidth) + "px";
        }*/
        
        Div.style.visibility="visible";
        
        return false;
        
    }
    catch(e){}
}
function GetYOffset( oElement )
{
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetTop;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}
function GetXOffset( oElement )
{
    var iReturnValue = 0;
    while( oElement != null ) {
        iReturnValue += oElement.offsetLeft;
        oElement = oElement.offsetParent;
    }
    return iReturnValue;
}

// 5/9/2010 3:34:16