
//---------------------------------------------------------------------------------------
//#######################################################################################
function FormSubmit(parForm)
{
	document.forms(parform).submit;
	return 0;
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function CriticarCampos(parForm) {
	parForm = document.forms(parForm);
	var ctlControle, i, j = 0;
  	for(j = 0; j < parForm.length; j++) {
		ctlControle = parForm.elements[j];
  		if (ctlControle.obr == 1 && (ctlControle.value == "")) {
  			window.alert("Aviso: Preencha o campo '" + ctlControle.title  + "'.");
  			ctlControle.focus();		      
  			return false;  				
  		}
		if (ctlControle.value.length != 0 && ctlControle.value.length < ctlControle.minimo) {
				if (ctlControle.minimo == ctlControle.maximo) {
				window.alert("Aviso: O tamanho do campo '" + ctlControle.title + "' e de " + ctlControle.minimo + " caracteres.");
			} else {
				window.alert("Aviso: O tamanho minimo do campo '" + ctlControle.title + "' e de " + ctlControle.minimo + " caracteres.");
			}
//			if (ctlControle.Exemplo.length != 0) {window.alert('Exemplo: ' + ctlControle.Exemplo)};
  			ctlControle.focus();		      
  			return false;
  	  		}
		return true;  	  		
	};
  	//document.FormB.submit();
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function openWindow(url,nome,largura,altura) {
	//javascript:openWindow('/global/WebDicasView.aspx?DicCodigo=28')

	popupWin = window.open(url,nome,'width='+largura+',height='+altura+',resizable=yes,scrollbars=yes')
	popupWin.focus();
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function PosicionarCombo(parCombo,ItemData) {
	var i;
	for (i = 0; i < parCombo.length; i++) {
		if (parCombo.options[i].value == ItemData) {
			parCombo.options[i].selected = true
		}
	}
}

//---------------------------------------------------------------------------------------
//#######################################################################################

function VerificarSenha(form, campo1, campo2) {
	if (eval(form).elements(campo1).value.length == 0 || (eval(form).elements(campo1).value != eval(form).elements(campo2).value)) {
		alert('Senha e confirmação de senha não conferem!');
		eval(form).elements(campo1).focus();
		return false;
	}
	return true;
}

//---------------------------------------------------------------------------------------
//#######################################################################################

function VerificaEmail(parCampoEmail) 
{

	parEmail = parCampoEmail.value.toLowerCase();
	var newString = parEmail.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi)
	if (!newString) {
		alert("E-mail "+ parEmail +" incorreto.");
		parCampoEmail.value="";
	}
}



//---------------------------------------------------------------------------------------
//#######################################################################################
function FormataTelefone(form,campo,tammax,teclapres) {

	var tecla = teclapres.keyCode;
	mCampo = document.forms(form)[campo];
	
	vr = mCampo.value;

	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		mCampo.value = vr ; }
	 	if ( (tam > 4) ){
	 		mCampo.value = vr.substr( 0, tam - 4 ) + '-' + vr.substr( tam - 4, tam ) ; }
	}		

}

//---------------------------------------------------------------------------------------
//#######################################################################################
function SaltaCampo (form,campo,prox,tammax,teclapres){

	var tecla = teclapres.keyCode;
	mCampo = document.forms(form)[campo];
	vr = mCampo.value;
	
	if( tecla == 109 || tecla == 188 || tecla == 110 || tecla == 111 || tecla == 223 || tecla == 108 ){
		mCampo.value = vr.substr( 0, vr.length - 1 ); }
	else{
	 	vr = vr.replace( "-", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( "/", "" );
	 	vr = vr.replace( ",", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	vr = vr.replace( ".", "" );
	 	tam = vr.length;	
	 	if (tecla != 0 && tecla != 9 && tecla != 16 ){
			if ( tam == tammax ){
					document.forms(form)[prox].focus();
			}
		}
	}

}

//---------------------------------------------------------------------------------------
//#######################################################################################
function FormataData(form,campo,teclapres) {

	var tecla = teclapres.keyCode;
	mCampo = document.forms(form)[campo];
	vr = mCampo.value;
	vr = vr.replace( ".", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	tam = vr.length + 1;

	if ( tecla != 9 && tecla != 8 ){
		if ( tam > 2 && tam < 5 )
			mCampo.value = vr.substr( 0, tam - 2  ) + '/' + vr.substr( tam - 2, tam );
		if ( tam >= 5 && tam <= 10 )
			mCampo.value = vr.substr( 0, 2 ) + '/' + vr.substr( 2, 2 ) + '/' + vr.substr( 4, 4 ); 
	}
	
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function FormataCPF(form,campo,tammax,teclapres) {

	var tecla = teclapres.keyCode;
	mCampo = document.forms(form)[campo];
	vr = mCampo.value;
	
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;

	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		mCampo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 5) ){
	 		mCampo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 6) && (tam <= 8) ){
	 		mCampo.value = vr.substr( 0, tam - 5 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 9) && (tam <= 11) ){
	 		mCampo.value = vr.substr( 0, tam - 8 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 12) && (tam <= 14) ){
	 		mCampo.value = vr.substr( 0, tam - 11 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		mCampo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	}		
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function FormataCNPJ(form,campo,teclapres) {
	
	tammax=14;
	var tecla = teclapres.keyCode;
	mCampo = document.forms(form)[campo];
	vr = mCampo.value;

	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( "/", "" );
	vr = vr.replace( ",", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( ".", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	vr = vr.replace( "-", "" );
	tam = vr.length;
	
	if (tam < tammax && tecla != 8){ tam = vr.length + 1 ; }

	if (tecla == 8 ){	tam = tam - 1 ; }
		
	if ( tecla == 8 || tecla >= 48 && tecla <= 57 || tecla >= 96 && tecla <= 105 ){
		if ( tam <= 2 ){ 
	 		mCampo.value = vr ; }
	 	if ( (tam > 2) && (tam <= 6) ){
	 		mCampo.value = vr.substr( 0, tam - 2 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 7) && (tam <= 9) ){
	 		mCampo.value = vr.substr( 0, tam - 6 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 10) && (tam <= 12) ){
	 		mCampo.value = vr.substr( 0, tam - 9 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 13) && (tam <= 14) ){
	 		mCampo.value = vr.substr( 0, tam - 12 ) + '.' + vr.substr( tam - 12, 3 ) + '.' + vr.substr( tam - 9, 3 ) + '/' + vr.substr( tam - 6, 4 ) + '-' + vr.substr( tam - 2, tam ) ; }
	 	if ( (tam >= 15) && (tam <= 17) ){
	 		mCampo.value = vr.substr( 0, tam - 14 ) + '.' + vr.substr( tam - 14, 3 ) + '.' + vr.substr( tam - 11, 3 ) + '.' + vr.substr( tam - 8, 3 ) + '.' + vr.substr( tam - 5, 3 ) + '-' + vr.substr( tam - 2, tam ) ;}
	}		
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function limita(form,campo,tamanho){
	mCampo=document.forms(form)[campo];
	var tamanhoatual = mCampo.value.length;
	var tex=mCampo.value;
	if (tamanhoatual>=tamanho) {
		mCampo.value=tex.substring(0,tamanho); 
	}
	return true;
}


//---------------------------------------------------------------------------------------
//#######################################################################################


/*
//---------------------------------------------------------------------------------------
//#######################################################################################
function VerificaData(mystring)
{
	var day = mystring.substring(0,2);
	var month = mystring.substring(3,6);
	var year = mystring.substring(7,11); 
	if (checkDia(day) == false || (checkMes(month) !=true) || checkAno(year)) {
		alert('Data Inválida!');
		return false; 
	}
	else return true; 
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function checkDia(entry) { 
// verifica se o valor é menor que zero ou não é número
	if ((parseInt(entry) > 31) || (parseInt(entry) < 0) || isNaN(parseInt(entry))) return false;
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function checkAno(entry) { 
	if ((parseInt(entry) < 0) || isNaN(parseInt(entry))) return false;
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function checkMes(entry) {
	var mes = entry.toUpperCase();
	if (mes == 'JAN' || mes == 'FEV' || mes == 'MAR' ||
	mes == 'ABR' || mes == 'MAI' || mes == 'JUN' ||
	mes == 'JUL' || mes == 'AGO' || mes == 'SET' ||
	mes == 'OUT' || mes == 'NOV' || mes == 'DEZ' ) {
		vgMesDigitado = true; 
		return true; 
	}
	else {
		alert(mes + ' mês Inválido !!!');
		return false;
	} 
}*/


<!--
/*
Funces Definidas
=================
So definidas as seguintes funcoes:

'FormataData(this, event)' que retorna o campo texto do formulario
formatado de acordo com o formato utilizado aqui no Brasil
(dd/mm/aaaa)

'VerificaData(this)' que retorna se a data no campo texto valida

'DataPorExtenso()' retorna a data atual por extenso, no formato:
dia-da-semana, dia_do_mes de mes de ano

Forma de Utilizar:
==================
<input type="Text" name="NomeDoCampo"
size="10" maxlength="10" value=""
onKeydown="FormataData(this,event)"
onBlur="VerificaData(this)">
*/

//---------------------------------------------------------------------------------------
//#######################################################################################
function DataPorExtenso() {

	var agora = new Date();
	var ano = agora.getFullYear()
	var mes = agora.getMonth() + 1;
	var dia = agora.getDay() + 1;
	var diaNr = ( (agora.getDate()<10) ? "0" : "") + agora.getDate();

	switch (dia) {
		case 1 : dia = "domingo"; break;
		case 2 : dia = "segunda-feira"; break;
		case 3 : dia = "tera-feira"; break;
		case 4 : dia = "quarta-feira"; break;
		case 5 : dia = "quinta-feira"; break;
		case 6 : dia = "sexta-feira"; break;
		case 7 : dia = "sbado"; break;
	}

	switch (mes) {
		case 1 : mes = "Janeiro"; break;
		case 2 : mes = "Fevereiro"; break;
		case 3 : mes = "Maio"; break;
		case 4 : mes = "Abril"; break;
		case 5 : mes = "Maio"; break;
		case 6 : mes = "Junho"; break;
		case 7 : mes = "Julho"; break;
		case 8 : mes = "Agosto"; break;
		case 9 : mes = "Setembro"; break;
		case 10 : mes = "Outubro"; break;
		case 11 : mes = "Novembro"; break;
		case 12 : mes="Dezembro"; break;
	}
	return dia + ", " + diaNr + " de " + mes + " de " + ano;
}


//---------------------------------------------------------------------------------------
//#######################################################################################
// retorna se o ano bissesto ou nao
function LeapYear(intYear) {
	if (intYear % 100 == 0) {
		if (intYear % 400 == 0) return true;
	} else {
		if ((intYear % 4) == 0) return true;
	}
	return false;
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function VerificaData(objNome) {
if (VerificaValidadeData(objNome) == false) {
	objNome.select();
	alert("Aviso: Campo '" + objNome.title  + "' incorreto.");
	objNome.value = "";
	objNome.focus();
	return false;
	} else return true;
}

//---------------------------------------------------------------------------------------
//#######################################################################################
function VerificaValidadeData(NomeObj) {
	var data = NomeObj.value;

	var strDay;
	var strMonth;
	var strYear;

	var intDay;
	var intMonth;
	var intYear;

	data = data.replace( ".", "" );
	data = data.replace( "/", "" );
	data = data.replace( "/", "" );
	tam = data.length + 1;

	if (data.length < 1) return true;

	if (data.length!=8) return false;

	strDay = data.substr(0, 2);
	strMonth = data.substr(2, 2);
	strYear = data.substr(4);

	if (strYear.length == 2) strYear = '20' + strYear;

	intDay = parseInt(strDay, 10);
	if (isNaN(intDay)) return false;

	intMonth = parseInt(strMonth, 10);
	if (isNaN(intMonth)) return false;

	intYear = parseInt(strYear, 10);
	if (isNaN(intYear)) return false;

	if (intMonth > 12 || intMonth < 1) return false;

	if (( intMonth == 1 || intMonth == 3 || intMonth == 5 || intMonth
	== 7 || intMonth == 8 || intMonth == 10 || intMonth == 12) && (intDay > 31
	|| intDay < 1)) return false;

	if ((intMonth == 4 || intMonth == 6 || intMonth == 9 || intMonth
	== 11) && (intDay > 30 || intDay < 1)) return false;

	if (intMonth == 2) {
		if (intDay < 1) return false;
		if (LeapYear(intYear) == true) {
			if (intDay > 29) return false;
		} else {
			if (intDay > 28) return false;
		}
	}
	
	return true;
}


var VersaoBrowser = navigator.appVersion;
var BrowserIE = ((VersaoBrowser.indexOf("IE") > -1) || (VersaoBrowser.indexOf("Mac") > -1));

function MudaTexto(Nome, Valor){
	if (BrowserIE ){
		document.all[Nome].innerHTML = Valor ;
	} else {	
		document.layers[Nome].document.open();
		document.layers[Nome].document.write(Valor);
		document.layers[Nome].document.close();
	}		
}
