	function nuevoAjax(){ 

		var xmlhttp=false;
		try	{
			// Creacion del objeto AJAX para navegadores no IE
			xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
		}
		catch(e){
			try	{
				// Creacion del objet AJAX para IE
				xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(E){
				if (!xmlhttp && typeof XMLHttpRequest!='undefined') xmlhttp=new XMLHttpRequest();
			}
		}
		return xmlhttp; 
	}

	function abrirpopup(nombre,ancho,alto) {
		dat =  'width=' + ancho + ',height=' + alto + ',left=200,top=150,resizable=no,scrollbars=yes,resize=no,menubar=yes,location=no,directories=no';
		window.open(nombre,'',dat)
	}

	function round(number,X) {
		X = (!X ? 2 : X);
		return Math.round(number*Math.pow(10,X))/Math.pow(10,X);
	}

	function Alternar(seccion){
	
		divActual = document.getElementById(seccion);
	
		if (divActual.style.display=="none"){divActual.style.display=""}
		else{divActual.style.display="none"}
	}

	function cambiaColor(row,color){		
		row.setAttribute("bgcolor", color, 0);
	}
	
	
	function obtenerValorDeOption(ctrl){
	    for(i=0;i<ctrl.length;i++)
			if(ctrl[i].checked) return ctrl[i].value;
	}


	function obtenerListaId(nameArrCheck){
	
		arrCheck= document.getElementsByName(nameArrCheck);
	
		listaValores = "";
		esElPrimero = true;
	
		for (var i=0;i < arrCheck.length;i++){		
			var elemento = arrCheck[i];
			if (elemento.checked==true){
				if (esElPrimero){
					listaValores += elemento.value; 
					esElPrimero=false;
				}
				else{
					listaValores += "," + elemento.value; 
				}
			}
		}
		return listaValores;
	}

	function chequearTodos(nameArrCheck, valor){
		arrCheck= document.getElementsByName(nameArrCheck);
		for (var i=0;i < arrCheck.length;i++){		
			var elemento = arrCheck[i];
			elemento.checked = valor;
		}
	}

	// Mensajes de ayuda

	if(navigator.userAgent.indexOf("MSIE")>=0) navegador=0;
	else navegador=1;

	function colocaAyuda(event){
		if(navegador==0){
			var corX=window.event.clientX+document.documentElement.scrollLeft;
			var corY=window.event.clientY+document.documentElement.scrollTop;
		}
		else{
			var corX=event.clientX+window.scrollX;
			var corY=event.clientY+window.scrollY;
		}
		
		cAyuda.style.top=corY+20+"px";
		cAyuda.style.left=corX+15+"px";
	}
	
	function ocultaAyuda(){
		
		cAyuda=document.getElementById("mensajesAyuda");
		cNombre=document.getElementById("ayudaTitulo");
		cTex=document.getElementById("ayudaTexto");
		cAyuda.style.display="none";
	
		if(navegador==0) {
			document.detachEvent("onmousemove", colocaAyuda);
			document.detachEvent("onmouseout", ocultaAyuda);
		}
		else {
			document.removeEventListener("mousemove", colocaAyuda, true);
			document.removeEventListener("mouseout", ocultaAyuda, true);
		}
	}	

	function muestraAyuda(event, campo){
		cAyuda=document.getElementById("mensajesAyuda");
		cNombre=document.getElementById("ayudaTitulo");
		cTex=document.getElementById("ayudaTexto");
	
		colocaAyuda(event);
	
		if(navegador==0) { 
			document.attachEvent("onmousemove", colocaAyuda); 
			document.attachEvent("onmouseout", ocultaAyuda); 
		}
		else {
			document.addEventListener("mousemove", colocaAyuda, true);
			document.addEventListener("mouseout", ocultaAyuda, true);
		}
		
		cNombre.innerHTML="N&uacute;mero de Solicitud";
		cTex.innerHTML="Se genera autom&aacute;ticamente cuando se graba el vi&aacute;tico";
		cAyuda.style.display="block";
	}
	
	function consultaSelCheque(campoRetorno) {
		url = "../bancos/queryCheques.php?funcion=1&campoRetorno="+campoRetorno;
		abrirpopup(url,700,550); // Está en funciones js de Secretaria/general
	}

	/**************************************************************
					FUNCIONES PARA CONTROL DE FECHAS
	**************************************************************/
	function esDigito(sChr){
		var sCod = sChr.charCodeAt(0);
		return ((sCod > 47) && (sCod < 58));
	}

	function valSep(oTxt){
		var bOk = false;
		// bOk = bOk || ((oTxt.value.charAt(2) == "-") && (oTxt.value.charAt(5) == "-"));
		bOk = bOk || ((oTxt.value.charAt(2) == "/") && (oTxt.value.charAt(5) == "/"));
		return bOk;
	}
	
	function finMes(oTxt){
		var nMes = parseInt(oTxt.value.substr(3, 2), 10);
		var nRes = 0;
		//incluir mes bisiesto
		switch (nMes){
			case 1: nRes = 31; break;
			case 2: nRes = 29; break;
			case 3: nRes = 31; break;
			case 4: nRes = 30; break;
			case 5: nRes = 31; break;
			case 6: nRes = 30; break;
			case 7: nRes = 31; break;
			case 8: nRes = 31; break;
			case 9: nRes = 30; break;
			case 10: nRes = 31; break;
			case 11: nRes = 30; break;
			case 12: nRes = 31; break;
		}
		
		return nRes;
	}
	
	function valDia(oTxt){
		var bOk = false;
		var nDia = parseInt(oTxt.value.substr(0, 2), 10);
		bOk = bOk || ((nDia >= 1) && (nDia <= finMes(oTxt)));
		return bOk;
	}
	
	function valMes(oTxt){
		var bOk = false;
		var nMes = parseInt(oTxt.value.substr(3, 2), 10);
		bOk = bOk || ((nMes >= 1) && (nMes <= 12));
		return bOk;
	}
	
	function valAno(oTxt){
		var bOk = true;
		var nAno = oTxt.value.substr(6);
		bOk = bOk && (nAno.length == 4) && (nAno > 2000);
		if (bOk){
			for (var i = 0; i < nAno.length; i++){
				bOk = bOk && esDigito(nAno.charAt(i));
			}
		}
		return bOk;
	}

	function valFecha(oTxt){ // se le pasa el objeto como parametro
		var bOk = true;
		if (oTxt.value != ""){
			bOk = bOk && (valAno(oTxt));
			bOk = bOk && (valMes(oTxt));
			bOk = bOk && (valDia(oTxt));
			bOk = bOk && (valSep(oTxt));

			return bOk;
		}
		else return false;
	}
	
	/**************************************************************
					FUNCIONES PARA CONTROL DE HORAS
	**************************************************************/

	function valSepHorario(oTxt){
		var bOk = false;
		bOk = bOk || (oTxt.value.charAt(2) == ":");
		return bOk;
	}

	function valHora(oTxt){
		var bOk = false;
		var hora = parseInt(oTxt.value.substr(0, 2), 10);
		bOk = bOk || ((hora >= 0) && (hora <= 23));
		return bOk;
	}

	function valMinuto(oTxt){
		var bOk = false;
		var minuto= parseInt(oTxt.value.substr(3, 2), 10);
		bOk = bOk || ((minuto >= 0) && (minuto <= 59));
		return bOk;
	}
	
	function valHorario(oTxt){ // se le pasa el objeto como parametro
		var bOk = (oTxt.value.length == 5);
		if (oTxt.value != ""){
			bOk = bOk && (valHora(oTxt));
			bOk = bOk && (valMinuto(oTxt));
			bOk = bOk && (valSepHorario(oTxt));
			return bOk;
		}
		else return false;
	}
	
	
function cambiarEstilo(objeto, estilo){
	objeto.className = estilo;
}

function disminuir(text){

	if ((isNaN(text.value)) || (text.value==1) || (text.value=="")){ //si no es un numero
		text.value=1;	
	}
	else{
		text.value= parseInt(text.value)-1;
	}
}

function aumentar(text){

	if (isNaN(text.value) || (text.value=="")){ //si no es un numero
		text.value=1;	
	}
	else{
		text.value= parseInt(text.value)+1;
	}
}


function validaHora(timeStr) {

	var timePat = /^(\d{1,2}):(\d{2})(:(\d{2}))$/;

	var matchArray = timeStr.match(timePat);
	
	if (matchArray == null) {
		return false;
	}
	
	hour = matchArray[1];
	minute = matchArray[2];
	second = matchArray[4];

	if (second=="") { second = null; }

	if (hour < 0  || hour > 23) {
		//alert("Entre 0 y 24");
		return false;
	}
	
	if (minute<0 || minute > 59) {
		//alert ("Minute must be between 0 and 59.");
		return false;
	}
	
	if (second != null && (second < 0 || second > 59)) {
		//alert ("Second must be between 0 and 59.");
		return false;
	}
	
	return true;
}

function validaTime(time) { // format time= hh:mm:ss:cc
	
	if (time.length != 10){
		return false;
	}
	else{
		hora = time.split(".");
		
		if ((!validaHora(hora[0])) || (hora[1].length !=1)) { // si la hora no es valida o las centesimas tampoco
			return false;
		}
		else return true;
	}	
}

function siguiente(campo,e){
	var tcl = (document.all)?event.keyCode:e.which;
   		if (tcl==13){
   			$(campo).focus();
		}
}

function completaHora(objHora){
	hora="00:00:00";
	desde = objHora.value.length;
	objHora.value = objHora.value + hora.substring(desde);
}

function completaTime(objHora){
	hora="00:00:00.0";
	desde = objHora.value.length;
	objHora.value = objHora.value + hora.substring(desde);
}

function penaliza(chk, text){

	if (chk.checked){
		$(text).disabled = false;
		$(text).value = "";
	}
	else {
		$(text).disabled = true;
		$(text).value = "00:00:00";
	}
}
