function IrParaMenu()
	{
	self.location ='frmMenu.asp'
	}
function AtualizaTopo()
	{
	window.parent.frames['fr_data'].location = window.parent.frames['fr_data'].location
	}
function ValidaTeclas(tipo)
	{
	if((tipo)=="NumeroPonto")
		{
		if(document.all) // Explorer
			var tecla = event.keyCode;
		else if(document.layers) // Nestcape
			var tecla = e.which;
		if(tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
			if ((tecla == 8) || (tecla == 46))// backspace || ponto
				return true;
			else
				return false;
			}
		}
	else if((tipo)=="NumeroPontoVirgula")
		{
		if(document.all) // Explorer
			var tecla = event.keyCode;
		else if(document.layers) // Nestcape
			var tecla = e.which;
		if(tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
			if ((tecla == 8) || (tecla == 46) || (tecla == 44))// backspace || ponto || virgula
				return true;
			else
				return false;
			}
		}
	if((tipo)=="Texto")
		{
		//nao saopermitidos '	"	<	>
		if(document.all) // Explorer
			var tecla = event.keyCode;
		else if(document.layers) // Nestcape
			var tecla = e.which;
		//alert(tecla)
		//34 "
		//39 '
		//60 <
		//62 >
		
		if ((tecla == 34) || (tecla == 39) || (tecla == 60) || (tecla == 62))// '"<>
			return false;
		else
			return true;
		}
	else if((tipo)=="Numero")
		{
		if(document.all) // Explorer
			var tecla = event.keyCode;
		else if(document.layers) // Nestcape
			var tecla = e.which;
		if(tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
			if ((tecla == 8)) //backspace
				return true;
			else
				return false;
			}
		}
	else if((tipo)=="Data")
		{
		if(document.all) // Explorer
			var tecla = event.keyCode;
		else if(document.layers) // Nestcape
			var tecla = e.which;
		if(tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
			if ((tecla == 8) || (tecla == 47)) //backspace || barra
				return true;
			else
				return false;
			}
		}
	if((tipo)=="Senha")
		{
		//nao saopermitidos '	"	<	>	*
		if(document.all) // Explorer
			var tecla = event.keyCode;
		else if(document.layers) // Nestcape
			var tecla = e.which;
		if ((tecla == 39) || (tecla == 34) || (tecla == 60) || (tecla == 62) || (tecla == 42)) // '"<>*
			return false;
		else
			return true;
		}
	else if((tipo)=="Fone")
		{
		if(document.all) // Explorer
			var tecla = event.keyCode;
		else if(document.layers) // Nestcape
			var tecla = e.which;
			
		alert(tecla)
		if(tecla > 47 && tecla < 58) // numeros de 0 a 9
			return true;
		else
			{
			if ((tecla == 8) || (tecla == 47)) //backspace || barra
				return true;
			else
				return false;
			}
		}
	}

function Foco() 
	{
	if (document.forms.length > 0) 
		{
		var field = document.forms[0];
		for (i = 0; i < field.length; i++) 
			{
			if ((field.elements[i].type == "text") || (field.elements[i].type == "textarea") || (field.elements[i].type == "button") || (field.elements[i].type.toString().charAt(0) == "s")) 
				{
				if (document.forms[0].elements[i].disabled == false)
					{
					document.forms[0].elements[i].focus();
					if ((document.forms[0].elements[i].type == "text") || (field.elements[i].type == "textarea"))
						{
						document.forms[0].elements[i].select();
						}
					break;
					}
				}
			}
		}
	}
	
function ValidaData(txtData,permite_brancos)
	{
	// passados 2 parametros
	// txtData = o nome do campo a ser testado
	// permite_brancos = é permitido campo vazio
	
	retorno = true;
	if ((permite_brancos != true) && (txtData.value.length == 0))
		{
		return !retorno;
		}
	if ((permite_brancos == true) && (txtData.value.length == 0))
		{
		return retorno;
		}
	else if (txtData.value.length != 0)
		{
		if (txtData.value.length != 10)
			{
			return !retorno;
			}
		else
			{
			data = txtData.value;
			dia = data.substring(0,2);
			mes = data.substring(3,5);
			ano = data.substring(6,10);
			
			barra1 = data.substring(2,3);
			barra2 = data.substring(5,6)
			
			if ((barra1 != "/" ) || (barra2 != "/"))
				{
				return !retorno;
				}
			else if ((dia < 1) || (dia > 31))
				{
				return !retorno;
				}
			else if ((mes < 1) || (mes > 12))
				{
				return !retorno;
				}
			else if ((ano < 1900) || (ano > 3000))
				{
				return !retorno;
				}
			if ((isNaN(dia)) || (isNaN(mes)) || (isNaN(ano)))
				{
				return !retorno;
				}
			if ((mes == 2 && dia > 28 && (ano % 4 != 0)))
				{
				return !retorno;
				}
			if ((mes == 2 && dia > 29 && (ano % 4 == 0)))
				{
				return !retorno;
				}
			if (((mes == 4) || (mes == 6) || (mes == 9) || (mes == 11)) && (dia > 30))
				{
				return !retorno;
				}
			}
		}
	}
function ValidaEmail(txtEmail,permite_brancos)
	{
	retorno = true;
	if ((permite_brancos != true) && (txtEmail.value.length == 0))
		{
		return !retorno;
		}
	if ((permite_brancos == true) && (txtEmail.value.length == 0))
		{
		return retorno;
		}
	else if (txtEmail.value.length != 0)
		{
		var str = txtEmail.value.split("@")
		nTotal = str.length-1
		if (nTotal > 1)
			{
			return !retorno;
			}		
		if ((txtEmail.value.length < 6)) // tamanho minimo deve ser de 6 caracteres "x@x.x.xx"
			{
			return !retorno;
			}
		if ((txtEmail.value.indexOf("@")) == -1)	//deve ter "arroba"
			{
			return !retorno;
			}	
		else if ((txtEmail.value.indexOf(".")) == -1)	// deve ter "ponto"
			{
			return !retorno;
			}
		else if ((txtEmail.value.indexOf(" ")) > -1)	// nao pode ter "espaco"
			{
			return !retorno;
			}
		else if ((txtEmail.value.indexOf("@.")) > -1)	// nao pode ter "arroba" seguido de "ponto"
			{
			return !retorno;
			}
		else if ((txtEmail.value.indexOf("@_")) > -1)	// nao pode ter "arroba" seguido de "underscore"
			{
			return !retorno;
			}
		else if ((txtEmail.value.indexOf("._")) > -1)	// nao pode ter "ponto" seguido por "underscore"
			{
			return !retorno;
			}
		}
	}

//-------------------------------------------------------------------
// Trim functions
//   Returns string with whitespace trimmed
//-------------------------------------------------------------------
function LTrim(str)
	{
	for(var i=0;str.charAt(i)==" ";i++);
	return str.substring(i,str.length);
	}
function RTrim(str)
	{
	for(var i=str.length-1;str.charAt(i)==" ";i--);
	return str.substring(0,i+1);
	}
function Trim(str)
	{
	return LTrim(RTrim(str));
	}


//-------------------------------------------------------------------
// getSingleInputValue(input_object,use_default)
//   Utility function used by others
//-------------------------------------------------------------------
function getSingleInputValue(obj,use_default) {
	switch(obj.type){
		case 'radio': case 'checkbox': 
			return(((use_default)?obj.defaultChecked:obj.checked)?obj.value:null);
		case 'text': case 'hidden': case 'textarea':	
			return(use_default)?obj.defaultValue:obj.value;
		case 'select-one':
			if(use_default){
				var o=obj.options;
				for(var i=0;i<o.length;i++){if(o[i].defaultSelected){return o[i].value;}}
				return null;
				}
			return(obj.options.length>0)?obj.options[obj.selectedIndex].value:null;
		case 'select-multiple': 
			var values=new Array();
			for(var i=0;i<obj.options.length;i++) {
				if((use_default&&obj.options[i].defaultSelected)||(!use_default&&obj.options[i].selected)) {
					values[values.length]=obj.options[i].value;
					}
				}
			return (values.length==0)?null:commifyArray(values);
		}
	alert("FATAL ERROR: Field type "+obj.type+" is not supported for this function");
	return null;
	}
//-------------------------------------------------------------------
// isArray(obj)
// Returns true if the object is an array, else false
//-------------------------------------------------------------------
function isArray(obj)
	{
	return(typeof(obj.length)=="undefined")?false:true;
	}
	
//-------------------------------------------------------------------
// getInputValue(input_object)
//   Get the value of any form input field
//   Multiple-select fields are returned as comma-separated values
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function getInputValue(obj) {
	var use_default=(arguments.length>1)?arguments[1]:false;
	if (isArray(obj) && (typeof(obj.type)=="undefined")) {
		var values=new Array();
		for(var i=0;i<obj.length;i++){
			var v=getSingleInputValue(obj[i],use_default);
			if(v!=null){values[values.length]=v;}
			}
		return commifyArray(values);
		}
	return getSingleInputValue(obj,use_default);
	}
	
//-------------------------------------------------------------------
// getInputDefaultValue(input_object)
//   Get the default value of any form input field when it was created
//   Multiple-select fields are returned as comma-separated values
//   (Doesn't support input types: button,file,password,reset,submit)
//-------------------------------------------------------------------
function getInputDefaultValue(obj)
	{
	return getInputValue(obj,true);
	}
	
function isChanged(obj)
	{
	return(getInputValue(obj)!=getInputDefaultValue(obj));
	}
function ComparaData(txtData1,txtData2)
	{
	data = txtData1;
	
	dia = data.substring(0,2);
	mes = data.substring(3,5);
	ano = data.substring(6,10);
	txtData1 = ano + mes + dia
	
	data = txtData2;
	
	dia = data.substring(0,2);
	mes = data.substring(3,5);
	ano = data.substring(6,10);
	txtData2 = ano + mes + dia
	
	diferenca = parseInt(txtData1) <= parseInt(txtData2)
	return diferenca;
	}
