function getObj(name)
{
  if (document.getElementById)
  {
  	return document.getElementById(name);

  }
  else if (document.all)
  {
	return document.all[name];
  }
  else if (document.layers)
  {
   	return document.layers[name];
  }

}

function Login()
{
   var FormLogin = getObj('FormLogin');


  if (FormLogin.style.visibility=='hidden')
  {
      FormLogin.style.visibility='visible';
  }
  else
  {
      FormLogin.style.visibility='hidden';
  }

}

function PopUPs(URL, Largura, Altura)
{
    window.open(URL,'Detalhe','toolbar=no,location=no,status=no,menubar=no,scrollbars=no,resizable=no,width='+Largura+',height='+Altura+'');
}

function MostraIMGProduto(URL)
{
    window.open(URL,'Imagem','status=no,resizable=no,scrollbars=no,menubar=no,width=550,height=425,left=15,top=20') ;
}


function AbrirTela(Tela)
{
    x_AbrirTela(Tela, AbrirTelaCallBack);
}

function AbrirTelaCallBack(Resultado)
{
    WorkStation = getObj('WorkStation');
    WorkStation.innerHTML = Resultado;
}

function InicializaCamposColor()
{
    var ObjetosText = document.body.getElementsByTagName("input");
    var aux;
    var ObjetoFocus;

    for (i = 0; i < ObjetosText.length; i++)
    {

        if (((ObjetosText[i].type == 'text') || (ObjetosText[i].type == 'password')) && (ObjetosText[i].onblur == null) && (ObjetosText[i].onfocus == null))
        {

            if(aux!=1) { ObjetoFocus = ObjetosText[i]; }
            ObjetosText[i].onfocus = function () { enterComponente(this);  }
            ObjetosText[i].onblur =  function () { exitComponente(this);  }
            aux = 1;
        }
    }

    ObjetoFocus.focus();
}

function SetFocusObjeto(ObjetoID)
{
    Objeto = getObj(ObjetoID);
    Objeto.focus();
}

function enterComponente(e)
{
    e.style.background = "#FEF0E7";
}

function exitComponente(e)
{
    e.style.background = "#FFFFFF";
}


function MostraTelaFeedBack(msg)
{
    var DivResultado = getObj('DivResultado');


    DivResultado.innerHTML="<div>"+
    "<table border='0' cellpadding='2' width='300' cellspacing='2'>"+
      "<tr>"+
        "<td width='100%'>"+
            "<p align='center'><img border='0' src='img/progress.gif'>"+msg+"</p>"+
        "</td>"+
      "</tr>"+
    "</table>"+
    "</div>";
}

function FechaDivFeedBack()
{

    var DivFeedBack = getObj('DivResultado');
    DivFeedBack.style.visibility="hidden";
}

function LimpaINPUT(divPai)
{
    Objetos = document.getElementById(divPai).getElementsByTagName('input');
    var Contador = 0;

    for (var i = 0; i < Objetos.length; i++)
    {
        if((Objetos[i].type == 'text') || (Objetos[i].type == 'textarea'))
        {
            if(Contador==1)
            {
                var objetoFoco = Objetos[i];
            }
            Objetos[i].value='';
            Contador++;
        }
    }
    objetoFoco.focus();
}

function mostraProduto(IDDivProduto)
{
    var DivProduto = getObj(IDDivProduto);
    
    if(DivProduto.style.visibility == 'hidden')
    {
       DivProduto.style.visibility = 'visible';
       DivProduto.style.top = '190px';
    }
    else
    {
       DivProduto.style.visibility = 'hidden';
    }
}


function emBranco(parametros)
{

   var pedacoString = "";
   var stringTemporaria = "";
	
   for(var i = 0; i < parametros.length; i++)
   {
	pedacoString = parametros.substr(i,1);
	if(pedacoString!=',')
	{
	    stringTemporaria+= pedacoString;
	}
	else
	{   
	   
	    var objetoTemporario = getObj(stringTemporaria);

	    if(typeof(objetoTemporario) == 'object')
	    {
	        if((objetoTemporario.type == 'text'))
		{  
		    if(objetoTemporario.value.length == 0)
		    {
    			return false;
		    }		
		}
 		else
	        if((objetoTemporario.type == 'textarea'))
		{
		    if(objetoTemporario.text.length == 0)
		    {
    			return false;
		    }		
		}
	    }	
	    else
	    {
		alert('Desculpe, um dos elementos informados não existe: '+ stringTemporaria);
	        return false;
            }	
	
	    stringTemporaria = '';
	}
   }

   return true;
}



