function esconde() {
    if(document.getElementById("floater").style.display != "none") {
        document.getElementById("floater").style.display = "none";
    }
}

function pegaNomeServidor(){
	var url = new String(location.href);
	var res = url.split("/");
	var servidor = res[2];
	return servidor;
}

function abreJanela(url, largura, altura){
	var winl = (screen.width - largura) / 2;
	var wint = (screen.height - altura) / 2;
	window.open(url,'Sistema','width='+largura+',height='+altura+',top='+wint+',left='+winl+',status=0,titlebar=0,toolbar=0,menubar=0,resizable=yes,scrollbars=no');	
}

function selOver(objeto) {
	objeto.style.backgroundColor='#316ac5';
	objeto.style.color='#FFFFFF';
}
function selOut(objeto) {
	objeto.style.backgroundColor='';
	objeto.style.color='';
}
function tituloOver(objeto) {
	objeto.style.backgroundColor='#faf8f3';
	objeto.style.borderBottomColor='#f9b119';
}
function tituloOut(objeto) {
	objeto.style.backgroundColor='';
	objeto.style.borderColor='';
}
function popup(url, name, width, height)
{
   var str = "height=" + height + ",innerHeight=" + height;
		str += ",width=" + width + ",innerWidth=" + width;
		str += ",status=no,scrollbars=yes,resizable=no";
		  if (window.screen)
		{
				var ah = screen.availHeight - 30;
				var aw = screen.availWidth - 10;
				var xc = (aw - width) / 2;
				var yc = (ah - height) / 2;

				str += ",left=" + xc + ",screenX=" + xc;
				str += ",top=" + yc + ",screenY=" + yc;
		}
		var win = window.open(url, name, str);
}
function listagem(url)
{
	var height = "450";
	var width = "600";
	var name = "Resultado";
   var str = "height=" + height + ",innerHeight=" + height;
		str += ",width=" + width + ",innerWidth=" + width;
		str += ",status=yes,scrollbars=yes,resizable=no";
		  if (window.screen)
		{
				var ah = screen.availHeight - 30;
				var aw = screen.availWidth - 10;
				var xc = (aw - width) / 2;
				var yc = (ah - height) / 2;

				str += ",left=" + xc + ",screenX=" + xc;
				str += ",top=" + yc + ",screenY=" + yc;
		}
		var win = window.open(url, name, str);
}
function formulario(url)
{
	var height = "400";
	var width = "400";
	var name = "Formulario";
   var str = "height=" + height + ",innerHeight=" + height;
		str += ",width=" + width + ",innerWidth=" + width;
		str += ",status=yes,scrollbars=yes,resizable=no";
		  if (window.screen)
		{
				var ah = screen.availHeight - 30;
				var aw = screen.availWidth - 10;
				var xc = (aw - width) / 2;
				var yc = (ah - height) / 2;

				str += ",left=" + xc + ",screenX=" + xc;
				str += ",top=" + yc + ",screenY=" + yc;
		}
		var win = window.open(url, name, str);
}

function submeter(arquivo)
{
	document.form01.action = arquivo;
	document.form01.submit();	
}

function validaCPF(campo) {
	cpf = campo;
	erro = new String;
	if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n"; 
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		erro += "Numero de CPF invalido!"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] * --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] * c--); 
		if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
		if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
			erro +="Digito verificador do CPF com problema!";
		}
		if (erro.length > 0){
		alert(erro);
		return false;
	}
	return true;
}


function validaCNPJ(campo) {
	StrCGC = campo;
	if (StrCGC == ''){
			alert('Por favor, preencha o CNPJ. Utilize somente números.');
			return false;
	}
	var varFirstChr = StrCGC.charAt(0);
	var vlMult,vlControle,s1, s2 = "";
	var i,j,vlDgito,vlSoma = 0;
	for ( var i=0; i<=13; i++ ) {
		var c = StrCGC.charAt(i);
		if( ! (c>="0")&&(c<="9") ){
			alert('O CNPJ não está informado corretamente. Utilize somente somente números. Verifique também o excesso de zeros a esquerda.');
			return false;
		}
		if( c!=varFirstChr ){
			vaCharCGC = true;
		}
	}
	if( ! vaCharCGC ) {
			alert('O CNPJ não está informado corretamente. Utilize somente somente números. Verifique também o excesso de zeros a esquerda.');
			return false;
	}

	s1 = StrCGC.substring(0,12);
	s2 = StrCGC.substring(12,15);
	vlMult = "543298765432";
	vlControle = "";
	
	for ( j=1; j<3; j++ ) {
		vlSoma = 0;
		for ( i=0; i<12; i++ ){
			vlSoma += eval( s1.charAt(i) )* eval( vlMult.charAt(i) );
		}
		if( j == 2 ){
			vlSoma += (2 * vlDgito);
		}
		vlDgito = ((vlSoma*10) % 11);
		if( vlDgito == 10 ){
			vlDgito = 0;
		}
		vlControle = vlControle + vlDgito;
		vlMult = "654329876543";
	}
	
	if( vlControle != s2 ) {
			alert('O CNPJ não está informado corretamente. Utilize somente somente números. Verifique também o excesso de zeros a esquerda.');
			return false;
	}else{
		// alert("Número do CGC Válido !");
		return true;
	}

/*                CNPJ = campo;
		erro = new String;
		 if (CNPJ.length < 18) erro += "É necessario preencher corretamente o número do CNPJ! \n\n"; 
		 if ((CNPJ.charAt(2) != ".") || (CNPJ.charAt(6) != ".") || (CNPJ.charAt(10) != "/") || (CNPJ.charAt(15) != "-")){
		 if (erro.length == 0) erro += "É necessário preencher corretamente o número do CNPJ! \n\n";
		 }
		//substituir os caracteres que não são números
	   if(document.layers && parseInt(navigator.appVersion) == 4){
			   x = CNPJ.substring(0,2);
			   x += CNPJ. substring (3,6);
			   x += CNPJ. substring (7,10);
			   x += CNPJ. substring (11,15);
			   x += CNPJ. substring (16,18);
			   CNPJ = x; 
	   } else {
			   CNPJ = CNPJ. replace (".","");
			   CNPJ = CNPJ. replace (".","");
			   CNPJ = CNPJ. replace ("-","");
			   CNPJ = CNPJ. replace ("/","");
	   }
	   var nonNumbers = /\D/;
	   if (nonNumbers.test(CNPJ)) erro += "A verificação de CNPJ suporta apenas números! \n\n"; 
	   var a = [];
	   var b = new Number;
	   var c = [6,5,4,3,2,9,8,7,6,5,4,3,2];
	   for (i=0; i<12; i++){
			   a[i] = CNPJ.charAt(i);
			   b += a[i] * c[i+1];
}
	   if ((x = b % 11) < 2) { a[12] = 0 } else { a[12] = 11-x }
	   b = 0;
	   for (y=0; y<13; y++) {
			   b += (a[y] * c[y]); 
	   }
	   if ((x = b % 11) < 2) { a[13] = 0; } else { a[13] = 11-x; }
	   if ((CNPJ.charAt(12) != a[12]) || (CNPJ.charAt(13) != a[13])){
			   erro +="Dígito verificador com problema!";
	   }
	   if (erro.length > 0){
			   alert(erro);
			   return false;
	   } else {
			   alert("CNPJ valido!");
	   }
	   return true;
*/       }
function isEmail(strEmail){
	if (strEmail.indexOf('@', 0) == -1){
		return false;
	}else{
		vRestoDepoisArroba = strEmail.substring((strEmail.indexOf('@', 0)+1),strEmail.length)
		if (vRestoDepoisArroba.indexOf('.', 0) == -1)
		{
			return false;
		}else{
			vRestoDepoisPonto = vRestoDepoisArroba.substring((vRestoDepoisArroba.indexOf('.', 0)+1),vRestoDepoisArroba.length)
			if (strEmail.indexOf('@', 0)+1==strEmail.indexOf('.', 0))
			{
				return false;
			}else{
				if (vRestoDepoisPonto.length<1){
					return false;
				}
			}
		}
	}
	return true;
}

//Formata conforme mascara
//OnKeyPress="formatar(this,'#####-###')"
//OnKeyPress="formatar(this,'###.###.###-##')"
//OnKeyPress="formatar(this,'##/##/####')"
function formatar(src, mask) {
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)
	if (texto.substring(0,1) != saida) 
	{
		src.value += texto.substring(0,1);
	}
}

//Função que recebe apenas numeros 
//usar: <input type="text" onKeyPress="return Numero(event);">
function Numero(e)
{
	navegador = /msie/i.test(navigator.userAgent);
	if (navegador)
		var tecla = event.keyCode;
	else
		var tecla = e.which;
	
	if(tecla > 47 && tecla < 58) // numeros de 0 a 9
		return true;
	else
	{
		if (tecla != 8) // backspace
			return false;
		else
			return true;
	}
}

function Contar(Campo){
if((500-Campo.value.length) <= 0){
   alert('Atenção! Você atingiu o limite máximo de caracteres!');
   Campo.value = Campo.value.substr(0,500);
}
document.getElementById("Qtd").innerText = 500-Campo.value.length
}
/*
function Contar(Campo){
	var total = document.getElementById("Qtd").innerText;
	if((total-Campo.value.length) <= 0){
	   alert('Atenção! Você atingiu o limite máximo de caracteres!');
	   Campo.value = Campo.value.substr(0,total);
	}
	document.getElementById("Qtd").innerText = total-Campo.value.length
}
*/
//by Almir F. Ambrosi
//usar: postIt('envia2.asp','id1',1111,'id2',2222,'id3',3333,'id4',4444)
function postIt(pagina_destino, nomecampo1, valorcampo1, nomecampo2, valorcampo2, nomecampo3, valorcampo3, nomecampo4, valorcampo4, nomecampo5, valorcampo5, nomecampo6, valorcampo6, nomecampo7, valorcampo7){
	var myform = document.createElement('form');
	
	myform.name = 'formParam';
	myform.action = pagina_destino;
	myform.method = 'post';
	
	var input1 = document.createElement('input');
	var input2 = document.createElement('input');
	var input3 = document.createElement('input');
	var input4 = document.createElement('input');
	var input5 = document.createElement('input');
	var input6 = document.createElement('input');
	var input7 = document.createElement('input');
	
	input1.name = nomecampo1;
	input1.value = valorcampo1;
	input1.type = "hidden";
	
	input2.name = nomecampo2;
	input2.value = valorcampo2;
	input2.type = "hidden";
	
	input3.name = nomecampo3;
	input3.value = valorcampo3;
	input3.type = "hidden";
	
	input4.name = nomecampo4;
	input4.value = valorcampo4;
	input4.type = "hidden";
	
	input5.name = nomecampo5;
	input5.value = valorcampo5;
	input5.type = "hidden";
	
	input6.name = nomecampo6;
	input6.value = valorcampo6;
	input6.type = "hidden";
	
	input7.name = nomecampo7;
	input7.value = valorcampo7;
	input7.type = "hidden";
	
	myform.appendChild(input1);
	myform.appendChild(input2);
	myform.appendChild(input3);
	myform.appendChild(input4);
	myform.appendChild(input5);
	myform.appendChild(input6);
	myform.appendChild(input7);

	document.body.appendChild(myform);
	myform.submit();
}
function popupPDF(url,winname)
{
winpops = window.open(url, winname, "width=750,height=600,toolbar=no,location=no,status=no,menubar=no, scrollbars=yes,resizable=yes"); //add to line above
}                

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_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_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];}
}

//inicio funções para abrir imagem em popup
var img1    = new Image(); 
var descricao;

function MM_openBrWindow(theURL,winName,features, nome_imagem, texto, altura, largura) { //v2.0 
  img1.src = nome_imagem; 
  descricao = texto; 
  newwin = window.open(theURL,winName,features); 
  newwin.focus(); 
  newwin.resizeTo(altura, largura); 
} 
function openPopup(imagem, texto, largura, altura) 
{ 
	MM_openBrWindow('http://portal.emobile.com.br/emobile/includes/popup/popup.htm','newwin','scrollbars=yes,top=15,left=15', imagem ,  texto , largura, altura); 
} 
//fim
