// Funções para o Nazareno São Carlos

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

// função newsletter

function ValidaFormNewsletter(form){
  
  if ( form.nome.value.length <= 1 || form.nome.value=="Nome:"){
	  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;
  }
}

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

//Valida Cadastre-se

function ValidaForm_Cadastre (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 selecionado corretamente.");
	  form.sexo.focus();
	  return false;
  }
  
  
  if ( form.endereco.value.length <= 1 ) {
	  alert("O campo Endereço deve estar preenchido corretamente.");
	  form.endereco.focus();
	  return false;
  }
  
  
  if ( form.bairro.value.length <= 1 ) {
	  alert("O campo Bairro deve estar preenchido corretamente.");
	  form.bairro.focus();
	  return false;
  }
  
  
  if ( form.cep.value.length <= 1 ) {
	  alert("O campo CEP deve estar preenchido corretamente.");
	  form.cep.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 preenchido corretamente.");
	  form.estado.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 str_email = form.confirme.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo Confirme deve ser preenchido corretamente");
    	form.confirme.focus();
    	return false;
	}
	

  if ( form.telefone.value.length <= 13 ) {
	  alert("O campo Telefone Fixo deve estar preenchido corretamente.");
	  form.telefone.focus();
	  return false;
  }
  

  if ( form.cod.value.length <=1 ) {
	  alert("Digite o Código de Segurança.");
	  form.cod.focus();
	  return false;
  }
	

}

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

//Valida Fale Conosco

function ValidaForm_Fale_Conosco (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 <= 13 ) {
	  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 preenchido 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("Digite o Código de Segurança.");
	  form.cod.focus();
	  return false;
  }
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Função de Máscara 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 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( " ", "" );
  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)); } // Números 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 popup
function MM_openBrWindow(theURL,winName,features) 
{
	var myWin =  window.open(theURL,winName,features);
	myWin.focus();
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//Função 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>');
}
/////////////////////////////////////////////////////////////////////////////////////////////////
//Função Adiciona a Favoritos
function fnAdicionaFavoritos()
{
	str_titulo = "Igreja do Nazareno São Carlos";
	str_url = "http://www.nazarenosaocarlos.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;
	}
}


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

//Função Validação do Indique 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 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo Seu E-mail deve ser preenchido corretamente.");
    	form.email.focus();
    	return false;
	}
	
	var str_email = form.emailamigo.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' ))
	{
    	alert("O campo E-mail do Destinatário deve ser preenchido corretamente.");
    	form.emailamigo.focus();
    	return false;
	}
	
	
}

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

//Função 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>');
}


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

//função para o (mostrar e ocultar)
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 == 'titulo'){
			id_link = 'titulo_'+(_div.id);
			_link = document.getElementById(id_link);

			if (_div.id != id){
				_div.style.display = 'none';
	
			}
			else{
				_div.style.display = esconder ? 'none' : 'block';
			}
		}
	}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////

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 E-MAIL corretamente!");
		newsletter.email.focus();
		return false;
	}
	return true;
}

