function EstableceValor(sCampo, sValor){
	var oCampo = document.getElementById(sCampo);
	if(oCampo != null){
		oCampo.value = sValor;
	}
}

function VerificaSalida(){
	var texto = "¿Está seguro que desea salir?";
	if(confirm(texto)){
		return true;
	}else{
		return false;
	}
}

function PreguntaSalida(){
	if(VerificaSalida()){
		noPostBack("salir.aspx");
		document.forms[0].submit();
	}
}

function AccedeAplicacion2(sNewFormAction, sIdSesion, sIdApl, sRFC, sNombre){
	//alert(sNewFormAction);
	document.forms[0].txtIdSesion.value = sIdSesion;
	document.forms[0].txtIdApl.value = sIdApl;
	document.forms[0].txtRFC.value = sRFC;
	document.forms[0].txtNombre.value = sNombre;
	noPostBack(sNewFormAction);
	document.forms[0].submit();
}

function AccedeAplicacion(sNewFormAction, sIdSesion, sIdApl){
	//alert(sNewFormAction);
	document.forms[0].txtIdSesion.value = sIdSesion;
	document.forms[0].txtIdApl.value = sIdApl;
	document.forms[0].txtRFC.value = "";	
	noPostBack(sNewFormAction);
	document.forms[0].submit();
}

function noPostBack(sNewFormAction){
	document.forms[0].action = sNewFormAction;
	document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
}

//A.D.R. 10-Ene-2009
//Se agregan las funciones noPostBack2 y redirecciona para dar soporte a SOIA
function noPostBack2(sNewFormAction){
	var resul;
	
	resul = confirm("¿Esta seguro de salir de SOIA y regresar a SAAIWeb ?");

	if (resul) 
	{
		document.forms[0].action = sNewFormAction;
		document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
		document.forms[0].submit();
	}
	
}

function redirecciona(sNewFormAction){
		document.forms[0].action = sNewFormAction;
		document.forms[0].__VIEWSTATE.name = 'NOVIEWSTATE';
		document.forms[0].submit();
}

function regresa(){
	history.go(-1);
}

function MuestraOculta(oItem){
	oElement = document.getElementById(oItem);
	if(oElement != null){
		if (oElement.style.display == "none"){
			oElement.style.display = "block";
		}else{
			oElement.style.display = "none";
		}
	}
}

function Muestra(oItem){
	var oElement;
	oElement = document.getElementById(oItem);
	if(oElement != null){
		oElement.style.display = "block";
	}
}

function Oculta(oItem){
	var oElement;
	oElement = document.getElementById(oItem);
	if(oElement != null){
		oElement.style.display = "none";
	}
}

function Habilita(oItem){
	var oElement;
	oElement = document.getElementById(oItem);
	if(oElement != null){
		oElement.disabled = false;
	}
}

function Deshabilita(oItem){
	var oElement;
	oElement = document.getElementById(oItem);
	if(oElement != null){
		oElement.disabled = true;
	}
}
	
function CampoTelefono(){
	if (e.keyCode!="1")
		return false;
	else
		return true;
	
}

//A.D.R. 05-Ene-2009
//Función para ejecutar varias funciones en el evento onload
function makeDoubleDelegate(function1, function2){
	return function(){
		if (function1)
			function1();
		if (function2)
			function2();
	}
}

document.onkeyup = KeyCheck;
function KeyCheck(e){
	var KeyID = (window.event) ? event.keyCode : e.keyCode;
	if(KeyID == 13){
		event.returnValue = false;
        event.cancel = true;
        boton = document.getElementById("btnBuscar");
        if(boton == null){
			boton = document.getElementById("btnGuardar");
        }
        if(boton == null){
			boton = document.getElementById("btnIniciar");
        }
        if(boton == null){
			boton = document.getElementById("BtnBuscaMan");
        }
        if(boton == null){
			boton = document.getElementById("BtnBuscar");
        }
        if(boton == null){
			boton = document.getElementById("btnBuscar");
        }
        if(boton == null){
			boton = document.getElementById("btnBusca");
        }
        if(boton == null){
			boton = document.getElementById("cmdBuscar");
        }
        if(boton == null){
			boton = document.getElementById("Buscar");
        }
        if(boton == null){
			boton = document.getElementById("btnGuardar");
        }
        if(boton == null){
			boton = document.getElementById("btnAceptar");
        }
        if(boton != null){
			boton.focus();
			boton.click();
		}else{
			document.forms[0].submit();
		}
	}
} 

function KeyDownHandler(btn){
    // process only the Enter key
    if (event.keyCode == 13){
        // cancel the default submit
        event.returnValue = false;
        event.cancel = true;
        // submit the form by programmatically clicking the specified button
        btn.click();
    }
}
