function verifica_data (data) {
/*
	dia = (document.forms[0].data.value.substring(0,2));
	mes = (document.forms[0].data.value.substring(3,5));
	ano = (document.forms[0].data.value.substring(6,10));
*/
	var dt = data.split("-");
	dia = parseInt(dt[0]);
	mes = parseInt(dt[1]);
	ano = parseInt(dt[2]);
	
	situacao = "";
	// verifica o dia valido para cada mes
	if ((dia < 1)||(dia < 1 || dia > 30) && (  mes == 4 || mes == 6 || mes == 9 || mes == 11 ) || dia > 31) {
		situacao = "falsa";
	}
	// verifica se o mes e valido
	if (mes < 01 || mes > 12 ) {
		situacao = "falsa";
	}
	// verifica se e ano bissexto
	if (mes == 2 && ( dia < 01 || dia > 29 || ( dia > 28 && (parseInt(ano / 4) != ano / 4)))) {
		situacao = "falsa";
	}
	if (data == "") {
		situacao = "falsa";
	}
	if (situacao == "falsa") {
		//alert("Data de "+text+" inválida!");
		return false;
		//document.forms[0].data.focus();
	}else{
		return true;
	}
}

function validaData(data){
	var dt = data.split("-");
	dia = dt[0];
	mes = dt[1];
	ano = dt[2];
	var now = new Date();
	var mName = now.getMonth() + 1;
	var dayNr = now.getDate();
	var yearNr=now.getYear();
	if(yearNr < 2000) Year = 1900 + yearNr;
	else Year = yearNr;
	// Variavel para exibir a data.
	//var todaysDate =(" " + dayNr + "/" + mName + "/" + Year);
	//alert(ano);
	if(ano > Year){
		return true;
	}else{
		if(ano == Year){
			if(mes > mName){
				return true;
			}else{
				if(mes == mName){
					if(dia >= dayNr){
						return true;
					}else{
						return false;
					}
				}else{
					return false;
				}
			}
		}else{
			return false;
		}
	}
}

// JavaScript Document
function abreImagem(file,w,h){
	var width  = parseInt(w);
	var height = parseInt(h);
	var left   = screen.Width / 2 - width / 2;
	var top    = screen.Height / 2 - height / 2;
	window.open('zoom.php?file='+file+'&width='+w+'&height='+h,'','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=no,status=yes')}

function abreAlbum(id){
	var width  = 580;
	var height = 550;			
	var left   = screen.Width / 2 - width / 2;
	var top    = screen.Height / 2 - height / 2;
	window.open('album.php?id='+id,'blank','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=yes,status=yes')
}

function abreAlbumAcompanhamento(id){
	var width  = 600;
	var height = 400;			
	var left   = screen.Width / 2 - width / 2;
	var top    = screen.Height / 2 - height / 2;
	window.open('album_acompanhamento.php?id='+id,'blank','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=yes,status=yes')
}


function verificaEmail(email){      
      strMail = new String(email);
			re = /^[^@]+@[^@]+.[a-z]{2,}$/i;
			if(strMail.search(re) == -1) {
     	return(false);
      }else {
      return (true);
      }
      
    }	
	
		
	//Verifica se email é um endereço de e-mail válido
	function emailValido(email){
		var padrao = "^([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[@]([0-9,a-z,A-Z]+)([.,_,-]([0-9,a-z,A-Z]+))*[.]([a-z,A-Z]){2,3}([0-9,a-z,A-Z])?$";
		var reg = new RegExp(padrao);
		return result = reg.exec(email);
	}
	
	function login(){
		var form = document.form2;
		var email = form.email.value;
		var senha = form.senha.value;
		var validacao = verificaEmail(email);
		
		if(validacao == true && senha != ''){
			form.action = "clientes_sap.php";
			form.submit();			
		}else{
			if(validacao == false){
			    alert('Digite um email válido');
			    form.email.style.borderColor = 'red'; 
			    form.email.focus();
			}
			    
			
			
			if(senha == ''){
				alert('Digite uma senha');
				form.senha.style.borderColor = 'red'; 
			    form.senha.focus();	
			}
		}
		
		}

	
	//retorna a extensao do arquivo em maiuscula
	function getExt(file){
		return (file.substring(file.length-3,file.length)).toUpperCase();
	}		
	
	//Valida o formulario retornando true/false
	function validate(){
		var form = document.form1;
		var focoElement = null;
		var array_erro = new Array();
		//Reinica as cores das bordas
		form.nome.style.borderColor      = '';
		form.email.style.borderColor     = '';
		form.ddd_conv.style.borderColor  = '';
		form.fone_conv.style.borderColor = '';
		form.ddd_cel.style.borderColor   = '';
		form.fone_cel.style.borderColor  = '';
		form.obs.style.borderColor       = '';
		form.arquivo.style.borderColor   = '';			
		//Verificação dos campos obrigatorios
		//Nome
		if(form.nome.value == ''){
			array_erro.push('Nome não preenchido');
			form.nome.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.nome;
		}
		//Email
		if(form.email.value == ''){
			array_erro.push('E-mail não preenchido');
			form.email.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.email;
		} else {
			if(!emailValido(form.email.value)){
				array_erro.push('O E-mail fornecido não é válido');
				form.email.style.borderColor = 'red';
				if(focoElement == null)
					focoElement = form.email;
			}			
		}
		//DDD Convencional
		if(form.ddd_conv.value == ''){
			array_erro.push('DDD do telefone convencional não preenchido');
			form.ddd_conv.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.ddd_conv;
		}
		//Fone Convencional
		if(form.fone_conv.value == ''){
			array_erro.push('Telefone convencional não preenchido');
			form.fone_conv.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.fone_conv;
		}
		//DDD Celular
		if(form.ddd_cel.value == ''){
			array_erro.push('DDD do telefone celular não preenchido');
			form.ddd_cel.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.ddd_cel;
		}
		//Fone Celular
		if(form.fone_cel.value == ''){
			array_erro.push('Telefone celular não preenchido');
			form.fone_cel.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.fone_cel;
		}
		//Arquivo
		if(form.arquivo.value == ''){
			array_erro.push('Nenhum arquivo selecionado no campo Curriculum Vitae');
			form.arquivo.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.arquivo;
		} else {
			var ext = getExt(form.arquivo.value);
			if(ext != 'DOC' && ext != 'PDF'){
				array_erro.push('Formato de arquivo inválido para o Curriculum Vitae (Somente doc e pdf)');
				form.arquivo.style.borderColor = 'red';
				if(focoElement == null)
					focoElement = form.arquivo;
			}			
		}
		//Área
		if(form.area.selectedIndex == 0){
			array_erro.push('A Área Desejada não foi selecionada');
			form.area.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.area;			
		}
																	
		var numErros = array_erro.length;
		if(numErros > 0){
			var str = 'Foram encontrados os seguintes erros:\n';
			for(i = 0; i < numErros; i++){
				str += '\n - ' + array_erro[i];
			}
			alert(str);
			focoElement.focus();
			return false;
		} else {
			return true;
		}		
	} // Fim validate()
	
	//Valida o formulario retornando true/false
	function validaCadastroEmpresa(){
		var form = document.form1;
		var focoElement = null;
		var array_erro = new Array();
		//Reinica as cores das bordas

		form.razao_social.style.borderColor    = '';
		form.cnpj.style.borderColor            = '';
		form.crm.style.borderColor             = '';
		form.nome_fantasia.style.borderColor   = '';
		form.endereco.style.borderColor        = '';
		form.estado.style.borderColor          = '';
		form.cidade.style.borderColor          = '';
		form.bairro.style.borderColor          = '';
		form.cep.style.borderColor             = '';
		form.ddd.style.borderColor             = '';
		form.fone.style.borderColor            = '';
		form.ddd_cel.style.borderColor         = '';
		form.celular.style.borderColor         = '';
		form.ddd_fax.style.borderColor         = '';
		form.fax.style.borderColor             = '';
		form.email.style.borderColor           = '';
		form.email_conf.style.borderColor      = '';
		form.nome_resp.style.borderColor       = '';
		form.cpf_resp.style.borderColor        = '';
		form.endereco_resp.style.borderColor   = '';
		form.rg_resp.style.borderColor         = '';
		form.estado_resp.style.borderColor     = '';
		form.cidade_resp.style.borderColor     = '';
		form.bairro_resp.style.borderColor     = '';
		form.cep_resp.style.borderColor        = '';
		form.senha.style.borderColor           = '';
		form.senha2.style.borderColor          = '';
		//Verificação dos campos obrigatorios
		//Razão social
		if(form.razao_social.value == ''){
			array_erro.push('Razão social não preenchida');
			form.razao_social.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.razao_social;
		}
		//CNPJ
		if(form.cnpj.value == ''){
			array_erro.push('CNPJ não preenchido');
			form.cnpj.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.cnpj;
		}
		
		//Email
		if(form.email.value == ''){
			array_erro.push('E-mail não preenchido');
			form.email.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.email;
		} else {
			if(!emailValido(form.email.value)){
				array_erro.push('O E-mail fornecido não é válido');
				form.email.style.borderColor = 'red';
				if(focoElement == null)
					focoElement = form.email;
			}			
		}
		//email_conf
		if(form.email_conf.value != form.email.value){
			array_erro.push('Repita o email para confirmar');
			form.email_conf.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.email_conf;
				
		}		
		//CRM
		if(form.crm.value == ''){
			array_erro.push('CRM não preenchida');
			form.crm.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.crm;
		}
		//Instituicao
		if(form.nome_fantasia.value == ''){
			array_erro.push('Nome Fantasia não preenchido');
			form.nome_fantasia.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.nome_fantasia;
		}
		//Endereço
		if(form.endereco.value == '' || form.endereco.value == "       "){
			array_erro.push('Endereço não preenchido');
			form.endereco.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.endereco;
		}

		//Endereço
		if(form.estado.value == ''){
			array_erro.push('Estado não selecionado');
			form.estado.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.estado;
		}
		//Cidade
		if(form.cidade.value == ''){
			array_erro.push('Cidade não preenchida');
			form.cidade.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.cidade;
		}
		//Bairro
		if(form.bairro.value == ''){
			array_erro.push('Bairro não preenchido');
			form.bairro.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.bairro;
		}
		//cep
		if(form.cep.value == ''){
			array_erro.push('CEP não preenchido');
			form.cep.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.cep;
		}
		//ddd
		if(form.ddd.value == ''){
			array_erro.push('DDD do telefone convencional não preenchido');
			form.ddd.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.ddd;
		}
		//fone
		if(form.fone.value == ''){
			array_erro.push('Telefone convencional não preenchido');
			form.fone.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.fone;
		}
		//ddd_cel
/*		if(form.ddd_cel.value == ''){
			array_erro.push('DDD do telefone celular não preenchido');
			form.ddd_cel.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.ddd_cel;
		}
		//celular
		if(form.celular.value == ''){
			array_erro.push('Telefone celular não preenchido');
			form.celular.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.celular;
		}
		//ddd_fax
		if(form.ddd_fax.value == ''){
			array_erro.push('DDD do fax não preenchido');
			form.ddd_fax.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.ddd_fax;
		}
		//fax
		if(form.fax.value == ''){
			array_erro.push('Telefone de fax não preenchido');
			form.fax.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.fax;
		}
*/
		//nome_resp
		if(form.nome_resp.value == ''){
			array_erro.push('Nome do responsável não preenchido');
			form.nome_resp.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.nome_resp;
		}
		//cpf_resp
		if(form.cpf_resp.value == ''){
			array_erro.push('CPF do responsável não preenchido');
			form.cpf_resp.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.cpf_resp;
		}
		//endereco_resp
		if(form.endereco_resp.value == '' || form.endereco.value == "       "){
			array_erro.push('Endereço do responsável não preenchido');
			form.endereco_resp.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.endereco_resp;
		}
		//rg_resp
		if(form.rg_resp.value == ''){
			array_erro.push('RG não preenchido');
			form.rg_resp.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.rg_resp;
		}
		//estado_resp
		if(form.estado_resp.value == ''){
			array_erro.push('Estado do responsavel não preenchido');
			form.estado_resp.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.estado_resp;
		}
		//cidade_resp
		if(form.cidade_resp.value == ''){
			array_erro.push('Cidade do responsável não preenchido');
			form.cidade_resp.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.cidade_resp;
		}
		//bairro_resp
		if(form.bairro_resp.value == ''){
			array_erro.push('Bairro do responsável não preenchido');
			form.bairro_resp.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.bairro_resp;
		}
		//cep_resp
		if(form.cep_resp.value == ''){
			array_erro.push('CEP do responsável não preenchido');
			form.cep_resp.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.cep_resp;
		}		
		//senha
		if(form.senha.value == ''){
			array_erro.push('Senha não preenchida');
			form.senha.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.senha;
		}
		//senha confirmacao
		if(form.senha.value != '' && form.senha2.value != form.senha.value){
			array_erro.push('Confirmação de senha diferente da senha');
			form.senha2.style.borderColor = 'red';
			form.senha.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.senha2;
		}		
	
/*		if(form.senha.value != '' && form.senha.length < "3"){
			array_erro.push('Confirmação de senha diferente da senha');
			form.senha2.style.borderColor = 'red';
			form.senha.style.borderColor = 'red';
			if(focoElement == null)
				focoElement = form.senha2;
		}		
*/		
		
		var numErros = array_erro.length;
		if(numErros > 0){
			var str = 'Foram encontrados os seguintes erros:\n';
			for(i = 0; i < numErros; i++){
				str += '\n - ' + array_erro[i];
			}
			alert(str);
			focoElement.focus();			
		} else {
			form.action = "cadastro.php"; 
			form.submit();
		}		
	} // Fim validate()	

	
	
	
	//Abre uma janela pop-up
	function popUp(url,name,properties){
		window.open(url,name,properties);
	}//fim popUp()
	
	//Verifica se o email foi digitado e abre janela
	function assinarNewsletter(action){
		var email  = document.formNL.email.value;
		var nome   = document.formNL.nome.value;
		var height = 150;
		var width  = 300;
		var left   = screen.Width / 2 - width / 2;
		var top    = screen.Height / 2 - height / 2;
		if(email != ''){
			window.open('newsletter.php?email='+email+'&nome='+nome+'&action='+action,'newsletter','height='+height+',width='+width+',top='+top+',left='+left+',scrollbars=no');
			document.formNL.email.value = '';
			document.formNL.nome.value  = '';
		} else { 
			alert('Você não digitou o seu e-mail');
		}
	}//fim assinarNewsletter()	
