function popupi(url,largura,altura) {
var a = window.screen.availWidth - largura ; 
var b = window.screen.availHeight - altura ; 
var leftdist = a/2;
var topdist = b/2;
var newpage = window.open("","_blank","left=" + leftdist + ",top=" + topdist + ",width=" + largura + ",height=" + altura + ",scrollbars=no");
newpage.document.write("<head><title>Psicoespaço</title></head>");
newpage.document.write("<body topmargin=0 leftmargin=0 marginheight=0 marginhwidth=0 scroll=yes>");
newpage.document.write("<img src=\"" + url + "\" border=0>");
newpage.document.write("</body>");
}

function get_flash(arquivo, largura, altura, bgcolor, id, qualidade, alinhamento,transparente,pgphp) {
	obj = '<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="'+largura+'" height="'+altura+'" id="'+id+'" align="'+alinhamento+'">';
	obj+= '<param name="allowScriptAccess" value="sameDomain" />';
	obj+= '<param name="movie" value="'+arquivo+'" />';
	obj+= '<param name="quality" value="'+qualidade+'" />';
	if(transparente == true) {
		obj+= '<param name="wmode" value="transparent" />';
	}
	obj+= '<param name="bgcolor" value="'+bgcolor+'" />';
	obj+= '<param name="FlashVars" value="pg='+pgphp+'" />';
	obj+= '<embed src="'+arquivo+'" '+((transparente==true)?'wmode="transparent"':'')+'" quality="'+qualidade+'" bgcolor="'+bgcolor+'" FlashVars="pg='+pgphp+'" width="'+largura+'" height="'+altura+'" name="'+id+'" align="'+alinhamento+'" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />';
	obj+= '</object>';
	document.write(obj);
}

function formatar(src, mask) {
	var i = src.value.length;
	var saida = mask.substring(0,1);
	var texto = mask.substring(i)

	if (texto.substring(0,1) != saida) {
		src.value += texto.substring(0,1);
	}
}

function checaCadastro(){

	if(window.document.frmCadastro.ds_mkt_pssoa_senha.value == "") {
		alert("Digite um SENHA");
		return false;
	}
	if(window.document.frmCadastro.confirme_senha.value == "") {
		alert("Digite um CONFIRME SENHA");
		return false;
	}
	if((window.document.frmCadastro.ds_mkt_pssoa_senha.value) != (window.document.frmCadastro.confirme_senha.value)) {
		alert("Senhas NÂO conferem!");
		return false;
	}
	if(window.document.frmCadastro.nm_mkt_pssoa.value == ""){
		alert("O campo PRIMEIRO NOME deve ser preenchido!");
		return false;
	}
	/*if(window.document.frmCadastro.nm_mkt_pssoa_meio.value == ""){
		alert("O campo NOME DO MEIO deve ser preenchido!");
		return false;
	}*/
	if(window.document.frmCadastro.nm_mkt_pssoa_ultim.value == ""){
		alert("O campo ÚLTIMO NOME deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.dt_mkt_pssoa_nasci.value == ""){
		alert("O campo DATA DE NASCIMENTO deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.id_mkt_pssoa_sexo.value == ""){
		alert("O campo SEXO deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.ds_mkt_pssoa_rg.value == ""){
		alert("O campo CARTEIRA DE IDENTIDADE deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.ds_mkt_pssoa_cpf.value == ""){
		alert("O campo CPF deve ser preenchido!");
		return false;
	}
	if(!validaCPF(window.document.frmCadastro.ds_mkt_pssoa_cpf.value)){
		return false;
	}

	if(window.document.frmCadastro.ds_mkt_pssoa_email.value == ""){
		alert("O campo E-MAIL deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.ds_mkt_pssoa_ender.value == ""){
		alert("O campo ENDEREÇO deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.ds_mkt_pssoa_numer.value == ""){
		alert("O campo NÚMERO deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.ds_mkt_pssoa_bairo.value == ""){
		alert("O campo BAIRRO deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.ds_mkt_pssoa_ciade.value == ""){
		alert("O campo CIDADE deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.cd_mkt_estdo.value == ""){
		alert("O campo ESTADO deve ser preenchido!");
		return false;
	}	

	if(window.document.frmCadastro.ds_mkt_pssoa_cep.value == ""){
		alert("O campo CEP deve ser preenchido!");
		return false;
	}

	if(window.document.frmCadastro.ds_mkt_pssoa_hora[0].checked == false &&
	   window.document.frmCadastro.ds_mkt_pssoa_hora[1].checked == false &&
	   window.document.frmCadastro.ds_mkt_pssoa_hora[2].checked == false) {
		alert("O HORÁRIO DISPONÍVEL deve ser escolhido!");
		return false;
	}
	
	if(window.document.frmCadastro.cd_mkt_estcv.value == ""){
		alert("O campo ESTADO CIVÍL deve ser preenchido!");
		return false;
	}

	if(window.document.frmCadastro.ds_mkt_pssoa_tel.value == ""){
		alert("O campo TELEFONE FIXO deve ser preenchido!");
		return false;
	} 

        if(window.document.frmCadastro.ds_mkt_pssoa_cel.value == ""){
		alert("O campo TELEFONE CELULAR deve ser preenchido!");
		return false;
	}

	/*if(window.document.frmCadastro.cd_mkt_nvesc.value == ""){
		alert("O campo NÍVEL DE ESCOLARIDADE deve ser preenchido!");
		return false;
	}*/ 


 
	if(window.document.frmCadastro.id_mkt_pssoa_filho.value == ""){
		alert("O campo NÚMERO DE FILHOS deve ser preenchido!");
		return false;
	}
	if(window.document.frmCadastro.id_mkt_pssoa_cnh.value == ""){
		alert("O campo CNH (Habilitação) deve ser preenchido!");
		return false;
	}
	/*if(window.document.frmCadastro.id_mkt_pssoa_pne[0].checked == false) {
		alert("O campo PORTADOR DE NECESSIDADES ESPECIAIS (PNE) deve ser preenchido!");
		return false;
	}
	/*
	if(window.document.frmCadastro.ds_mkt_pssoa_profi.value == ""){
		alert("O campo PROFISSÂO deve ser preenchido!");
		return false;
	}
	
	if(window.document.frmCadastro.ds_mkt_pssoa_cargo.value == ""){
		alert("O campo CARGO ATUAL deve ser preenchido!");
		return false;
	}
	*/
	window.document.frmCadastro.submit();
	return true;
}


/*
function validaCadastro(){
	var frm = window.document.frmCadastro;
	if (frm.foto.value != "") {
		var file = new String(frm.foto.value);
		if (file.indexOf('.jpg') == -1) {
			alert('A imagem deve ser JPG');
			return;
		}else{
		frm.submit();
		}
	}else{
		frm.submit();
	}
}
*/
function validaCadastro(){
	var frm = window.document.frmCadastro;
	frm.submit();
}

function Popup(Url, Titulo, Width, Height, Scrollbar) 
{
    window.open(Url, Titulo, 'width='+Width+', height='+Height+', scrollbars='+Scrollbar+', status=no, resizable, top='+((screen.availHeight/2)-(Height/2))+', left='+((screen.availWidth/2)-(Width/2)))
}


function Checa() {


	return true;
}

function Desativa() {
	window.document.getElementById("teste").className = "";
}	

function Ativa() {
	VerificaSenha();
}	

function VerificaSenha() {
	if((window.document.frmCadastro.ds_mkt_pssoa_senha.value != "") && (window.document.frmCadastro.confirme_senha.value != "")){
		if(window.document.frmCadastro.ds_mkt_pssoa_senha.value == window.document.frmCadastro.confirme_senha.value) {
			window.document.getElementById("teste").className = "sim";	
		} else {
			window.document.getElementById("teste").className = "nao";	
		}
	}
}


function VerificaInt(e)
{
	if (document.all){var evt=event.keyCode;}
	else{var evt = e.charCode;}
	if (evt <20 || (evt >47 && evt<58)){return true;}
	return false;
}

function validaCPF(campo) {
	cpf = new String(campo);
	cpf = cpf.replace(".","");
	cpf = cpf.replace(".","");
	cpf = cpf.replace("-","");

	valor = true;
	erro = new String;
	if (cpf.length < 11) erro += "Sao necessarios 11 digitos para verificacao do CPF! \n\n"; 
	var nonNumbers = /\D/;
	if (nonNumbers.test(cpf)) erro += "A verificacao de CPF suporta apenas numeros! \n\n";	
	if (cpf == "00000000000" || cpf == "11111111111" || cpf == "22222222222" || cpf == "33333333333" || cpf == "44444444444" || cpf == "55555555555" || cpf == "66666666666" || cpf == "77777777777" || cpf == "88888888888" || cpf == "99999999999"){
		  erro += "Numero de CPF invalido!"
	}
	var a = [];
	var b = new Number;
	var c = 11;
	for (i=0; i<11; i++){
		a[i] = cpf.charAt(i);
		if (i < 9) b += (a[i] *  --c);
	}
	if ((x = b % 11) < 2) { a[9] = 0 } else { a[9] = 11-x }
	b = 0;
	c = 11;
	for (y=0; y<10; y++) b += (a[y] *  c--); 
	if ((x = b % 11) < 2) { a[10] = 0; } else { a[10] = 11-x; }
	if ((cpf.charAt(9) != a[9]) || (cpf.charAt(10) != a[10])){
		erro +="Digito verificador com problema!";
	}
	if (erro.length > 0){
		alert(erro);
		return false;
	}
	return true;
}

function doDate(pStr)
{

 var reDate5 = /^((0[1-9]|[12]\d)\/(0[1-9]|1[0-2])|30\/(0[13-9]|1[0-2])|31\/(0[13578]|1[02]))\/\d{4}$/;

	if (reDate5.test(pStr)) {
		
	} else if (pStr != null && pStr != "") {
		alert("DATA DE NASCIMENTO não é válida!\n"+pStr);
		window.document.frmCadastro.dt_mkt_pssoa_nasci.value = "";
	} 
}

function ConfirmDelete(){
	if(confirm("Deseja Excluir o(s) Registro(s) Selecionado(s)?"))
		return true;
	else
		return false;
}

function delete_mkt_pssoa(){
	if(confirm("Deseja realmente excluir seu Cadastro?")){
			window.document.location.href = "deletar.php";
	}else{
			return false;
	}
}