//Funcoes para o Foca Frezart

/////////////////////////////////////////////////////////////////////////////////////////////////

// Funcao de Mascara de Campos
function FormatMask(objForm, strField, sMask, evtKeyPress) {
  var i, nCount, sValue, fldLen, mskLen,bolMask, sCod, nTecla;

  if(window.event) { // Internet Explorer
    nTecla = evtKeyPress.keyCode; }
  else if(evtKeyPress.which) { // Nestcape
    nTecla = evtKeyPress.which;
  }

  sValue = objForm[strField].value;

  // Limpa todos os caracteres de formatacao que
  // ja 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( " ", "" );
  fldLen = sValue.length;
  mskLen = sMask.length;

  i = 0;
  nCount = 0;
  sCod = "";
  mskLen = fldLen;

  if (nTecla != 8) { // backspace
    if (sMask.charAt(i-1) == "9") { // apenas números...
      return ((nTecla > 47) && (nTecla < 58)); } // numeros de 0 a 9
    else { // qualquer caracter...


  while (i <= mskLen) {
     bolMask = ((sMask.charAt(i) == "-") || (sMask.charAt(i) == ".") || (sMask.charAt(i) == "/"))
     bolMask = bolMask || ((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;

      return true;
    } }
  else {
    return true;
  }
}

//Função de verificacao de email
function verificaEmail(newsletter,tipo){
	document.getElementById('acao').value = tipo;
	if(newsletter.email.value == ""){
		alert("Atenção!\nO campo EMAIL deve ser preenchido!");
		newsletter.email.focus();
		return false;
	}
	if(newsletter.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1){
		alert("Atenção!\nVocê não preencheu o campo EMAIL corretamente!");
		newsletter.email.focus();
		return false;
	}
	return true;
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao de popup
function MM_openBrWindow(theURL,winName,features) 
{
	var myWin =  window.open(theURL,winName,features);
	myWin.focus();
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao para o Menu PopUp

function fnImagemPopUp( titulo, largura , altura , imagem , alt )
{
	
		var janela ;
		janela = window.open("","popFoto","width="+largura+",height="+altura+",scrollbars=no,toolbar=no,location=no,status=no,menubar=no,resizable=no,left=300,top=300'");
		janela.document.write('<html><head><title>' + titulo + '</title></head>');
		janela.document.write('<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">');
		janela.document.write('<a href="javascript:window.close();"><img src="'+ imagem + '" alt="' + alt + '" border="0" /></a> ');
		janela.document.write('</body></html>');

}


/////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao Adiciona a Favoritos
function fnAdicionaFavoritos()
{
	str_titulo = ":: FOCA Frezart";
	str_url = "http://www.focafrezart.com.br";
	//FireFox
	if (window.sidebar)
	{
   		window.sidebar.addPanel(str_titulo, str_url,"");
	}
	//IE
	else if( window.external )
	{
  		window.external.AddFavorite( str_url, str_titulo);
	}
	//Opera
	else if(window.opera && window.print)
	{
   		return true;
	}
}

////////////////////////////////////////////////////////////////////////////////////////////

//Funcao Validacao do Indique Amigo
function validaIndique(form,evento) {

	if ( form.nome.value == '' )
	{
		alert('Atenção!\nO campo NOME deve ser preenchido.') ;
		form.nome.focus();
		return false ;
	}

	if (form.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	{
		alert("Atenção!\nO campo E-MAIL deve ser preenchido.");
		form.email.focus();
		return false;
	}
	
	if (form.emailamigo.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)
	{
		alert("Atenção!\nO campo E-MAIL DO AMIGO deve ser preenchido.");
		form.emailamigo.focus();
		return false;
	}
	
	if ( form.mensagem.value == '' )
	{
		alert('Atenção!\nO campo MENSAGEM deve ser preenchido.') ;
		form.mensagem.focus();
		return false ;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao Validacao do Newsletter
function ValidaNews (form) 
{
	if (form.nome.value.length <= 2 )
	{
		alert("O campo Nome deve ser preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	
	var str_email = form.email.value ;
    if (str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 )
    {
    alert("O campo E-mail deve ser preenchido corretamente");
	form.email.focus();
	return false;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao Validacao da Busca
function ValidaBusca (form) 
{
	if (form.busca.value.length <= 2 )
	{
		alert("O campo Busca deve ser preenchido corretamente.");
		form.busca.focus();
		return false;
	}
}


///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Validacao CONTATO

function ValidaContato(form,evento){
	if ( form.nome.value == '' )
	{
		alert('Atenção\nPreencha o campo NOME.') ;
		form.nome.focus();
		return false ;
	}

	if ( form.email.value == '' )
	{
		alert('Atenção\nPreencha o campo E-MAIL.') ;
		form.email.focus();
		return false ;
	}
	if (form.email.value.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1) {
		alert("Atenção!\nO campo E-MAIL deve ser preenchido corretamente.");
		form.email.value = ('');
		form.email.focus();
		return false;
 	}
	
	if ( form.telefone.value == '' )
	{
		alert('Atenção\nPreencha o campo de TELEFONE.') ;
		form.telefone.focus();
		return false ;
	}
	
	if ( form.mensagem.value == '' )
	{
		alert('Atenção\nPreencha o campo de MENSAGEM.') ;
		form.mensagem.focus();
		return false ;
	}
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

//Funcao para o flash

function fnFlash(str_url, int_largura, int_altura)
{
	document.writeln('<object type="application/x-shockwave-flash" data="' + str_url + '" width="' + int_largura + '" height="' + int_altura + '">');
	document.writeln('<param name="movie" value="' + str_url + '">');
	document.writeln('<param name="quality" value="high">');
	document.writeln('<param name="wmode" value="transparent">');
	document.writeln('</object>');
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////

/*FUNCAO MENU LATERAL*/
function mostra(campo)
{
    document.getElementById(campo).style.display='' ;
}
function oculta(campo)
{
    document.getElementById(campo).style.display='none' ;
}

function onOff(id) { 
	esconder = (document.getElementById(id).style.display == 'block');
	/*if ( visivel == "" || visivel == "none" ) {
		document.getElementById(id).style.display = "block"
	} else {
		document.getElementById(id).style.display = "none";
	}*/
	
	divs = document.getElementsByTagName('DIV');
	for(d=0; d<divs.length; d++){
		_div = divs[d];

		if (_div.className == 'abre_menu'){
			id_link = 'titulo_'+(_div.id);
			_link = document.getElementById(id_link);

			if (_div.id != id){
				_div.style.display = 'none';
				if (_link) _link.style.color = 'black';
			}
			else{
				_div.style.display = esconder ? 'none' : 'block';
				if (_link) _link.style.color = esconder ? 'black' : '#000';
			}
		}
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//valida formulario Contato
function ValidaForm_Contato(form){
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////
//valida formulario Trabalhe Conosco
function ValidaForm_Trabalhe_Conosco(form){	
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	if(form.sexo.value.length<=1){
		alert("O campo Sexo deve estar preenchido corretamente.");
		form.sexo.focus();
		return false;
	}
	if(form.estado_civil.value.length<=1){
		alert("O campo Estado Civil deve estar preenchido corretamente.");
		form.estado_civil.focus();
		return false;
	}
	if(form.endereco.value.length<=1){
		alert("O campo Endere&ccedil;o deve estar preenchido corretamente.");
		form.endereco.focus();
		return false;
	}
	if(form.numero.value.length<=1){
		alert("O campo N° deve estar preenchido corretamente.");
		form.numero.focus();
		return false;
	}
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	if(form.cep.value.length<=1){
		alert("O campo CEP deve estar preenchido corretamente.");
		form.cep.focus();
		return false;
	}
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar preenchido corretamente.");
		form.estado.focus();
		return false;
	}
	/*if(form.rg.value.length<=1){
		alert("O campo RG deve estar preenchido corretamente.");
		form.rg.focus();
		return false;
	}
	if(form.cpf.value.length<=1){
		alert("O campo CPF para contato deve estar selecionado corretamente.");
		form.cpf.focus();
		return false;
	}*/
	
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	
	var contador ;
	var flag ;
	
	flag = false ;
	
	for ( contador = 0 ; contador < form.empregado.length ; contador ++ )
	{
		if ( form.empregado[contador].checked )
		{
			flag = true ;
		}
	}
	
	if ( !flag )
	{
		alert("O campo Est&aacute; empregado atualmente? deve estar preenchido corretamente.");
		return false ;
	}
	
	
	if(form.pretensao.value.length<=1){
		alert("O campo Pretens&atilde;o Salarial deve estar preenchido corretamente.");
		form.pretensao.focus();
		return false;
	}
	
	if(form.cargo.value.length<=1){
		alert("O campo Cargo pretendido deve estar preenchido corretamente.");
		form.cargo.focus();
		return false;
	}
	if(form.cole.value.length<=1){
		alert("O campo Cole aqui seu curr&iacute;culo deve estar preenchido corretamente.");
		form.cole.focus();
		return false;
	}
}

//Funcao da Mascara
function fnMascara(objeto, evt, mask)
{ 
	var LetrasU = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var LetrasL = 'abcdefghijklmnopqrstuvwxyz';
	var Letras  = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';	
	var Numeros = '0123456789';
	var Fixos  = '().-:/ ';
	var Charset = " !\"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_/`abcdefghijklmnopqrstuvwxyz{|}~";

	evt = (evt) ? evt : (window.event) ? window.event : "";
	var value = objeto.value;
	if (evt) {
 	var ntecla = (evt.which) ? evt.which : evt.keyCode;
 	tecla = Charset.substr(ntecla - 32, 1);
 	if (ntecla < 32) return true;

 	var tamanho = value.length;
 	if (tamanho >= mask.length) return false;

 	var pos = mask.substr(tamanho,1);
 	while (Fixos.indexOf(pos) != -1)
	 	{
 	 		value += pos;
 	 		tamanho = value.length;
 	 		if (tamanho >= mask.length) return false;
 	 		pos = mask.substr(tamanho,1);
		}

 	switch (pos) 
		{
   			case '#' : if (Numeros.indexOf(tecla) == -1) return false; break;
   			case 'A' : if (LetrasU.indexOf(tecla) == -1) return false; break;
   			case 'a' : if (LetrasL.indexOf(tecla) == -1) return false; break;
   			case 'Z' : if (Letras.indexOf(tecla) == -1) return false; break;
   			case '*' : objeto.value = value; return true; break;
   			default : return false; break;
 		}
	}
	objeto.value = value;
	return true;
}

///////////////////////////////////////////////////////////////////
// Funcao valida form do Indique o amigo
function ValidaForm_IndiqueAmigo(form) {	
	if (form.nome.value=="") {
		alert("O campo Seu nome deve ser preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	
	var str_email = form.email.value ;
    if ( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) {
    	alert("O campo Seu E-mail deve ser preenchido corretamente.");
    	form.email.focus();
    	return false;
	}
	if (form.emailamigo.value=="") {
		alert("O campo E-mail de Destin&Aacute;tario deve ser preenchido corretamente.");
		form.emailamigo.focus();
		return false;
	}
	
	
}
function indique() {
	window.open('indique_amigo.php','indiqueAmigo','width=440,height=470,scrollbars=no');
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//valida Valida_Treinamento

function Valida_Treinamento(form){
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}
}



///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Validacao Testemunhais

function Valida_Testemunhais(form){
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Valida_Processos_de_Qualificaao

function Valida_Processos_de_Qualificaao(form){
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Valida_Processos_de_Producao

function Valida_Processos_de_Producao(form){
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}
}


//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Valida_Responsabilidade_Ambiental

function  Valida_Responsabilidade_Ambiental(form){
	if(form.nome.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome.focus();
		return false;
	}
	var str_email = form.email.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
	if(form.telefone.value.length<=1){
		alert("O campo Telefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	if(form.cidade.value.length<=1){
		alert("O campo Cidade deve estar preenchido corretamente.");
		form.cidade.focus();
		return false;
	}
	if(form.estado.value.length<=1){
		alert("O campo Estado deve estar selecionado corretamente.");
		form.estado.focus();
		return false;
	}
	if(form.mensagem.value.length<=1){
		alert("O campo Mensagem deve estar preenchido corretamente.");
		form.mensagem.focus();
		return false;
	}
	if(form.cod.value.length<=1){
		alert("O campo Código de Segurança deve estar preenchido corretamente.");
		form.cod.focus();
		return false;
	}
}
