<!--

var browserName;
var browserVersion;
var browserVersionDecimal = 0;
var browserPlatform;
var tempVersion;

if (navigator.appName.toLowerCase().indexOf("netscape") != -1)
{
    browserName = "NS";
    browserVersion = parseInt(navigator.appVersion.charAt(0));
}
else if (navigator.appName.toLowerCase().indexOf("microsoft") != -1)
{
    browserName = "MSIE";
    tempVersion = parseInt(navigator.appVersion.charAt(0));
    if (tempVersion < 4)
      browserVersion = tempVersion;
    else {
      browserVersion = parseInt(navigator.appVersion.substr((navigator.appVersion.indexOf("MSIE ") + 5),1));
      browserVersionDecimal = parseInt(navigator.appVersion.substr((navigator.appVersion.indexOf("MSIE ") + 7),1));
    }

}
else
{
    browserName = "?";
    browserVersion = parseInt(navigator.appVersion.charAt(0));
}

if ((browserName == "NS") && (browserVersion < 4))
  browserPlatform = "WINDOWS"
else
{
  if (navigator.platform.toLowerCase().indexOf("win") != -1)
      browserPlatform = "WINDOWS";
  else if (navigator.platform.toLowerCase().indexOf("mac") != -1)
      browserPlatform = "MAC";
  else
      browserPlatform = "?";
}


// -- Contador para objeto TextArea.
function LimitaCampo(campo,tam){
	var tamanho = document.form[campo].value.length;
	var tex=document.form[campo].value;
	if (tamanho>=tam) {
		document.form[campo].value=tex.substring(0,tam); 
	}
	return true;
}

// --
function SetTexto(campo,txt) { campo.innerHTML = txt ; }


function FormataDado(campo,tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "-", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length ;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){ tam = tam - 1 ; }
			
	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
	 		document.form[campo].value = vr ;}
		if ( tam > pos && tam <= tammax ){
			document.form[campo].value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );}
	}
}

function FormataValor(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[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 && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + ',' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[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) ){
	 		document.form[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) ){
	 		document.form[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 ) ;}
	}		
	
}

function SaltaCampo (campo,prox,tammax,teclapres){
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		document.form[campo].value = vr.substr( 0, vr.length - 1 ); }
	else{
		
		vr = vr.replace( "-", "" );
	 	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 (tecla != 0 && tecla != 9 && tecla != 16 ){
			if ( tam == tammax ){
				if ( document.form[prox] )
					document.form[prox].focus();
			}
		}
	}
}

function FormataData(Campo,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[Campo].value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

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


function FormataHora(Campo,teclapres) {
	var tecla = teclapres.keyCode
	vr = document.form[Campo].value
	vr = vr.replace( ":", "" )
	vr = vr.replace( ".", "" )
	vr = vr.replace( "/", "" )
	vr = vr.replace( "/", "" )
	tam = vr.length + 1

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			document.form[Campo].value = vr.substr( 0, tam - 2  ) + ':' + vr.substr( tam - 2, tam )
	}
}


function FormataCpf(campo,tammax,teclapres) {
	var tecla = teclapres.keyCode;
	vr = document.form[campo].value;
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	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 && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		document.form[campo].value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		document.form[campo].value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		document.form[campo].value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		document.form[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) ){
	 		document.form[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) ){
	 		document.form[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 ) ;}
	}		
}

function VerificaJava()	{
	if (navigator.javaEnabled())
		document.form.javas.value="sim"
}

function IsNumeric(pNum){

	if (pNum==''){
		return false;
	}
	for (var i = 0; i < pNum.length; i++){
		var ch = pNum.substring(i, i + 1);
		if (ch < '0' || '9' < ch){
			return false;
		}
	}
	return true;
}


function IsDecimal(pNum){

	if (pNum==''){
		return false;
	}
	
	for (var i = 0; i < pNum.length; i++){
		var ch = pNum.substring(i, i + 1);
		if ((ch < '0' || '9' < ch) && (ch != ',') && (ch != '.') && (ch != '-')){
			return false;
		}
	}
	return true;
}


function IsDate(pData){

	if(pData.length<10 || pData.length>10){

		return false;
	}

	var ano = '' + pData.substring(6,10);
	var mes = '' + pData.substring(3,5);
	var dia = '' + pData.substring(0,2);
	
	if (!IsNumeric(ano) || !IsNumeric(mes) || !IsNumeric(dia)){
		return false;
	}
			
	if(dia>'31'){
		return false;
	}
				
	if(mes>'12'){
		return false;
	}

	if(ano<='1900'){
		return false;
	}

	if(mes=='02'){
		if(ano%4!=0 && dia>'28'){
			return false;
		}
		else{
			if(dia>'29'){
				return false;
			}
		}
	}
	
	if(mes<='07'){
		if(mes%2==0 && dia>'30'){
			return false;
		}
	}
	else{
		if(mes>'09'){
			if(mes%2!=0 && dia>'30'){
				return false;
			}
		}
	}
					
	return true
}

//FUNÇÃO PARA VALIDAR UMA HORA INFORMADA
function IsHour(pHora){

	if (pHora != ''){
	
		if(pHora.length < 4 || pHora.length > 5){
			return false
		}

		var aux = pHora.indexOf(":")
		var hora = pHora.substring(0,aux)
		var min = pHora.substring(aux+1,pHora.length)
	
		if(hora > 23 || hora < 0){
			return false
		}
					
		if(min > 59 || min < 0){
			return false
		}
	}
	
	return true
}


function IsEmail(email){

	if ((email.search(/;/i) == -1) &&
	    (email.search(/,/i) == -1) &&
	    (email.indexOf("..") == -1) &&
	    (email.indexOf(".@") == -1) &&
	    (email.indexOf("@.") == -1) &&
	    (email.search(/ /i) == -1) &&
	    (email.search(/"/i) == -1) &&
	    (email.search(/'/i) == -1) &&
	    (email.indexOf("^") == -1) &&
	    (email.search(/`/i) == -1) &&
	    (email.search(/´/i) == -1) &&
	    (email.search(/~/i) == -1) &&
	    (email.search(/ç/i) == -1) &&
	    (email.length != 0) &&
	    (email.search(/@/i) >= 2) &&
	    (email.substr(0,1) != ".") &&               //Não pode começar com ponto
	    (email.substr(email.length-1) != ".") &&    //Não pode terminar com ponto
	    (email.indexOf("hotmail.com.br") == -1) &&
	    (email.indexOf("aol.com.br") == -1) &&
	    (email.indexOf("globo.com.br") == -1) &&
	    (email.indexOf(" ") == -1))
		return true;
	else
		return false; 
}

function Mid(campo,x,y){

	var res;
	if(x>0)
		x = x-1;
	if(x+y > campo.length)
		y = campo.length
	else
		y = x + y;
	res = campo.substring(x,y);
	return res;
}

	
function Left(campo,x){

	var res;
	if(x > campo.length)
		x = campo.length;
	res = campo.substring(0,x);
	return res;
}

	
function Right(campo,x){

	var res;
	if(x > campo.length){
		res = campo;
		return res;
	}
	res = campo.substring(campo.length-x,campo.length);
	return res;
}

	
function UCase(campo){

	return campo.toUpperCase()
}

	
function LCase(campo){

	return campo.toLowerCase()
}

	
function RTrim(campo){

	y=true;
	while(y==true){
		x = campo.length;
		if(Right(campo,1)==' '){
			campo = Left(campo,x-1);
			y=true;
		}
		else{
			y=false
		}
	}
	return campo;
}

	
function LTrim(campo){

	y=true;
	while(y==true){
		x = campo.length-1;
		if(Left(campo,1)==' '){
			campo = Right(campo,x);
			y=true;
		}
		else{
			y=false;
		}
	}
	return campo;
}

	
function Trim(campo){

	return RTrim(LTrim(campo));
}


//FUNÇÃO PARA OCULTAR OU TORNAR VISÍVEL UM OBJETO DE UMA PÁGINA
function ShowHide(opcao,id) {
	
	el = document.all ? document.all[id] : 
	dom ? document.getElementById(id) : 
	document.layers[id];
	els = dom ? el.style : el;

	if (dom) {
	  if (opcao == 1) els.visibility = "visible"
	  else els.visibility = "hidden"
	}
	else if (ns4){
	  if (opcao == 1) els.visibility = "show"
	  else els.visibility = "hide"
	}

}

function IsNumber() {
	if ((event.keyCode >= 48) && (event.keyCode <= 57))
		return true;
	else
		return false;
}

// Tecla Enter se comportando como Tab
function SetFocus(campo){
	if(window.event.srcElement.type == 'text' || window.event.srcElement.type == 'password'){ 
		var ele = window.event.srcElement;
		//var index = ele.sourceIndex;
		if(window.event.keyCode == 13){
			//document.all.item(index + 2).focus(); 
			if (campo.disabled == false){
				if (campo.type != 'select-one')
					campo.select()
				else
					campo.focus()
			}
			
			window.event.returnValue = false;     
		}
	} 
}


// Função utilizada para validação de CPF e CNPJ
function modulo(str) {

   	soma=0;
   	ind=2;
   	for(pos=str.length-1;pos>-1;pos=pos-1) {
   		soma = soma + (parseInt(str.charAt(pos)) * ind);
   		ind++;
   		if(str.length>11) {
   			if(ind>9) ind=2;
   		}
	}
   	resto = soma - (Math.floor(soma / 11) * 11);
   	if(resto < 2) {
    	return 0
   	}
   	else {
   		return 11 - resto
   	}
}

// Função para validação do CPF
function IsCPF(valor) {

	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=11){
		return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	if (falso){
		return false;
	}
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) != valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}


// Função para validação do cnpj
function IsCNPJ(valor) {

	primeiro=valor.substr(1,1);
	falso=true;
	size=valor.length;
	if (size!=14){
		return false;
	}
	size--;
	for (i=2; i<size-1; ++i){
		proximo=(valor.substr(i,1));
		if (primeiro!=proximo) {
			falso=false
		}
	}
	
	if (falso){
		return;
	}
	
   	if(modulo(valor.substring(0,valor.length - 2)) + "" + modulo(valor.substring(0,valor.length - 1)) !=valor.substring(valor.length - 2,valor.length)) {
   		return false;
   	}
   	return true
}

//======================================================
// FUNÇÃO PARA ABRIR O FORMULÁRIO DE PESQUISA DE CIDADES 
//======================================================
function PesquisaCidades(uf,nome,campo_uf,campo_nome,campo_numg)
{
   url = "pesqcidades.asp?uf=" + uf + "&nome=" + nome + "&campo_uf=" + campo_uf + "&campo_nome=" + campo_nome + "&campo_numg=" + campo_numg
   
   if(navigator.appName.indexOf("Netscape")>=0){
		window.open(url,"pesqcidades","resizable=no,scrollbars=yes,status=no,toolbar=no,location=no,menubar=no,width=450,height=190,screenX=230,screenY=250")
   } else {
		window.open(url,"pesqcidades","resizable=no,scrollbars=yes,status=no,toolbar=no,location=no,menubar=no,width=450,height=190,top=" + (window.screenTop + 130) + ",left=" + (window.screenLeft + 100))
   }
		
}	

function FechaForm(){
	if (event.keyCode == 27){
		window.close()
	}
}

function pesquisarCEP(){
	var URL = "busca_CEP.htm";
	window.open(URL,'busca_CEP','scrollbars=no,screenX=150,screenY=150,width=338,height=333');
}


//==============================================================
// FUNÇÃO PARA MONTAR AS TAB's DOS FORMULARIO
//==============================================================
function AlteraTab(tab,ntabs){

	for (i=1;i<=ntabs;i++){		
		document.getElementById('tab' + i).style.display = "none"		
		document.getElementById('imgtab' + i).style.display = "none"				
	}
	document.getElementById('tab' + tab).style.display = "block"
	document.getElementById('imgtab' + tab).style.display = "block"	
	
}


function montaTabs(vRotulos,nTabs) {

	if (vRotulos.length > 0) {
		nRotulos = vRotulos.length
		sAux=""
		for (i=0;i<vRotulos.length;i++) {
			sAux += "<div id='imgtab" + (i+1) + "' style='display:none'>" + '\n'

			sAux += "<table border=0 width=255 height=26 cellspacing=0 cellpadding=0 align=left background='images/tab_" + (i+1) + "_" + nTabs + ".jpg'>" + '\n'
			sAux += "<tr align=center>" + '\n'
			for (j=0;j<vRotulos.length;j++) {
				//TAB EM DESTAQUE
				if (i==j) {
					sAux += "<td width='" + parseInt(100/nRotulos) + "%'><a href='javascript:AlteraTab(" + (j+1) + "," + nTabs + ")' class=link-tab><b>" + vRotulos[j] + "</b></a></td>" + '\n'
				} else {
					sAux += "<td width='" + parseInt(100/nRotulos) + "%'><a href='javascript:AlteraTab(" + (j+1) + "," + nTabs + ")' class=link-tab>" + vRotulos[j] + "</a></td>"
				}
			}
			sAux += "</tr>"
			sAux += "</table>"
			sAux += "</div>"
		}
		document.write(sAux)
	}
	
}

/**
* Troca a fonte de uma 
*/
function trocaClass(id,classe){
	
	
	document.getElementById(id).className=classe;
	
	
}


var fontPub=12;

function aumentaFont()
{	

	fontPub++;
	cls = "fonte"+fontPub;
	
	if(fontPub<16)
	{	   
		trocaClass('conteudoPublicacao', cls);	
		//trocaClass('conteudoPublicacao', cls);			
		
	}else{
		
		fontPub = 16;
		cls = "fonte"+fontPub;		
		trocaClass('conteudoPublicacao', cls);	
		//trocaClass('conteudoPublicacao', cls);						
	}	
}


function diminuiFont()
{	
	fontPub--;
	cls = "fonte"+fontPub;

	if(fontPub>=10)
	{	  
		trocaClass('conteudoPublicacao', cls);	
		//trocaClass('conteudoPublicacao', cls);		
	}else{		
		fontPub = 10;
		cls = "fonte"+fontPub;
		trocaClass('conteudoPublicacao', cls);	
		//trocaClass('conteudoPublicacao', cls);		
	}	
}


function mascara(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);
  }
}



/**
* Descrição: deixa somente números na string digitada
* Data: 17/09/2007
* Autor: Jean Moreira
* @param: objeto campo
* @return: boolean
* Uso: onkeyup="isNumero(this)"
*/
function isNumero(campo) {
	var numeros = "";
	var keyCode;
	if(window.event){
		keyCode = window.event.keyCode;

		switch(keyCode) {
			case 8://backspace
			isTeclaUtil = true;
			break;
			case 46://delete
			isTeclaUtil = true;
			break;
			case 37://seta para esquerda
			isTeclaUtil = true;
			break;
			case 39://seta para direita
			isTeclaUtil = true;
			break;
			case 16://shift
			isTeclaUtil = true;
			break;
			case 36://home
			isTeclaUtil = true;
			break;
			case 35://end
			isTeclaUtil = true;
			break;
			default:
			isTeclaUtil = false;
			break;
		}

		if ( ((keyCode >= 48) && (keyCode <= 57)) || ((keyCode >= 96) && (keyCode <= 105)) || isTeclaUtil ) {
			void(0);
		} else {
			for(var i  = 0; i <= campo.value.length ; i++){

				if(campo.value.charAt(i) >= "0" && campo.value.charAt(i) <= "9" ){
					numeros += campo.value.charAt(i);
				}

			}
			campo.value = numeros;
		}
	} else {
		for(var i  = 0; i <= campo.value.length ; i++){

			if(campo.value.charAt(i) >= "0" && campo.value.charAt(i) <= "9" ){
				numeros += campo.value.charAt(i);
			}

		}
		campo.value = numeros;
	}
}
/** http://kevin.vanzonneveld.net
 * original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
 * +   improved by: Onno Marsman
 * +   bugfixed by: Daniel Esteban
 * +   improved by: Brett Zamir (http://brett-zamir.me)
 *     example 1: strpos('Kevin van Zonneveld', 'e', 5);
 *     returns 1: 14
*/
function strpos (haystack, needle, offset) {
    var i = (haystack+'').indexOf(needle, (offset || 0));
    return i === -1 ? false : i;
}
// http://kevin.vanzonneveld.net
// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   bugfixed by: Onno Marsman
// +   input by: saulius
// +   bugfixed by: Brett Zamir (http://brett-zamir.me)
// *     example 1: strrpos('Kevin van Zonneveld', 'e');
// *     returns 1: 16
// *     example 2: strrpos('somepage.com', '.', false);
// *     returns 2: 8
// *     example 3: strrpos('baa', 'a', 3);
// *     returns 3: false
// *     example 4: strrpos('baa', 'a', 2);
// *     returns 4: 2
function strrpos (haystack, needle, offset) {
    var i = -1;
    if (offset) {
        i = (haystack+'').slice(offset).lastIndexOf(needle); // strrpos' offset indicates starting point of range till end,
        // while lastIndexOf's optional 2nd argument indicates ending point of range from the beginning
        if (i !== -1) {
            i += offset;
        }
    }
    else {
        i = (haystack+'').lastIndexOf(needle);
    }
    return i >= 0 ? i : false;
}
function substr (str, start, len) {
// Returns part of a string
//
// version: 909.322
// discuss at: http://phpjs.org/functions/substr
// +     original by: Martijn Wieringa
// +     bugfixed by: T.Wild
// +      tweaked by: Onno Marsman
// +      revised by: Theriault
// +      improved by: Brett Zamir (http://brett-zamir.me)
// %    note 1: Handles rare Unicode characters if 'unicode.semantics' ini (PHP6) is set to 'on'
// *       example 1: substr('abcdef', 0, -1);
// *       returns 1: 'abcde'
// *       example 2: substr(2, 0, -6);
// *       returns 2: false
// *       example 3: ini_set('unicode.semantics',  'on');
// *       example 3: substr('a\uD801\uDC00', 0, -1);
// *       returns 3: 'a'
// *       example 4: ini_set('unicode.semantics',  'on');
// *       example 4: substr('a\uD801\uDC00', 0, 2);
// *       returns 4: 'a\uD801\uDC00'
// *       example 5: ini_set('unicode.semantics',  'on');
// *       example 5: substr('a\uD801\uDC00', -1, 1);
// *       returns 5: '\uD801\uDC00'
// *       example 6: ini_set('unicode.semantics',  'on');
// *       example 6: substr('a\uD801\uDC00z\uD801\uDC00', -3, 2);
// *       returns 6: '\uD801\uDC00z'
// *       example 7: ini_set('unicode.semantics',  'on');
// *       example 7: substr('a\uD801\uDC00z\uD801\uDC00', -3, -1)
// *       returns 7: '\uD801\uDC00z'
// Add: (?) Use unicode.runtime_encoding (e.g., with string wrapped in "binary" or "Binary" class) to
// allow access of binary (see file_get_contents()) by: charCodeAt(x) & 0xFF (see https://developer.mozilla.org/En/Using_XMLHttpRequest ) or require conversion first?

    var i = 0, allBMP = true, es = 0, el = 0, se = 0, ret = '';
    str += '';
    var end = str.length;

    // BEGIN REDUNDANT
    this.php_js = this.php_js || {};
    this.php_js.ini = this.php_js.ini || {};
    // END REDUNDANT
    switch(
        (this.php_js.ini['unicode.semantics'] &&
            this.php_js.ini['unicode.semantics'].local_value.toLowerCase())) {
        case 'on': // Full-blown Unicode including non-Basic-Multilingual-Plane characters
            // strlen()
            for (i=0; i < str.length; i++) {
                if (/[\uD800-\uDBFF]/.test(str.charAt(i)) && /[\uDC00-\uDFFF]/.test(str.charAt(i+1))) {
                    allBMP = false;
                    break;
                }
            }

            if (!allBMP) {
                if (start < 0) {
                    for (i = end - 1, es = (start += end); i >= es; i--) {
                        if (/[\uDC00-\uDFFF]/.test(str.charAt(i)) && /[\uD800-\uDBFF]/.test(str.charAt(i-1))) {
                            start--;
                            es--;
                        }
                    }
                }
                else {
                    var surrogatePairs = /[\uD800-\uDBFF][\uDC00-\uDFFF]/g;
                    while ((surrogatePairs.exec(str)) != null) {
                        var li = surrogatePairs.lastIndex;
                        if (li - 2 < start) {
                            start++;
                        }
                        else {
                            break;
                        }
                    }
                }

                if (start >= end || start < 0) {
                    return false;
                }
                if (len < 0) {
                    for (i = end - 1, el = (end += len); i >= el; i--) {
                        if (/[\uDC00-\uDFFF]/.test(str.charAt(i)) && /[\uD800-\uDBFF]/.test(str.charAt(i-1))) {
                            end--;
                            el--;
                        }
                    }
                    if (start > end) {
                        return false;
                    }
                    return str.slice(start, end);
                }
                else {
                    se = start + len;
                    for (i = start; i < se; i++) {
                        ret += str.charAt(i);
                        if (/[\uD800-\uDBFF]/.test(str.charAt(i)) && /[\uDC00-\uDFFF]/.test(str.charAt(i+1))) {
                            se++; // Go one further, since one of the "characters" is part of a surrogate pair
                        }
                    }
                    return ret;
                }
                break;
            }
            // Fall-through
        case 'off': // assumes there are no non-BMP characters;
                           //    if there may be such characters, then it is best to turn it on (critical in true XHTML/XML)
        default:
            if (start < 0) {
                start += end;
            }
            end = typeof len === 'undefined' ? end : (len < 0 ? len + end : len + start);
            // PHP returns false if start does not fall within the string.
            // PHP returns false if the calculated end comes before the calculated start.
            // PHP returns an empty string if start and end are the same.
            // Otherwise, PHP returns the portion of the string from start to end.
            return start >= str.length || start < 0 || start > end ? !1 : str.slice(start, end);
    }
    return undefined; // Please Netbeans
}
// http://kevin.vanzonneveld.net
// +   original by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   improved by: Gabriel Paderni
// +   improved by: Philip Peterson
// +   improved by: Simon Willison (http://simonwillison.net)
// +    revised by: Jonas Raoni Soares Silva (http://www.jsfromhell.com)
// +   bugfixed by: Anton Ongson
// +      input by: Onno Marsman
// +   improved by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +    tweaked by: Onno Marsman
// +      input by: Brett Zamir (http://brett-zamir.me)
// +   bugfixed by: Kevin van Zonneveld (http://kevin.vanzonneveld.net)
// +   input by: Oleg Eremeev
// +   improved by: Brett Zamir (http://brett-zamir.me)
// +   bugfixed by: Oleg Eremeev
// %          note 1: The count parameter must be passed as a string in order
// %          note 1:  to find a global variable in which the result will be given
// *     example 1: str_replace(' ', '.', 'Kevin van Zonneveld');
// *     returns 1: 'Kevin.van.Zonneveld'
// *     example 2: str_replace(['{name}', 'l'], ['hello', 'm'], '{name}, lars');
// *     returns 2: 'hemmo, mars'
function str_replace (search, replace, subject, count) {
    var i = 0, j = 0, temp = '', repl = '', sl = 0, fl = 0,
            f = [].concat(search),
            r = [].concat(replace),
            s = subject,
            ra = r instanceof Array, sa = s instanceof Array;
    s = [].concat(s);
    if (count) {
        this.window[count] = 0;
    }

    for (i=0, sl=s.length; i < sl; i++) {
        if (s[i] === '') {
            continue;
        }
        for (j=0, fl=f.length; j < fl; j++) {
            temp = s[i]+'';
            repl = ra ? (r[j] !== undefined ? r[j] : '') : r[0];
            s[i] = (temp).split(f[j]).join(repl);
            if (count && s[i] !== temp) {
                this.window[count] += (temp.length-s[i].length)/f[j].length;}
        }
    }
    return sa ? s : s[0];
}
/**
 * Descrição: Retorna primeira posição objeto json
 * @author Fabricio Nogueira.
 * Data: 24/09/2010
 * obs.: As funções: strpos; substr; str_replace são obrigatórias.
 **/
function retornaStringPrimeiraPosicaoJson(objto,inicioString){
    inicio = strpos(JSON.stringify(objto), '"',inicioString)
    fim = strpos(JSON.stringify(objto), '"',inicio+1)
    tamanho = (fim - inicio);
    produto = substr(JSON.stringify(objto), inicio,tamanho+1);
    produtoFinal = str_replace("\"","",produto);
    return produtoFinal;
//    alert(inicio)
//    alert(fim)
//    alert(tamanho)
//    alert(produto)
//    alert(produtoFinal)
}


/*Funções removidas da página FaleConosco pois estava retornando erros de validação pelo W3C*/


//Função que copia os textos dos options da UF e Municipio selecionado para seus respectivos Hiddens
function transfereValores(){
    //Espera um segundo para que os elementos possam ser devidamente copiados
    setInterval("void;", 1000);
    
    var IndiceSelecionadoUf = document.getElementById("cboUf").selectedIndex;
    var IndiceSelecionadoMunicipio = document.getElementById("cboMunicipios").selectedIndex;

    document.getElementById("hdUf").value = document.getElementById("cboUf").options[IndiceSelecionadoUf].text;
    document.getElementById("hdMunicipio").value = document.getElementById("cboMunicipios").options[IndiceSelecionadoMunicipio].text;
}

function buscaMunicipios(tuf){

    //limpa o select
    var c=document.getElementById("cboMunicipios")
    while(c.options.length>0)c.options[0]=null
    c.options[0]=new Option("Aguarde um instante...","")

    //Monta a url com a uf
    xmlhttp.open("GET", "modulos/busca_municipios.php?uf="+tuf,true);

    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4){
            
			//limpa o select
            var c=document.getElementById("cboMunicipios")
			
            while(c.options.length>0)c.options[0]=null
			
            //Transforma a lista de cidades JSON
            var aCidades=eval((xmlhttp.responseText));
            
			var aux = "";
			
			//popula o select com a lista de cidades obtida
			for(i=0;i<aCidades.length;i++){
				aux = unescape(aCidades[i])
				aux = aux.split("-")
				//aCidades[i]=unescape(aCidades[i])
				c.options[c.options.length]=new Option(aux[1],aux[0])
			}
        }
    }
    xmlhttp.send(null)
}

/*Fim das funções movidas da página FaleConosco*/
//-->

