﻿// JavaScript Document
// VALIDACIONES DE LOS FORMULARIOS DE PMU
var validaFormato	= new RegExp("^([0-9](?:.[0-9]{3})*)+(?:,[0-9]{1}){0,1}$");
var validaEntero 	= new RegExp("^[0-9]+$");
var validaAnio 		= new RegExp("^[0-9]{4}$");
var validaNumero 	= new RegExp("^[0-9]{4}$");
var validaMes 		= new RegExp("^0[0-9]|1[012]$");
var validaDia 		= new RegExp("^0[1-9]|[12][0-9]|3[01]$");
//var validaReal	= new RegExp("^[0-9]+(?:.[0-9]){0,1}$"); 
//var validaReal	= new RegExp("^[0-9]+((?:.[0-9]){0,1}|(?:,[0-9]){0,1})$");
var validaRealDosDecimales	= new RegExp("^[0-9]+((?:.([0-9]{2})){0,1}|(?:,([0-9]{2})){0,1})$");
var validaRealDos	= new RegExp("^[0-9]+((?:.([0-9]{1,2})){0,1}|(?:,([0-9]{1,2})){0,1})$");

var validaReal = new RegExp("^[0-9]+((?:.([0-9])){0,1}|(?:,([0-9])){0,1})$");
var validaCaracter 	= new RegExp("^[a-zA-Z]{1}$");


var ValidacionAdmin = {
	formateaDecimal : function ( campo, cantDecimales, mensaje ) {
		var tieneComas = false;
		if ( campo.value.indexOf( "," ) != -1 ) {
			reComa = /,/gi
			rePunto = /\./gi
			tieneComas = true;
			campo.value = campo.value.replace( reComa, "." );
		}
		if ( isNaN( parseFloat( campo.value ) ) ) {
			return fnG.alerta( mensaje, campo );
		} else {
			campo.focus();
			campo.value = parseFloat( campo.value );
			var numFormatear = new NumberFormat( campo.value );
			numFormatear.setCurrency( false );
			numFormatear.setCommas( false );
			numFormatear.setPlaces( cantDecimales );
			campo.value = numFormatear.toFormatted();
			if ( tieneComas ) {
				campo.value = campo.value.replace( rePunto, "," );
			}
		}
		return true;
	},
	
	validaLogin : function () {
		if (fnG.trim($("usuario").value) == ""){
			return fnG.alerta("Favor ingrese su Cuenta de Usuario.",$("usuario"));
		}
		
		if (fnG.trim($("clave").value) == ""){
			return fnG.alerta("Favor ingrese su Password.",$("clave"));
		}

		return true;
	},
	
	validaFormContacto : function(){

		if (fnG.trim($("nombre").value) == ""){
			return fnG.alerta("Favor ingrese su Nombre.",$("nombre"));
		}
			
		if (fnG.trim($("direccion").value) == ""){
			return fnG.alerta("Favor ingrese su Dirección.",$("direccion"));
		}

		if (fnG.trim($("telefono").value) == ""){
			return fnG.alerta("Favor ingrese su Telefono.",$("telefono"));
		}

		if (fnG.trim($("email").value) == ""){
			return fnG.alerta("Favor ingrese su Email.",$("email"));
		}

		if ( !fnG.esEmail($("email").value) ){
			return fnG.alerta("Favor ingrese un Email Valido.",$("email"));
		}

		return true;

	},
	
	
	validaNuevoProyecto: function () {
		var nombreForm 		= 'document.formulario';
		with ( eval( nombreForm ) ) {

			/* identificacion */
			fnG.borraEspacios( nombreForm );
			try {
			if (pmutxtsubprograma.value == '')
				return fnG.alerta( "Favor ingrese un Sub-programa.", pmutxtsubprograma );
			} catch (e) {
			}
			if (txtnombre.value == '')
				return fnG.alerta( "Favor ingrese el nombre del Proyecto.", txtnombre );
			if (cmbtipo.value == '')
				return fnG.alerta( "Favor ingrese una Tipología.", cmbtipo );
			if (txtpoblacion.value == '')
				return fnG.alerta( "Favor ingrese Población o Sector", txtpoblacion );
			if (txtcoordx.value=='')
				return fnG.alerta("Favor ingrese el valor de la Coordenada X.", txtcoordx);				
			if (!validaEntero.test(txtcoordx.value))
				return fnG.alerta("El valor de la Coordenada X debe ser un número entero.", txtcoordx);
			if (txtcoordy.value=='')
				return fnG.alerta("Favor ingrese el valor de la Coordenada Y.", txtcoordy);
			if (!validaEntero.test(txtcoordy.value))
				return fnG.alerta("El valor de la coordenada Y debe ser un número entero.", txtcoordy);
				
			/* area */
			if (pmucmbregion.value=='')
				return fnG.alerta("Favor seleccione una Región.", pmucmbregion);
			if (pmucmbprovincia.value=='')
				return fnG.alerta("Favor seleccione una Provincia.", pmucmbprovincia);
			if (pmucmbcomuna.value=='')
				return fnG.alerta("Favor seleccione una Comuna.", pmucmbcomuna);
			if (txtunidad.value=='')
				return fnG.alerta("Favor ingrese una Unidad Vecinal o Localidad.", txtunidad);
				
			/* cobertura */
			if (txtnumempleadosh.value=="")
				return fnG.alerta("Favor ingrese el Número de Empleos Programados para Hombres.", txtnumempleadosh);
			if (!validaEntero.test(txtnumempleadosh.value))
				return fnG.alerta("El Número de Empleos Programados para Hombres debe ser un número entero.", txtnumempleadosh);
			if (txtnumempleadosm.value=="")
				return fnG.alerta("Favor ingrese el Número de Empleos Programados para Mujeres.", txtnumempleadosm);
			if (!validaEntero.test(txtnumempleadosm.value))
				return fnG.alerta("El Número de Empleos Programados para Mujeres debe ser un número entero.", txtnumempleadosm);
			if (txthabitantesunidad.value=="")
				return fnG.alerta("Favor ingrese el Número de Habitantes de la Unidad Vecinal o Localidad.", txthabitantesunidad);
			if (!validaEntero.test(txthabitantesunidad.value))
				return fnG.alerta("El Número de Habitantes de la Unidad Vecinal o Localidad debe ser un número entero.", txthabitantesunidad);
			if (txthabitanteshombres.value=="")
				return fnG.alerta("Favor ingrese el Número de Habitantes Hombres Beneficiados.", txthabitanteshombres);
			if (!validaEntero.test(txthabitanteshombres.value))
				return fnG.alerta("El Número de Habitantes Hombres Beneficiados debe ser un número entero.", txthabitanteshombres);
			if (txthabitantesmujeres.value=="")
				return fnG.alerta("Favor ingrese el Número de Habitantes Mujeres Beneficiadas.", txthabitantesmujeres);
			if (!validaEntero.test(txthabitantesmujeres.value))
				return fnG.alerta("El Número de Habitantes Mujeres Beneficiadas debe ser un número entero.", txthabitantesmujeres);
				
			/* financiamiento */
			if (txtmontosubdere.value=="")
				return fnG.alerta("Favor ingrese el Monto Solicitado a SUBDERE.", txtmontosubdere);
			if (!validaReal.test(txtmontosubdere.value)) {
				//return PMU.formateaDecimal( txtmontosubdere, 1, "El Monto Solicitado a SUBDERE debe ser un número válido." );
				if ( !PMU.formateaDecimal( txtmontosubdere, 1, "El Monto Solicitado a SUBDERE debe ser un número válido." ) ) {
					return false;
				}
			}
			
			if (txtaportemunicipal.value=="")
				return fnG.alerta("Favor ingrese el Monto Aporte Municipal.", txtaportemunicipal);
			if (!validaReal.test(txtaportemunicipal.value)) {
				if ( !PMU.formateaDecimal( txtaportemunicipal, 1, "El Monto Aporte Municipal debe ser un número válido." ) ) {
					return false;
				}
			}
			if (txtaporteterceros.value!="") {
				if (!validaReal.test(txtaporteterceros.value)) {
					if ( !PMU.formateaDecimal( txtaporteterceros, 1, "El Monto Aporte Terceros debe ser un número válido." ) ) {
						return false;
					}
				}
			}
			
			if (txtinversion.value=="")
			{	return fnG.alerta("Favor ingrese el porcentaje de inversión utilizada en mano de obra", txtinversion);}
			if ( !validaReal.test( txtinversion.value ) ) {
				if ( !PMU.formateaDecimal( txtinversion, 1, "El porcentaje de inversión utilizada en mano de obra debe ser un número válido." ) ) {
					return false;
				}
			}
			if (  parseFloat( $('txtinversion').value.replace( ',', "." ), 10 ) < 0.0 || parseFloat( $('txtinversion').value.replace( ',', "." ), 10 ) > 100.0 ) {
				return fnG.alerta( "El Porcentaje debe ser entre 0 y 100", txtinversion );
			}
				
			/* periodo */
			if (txtnumeromeses.value=="")
				return fnG.alerta("Favor ingrese el Número de Meses Ejecución.", txtnumeromeses);
			if (!validaEntero.test(txtnumeromeses.value))
				return fnG.alerta("El Número de Meses debe ser un número entero.", txtnumeromeses);
			if (txtnumeroetapas.value=="")
				return fnG.alerta("Favor ingrese el Número de Etapas.", txtnumeroetapas);
			if (!validaEntero.test(txtnumeroetapas.value))
				return fnG.alerta("El Número de Etapas debe ser un número entero.", txtnumeroetapas);
				
			if (pmutxtdiaini.value=="dd")
				pmutxtdiaini.value= "";
			if (pmutxtmesini.value=="mm")
				pmutxtmesini.value= "";
			if (pmutxtanioini.value=="aaaa")
				pmutxtanioini.value= "";
			if (pmutxtdiafin.value=="dd")
				pmutxtdiafin.value= "";
			if (pmutxtmesfin.value=="mm")
				pmutxtmesfin.value= "";
			if (pmutxtaniofin.value=="aaaa")
				pmutxtaniofin.value= "";
				

			if (pmutxtdiaini.value!='' && !isNaN(pmutxtdiaini.value) ) {
				pmutxtdiaini.value = pmutxtdiaini.value.pad( 2, "0", 0 );
			}
			if (pmutxtmesini.value!='' && !isNaN(pmutxtmesini.value) ) {
				pmutxtmesini.value = pmutxtmesini.value.pad( 2, "0", 0 );
			}
			if (pmutxtanioini.value!='' && !isNaN(pmutxtanioini.value) ) {
				pmutxtanioini.value = pmutxtanioini.value.pad( 4, "0", 0 );
			}
			
			if (pmutxtdiafin.value!='' && !isNaN(pmutxtdiafin.value) ) {
				pmutxtdiafin.value = pmutxtdiafin.value.pad( 2, "0", 0 );
			}
			if (pmutxtmesfin.value!='' && !isNaN(pmutxtmesfin.value) ) {
				pmutxtmesfin.value = pmutxtmesfin.value.pad( 2, "0", 0 );
			}
			if (pmutxtaniofin.value!='' && !isNaN(pmutxtaniofin.value) ) {
				pmutxtaniofin.value = pmutxtaniofin.value.pad( 4, "0", 0 );
			}
				
			if (!validaDia.test(pmutxtdiaini.value)) {
				return fnG.alerta("La fecha correspondiente al Día va entre 1 y 31.", pmutxtdiaini);
			}
			if (!validaMes.test(pmutxtmesini.value))
				return fnG.alerta("La fecha correspondiente al Mes va entre 1 y 12.", pmutxtmesini);
			if (!validaAnio.test(pmutxtanioini.value))
				return fnG.alerta("La fecha correspondiente al Año debe ser de 4 dígitos.", pmutxtanioini);
			anioIn = parseInt(pmutxtanioini.value,10)
			if ( anioIn < 1900 )
				return fnG.alerta("Favor ingrese una fecha válida para el Año,\n debe ser mayor o igual a 1900.", pmutxtanioini);
				
			if (!validaDia.test(pmutxtdiafin.value))
				return fnG.alerta("La fecha correspondiente al Día va entre 1 y 31.", pmutxtdiafin);
			if (!validaMes.test(pmutxtmesfin.value))
				return fnG.alerta("La fecha correspondiente al Mes va entre 1 y 12.", pmutxtmesfin);
			if (!validaAnio.test(pmutxtaniofin.value))
				return fnG.alerta("La fecha correspondiente al Año debe ser de 4 dígitos.", pmutxtaniofin);
			anioFin2 = parseInt(pmutxtaniofin.value,10)
			if ( anioFin2 < 1900 )
				return fnG.alerta("Favor ingrese una fecha válida para el Año,\n debe ser mayor  o igual a 1900.", pmutxtaniofin);

			if (pmutxtdiaini.value!="" && pmutxtmesini.value!="" && pmutxtanioini.value!="" && fnG.esFecha(pmutxtanioini.value,pmutxtmesini.value,pmutxtdiaini.value)!=0)
				return fnG.alerta(fnG.obtFechaMensaje(fnG.esFecha(pmutxtanioini.value,pmutxtmesini.value,pmutxtdiaini.value)), pmutxtdiaini);
			if (pmutxtdiafin.value!="" && pmutxtmesfin.value!="" && pmutxtaniofin.value!="" && fnG.esFecha(pmutxtaniofin.value,pmutxtmesfin.value,pmutxtdiafin.value)!=0)
				return fnG.alerta(fnG.obtFechaMensaje(fnG.esFecha(pmutxtaniofin.value,pmutxtmesfin.value,pmutxtdiafin.value)), pmutxtdiafin);

			if (pmutxtdiaini.value!="" && pmutxtmesini.value!="" && pmutxtanioini.value!="" && pmutxtdiafin.value!="" && pmutxtmesfin.value!="" && pmutxtaniofin.value!="" && fnG.fechaMayor(pmutxtdiaini.value, pmutxtmesini.value, pmutxtanioini.value, pmutxtdiafin.value, pmutxtmesfin.value, pmutxtaniofin.value))
				return fnG.alerta("La fecha inicial no puede ser mayor a la fecha final.", pmutxtdiaini);

			/* antecedentes del proyecto */
			if (txtcantidadobra.value=="")
				return fnG.alerta("Favor ingrese la Cantidad de Obra.", txtcantidadobra);
			if (!validaEntero.test(txtcantidadobra.value))
				return fnG.alerta("La Cantidad de Obra debe ser un valor numérico.", txtcantidadobra);
			if (cmbunidad.value=='')
				return fnG.alerta("Debe seleccionar la unidad.", cmbunidad);
			if (cmbmodalidad.value=='')
				return fnG.alerta("Debe seleccionar una modalidad de ejecución.", cmbmodalidad);
			if (txtjustificacion.value=="")
				return fnG.alerta("Favor ingrese una Justificación.", txtjustificacion);
			if (txtdescripcion.value=="")
				return fnG.alerta("Favor ingrese una Descripción.", txtdescripcion);

			if ( fnG.trim( $('txtdesempleoregional').value ) == '' ) {
				return fnG.alerta( 'Favor ingrese el Indice de Desempleo Regional.', $('txtdesempleoregional') );
			}
			if ( !validaReal.test( $('txtdesempleoregional').value ) ) {
				if ( !PMU.formateaDecimal( $('txtdesempleoregional'), 1, "El Indice de Desempleo Regional debe ser un número válido." ) ) {
					return false;
				}
			}
			var indiceR = parseFloat( $('txtdesempleoregional').value.replace( ',', "." ), 10 );
			if ( indiceR < 0.0 || indiceR > 100.0 ) {
				return fnG.alerta( 'Favor ingrese un Porcentaje válido.', $('txtdesempleoregional') );
			}
			if ( fnG.trim( $('txtdesempleocomunal').value ) == '' ) {
				return fnG.alerta( 'Favor ingrese Indice de Desempleo Comunal.', $('txtdesempleocomunal') );
			}
			if ( !validaReal.test( $('txtdesempleocomunal').value ) ) {
				if ( !PMU.formateaDecimal( $('txtdesempleocomunal'), 1, "El Indice de Desempleo Comunal debe ser un número válido." ) ) {
					return false;
				}
			}
			var indiceC = parseFloat( $('txtdesempleocomunal').value.replace(',', "."),10);
			if ( indiceC < 0.0 || indiceC > 100.0 ) {
				return fnG.alerta( 'Favor ingrese un Porcentaje válido.', $('txtdesempleocomunal') );
			}
		
			if (txtrankingcomunal.value!="" && !validaReal.test(txtrankingcomunal.value)) {
				if ( !PMU.formateaDecimal( txtrankingcomunal, 1, "El Ranking Déficit Infraestructura Comunal debe ser un número válido." ) ) {
					return false;
				}
			}
			
			if (txtrankingpobre.value!="" && !validaReal.test(txtrankingpobre.value)) {
				if ( !PMU.formateaDecimal( txtrankingpobre, 1, "El Ranking Comuna Pobre debe ser un número válido." ) ) {
					return false;
				}
			}

			if (txtencargado.value =="")
				return fnG.alerta("Favor ingrese el Encargado Municipal.", txtencargado);
			if (txtdireccion.value=="")
				return fnG.alerta("Favor ingrese una Direccion.", txtdireccion);
			
			if (txttelefono.value=='')
				return fnG.alerta("Favor ingrese un Número Telefónico.", txttelefono);							
			
			if (txtcuentacorriente.value=='')
				return fnG.alerta("Favor ingrese una Cuenta Corriente.", txtcuentacorriente);
				
			if (cmbbanco.value=='')
				return fnG.alerta("Favor ingrese un Banco.", cmbbanco);
				
				
			return true;
		}

	},
	validaNuevosDocumentos: function() {
		total = $('contadorArchivos').value;
		if ($('edicionArchivos')==0) {
			for (var i=0;i<=total;i++) {
				try	{
					if (fnG.trim($('archivoAdjunto'+i).value) == "" )
						return fnG.alerta("Favor adjunte archivo.", $('archivoAdjunto'+i));
				} catch (e) {
				}
			}
		}
		return true;
	},
	
	validaNuevasImagenes: function () {
		total = $('contadorArchivos').value;
		for ( var i = 0; i <= total; i++ ) {
			try	{
				if ( fnG.trim( $('archivoAdjunto' + i).value ) != "" && fnG.trim( $('descripcion' + i).value ) == '' ) {
					return fnG.alerta( "Favor ingrese una Descripción.", $('descripcion' + i) );
				}
			} catch ( e ) {
			}
		}
		if ( $('archivosExistentes').value == 0 ) {
			if ( fnG.trim( $('descripcion1').value ) == "" && fnG.trim( $('archivoAdjunto1').value ) == "" ) {
				return fnG.alerta( "Favor seleccione una Fotografía para Guardar.", $('descripcion1') );
			}
		}
		return true;
	},
	validaComentario: function() {
		if (fnG.trim($('comentarios').value) == "")
			return fnG.alerta("Favor ingrese un Comentario.", $('comentarios'));
		return true;	
	},
	validaVisado: function() {
		tipo = $('opcionClick').value;
		if (tipo=='AP') {
			var validaEntero 	= new RegExp("^[0-9]+$");
			
			if (fnG.trim($('oficioaprobacion').value)=="")
				return fnG.alerta('Favor ingrese un Oficio.',$('oficioaprobacion'));
				
				
			if ($('diaoficio').value!='' && !isNaN($('diaoficio').value) ) {
				$('diaoficio').value = $('diaoficio').value.pad( 2, "0", 0 );
			}
			if ($('mesoficio').value!='' && !isNaN($('mesoficio').value) ) {
				$('mesoficio').value = $('mesoficio').value.pad( 2, "0", 0 );
			}
			if ($('anooficio').value!='' && !isNaN($('anooficio').value) ) {
				$('anooficio').value = $('anooficio').value.pad( 4, "0", 0 );
			}

				
			if (fnG.trim($('diaoficio').value)=='')
				return fnG.alerta('Favor ingrese un Día.',$('diaoficio'));
			if (!validaEntero.test($('diaoficio').value))
				return fnG.alerta('Debe ingresar un valor numérico.',$('diaoficio'));
			if (fnG.trim($('mesoficio').value)=='')
				return fnG.alerta('Favor ingrese un Mes',$('mesoficio'));
			if (!validaEntero.test($('mesoficio').value))
				return fnG.alerta('Debe ingresar un valor numérico.',$('mesoficio'));
			if (fnG.trim($('anooficio').value)=='')
				return fnG.alerta('Favor ingrese un Año.',$('anooficio'));
			if (!validaEntero.test($('anooficio').value))
				return fnG.alerta('Debe ingresar un valor numérico.',$('anooficio'));
			anioV = parseInt(fnG.trim($('anooficio').value,10));
			if ( anioV < 1900 ){
				return fnG.alerta("Favor ingrese una fecha válida para el Año, \n debe ser mayor a 1900.", $('anooficio'));
			}
			if (fnG.esFecha($('anooficio').value,$('mesoficio').value,$('diaoficio').value))
				return fnG.alerta('La Fecha ingresada no es válida.',$('diaoficio'));
				
				
			if (fnG.trim($('txtcomentario').value)=='')
				return fnG.alerta('Favor ingrese un Comentario.',$('txtcomentario'));
			if (fnG.trim($('archivoAdjunto').value)=='')
				return fnG.alerta('Favor adjunte un Archivo.',$('archivoAdjunto'));
			return true;		
		}
		
		if (tipo=='RE') {
			if (fnG.trim($('txtcomentario').value)=='')
				return fnG.alerta('Favor ingrese un Comentario.',$('txtcomentario'));
			return true;
		}
		
		return false;		
	},
	
	validaAprobado: function() {
		tipo = $('opcionClick').value;
		if ( tipo == 'AP' ) {
			var validaEntero = new RegExp( "^[0-9]+$" );
			if ( fnG.trim( $('oficioaprobacion').value ) == "" ) {
				return fnG.alerta( 'Favor ingrese un Oficio.', $('oficioaprobacion') );
			}
			
			if ($('diaoficio').value!='' && !isNaN($('diaoficio').value) ) {
				$('diaoficio').value = $('diaoficio').value.pad( 2, "0", 0 );
			}
			if ($('mesoficio').value!='' && !isNaN($('mesoficio').value) ) {
				$('mesoficio').value = $('mesoficio').value.pad( 2, "0", 0 );
			}
			if ($('anooficio').value!='' && !isNaN($('anooficio').value) ) {
				$('anooficio').value = $('anooficio').value.pad( 4, "0", 0 );
			}
			
			
			if ( fnG.trim( $('diaoficio').value ) == '' ) {
				return fnG.alerta( 'Favor ingrese un Día.', $('diaoficio') );
			}
			if ( !validaEntero.test( $('diaoficio').value ) ) {
				return fnG.alerta( 'Debe ingresar un valor numérico.', $('diaoficio') );
			}
			if ( fnG.trim( $('mesoficio').value ) == '' ) {
				return fnG.alerta( 'Favor ingrese un Mes.', $('mesoficio') );
			}
			if ( !validaEntero.test( $('mesoficio').value ) ) {
				return fnG.alerta( 'Debe ingresar un valor numérico.', $('mesoficio') );
			}
			if ( fnG.trim( $('anooficio').value ) == '' ) {
				return fnG.alerta( 'Favor ingrese un Año.', $('anooficio') );
			}
			if ( !validaEntero.test( $('anooficio').value) ) {
				return fnG.alerta( 'Debe ingresar un valor numérico.', $('anooficio') );
			}

			anioOf = parseInt( fnG.trim( $('anooficio').value,10 ) );
			if ( anioOf < 1900 ) {
				return fnG.alerta( "Favor ingrese una fecha válida para el Año, \n debe ser mayor a 1900.", $('anooficio') );
			}
			
			if ( fnG.esFecha( $('anooficio').value, $('mesoficio').value, $('diaoficio').value ) ) {
				return fnG.alerta( 'La Fecha ingresada no es válida.', $('diaoficio') );
			}
			if ( fnG.trim( $('montoAprobado').value ) == '' ) {
				return fnG.alerta( 'Favor ingrese un Monto de Aprobación.', $('montoAprobado') );
			}
			if ( !validaReal.test( $('montoAprobado').value ) ) {
				if ( !PMU.formateaDecimal( $('montoAprobado'), 1, "El Monto de Aprobación debe ser un número válido." ) ) {
					return false;
				}
			}
			if ( parseFloat( $('montoAprobado').value ) > parseFloat( $('montoSolicitado').value ) ) {
				//return fnG.alerta( 'El Monto Aprobado ' + $('montoAprobado').value + ' debe ser menor o igual al Monto Solicitado ' + $('montoSolicitado').value + ' .', $('montoAprobado') );
				return fnG.alerta( 'El Monto Aprobado debe ser menor o igual al Monto Solicitado.', $('montoAprobado') );
			}
			if ( fnG.trim( $('txtcomentario').value ) == '' ) {
				return fnG.alerta( 'Favor ingrese un Comentario.', $('txtcomentario') );
			}
			if ( fnG.trim( $('archivoAdjunto').value ) == '' ) {
				return fnG.alerta( 'Favor adjunte un Archivo.', $('archivoAdjunto') );
			}
			return true;		
		}
		
		if (tipo=='RE') {
			if (fnG.trim($('txtcomentario').value)=='')
				return fnG.alerta('Favor ingrese un Comentario.',$('txtcomentario'));
			return true;
		}
		
		return false;		
	},
	
	GiroNuevo: function() {

		var i;

		if (fnG.trim($('subprograma').value)=="")
			return fnG.alerta('Favor seleccione un SubPrograma.',$('subprograma'));

		if (fnG.trim($('anio').value)=='')
			return fnG.alerta('Favor seleccione un Año.',$('anio'));

		if (fnG.trim($('proyecto').value)=='')
			return fnG.alerta('Favor seleccione un Proyecto.',$('proyecto'));

		if (fnG.trim($('decreto_alcaldicio').value)=='')
			return fnG.alerta('Favor seleccione un Decreto Alcaldicio.',$('decreto_alcaldicio'));

		if (fnG.trim($('mo_mes').value)=='0')
			return fnG.alerta('Favor seleccione un Mes de la Mano de Obra.',$('mo_mes'));

		if (fnG.trim($('mo_monto').value)=='')
			return fnG.alerta('Favor seleccione un Monto de la Mano de Obra.',$('mo_monto'));

		if (fnG.trim($('TotalRemesaMes').value) <= 0)
			return fnG.alerta('El Valor de la Remesa del Mes debe ser mayor a Cero.',$('mo_monto'));


		// validacion de rut de las cajas de texto
		for(i = 1 ; i <= 10 ; i ++){
			StrRut	= eval('$("rut_' + i + '")');
			StrDv	= eval('$("dv_' + i + '")');

			try{
				if (StrRut.value != ""){
					if (validar_rut( StrRut.value , StrDv.value ) == false){
						return fnG.alerta('Favor ingrese un RUT válido.' , StrRut);
					}
				}
			}catch(e){
			}
		}
		
		return true;
	},

	validaGiroAprobar: function() {

		if ( !validaEntero.test( $('Nro_remesa').value ) ) {
			return fnG.alerta( 'El valor del Número de Remesa debe ser un número entero.', $('Nro_remesa') );
		}
		if ( parseFloat( $('monto').value ) <= 0.0 ) {
			return fnG.alerta( 'El valor del Monto debe ser Mayor que Cero.', $('monto') );
		}

		if ( !validaRealDos.test( $('monto').value) ) {
			if ( !PMU.formateaDecimal( $('monto'), 2, "Favor ingrese un número válido para Monto." ) ) {
				return false;
			}
		}
		return true;
	},

	validaGiroRechazo: function() {

		if ($('comentarios').value.length == 0){
			return fnG.alerta('Favor ingrese un Comentario.',$('comentarios'));
		}
		return true;
	},

	validaAprobacion: function() {
		if ($('comentarios').value.length == 0){
			return fnG.alerta('Favor ingrese un Comentario.',$('comentarios'));
		}
		return true;
	},
	
	validaArrastre: function() {
		if ( !cBx.hayCheckBoxSeleccionados( $('formListado'), 'checkbox' ) ) {
			return fnG.alerta( "Favor seleccione por lo menos un registro.", $('checkbox1') );
		}
		var proyectosMarcados = "";
		var proyectosDesMarcados = "";
		var separador = "";
		for ( i = 1; i <= cBx.cantidadCheckBox( $('formListado'), 'checkbox' ); i++ ) {
			if ( $('checkbox'+i).checked ) {
				separador = "#";
				if ( proyectosMarcados == "" ) {
					separador = "";
				}
				proyectosMarcados += separador + $('checkbox'+i).value;
			} else if ( $('marcaArrastreOriginal'+i).value != "" ) {
				separador = "#";
				if ( proyectosDesMarcados == "" ) {
					separador = "";
				}
				proyectosDesMarcados += separador + $('checkbox'+i).value;
			}
		}
		$('proyectosArrastreDesMarcados').value = proyectosDesMarcados;
		$('proyectosArrastre').value = proyectosMarcados;
		$('envioArrastre').value = 1;
		return true;
	},
	
	validaCierre: function() {
		if ( fnG.trim( $('txtGastosMateriales').value ) == "" ) {
			return fnG.alerta( 'Favor ingrese el Monto de los Gastos de Materiales.', $('txtGastosMateriales') );
		}
		if ( !validaRealDos.test( $('txtGastosMateriales').value ) ) {
			if ( !PMU.formateaDecimal( $('txtGastosMateriales'), 2, "El valor del Monto de los Gastos de Materiales debe ser un número válido." ) ) {
				return false;
			}
		}
		if ( fnG.trim( $('txtGastosMano').value ) == "" ) {
			return fnG.alerta( 'Favor ingrese el Monto de los Gastos de Mano de Obra.', $('txtGastosMano') );
		}
		if ( !validaRealDos.test( $('txtGastosMano').value ) ) {
			if ( !PMU.formateaDecimal( $('txtGastosMano'), 2, "El valor del Monto de los Gastos de Mano de Obra debe ser un número válido." ) ) {
				return false;
			}
		}
		
		
			if ($('pmutxtdiaini').value!='' && !isNaN($('pmutxtdiaini').value) ) {
				$('pmutxtdiaini').value = $('pmutxtdiaini').value.pad( 2, "0", 0 );
			}
			if ($('pmutxtmesini').value!='' && !isNaN($('pmutxtmesini').value) ) {
				$('pmutxtmesini').value = $('pmutxtmesini').value.pad( 2, "0", 0 );
			}
			if ($('pmutxtanioini').value!='' && !isNaN($('pmutxtanioini').value) ) {
				$('pmutxtanioini').value = $('pmutxtanioini').value.pad( 4, "0", 0 );
			}
			
			if ($('pmutxtdiafin').value!='' && !isNaN($('pmutxtdiafin').value) ) {
				$('pmutxtdiafin').value = $('pmutxtdiafin').value.pad( 2, "0", 0 );
			}
			if ($('pmutxtmesfin').value!='' && !isNaN($('pmutxtmesfin').value) ) {
				$('pmutxtmesfin').value = $('pmutxtmesfin').value.pad( 2, "0", 0 );
			}
			if ($('pmutxtaniofin').value!='' && !isNaN($('pmutxtaniofin').value) ) {
				$('pmutxtaniofin').value = $('pmutxtaniofin').value.pad( 4, "0", 0 );
			}
		
		
		if ( fnG.trim( $('pmutxtdiaini').value ) == "" ) {
			return fnG.alerta( 'Favor ingrese el Día del inicio.', $('pmutxtdiaini') );
		}
		if ( !validaDia.test( $('pmutxtdiaini').value ) ) {
			return fnG.alerta( 'El valor del Día debe ser entre 1 y 31.', $('pmutxtdiaini') );
		}
		if ( fnG.trim($('pmutxtmesini').value) == "" ) {
			return fnG.alerta( 'Favor ingrese el Mes del inicio.',$('pmutxtmesini') );
		}
		if ( !validaDia.test($('pmutxtmesini').value) ) {
			return fnG.alerta('El valor del Mes debe ser entre 1 y 12.',$('pmutxtmesini'));
		}
		if ( fnG.trim( $('pmutxtanioini').value ) == "" ) {
			return fnG.alerta('Favor ingrese el Año del inicio.',$('pmutxtanioini'));
		}
		if ( !validaAnio.test( $('pmutxtanioini').value ) ) {
			return fnG.alerta('El valor del Año debe ser de 4 dígitos.',$('pmutxtanioini'));
		}
		if (parseInt($('pmutxtanioini').value,10)<1900) {
			return fnG.alerta('El valor del Año debe ser de mayor a 1900.',$('pmutxtanioini'));
		}
		
		if ( fnG.esFecha( $('pmutxtanioini').value, $('pmutxtmesini').value, $('pmutxtdiaini').value != 0 ) ) {
			return fnG.alerta( fnG.obtFechaMensaje( fnG.esFecha( $('pmutxtanioini').value, $('pmutxtmesini').value, $('pmutxtdiaini').value) ), $('pmutxtdiaini') );		
		}
		
		
		if ( fnG.trim( $('pmutxtdiafin').value ) == "" ) {
			return fnG.alerta( 'Favor ingrese el Día del final.', $('pmutxtdiafin') );
		}
		if ( !validaDia.test( $('pmutxtdiafin').value ) ) {
			return fnG.alerta( 'El valor del Día inicial debe ser entre 1 y 31.', $('pmutxtdiafin') );
		}
		if ( fnG.trim($('pmutxtmesfin').value) == "" ) {
			return fnG.alerta( 'Favor ingrese el Mes del final.',$('pmutxtmesfin') );
		}
		if ( !validaDia.test($('pmutxtmesfin').value) ) {
			return fnG.alerta('El valor del Mes inicial debe ser entre 1 y 12.',$('pmutxtmesfin'));
		}
		if ( fnG.trim( $('pmutxtaniofin').value ) == "" ) {
			return fnG.alerta('Favor ingrese el Año final.',$('pmutxtaniofin'));
		}
		if ( !validaAnio.test( $('pmutxtaniofin').value ) ) {
			return fnG.alerta('El valor del Año inicial debe ser de 4 dígitos.',$('pmutxtaniofin'));
		}
		
		if (parseInt($('pmutxtaniofin').value,10)<1900) {
			return fnG.alerta('El valor del Año debe ser de mayor a 1900.',$('pmutxtaniofin'));
		}
		
		if ( fnG.esFecha( $('pmutxtaniofin').value, $('pmutxtmesfin').value, $('pmutxtdiafin').value != 0 ) ) {
			return fnG.alerta( fnG.obtFechaMensaje( fnG.esFecha( $('pmutxtaniofin').value, $('pmutxtmesfin').value, $('pmutxtdiafin').value) ), $('pmutxtdiafin') );		
		}
		
		
		if ( fnG.trim( $('programada').value ) == "" ) {
			return fnG.alerta( 'Favor ingrese la Cantidad de Mano de Obra Programada.',$('programada') );
		}
		if ( !validaEntero.test( $('programada').value ) ) {
			return fnG.alerta('La Cantidad de Mano de Obra Programada debe ser un número entero.',$('programada'));
		}
		if ( fnG.trim( $('efectiva').value ) == "" ) {
			return fnG.alerta('Favor ingrese la Cantidad de Mano de Obra Efectiva.',$('efectiva'));
		}
		if ( !validaEntero.test( $('efectiva').value ) ) {
			return fnG.alerta( 'La Cantidad de Mano de Obra Efectiva debe ser un número entero.',$('efectiva'));
		}
		if ( fnG.trim( $('txtsituacioninicio1').value ) == "" ) {
			return fnG.alerta( 'Favor ingrese la Descripción de la Situación.', $('txtsituacioninicio1') );
		}
		if ( fnG.trim( $('unidadinicio1').value ) == "" ) {
			return fnG.alerta('Favor ingrese la Unidad de la Situación.',$('unidadinicio1'));
		}
		if ( fnG.trim( $('txtcantidadinicio1').value ) == "" ) {
			return fnG.alerta( 'Favor ingrese la Cantidad de la Situación.', $('txtcantidadinicio1') );
		}
		if ( !validaRealDos.test( $('txtcantidadinicio1').value ) ) {
			if ( !PMU.formateaDecimal( $('txtcantidadinicio1'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
				return false;
			}
		}
		if ( fnG.trim( $('txtsituacioninicio2').value ) != "" ) {
			if ( fnG.trim( $('unidadinicio2').value ) == "" ) {
				return fnG.alerta( 'Favor ingrese la Unidad de la Situación.', $('unidadinicio2') );
			}
			if ( fnG.trim( $('txtcantidadinicio2').value ) == "" ) {
				return fnG.alerta( 'Favor ingrese la Cantidad de la Situación', $('txtcantidadinicio2') );
			}
			if ( !validaRealDos.test( $('txtcantidadinicio2').value ) ) {
				if ( !PMU.formateaDecimal( $('txtcantidadinicio2'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
					return false;
				}
			}
		}
			
		if ( fnG.trim($('txtsituacioninicio3').value ) != "" ) {
			if ( fnG.trim( $('unidadinicio3').value ) == "" ) {
				return fnG.alerta( 'Favor ingrese la Unidad de la Situación.', $('unidadinicio3') );
			}
			if ( fnG.trim( $('txtcantidadinicio3').value ) == "" ) {
				return fnG.alerta( 'Favor ingrese la Cantidad de la Situación.', $('txtcantidadinicio3') );
			}
			if ( !validaRealDos.test( $('txtcantidadinicio3').value ) ) {
				if ( !PMU.formateaDecimal( $('txtcantidadinicio3'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
					return false;
				}
			}
		}
			
		if (fnG.trim($('txtsituacionprogramada1').value) == "" )
			return fnG.alerta('Favor ingrese la Descripción de la Situación.',$('txtsituacionprogramada1'));
		if (fnG.trim($('unidadprogramada1').value) == "" )
			return fnG.alerta('Favor ingrese la Unidad de la Situación.',$('unidadprogramada1'));
		if (fnG.trim($('txtcantidadprogramada1').value) == "" )
			return fnG.alerta('Favor ingrese la Cantidad de la Situación.',$('txtcantidadprogramada1'));
		if ( !validaRealDos.test( $('txtcantidadprogramada1').value ) ) {
			if ( !PMU.formateaDecimal( $('txtcantidadprogramada1'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
				return false;
			}
		}
			
		if (fnG.trim($('txtsituacionprogramada2').value) != "" ){
			if (fnG.trim($('unidadprogramada2').value) == "" )
				return fnG.alerta('Favor ingrese la Unidad de la Situación.',$('unidadprogramada2'));
			if (fnG.trim($('txtcantidadprogramada2').value) == "" )
				return fnG.alerta('Favor ingrese la Cantidad de la Situación.',$('txtcantidadprogramada2'));
			if ( !validaRealDos.test( $('txtcantidadprogramada2').value ) ) {
				if ( !PMU.formateaDecimal( $('txtcantidadprogramada2'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
					return false;
				}
			}
		}
			
		if (fnG.trim($('txtsituacionprogramada3').value) != "" ) {
			if (fnG.trim($('unidadprogramada3').value) == "" )
				return fnG.alerta('Favor ingrese la Unidad de la Situación.',$('unidadprogramada3'));
			if (fnG.trim($('txtcantidadprogramada3').value) == "" )
				return fnG.alerta('Favor ingrese la Cantidad de la Situación.',$('txtcantidadprogramada3'));
			if ( !validaRealDos.test( $('txtcantidadprogramada3').value ) ) {
				if ( !PMU.formateaDecimal( $('txtcantidadprogramada3'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
					return false;
				}
			}
		}
		
			
		if (fnG.trim($('txtsituacionfinal1').value) == "" )
			return fnG.alerta('Favor ingrese la Descripción de la Situación.',$('txtsituacionfinal1'));
		if (fnG.trim($('unidadfinal1').value) == "" )
			return fnG.alerta('Favor ingrese la Unidad de la Situación.',$('unidadfinal1'));
		if (fnG.trim($('txtcantidadfinal1').value) == "" )
			return fnG.alerta('Favor ingrese la Cantidad de la Situación.',$('txtcantidadfinal1'));
		if ( !validaRealDos.test( $('txtcantidadfinal1').value ) ) {
			if ( !PMU.formateaDecimal( $('txtcantidadfinal1'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
				return false;
			}
		}
			
		if (fnG.trim($('txtsituacionfinal2').value) != "" ) {
			if (fnG.trim($('unidadfinal2').value) == "" )
				return fnG.alerta('Favor ingrese la Unidad de la Situación.',$('unidadfinal2'));
			if (fnG.trim($('txtcantidadfinal2').value) == "" )
				return fnG.alerta('Favor ingrese la Cantidad de la Situación.',$('txtcantidadfinal2'));
			if ( !validaRealDos.test( $('txtcantidadfinal2').value ) ) {
				if ( !PMU.formateaDecimal( $('txtcantidadfinal2'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
					return false;
				}
			}
		}
			
		if (fnG.trim($('txtsituacionfinal3').value) != "" ) {
			if (fnG.trim($('unidadfinal3').value) == "" )
				return fnG.alerta('Favor ingrese la Unidad de la Situación.',$('unidadfinal3'));
			if (fnG.trim($('txtcantidadfinal3').value) == "" )
				return fnG.alerta('Favor ingrese la Cantidad de la Situación.',$('txtcantidadfinal3'));
			if ( !validaRealDos.test( $('txtcantidadfinal3').value ) ) {
				if ( !PMU.formateaDecimal( $('txtcantidadfinal3'), 2, "La Cantidad de Situación debe ser un número válido." ) ) {
					return false;
				}
			}
		}

		return true;
	},
	
	validaFichaEvaluacion: function() {
		fnG.borraEspacios( 'document.formulario' );
		if ( !$('rdTipoComuna1').checked && !$('rdTipoComuna2').checked ) {
			return fnG.alerta( 'Favor seleccione Tipo de Comuna.', $('rdTipoComuna1') );
		}
		if ( $('pmutxtHabitantesLocalidad').value == "" ) {
			return fnG.alerta( 'Favor ingrese Número habitante localidad.', $('pmutxtHabitantesLocalidad') );
		}
		if ( $('pmutxtHabitantesComuna').value == "" ) {
			return fnG.alerta( 'Favor ingrese Número habitante comuna.', $('pmutxtHabitantesComuna') );
		}
		if ( $('pmucmbCondicion').value == "" ) {
			return fnG.alerta( 'Favor seleccione Condición.', $('pmucmbCondicion') );
		}
		if ( $('pmuValorCanasta').value == "" ) {
			return fnG.alerta( 'Favor ingrese Valor canasta familiar.', $('pmuValorCanasta') );
		}
		if ( !validaReal.test( $('pmuValorCanasta').value ) ) {
			if ( !PMU.formateaDecimal( $('pmuValorCanasta'), 1, "El Valor canasta familiar debe ser un número válido." ) ) {
				return false;
			}
		}
		if ( fnG.trim( $('pmuIndiceRegional').value ) == '' ) {
			return fnG.alerta( 'Favor ingrese Indice Regional.', $('pmuIndiceRegional') );
		}
		if ( !validaReal.test( $('pmuIndiceRegional').value ) ) {
			if ( !PMU.formateaDecimal( $('pmuIndiceRegional'), 1, "El Indice de Desempleo Regional debe ser un número válido." ) ) {
				return false;
			}
		}
		var indiceR = parseFloat( $('pmuIndiceRegional').value.replace( ',', "." ), 10 );
		if ( indiceR < 0.0 || indiceR > 100.0 ) {
			return fnG.alerta( 'Favor ingrese un Porcentaje válido.', $('pmuIndiceRegional') );
		}
		//anioIn = parseInt(pmutxtanioini.value,10)
		
		if ( fnG.trim( $('pmuIndiceComunal').value ) == '' ) {
			return fnG.alerta( 'Favor ingrese Indice de Desempleo Comunal.', $('pmuIndiceComunal') );
		}
		
		if ( !validaReal.test( $('pmuIndiceComunal').value ) ) {
			if ( !PMU.formateaDecimal( $('pmuIndiceComunal'), 1, "El valor del Indice Comunal debe ser un número válido." ) ) {
				return false;
			}
		}
		
		var indiceC = parseFloat( $('pmuIndiceComunal').value.replace(',', "."),10);
		if ( indiceC < 0.0 || indiceC > 100.0 ) {
			return fnG.alerta( 'Favor ingrese un Porcentaje válido.', $('pmuIndiceComunal') );
		}
		
		if ( fnG.trim( $('pmuRankingInfComunal').value ) == '' ) {
			return fnG.alerta( 'Favor ingrese Ranking Deficit Infraestructura Comunal.', $('pmuRankingInfComunal') );
		}

		if ( !validaReal.test( $('pmuRankingInfComunal').value ) ) {
			if ( !PMU.formateaDecimal( $('pmuRankingInfComunal'), 1, "El Ranking Déficit Infraestructura Comunal debe ser un número válido." ) ) {
				return false;
			}
		}
		
		if ( fnG.trim( $('pmuRankingComunaPobre').value ) == '' ) {
			return fnG.alerta( 'Favor ingrese Ranking Comuna Pobre.', $('pmuRankingComunaPobre') );
		}
		if ( !validaReal.test( $('pmuRankingComunaPobre').value ) ) {
			if ( !PMU.formateaDecimal( $('pmuRankingComunaPobre'), 1, "El valor del Ranking Comuna Pobre debe ser un número válido." ) ) {
				return false;
			}
		}
		
		var indice2 = parseFloat( $('pmuRankingComunaPobre').value.replace( ',', "." ), 10 );
		if ( indice2 < 0.0 || indice2 > 100.0 ) {
			return fnG.alerta( 'Favor ingrese un Porcentaje válido.', $('pmuRankingComunaPobre') );
		}
		
		if ( fnG.trim( $('pmuPorcInvRecurPropios').value ) == '' ) {
			return fnG.alerta( 'Favor ingrese Porcentaje de Inversion de Recursos Propios.', $('pmuPorcInvRecurPropios') );
		}
		if ( !validaReal.test( $('pmuPorcInvRecurPropios').value ) ) {
			if ( !PMU.formateaDecimal( $('pmuPorcInvRecurPropios'), 1, "El valor Porcentaje de Inversión de Recursos Propios debe ser un número válido." ) ) {
				return false;
			}
		}
		var indice3 = parseFloat( $('pmuPorcInvRecurPropios').value.replace( ',', "." ), 10 );
		if ( indice3 < 0.0 || indice3 > 100.0 ) {
			return fnG.alerta( 'Favor ingrese un Porcentaje válido.', $('pmuPorcInvRecurPropios' ) );
		}
		return confirm( "Al grabar la Ficha de Evaluación \nya no la podrá modificar con posterioridad\n¿Desea Continuar?" );
	},
	
	validaGirar: function() {
		if ( $('cmbRemesa').value == 0 ) {
			return fnG.alerta( "Favor seleccione N° Remesa.", $('cmbRemesa') );
		} else if ( !confirm( '¿Confirma que desea realizar el Giro para la Remesa ' + $('cmbRemesa').options[$('cmbRemesa').selectedIndex].text + '?' ) ) {
			return false;
		}
		$('envio').value = 1;
		return true;
	},

	validaAceptarLey: function() {
		if ( cBx.cantidadCheckBox( $('formListado'), 'checkbox' ) > 0 ) {
			if ( !cBx.hayCheckBoxSeleccionados( $('formListado'), 'checkbox' ) ) {
				alert( "Favor seleccione por lo menos un registro." );
				return false;
			}
			var girosMarcados = "";
			var separador = "";
			var count = 0;
			for ( i = 1; i <= cBx.cantidadCheckBox( $('formListado'), 'checkbox' ); i++ ) {
				if ( $('checkbox'+i).checked ) {
					separador = "#";
					if ( girosMarcados == "" ) {
						separador = "";
					}
					girosMarcados += separador + $('checkbox'+i).value;
					count++;
				}
			}
			$('girosAceptar').value = girosMarcados;
			var textoGiros = "el Giro";
			if ( count > 1 ) {
				textoGiros = "los Giros";
			}
			if ( !confirm( '¿Confirma que desea aceptar ' + textoGiros + ' según Ley 19.862?' ) ) {
				return false;
			} else {
				$('envioAceptar').value = 1;
				return true;
			}
		} else {
			return false;
		}
	},
	
	validaFormAceptarLey: function() {
		if ( !confirm( '¿Confirma que desea aceptar el Giro según Ley 19.862?' ) ) {
			return false;
		}
		$('envio').value = 1;
		return true;
	},
	
	validaFormRechazarGiro: function() {
		if ( $('comentarioRechazo').value.length == 0 ) {
			return fnG.alerta( "Favor ingrese un Comentario.", $('comentarioRechazo') );
		}
		if ( !confirm( '¿Confirma que desea rechazar el Giro?' ) ) {
			return false;
		}
		$('envio').value = 1;
		return true;
	},

	/* Validaciones del administrador del sitio */

	validaAdminSubPro: function() {

		if ( $('idPrograma').value == 0 ) {
			return fnG.alerta( "Debe seleccionar un Programa.", $('idPrograma') );
		}

		if (fnG.trim( $('nombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido (Solo Letras y Numeros).", $('nombre') );
		}

		/*if ( $('alias').value == "" ) {
			return fnG.alerta( "Debe seleccionar un Alias Valido (Solo Letras y Numeros ).", $('alias') );
		}*/

		return true;
	},

	validaAdminTipologia: function() {

		if ( fnG.trim( $('nombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido (Solo Letras y Numeros).", $('nombre') );
		}

		return true;
	},
	
	validaAdminModalidad: function() {

		if ( fnG.trim( $('nombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido (Solo Letras y Numeros).", $('nombre') );
		}

		return true;
	},

	validaAdminUnidad: function() {

		if ( fnG.trim( $('nombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido (Solo Letras y Numeros).", $('nombre') );
		}

		return true;
	},

	validaAdminPpto: function() {
/*
if ( $('region').value == 0 ) {
			return fnG.alerta( "Favor Seleccione una region.", $('region') );
		}
*/

		if ( $('comuna').value == 0 ) {
			return fnG.alerta( "Favor Seleccione una comuna.", $('comuna') );
		}

		if ( $('anio').value == 0 ) {
			return fnG.alerta( "Favor Seleccione un año.", $('anio') );
		}

		if ( $('programa').value == 0 ) {
			return fnG.alerta( "Favor Seleccione un Programa.", $('programa') );
		}

		if ( $('subprograma').value == 0 ) {
			return fnG.alerta( "Favor Seleccione un SubPrograma.", $('subprograma') );
		}

		if ( fnG.trim( $('monto').value ) == "" ) {
			return fnG.alerta( "Favor Seleccione un valor para monto.", $('monto') );
		}

		if (!validaRealDosDecimales.test($('monto').value)) {
			if ( !PMU.formateaDecimal( $('monto'), 2, "Favor Seleccione un valor válido para monto." ) ) {
				return false;
			}
		}

		return true;
	},
	
		validaAdminEmails: function() {

		if ( $('region').value == 0 ) {
			return fnG.alerta( "Favor Seleccione una Región.", $('region') );
		}

		try{
			if ( $('comuna').value == 0 ) {
				return fnG.alerta( "Favor Seleccione una Comuna.", $('comuna') );
			}

			if ( fnG.trim( $('email01').value ) != "" && !fnG.esEmail( $('email01').value )) {
				return fnG.alerta( "Debe ingresar un Email Valido.", $('email01') );
			}

			if ( fnG.trim( $('email02').value ) != "" && !fnG.esEmail( $('email02').value )) {
				return fnG.alerta( "Debe ingresar un Email Valido.", $('email02') );
			}

			if ( fnG.trim( $('email03').value ) != "" && !fnG.esEmail( $('email03').value )) {
				return fnG.alerta( "Debe ingresar un Email Valido.", $('email03') );
			}
		}catch(e){
		}

		return true;
	},
	
		validaAdminEmailsRegion: function() {

		if ( $('region').value == 0 ) {
			return fnG.alerta( "Favor Seleccione una Región.", $('region') );
		}

		try{

			if ( fnG.trim( $('email01').value ) != "" && !fnG.esEmail( $('email01').value )) {
				return fnG.alerta( "Debe ingresar un Email Valido.", $('email01') );
			}

			if ( fnG.trim( $('email02').value ) != "" && !fnG.esEmail( $('email02').value )) {
				return fnG.alerta( "Debe ingresar un Email Valido.", $('email02') );
			}

			if ( fnG.trim( $('email03').value ) != "" && !fnG.esEmail( $('email03').value )) {
				return fnG.alerta( "Debe ingresar un Email Valido.", $('email03') );
			}
			
		}catch(e){
		}

		return true;
	},

	validaProgramaRespon: function(){

		CantidadTablas	=	$("CantTablas").value;

		for ( i = 1 ; i <= CantidadTablas ; i++ ){

			try{
				StrRut	=	eval('$("rut_' + i + '")');
				nombre	=	eval('$("nombre_' + i + '")');
				ap_pat	=	eval('$("ap_pat_' + i + '")');
				ap_mat	=	eval('$("ap_mat_' + i + '")');
				cargo	=	eval('$("cargo_' + i + '")');

				if (fnG.trim(StrRut.value) != ""){

					newRut	= StrRut.value;
					SnRut	= newRut.split('-');

					if (validar_rut( SnRut[0] , SnRut[1] ) == false){
						return fnG.alerta('Favor ingrese un RUT válido.' , StrRut);
					}
					
					if ( fnG.trim( nombre.value ) == "" ) {
						return fnG.alerta( "Ingrese un nombre valido.", nombre );
					}
			
					if ( fnG.trim( ap_pat.value ) == "" ) {
						return fnG.alerta( "Ingrese un Apellido Paterno valido.", ap_pat );
					}
	
					if ( fnG.trim( ap_mat.value ) == "" ) {
						return fnG.alerta( "Ingrese un Apellido Materno valido.", ap_mat );
					}
				}else{
					return fnG.alerta( "Ingrese el Rut del Responsable.", StrRut );
				}
			}catch(e){
			}

		}
	
	},
	
	validaProgramaLineaBase: function(){

		if ( fnG.trim( $('variable1').value ) == "0" ) {
			return fnG.alerta( "Debe seleccionar un valor de la variable 1.", $('variable1') );
		}
			
		if ( fnG.trim( $('variable2').value ) == "0" ) {
			return fnG.alerta( "Debe seleccionar un valor de la variable 2.", $('variable2') );
		}
	
		flag = 0;
		var losInputs = $$('#div-lineabase input');
		losInputs.each(function(el, i) {
			
			if( fnG.trim( el.value ) == "" && !validaEntero.test( el.value ) ){
				flag = 1;
			}
			
		});
		
		if( flag == 1 ){
		
			return fnG.alerta( "Debe Ingresar un valor numérico.", $('variable1') );
		
		}
	
	/*
		for ( i = 1 ; i < 4 ; i++ ){
			
			cantproytrim	=	$('cantproytrim' + i);
			montoproytrim	=	$('montoproytrim' + i);
			cantmunitrim	=	$('cantmunitrim'+i);

			if ( fnG.trim( $('variable1').value ) == "0" ) {
				return fnG.alerta( "Debe seleccionar un valor de la variable 1.", $('variable1') );
			}
			
			if ( fnG.trim( $('variable2').value ) == "0" ) {
				return fnG.alerta( "Debe seleccionar un valor de la variable 2.", $('variable2') );
			}
			
			if ( fnG.trim( cantproytrim.value ) != "" && !validaEntero.test( cantproytrim.value ) ) {
				return fnG.alerta( "La cantidad de proyectos debe ser un valor entero.", cantproytrim );
			}
	
			if ( fnG.trim( montoproytrim.value ) != "" && !validaEntero.test( montoproytrim.value ) ) {
				return fnG.alerta( "El monto de los proyectos debe ser un valor entero. (Máximo 2 Decimales)", montoproytrim );
			}
			
			if ( fnG.trim( cantmunitrim.value ) != "" && !validaEntero.test( cantmunitrim.value ) ) {
				return fnG.alerta( "La Cantidad de municipios debe ser un valor entero.", cantmunitrim );
			}
			
		}
	*/

	},

	validaProgramaEditGral: function(){
		
		if ( fnG.trim( $('codMoneda').value ) == "0" ) {
			return fnG.alerta( "Debe seleccionar el Tipo de Moneda.", $('codMoneda') );
		}

		
		if ( !validaRealDos.test( $('montoPrograma').value) ) {
			return fnG.alerta( "Debe ingresar un monto Valido.", $('montoPrograma') );
		}

		if ( fnG.trim( $('codPrestamo').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Codigo Valido.", $('codPrestamo') );
		}

		extensiones_permitidas = new Array(".gif", ".jpg", ".png");
		mierror = "";

		archivo = document.form1.urlLogo.value;
		if (archivo) {
			extension = (archivo.substring(archivo.lastIndexOf("."))).toLowerCase();
			permitida = false;
			for (var i = 0; i < extensiones_permitidas.length; i++) {
				if (extensiones_permitidas[i] == extension) {
					permitida = true;
					break;
				}
			}

			if (!permitida) {
				mierror = "Comprueba la extensión de los archivos a subir. \nSólo se pueden subir archivos con extensiones: " + extensiones_permitidas.join();
				return fnG.alerta(mierror , $("codPrestamo"));
			}

		}

	},

	validaProgramaEditBasico: function(){
		if ( fnG.trim( $('nombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido.", $('nombre') );
		}

		/* valida fecha inicial */
		if (!validaEntero.test($('fechaInicioVig_dia').value) || $('fechaInicioVig_dia').value > 31 ) {
			$('fechaInicioVig_dia').value = "";
			return fnG.alerta("Favor digite un dia valido" , $("fechaInicioVig_dia"));
		}

		if (!validaEntero.test($('fechaInicioVig_mes').value) || $('fechaInicioVig_mes').value > 12 ) {
			$('fechaInicioVig_mes').value = "";
			return fnG.alerta("Favor digite un mes valido" , $("fechaInicioVig_mes"));
		}

		if (!validaEntero.test($('fechaInicioVig_anio').value) || $('fechaInicioVig_anio').value.length > 4 ) {
			$('fechaInicioVig_anio').value = "";
			return fnG.alerta("Favor digite un año valido" , $("fechaInicioVig_anio"));
		}


		if (fnG.esFecha( $("fechaInicioVig_anio").value, $("fechaInicioVig_mes").value, $("fechaInicioVig_dia").value ) != 0){
			anio	=	$("fechaInicioVig_anio").value;
			mes		=	$("fechaInicioVig_mes").value;
			dia		=	$("fechaInicioVig_dia").value;
			
			return fnG.alerta( fnG.obtFechaMensaje(fnG.esFecha(anio, mes, dia) ) , $("fechaInicioVig_dia") );
			
		}
		
		/* valida fecha Final */
		if (!validaEntero.test($('fechaTerminoVig_dia').value) || $('fechaTerminoVig_dia').value > 31 ) {
			$('fechaTerminoVig_dia').value = "";
			return fnG.alerta("Favor digite un dia valido" , $("fechaTerminoVig_dia"));
		}

		if (!validaEntero.test($('fechaTerminoVig_mes').value) || $('fechaTerminoVig_mes').value > 12 ) {
			$('fechaTerminoVig_mes').value = "";
			return fnG.alerta("Favor digite un mes valido" , $("fechaTerminoVig_mes"));
		}

		if (!validaEntero.test($('fechaTerminoVig_anio').value) || $('fechaTerminoVig_anio').value.length > 4 ) {
			$('fechaTerminoVig_anio').value = "";
			return fnG.alerta("Favor digite un año valido" , $("fechaTerminoVig_anio"));
		}

		if (fnG.esFecha($("fechaTerminoVig_anio").value, $("fechaTerminoVig_mes").value, $("fechaTerminoVig_dia").value)!=0){
			anioT	=	$("fechaInicioVig_anio").value;
			mesT	=	$("fechaInicioVig_mes").value;
			diaT	=	$("fechaInicioVig_dia").value;

			return fnG.alerta(fnG.obtFechaMensaje( fnG.esFecha( anioT, mesT, diaT ) ),$("fechaTerminoVig_dia"));
		}

		FechaInicio		= $("fechaInicioVig_anio").value+"-"+$("fechaInicioVig_mes").value+"-"+$("fechaInicioVig_dia").value;
		FechaTermino	= $("fechaTerminoVig_anio").value+"-"+$("fechaTerminoVig_mes").value+"-"+$("fechaTerminoVig_dia").value;
		if ( !fecha1_esmenorque_fecha2(FechaInicio, FechaTermino) ){
			
			return fnG.alerta( "La fecha de termino debe ser mayor a la fecha de inicio" , $("fechaTerminoVig_dia") );
		}
		
		
		if( !isAnoLimiteInferiorValido( $("fechaInicioVig_anio").value ) ){
			return fnG.alerta( "El año debe ser mayor a 1900" , $("fechaInicioVig_anio") );
		}

		if( !isAnoLimiteInferiorValido( $("fechaTerminoVig_anio").value ) ){
			return fnG.alerta( "El año debe ser mayor a 1900" , $("fechaTerminoVig_anio") );
		}


	},
	
	
	
	validaProgramaDocumentos: function(){
		
		var Contador		= $("Contador").value;
		var ExtPermitidas	= new Array(".xls", ".ppt", ".doc", ".pdf");

		for ( i = 1 ; i < Contador ; i++ ){

			//try{
				Descripcion		=	eval('$("descripcion[' + i + ']")');
				archivoAdjunto	=	eval('$("file[' + i + ']")');
				FileOld			=	eval('$("fileAdj[' + i + ']")');

				if ( fnG.trim( Descripcion.value ) == "" ) {
					return fnG.alerta( "Ingrese La descripcion de su Documento.", Descripcion );
				}
		
				if ( fnG.trim( archivoAdjunto.value ) == "" && fnG.trim( FileOld.value ) == "" ) {
					return fnG.alerta( "Ingrese el Documento.", archivoAdjunto );
				}

				if ( fnG.trim( archivoAdjunto.value ) != "" && !comprueba_extension( archivoAdjunto.value , ExtPermitidas ) ) {
					Mensaje = "Comprueba la extensión de los archivos a subir. \nSólo se pueden subir archivos con extensiones: " + ExtPermitidas.join();
					return fnG.alerta( Mensaje, archivoAdjunto );
				}

			//}catch(e){
			//}

		}
	},
	
	validaProgramaNuevo: function(){

		if (!validaEntero.test($('idPrograma').value)) {
			return fnG.alerta("El Programa debe ser un valor entero" , $("idPrograma"));
		}

		if ( $('idSubPrograma').value == 0 ) {
			return fnG.alerta( "Favor Seleccione un SubPrograma.", $('idSubPrograma') );
		}

		if (!validaEntero.test($('anio').value) || $('anio').value.length > 4 ) {
			return fnG.alerta("Favor digite un año valido" , $("anio"));
		}

		if ( fnG.trim( $('nombre').value ) == "" ) {
			return fnG.alerta( "Debe ingresar un Nombre Valido.", $('nombre') );
		}

		/* valida fecha inicial */
		if (!validaEntero.test($('fechaInicioVigencia_dia').value) || $('fechaInicioVigencia_dia').value > 31 ) {
			$('fechaInicioVigencia_dia').value = "";
			return fnG.alerta("Favor digite un dia valido" , $("fechaInicioVigencia_dia"));
		}

		if (!validaEntero.test($('fechaInicioVigencia_mes').value) || $('fechaInicioVigencia_mes').value > 12 ) {
			$('fechaInicioVigencia_mes').value = "";
			return fnG.alerta("Favor digite un mes valido" , $("fechaInicioVigencia_mes"));
		}

		if (!validaEntero.test($('fechaInicioVigencia_anio').value) || $('fechaInicioVigencia_anio').value.length > 4 ) {
			$('fechaInicioVigencia_anio').value = "";
			return fnG.alerta("Favor digite un año valido" , $("fechaInicioVigencia_anio"));
		}


		if (fnG.esFecha( $("fechaInicioVigencia_anio").value, $("fechaInicioVigencia_mes").value, $("fechaInicioVigencia_dia").value ) != 0){
			anio	=	$("fechaInicioVigencia_anio").value;
			mes		=	$("fechaInicioVigencia_mes").value;
			dia		=	$("fechaInicioVigencia_dia").value;

			return fnG.alerta( fnG.obtFechaMensaje(fnG.esFecha(anio, mes, dia) ) , $("fechaInicioVigencia_dia") );
		}
		
		/* valida fecha Final */
		if (!validaEntero.test($('fechaTerminoVigencia_dia').value) || $('fechaTerminoVigencia_dia').value > 31 ) {
			$('fechaTerminoVigencia_dia').value = "";
			return fnG.alerta("Favor digite un dia valido" , $("fechaTerminoVigencia_dia"));
		}

		if (!validaEntero.test($('fechaTerminoVigencia_mes').value) || $('fechaTerminoVigencia_mes').value > 12 ) {
			$('fechaTerminoVigencia_mes').value = "";
			return fnG.alerta("Favor digite un mes valido" , $("fechaTerminoVigencia_mes"));
		}

		if (!validaEntero.test($('fechaTerminoVigencia_anio').value) || $('fechaTerminoVigencia_anio').value.length > 4 ) {
			$('fechaTerminoVigencia_anio').value = "";
			return fnG.alerta("Favor digite un año valido" , $("fechaTerminoVigencia_anio"));
		}

		if (fnG.esFecha($("fechaTerminoVigencia_anio").value, $("fechaTerminoVigencia_mes").value, $("fechaTerminoVigencia_dia").value)!=0){
			anioT	=	$("fechaInicioVigencia_anio").value;
			mesT	=	$("fechaInicioVigencia_mes").value;
			diaT	=	$("fechaInicioVigencia_dia").value;

			return fnG.alerta(fnG.obtFechaMensaje( fnG.esFecha( anioT, mesT, diaT ) ),$("fechaTerminoVigencia_dia"));
		}
		
		
		FechaInicio		= $("fechaInicioVigencia_anio").value+"-"+$("fechaInicioVigencia_mes").value+"-"+$("fechaInicioVigencia_dia").value;
		FechaTermino	= $("fechaTerminoVigencia_anio").value+"-"+$("fechaTerminoVigencia_mes").value+"-"+$("fechaTerminoVigencia_dia").value;
		if ( !fecha1_esmenorque_fecha2(FechaInicio, FechaTermino) ){
			
			return fnG.alerta( "La fecha de termino debe ser mayor a la fecha de inicio" , $("fechaTerminoVigencia_dia") );
		}
		
		
		if( !isAnoLimiteInferiorValido( $("fechaInicioVigencia_anio").value ) ){
			return fnG.alerta( "El año debe ser mayor a 1900" , $("fechaInicioVigencia_anio") );
		}

		if( !isAnoLimiteInferiorValido( $("fechaTerminoVigencia_anio").value ) ){
			return fnG.alerta( "El año debe ser mayor a 1900" , $("fechaTerminoVigencia_anio") );
		}

	}

}