function checkTextAreaMaxLength(textBox,e, length)
		{
    
				var mLen = textBox["MaxLength"];
				if(null==mLen)
					mLen=length;
		        
				var maxLength = parseInt(mLen);
				if(!checkSpecialKeys(e))
				{
					if(textBox.value.length > maxLength-1)
					{
						if(window.event)//IE
						e.returnValue = false;
						else//Firefox
							e.preventDefault();
					}
				}   
		}
		
function CheckEmail(email)
{
   var achou_ponto=false;
   var achou_arroba=false;
   var nao_achou_espaco=false;

   for (var i=0; i < email.length; i++)
   {
      if (email.charAt(i)=="@")
      { 
         if (email.charAt(i+1)==".") achou_arroba=false;
         else achou_arroba=true;
      }
      else if (email.charAt(i)==".") achou_ponto=true;
      else if (email.charAt(i)!=" ") nao_achou_espaco=true;
   }
   
   if(email.charAt(email.length-1)==".") achou_ponto=false;
   
   
   
   if (achou_ponto && achou_arroba && nao_achou_espaco) return true;
   else
   {      
      return false;  
   }
}

function verificaAssinante(){
	with(document.formNews){
		if (txtNome.value == "") {
			alert('Informe o nome.');
			txtNome.focus();
			return false;
		}
		
		if (txtSobrenome.value == "") {
			alert('Informe o sobrenome.');
			txtSobrenome.focus();
			return false;
		}
		
		if (txtEmail.value == "") {
			alert('O Campo E-MAIL é de preenchimento obrigatório.');
			txtEmail.focus();
			return false;
		}else{
			if (!(CheckEmail(txtEmail.value))){
				alert('E-mail inválido!');
				txtEmail.focus();
				return false;
			}
		}
					
	}

}

function verificaIndicacao(){
	with(document.formIndicacao){
		if (txtNome.value == "") {
			alert('Informe o nome.');
			txtNome.focus();
			return false;
		}
		
		if (txtEmail.value == "") {
			alert('O Campo E-MAIL é de preenchimento obrigatório.');
			txtEmail.focus();
			return false;
		}else{
			if (!(CheckEmail(txtEmail.value))){
				alert('E-mail inválido!');
				txtEmail.focus();
				return false;
			}
		}
		
		if (txtNomeAmigo.value == "") {
			alert('Informe o nome do amigo.');
			txtNomeAmigo.focus();
			return false;
		}
		
		if (txtEmailAmigo.value == "") {
			alert('Informe o e-mail do amigo.');
			txtEmailAmigo.focus();
			return false;
		}else{
			if (!(CheckEmail(txtEmailAmigo.value))){
				alert('E-mail inválido!');
				txtEmailAmigo.focus();
				return false;
			}
		}
					
	}

}


function verifica(){
	with(document.form1){
		if (nome.value == "") {
			alert('O Campo NOME é de preenchimento obrigatório.');
			nome.focus();
			return false;
		}
		
		if (email.value == "") {
			alert('O Campo E-MAIL é de preenchimento obrigatório.');
			email.focus();
			return false;
		}else{
			if (!(CheckEmail(email.value))){
				alert('E-mail inválido!');
				email.focus();
				return false;
			}
		}
		
		if (!isData(dtInicio.value)) {
			alert('O Campo DATA INÍCIO é inválido.');
			dtInicio.focus();
			return false;
		}
		
		if (!isData(dtFim.value)) {
			alert('O Campo DATA FINAL é inválido.');
			dtFim.focus();
			return false;
		}
		
		if (msg.value == "") {
			alert('O Campo MENSAGEM é de preenchimento obrigatório.');
			msg.focus();
			return false;
		}
		
		if (!isNumerico(numHospedes.value)) {
			alert('O Campo NÚMERO DE HÓSPEDES aceita apenas números.');
			numHospedes.focus();
			return false;
		}
		
		if (!isNumerico(numQuartos.value)) {
			alert('O Campo NÚMERO DE QUARTOS aceita apenas números.');
			numQuartos.focus();
			return false;
		}
			
	}

}

function verificaEnvioNews(){
	with(document.form1){
		if (Subject.value == "") {
			alert('Informe o assunto do e-mail.');
			Subject.focus();
			return false;
		}
		
		if (Arquivo.value == "") {
			alert('Selecione o arquivo a ser enviado.');
			Arquivo.focus();
			return false;
		}
		
	}

}


function isData(pVal)
{
	var reTipo = /^((0?[1-9]|[12]\d)\/(0?[1-9]|1[0-2])|30\/(0?[13-9]|1[0-2])|31\/(0?[13578]|1[02]))\/(19|20)?\d{2}$/;

	return reTipo.test(pVal);
}

function isNumerico(pVal)
{
	var reTipo = /^\d+$/;
	return reTipo.test(pVal);
}



function FormataTel(tammax,pos,teclapres){
	var tecla = teclapres.keyCode;
	var fvr = '';
	// ao invés de recuperar valor do campo utilizadno o form, vou
	// pegar pelo evento<b></b>
	vr = event.srcElement.value;
	for(i=0;i<vr.length;i++){
		ch=vr.charAt(i);
		if((ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")||(ch=="0")){
			fvr=fvr+ch;
		}
		}
		vr=fvr;		
	tam = vr.length ;
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){ tam = tam - 1 ; }
			
	if ( tecla == 8 || tecla == 88 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){
			event.srcElement.value = "("+vr
		}
		if ( tam > pos+2 && tam <= tammax ){
			event.srcElement.value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );
			txt=event.srcElement.value
			event.srcElement.value = "("+txt.substr(0,2)+")"+txt.substr(2,tam)
			
		}
	}
}


function FormataTel2(tammax,pos,teclapres){
	var fvr = '';
	// ao invés de recuperar valor do campo utilizadno o form, vou
	// pegar pelo evento<b></b>
	vr = event.srcElement.value;
	for(i=0;i<vr.length;i++){
		ch=vr.charAt(i);
		if((ch=="1")||(ch=="2")||(ch=="3")||(ch=="4")||(ch=="5")||(ch=="6")||(ch=="7")||(ch=="8")||(ch=="9")||(ch=="0")){
			fvr=fvr+ch;
		}
		}
		vr=fvr;
		
	tam = vr.length ;
		if ((tam>0)&&(tam<=2)){
			event.srcElement.value = "("+vr
		}
		if ( tam > pos+2 && tam <= tammax ){
			event.srcElement.value = vr.substr( 0, tam - pos ) + '-' + vr.substr( tam - pos, tam );
			txt=event.srcElement.value
			event.srcElement.value = "("+txt.substr(0,2)+")"+txt.substr(2,tam)
			
		}
}
