// JavaScript Document
function mudabanner(img){
	document.getElementById('imgbanner').src = 'central/banner/img/'+img;
}


function comprar_front(idproduto, valor){
    var ajaxUC = ajaxInit();
	ajaxUC.open("GET", "central/func/comprar.php?idproduto="+idproduto+"&valor="+valor,true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				var valor = ajaxUC.responseText;
                //carrinho();                
            }else{
                alert(ajaxUC.responseText);
            }
		}
	}
	ajaxUC.send(null);
}

function cadastrarEmail(){
	var email = document.getElementById('email-newsletter').value;
    var ajaxUC = ajaxInit();
	ajaxUC.open("GET", "central/func/newsletter.php?email="+email,true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				var valor = ajaxUC.responseText;
                document.getElementById('email-newsletter').value = '';
				alert('Obrigado por se inscrever no nosso Newsletter !!');
            }else{
                alert(ajaxUC.responseText);
            }
		}
	}
	ajaxUC.send(null);

}

function maisFlores(){
    var ajaxUC = ajaxInit();
	ajaxUC.open("GET", "central/func/flor.php",true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				var valor = ajaxUC.responseText;
				//arr = valor.split('|');
				//document.getElementById('foto-flor').style.background = arr[0];
				//document.getElementById('TextoDescricaoFlores').innerHTML = arr[1];
				document.getElementById('flores').innerHTML = valor;
				correctPNG();
				window.setTimeout("maisFlores()", 10000);
            }else{
                alert(ajaxUC.responseText);
            }
		}
	}
	ajaxUC.send(null);

}



/////////////////////


function comprar(idproduto, valor){
    var ajaxUC = ajaxInit();
	ajaxUC.open("GET", "../func/comprar.php?idproduto="+idproduto+"&valor="+valor,true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				var valor = ajaxUC.responseText;
                carrinho();                
            }else{
                alert(ajaxUC.responseText);
            }
		}
	}
	ajaxUC.send(null);

}

function carrinho(){
    var ajaxUC = ajaxInit();
	ajaxUC.open("GET", "../func/carrinho.php",true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				var valor = ajaxUC.responseText;
				document.getElementById('carrinho').innerHTML=valor;
                var valorfinal = document.getElementById('valorfinal');
                if(valorfinal!='undefined'){
                   totalCarrinho();
                }else{
                    alert(valorfinal);
                }
                
			}else{
                alert(ajaxUC.responseText);
            }
		}
	}
	ajaxUC.send(null);
}

function totalCarrinho(){
    var ajaxUC = ajaxInit();
	ajaxUC.open("GET", "../func/carrinho_total.php",true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				var taxa = document.getElementById('taxaentrega').value;
				taxa = taxa.replace(',','.');
				if(taxa==''){taxa=0}
				var valor = ajaxUC.responseText;
				valor = valor.replace(',','.');
				total = (eval(valor) + eval(taxa)) + '';
				total = total.replace('.',',');
				document.getElementById('valorfinal').value = total;
			}else{
                alert(ajaxUC.responseText);
            }
		}
	}
	ajaxUC.send(null);
}

function excluirCarrinho(id){
    var ajaxUC = ajaxInit();
	ajaxUC.open("GET", "../func/carrinho_excluir.php?id="+id,true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				carrinho();
			}else{
                alert(ajaxUC.responseText);
            }
		}
	}
	ajaxUC.send(null);
}

function AddOpcao(combo, valor, strDescricao){
	var novaOpcao = new Option(strDescricao, valor);
	combo.options[combo.length] = novaOpcao;
	combo.options[combo.length].selected = true;
}

function DelOpcao(combo, strIndice){
	combo.options.remove(strIndice);
}

function editaLinha(idobj, tabela, id, campo, tipo){
	var obj = document.getElementById(idobj);
	var valor = obj.innerHTML;
	var mascara = "";
	if(tipo=='datetime'){
		mascara = " onkeyup=\"mascaradata(this.value, this)\"";
	}
	obj.innerHTML = "<input id=\""+idobj+campo+"ED\" type=\"text\" value=\""+valor+"\" antigo=\""+valor+"\" name=\"campo\" class=\"inputText\" style=\"width: 90%\" onblur=\"atualizaLinha('"+idobj+"', this.value, '"+tabela+"', "+id+", '"+campo+"', '"+tipo+"')\" onkeypress=\"if(event.keyCode == '13'){atualizaLinha('"+idobj+"', this.value, '"+tabela+"', "+id+", '"+campo+"', '"+tipo+"')}else if(event.keyCode=='27'){cancelaLinha('"+idobj+"', this.getAttribute('antigo'))}\" "+mascara+">";
	objaux = document.getElementById(idobj+campo+"ED");
	objaux.focus();
}

function cancelaLinha(idobj, valor){
	obj = document.getElementById(idobj);
	obj.innerHTML = "CANCELADO";
	window.setTimeout("document.getElementById('"+idobj+"').innerHTML='"+valor+"'", 2000);
}

function atualizaLinha(idobj, valor, tabela, id, campo, tipo){
	obj = document.getElementById(idobj);
	url = "../includes/atualiza_campo.php?id="+id+"&tabela="+tabela+"&campo="+campo+"&valor="+valor+"&tipo="+tipo;
	var ajaxUC = ajaxInit();
	ajaxUC.open("GET", url,true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				document.getElementById(idobj).style.color = 'blue';
				obj.innerHTML="ATUALIZADO";
				window.setTimeout("document.getElementById('"+idobj+"').innerHTML='"+valor+"'; document.getElementById('"+idobj+"').style.fontWeight = 'normal'; document.getElementById('"+idobj+"').style.color = 'black';",2000);
			}else{
				document.getElementById(idobj).style.color = 'red';
				obj.innerHTML="ERRO";
				window.setTimeout("document.getElementById('"+idobj+"').innerHTML='"+valor+"'; document.getElementById('"+idobj+"').style.fontWeight = 'normal'; document.getElementById('"+idobj+"').style.color = 'black';",2000);				
			}
		}
	}
	ajaxUC.send(null);
}


function enviarCadastro(){
	//inputs = document.forms[0].elements;
	inputs = document.getElementsByTagName("input");
	erro=0;
	nome = "";
	tam = inputs.length;
	if(tam>20){
		tam=21;
	}
	cont=0;
	for(x=0; x<=tam-1; x++){
		aux = inputs[x];
		if(aux.getAttribute('obrigatorio')=="sim"){
			if(aux.value==''){
				erro=1;
				cont++;
				nome += cont+".)  "+aux.getAttribute('name')+"\n";
			}
		}
	}
	
	if(erro==1){
		alert("Preencher os campos obrigatarios abaixo: \n\n" + nome);
	}else{
		document.forms[0].submit();
	}
}

function abcPesquisa(valor){
	document.getElementById("inputInicio").value = 1;
	document.getElementById("inputValor").value = valor;
	document.forms[0].submit();	
}

function funcListaParceiro(idevento){
	var ajaxUC = ajaxInit();
	ajaxUC.open("GET", "../classes/parceiro_listaevento.php?idevento="+idevento,true);
	ajaxUC.onreadystatechange = function() {
		if(ajaxUC.readyState == 4) {
			if(ajaxUC.status == 200) {
				var valor = ajaxUC.responseText;
				document.getElementById('parceirolista').innerHTML = valor;

			}
		}
	}
	ajaxUC.send(null);
}

function mascaradata(S,campo){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	var dig = "";
	var espaco;
	var numero;
	numero = 0;
	espaco = 0;
	S = limpa_string(S);	
   	for (var i=0; i<S.length; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
  		if (i<=8) {
			if (Digitos.indexOf(digito)>=0){temp = temp + digito}
			if (numero == 4 ){if (Digitos.indexOf(digito)>=0){temp = "/"+ S.charAt(0) + S.charAt(1) + S.charAt(2) + S.charAt(3)}}
			if (numero == 5 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"/"+ S.charAt(1) + S.charAt(2) + S.charAt(3) + S.charAt(4)}}
			if (numero == 6 ){if (Digitos.indexOf(digito)>=0){temp = "/"+ S.charAt(0) + S.charAt(1) +"/"+ S.charAt(2) + S.charAt(3) + S.charAt(4) + S.charAt(5)}}
			if (numero == 7 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"/"+ S.charAt(1) + S.charAt(2) +"/"+ S.charAt(3) + S.charAt(4) + S.charAt(5)+ S.charAt(6)}}
			if (numero == 8 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) +"/"+ S.charAt(2) + S.charAt(3) +"/"+ S.charAt(4) + S.charAt(5) + S.charAt(6)+ S.charAt(7)}}
		}
	}
    campo.value = temp;
}

function mascaradatahora(S,campo){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	var dig = "";
	var espaco;
	var numero;
	numero = 0;
	espaco = 0;
	S = limpa_string(S);	
   	for (var i=0; i<S.length; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
  		if (i<=14) {
			if (Digitos.indexOf(digito)>=0){temp = temp + digito}
			if (numero == 5 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"/"+ S.charAt(1) + S.charAt(2) + S.charAt(3) + S.charAt(4)}}
			if (numero == 6 ){if (Digitos.indexOf(digito)>=0){temp = "/"+ S.charAt(0) + S.charAt(1) +"/"+ S.charAt(2) + S.charAt(3) + S.charAt(4) + S.charAt(5)}}
			if (numero == 7 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"/"+ S.charAt(1) + S.charAt(2) +"/"+ S.charAt(3) + S.charAt(4) + S.charAt(5)+ S.charAt(6)}}
			if (numero == 8 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) +"/"+ S.charAt(2) + S.charAt(3) +"/"+ S.charAt(4) + S.charAt(5) + S.charAt(6)+ S.charAt(7)}}
			if (numero == 9 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + S.charAt(2) +" "+ S.charAt(3) + S.charAt(4) + ":" + S.charAt(5) + S.charAt(6) + ":" + S.charAt(7)+ S.charAt(8)}}
			if (numero == 10 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + S.charAt(2) + S.charAt(3) +" "+ S.charAt(4) + S.charAt(5) + ":" + S.charAt(6) + S.charAt(7) + ":" + S.charAt(8)+ S.charAt(9)}}
			if (numero == 11 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + "/" + S.charAt(1) + S.charAt(2) + S.charAt(3) + S.charAt(4) + " " + S.charAt(5) + S.charAt(6) + ":" + S.charAt(7) + S.charAt(8) + ":" + S.charAt(9)+ S.charAt(10)}}
			if (numero == 12 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + "/" + S.charAt(2) + S.charAt(3) + S.charAt(4) + S.charAt(5) + " " + S.charAt(6) + S.charAt(7) + ":" + S.charAt(8) + S.charAt(9) + ":" + S.charAt(10)+ S.charAt(11)}}
			if (numero == 13 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + "/" + S.charAt(1) + S.charAt(2) + "/" + S.charAt(3) + S.charAt(4) + S.charAt(5) + S.charAt(6) + " " + S.charAt(7) + S.charAt(8) + ":" + S.charAt(9) + S.charAt(10) + ":" + S.charAt(11)+ S.charAt(12)}}
			if (numero == 14 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + "/" + S.charAt(2) + S.charAt(3) + "/" + S.charAt(4) + S.charAt(5) + S.charAt(6) + S.charAt(7) + " "+ S.charAt(8) + S.charAt(9) + ":" + S.charAt(10) + S.charAt(11) + ":" + S.charAt(12)+ S.charAt(13)}}
		}
	}
    campo.value = temp;
}

function mascarahora(S,campo){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	var dig = "";
	var espaco;
	var numero;
	numero = 0;
	espaco = 0;
	S = limpa_string(S);	
   	for (var i=0; i<S.length; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
  		if (i<=5) {
			if (Digitos.indexOf(digito)>=0){temp = temp + digito}
			if (numero == 3 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + ":" + S.charAt(1)+ S.charAt(2)}}
			if (numero == 4 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + ":" + S.charAt(2)+ S.charAt(3)}}
			if (numero == 5 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + ":" + S.charAt(1) + S.charAt(2) + ":" + S.charAt(3)+ S.charAt(4)}}
			if (numero == 6 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + ":" + S.charAt(2) + S.charAt(3) + ":" + S.charAt(4)+ S.charAt(5)}}
		}
	}
    campo.value = temp;
}

function mascaracep(S,campo){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	var dig = "";
	var espaco;
	var numero;
	numero = 0;
	espaco = 0;
	S = limpa_string(S);	
   	for (var i=0; i<S.length; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
  		if (i<=6) {
			if (Digitos.indexOf(digito)>=0){temp = temp + digito}
			if (numero == 3 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + "-" + S.charAt(1) + S.charAt(2) + S.charAt(3)}}
			if (numero == 4 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + "-" + S.charAt(2) + S.charAt(3) + S.charAt(4)}}
			if (numero == 5 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + S.charAt(2) + "-" + S.charAt(3) + S.charAt(4) + S.charAt(5)}}
			if (numero == 6 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + "." + S.charAt(1) + S.charAt(2) + S.charAt(3) + "-" + S.charAt(4) + S.charAt(5) + S.charAt(6)}}
			if (numero == 7 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + "." + S.charAt(2) + S.charAt(3) + S.charAt(4) + "-" + S.charAt(5) + S.charAt(6) + S.charAt(7)}}
		}
	}
//	document.formulario.CGC.value = temp;
    campo.value = temp;
}

function mascarafone(S,campo){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	var dig = "";
	var espaco;
	var numero;
	numero = 0;
	espaco = 0;
	S = limpa_string(S);	
   	for (var i=0; i<S.length; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
  		if (i<=10) {
			if (Digitos.indexOf(digito)>=0){temp = temp + digito}
			if (numero == 5 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"-"+ S.charAt(1) + S.charAt(2) + S.charAt(3) + S.charAt(4)}}
			if (numero == 6 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) +"-"+ S.charAt(2) + S.charAt(3) + S.charAt(4) + S.charAt(5)}}
			if (numero == 7 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + S.charAt(2) +"-"+ S.charAt(3) + S.charAt(4) + S.charAt(5)+ S.charAt(6)}}
			if (numero == 8 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + S.charAt(2) + S.charAt(3) +"-"+ S.charAt(4) + S.charAt(5) + S.charAt(6) + S.charAt(7)}}
			if (numero == 9 ){if (Digitos.indexOf(digito)>=0){temp = "(" + S.charAt(0) + ") " + S.charAt(1) + S.charAt(2) + S.charAt(3) + S.charAt(4) +"-"+ S.charAt(5) + S.charAt(6) + S.charAt(7)+ S.charAt(8)}}
			if (numero == 10 ){if (Digitos.indexOf(digito)>=0){temp = "(" + S.charAt(0) + S.charAt(1) + ") " + S.charAt(2) + S.charAt(3) + S.charAt(4) + S.charAt(5) +"-"+ S.charAt(6) + S.charAt(7) + S.charAt(8)+ S.charAt(9)}}
		}
	}
//	document.formulario.CGC.value = temp;
    campo.value = temp;
}

function mascaranumero(S,campo){
	var Digitos = "0123456789";
	S = limpa_string(Money_2_Java(S));
	ini_z = false
	sem_zero = ""
	for (var i=0; i<S.length; i++){
		if (ini_z == true || S.charAt(i) != "0"){
			ini_z = true;
			sem_zero = sem_zero + S.charAt(i);
		}
	}
	S = sem_zero;
	a_virg = "";
	numero = 0;
   	for (var i=0; i<S.length - 2; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0){a_virg = a_virg + digito}
	}

 	if (S.length == 1){
		temp = "0.0" + S;
		temp = NumJava_2_Money(temp);
	}else if (S.length == 2){
		temp = "0." + S;
		temp = NumJava_2_Money(temp);
	}else if (S.length > 2){
		temp = a_virg + "." + S.charAt(S.length-2) + S.charAt(S.length-1);
		temp = NumJava_2_Money(temp);
	}else{
		temp = S;
	}
	if (eval(Money_2_Java(temp)) == 0){temp = "";}
	if(temp=="")
	{temp = "0,00"}
    campo.value = temp;
}

function mascarapeso(S,campo){
	var Digitos = "0123456789";
	S = limpa_string(Money_2_Java(S));
	ini_z = false
	sem_zero = ""
	for (var i=0; i<S.length; i++){
		if (ini_z == true || S.charAt(i) != "0"){
			ini_z = true;
			sem_zero = sem_zero + S.charAt(i);
		}
	}
	S = sem_zero;
	a_virg = "";
	numero = 0;
   	for (var i=0; i<S.length - 3; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0){a_virg = a_virg + digito}
	}
	if (S.length == 1){
		temp = "0.00" + S
		temp = NumJava_2_Money(temp);
	}else if (S.length == 2){
		temp = "0.0" + S
		temp = NumJava_2_Money(temp);
	}else if (S.length == 3){
		temp = "0." + S
		temp = NumJava_2_Money(temp);
	}else if (S.length > 3){
		temp = a_virg + "." + S.charAt(S.length-3) + S.charAt(S.length-2) + S.charAt(S.length-1);
		temp = NumJava_2_Money(temp);
	}else{
		temp = S;
	}
	if (eval(Money_2_Java(temp)) == 0){temp = "";}
	if(temp=="")
	{temp = "0.00"}
    campo.value = temp;
}

function mascaranumero2(S,campo){
	var Digitos = "0123456789";
	S = limpa_string(Money_2_Java(S));
	ini_z = false
	sem_zero = ""
	for (var i=0; i<S.length; i++){
		if (ini_z == true || S.charAt(i) != "0"){
			ini_z = true;
			sem_zero = sem_zero + S.charAt(i);
		}
	}
	S = sem_zero;
	a_virg = "";
	numero = 0;
   	for (var i=0; i<S.length - 2; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
		if (Digitos.indexOf(digito)>=0){a_virg = a_virg + digito}
	}
	temp = S;
	if (eval(Money_2_Java(temp)) == 0){temp = "";}
    campo.value = temp;
}

function mascaracpfcnpj(S,campo){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	var dig = "";
	var espaco;
	var numero;
	numero = 0;
	espaco = 0;
	S = limpa_string(S);	
   	for (var i=0; i<S.length; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
  		if (i<=13) {
			if (Digitos.indexOf(digito)>=0){temp = temp + digito}
			if (numero == 2 ){temp = "-" + S.substring(S.length-2,S.length)}
			if (numero == 3 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"-"+ S.charAt(1) + S.charAt(2)}}
			if (numero == 4 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + "-" + S.charAt(2) + S.charAt(3)}}
			if (numero == 5 ){if (Digitos.indexOf(digito)>=0){temp = "."+S.charAt(0) + S.charAt(1) + S.charAt(2) + "-" + S.charAt(3) + S.charAt(4)}}
			if (numero == 6 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"."+ S.charAt(1) + S.charAt(2) + S.charAt(3) + "-" + S.charAt(4) + S.charAt(5)}}
			if (numero == 7 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) +"."+ S.charAt(2) + S.charAt(3) + S.charAt(4) + "-" + S.charAt(5)+ S.charAt(6)}}
			if (numero == 8 ){if (Digitos.indexOf(digito)>=0){temp = "."+S.charAt(0) + S.charAt(1) + S.charAt(2) +"."+ S.charAt(3) + S.charAt(4) + S.charAt(5) + "-" + S.charAt(6)+ S.charAt(7)}}
			if (numero == 9 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"."+ S.charAt(1) + S.charAt(2) + S.charAt(3) +"."+ S.charAt(4) + S.charAt(5) + S.charAt(6) + "-" + S.charAt(7)+ S.charAt(8)}}
			if (numero == 10){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) +"."+ S.charAt(2) + S.charAt(3) + S.charAt(4) +"."+ S.charAt(5) + S.charAt(6) + S.charAt(7) + "-" + S.charAt(8)+ S.charAt(9)}}
			if (numero == 11){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + S.charAt(2) +"."+ S.charAt(3) + S.charAt(4) + S.charAt(5) +"."+ S.charAt(6) + S.charAt(7) + S.charAt(8) + "-" + S.charAt(9) + S.charAt(10)}}
			if (numero == 12){if (Digitos.indexOf(digito)>=0){temp = "." + S.charAt(0) + S.charAt(1) + S.charAt(2) + "." + S.charAt(3) + S.charAt(4) + S.charAt(5) + "/" +  S.charAt(6) + S.charAt(7) + S.charAt(8) + S.charAt(9) + "-" + S.charAt(10) + S.charAt(11)}}
			if (numero == 13){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + "." +  S.charAt(1) + S.charAt(2) + S.charAt(3) +"."+ S.charAt(4) + S.charAt(5) + S.charAt(6) +"/"+ S.charAt(7) + S.charAt(8) + S.charAt(9) + S.charAt(10) +"-"+ S.charAt(11) + S.charAt(12)}}
			if (numero == 14){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + "." + S.charAt(2) + S.charAt(3) + S.charAt(4) + "." + S.charAt(5) + S.charAt(6) + S.charAt(7) + "/" + S.charAt(8) + S.charAt(9) + S.charAt(10) + S.charAt(11) +"-"+ S.charAt(12) + S.charAt(13)}}
		}
	}
//	document.formulario.CGC.value = temp;
    campo.value = temp;
}

function mascaracnpjcol(S,campo){
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
	var dig = "";
	var espaco;
	var numero;
	numero = 0;
	espaco = 0;
	S = limpa_string(S);	
   	for (var i=0; i<S.length; i++){
	  	numero = numero + 1;
	  	digito = S.charAt(i);
  		if (i<=11) {
			if (Digitos.indexOf(digito)>=0){temp = temp + digito}
			if (numero == 2 ){temp = "-" + S.substring(S.length-2,S.length)}
			if (numero == 3 ){if (Digitos.indexOf(digito)>=0){temp = "." + S.charAt(0) + S.charAt(1) + S.charAt(2)}}
			if (numero == 4 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"."+ S.charAt(1) + S.charAt(2) + S.charAt(3)}}
			if (numero == 5 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) +"."+ S.charAt(2) + S.charAt(3) + S.charAt(4)}}
			if (numero == 6 ){if (Digitos.indexOf(digito)>=0){temp = "."+S.charAt(0) + S.charAt(1) + S.charAt(2) +"."+ S.charAt(3) + S.charAt(4) + S.charAt(5)}}
			if (numero == 7 ){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) +"."+ S.charAt(1) + S.charAt(2) + S.charAt(3) +"."+ S.charAt(4) + S.charAt(5) + S.charAt(6)}}
			if (numero == 8){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) +"."+ S.charAt(2) + S.charAt(3) + S.charAt(4) +"."+ S.charAt(5) + S.charAt(6) + S.charAt(7)}}
			if (numero == 9){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + S.charAt(2) +"."+ S.charAt(3) + S.charAt(4) + S.charAt(5) +"."+ S.charAt(6) + S.charAt(7) + S.charAt(8)}}
			if (numero == 10){if (Digitos.indexOf(digito)>=0){temp = "." + S.charAt(0) + S.charAt(1) + S.charAt(2) + "." + S.charAt(3) + S.charAt(4) + S.charAt(5) + "/" +  S.charAt(6) + S.charAt(7) + S.charAt(8) + S.charAt(9)}}
			if (numero == 11){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + "." +  S.charAt(1) + S.charAt(2) + S.charAt(3) +"."+ S.charAt(4) + S.charAt(5) + S.charAt(6) +"/"+ S.charAt(7) + S.charAt(8) + S.charAt(9) + S.charAt(10)}}
			if (numero == 12){if (Digitos.indexOf(digito)>=0){temp = S.charAt(0) + S.charAt(1) + "." + S.charAt(2) + S.charAt(3) + S.charAt(4) + "." + S.charAt(5) + S.charAt(6) + S.charAt(7) + "/" + S.charAt(8) + S.charAt(9) + S.charAt(10) + S.charAt(11)}}
		}
	}
//	document.formulario.CGC.value = temp;
    campo.value = temp;
}

function limpa_string(S){
	// Deixa so' os digitos no numero
	var Digitos = "0123456789";
	var temp = "";
	var digito = "";
   	for (var i=0; i<S.length; i++){
      digito = S.charAt(i);
      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
   	}
   return temp
}

function limpa_string_virg(S){
	// Deixa so' os digitos no numero
	var Digitos = "0123456789,.";
	var temp = "";
	var digito = "";
   	for (var i=0; i<S.length; i++){
	      digito = S.charAt(i);
	      if (Digitos.indexOf(digito)>=0){temp=temp+digito}
   	}
   return temp;
}

function valida_CPF(s){
	var i;
	s = limpa_string(s);
	var c = s.substr(0,9);
	var dv = s.substr(9,2);
	var d1 = 0;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(10-i);
	}
        if (d1 == 0) return false;
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 9; i++){
		d1 += c.charAt(i)*(11-i);
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}
   return true;
}
function valida_CGC(s){
	var i;
	s = limpa_string(s);
	var c = s.substr(0,12);
	var dv = s.substr(12,2);

	var d1 = 0;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+(i % 8));
	}
        if (d1 == 0) return false;
        d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(0) != d1){
		return false;
	}

	d1 *= 2;
	for (i = 0; i < 12; i++){
		d1 += c.charAt(11-i)*(2+((i+1) % 8));
	}
	d1 = 11 - (d1 % 11);
	if (d1 > 9) d1 = 0;
	if (dv.charAt(1) != d1){
		return false;
	}
        return true;
}
function ltrim(string){
	inicio = false;
	nova_string = "";
	for (x=0;x<string.length;x++){
		if (string.charAt(x) != " "){
			inicio = true;
			nova_string = nova_string + string.charAt(x);
		}else if(inicio){
			nova_string = nova_string + string.charAt(x);
		}
	}
	return nova_string
}
