function checkdata() {
	with(document.cadastro) {	


			if (nome.value == "") {
				alert("Preencha o nome do Comprador!");
				nome.focus();
				return false; }

			if (sobrenome.value == "") {
				alert("Preencha o sobrenome do Comprador!");
				sobrenome.focus();
				return false; }

			if (cgc.value != "") {
				if(!checaCPF(cgc.value)){	
					alert("O CPF é Invalido!");
					cgc.select();
					return false;}
				}	
			

			if (cgc.value == "") {
			alert("Preencha o CPF do Comprador!");
				cgc.select();
				return false;
			}	

	
			if (empresa.value == "") {
				alert("Preencha o nome da Empresa do Comprador!");
				empresa.focus();
				return false; }

	        if (cargo.value == "") {
				alert("Preencha o Cargo do Comprador!");
				cargo.focus();
				return false; }

	        if (area_atuacao.value == "") {
				alert("Preencha o Área de Atuação do Comprador!");
				area_atuacao.focus();
				return false; }
	

	        if (quem_paga[1].checked && cgc.value == "" ) {
				alert("Preencha o CPF do Comprador!");
				cgc.focus();
				return false; }

	        if (quem_paga[1].checked && end_res.value == "" ) {
				alert("Preencha o Endereço Residencial do Comprador!");
				end_res.focus();
				return false; }
				
	        if (quem_paga[1].checked && num_res.value == "" ) {
				alert("Preencha o Número/Complemento do \n Endereço Residencial do Comprador!");
				num_res.focus();
				return false; }
				
	        if (quem_paga[1].checked && bairro_res.value == "" ) {
				alert("Preencha o Bairro do \n Residencial do Comprador!");
				bairro_res.focus();
				return false; }
				

	        if (quem_paga[1].checked && cep_res.value == "" ) {
				alert("Preencha o CEP do Residencial do Comprador!");
				cep_res.focus();
				return false; }

	        if (quem_paga[1].checked && cidade_res.value == "" ) {
				alert("Preencha a Cidade do \n Endereço Residencial do Comprador!");
				cidade_res.focus();
				return false; }

	        if (quem_paga[1].checked && uf_res.value == "" ) {
				alert("Selecione o Estado do \n Endereço Residencial do Comprador!");
				uf_res.focus();
				return false; }
				
		    if (email_pess.value != "") {
				if(!isEmailAddr(email_pess.value))
						{	alert("O E-mail Pessoal está Incorreto!");
							email_pess.select();
							return false;
						}
				}	
				
				
	        if (end_emp.value == "") {
				alert("Preencha o Endereço Comercial Comprador!");
				end_emp.focus();
				return false; }
				
	        if (num_emp.value == "") {
				alert("Preencha o Número/Complemento do  \n Endereço Comercial do Comprador!");
				num_emp.focus();
				return false; }

	        if (bairro_emp.value == "") {
				alert("Preencha o Bairro do \n Endereço Comercial do Comprador!");
				bairro_emp.focus();
				return false; }

	        if (cep_emp.value == "") {
				alert("Preencha o CEP do\n Endereço Comercial do Comprador!");
				cep_emp.focus();
				return false; }
				
	        if (cidade_emp.value == "") {
				alert("Preencha a Cidade do \n Endereço Comercial do Comprador!");
				cidade_emp.focus();
				return false; }	
				
	        if (estado_emp.value == "") {
				alert("Preencha o Estado do \n Endereço Comercial do Comprador!");
				estado_emp.focus();
				return false; }					
				
	        if (tel_emp.value == "") {
				alert("Preencha o Número de Telefone Comercial do Comprador!");
				tel_emp.focus();
				return false; }	
				
	        if (fax_emp.value == "") {
				alert("Preencha o Número de Fax Comercial do Comprador!");
				fax_emp.focus();
				return false; }	

	        if (email_com.value == "") {
				alert("Preencha o E-mail Comercial do Comprador!");
				email_com.focus();
				return false; }	
				else
				{
					if(!isEmailAddr(email_com.value))
						{	alert("O E-mail Comercial está Incorreto!");
							email_com.select();
							return false;
						}
				}
				
			if (!resp_insc[0].checked && !resp_insc[1].checked) {
				alert("Selecione o Responsável pela Inscrição!");
				resp_insc[0].focus();
				return false; }

	        if (nome_resp.value == "") {
				alert("Preencha o Nome do Responsável pela Inscrição!");
				nome_resp.focus();
				return false; }	

			if (sobrenome_resp.value == "") {
				alert("Preencha o Sobrenome do Responsável pela Inscrição!");
				sobrenome_resp.focus();
				return false; }	
				
			if (cgc_resp.value != "") {
				if(!checaCPF(cgc_resp.value)){	
					alert("O CPF é Invalido!");
					cgc_resp.select();
					return false;}
				}	
			

			if (cgc_resp.value == "") {
			alert("Preencha o CPF do Comprador!");
				cgc_resp.select();
				return false;
			}	

	        if (telefone_resp.value == "") {
				alert("Preencha o Telefone do Responsável pela Inscrição!");
				telefone_resp.focus();
				return false; }	

	        if (email_resp.value == "") {

				alert("Preencha o E-mail do Responsável pela Inscrição!");
				email_resp.focus();
				return false; }
				else
				{
					if(!isEmailAddr(email_resp.value))
						{	alert("O E-mail do Responsável está Incorreto!");
							email_resp.select();
							return false;
						}
				}
				

	        if (cargo_resp.value == "") {
				alert("Preencha o Cargo do Responsável pela Inscrição!");
				cargo_resp.focus();
				return false; }	

	        if (area_atuacao_resp.value == "") {
				alert("Preencha a Área de Atuação do Responsável pela Inscrição!");
				area_atuacao_resp.focus();
				return false; }	

	        if (end_resp.value == "") {
				alert("Preencha o Endereço do Responsável pela Inscrição!e!");
				end_resp.focus();
				return false; }	

			if (num_resp.value == "") {
				alert("Preencha o Número/Complemento do \n Responsável pela Inscrição!");
				num_resp.focus();
				return false; }	
				
			if (bairro_resp.value == "") {
				alert("Preencha o Bairro do Responsável pela Inscrição!");
				bairro_resp.focus();
				return false; }	

			if (cep_resp.value == "") {
				alert("Preencha o CEP do Responsável pela Inscrição!");
				cep_resp.focus();
				return false; }	
				
			if (cidade_resp.value == "") {
				alert("Preencha a Cidade do Responsável pela Inscrição!");
				cidade_resp.focus();
				return false; }	

			if (estado_resp.value == "") {
				alert("Preencha o Estado do Responsável pela Inscrição!");
				estado_resp.focus();
				return false; }
				
			if (!quem_paga[0].checked && !quem_paga[1].checked) {
				alert("Selecione para quem será a Nota Fiscal!");
				quem_paga[0].focus();
				return false; }
				
			if (razao_social.value == "") {
				alert("Preencha a Nome/Razão Social \n para Nota Fiscal!");
				razao_social.focus();
				return false; }
				
			if (qtd.value == "") {
				alert("Digite a quantidade!");
				qtd.focus();
				return false;
			}
			
			if (!forma[0].checked && !forma[1].checked && !forma[2].checked) {
				alert("Selecione a Forma de Pagamento!");
				forma[0].focus();
				return false; }
				
			if (cnpj_pag.value == "") {
				alert("Preencha o CPF/CNPJ para Nota Fiscal!");
				cnpj_pag.focus();
				return false; }
				

			if (cnpj_pag.value != "") {
				if(document.cadastro.quem_paga[1].checked) {
					if(!checaCPF(cgc.value)){	
						alert("O CPF é Invalido!");
						cgc.select();
						return false;}
					} 
					else {
						if(!checaCNPJ(cnpj_pag.value)){
						alert("Preencha o CNPJ corretamente!");
						cnpj_pag.select();
						return false;}
					}
				}	
			

			if (quem_paga[0].checked && inscricao.value == "") {
				alert("Preencha a Inscrição para Nota Fiscal!");
				inscricao.focus();
				return false; }
				
			if (!tipo_insc[0].checked && !tipo_insc[1].checked && quem_paga[0].checked && inscricao.value != "") {
				alert("Preencha o Tipo de Inscrição!");
				tipo_insc[0].focus();
				return false; }
				
			if (end_pag.value == "") {
				alert("Preencha o Endereço para Nota Fiscal!");
				end_pag.focus();
				return false; }
				
			if (num_pag.value == "") {
				alert("Preencha o Número/Complemento para Nota Fiscal!");
				num_pag.focus();
				return false; }
				
			if (bairro_pag.value == "") {
				alert("Preencha o Bairro para Nota Fiscal!");
				bairro_pag.focus();
				return false; }
				
			if (cep_pag.value == "") {
				alert("Preencha o CEP para Nota Fiscal!");
				cep_pag.focus();
				return false; }

			if (cidade_pag.value == "") {
				alert("Preencha a Cidade para Nota Fiscal!");
				cidade_pag.focus();
				return false; }

			if (estado_pag.value == "") {
				alert("Preencha o Estado para Nota Fiscal!");
				estado_pag.focus();
				return false; }
				
			if (!end_envio[0].checked && !end_envio[1].checked && !end_envio[2].checked) {
				alert("Selecione o Endereço de Envio da Publicação!");
				end_envio[0].focus();
				return false; }

			if (!aceito.checked) {
				alert("Você deve aceitar as condições apresentadas!");
				aceito.focus();
				return false; }

             submit();
	}  //end with
} //funciton
function  Quem_Paga_PJ() {
	cadastro.razao_social.value = cadastro.empresa.value;
	cadastro.cnpj_pag.value = "";
	cadastro.end_pag.value = cadastro.end_emp.value;
	cadastro.num_pag.value = cadastro.num_emp.value;
	cadastro.bairro_pag.value = cadastro.bairro_emp.value;		
	cadastro.cep_pag.value = cadastro.cep_emp.value;
	cadastro.cidade_pag.value = cadastro.cidade_emp.value;
	cadastro.estado_pag.value = cadastro.estado_emp.value;
}

function  Quem_Paga_PF () {
	cadastro.razao_social.value = cadastro.nome_resp.value;
	cadastro.cnpj_pag.value = cadastro.cgc.value;
	cadastro.end_pag.value = cadastro.end_res.value;
	cadastro.num_pag.value = cadastro.num_res.value;
	cadastro.bairro_pag.value = cadastro.bairro_res.value;		
	cadastro.cep_pag.value = cadastro.cep_res.value;
	cadastro.cidade_pag.value = cadastro.cidade_res.value;
	cadastro.estado_pag.value = cadastro.uf_res.value;
}
function chama_Resp_Proprio() {
	if (cadastro.resp_insc[1].checked) {Resp_Proprio();}
}
function Resp_Proprio() {  //Quando digitar nas informacoes pessoais alterar no responsavel
	cadastro.nome_resp.value = cadastro.nome.value;
	cadastro.sobrenome_resp.value = cadastro.sobrenome.value;	
	cadastro.cgc_resp.value = cadastro.cgc.value;	
	cadastro.telefone_resp.value = cadastro.telefone_pess.value;
	cadastro.email_resp.value = cadastro.email_pess.value;
	cadastro.fax_resp.value = cadastro.fax_emp.value;
	cadastro.cargo_resp.value = cadastro.cargo.value;
	cadastro.area_atuacao_resp.value = cadastro.area_atuacao.value;
	cadastro.end_resp.value = cadastro.end_res.value;
	cadastro.num_resp.value = cadastro.num_res.value;
	cadastro.bairro_resp.value = cadastro.bairro_res.value;
	cadastro.cep_resp.value = cadastro.cep_res.value;
	cadastro.cidade_resp.value = cadastro.cidade_res.value;
	cadastro.estado_resp.value = cadastro.uf_res.value;
}
function chama_Proprio_Resp() {
	if (cadastro.resp_insc[1].checked) {Proprio_Resp();}
}
function Proprio_Resp() {//Quando digitar nas informacoes do responsavel alterar as pessoas
	cadastro.email_com.value = cadastro.email_resp.value;
	cadastro.nome.value = cadastro.nome_resp.value;
	cadastro.fax_emp.value = cadastro.fax_resp.value;
	cadastro.tel_emp.value = cadastro.telefone_resp.value;
	cadastro.email_com.value = cadastro.email_resp.value;
	cadastro.cargo.value = cadastro.cargo_resp.value;
	cadastro.area_atuacao.value = cadastro.area_atuacao_resp.value;
	cadastro.end_emp.value = cadastro.end_resp.value;
	cadastro.num_emp.value = cadastro.num_resp.value;
	cadastro.bairro_emp.value = cadastro.bairro_resp.value;
	cadastro.cep_emp.value = cadastro.cep_resp.value;
	cadastro.cidade_emp.value = cadastro.cidade_resp.value;
	cadastro.estado_emp.value = cadastro.estado_resp.value;
}



function Resp_Terceiro() {
	cadastro.nome_resp.value = '';
	cadastro.sobrenome_resp.value = '';	
	cadastro.cgc_resp.value = '';	
	cadastro.telefone_resp.value = '';
	cadastro.email_resp.value = '';
	cadastro.fax_resp.value = '';
	cadastro.cargo_resp.value = '';
	cadastro.area_atuacao_resp.value = '';
	cadastro.end_resp.value = cadastro.end_emp.value;
	cadastro.num_resp.value = cadastro.num_emp.value;
	cadastro.bairro_resp.value = cadastro.bairro_emp.value;
	cadastro.cep_resp.value = cadastro.cep_emp.value;
	cadastro.cidade_resp.value = cadastro.cidade_emp.value;
	cadastro.estado_resp.value = cadastro.estado_emp.value;
}

function Tecla(e)  //Permite apenas a entrada de numeros
{
	if (document.all) // Internet Explorer
		var tecla = event.keyCode;
		if (tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
				if (tecla != 8) // backspace
					event.keyCode = 0;
				else
					return true;
			}
}


function mascaraCep(objeto){  //mascara para o CEP

	Tecla(event);
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 5){ objeto.value = ""; }
	if (objeto.value.length == 5){
		objeto.value += "-";
	}
 
}


function mascaraCPF(objeto){  //mascara para o CEP

	Tecla(event);
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 15){ objeto.value = ""; }

	if (objeto.value.length > 13){objeto.value = objeto.value.substr(0,13);}
	
	if (objeto.value.length == 3){
		objeto.value += ".";
	}
	if (objeto.value.length == 7){
		objeto.value += ".";
	}
		if (objeto.value.length == 11){
		objeto.value += "-";
	}
 
}

function mascaraTelefone(objeto){ // mascara para o Telefone
	Tecla(event);
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 8){objeto.value = "";}

	if (objeto.value.length == 0){
		objeto.value +="(";
	}
	if (objeto.value.length == 3){
		objeto.value +=")";
	}
	if (objeto.value.length == 8){
		objeto.value +="-";
	}
}



function isEmailAddr(email){  // checa se o email é valido
  var result = false;
  var theStr = new String(email);
  var index = theStr.indexOf("@");
  if (index > 0){
    var pindex = theStr.indexOf(".",index);
    if ((pindex > index+1) && (theStr.length > pindex+1))
	result = true;
  }
  return result;
}

function checaCPF (CPF) {
	CPF = CPF.replace('.', '');
	CPF = CPF.replace('.', '');
	CPF = CPF.replace('-', '');
	if (CPF.length != 11 || CPF == "00000000000" || CPF == "11111111111" ||
			CPF == "22222222222" ||	CPF == "33333333333" || CPF == "44444444444" ||
			CPF == "55555555555" || CPF == "66666666666" || CPF == "77777777777" ||
			CPF == "88888888888" || CPF == "99999999999")
			return false;
		soma = 0;
		for (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)))
			return false;
		soma = 0;
		for (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)))
			return false;
		return true;
 } 

function mascaraCNPJ(objeto){ // mascara para o Telefone
	Tecla(event);
	if (objeto.value.indexOf("-") == -1 && objeto.value.length > 18){ objeto.value = ""; }
	if (objeto.value.length == 2){
		objeto.value +=".";
	}
	if (objeto.value.length == 6){
		objeto.value +=".";
	}
	if (objeto.value.length == 10){
		objeto.value +="/";
	}
	if (objeto.value.length == 15){
		objeto.value +="-";
	}
}


function CNPJouCPF() {
	if (document.cadastro.quem_paga[1].checked) {
		mascaraCPF(document.cadastro.cnpj_pag);
	} 
	if ( (document.cadastro.quem_paga[0].checked) ){
			mascaraCNPJ(document.cadastro.cnpj_pag);
	}
	if ( (!document.cadastro.quem_paga[0].checked) && (!document.cadastro.quem_paga[1].checked) ) {
			alert("Selecione a pessoa responsável pelo pagamento!");
			document.cadastro.quem_paga[0].focus();
	}
	
}

function checaCNPJ(CNPJ) {
//	CNPJ = document.validacao.CNPJID.value;
	erro = new String;
	if (CNPJ.length < 18) {
			//erro += "É necessario preencher corretamente o número do CNPJ! "; 
			return false;
	}
	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! ";
		return false;
	}
	//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! "; 
	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])){
		return false;//erro +="Dígito verificador com problema!";
	}
	if (erro.length > 0){
		//alert(erro);
		return false;
		};
return true;
}