// Funções para G Sete

///////////////////////////////////////////////////////////////////////////////////////////////////////////

//Valida 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 <= 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;
  }
  
}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ValidaFormCadastro(form){
	
	if(form.proprietario.value.length<=1)
	{
		alert("O campo Proprietário deve estar preenchido corretamente.");
		form.proprietario.focus();
		return false;
	}
	
	if(form.endereco.value.length<=1)
	{
		alert("O campo Endereço deve estar selecionado 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.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.cep.value.length<=1)
	{
		alert("O campo CEP deve estar preenchido corretamente.");
		form.cep.focus();
		return false;
	}
	
	if(form.telres.value.length<=1)
	{
		alert("O campo Telefone Residencial deve estar preenchido corretamente.");
		form.telres.focus();
		return false;
	}
	
	if(form.telcel.value.length<=1)
	{
		alert("O campo Celular deve estar preenchido corretamente.");
		form.telcel.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;
	}

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

function ValidaFormCorretor(form){
	
	if(form.tipo_negocio.value.length<=1)
	{
		alert("O campo Tipo de Negócio deve estar selecionado corretamente.");
		form.tipo_negocio.focus();
		return false;
	}
	
	if(form.tipo_imovel.value.length<=1)
	{
		alert("O campo Tipo de Imóvel deve estar selecionado corretamente.");
		form.tipo_imovel.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.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 Tefone deve estar preenchido corretamente.");
		form.telefone.focus();
		return false;
	}
	

}

//////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//valida Data
function validaData(DATA){
	var expReg = /^(([0-2]\d|[3][0-1])\/([0]\d|[1][0-2])\/[1-2][0-9]\d{2})$/;
	var msgErro = 'Formato inválido de data.';
	var vdt = new Date();
	var vdia = vdt.getDay();
	var vmes = vdt.getMonth();
	var vano = vdt.getYear();
	var vano = parseInt(vano)+1900;
	if ((DATA.value.match(expReg))&&(DATA.value!='')){
		var dia = DATA.value.substring(0,2);
		var mes = DATA.value.substring(3,5);
		var ano = DATA.value.substring(6,10);
		if((mes==04 && dia > 30)||(mes==06 && dia > 30)||(mes==09 && dia > 30)||(mes==11 && dia > 30)){
			alert("Dia incorreto! O mês especificado contém no máximo 30 dias.");
			DATA.focus();
			return false;
		}
		else{
			//1
			if(ano%4!=0 && mes==2 && dia>28){
				alert("Data incorreta! O mês especificado contém no máximo 28 dias.");
				DATA.focus();
				return false;
			} 
			else{ //2
				if(ano%4==0 && mes==2 && dia>29){
					alert("Data incorreta! O mês especificado contém no máximo 29 dias.");
					DATA.focus();
					return false;
				}
				else{ //3
					if(ano > vano){
						alert("Data incorreta! Ano informado maior que ano atual.");
						DATA.focus();
						return false;
					}
					else{ //4
					//alert ("Data correta!");
					return true;
					} //4-else
				} //3-else
			}//2-else
		}//1-else
	}
	else{ //5
		alert(msgErro);
		DATA.focus();
		return false;
	} //5-else
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//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;
}

/////////////////////////////////////////////////////////////////////////////////////////////////

//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>');
}

//////////////////////////////////////////////////////////////////////////////////////////////////
