var isNN = (navigator.appName.indexOf("Netscape")!=-1);

//Disabilita todos os elementos de um formulário
function disEl (form) {
  for (i=0;i<form.length;i++) {
  	form.elements[i].disabled = true
  }
} 

//Habilita todos os elementos de um formulário
function enaEl (form) {
  for (i=0;i<form.length;i++) {
  	form.elements[i].disabled = false
  }
}

function logoff (pgLogoff) {
	parent.window.location = pgLogoff
}

var preEl ;
var orgBColor;
var orgTColor;
function HighLightTR(backColor,textColor){  
  if(typeof(preEl)!='undefined') {
    preEl.bgColor=orgBColor; 
    try{ChangeTextColor(preEl,orgTColor);}catch(e){;}
  } 

  var el = event.srcElement;
  el = el.parentElement;
  orgBColor = el.bgColor;
  orgTColor = el.style.color;
  el.bgColor=backColor;

  try{ChangeTextColor(el,textColor);}catch(e){;}
  preEl = el; 
}

function ChangeTextColor(a_obj,a_color){  ;
  for (i=0;i<a_obj.cells.length;i++){
  a_obj.cells(i).style.color=a_color; 
  }
}

function autoTab(input,len, e)
{
  var keyCode = (isNN) ? e.which : e.keyCode; 
  var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
  if(input.value.length >= len && !containsElement(filter,keyCode))
	{
    input.value = input.value.slice(0, len);
    input.form[(getIndex(input)+1) % input.form.length].focus();
  }
  function containsElement(arr, ele)
	{
     var found = false, index = 0;
     while(!found && index < arr.length)
     if(arr[index] == ele) found = true;
     else index++;
     return found;
  } 
  function getIndex(input)
	{
    var index = -1, i = 0, found = false; 
     while (i < input.form.length && index == -1)
     if (input.form[i] == input)index = i;
     else i++;
     return index;
  }
  return true;
}

//Formata um valor monetário
function FormataValor(campo,tammax,e)
{
  if (isNN) return;
  var keyCode = e.keyCode; 
  //var keyCode = (isNN) ? e.which : e.keyCode; 
  vr=campo.value;
  vr=vr.replace("/","");
  vr=vr.replace("/","");
  vr=vr.replace(",","");
  vr=vr.replace(".","");
  vr=vr.replace(".","");
  vr=vr.replace(".","");
  vr=vr.replace(".","");
  tam = vr.length;
  if(tam < tammax && keyCode != 8) tam=vr.length+1;
  if(keyCode == 8) tam=tam-1;
  if(keyCode == 8 || keyCode >= 48 && keyCode <= 57 || keyCode >= 96 && keyCode <= 105 )
	{
     if(tam <= 2) 
		   campo.value=vr;
     if((tam > 2)&&(tam <= 5))  
		   campo.value=vr.substr(0,tam-2) + ',' + vr.substr(tam-2,tam);
     if((tam >= 6)&&(tam <= 8)) 
		   campo.value=vr.substr(0,tam-5) + '.' + vr.substr(tam-5,3) + ',' + vr.substr(tam-2,tam);
     if((tam >= 9)&&(tam <= 11)) 
		   campo.value=vr.substr(0,tam-8) + '.' + vr.substr(tam-8,3) + '.' + vr.substr(tam-5,3) + ',' + vr.substr(tam-2,tam);
     if((tam >= 12)&&(tam <= 14)) 
		   campo.value=vr.substr(0,tam-11) + '.' + vr.substr(tam-11,3) + '.' + vr.substr(tam-8,3) + '.' + vr.substr(tam-5,3) + ',' + vr.substr(tam-2,tam);
     if((tam >= 15)&&(tam <= 17)) 
		   campo.value=vr.substr(0,tam-14) + '.' + vr.substr(tam-14,3) + '.' + vr.substr(tam-11,3) + '.' + vr.substr(tam-8,3) + '.' + vr.substr(tam-5,3) + ',' + vr.substr(tam-2,tam);  
  }			
}

//Formata um valor monetário
function FormataValor2(campo,tammax,e)
{
  if (isNN) return;
  var keyCode = e.keyCode; 
  //var keyCode = (isNN) ? e.which : e.keyCode; 
  vr=campo.value;
  vr=vr.replace("/","");
  vr=vr.replace("/","");
  vr=vr.replace(",","");
  vr=vr.replace(".","");
  vr=vr.replace(".","");
  vr=vr.replace(".","");
  vr=vr.replace(".","");
  tam = vr.length;
  if(tam < tammax && keyCode != 8) tam=vr.length+1;
  if(keyCode == 8) tam=tam-1;
  if(keyCode == 8 || keyCode >= 48 && keyCode <= 57 || keyCode >= 96 && keyCode <= 105 )
	{
     if(tam <= 2) 
		   campo.value=vr;
     if((tam > 2)&&(tam <= 5))  
		   campo.value=vr.substr(0,tam-2) + '.' + vr.substr(tam-2,tam);
     if((tam >= 6)&&(tam <= 8)) 
		   campo.value=vr.substr(0,tam-5) + ',' + vr.substr(tam-5,3) + '.' + vr.substr(tam-2,tam);
     if((tam >= 9)&&(tam <= 11)) 
		   campo.value=vr.substr(0,tam-8) + ',' + vr.substr(tam-8,3) + ',' + vr.substr(tam-5,3) + '.' + vr.substr(tam-2,tam);
     if((tam >= 12)&&(tam <= 14)) 
		   campo.value=vr.substr(0,tam-11) + ',' + vr.substr(tam-11,3) + ',' + vr.substr(tam-8,3) + ',' + vr.substr(tam-5,3) + '.' + vr.substr(tam-2,tam);
     if((tam >= 15)&&(tam <= 17)) 
		   campo.value=vr.substr(0,tam-14) + ',' + vr.substr(tam-14,3) + ',' + vr.substr(tam-11,3) + ',' + vr.substr(tam-8,3) + ',' + vr.substr(tam-5,3) + '.' + vr.substr(tam-2,tam);  
  }		
}

//Formata data com MASCARA dd/mm/aaaa coloca as barras (/) sozinho
function FormataData(campo)
{
  if (isNN) return;
  campo.value = FiltraCampo(campo);
  vr = campo.value;
  tam = vr.length;
  if (tam > 2 && tam < 5)
	  campo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
  if ( tam >= 5 && tam <= 10 ) 
	  campo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
}

function FiltraCampo(campo)
{
  var s = "";
  var cp = "";
  vr = campo.value;
  tam = vr.length;
  for (i = 0; i < tam ; i++)
	{  
    if (vr.substring(i,i + 1) != "/" && vr.substring(i,i + 1) != "-" && vr.substring(i,i + 1) != "."  && vr.substring(i,i + 1) != "," )
		{
  	  s = s + vr.substring(i,i + 1);
    }
  }
  campo.value = s;
  return cp = campo.value
}

//Formata CPF com 000.000.000-00
function FormataCPF(pForm,pCampo,pTamMax,pPos1,pPos2,pPosTraco,pTeclaPres)
{
	var wTecla, wVr, wTam;	
	var nerros=true;
	
  wTecla = pTeclaPres.keyCode;
	wVr = pForm[pCampo].value;
	wVr = wVr.toString().replace( "-", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( "/", "" );
	wTam = wVr.length ;
	
	if (wTam < pTamMax && wTecla != 8) 
	{ 
	   wTam = wVr.length + 1 ; 
	}

	if (wTecla == 8 ) 
	{ 
	   wTam = wTam - 1 ; 
	}
			
	if ( wTecla == 8 || wTecla == 88 || (wTecla >= 48 && wTecla <= 57) || (wTecla >= 96 && wTecla <= 105) )
	{
		if ( wTam <= 2 )
		{
	 		pForm[pCampo].value = wVr ;
		}
		if (wTam > pPosTraco && wTam <= pTamMax) 
		{
	       wVr = wVr.substr(0, wTam - pPosTraco) + '-' + wVr.substr(wTam - pPosTraco, wTam);
		}
		if ( wTam == pTamMax)
		{
		      wVr = wVr.substr( 0, wTam - pPos1 ) + '.' + wVr.substr(wTam - pPos1, 3) + '.' + wVr.substr(wTam - pPos2, wTam);
		}
		pForm[pCampo].value = wVr;
		pForm[pCampo].value = toInteger(pForm[pCampo].value);
		nerros=true;
	}
	else
	{		
		pForm[pCampo].value = toInteger(pForm[pCampo].value);
		nerros = false;				
	}
	if (wTecla == 9) nerros = true;
	return nerros;
}

// format valores no formulario
function FormataValorDisplay(pForm, pCampo, pTamMax, pVirgula) 
{
	wVr = pForm[pCampo].value;
	wVr = wVr.toString().replace( "/", "" );
	wVr = wVr.toString().replace( "/", "" );
	wVr = wVr.toString().replace( ",", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wTam = wVr.length;

      if (pVirgula == 1) {
		if ( wTam <= 2 ){ 
	 		pForm[pCampo].value = wVr ; }
	 	if ( (wTam > 2) && (wTam <= 5) ){
		   pForm[pCampo].value = wVr.substr( 0, wTam - 2 ) + ',' + wVr.substr( wTam - 2, wTam ) ; }
	 	if ( (wTam >= 6) && (wTam <= 8) ){
    	   pForm[pCampo].value = wVr.substr( 0, wTam - 5 ) + '.' + wVr.substr( wTam - 5, 3 ) + ',' + wVr.substr( wTam - 2, wTam ) ; }
	 	if ( (wTam >= 9) && (wTam <= 11) ) {
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 8 ) + '.' + wVr.substr( wTam - 8, 3 ) + '.' + wVr.substr( wTam - 5, 3 ) + ',' + wVr.substr( wTam - 2, wTam ) ; }
	 	if ( (wTam >= 12) && (wTam <= 14) ){
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 11 ) + '.' + wVr.substr( wTam - 11, 3 ) + '.' + wVr.substr( wTam - 8, 3 ) + '.' + wVr.substr( wTam - 5, 3 ) + ',' + wVr.substr( wTam - 2, wTam ) ; }
	 	if ( (wTam >= 15) && (wTam <= 17) ){
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 14 ) + '.' + wVr.substr( wTam - 14, 3 ) + '.' + wVr.substr( wTam - 11, 3 ) + '.' + wVr.substr( wTam - 8, 3 ) + '.' + wVr.substr( wTam - 5, 3 ) + ',' + wVr.substr( wTam - 2, wTam ) ;}
     } else { 
		if ( wTam <= 3 ){ 
	 		pForm[pCampo].value = wVr ; }
	 	if ( (wTam > 3) && (wTam <= 6) ){
		   pForm[pCampo].value = wVr.substr( 0, wTam - 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ; }
	 	if ( (wTam >= 7) && (wTam <= 9) ) {
    	   pForm[pCampo].value = wVr.substr( 0, wTam - 6 ) + '.' + wVr.substr( wTam - 6, 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ; }
	 	if ( (wTam >= 10) && (wTam <= 12) ) {
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 9 ) + '.' + wVr.substr( wTam - 9, 3 ) + '.' + wVr.substr( wTam - 6, 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ; }
	 	if ( (wTam >= 13) && (wTam <= 15) ){
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 12 ) + '.' + wVr.substr( wTam - 12, 3 ) + '.' + wVr.substr( wTam - 9, 3 ) + '.' + wVr.substr( wTam - 6, 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ; }
	 	if ( (wTam >= 16) && (wTam <= 18) ){
	 		pForm[pCampo].value = wVr.substr( 0, wTam - 15 ) + '.' + wVr.substr( wTam - 15, 3 ) + '.' + wVr.substr( wTam - 12, 3 ) + '.' + wVr.substr( wTam - 9, 3 ) + '.' + wVr.substr( wTam - 6, 3 ) + '.' + wVr.substr( wTam - 3, wTam ) ;}
	 }
}

//verifica cpf
function VCPF( obj )
 {		
	var wVr, wVrCPF, wVrSEQ, wTam, wSoma, wSoma2, i, j, wDig1, wDig2,aux,
	    wVETOR_CC = new Array(11),
	    wVETOR_PESO = new Array(11);
 	var Erro = false;
	wVrCPF = obj.value;
	
	if (wVrCPF != '')
	{
	
  	aux = obj.value;	  
  	wVr= aux.toString().substring(0,3) + aux.toString().substring(4,7) + aux.toString().substring(8,11) + aux.toString().substring(12,14) ;     
  	wTam = wVr.length + 1;
    if (wTam < 11)
    {
    	  alert("Nº de dígitos do CPF menor que o normal. Redigite !!!");
    	  obj.value = "";
    	  obj.focus();
    	  return false;
    }    
  	for (i = 0; i < wVr.length; i++)
  	{
  	   if (isNaN(parseInt(wVr.charAt(i))) )
  		 {
    	     alert("O CPF contém dígitos inválidos. Corrija-o !!!");
  	     obj.value = "";
  	     obj.focus();
  	     return false;
  	   }
  	}
    wSoma = 0;
  	wSoma2 = 0;
    j = 2;
    for (i = 0; i < 11; i++)
    {
      wVETOR_CC[i] = wVr.charAt(i);
      wVETOR_PESO[i] = j;
      j++; 
    } 
    i = 0;	  
    while (i < 9) 
    {
      i++;
      if (i < 10)
      {
            wSoma += wVETOR_CC[9 - i] * wVETOR_PESO[i - 1];
      }
      wSoma2 += wVETOR_CC[10 - i] * wVETOR_PESO[i - 1];
    }
  	wDig1 = (wSoma * 10) % 11;
  	wDig2 = (wSoma2 * 10) % 11;
  	if (wDig1 == 10)
  	{ 
  	    wDig1 = 0;
  	}	
  	if (wDig2 == 10)
  	{ 
  	    wDig2 = 0;
  	}		
    if (parseInt(wVr.charAt(9)) != wDig1 || parseInt(wVr.charAt(10)) != wDig2)
  	{
    	 alert("CPF com Dígito Verificador inválido. Redigite-o !!!");
			 obj.value = "";
  	   obj.focus();
  	   return false;
    }	
    obj.value = wVrCPF;
  	return true;
	}
	else
	{
	  return true;
	}
}

function FormataCGC(pForm,pCampo,pTeclaPres){
	var wTecla, wVr, wTam;	

	wTecla = pTeclaPres.keyCode;

	wVr = pForm[pCampo].value;
	wVr = wVr.toString().replace( "-", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( ".", "" );
	wVr = wVr.toString().replace( "/", "" );
	wTam = wVr.length ;

	if (wTam < 14 && wTecla != 8) { 
	   wTam = wVr.length + 1 ; 
	}

	if (wTecla == 8 ) { 
	   wTam = wTam - 1 ; 
	}

	if ( wTecla == 8 || wTecla == 88 || wTecla >= 48 && wTecla <= 57 || wTecla >= 96 && wTecla <= 105 ){
		if ( wTam <= 2 ){
	 		pForm[pCampo].value = wVr ;
		}
		if (wTam > 2 && wTam <= 14) {
		   wVr = wVr.substr(0, wTam - 2) + '-' + wVr.substr(wTam - 2, wTam);
		}
		if ( wTam == 14){
	       wVr = wVr.substr( 0, wTam - 12 ) + '.' + wVr.substr(wTam - 12, 3) + '.' + wVr.substr(wTam - 9, 3) + "/" + wVr.substr(wTam - 6, wTam);
		}
		pForm[pCampo].value = wVr;
	
	}

}

function VCGC(pForm, pCampo)
{ 
	var Numero; 
	var Digito; 
	var CNPJ ,aux = pForm[pCampo].value
	Numero = aux.toString().substring(0,2) + aux.toString().substring(3,6) + aux.toString().substring(7,10) + aux.toString().substring(11,15);
	CNPJ= aux.toString().substring(0,2) + aux.toString().substring(3,6) + aux.toString().substring(7,10) + aux.toString().substring(11,15) + aux.toString().substring(16,18);
	Digito=aux.toString().substring(16,18);
	var CGC = Numero;
	var peso1 = '543298765432';
	var peso2 = '654329876543';
	var soma1 = 0;
	var soma2 = 0;
	var digito1 = 0;
	var digito2 = 0;
          
	 if (CNPJ == '00000000000000'){
	 	alert("CNPJ Inválido. Redigite!");
		pForm[pCampo].value = "";
	  	pForm[pCampo].focus();
	  	return false;
	 } 
	 
	 if ((Numero.length + Digito.length + 1 > 1) && (Numero.length + Digito.length + 1 < 15)) 
	 {
	  alert("Nº de dígitos do CNPJ menor que o normal. Redigite !!!");
	  pForm[pCampo].value = "";
	  pForm[pCampo].focus();
	  return false;
	 }	
 
 	if (Numero.length + Digito.length + 1 > 1){
 		 
		 for (i = 1; i < 12 - Numero.length + 1; i++) 
		 {
		  CGC = eval("'" + 0 + CGC + "'")
		 }
		    
		 for (i = 1; i < CGC.length+1; i++) 
		 {
		  soma1 += CGC.substring(i, i-1) * peso1.substring(i, i-1);
		 } 
		
		 soma1 %= 11;
		
		 if (soma1  < 2) 
		 {
		  digito1 = 0;
		 }
		 else 
		 {
		  digito1 = 11 - soma1; 
		 }
		
		 for (i = 1; i < CGC.length+1; i++) 
		 {
		  soma2 += CGC.substring(i, i-1) * peso2.substring(i, i-1);
		 } 
		 
		 soma2 += digito1 * 2 
		 soma2 %= 11;
		
		 if (soma2  < 2) 
		 {
		  digito2 = 0;
		 }
		 else 
		 {
		  digito2 = 11 - soma2; 
		 }
		
		 if (eval("'" + digito1 + digito2 + "'") != Digito)
		 {
		  return false;
		 }
		 else 
		 {
		  return true;
		 }
	}
}

//Formatar Telefone
function FormataTEL(pForm, pCampo, pTeclaPres) {
	var wTecla = pTeclaPres.keyCode;
	var wTam;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "-", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 ){
		if ( wTam > 0 && wTam < 2 ) 
			pForm[pCampo].value = '(' ;
		if ( wTam > 3 && wTam < 5 ) 
			pForm[pCampo].value = wVr.substr( 0, 8 ) + ')' + wVr.substr( 8, 4 );
		if ( wTam > 7 && wTam < 9 ) 
			pForm[pCampo].value = wVr.substr( 0, 8 ) + '-' + wVr.substr( 8, 4 );
		if ( wTam > 11)
			pForm[pCampo].value = wVr.substr( 0, 8 ) + '-' + wVr.substr( 8, 4 ); 
	}			
}

function keyLowerCase() 
{
 var tecla;
 var key; 
 if(navigator.appName.indexOf("Netscape")!= -1) 
    tecla= event.which; 
 else 
    tecla= event.keyCode; 

 if ( tecla>=65 && tecla<=90 ) 
 {
    key = String.fromCharCode(tecla); 
    key = key.toLowerCase();
    event.keyCode=key.charCodeAt();
 }
}

function keyUpCase() 
{
 var tecla;
 var key; 
 if(navigator.appName.indexOf("Netscape")!= -1) 
    tecla= event.which; 
 else 
    tecla= event.keyCode; 
 if ( tecla>=97 && tecla<=122 )
 {
    key = String.fromCharCode(tecla); 
    key = key.toUpperCase();
    event.keyCode=key.charCodeAt();
 }	
}

function CampoUpcase(pForm, pCampo, pOperacao)
{
   if (pOperacao == "+")
	 {
     pForm[pCampo].value = pForm[pCampo].value.toUpperCase();
   }
	 else
	 {
     pForm[pCampo].value = pForm[pCampo].value.toLowerCase();
   }
}

function FormataCEP(pForm, pCampo, pTeclaPres) {
	var wTecla = pTeclaPres.keyCode;
	var wTam;
	wVr = pForm[pCampo].value;
	wVr = wVr.replace( ".", "" );
	wVr = wVr.replace( "-", "" );
	wVr = wVr.replace( "/", "" );
	wTam = wVr.length + 1;

	if ( wTecla != 9 && wTecla != 8 ){
		if ( wTam > 2 && wTam < 6 )
			pForm[pCampo].value = wVr.substr( 0, wTam - 2  ) + '.' + wVr.substr( wTam - 2, wTam );
		if ( wTam >= 6 && wTam <= 9 )
			pForm[pCampo].value = wVr.substr( 0, 2 ) + '.' + wVr.substr( 2, 3 ) + '-' + wVr.substr( 5, 3 ); 
	}			
}

function VerificaEmail(pcampo)
{ 
	  pcampo.value = pcampo.value.toLowerCase();					
    parametro = pcampo.value;								
	  teste_parametro = "false"; 
	  tamanho_parametro = parametro.length;
	  aposicao = 0; //posicao @
	  pposicao = 0; //poiscao ponto
	  narrobas = 0; // numero de @
	  for (i = 0; i < tamanho_parametro; i++) { /*verifica se existe espaco em branco */
		   if (parametro.charAt(i) == "@") {
		  	     narrobas = narrobas + 1
				 aposicao = i;
		   }
		   if (parametro.charAt(i) == ".") {
		  	     
				 pposicao = i;
		   }
		   
	   }
	   if (aposicao > 0 && aposicao+1 < pposicao && narrobas<2){
     	   teste_parametro = "true"; 
	   }	   
      	  
	  for (i = 0; i < tamanho_parametro; i++) { /*verifica se existe espaco em branco */
		   if (parametro.charAt(i) == " ") {
		  	     teste_parametro = "false"; 
		   }
	   }
		
	   if (tamanho_parametro < 5) {
	   	  teste_parametro = "false"; /*tamanho minimo*/
	   }
	  
			
	   if (parametro.charAt(0) == " " || parametro.charAt(1) == " ") { /*Primeiros chars em branco */
			  teste_parametro = "false"; 
	   }
				
		
		if (teste_parametro == "false" && tamanho_parametro != 0 ) { /*Existe algum problema no preenchiento do nome */
			alert("E-mail inválido!");
			pcampo.focus();
			return false;
		} else {
			return true;
		}
}

function LTrim(str)
{
        var whitespace = new String(" \t\n\r");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(0)) != -1)
				{
            var j=0, i = s.length;
            while (j < i && whitespace.indexOf(s.charAt(j)) != -1)
                j++;
            s = s.substring(j, i);
        }
        return s;
}


function RTrim(str)
{
        var whitespace = new String(" \t\n\r");
        var s = new String(str);
        if (whitespace.indexOf(s.charAt(s.length-1)) != -1) {
            var i = s.length - 1;       // Get length of string
            while (i >= 0 && whitespace.indexOf(s.charAt(i)) != -1)
                i--;
            s = s.substring(0, i+1);
        }
        return s;
}

function Trim(str)
{
   return RTrim(LTrim(str));
}

function toInteger(checkString)
{
 var newString = "";    
 var count = 0;         
    for (i = 0; i < checkString.length; i++) {
        ch = checkString.substring(i, i+1);
        if (ch >= "0" && ch <= "9") 
        {
            newString += ch;
        }
        else
        {
         if (ch == "-") newString += ch;
         if (ch == ".") newString += ch;
         if (ch == "/") newString += ch;
        }
    }    
    return newString; //checkString;
}

function popup_animado(endereco,largura,altura,vh,vv)
{
  var velocidadev = vh; 
  var velocidadeh = vv;
	var esquerda = (screen.width-largura)/2;
  var topo = (screen.height-altura)/2;
  if (document.all)
	{
		var tamlar = altura;
    var tamjan = largura;
    var tamanho = window.open("","","left=" + esquerda + ",top=" + topo + ",width=1,height=1,titlebar=0,toolbar=0,menubar=0,directories=0,location=0,resizable=0,status=0,scrollbars=0");
    for (sizeheight = 1; sizeheight < tamlar; sizeheight += velocidadev)
		{
      tamanho.resizeTo("1",sizeheight );
		}
    for (sizewidth = 1; sizewidth < tamjan; sizewidth += velocidadeh)
		{
		  tamanho.resizeTo(sizewidth+6,sizeheight);
		}
		tamanho.location = endereco;
	}
	else
	{
    window.location = endereco;
	}
}

function popup_center(a,b,w,h,scroll)
// a=endereco ; b=titulo
{	  		
	var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
	var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no,';
			settings +='titlebar=no,';
      settings +='toolbar=no,';     
      settings +='location=no,';    
      settings +='directories=no,'; 
      settings +='status=yes,';  
			settings +='menubar=no';  
  NewWin2 = window.open(a,b,settings);
  if(parseInt(navigator.appVersion) >= 4){NewWin2.window.focus();}						
}

function popup_center2(a,b,w,h,scroll)
{	  		
	var winl = (screen.width-w)/2;
  var wint = (screen.height-h)/2;
	var settings  ='height='+h+',';
      settings +='width='+w+',';
      settings +='top='+wint+',';
      settings +='left='+winl+',';
      settings +='scrollbars='+scroll+',';
      settings +='resizable=no,';
			settings +='titlebar=no,';
      settings +='toolbar=no,';     
      settings +='location=no,';    
      settings +='directories=no,'; 
      settings +='status=yes,';  
			settings +='menubar=no';  
  NewWin2 = window.open(a,b,settings);
  if(parseInt(navigator.appVersion) >= 4){NewWin2.window.focus();}						
}

function proximo_campo( pForm, pCampo )
{
  //Se a tecla for <ENTER> passa para o proximo campo
	if( window.event.keyCode == 13 )
	{	  		
		pForm[pCampo].focus();
		if( pForm[pCampo].value.length > 0 )
		{
		  pForm[pCampo].select();
		}
	}
}

//Checa o minimo de caracteres permitidos para o campo passado como parametro
function check_min_caracter( pForm, pCampo, NumMin )
{  
	if( (pForm[pCampo].value.length !=0) && (pForm[pCampo].value.length < NumMin) )
	{
	  alert("Este campo deve ter no mínimo "+NumMin+" caracteres");
		pForm[pCampo].select();		
	}
}

function check_int_return( pCampo )
{
  var num = /[^0123456789]/;
  num = num.exec( pCampo.value ); 
	if (num != null)
	{
    return false;
	}
	return true;  
}

//Checa se o campo passado como parametro é inteiro
function check_int( pCampo )
{
  var num = /[^,.0123456789]/;
  num = num.exec( pCampo.value ); 
	if (num != null)
  {     
     alert("Este campo só aceita números.");
     pCampo.value = "";		 
		 pCampo.focus();		 
     return false;
  }
	return true;  
}

function check_int2( pCampo )
{
  var num = /[^0123456789]/;
	if( pCampo.value.length > 0 )
	{
    num = num.exec( pCampo.value );
  	if (num != null)
    {     
       alert("Este campo só aceita números inteiros.");
  		 pCampo.value = "";
			 pCampo.focus();		      
    }
	}	  
}

function check_int2_return( pCampo )
{
  var num = /[^0123456789]/;
	if( pCampo.value.length > 0 )
	{
    num = num.exec( pCampo.value );
  	if (num != null)
    {     
       return false;
    }
		return true;
	}	  
}

function proximo_campo_tam( pForm, pCampoAnt, pCampoPx, pTam )
{  
	if( pForm[pCampoAnt].value.length == pTam )
	{	  		
		pForm[pCampoPx].focus();
		if( pForm[pCampoPx].value.length > 0 )
		{
		  pForm[pCampoPx].select();
		}
	}
}

function maximiza()
{
  self.resizeTo(screen.availWidth,screen.availHeight);
  self.moveTo(0,0);
}

function MM_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}

function ajax_carrega_curso( obj_filial,monta_turma,id_curso_default )
{
	var id_filial = obj_filial.value;	
	if( id_filial != '' )
	{
	  ajax_carrega( 'ajax_monta_curso.php?id_filial='+id_filial+'&monta_turma='+monta_turma+'&id_curso_pesq='+id_curso_default, 'div_curso', 'Carregando Curso ...' );
		document.getElementById('div_titulo_curso').style.display = 'block';
  }
	else
	{
		document.getElementById('div_curso').innerHTML = "";
		document.getElementById('div_titulo_curso').style.display = 'none';		
		document.getElementById('div_curso').style.display = 'none';
		if( monta_turma == true )
		{
			document.getElementById('div_turma').innerHTML = "";
			document.getElementById('div_titulo_turma').style.display = 'none';		
			document.getElementById('div_turma').style.display = 'none';
		}
	}
} 

function ajax_carrega_turma( obj_curso,id_turma_default )
{
	var id_curso = obj_curso.value;	
	if( id_curso != '' )
	{
	  ajax_carrega( 'ajax_monta_turma.php?id_curso='+id_curso+'&id_turma_pesq='+id_turma_default, 'div_turma', 'Carregando Turma ...' );
		document.getElementById('div_titulo_turma').style.display = 'block';
  }
	else
	{
		document.getElementById('div_turma').innerHTML = "";
		document.getElementById('div_titulo_turma').style.display = 'none';		
		document.getElementById('div_turma').style.display = 'none';
	}
} 

function paginacao( pagina )
{
	document.forms.frm_busca['pagina'].value = pagina;
	document.forms.frm_busca.submit();
}

function confirma_del2( url )
{
	if( confirm("Deseja realmente apagar o registro ?") == true )
	{
		processa.document.location = url;
	}
}

function confirma_del_busy( url )
{
	if( document.forms.frm_busca['busy'].value == 0 )
	{
		if( confirm("Deseja realmente apagar o registro ?") == true )
		{
			processa.document.location = url;
		}		
	}
	else
	{
		alert(" ... Em processamento ... \nAguarde!");
	}
}

function vai_busy( url )
{
	if( document.forms.frm_busca['busy'].value == 0 )
	{
		document.location = url;
	}
	else
	{
		alert(" ... Em processamento ... \nAguarde!");
	}	
}

function confirma( url, msg )
{
	if( confirm(msg) == true )
	{
		processa.document.location = url;
	}
}

function texto_div( div_,texto )
{
	var div_resultado = document.getElementById(div_);	
	div_resultado.innerHTML = texto; 		
}

function ajax_carrega_subtipo( obj_tipo_imovel,monta_categoria,id_subtipo_imovel_default )
{
	var id_tipo_imovel = obj_tipo_imovel.value;	
	if( id_tipo_imovel != '' )
	{
	  ajax_carrega( 'ajax_monta_subtipo_imovel.php?id_tipo_imovel='+id_tipo_imovel+'&monta_categoria='+monta_categoria+'&id_subtipo_imovel_pesq='+id_subtipo_imovel_default, 'div_subtipo', 'Carregando Subtipo ...' );
		document.getElementById('div_titulo_subtipo').style.display = 'block';
		document.getElementById('div_categoria').innerHTML = "";
		document.getElementById('div_titulo_categoria').style.display = 'none';		
		document.getElementById('div_categoria').style.display = 'none';
  }
	else
	{
		document.getElementById('div_subtipo').innerHTML = "";
		document.getElementById('div_titulo_subtipo').style.display = 'none';		
		document.getElementById('div_subtipo').style.display = 'none';
		if( monta_categoria == true )
		{
			document.getElementById('div_categoria').innerHTML = "";
			document.getElementById('div_titulo_categoria').style.display = 'none';		
			document.getElementById('div_categoria').style.display = 'none';
		}
	}
}

function ajax_carrega_subtipo_nome( obj_tipo_imovel,monta_categoria,id_subtipo_imovel_default,nome,nome_categ,div_subtipo,div_titulo_subtipo,div_categoria,div_titulo_categoria )
{	
	var id_tipo_imovel = obj_tipo_imovel.value;
  if( id_tipo_imovel != '' )
	{
	  ajax_carrega( 'ajax_monta_subtipo_imovel.php?id_tipo_imovel='+id_tipo_imovel+'&monta_categoria='+monta_categoria+'&id_subtipo_imovel_pesq='+id_subtipo_imovel_default+'&nome='+nome+'&nome_categ='+nome_categ+'&div_subtipo='+div_subtipo+'&div_titulo_subtipo='+div_titulo_subtipo+'&div_categoria='+div_categoria+'&div_titulo_categoria='+div_titulo_categoria, div_subtipo, 'Carregando Subtipo ...' );
		document.getElementById(div_titulo_subtipo).style.display = 'block';
		document.getElementById(div_categoria).innerHTML = "";
		document.getElementById(div_titulo_categoria).style.display = 'none';		
		document.getElementById(div_categoria).style.display = 'none';
  }
	else
	{
		document.getElementById(div_subtipo).innerHTML = "";
		document.getElementById(div_titulo_subtipo).style.display = 'none';		
		document.getElementById(div_subtipo).style.display = 'none';
		if( monta_categoria == true )
		{
			document.getElementById(div_categoria).innerHTML = "";
			document.getElementById(div_titulo_categoria).style.display = 'none';		
			document.getElementById(div_categoria).style.display = 'none';
		}
	}
}

function ajax_carrega_categoria( obj_subtipo_imovel,id_categoria_default )
{
	var id_subtipo_imovel = obj_subtipo_imovel.value;	
	if( id_subtipo_imovel != '' )
	{
	  ajax_carrega( 'ajax_monta_categoria.php?id_subtipo_imovel='+id_subtipo_imovel+'&id_categoria_pesq='+id_categoria_default, 'div_categoria', 'Carregando Categoria ...' );
		document.getElementById('div_titulo_categoria').style.display = 'block';
  }
	else
	{
		document.getElementById('div_categoria').innerHTML = "";
		document.getElementById('div_titulo_categoria').style.display = 'none';		
		document.getElementById('div_categoria').style.display = 'none';
	}
}

function ajax_carrega_categoria_nome( obj_subtipo_imovel,id_categoria_default,nome_categ,div_categoria,div_titulo_categoria )
{
	var id_subtipo_imovel = obj_subtipo_imovel.value;		
	if( id_subtipo_imovel != '' )
	{
	  ajax_carrega( 'ajax_monta_categoria.php?id_subtipo_imovel='+id_subtipo_imovel+'&id_categoria_pesq='+id_categoria_default+'&nome_categ='+nome_categ, div_categoria, 'Carregando Categoria ...' );
		document.getElementById(div_titulo_categoria).style.display = 'block';
  }
	else
	{
		document.getElementById(div_categoria).innerHTML = "";
		document.getElementById(div_titulo_categoria).style.display = 'none';		
		document.getElementById(div_categoria).style.display = 'none';
	}
}

function mostra_esconde( se )
{	
  if( document.getElementById(se).style.display == 'none' )
  {
	  document.getElementById(se).style.display = 'block';
		//return true;
	}
	else
	{
	 document.getElementById(se).style.display = 'none';
	 //return true;
	}	
}

function mostra_div( div_, mostra )
{
	var obj_div = document.getElementById(div_);
	obj_div.style.display = mostra;
}

function grava_posicao(posicao,id_img,id_frm)
{	
	var form = document.getElementById(id_frm);
	var img1 = document.getElementById(id_img+'_1');
	var img2 = document.getElementById(id_img+'_2');
	var img3 = document.getElementById(id_img+'_3');
	var img4 = document.getElementById(id_img+'_4');	
	img1.style.borderStyle = 'none';
	img2.style.borderStyle = 'none';
	img3.style.borderStyle = 'none';
	img4.style.borderStyle = 'none';
	if( posicao == '1' ){
		//Cima Esquerda
		img1.style.borderStyle = 'solid';
		img1.style.borderWidth = '3px';
		img1.style.borderColor = '#868622';		
		form.posicao.value = 'cima_esquerda';
	}
	if( posicao == '2' ){
		//Cima Direita
		img2.style.borderStyle = 'solid';
		img2.style.borderWidth = '3px';
		img2.style.borderColor = '#868622';		
		form.posicao.value = 'cima_direita';
	}
	if( posicao == '3' ){
		//Baixo Direita
		img3.style.borderStyle = 'solid';
		img3.style.borderWidth = '3px';
		img3.style.borderColor = '#868622';		
		form.posicao.value = 'baixo_direita';
	}
	if( posicao == '4' ){
		//Baixo Esquerda
		img4.style.borderStyle = 'solid';
		img4.style.borderWidth = '3px';
		img4.style.borderColor = '#868622';		
		form.posicao.value = 'baixo_esquerda';
  }
}

function envia_email_imovel_unico( id_imovel, id_atendido )
{
	if( confirm("Deseja realmente enviar email deste imóvel para este atendido ?") == true )
	{
		processa.document.location = 'imovel_envia_email_atendido_unico.php?id_imovel='+id_imovel+'&id_atendido='+id_atendido;
	}
}

function anima_rezise_iframe( iframe, altura, sinal ){	
	if( parar != true ){
	  var parar = false;
	}
	var id_iframe_nome = 'id_'+iframe;
	var iframe_ = document.getElementById(id_iframe_nome);
	
	if( sinal == '-' ){
		var altura_ = Math.round(iframe_.height) - Math.round('50');
		iframe_.height = altura_;
	}
	if( sinal == '+' ){
		var altura_ = Math.round(iframe_.height) + Math.round('50');
		iframe_.height = altura_;
	}
	
	if( ( (sinal == '+')&&(iframe_.height >= altura) )||( (sinal == '-')&&(iframe_.height <= 0) ) ){
		parar = true;
	}
			
	if( parar == false ){
	  setTimeout("anima_rezise_iframe('"+iframe+"','"+altura+"','"+sinal+"');",1);
	}
}

function rezise_iframe( iframe ){	
	if( screen.width == '1280' ){
	  var altura = 400;
	}
	else{
	  var altura = 300;
	}
	var id_iframe_nome = 'id_'+iframe;
	var iframe_ = document.getElementById(id_iframe_nome);
	if( iframe_.height == altura ){
		//Minimizar
		anima_rezise_iframe( iframe, altura, '-' );
	}else{
		//Maximizar
		anima_rezise_iframe( iframe, altura, '+' );
	}
}

function conta_segundo(segundo)
{
	segundo = segundo - 1;
	var minuto = document.getElementById('div_min').innerHTML;
	
	//Mudança de estado de acordo com o tempo que falta para finalizar o pedido		
	if( minuto >= 5 )
	{
		//Piscando Verde		
		document.getElementById('div_conta_tempo').style.color = 'green';
		document.getElementById('id_imagem_pisca').src = 'images/icones/verde_piscando.gif';
	}
	if( (minuto <= 4)&&(minuto >= 2) )
	{
		//Piscando Amarelo	
		document.getElementById('div_conta_tempo').style.color = 'yellow';
		document.getElementById('id_imagem_pisca').src = 'images/icones/amarelo_piscando.gif';
	}
	if( minuto <= 1 )
	{
		//Piscando Vermelho		
		document.getElementById('div_conta_tempo').style.color = 'red';
		document.getElementById('id_imagem_pisca').src = 'images/icones/vermelho_piscando.gif';
	}
	document.getElementById('div_imagem_pisca').style.display = 'block';
	/*	
	if( (segundo == 0) && (minuto == 0) )
	{
		document.forms.form['id_vai'].value = '1';
		document.forms.form.submit();
	}
	*/
	if( segundo < 10 )
	{
		segundo_mostra = '0'+segundo;
	}
	else
	{
		segundo_mostra = segundo;
	}	
	document.getElementById('div_seg').innerHTML = segundo_mostra;		
	if( segundo > 0 )
	{		
		setTimeout("conta_segundo("+segundo+")",1000);
	}
	else if( (segundo != 0)||(minuto != 0) )
	{						
		conta_segundo('60');
		conta_tempo();
	}
}

function conta_tempo()
{	
	var minuto = document.getElementById('div_min').innerHTML;	
	minuto = minuto - 1;
	document.getElementById('div_min').innerHTML = minuto;	
}

function completa_endereco(obj, id_id_estado, id_id_cidade, id_no_cidade, id_id_bairro, id_no_bairro, id_no_logradouro)
{
	if( obj.value.length >= 3 )
	{		
		var cep = obj.value;
		//parent.document.getElementById("div_wait").innerHTML = "<table border='0' cellpadding='0' cellspacing='0' align='center'><tr><td align='center'><img src='images/ajax/indicator.gif' border='0'><br />Carregando Endereço</td></tr></table>";
		processa.document.location = 'ajax_cep.php?cep='+cep+'&id_id_estado='+id_id_estado+'&id_id_cidade='+id_id_cidade+'&id_no_cidade='+id_no_cidade+'&id_id_bairro='+id_id_bairro+'&id_no_bairro='+id_no_bairro+'&id_no_logradouro='+id_no_logradouro;
	}
}

function cronoStart(){  
	var segs = parseInt(document.forms.frm_controle_login['segundo_controle'].value);
	var mins = parseInt(document.forms.frm_controle_login['minuto_controle'].value);
	var hrs = parseInt(document.forms.frm_controle_login['hora_controle'].value);	
	segs++;	
	if( (segs == 15)||(segs == 30)||(segs == 45)||(segs == 60) ){
		var id_aluno_session = document.forms.frm_controle_login['id_aluno_session'].value;
		var id_disciplina_etapa_pass = document.forms.frm_controle_login['id_disciplina_etapa_pass'].value;
		var id_filial_pass = document.forms.frm_controle_login['id_filial_pass'].value;
		var id_curso_pass = document.forms.frm_controle_login['id_curso_pass'].value;
		var id_turma_pass = document.forms.frm_controle_login['id_turma_pass'].value;
		var id_disciplina_pass = document.forms.frm_controle_login['id_disciplina_pass'].value;
		processa_tempo.document.location = "grava_tempo_aluno_disciplina.php?id_aluno_session="+id_aluno_session+"&id_disciplina_etapa_pass="+id_disciplina_etapa_pass+"&id_filial_pass="+id_filial_pass+"&id_curso_pass="+id_curso_pass+"&id_turma_pass="+id_turma_pass+"&id_disciplina_pass="+id_disciplina_pass;		
	}
	if(segs == 60){ 
	  mins++;  
		segs=0;  
		if(mins == 60){
		  hrs++;
			mins=0;
		}	
	}	
	var formSegs=(segs < 10) ? "0"+segs : segs;	
	var formMins=(mins < 10) ? "0"+mins : mins;	
	var formHrs=(hrs < 10) ? "0"+hrs : hrs;
	//Atualizar no div
	document.getElementById('div_seg').innerHTML = formSegs;
	document.getElementById('div_min').innerHTML = formMins;
	document.getElementById('div_hora').innerHTML = formHrs;
	//Atualizar no cotrole
	document.forms.frm_controle_login['segundo_controle'].value = segs;
	document.forms.frm_controle_login['minuto_controle'].value = mins;
	document.forms.frm_controle_login['hora_controle'].value = hrs;
	setTimeout("cronoStart();",1000);
}

function expande_textarea(sinal,id_obj){
	if( sinal == '+' ){
		document.getElementById(id_obj).style.height = '100px';
	}else if( sinal == '-' ){
		document.getElementById(id_obj).style.height = '19px';
	}
}

function carrega_info_filial(){
	var id_filial = document.getElementById('id_id_filial').value;
	if( id_filial ){
	  ajax_carrega('ajax_info_filial.php?id_filial='+id_filial,'div_info_filial','Carregando Filial ...');
	}
}
