function browser () {
	var b = navigator.appName;
	var v = this.version = navigator.appVersion;
	var ua = navigator.userAgent.toLowerCase();	
	this.v = parseInt(v);
	this.safari = ua.indexOf("safari")>-1;	// always check for safari & opera 
	this.opera = ua.indexOf("opera")>-1;	// before ns or ie
	this.ns = !this.opera && !this.safari && (b=="Netscape");
	this.ie = !this.opera && (b=="Microsoft Internet Explorer");
	this.gecko = ua.indexOf('gecko')>-1; // check for gecko engine
	if (this.ns) {
		this.ns4 = (this.v==4);
		this.ns6 = (this.v>=5);	
		this.b = "Netscape";
	}else if (this.ie) {
		this.ie4 = this.ie5 = this.ie55 = this.ie6 = false;
		if (v.indexOf('MSIE 4')>0) {this.ie4 = true; this.v = 4;}
		else if (v.indexOf('MSIE 5')>0) {this.ie5 = true; this.v = 5;}
		else if (v.indexOf('MSIE 5.5')>0) {this.ie55 = true; this.v = 5.5;}
		else if (v.indexOf('MSIE 6')>0) {this.ie6 = true; this.v = 6;}
		this.b = "MSIE";
	}else if (this.opera) {
		this.v=parseInt(ua.substr(ua.indexOf("opera")+6,1)); // set opera version
		this.opera6=(this.v>=6);
		this.opera7=(this.v>=7);
		this.b = "Opera";
	}else if (this.safari) {
		this.ns6 = (this.v>=5);	// ns6 compatible correct?
		this.b = "Safari";
	}
	this.dom = (document.createElement && document.appendChild && document.getElementsByTagName)? true : false;
	this.def = (this.ie||this.dom);
	this.win32 = ua.indexOf("win")>-1;
	this.mac = ua.indexOf("mac")>-1;
	this.other = (!this.win32 && !this.mac);
	this.supported = (this.def||this.ns4||this.ns6||this.opera)? true:false;
};

function verificaNavegador() {
	var navId;
	var navVersion;
	var navUserAgent = navigator.userAgent
	var reg = new RegExp('/');
	
	var isMinNS4 = document.layers;
	var ie=document.all&&navUserAgent.indexOf("Opera")==-1;
	var fir=document.getElementById&&!ie&&navUserAgent.indexOf("Firefox")>0;
	var opr=document.getElementById&&!ie&&navUserAgent.indexOf("Opera")>0;
	var dom=document.getElementById&&!ie&&navUserAgent.indexOf("Opera")==-1;

	if(isMinNS4) {
		navId = navUserAgent.search(reg);
		navVersion = navUserAgent.substr(navId+1);
		return "NS:" + navVersion;
	}
	if(ie) {
		navId = navUserAgent.indexOf('MSIE');
		navVersion = navUserAgent.substr(navId,8);
		return "IE:" + navVersion;
	}
	if(fir) {
		navId = navUserAgent.indexOf("Firefox");
		navVersion = navUserAgent.substr(navId);
		return "FF:" + navVersion;
	}
	if(opr) {
		navId = navUserAgent.indexOf("Opera");
		navVersion = navUserAgent.substr(navId);
		return "OP:" + navVersion;
	}
	if(dom) {
		navId = navUserAgent.search(reg);
		navVersion = navUserAgent.substr(navId+1);
		return "OT:" + navVersion;
	}
}

function mmLoadMenus() {

	if (window.mm_menu_empresa_0) return;

	window.mm_menu_empresa_0 = new Menu("root",167,20,"Verdana, Arial, Helvetica, sans-serif",11,"#666666","#273f76","#E1E1E1","#55B0C5","left","middle",4,0,500,-5,7,true,true,true,5,true,true);
	mm_menu_empresa_0.addMenuItem("Sobre a empresa","location='main.php?url=empresa.php'");
	mm_menu_empresa_0.addMenuItem("Localização","location='main.php?url=localizacao.php'");
	mm_menu_empresa_0.addMenuItem("RH - Oportunidades","location='main.php?url=oportunidades.php'");
	mm_menu_empresa_0.hideOnMouseOut=true;
	mm_menu_empresa_0.menuBorder=1;
	mm_menu_empresa_0.menuLiteBgColor='#cccccc';
	mm_menu_empresa_0.menuBorderBgColor='#ffffff';
	mm_menu_empresa_0.bgColor='#cccccc';

	window.mm_menu_produtos_2 = new Menu("root",169,20,"Verdana, Arial, Helvetica, sans-serif",11,"#666666","#273f76","#E1E1E1","#55B0C5","left","middle",4,0,1000,-5,7,true,true,true,5,true,true);
	mm_menu_produtos_2.addMenuItem("Processo de Produção","location='main.php?url=produtos_producao.php'");
	mm_menu_produtos_2.addMenuItem("Fécula In natura","location='main.php?url=produtos_fec_innatura.php'");
	mm_menu_produtos_2.addMenuItem("Fécula Esterilizada","location='main.php?url=produtos_fec_esterilizada.php'");
	mm_menu_produtos_2.addMenuItem("Outros","location='main.php?url=produtos_outros.php'");
	mm_menu_produtos_2.hideOnMouseOut=true;
	mm_menu_produtos_2.menuBorder=1;
	mm_menu_produtos_2.menuLiteBgColor='#cccccc';
	mm_menu_produtos_2.menuBorderBgColor='#ffffff';
	mm_menu_produtos_2.bgColor='#cccccc';

	mm_menu_produtos_2.writeMenus();
}

function soNumeros(dados) {
	dados = strReplaceAll ( dados, ",", "");
	dados = strReplaceAll ( dados, ".", "");
	if (isNaN(dados)) {
		alert ("Só é permitido NÚMEROS");
		return (false);
	}
	return (true);
}  

function strReplaceAll ( theSource, toFind, replaceWith ) {
     if (null == theSource ) return "";
     li_pos = theSource.indexOf( toFind );
     while (li_pos != -1)
     {
        if (li_pos < theSource.length -1 )
	   theSource = theSource.substring(0, li_pos ) + replaceWith +
	              theSource.substring(li_pos+1, theSource.length);
        else
  	   theSource = theSource.substring(0, li_pos );
 
	   li_pos = theSource.indexOf( toFind, li_pos + replaceWith.length ); 
     }
     return theSource;
}

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 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_nbGroup(event, grpName) { //v6.0
  var i,img,nbArr,args=MM_nbGroup.arguments;
  if (event == "init" && args.length > 2) {
    if ((img = MM_findObj(args[2])) != null && !img.MM_init) {
      img.MM_init = true; img.MM_up = args[3]; img.MM_dn = img.src;
      if ((nbArr = document[grpName]) == null) nbArr = document[grpName] = new Array();
      nbArr[nbArr.length] = img;
      for (i=4; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
        if (!img.MM_up) img.MM_up = img.src;
        img.src = img.MM_dn = args[i+1];
        nbArr[nbArr.length] = img;
    } }
  } else if (event == "over") {
    document.MM_nbOver = nbArr = new Array();
    for (i=1; i < args.length-1; i+=3) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = (img.MM_dn && args[i+2]) ? args[i+2] : ((args[i+1])? args[i+1] : img.MM_up);
      nbArr[nbArr.length] = img;
    }
  } else if (event == "out" ) {
    for (i=0; i < document.MM_nbOver.length; i++) {
      img = document.MM_nbOver[i]; img.src = (img.MM_dn) ? img.MM_dn : img.MM_up; }
  } else if (event == "down") {
    nbArr = document[grpName];
    if (nbArr)
      for (i=0; i < nbArr.length; i++) { img=nbArr[i]; img.src = img.MM_up; img.MM_dn = 0; }
    document[grpName] = nbArr = new Array();
    for (i=2; i < args.length-1; i+=2) if ((img = MM_findObj(args[i])) != null) {
      if (!img.MM_up) img.MM_up = img.src;
      img.src = img.MM_dn = (args[i+1])? args[i+1] : img.MM_up;
      nbArr[nbArr.length] = img;
  } }
}

function setarCidade( CodCidade, targOrigem, urlDestino, targDestino ) {
	eval("document.setarCidade.target='"+targOrigem+"'");
	eval("document.setarCidade.action='setar_cidade.php?CodCidade="+CodCidade+"&targ="+targDestino+"'");
	document.setarCidade.urld.value = urlDestino;
	document.setarCidade.submit();
}

function ultimoCaracter(str, carf) {
	var pos = str.lastIndexOf(carf);
	return pos;
}

function abrePopup(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable) {
	toolbar_str = toolbar ? 'yes' : 'no';
	menubar_str = menubar ? 'yes' : 'no';
	statusbar_str = statusbar ? 'yes' : 'no';
	scrollbar_str = scrollbar ? 'yes' : 'no';
	resizable_str = resizable ? 'yes' : 'no';
	// Manter o comando abaixo na mesma linha
	window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

function verFoto( dir, ds_foto, wi, he, scr ) {
	wi = wi + 40;
	he = he + 80;
	le = ((screen.width) - wi) / 2 ;
	to = ((screen.height) - he) / 2 ;
	abrePopup('Visualização', dir + 'ver_foto.php?src=' + ds_foto, le, to, wi, he, 0, 0, 0, scr, 0);
}

function trocaString(Campo, CaracterDe, CaracterPor){
   var Retorno = '';
   var Tamanho = Campo.length;
   var Conteudo = Campo
   var Posicao = 0
   var TamanhoCaracterDe = CaracterDe.length

   Posicao = Conteudo.indexOf(CaracterDe, 0)

   var Anterior = Conteudo.substring(0,Posicao)
   var Posterior = Conteudo.substring((Posicao+TamanhoCaracterDe),Conteudo.length)
   Retorno = Anterior + CaracterPor + Posterior
   return (Retorno);
}

function validaDominio(str) {
	if (str.indexOf(".") > 0)
		return true;
    else
		return false;
}

function validaEmail(str) {
	var reg1 = new RegExp("(@.*@)|(\\.\\.)|(@\\.)|(\\.@)|(^\\.)");
	var reg2 = new RegExp("[a-zA-Z0-9\\-\\.]+\\@(\\[?)[a-zA-Z0-9\\-\\.]+\\.([a-zA-Z]{2,3}|[0-9]{1,3})(\\]?)$");
	if (!reg1.test(str) && (reg2.test(str)))
		return true;
    else
		return false;
}

function exibeEsconde(tipo, exibe) {
	if (tipo == 'E') {
		// exibe
		for(var i = 0; i < exibe.length; i++) 
		{
			if(document.getElementById(exibe[i])) 
			{
				document.getElementById(exibe[i]).style.display = 'block';
			}
		}
	} else {
		// esconde
		for(var i = 0; i < exibe.length; i++) 
		{
			if(document.getElementById(exibe[i])) 
			{
				document.getElementById(exibe[i]).style.display = 'none';
			}
		}
	}
}

// Objetos / Lauyers
function showHideLayers() { //v6.0 
  var i,p,v,obj,args=showHideLayers.arguments; 
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2]; 
    if (obj.style) { obj=obj.style; v=(v=='abrir')?'visible':(v=='fechar')?'hidden':v; } 
    obj.visibility=v; }
}

// Oculta/Exibe campos combo
function exibeEscondeCombos(form, fact) {
	for (i = 0; i < eval(form+".length"); i++) {
		if (eval(form+".elements[i].type") == "select-one") {
			if (fact)
				eval(form+".elements[i].style.display = 'block'");
			else
				eval(form+".elements[i].style.display = 'none'");
		}
	}
}

function trocaImagens(objs, imgs) {
	for(var i = 0; i < objs.length; i++) 
	{
		if(document.getElementById(objs[i])) 
		{
			document.getElementById(objs[i]).src = imgs[i];
		}
	}
}

function verfonte() {
	if (event.button==2) {
		window.alert('Todos os Direitos Reservados.\n\nClique em Ok, para continuar navegando no site.')
	}
}

function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) {
			return true;
		}
	}
	else {
		if ((intYear % 4) == 0) {
			return true;
		}
	}
	return false;
}

function redireciona(pagina) {
   document.location.href=pagina;
}

function KeyFormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = event.srcElement.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
		{
			event.srcElement.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		}
		if ( tam >= 5 && tam <= 10 )
		{
			event.srcElement.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); }
		}
}  

function validaData(data) {
   if (data.length != 10) {
      return (false);
   }

   pos0 = data.indexOf("/");
   if (pos0 == -1) {
      return (false);
   }

   pos1 = data.indexOf("/", pos0 + 1);
   if (pos1 == -1) {
      return (false);
   }
   if (data.indexOf("/", pos1 + 1) != -1) {
      return (false);
   }

   dia = data.substring(0,pos0);
   dia = (dia.charAt(0) == "0")?dia.charAt(dia.length - 1):dia
   mes = data.substring(pos0 + 1, pos1);
   mes = (mes.charAt(0) == "0")?mes.charAt(mes.length - 1):mes
   ano = data.substring(pos1 + 1, data.length);
   ano = (ano.charAt(0) == "0")?ano.charAt(ano.length - 1):ano
   
   if (isNaN(dia) || isNaN(mes) || isNaN(ano)) {
      return (false);
   }

   if (mes <= 0 || mes >= 13) {
      return (false);
   }

   numero = (parseInt(ano) % 4);
   
   if (numero == 0) {
      dias = "312931303130313130313031";
   }
   else {
      dias = "312831303130313130313031";
   }

   diamax = parseInt(dias.substring((mes-1)*2,((mes-1)*2)+2));
   if(parseInt(dia) < 1 || parseInt(dia) > diamax) {
      return (false);
   }
   
   return (true);
}

function KeyFormataHora(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = event.srcElement.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( ":", "" );
	vr = vr.replace( ":", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
		{
			event.srcElement.value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam );
		}
	}
}  

function KeyFormataValorVirgula(Campo,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = event.srcElement.value;
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > decimal )
		{
			event.srcElement.value = vr.substr( 0, tam - decimal  ) + ',' + vr.substr( tam - decimal, tam );
		}
	}
}  

function KeyFormataValorPonto(Campo,teclapres,decimal) {
	var tecla = teclapres.keyCode;
	vr = event.srcElement.value;
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > decimal )
		{
			event.srcElement.value = vr.substr( 0, tam - decimal  ) + '.' + vr.substr( tam - decimal, tam );
		}
	}
}  

function DDDUf(nome,estilo,cid,val) {
	var sHtml, attrib;
	attrib = " selected";
	sHtml  = "<select name='"+nome+"' class='"+estilo+"' id='"+cid+"'>";

	sHtml += "<option value='IN'";
	if (val == 'IN')
		sHtml += attrib;
	sHtml += "></option>";
	
	sHtml += "<option value='AC'";
	if (val == 'AC')
		sHtml += attrib;
	sHtml += ">AC</option>";

	sHtml += "<option value='AL'";
	if (val == 'AL')
		sHtml += attrib;
	sHtml += ">AL</option>";

	sHtml += "<option value='AM'";
	if (val == 'AM')
		sHtml += attrib;
	sHtml += ">AM</option>";
	
	sHtml += "<option value='AP'";
	if (val == 'AP')
		sHtml += attrib;
	sHtml += ">AP</option>";
	
	sHtml += "<option value='BA'";
	if (val == 'BA')
		sHtml += attrib;
	sHtml += ">BA</option>";
	
	sHtml += "<option value='CE'";
	if (val == 'CE')
		sHtml += attrib;
	sHtml += ">CE</option>";
	
	sHtml += "<option value='DF'";
	if (val == 'DF')
		sHtml += attrib;
	sHtml += ">DF</option>";
	
	sHtml += "<option value='ES'";
	if (val == 'ES')
		sHtml += attrib;
	sHtml += ">ES</option>";
	
	sHtml += "<option value='GO'";
	if (val == 'GO')
		sHtml += attrib;
	sHtml += ">GO</option>";
	
	sHtml += "<option value='MA'";
	if (val == 'MA')
		sHtml += attrib;
	sHtml += ">MA</option>";
	
	sHtml += "<option value='MG'";
	if (val == 'MG')
		sHtml += attrib;
	sHtml += ">MG</option>";
	
	sHtml += "<option value='MS'";
	if (val == 'MS')
		sHtml += attrib;
	sHtml += ">MS</option>";
	
	sHtml += "<option value='MT'";
	if (val == 'MT')
		sHtml += attrib;
	sHtml += ">MT</option>";
	
	sHtml += "<option value='PA'";
	if (val == 'PA')
		sHtml += attrib;
	sHtml += ">PA</option>";
	
	sHtml += "<option value='PB'";
	if (val == 'PB')
		sHtml += attrib;
	sHtml += ">PB</option>";
	
	sHtml += "<option value='PE'";
	if (val == 'PE')
		sHtml += attrib;
	sHtml += ">PE</option>";
	
	sHtml += "<option value='PI'";
	if (val == 'PI')
		sHtml += attrib;
	sHtml += ">PI</option>";
	
	sHtml += "<option value='PR'";
	if (val == 'PR')
		sHtml += attrib;
	sHtml += ">PR</option>";
	
	sHtml += "<option value='RJ'";
	if (val == 'RJ')
		sHtml += attrib;
	sHtml += ">RJ</option>";
	
	sHtml += "<option value='RN'";
	if (val == 'RN')
		sHtml += attrib;
	sHtml += ">RN</option>";
	
	sHtml += "<option value='RO'";
	if (val == 'RO')
		sHtml += attrib;
	sHtml += ">RO</option>";
	
	sHtml += "<option value='RR'";
	if (val == 'RR')
		sHtml += attrib;
	sHtml += ">RR</option>";
	
	sHtml += "<option value='RS'";
	if (val == 'RS')
		sHtml += attrib;
	sHtml += ">RS</option>";
	
	sHtml += "<option value='SC'";
	if (val == 'SC')
		sHtml += attrib;
	sHtml += ">SC</option>";
	
	sHtml += "<option value='SE'";
	if (val == 'SE')
		sHtml += attrib;
	sHtml += ">SE</option>";
	
	sHtml += "<option value='SP'";
	if (val == 'SP')
		sHtml += attrib;
	sHtml += ">SP</option>";
	
	sHtml += "<option value='TO'";
	if (val == 'TO')
		sHtml += attrib;
	sHtml += ">TO</option>";
	
	sHtml += "</select>";
	document.writeln(sHtml);
}

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function checaCNPJ(CNPJ) {

	var dig1=0;
	var dig2=0;
	var x;
	var Mult1 = '543298765432';
	var Mult2 = '6543298765432';
	
	for(x=0; x<=11; x++) {
		dig1 = dig1 +(parseInt(CNPJ.slice(x,x+1)) *	parseInt(Mult1.slice(x,x+1)));
	}
	for(x=0; x<=12; x++) {
		dig2 = dig2 + (parseInt(CNPJ.slice(x, x+1)) * parseInt(Mult2.slice(x,x+1)));
    	}	
	
	dig1 = (dig1 * 10)%11;
	dig2 = (dig2 * 10)%11;
	
	if (dig1 == 10) {dig1 = 0;}
	if (dig2 == 10) {dig2 = 0;}
	
	if (dig1 != parseInt(CNPJ.slice(12, 13))) {
		alert("CNPJ Invalido");
		return (false);
	} else {
		if (dig2 != parseInt(CNPJ.slice(13, 14))) {
			alert("CNPJ Invalido");
			return (false);
		} else {
	    	return (true);
		}
	}
}

function checaCPF (CPF) {
   CPF = FiltraCampo(CPF);
   if (CPF == '') {
      return (true);
   }
   
   if (CPF.length != 11            || CPF == "00000000000" || CPF == "11111111111" ||
       CPF        == "22222222222" || CPF == "33333333333" || CPF == "44444444444" ||
       CPF        == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
       CPF        == "88888888888" || CPF == "99999999999") {

      alert ("CPF inválido");
      return (false);
   }

   soma = 0;
   for (var i = 0; i < 9; i ++) {
      soma += parseInt(CPF.charAt(i)) * (10 - i);
   }
   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11) {
      resto = 0;
   }
   if (resto != parseInt(CPF.charAt(9))) {
      alert ("CPF inválido");
      return (false);
   }
   soma = 0;
   for (var i = 0; i < 10; i ++) {
      soma += parseInt(CPF.charAt(i)) * (11 - i);
   }
   resto = 11 - (soma % 11);
   if (resto == 10 || resto == 11) {
      resto = 0;
   }
   if (resto != parseInt(CPF.charAt(10))) {
      alert ("CPF inválido");
      return (false);
   }

   return (true);
 }
 
function checaCPFCNPJ(CPFCNPJ) {
	if (CPFCNPJ.length < 11) {
		alert ("CNPJ/CPF inválido");
		return false;
	}
	if (CPFCNPJ.length > 11)
		return checaCNPJ(CPFCNPJ);
	else
	 	return checaCPF(CPFCNPJ);	
}

function FiltraCampo(campo){
	var s = "";
	var cp = "";
	vr = campo;
	tam = vr.length;
	for (var 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) != "," && vr.substring(i, i + 1) != ":"){
		 	s = s + vr.substring(i,i + 1);}
	}
	;
  retorno = s;
  return (retorno);
}

function formataCep(campo){
	vr = FiltraCampo(campo);
	tam = vr.length;
  if (isNaN(vr)) {
    alert ("CEP Inválido - Só é permitido NÚMEROS");
    retorno = "" ;
    return (retorno);
  }

  if (vr.length == 0) {
    return ""
  }

  if (tam > 8){
    alert ("CEP Inválido");
    retorno = "";
  }
	if ( tam >= 1 && tam <= 8 ) 
      vr = '00000000'+vr;
    	tam = vr.length;
      vr = vr.substring((tam-8),tam);
		retorno = vr.substring( 0, 5 ) + '-' + vr.substring( 5, vr.length ) ;
    return (retorno);
}

function AdicionarFavoritos(url,descricao) {
	if ((navigator.appName=="Microsoft Internet Explorer") && (parseInt(navigator.appVersion)>=4)) {
		if (null == url) url = '';
		if (url == '') url = document.location;
		if (null == descricao) descricao = '';
		if (descricao == '') descricao = document.title;
		
		window.external.AddFavorite(url,descricao);
	}
	else {
		if(navigator.appName == "Netscape")
			alert ("Pressione Crtl+D para adicionar esta página em seus favoritos.");
	}
}

function radioButtonChecker(form,campo) {
	var radio_choice = false;
	var campo_validar = eval("form."+campo);
	
	for (counter = 0; counter < campo_validar.length; counter++) {
		if (campo_validar[counter].checked)
			radio_choice = true; 
	}
	if (!radio_choice) {
		alert("Selecione uma opção.")
		return (false);
	}
	return (true);
}

function setaCookie (NmCookie, Valor) {
    document.cookie =  NmCookie + "=" + Valor;
}

function leCookie (NmCookie) {
   if (document.cookie == '') {
      return (null);
   }
   
   VetCookie = document.cookie.split ("; ");
   for (var i = 0; i <= (VetCookie.length - 1); i++) {
      if (NmCookie == VetCookie[i].split("=")[0]) {
         return (VetCookie[i].split("=")[1]);
      }
   }

   return (null);
}

function round(number, X) {
    // arredonda number para X casas decimais, o defaults é para 2
    X = (!X ? 2 : X);
    return (Math.round(number*Math.pow(10,X))/Math.pow(10,X));
}

function tornaInvisivelCampo (form, campo, TodosCampos){
   if (TodosCampos == true) {
      for (var i = 0; i <= form.elements.length - 1; i++) {
         form.elements[i].style.visibility="hidden";
      }
   }
   else {
        eval('document.getElementById("' + form.name+'").'+campo+'.style.visibility="hidden"');
   }
}

function tornaVisivelCampo (form, campo, TodosCampos){
   if (TodosCampos == true) {
      for (var i = 0; i <= form.elements.length - 1; i++) {
         form.elements[i].style.visibility="visible";
      }
   }
   else {
        eval('document.getElementById("' + form.name+'").'+campo+'.style.visibility="visible"');
   }
}

function habilitaCampo (form, campo, TodosCampos){
   if (TodosCampos == true) {
      for (var i = 0; i <= form.elements.length - 1; i++) {
         if (form.elements[i].type != "hidden" && form.elements[i].type != "button") {
             form.elements[i].disabled = false;
             form.elements[i].style.backgroundColor = "#FFFFFF";
         }
      }
   }
   else {
        eval('document.getElementById("'+form.name+'").'+campo+'.disabled = false');
        eval('document.getElementById("'+form.name+'").'+campo+'.style.backgroundColor = "#FFFFFF"');   
   }
}

function desabilitaCampo (form, campo, TodosCampos){
   if (TodosCampos == true) {
      for (var i = 0; i <= form.elements.length - 1; i++) {
         if (form.elements[i].type != "hidden" && form.elements[i].type != "button") {
             form.elements[i].disabled = true;
             form.elements[i].style.backgroundColor = "#EEEEF2";
         }
      }
   } else {
        eval('document.getElementById("'+form.name+'").'+campo+'.disabled = true');
        eval('document.getElementById("'+form.name+'").'+campo+'.style.backgroundColor = "#EEEEF2"');   
   }
}

function maiusculo (param){
    param = param.toUpperCase();
    return (param);
}

function IsNumber(valor){
  if (isNaN(valor)) {
    alert ("Valor Inválido - Só é permitido NÚMEROS");
    return ('');
  }
  else {
    return (valor)
  }
}

function IsPercentualValido(valor, tipo){
  var vr = FiltraCampo(valor);

  if (IsNumber(vr) == "") {
     return ('');
  }

  if (tipo == null) {
     tipo = 1;
  }
 
  valor = formataValor(valor);
  if (valor != "") {
     vr = trocaCaracter(valor, ",", "");
     vr = trocaCaracter(vr, "-", "");
     vr = new Number (vr);

     if (vr > 100.00) {
        alert ('O Percentual não pode ser maior do que 100.00%');
        return ('');
     }

     if (tipo == 1) {
        // só permite valores positivos
        if (valor.indexOf('-', 0) >= 0) {
           alert ('Somente é permitido Percentual positivo');
           return ('');
        }
     }
     else {
         if (tipo == 2) {
            // só permite valores negativos
            if (valor.indexOf('-', 0) < 0) {
               alert ('Somente é permitido Percentual negativo');
               return ('');
            }
         }
     }
  }

  return (valor); 
}

function IsAnoValido(valor){
  var vr = FiltraCampo(valor);

  if (IsNumber(vr) == "") {
     return ('');
  }

  if (vr.length > 5) {
    alert ("Ano Inválido, somente é permitido anos entre 1960 e 2050");
    return ('');
  }
  else {
     if (vr.length == 5) {
        var NrSemestre = vr.substring (4, 5);
        if (NrSemestre != "1" && NrSemestre != "2") {
            alert ("Semestre Inválido, somente é permito semestre 1 ou 2");
            return ('');
        }
     }
     vr = vr.substring (0, 4);
  }

  vr = new Number (vr);
  if (vr < 1960 || vr > 2050) {
    alert ("Ano Inválido, somente é permitido anos entre 1960 e 2050");
    return ('');
  }

  return (valor);
}

function formataIP(NrIP, ComPontos){
   var NrIpRetorno = "";
   var NrIpParte   = "";
   var NrInicio    = 0;
   var NrFim       = 0;
   
   NrFim = NrIP.indexOf(".", 0);
   if (NrFim < 0) {
       if (ComPontos == true) {
           NrIP = formataValorMascara(NrIP, "000.000.000.000", "NUMERIC");
       }

       return (NrIP);
   }
   
   while (NrFim >= 0) {
       NrIpParte    = NrIP.substring (NrInicio, NrFim);
       NrIpRetorno += formataValorMascara(NrIpParte, "000", "NUMERIC");

       NrInicio = NrFim + 1;
       NrFim    = NrIP.indexOf(".", NrInicio);
   }

   NrIpParte    = NrIP.substring (NrInicio, NrIP.length);
   NrIpRetorno += formataValorMascara(NrIpParte, "000", "NUMERIC");

   if (ComPontos == true) {
       NrIpRetorno = formataValorMascara(NrIpRetorno, "000.000.000.000", "NUMERIC");
   }
   
   return (NrIpRetorno);
}
