// JavaScript Document

/*
	Archivo de Libreria de Funciones
	Fecha: 06/06/2006
	Autor: L.I. Gerardo Daniel Ibarra Hernández.
	Ver. 1.0
*/

//Esta Funcion Redirecciona a la pagina de asistencia en modo de Modificacion
function modAsistencia(pOpcion, pCve_Nivel, pCve_Calendario, pCve_Grado, pCve_Grupo, pCve_Materia, pFecha_Asistencia){
	var vUrl = "asistencialist.jsp?opc="+pOpcion+"&nivel="+pCve_Nivel+"&calendario="+pCve_Calendario+"&grado="+pCve_Grado+"&grupo="+pCve_Grupo+"&materia="+pCve_Materia+"&fecha="+pFecha_Asistencia;
	window.location = vUrl;
}

//Regresa a la pagina que la invoco en el Modulo de Asistencias
function BackToMenu(pOpcion, pNivel, pCalendario, pGrado, pGrupo, pMateria, pFechaAsistencia){
	var vUrl;
	
	//if(pOpcion == 1)
		vUrl = "asistencia.jsp?msg=&opc="+pOpcion+"&nivel=";
	/*else
		vUrl = "asistencialistdel.jsp?nivel=";
	*/	
	vUrl = vUrl+pNivel+"&calendario="+pCalendario+"&grado="+pGrado+"&grupo="+pGrupo+"&materia="+pMateria+"&fecha="+pFechaAsistencia;
	
	if(confirm("¿Esta Seguro de Abandonar la Operacion?..."))
		location.href(vUrl);
	else return false;
}

function valDatosAsist(){
	var valor = 0;
	
	for(i=0; i<document.frmAsist_Borra.elements.length; i++){
			if(document.frmAsist_Borra.elements[i].type == "checkbox")
				if(document.frmAsist_Borra.elements[i].checked){
					valor = document.frmAsist_Borra.elements[i].value
					break;
				}			
	}
	
	if(valor != 0)
		if(confirm("¿Está Seguro que los Datos Seleccionados son Correctos?"))
			return true;
		else return false;	
	else{
		alert("Debe Elegir una  Fecha para Eliminar");
		return false;
	}
	
}
// Esta Funcion sirve para Abrir una Pagina en otro navegador centrada en pantalla
function OpenBrWindow(theURL,winName,features, myWidth, myHeight, isCenter) { 
	if(window.screen)
		if(isCenter)
			if(isCenter=="true"){
				if(myWidth == 0)//le Asigna el 70 % de acuerdo a la resolucion de la pantalla de altura
					myWidth = screen.width * .9
				
				if(myHeight == 0) //le Asigna el 50 % de acuerdo a la resolucion de la pantalla de altura
					myHeight = screen.height * .9
					
				var myLeft = (screen.width-myWidth)/2;
				var myTop = (screen.height-myHeight)/2;
				features+=(features !='')?',':'';
				features+='left='+myLeft+',top='+myTop;
	}
	window.open(theURL,winName,features+((features!='')?',':'')+'width='+myWidth+',height='+myHeight);
}

//Cambia a Letra Capital
function Convertir(objeto) 
{
var index;
var tmpStr;
var tmpChar;
var preString;
var postString;
var strlen;
tmpStr = objeto.value.toLowerCase();
strLen = tmpStr.length;
    if (strLen > 0) 
    {
    for (index = 0; index < strLen; index++) 
        {
        if (index == 0) 
            {
            tmpChar = tmpStr.substring(0,1).toUpperCase();
            postString = tmpStr.substring(1,strLen);
            tmpStr = tmpChar + postString;
            }
            else 
            {
            tmpChar = tmpStr.substring(index, index+1);
                if (tmpChar == " " && index < (strLen-1)) 
                {
                tmpChar = tmpStr.substring(index+1, index+2).toUpperCase();
                preString = tmpStr.substring(0, index+1);
                postString = tmpStr.substring(index+2,strLen);
                tmpStr = preString + tmpChar + postString;
                }
            }
        }
    }
objeto.value = tmpStr;
}

//Oculta una Capa al Imprimir
function toPrint(pCloseWin){
	document.all.imprime.style.visibility="hidden";	
	window.print();
	if(pCloseWin)
		window.close();
	else
		document.all.imprime.style.visibility="visible";
}

//Obtiene la fecha del Ordenador
function fechaHoy(){
	fec=new Date;
	dia=fec.getDate();
	if (dia<10) dia='0'+dia;
	mes=fec.getMonth()+1;
	if (mes<10) mes='0'+mes;
	anio=fec.getFullYear();
	fecha=dia+'/'+mes+'/'+anio;
	
return fecha;
}

/*
	Esta Funcion Compara 2 Fechas y Determina si una fecha es Mayor o Menor
	la una respecto a la otra
*/
function comparaFechas(pFecha_Compara, pFecha_RspctoA, pOperacion){
var vFecha_Cmpra = new Date(pFecha_Compara.substring(6,10), eval(pFecha_Compara.substring(3,5)-1), pFecha_Compara.substring(0,2));
var vFecha_RspctoA = new Date(pFecha_RspctoA.substring(6,10), eval(pFecha_RspctoA.substring(3,5)-1), pFecha_RspctoA.substring(0,2));

	if(pOperacion == "MAYOR QUE")
		if(vFecha_Cmpra > vFecha_RspctoA)
			return true;
		else return false;
	else if(pOperacion == "MENOR QUE")
		if(vFecha_Cmpra < vFecha_RspctoA)
			return true;
		else return false;
	else if(pOperacion == "IGUAL QUE")
		if(vFecha_Cmpra == vFecha_RspctoA)
			return true;
		else return false;	
}


/* 
	Las Siguientes Funciones para su funcionamiento requieren de la instalacion de la 
	libreria
				'prototype.js'
	y la invocacion de esta en primer lugar antes del archivo de funciones de la siguiente
	forma:
		<script type="text/javascript" src="js/prototype.js"></script>	  
		<script language="javascript" src="js/funciones.js"></script>
*/
/*
	Esta funcion le da el foco a un elemento de una lista de Objetos de un Formulario
	de Acuerdo a los siguientes parametros:
		pId_Campo - id del Campo del Formulario al cual se le quiere dar el foco
*/
function fCampo(pId_Campo){
	Field.focus(pId_Campo);
	if(Field.present(pId_Campo))
		Field.select(pId_Campo);
}

/*
	Esta Funcion asigna un Valor a un Campo de Texto proporcionando
	los siguientes parametros:
	pId_Sel - Selector es un Obj. Checkbox en su estado puede ser falso o verdadero.
	pId_CmpoSrc - Campo Fuente es el Textbox que contiene el valor a pasar.
	pId_CmpoTrg - Campo Destino es el Textbox que va a recibir el valor.
*/
function asgVal_Campo(pId_Sel, pId_CmpoSrc, pId_CmpoTrg){
	if($(pId_Sel).checked)
		if(Field.present(pId_CmpoSrc)){
			$(pId_CmpoTrg).value = $(pId_CmpoSrc).value;
			$(pId_Sel).checked = true;			
		}else{
			alert("Debe Asignar un Valor");
			$(pId_Sel).checked = false;			
		}
	else
		$(pId_CmpoTrg).value = "";
}

//Limpia Una area determinada la cual incluya una etiqueta id
function clrSubtool(pId){
	$(pId).innerHTML = "";
}

/*
	Selecciona Todos los Checks de un formulario
	parametros : recibe ID del formulario
*/
function selChkTodo(pId){
	var aChk = Form.getInputs(pId, 'checkbox');
	aChk.each(
				function(value, index){
					if(aChk[0].checked){
						aChk[index].click();
						aChk[0].checked = aChk[index].checked;
					}else{
						aChk[index].click();
						aChk[0].checked = aChk[index].checked;						
					}
				}				
			)
}

//Devuelve el Valor de un Radio Button
function getValorObj(pId , pObj){
	var vValor = null;
	var aRdio = Form.getInputs(pId, pObj);
	aRdio.each(
				function(value, index){
					if(aRdio[index].checked)
						vValor = aRdio[index].value;
				}
			  )
	return vValor;
}

//Habilita textBox para los Movimientos de Prestamo, Entrega
function enaDatoAdic(pId, pObjTxt, pVisibility){
		$(pId).style.visibility = pVisibility;
		
	Field.focus(pObjTxt);
}

//Carga la Ventana del Catalogo
function loadPagina(pUrl, pElemId, pParam){
	var vParam = pParam + "&kh="+Math.random();
	if(pParam == "")
		vParam = "?kh="+Math.random();

	var peticion = new Ajax.Request(
		pUrl, 
		{
			method: "get",
			parameters: vParam,
			onFailure: function(){
				$(pElemId).innerHTML = "error"; //respuesta.responseText;
			},
			onComplete: function(respuesta){
				$(pElemId).innerHTML = respuesta.responseText;
			},
			onSuccess: function(){
				$(pElemId).innerHTML = "Seleccione un Elemento de Catalogo";
			}
		}
	);
}

// esta funcion nos lleva al calendario de actividades eligiendo un area determinada
function ver_calendario(fecha)
{
	valor_area = getValorObj("filt" , "radio");
		if(valor_area==null){
			alert("Elige una area para la busqueda de actividades");	
			return false;
		}
	OpenBrWindow("siacal.asp?src=EML&usr=0&area="+valor_area+"&fecha="+fecha,'','toolbar=no,directories=no,status=yes, scrollbars=yes',0,0,'true');
	
	window.close();
}


