// JavaScript Document
function FormataCampo(Campo,teclapres,mascara){ 
	strtext = Campo.value 
	tamtext = strtext.length 
	tammask = mascara.length 
	arrmask = new Array(tammask) 
	for (var i = 0 ; i < tammask; i++){ 
		arrmask[i] = mascara.slice(i,i+1) 
	} 

	if (((((arrmask[tamtext] == "#") || (arrmask[tamtext] == "9"))) || (((arrmask[tamtext+1] != "#") || (arrmask[tamtext+1] != "9"))))){ 
		if ((teclapres.keyCode >= 37 && teclapres.keyCode <= 40)||(teclapres.keyCode >= 48 && teclapres.keyCode <= 57)||(teclapres.keyCode >= 96 && teclapres.keyCode <= 105)||(teclapres.keyCode == 8)||(teclapres.keyCode == 9) ||(teclapres.keyCode == 46) ||(teclapres.keyCode == 13)){ 
			Organiza_Casa(Campo,arrmask[tamtext],teclapres.keyCode,strtext) 
		} else { 
			Detona_Event(Campo,strtext) 
		} 
	} else {
		if ((arrmask[tamtext] == "A")) { 
			charupper = event.valueOf() 
			Detona_Event(Campo,strtext) 
			masktext = strtext + charupper 
			Campo.value = masktext 
		} 
	} 
} 

function MM_jumpMenu(targ,selObj,restore){ //v3.0
  eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
  if (restore) selObj.selectedIndex=0;
}

function Organiza_Casa(Campo,arrpos,teclapres_key,strtext){ 
	if (((arrpos == "/") || (arrpos == ".") || (arrpos == ",") || (arrpos == ":") || (arrpos == " ") || (arrpos == "-")) && !(teclapres_key == 8)){ 
		separador = arrpos 
		masktext = strtext + separador 
		Campo.value = masktext 
	} 
} 

function Detona_Event(Campo,strtext){ 
	event.returnValue = false 
	if (strtext != "") { 
		Campo.value = strtext 
	} 
} 

function resetaForm(formulario){
	formulario.reset()	
}

function SendLognUsua(){
	des_logn = document.getElementById("DES_LOGN")
	des_pass = document.getElementById("DES_PASS")
	
	if(des_logn.value == ""){
		des_logn.focus()
		window.alert("O campo usurio  requerido")
		return false;	
	}
	if(des_pass.value == ""){
		des_pass.focus()
		window.alert("O campo senha  requerido")
		return false			
	}
	document.getElementById("frmLognUsua").submit()
}

function SendBusca(){
	asp_des_busc = document.getElementById("ASP_DES_BUSC")
	//if(asp_des_busc.value == ""){
	//	asp_des_busc.focus()
	//	window.alert("Preencha os parametros de busca!")
	//	return false
	//}
	document.getElementById("frmBusca").submit()
}

function openAjax() {
	var ajax;
	try{
		ajax = new XMLHttpRequest();
	}catch(ee){
		try{
			ajax = new ActiveXObject("Msxml2.XMLHTTP");
		}catch(e){
			try{
				ajax = new ActiveXObject("Microsoft.XMLHTTP");
			}catch(E){
				ajax = false;
			}
		}
	}
	return ajax;
}

function ExcluiRegistro(COD,METH,RETURN) {
	conf = window.confirm("deseja relamente excluir o registro?")
	if(conf){
	
		if(document.getElementById) {
			var ajax = openAjax();
			
			GETVAL = "PAGES/ACTEXCLUI.asp?DES_RETORNO="+RETURN+"&COD_REGI="+COD+"&DES_METH="+METH
	
			ajax.open("GET", GETVAL , false);
			ajax.setRequestHeader("Cache-Control", "no-store, no-cache, must-revalidate");
			ajax.setRequestHeader("Cache-Control", "post-check=0, pre-check=0");
			ajax.setRequestHeader("Pragma", "no-cache");
			ajax.onreadystatechange = function() {
				if(ajax.readyState == 1) {
					//exibeResultado.innerHTML = "Aguarde"
				}
				if(ajax.readyState == 4) {
					//exibeResultado.innerHTML = ""
					if(ajax.status == 200) {
						var resultado = null;
						resultado = ajax.responseText;
						resultado = resultado.replace(/\+/g," ");
						resultado = unescape(resultado);
						if(resultado=="1"){
				
							window.alert("registro excluido com sucesso");
							
							history.go();
						}
					} else {
						window.alert("An error occurred")
					}
				}
			}
			ajax.send(null);
		}
	}
}


