try
{
    if(jQuery)
    {
        jQuery.noConflict();
        var $j = jQuery;
    }
}
catch(e)
{
}

function procWidth(obj){
	var curwidth = 0;
	if (obj.offsetParent){
		curwidth = obj.offsetWidth;
	}else if (obj.x){
		curwidth = obj.width;
	}
	return curwidth;
}

function procHeight(obj){
	var curheight = 0;
	if (obj.offsetParent){
		curheight = obj.offsetHeight;
	}else if (obj.x){
		curheight = obj.height;
	}
	return curheight;
}

function procPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;
		}
	}else if (obj.x){
		curleft += obj.x;
	}
	return curleft;
}

function procPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;
		}
	}else if (obj.y){
		curtop += obj.y;
	}
	return curtop;
}


function posicao(obj, reference, dist) {
	var newX = procPosX(reference);
	var newY = procPosY(reference);
	var newWidth = procWidth(reference);
	var newHeight = procHeight(reference);
	
	if(obj.id.substring(10,11) > 1){
		obj.style.left = newX + newWidth - 15;
	}else{
		obj.style.left = newX + newWidth;
	}
	obj.style.top = newY + dist;
}

function showItem(pItem){
	var _item = document.getElementById(pItem);
	//
	if(_item != null){
	    _item.style.display = "block";
	}
}

function hideItem(pItem){
    var _item = document.getElementById(pItem);
	//
	if(_item != null){
	    _item.style.display = "none";	
	}
}

function hideItens(pTotal){
    var _total = pTotal;
    //
    for(var i = 1; i <= _total; i++){
        hideItem("subMenu"+i);
    }
}

function selecItem(pItem, pClass){
	_item = document.getElementById(pItem);
	_class = pClass;
	//
	_item.className = _class;
}


showModal = function(tipo, texto, redirection, contentElementID)
{
        
    if($j)
    {
     
     if(!redirection)
     {
        redirection = "";
     }
     
        $j.ajax({
            type:			"POST",
            data:			"tipo=" + tipo + "&texto=" + texto + "&redirection=" + redirection,
            url:			"../popup.aspx",
            success:		function(res) {
                                setLayer(res);
                            }
            });
            
     }
     else
     {
        alert("Por favor incluir os scripts de jQuery nesta página");
        return false;
     }
     
     function setLayer(res)
     {

        window.scrollTo(0,0);
        
        $j('#systemMessages').css("width",screen.width + "px");
        $j('#systemMessages').css("height",screen.height + "px");
        window.scrollTo(0,0);
        $j('body').css("overflow", "hidden");
        $j('#systemMessages').html(res);

        if(tipo =="generic")
        {
            var genericContent = $j("#" + contentElementID).html();
            $j(".txtDialog").html(genericContent);
            $j(".txtDialog").find("*").show();
        }

        $j("select").hide();
     }
}

function hideModal()
{
    $j('body').css("overflow", "auto");
    $j(".modalBox").hide();
    $j('#systemMessages').css("width","0px");
	$j('#systemMessages').css("height","0px");
	$j("select").show();
	
}

function  returnConfirm()
{

}

if($j)
{
	$j(document).ready(
	    function()
	    {
	        
	        $j("#txtBanco").keyup(
	            function()
	            {
	                if($j(this).val().length > 0)
	                {
	                    if($j("#hdfBancoNome").val() != $j(this).val())
	                    {
	                        $.ajax({
						    type:			"POST",
						    data:			"word=" + $j(this).val(),
						    url:			"Bancos.aspx",
						    success:		function(res) {
											    $j('#listaBancos').html(res);
											    $j("#listaBancos").show();
										    },
						    error:			function(red) {
						                        $j("#listaBancos").html("");
											    $j("#listaBancos").hide();
										    }
				            });
				         }
	                }
	                else
	                {
	                    $j("#hdfBancoID").val("");
	                    $j("#hdfBancoNome").val("");
	                    $j("#listaBancos").html("");
	                    $j("#listaBancos").hide();
	                }
	            }
	         );
	    }
	);

	function setBancoID(bancoID, bancoNome)
	{
	    $j("#hdfBancoID").val(bancoID);
	    $j("#hdfBancoNome").val(bancoNome);
	    $j("#listaBancos").hide();
	    $j("#txtBanco").val(bancoNome);
	    
	}

	$j(document).ready(function(){

	    //Concurso
	    $j(".btnConcurso").click(function(){
	        window.scrollTo(0,0);
	        return validateGroup("concurso", "../images/");
	    });
	    
	    //Concurso Pessoais
	    $j(".btnConcursoPessoais").click(function(){
	        return validateGroup("concursoPessoais", "../images/");
	    });
	    
	     //Concurso Organização
	    $j(".btnConcursoOrganizacao").click(function(){
	        return validateGroup("concursoOrganizacao", "../images/");
	    });
	    
	    //Concurso Descrição
	    $j(".btnConcursoDescricao").click(function(){
	        return validateGroup("concursoDescricao", "../images/");
	    });
	    
	    //Concurso Adicione Despesa
	    $j(".btnconcursoAdicioneDespesa").click(function(){
	        return validateGroup("concursoAdicioneDespesa", "../images/");
	    });
	       
	});
}

$j(document).ready(function(){
    
    $j(".btnVejaTabela").click(function(e){
        
        showModal("generic","generic","", "tabResumo");
	        
    });
});
