////////////////////////////////////////////////////////////////////////////////////////
//funcao 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 fnTarget(str_target)
{
	//declaracao de variaveis
	var ch_tag_A, vet_A, int_i;
	var str_titulo;

	//pega todos os <a> da pagina e percorre um por um para achar o rel="external"
    ch_tag_A = document.getElementsByTagName('a');
    for(int_i=0; int_i<ch_tag_A.length; int_i++)
	{
		vet_A = ch_tag_A[int_i];
		if(vet_A.getAttribute("href") && vet_A.getAttribute('rel') != null)
		{
			if (vet_A.getAttribute('rel').substring(0,8) == 'external')
			{
				vet_A.target = str_target;
				str_titulo = ch_tag_A.title;
				ch_tag_A.title = str_titulo;
			}
		}
	}
}

function fnMostraOculta(pId)
{
	if (document.getElementById(pId).style.display == 'block')
	{
    	document.getElementById(pId).style.display='none' ;
	}
	else
	{
		document.getElementById(pId).style.display='block' ;
	}
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Funcao de popup
function MM_openBrWindow(theURL,winName,features){
	var myWin =  window.open(theURL,winName,features);
	myWin.focus();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Esqueci
function ValidaEsqueceu(form){
	var str_email = form.emaill.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.emaill.focus();
    	return false;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Funcao Adiciona a Favoritos
function fnAdicionaFavoritos(){
	str_titulo = ":: Gelinter Bebedouros ::";
	str_url = "http://www.gelinterbebedouros.com.br ";
	if(window.sidebar){ window.sidebar.addPanel(str_titulo, str_url,""); }
	else if(window.external){ window.external.AddFavorite( str_url, str_titulo); }
	else if(window.opera && window.print){ return true; }
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
 function verificaNews(form){
	var email = form.email.value;
    if((email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1)||(email == '::Digite seu e-mail::')){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	form.email.focus();
    	return false;
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//Funcao Validacao Login
function ValidaLogin(form)
{
	if (form.nome.value.length <= 2 || form.nome.value == " :: Nome ::" ){
		alert("O campo Nome deve ser preenchido corretamente.");
		form.nome.focus();
		return false;
	}

	if (form.senha.value == ''){
		alert("Atenção!\ O campo Senha deve ser preenchido.");
		form.senha.focus();
		return false;
	}
}

//Funcao Validacao do Indique Amigo
function ValidaForm_IndiqueAmigo(form,evento){
	if(form.nome.value == ''){
		alert('Atenção!\nO campo SEU 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 SEU E-MAIL deve ser preenchido.");
		form.email.focus();
		return false;
	}
	if(form.emailamigo.value == ''){
		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 ;
	}
}
//////////////////////////////////////////////////////////////////////////////////////////////
//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 Contato
function ValidaForm_Orcamento(form){
	if(form.nome_orcamento.value.length<=1){
		alert("O campo Nome deve estar preenchido corretamente.");
		form.nome_.focus();
		return false;
	}
	var str_email = form.email_orcamento.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_orcamento.focus();
    	return false;
	}
	
}

//cadastre-se

function fn_seleciona_tipo_pessoa(tipo){
	if(tipo == "fisica"){
		document.getElementById('oculta_empresaa').style.display = 'none';
		document.getElementById('oculta_empresa').style.display = 'none';
		document.getElementById('oculta_nome').style.display = '';
		document.getElementById('oculta_dado').style.display = '';
	}
	if(tipo == "juridica"){
		document.getElementById('oculta_empresaa').style.display = '';
		document.getElementById('oculta_empresa').style.display = '';
		document.getElementById('oculta_nome').style.display = 'none';
		document.getElementById('oculta_dado').style.display = 'none';
	}
}

// valida cadastre-se
function verificaCadastro(formCadastro){
	if((document.getElementById('pessoa_f').checked == false)&&(document.getElementById('pessoa_j').checked == false)){
		alert("Atenção!\nO campo PESSOA deve ser preenchido.");
		return false;
	}

	/*pessoa*/
	if(document.getElementById('pessoa_j').checked == true){
		if(formCadastro.empresa.value == ''){
			alert("O campo Razão Social deve ser preenchido.");
			formCadastro.empresa.focus();
			return false;
		}
		if(formCadastro.nome_contato.value == ''){
			alert("O campo Nome Contato deve ser preenchido.");
			formCadastro.nome_contato.focus();
			return false;
		}
		if(formCadastro.cnpj.value == ''){
			alert("O campo CNPJ deve ser preenchido.");
			formCadastro.cnpj.focus();
			return false;
		}
	}


	/*pessoa*/
	if(document.getElementById('pessoa_f').checked == true){
		if(formCadastro.nome.value == ''){
			alert("O campo NOME deve ser preenchido.");
			formCadastro.nome.focus();
			return false;
		}
		if(formCadastro.sobrenome.value == ''){
			alert("O campo Sobrenome deve ser preenchido.");
			formCadastro.sobrenome.focus();
			return false;
		}
		if(formCadastro.rg.value == ''){
			alert("O campo RG deve ser preenchido.");
			formCadastro.rg.focus();
			return false;
		}
		if(formCadastro.cpf.value == ''){
			alert("O campo CPF deve ser preenchido.");
			formCadastro.cpf.focus();
			return false;
		}
		if(formCadastro.data_nascimento.value == ''){
			alert("O campo Data Nascimento deve ser preenchido.");
			formCadastro.data_nascimento.focus();
			return false;
		}

		var contador ;
			var flag ;

			flag = false ;

			for ( contador = 0 ; contador < formCadastro.sexo.length ; contador ++ )
			{
				if ( formCadastro.sexo[contador].checked )
				{
					flag = true ;
				}
			}

			if ( !flag )
			{
				alert("O campo Sexo deve estar preenchido corretamente.");
				return false ;
			}


	}


	var str_email = formCadastro.loginn.value ;
    if (( str_email.search(/^\w+((-\w+)|(\.\w+))*\@\w+((\.|-)\w+)*\.\w+$/) == -1 ) || ( str_email == 'Email:' )){
    	alert("O campo E-mail deve ser preenchido corretamente");
    	formCadastro.loginn.focus();
    	return false;
	}
	/*
	if(formCadastro.loginn.value == ''){
		alert("O campo LOGIN deve ser preenchido.");
		formCadastro.loginn.focus();
		return false;
	}
	*/
	if(formCadastro.senha.value == ''){
		alert("O campo Senha deve ser preenchido.");
		formCadastro.senha.focus();
		return false;
	}
	if(formCadastro.endereco.value == ''){
		alert("O campo ENDEREÇO deve ser preenchido.");
		formCadastro.endereco.focus();
		return false;
	}
	if(formCadastro.numero.value == ''){
		alert("O campo Numero deve ser preenchido.");
		formCadastro.numero.focus();
		return false;
	}
	if(formCadastro.bairro.value == ''){
		alert("O campo BAIRRO deve ser preenchido.");
		formCadastro.bairro.focus();
		return false;
	}
	if(formCadastro.cep.value == ''){
		alert("O campo CEP deve ser preenchido.");
		formCadastro.cep.focus();
		return false;
	}
	if(formCadastro.cidade.value == ''){
		alert("O campo CIDADE deve ser preenchido.");
		formCadastro.cidade.focus();
		return false;
	}
    if(formCadastro.estado.value == ''){
		alert("O campo ESTADO deve ser preenchido.");
		formCadastro.estado.focus();
		return false;
	}
	if(formCadastro.telefone1.value == ''){
		alert("O campo TELEFONE deve ser preenchido.");
		formCadastro.telefone1.focus();
		return false;
	}
	if(formCadastro.cod.value == ''){
		alert("O campo CÓDIGO de SEGURANÇA deve ser preenchido.");
		formCadastro.cod.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;
}

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>');
}


