﻿// JavaScript Document

function fechar(){
document.getElementById("popup").style.display = "none";
}


function abrir(){
document.getElementById("popup").style.display = "block";
}



function validaForm(id,tipo,campo,obrigatorio){
	var regEMAIL = /^[\w!#$%&'*+\/=?^`{|}~-]+(\.[\w!#$%&'*+\/=?^`{|}~-]+)*@(([\w-]+\.)+[A-Za-z]{2,6}|\[\d{1,3}(\.\d{1,3}){3}\])$/;
	var obj = document.getElementById(id);
	var valor = obj.getAttributeNode('name').value;

	if ((obj.value == "")&&(obrigatorio==1)){
		alert("O campo " + campo + " deve ser preenchido!");
		obj.focus();
		return false;
	}

	if ((tipo == "EMAIL")&&(obj.value != "")){
		if (!regEMAIL.test(obj.value)){
			alert("Formato de e-mail inválido!");
			obj.focus();
			return false;
		}
	}	
	
	if ((tipo == "COMBO")&&(obj.value != "")) {
		if (obj.selectedIndex==0){
			alert ("O campo "+ campo +" deve ser selecionado!");
			obj.focus();
			return false;
		}
	} 
	
		
	return true;

}
	
	
function valida(){
  var ok = validaForm('idNome','','Nome',1)
  if(ok) var ok = validaForm('idCpf','','CPF',1);
  if(ok) var ok = validaForm('idEmail','EMAIL','Email',1);
  if(ok) var ok = validaForm('idMini','COMBO','Mini-Curso',1);
  if(ok) var ok = validaForm('idData','COMBO','Data',1);
  if(ok) var ok = validaForm('idTel','','Telefone',1);
  if(ok) var ok = validaForm('idInst','','Instituição',1);
  return ok;
}

	
	
function formata(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 VALIDACPF() {
	if(document.form1.cpf.value != ""){
		if(!isCPFCNPJ(document.form1.cpf.value,1)) {
			alert('CPF INVÁLIDO');
			document.form1.cpf.value = "";
			document.form1.cpf.focus();
			return false;
		}
	}
}



function showForm(){
	var divForm = document.getElementById('divForm')
	if (divForm.style.display == 'none') {
		divForm.style.display = 'block';
		document.getElementById('showf').style.color = '#FF9900';
	} else {
		divForm.style.display = 'none';
		document.getElementById('showf').style.color = '#0033FF';
	}
}


function selectData(obj){
	var datas = document.getElementById('idData');
	if(obj.selectedIndex==0){
		clearDatas();
	}
	if(obj.selectedIndex==1){
		clearDatas();
		var option1 = document.createElement('option');
		var data1 = document.createTextNode('23/09/2009');
		option1.value = '23/09/2009';
		var option2 = document.createElement('option');
		var data2 = document.createTextNode('26/09/2009');
		option2.value = '26/09/2009';
		option1.appendChild(data1);
		option2.appendChild(data2);
		datas.appendChild(option1);
		datas.appendChild(option2);
	}
		
	if(obj.selectedIndex==2){
		clearDatas();
		var option1 = document.createElement('option');
		var data1 = document.createTextNode('24/09/2009');
		option1.value = '24/09/2009';
		var option2 = document.createElement('option');
		var data2 = document.createTextNode('26/09/2009');
		option2.value = '26/09/2009';
		option1.appendChild(data1);
		option2.appendChild(data2);
		datas.appendChild(option1);
		datas.appendChild(option2);
	}
	if(obj.selectedIndex==3){
		clearDatas();
		var option1 = document.createElement('option');
		var data1 = document.createTextNode('26/09/2009');
		option1.value = '26/09/2009';
		option1.setAttribute('selected','selected');
		option1.appendChild(data1);
		datas.appendChild(option1);
	}


}

function clearDatas(){
	var datas = document.getElementById('idData');
	while(datas.firstChild)
		datas.removeChild(datas.firstChild);
	var option = document.createElement('option');
	var texto = document.createTextNode('--Selecione--');
	option.setAttribute('value','0');
	option.appendChild(texto);
	datas.appendChild(option);

}

