// VALIDAÇÃO DE E-MAIL
function checkEmail(campo)
{
 if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(campo.value))
 {
   return (true)
 } if(campo.value!=""){
   alert("O e-mail informado não é valido.")
   campo.focus();
   campo.style.background='#EFFCE4';
   return (false)
 }
}

// Abre nova Janela
function open_window(name, url, left, top, width, height, toolbar, menubar, statusbar, scrollbar, resizable)
{
  toolbar_str = toolbar ? 'yes' : 'no';
  menubar_str = menubar ? 'yes' : 'no';
  statusbar_str = statusbar ? 'yes' : 'no';
  scrollbar_str = scrollbar ? 'yes' : 'no';
  resizable_str = resizable ? 'yes' : 'no';
  window.open(url, name, 'left='+left+',top='+top+',width='+width+',height='+height+',toolbar='+toolbar_str+',menubar='+menubar_str+',status='+statusbar_str+',scrollbars='+scrollbar_str+',resizable='+resizable_str);
}

// Mostra e Esconde o Menu
function mostra(id){

var id
x = document.getElementById(id).style.display;

if(x == ''){
	document.getElementById(id).style.display='none';
}
else{
	document.getElementById(id).style.display='';
	}
}
function printSWF(nomeSWF,larguraSWF,alturaSWF,wmodeSWF){
document.write('<embed src="'+nomeSWF+'?rnd=000000022" type="application/x-shockwave-flash" width="'+larguraSWF+'" height="'+alturaSWF+'" wmode="'+wmodeSWF+'"></embed>')
}
// Valida Formulário de CURRICULO
function validaFormCurriculo(){

if(document.form.nome.value==''){
	alert("Campo Obrigatório!")
	document.form.nome.focus();
	document.form.nome.style.background='#D7E6D5';
	return false
	}
if(document.form.cpf.value==''){
	alert("Campo Obrigatório!")
	document.form.cpf.focus();
	document.form.cpf.style.background='#D7E6D5';
	return false
	}
if(document.form.arquivo.value==''){
	alert("Campo Obrigatório!")
	document.form.arquivo.focus();
	document.form.arquivo.style.background='#D7E6D5';
	return false
	}

if(validacpf()){
return true
}else{
return false
}


} 	

// Valida Formulário de Envio Torne-se Cliente

function validaFormCliente(){

campoemail=document.form.email

if(document.form.razao.value==''){
	alert("Campo Obrigatório!")
	document.form.razao.focus();
	document.form.razao.style.background='#EFFCE4';
	return false
	}
if(document.form.contato.value==''){
	alert("Campo Obrigatório!")
	document.form.contato.focus();
	document.form.contato.style.background='#EFFCE4';
	return false
	}
if(document.form.telefone.value==''){
	alert("Campo Obrigatório!")
	document.form.telefone.focus();
	document.form.telefone.style.background='#EFFCE4';
	return false
	}
if(document.form.email.value==''){
	alert("Campo Obrigatório!")
	document.form.email.focus();
	document.form.email.style.background='#EFFCE4';
	return false		
	}
	else{
	 if(checkEmail(campoemail)==false){
	  return false     
	  }
	}
if(document.form.endereco.value==''){
	alert("Campo Obrigatório!")
	document.form.endereco.focus();
	document.form.endereco.style.background='#EFFCE4';
	return false
	}
if(document.form.bairro.value==''){
	alert("Campo Obrigatório!")
	document.form.bairro.focus();
	document.form.bairro.style.background='#EFFCE4';
	return false
	}
if(document.form.cep.value==''){
	alert("Campo Obrigatório!")
	document.form.cep.focus();
	document.form.cep.style.background='#EFFCE4';
	return false
	}
if(document.form.cidade.value==''){
	alert("Campo Obrigatório!")
	document.form.cidade.focus();
	document.form.cidade.style.background='#EFFCE4';
	return false
	}
if(document.form.UF.value==''){
	alert("Campo Obrigatório!")
	document.form.UF.focus();
	document.form.UF.style.background='#EFFCE4';
	return false
	}
if(document.form.assunto.value==''){
	alert("Campo Obrigatório!")
	document.form.assunto.focus();
	document.form.assunto.style.background='#EFFCE4';
	return false
	}
if(document.form.mensagem.value==''){
	alert("Campo Obrigatório!")
	document.form.mensagem.focus();
	document.form.mensagem.style.background='#EFFCE4';
	return false
	}
} 	


/*** 
* Descrição.: formata um campo do formulário de 
* acordo com a máscara informada... 
* Parâmetros: - objForm (o Objeto Form) 
* - strField (string contendo o nome 
* do textbox) 
* - sMask (mascara que define o 
* formato que o dado será apresentado, 
* usando o algarismo "9" para 
* definir números e o símbolo "!" para 
* qualquer caracter... 
* - evtKeyPress (evento) 
* Uso.......: <input type="textbox" 
* name="xxx"..... 
* onkeypress="return txtBoxFormat(document.rcfDownload, 'str_cep', '99999-999', event);"> 
* Observação: As máscaras podem ser representadas como os exemplos abaixo: 
* CEP -> 99.999-999 
*   -> 999.999.999-99 
* CNPJ -> 99.999.999/9999-99 
* Data -> 99/99/9999 
* Tel Resid -> (99) 999-9999 
* Tel Cel -> (99) 9999-9999 
* Processo -> 99.999999999/999-99 
* C/C -> 999999-! 
* Hora -> 99:99:99 
* E por aí vai... 
***/

function txtBoxFormat(objForm, strField, sMask, evtKeyPress) {
var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

if(document.all) { // Internet Explorer
nTecla = evtKeyPress.keyCode; }
else if(document.layers) { // Nestcape
nTecla = evtKeyPress.which;
}

sValue = objForm[strField].value;

// Limpa todos os caracteres de formatação que
// já estiverem no campo.
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( "-", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( ".", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "/", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( "(", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( ")", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( " ", "" );
sValue = sValue.toString().replace( ":", "" );
sValue = sValue.toString().replace( ":", "" );
fldLen = sValue.length;
mskLen = sMask.length;

i = 0;
nCount = 0;
sCod = "";
mskLen = fldLen;

while (i <= mskLen) {
bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
bolMask = bolMask || ((sMask.charAt(i) == "(") || (sMask.charAt(i) == ")") || (sMask.charAt(i) == " ") || (sMask.charAt(i) == ":"))

if (bolMask) {
sCod += sMask.charAt(i);
mskLen++; }
else {
sCod += sValue.charAt(nCount);
nCount++;
}

i++;
}

objForm[strField].value = sCod;

if (nTecla != 8) { // backspace
if (sMask.charAt(i-1) == "9") { // apenas números...
return ((nTecla > 47) && (nTecla < 58)); } // números de 0 a 9
else { // qualquer caracter...
return true;
} }
else {
return true;
}
}
//Fim da Função Máscaras Gerais

function escondeCurso(id){

for (i=0;i<document.form1.elements.length;i++){

id1 = document.form1.elements[i].value

if (id != id1){
	document.getElementById(id1).style.display = "none";
	document.getElementById(id1).style.position = "absolute";
	}
}
if (document.getElementById(id).style.display == 'block'){
	document.getElementById(id).style.display = "none";
	document.getElementById(id).style.position = "absolute";
}else{		
	document.getElementById(id).style.display = "block";
	document.getElementById(id).style.position = "static";
	}
//atualizaIframe();
}

//VALIDA CPF
function validacpf(){ 
  var i; 
  s = document.form.cpf.value; 
  s = s.toString().replace( "-", "" );
  s = s.toString().replace( ".", "" );
  s = s.toString().replace( ".", "" );  
  if (s.length < 11){
  	alert("CPF Invalido")
	return false;
  }
  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){ 
  	alert("CPF Invalido") 
    return false; 
  } 
  d1 = 11 - (d1 % 11); 
  if (d1 > 9) d1 = 0; 
  	if (dv.charAt(0) != d1) { 
  		alert("CPF Invalido") 
  		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){ 
    	alert("CPF Invalido") 
  		return false; 
    } 
	return true; 
  
}
function validaLivro(){
if(document.getElementById('texto').value==''){
	alert("Campo Obrigatório!")
	document.getElementById('texto').focus();
	document.getElementById('texto').style.background='#EFFCE4';
	return false
	}
if(document.getElementById('nome').value==''){
	alert("Campo Obrigatório!")
	document.getElementById('nome').focus();
	document.getElementById('nome').style.background='#EFFCE4';
	return false
	}	
	else{
	retorna();
	}
}
function retorna(){
	var nome  = document.getElementById('nome').value;
	var texto = document.getElementById('texto').value;
	var icone = document.getElementById('icone').value;

	if(icone == ''){
		icone = 'teeth_smile.gif'
		}

	document.getElementById('GN').value = nome;
	document.getElementById('GT').value = texto;
	document.getElementById('GI').value = icone
	
	lform.submit();
	}



// Valida Formulário de envio de contato
function validaForm(){

email=document.form.email
if(document.form.spara.value==''){
	alert("Campo Obrigatório!")
	document.form.spara.focus();
	document.form.spara.style.background='#EFFCE4';
	return false
	}

if(document.form.empresa.value==''){
	alert("Campo Obrigatório!")
	document.form.empresa.focus();
	document.form.empresa.style.background='#EFFCE4';
	return false
	}
if(document.form.nome.value==''){
	alert("Campo Obrigatório!")
	document.form.nome.focus();
	document.form.nome.style.background='#EFFCE4';
	return false
	}
if(document.form.email.value==''){
	alert("Campo Obrigatório!")
	document.form.email.focus();
	document.form.email.style.background='#EFFCE4';
	return false		
	}
	else{
	 if(checkEmail(email)==false){
	  return false     
	  }
	}
if(document.form.assunto.value==''){
	alert("Campo Obrigatório!")
	document.form.assunto.focus();
	document.form.assunto.style.background='#EFFCE4';
	return false
	}

if(document.form.mensagem.value==''){
	alert("Campo Obrigatório!")
	document.form.mensagem.focus();
	document.form.mensagem.style.background='#EFFCE4';
	return false
	}
} 	

function abre(url, name)
{     
	var str = "left=0,screenX=0,top=0,screenY=0,status=1,scrollbars=1";

     if (window.screen) {
       var ah = screen.availHeight - 50;
       var aw = screen.availWidth - 10;
       str += ",height=" + ah;
       str += ",innerHeight=" + ah;
       str += ",width=" + aw;
       str += ",innerWidth=" + aw;
     } else {
       str += ",resizable"; // redimensiona a janela para o usuário
     }

	var janela = window.open(url, name, str);

	if (!janela)
	{
		alert("Por favor, desative seu anti-popup para usar o sistema.");
	}
}

function abre2(url, name)
{     
	var str = "status=1,scrollbars=1";

     if (window.screen) {
       var ah = 600;//screen.availHeight - 50;
       var aw = 650;//screen.availWidth - 10;
       str += ",height=" + ah;
       str += ",innerHeight=" + ah;
       str += ",width=" + aw;
       str += ",innerWidth=" + aw;
	   str += ",top=" + (screen.availHeight-ah)/2;
	   str += ",left=" + (screen.availWidth-aw)/2;
	   str += ",screenY=" + (screen.availHeight-ah)/2;
	   str += ",screenX=" + (screen.availWidth-aw)/2;
     } else {
       str += ",resizable"; // redimensiona a janela para o usuário
     }

	var janela = window.open(url, name, str);

	if (!janela)
	{
		alert("Por favor, desative seu anti-popup para usar o sistema.");
	}
}