//Rutinas para establecer configuración de inicio
var wTDC=0
var hTDC=0
var Vista="";
var Usuario=""; var UsuarioNombre=""


//RUTINAS PARA LA GESTIÓN DE EVENTOS
document.onclick=dclic;
document.onmousedown=dclic;
document.onkeypress=dpress;
var xObjClic=null
var xTxtObjClic=""
function dclic(e){
	var xId=""
	if(window.event){
		xObjClic=window.event.srcElement
		xTxtObjClic=window.event.srcElement.innerHTML
		xId=window.event.srcElement.id}
	else{
		xObjClic=e.target
		xTxtObjClic=e.target.innerHTML
		xId=e.target.id}			
	if(xId!='aMenuAplicacion' && xId!='tdLista' && xId!='xCMes' && xId!="xCAnio"){
		msgQuita('divLista|divMenuAplicacion|')		
		xLnkAplicacionClic=false;
	}
	
//	alert(xObjClic.tagName)
	if(xObjClic.tagName!="INPUT" && xObjClic.tagName!="SELECT" && xObjClic.tagName!="TEXTAREA"  ){
		return false
	}
}

function dpress(e){
	if(window.event){
		xTecla=window.event.keyCode}
	else{
		xTecla=e.keyCode}
	if(xTecla==27){
		xIdCatalogoVentana=0;
		if(document.getElementById('divLista').style.display==''){
			msgQuita('divLista|')
		}
		else{
			msgQuita('divLista|divMenuAplicacion|divVentanaFormato|divVentanaEsperaFormato|')
		}				
	}
}


function doNothing(){}
		
function findPosX(obj){
	var curleft = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curleft += obj.offsetLeft
			obj = obj.offsetParent;	}
	}
	else if (obj.x)
		curleft += obj.x;
	return curleft;
}

function findPosY(obj){
	var curtop = 0;
	if (obj.offsetParent){
		while (obj.offsetParent){
			curtop += obj.offsetTop
			obj = obj.offsetParent;	}
	}
	else if (obj.y)
		curtop += obj.y;
	return curtop;
}


//Rutnias para la gestión de mensajes y ventanas
function ubicaCentro(xDiv){
	xDiv.style.left=(document.body.offsetWidth / 2) - (xDiv.offsetWidth / 2)
	xDiv.style.top=(document.body.offsetHeight / 2) - (xDiv.offsetHeight / 2)
	if(document.body.scrollTop>0){
		xDiv.style.top=(document.body.scrollTop) + 130
	}
}
function ubicaVentana(xDiv){
	xDiv.style.left=(document.body.offsetWidth / 2) - (xDiv.offsetWidth / 2)
	xDiv.style.top=(document.body.scrollTop) + 130
}
function msgEspera(xMsg){
	var xDiv=document.getElementById("divMsg")
	xDiv.innerHTML="<DIV Class='CuerpoMensaje'>"+xMsg+"</DIV>"
	document.getElementById("divEspera").style.display=''
	document.getElementById("divEspera").style.height=document.getElementById('divPrincipal').offsetHeight
	document.getElementById("divEspera").style.width=document.body.offsetWidth - 20
	
	xDiv.style.display=''
	ubicaCentro(xDiv)
}
function msgQuita(xObjetos){		
	var xTexto=xObjetos
	xTexto=xTexto.split("|")
	ocultaObjeto('')
	for(i=0; i<xTexto.length - 1; i++){
		if(document.getElementById(xTexto[i])!=null){document.getElementById(xTexto[i]).style.display='none'}
	}
}

function mueveDivADM(xD,xDivT){
	var xDiv="divTblTitulos"
	if(xDivT!=null){xDiv=xDivT}
	document.getElementById(xDiv).scrollLeft=xD.scrollLeft
	document.getElementById(xDiv).scrollTop=xD.scrollTop
}

function mueveDiv(xD){
	document.getElementById("divEncabezadoCentro").scrollLeft=xD.scrollLeft
	document.getElementById("divCuerpoIzquierdo").scrollTop=xD.scrollTop
	document.getElementById("divCuerpoCentro").scrollTop=xD.scrollTop
}


//Rutinas de AJAX
var xIncremento=205
var xIncrementaScroll=0; var xReduce=43; var xReduceAncho=580;
function objAJAX(){
	var obj;
	if(window.XMLHttpRequest) { // Mozzilla/Safari
		xIncrementaScroll=2
		xReduce=57
		xReduceAncho=595		
		obj = new XMLHttpRequest();
		xIncremento=205
	}
	 else { 
			try {obj = new ActiveXObject("Microsoft.XMLHTTP");} //Internet Explorer
			catch (e) {alert('Existe un problema con el navegador');}
	}
	return obj;
}

//Rutinas de validación
function revisaFecha(xD,xM,xA){
	var xFecha = new Date();
	xFecha.setFullYear(xA,xM,xD);
	if(xFecha.getMonth()!=xM){
		return false;
	} 
	else{
		return true;
	}
}

function ultimoDia(xMes,xAnio){ 
	var ud=28; 
	while(revisaFecha(ud + 1,xMes - 1,xAnio)){ 
		ud++; 
	} 
	return ud; 
}

function validaTeclaNumero(xObj,xTecla){	
	if((xTecla<48 || xTecla>57) && xTecla!=109 && xTecla!=61 && xTecla!=8 && xTecla!=37 && xTecla!=39){
		return false;
	}	
}
var numeros="0123456789.";
function numero(car){
	return (numeros.indexOf(car)>=0)}

function validaNumero(xcontenido){  
	var contenido;
	contenido=xcontenido				
	if(contenido.length>0){  
		for (var i=0; i<contenido.length; ++i){
		    var car=contenido.charAt(i);					  
	        if (!numero(car)){
				i=contenido.length;
				return true;}
		}
	}
	else{
	 	return true;}			
 }

function ocultaObjeto(xOp){
	capas=document.getElementsByTagName('SELECT');
	for (i=0;i<capas.length;i++){		
		capas[i].style.display=""+xOp+"";
	}
}	
 
var xOpcion=""
var xCellClick; var xTxtClick;
function cargaCalendario(xObj,xFecha,xM,xA){
	xTxtClick=xObj;
	xCellClick=xObj.parentNode;
	var xParam="fecha="+xFecha
	if(xM!=null){xParam+="&xMes="+xM}
	if(xA!=null){xParam+="&xAnio="+xA}
	xParam+="&Opcion="+xOpcion
	ajax=objAJAX();
	ajax.open("POST", "Calendario.asp",true);		
	ajax.onreadystatechange=function() {
										if (ajax.readyState==2) {
											xDiv=document.getElementById("divLista")
											xDiv.innerHTML="<DIV Style=\"padding: 5px; width: 200px\">Cargando...</DIV>"
											xDiv.style.display=''
											ubicaMenu(xObj,xDiv,"calendario")
										}
										if (ajax.readyState==4) {
											xDiv.innerHTML=ajax.responseText
											ubicaMenu(xObj,xDiv,"calendario")
										}
									}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(xParam)
}

function cargaReloj(xObj,xHora,xM,xA){
	xTxtClick=xObj;
	xCellClick=xObj.parentNode;
	var xParam="hora="+xHora
	xParam+="&Opcion="+xOpcion
	ajax=objAJAX();
	ajax.open("POST", "../Reloj.asp",true);		
	ajax.onreadystatechange=function() {
										if (ajax.readyState==2) {
											xDiv=document.getElementById("divLista")
											xDiv.innerHTML="<DIV Style=\"padding: 5px; width: 200px\">Cargando...</DIV>"
											xDiv.style.display=''
											ubicaMenu(xObj,xDiv)
										}
										if (ajax.readyState==4) {
											xDiv.innerHTML=ajax.responseText
											ubicaMenu(xObj,xDiv)
										}
									}
	ajax.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
	ajax.send(xParam)
}




//RUTINAS PARA EL ARRASTRE DE OBJETOS
//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;
  this.isNS    = false;
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.
  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

// Global object to hold drag information.
var dragObj = new Object();
dragObj.zIndex = 0;

//Para saber si se mueve o dimensiona
var MovDim=""
function dragStart(event, id, xMovDim) {
	
  var el;
  var x, y;
  
  MovDim=xMovDim
  
  // If an element id was given, find it. Otherwise use the element being
  // clicked on.
  if (id)
    dragObj.elNode = document.getElementById(id);
  else {
    if (browser.isIE)
      dragObj.elNode = window.event.srcElement;
    if (browser.isNS)
      dragObj.elNode = event.target;

    // If this is a text node, use its parent element.
    if (dragObj.elNode.nodeType == 3)
      dragObj.elNode = dragObj.elNode.parentNode;
  }

  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }

  // Save starting positions of cursor and element.
  dragObj.cursorStartX = x;
  dragObj.cursorStartY = y;
  dragObj.elStartLeft  = parseInt(dragObj.elNode.style.left, 10);
  dragObj.elStartTop   = parseInt(dragObj.elNode.style.top,  10);

  if (isNaN(dragObj.elStartLeft)) dragObj.elStartLeft = 0;
  if (isNaN(dragObj.elStartTop))  dragObj.elStartTop  = 0;

  // Update element's z-index.
  //dragObj.elNode.style.zIndex = ++dragObj.zIndex;
  // Capture mousemove and mouseup events on the page.
  if (browser.isIE) {
    document.attachEvent("onmousemove", dragGo);
    document.attachEvent("onmouseup",	dragStop);
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", dragGo,   true);
    document.addEventListener("mouseup",   dragStop, true);
    event.preventDefault();
  }
}
var xIW=0, xIH=0
function dragGo(event) {

  var x, y, xW=0, xH=0;
  // Get cursor position with respect to the page.
  if (browser.isIE) {
    x = window.event.clientX + document.documentElement.scrollLeft
      + document.body.scrollLeft;
    y = window.event.clientY + document.documentElement.scrollTop
      + document.body.scrollTop;
  }
  if (browser.isNS) {
    x = event.clientX + window.scrollX;
    y = event.clientY + window.scrollY;
  }
  
//CODIGO EDITADO POR Mario A. Rmz. Monrreal para hacer crecer
  // Move drag element by the same amount the cursor has moved.
  if(MovDim=="m"){
   dragObj.elNode.style.left = (dragObj.elStartLeft + x - dragObj.cursorStartX) + "px";
   dragObj.elNode.style.top  = (dragObj.elStartTop  + y - dragObj.cursorStartY) + "px";
  }
  if(MovDim=="d"){
  	xW=xIW + x - dragObj.cursorStartX
	xH=xIH + y - dragObj.cursorStartY
  	if(xW>0){dragObj.elNode.style.width = (xW) + "px";}
	if(xH>0){dragObj.elNode.style.height = (xH) + "px";}
  }	
//---------------------------------------------------------------------------------------------------
  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function dragStop(event) {
  // Stop capturing mousemove and mouseup events.
  if (browser.isIE) {
    document.detachEvent("onmousemove", dragGo);
    document.detachEvent("onmouseup",	dragStop);
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", dragGo,	true);
    document.removeEventListener("mouseup",   dragStop, true);
  }
}

//DESACTIVAR SELECCIÓN DE LA PÁGINA
//if IE4+
document.onselectstart=new Function ("return false")

function Todos(Forma,xObj){//funcion para poner en seleccionados todos
	for (c=0; c < Forma.elements.length; c++){
		if (Forma.elements[c].type=="checkbox"){
			Forma.elements[c].checked=xObj.checked
		}
	}
}
