/**
 * Trata os campos com valor inicial apenas descritivos que devem ser apagados quando recebe foco
 */
function recebeFoco(campo, valorInicial)
{
    if (campo.value == valorInicial)
    {
        campo.value = "";
    }
}

function perdeFoco(campo, valorInicial)
{
    if (campo.value == "")
    {
        campo.value = valorInicial;
    }
}


/**
 * Permite digitar apenas letra e número
 */
function apenasLetraNumero(e)
{
var key;
var keychar;

if (window.event)
   key = window.event.keyCode;
else if (e)
   key = e.which;
else
   return true;
keychar = String.fromCharCode(key);
keychar = keychar.toLowerCase();

// control keys
if ((key==null) || (key==0) || (key==8) || 
    (key==9) || (key==13) || (key==27) )
   return true;

// alphas and numbers
else if ((("abcdefghijklmnopqrstuvwxyz0123456789").indexOf(keychar) > -1))
   return true;
else
   return false;
}



/**
 * Muda o css de um elemento
 */
function mudaCss(elem,newClass)
{document.getElementById(elem).className=newClass; }


/**
 * Altera a seta do menu
 */ 
 
function alterarSeta(id) {
    if (document.getElementById(id).src.indexOf('maximizarPanel.gif') != -1 )
    {    
        document.getElementById(id).src = '../Imagem/Simples/Layout/minimizarPanel.gif';
    } else {
        document.getElementById(id).src = '../Imagem/Simples/Layout/maximizarPanel.gif';        
    }
}

/**
 * Seta o foco no elemento selecionado
 */ 
function SetFoco(id) 
{ 
    document.getElementById(id).focus();
}

/**
 * Imprime o frame informado como parametro
 */
function ImprimirFrame(nomeFrame){
	parent[nomeFrame].focus();
	parent[nomeFrame].print();
}

/**
 * Seta o visible como falso de qualquer elemento com esse ID
 */
function Esconder(id)
{
	el = document.getElementById(id);
	var display = el.style.display ? '' : 'none';
	el.style.display = display;
}

/**
 * Imprime o frame principal
 */
function ImprimirFramePrincipal() {
	this.print();
}

/**
 * Abre uma janela popup centralizada
 */
function AbrirPopup(pagina, nome, largura, altura, rolagem) {
	agente=navigator.userAgent.toLowerCase();
	ehExplorer=agente.indexOf('msie')!=-1?1:0;
	ehOpera=agente.indexOf('opera')==-1?0:1;
		
	if(ehExplorer==1 && ehOpera==0) {
		janelaPropriedades = 'status=no;dialogWidth=' + largura+'px;dialogHeight='+altura+'px;help=no;scroll='+rolagem;
		window.showModalDialog(pagina,window,janelaPropriedades);
	}else{
		janelaPropriedades = 'modal=yes,status=no,width=' + largura+',height='+altura+',help=no,scrollbars='+rolagem;
		window.open(pagina,window,janelaPropriedades);
	}
}

function AbrirPopupNormal(pagina, nome, largura, altura, rolagem) {
	newwindow=window.open(pagina,nome,'status=no,height=' + altura + ',width=' + largura + ',resizable=1,help=no,scrollbars='+rolagem);
	if (window.focus) {newwindow.focus()}
}

/**
 * limita o número de caracteres
 */
function LimitarTamanho(campo, tamanho) {
	if (campo.value.length > tamanho)
	{
		alert('Esse campo permite apenas ' + tamanho + ' caracteres');
		campo.value = campo.value.substring(0, tamanho);
	}
}

/**
 * seleciona todos os checkbox
 */
function SelecionarTodos (chkVal, idVal, id) 
{ 
    var frm = document.forms[0];
    // Loop through all elements
    for (i=0; i<frm.length; i++) 
    {
        // Look for our Header Template's Checkbox
        if (idVal.indexOf (idVal) != -1) 
        {
            // Check if main checkbox is checked, then select or deselect datagrid checkboxes 
            if(chkVal == true) 
            {
                frm.elements[i].checked = true;
            } 
            else 
            {
                frm.elements[i].checked = false;
            }
            // Work here with the Item Template's multiple checkboxes
        } 
        else if (idVal.indexOf (id) != -1) 
        {
            // Check if any of the checkboxes are not checked, and then uncheck top select all checkbox
            if(frm.elements[i].checked == false)
            {
                frm.elements[1].checked = false; //Uncheck main select all checkbox
            }
        }        
    }
}

/**
 * funções para manipular os botões e links de aguardar
 */
function GetDiv(sDiv)
{
	var div;
	if (document.getElementById)
		div = document.getElementById(sDiv);
	else if (document.all)
		div = eval("window." + sDiv);
	else if (document.layers)
		div = document.layers[sDiv];
	else
		div = null;

	return div;
}

function HideDiv(sDiv)
{
	d = GetDiv(sDiv);
	if (d)
	{
		if (document.layers) d.visibility = "hide";
		else d.style.visibility = "hidden";
	}
}

function PleaseWait(sDivButton, sDivMessage, sInnerHtml)
{
	HideDiv(sDivButton);
	var d = GetDiv(sDivMessage);
	if (d) d.innerHTML = sInnerHtml;
}
