/* ================================================================================================================================= */
var sImagenError       = '<img src="../imagenes/Iconos/ic_error.gif"         width="14" height="14" border=0/>';
var sImagenAdvertencia = '<img src="../imagenes/Iconos/ic_advertencia.gif"   width="16" height="14"         />';
var sImagenCargando    = '<img src="../imagenes/Iconos/ic_ani_cargando.gif"  width="20" height="20"         />';
var sImagenExito       = '<img src="../Imagenes/Iconos/ic_ok.gif" width="15"            height="15"         />';

/* ================================================================================================================================= */

        function validarLargo(textbox,largo)
        {		
            //alert('ad');
            largo = parseFloat(largo);
		    if(textbox.value.length > largo)
		    {
			  textbox.value = textbox.value.slice(0,largo)
		    }
	    }
		function errorPagina(mensaje)
		{
			document.getElementById('divErrorPagina').innerHTML=  sImagenError + ' ' + mensaje;
			document.getElementById('divErrorPagina').style.display = '';
			document.getElementById('divMensajeExito').style.display = 'none';
			window.location.href='#subir';
		}
	
		function imprimirError(Objeto,mensaje)
		{
			document.getElementById('div' + Objeto.split('txt')[1]).innerHTML=  sImagenAdvertencia + ' ' + mensaje;
			document.getElementById('div' + Objeto.split('txt')[1]).style.display = '';
		}
		function imprimirErrorddl(Objeto,mensaje)
		{
			document.getElementById('div' + Objeto.split('ddl')[1]).innerHTML=  sImagenAdvertencia + ' ' + mensaje;
			document.getElementById('div' + Objeto.split('ddl')[1]).style.display = '';
		}

		function imprimirErrorrbl(Objeto,mensaje)
		{
			document.getElementById(Objeto).innerHTML=  sImagenAdvertencia + ' ' + mensaje;
			document.getElementById(Objeto).style.display = '';
		}

		function validarLargoTxt(c,divid,msg)
        {		
            var id = c.id;
            var arr=id.split()
            if(c.value.length > 2000)
            {
                c.value = c.value.slice(0,2000)
	            document.getElementById(divid).innerHTML=  sImagenAdvertencia + ' ' + msg;
	            document.getElementById(divid).style.display = '';
            }
            else
            {
                document.getElementById(divid).style.display = 'none';
            }
        }
        
        
        
        function validarLargoTxtDivError(c,divid,msg,maxlen)
        {		
            var id = c.id;
            var arr=id.split()
            if(c.value.length > maxlen)
            {
                c.value = c.value.slice(0,maxlen)
	            document.getElementById(divid).innerHTML=  sImagenAdvertencia + ' ' + msg;
	            document.getElementById(divid).style.display = '';
            }
            else
            {
                document.getElementById(divid).style.display = 'none';
            }
        }
    
		function revisarPagina() 
		{
			
			var blnPaginaValida = true
			
			document.getElementById('divNombreExp').style.display = 'none'
			
			if (document.getElementById('txtNombreExp').value =='') 
			{

				document.getElementById('divNombreExp').style.display = 'none'
				errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				imprimirError('txtNombreExp','Debe especificar el Nombre del Proceso')
				window.location.href='#subir'
				blnPaginaValida = false
			}

			if (document.getElementById('txtDescExp').value =='') 
			{

				document.getElementById('divDescExp').style.display = 'none'
				errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				imprimirError('txtDescExp','Debe especificar el Objeto del Expediente')
				window.location.href='#subir'
				blnPaginaValida = false
			}

			/*if (document.getElementById('txtPlazoEstimado').value =='') 
			{

				document.getElementById('divPlazoEstimado').style.display = 'none'
				errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				imprimirError('txtPlazoEstimado','Debe especificar el Plazo Estimado')
				window.location.href='#subir'
				blnPaginaValida = false
			}

			if (document.getElementById('ddlTipoUnidad').value =='0')
			{

				document.getElementById('divTipoUnidad').style.display = 'none'
				errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				imprimirErrorddl('ddlTipoUnidad','Debe especificar la Unidad del Plazo Estimado')
				window.location.href='#subir'
				blnPaginaValida = false
			}*/
			
			if ((!document.getElementById('rblRegimen_0').checked) && (!document.getElementById('rblRegimen_1').checked))
			{ 
				document.getElementById('divRegimen').style.display = 'none'
				errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				document.getElementById('divRegimen').innerHTML=  sImagenAdvertencia + ' Debe escojer Regimen de Contratacion';
				document.getElementById('divRegimen').style.display = '';
				window.location.href='#subir'
				blnPaginaValida = false
			}
	
		
			if (blnPaginaValida){
				__doPostBack('btnCrearProceso','')
			}

		}
		
		function revisarPaginaModificar() 
		{
			
			var blnPaginaValida = true
			
			document.getElementById('divNombreExp').style.display = 'none'
			
			if (document.getElementById('txtNombreExp').value =='') 
			{

				document.getElementById('divNombreExp').style.display = 'none'
				errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				imprimirError('txtNombreExp','Debe especificar el Nombre del Expediente')
				window.location.href='#subir'
				blnPaginaValida = false
			}

			if (document.getElementById('txtDescExp').value =='') 
			{

				document.getElementById('divDescExp').style.display = 'none'
				errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				imprimirError('txtDescExp','Debe especificar la Descripci&oacute;n del Expediente')
				window.location.href='#subir'
				blnPaginaValida = false
			}

			if ((!document.getElementById('rblRegimen_0').checked) && (!document.getElementById('rblRegimen_1').checked))
			{ 
				document.getElementById('divRegimen').style.display = 'none'
				errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				document.getElementById('divRegimen').innerHTML=  sImagenAdvertencia + ' Debe escojer Regimen de Contratacion';
				document.getElementById('divRegimen').style.display = '';
				window.location.href='#subir'
				blnPaginaValida = false
			}
	
		
			if (blnPaginaValida){
				__doPostBack('btnModificarProceso','')
			}

		}
		
		function PopupBuscarPlanes() 
		{			
			s = "../ProcesoContractual/BuscarPlanCompra_Popup.aspx"
			open(s , "PlanesdeCompra", "width=700, height=550, status=yes, scrollbars=yes, left=50, top=50, resizable=yes");
		}
		function SeleccionarPlandeCompra(IdPC, Numero, Nombre, Descripcion)
		{	
			window.opener.ListarPlanesdeCompra(IdPC, Numero, Nombre, Descripcion);
			self.close();
		}	
		function ListarPlanesdeCompra(IdPC, Numero, Nombre, Descripcion)
		{	
		    document.forms[0].hidIdPC.value = IdPC;
		    document.forms[0].hidNumero.value = Numero;
		    document.forms[0].hidNombre.value = Nombre;
		    document.forms[0].hidDescripcion.value = Descripcion;		
			__doPostBack('btnAgregarPlandeCompra','');
		}
		function EliminarPlan(IdPC, Numero)
		{	
		    document.forms[0].hidIdPC.value = IdPC;
		    document.forms[0].hidNumero.value = Numero;
		    __doPostBack('btnEliminaPlandeCompra','');
		}
		function _ver_Calendario(strIdControl)
        {
        var form;
        if (window.navigator.appName.toLowerCase().indexOf("netscape") > -1) { form = document.forms["Form1"]; } else { form = document.Form1;}	

        //var idControl = eval ("form1."+strIdControl);
        var idControl = document.getElementById(strIdControl);
        open("../includes/calendario.aspx?hora=0&campo="+idControl.name+"&valor="+idControl.value, "calendario","width=200, height=150, status=yes, scrollbars=yes, left=50, top=50");
        }		
        
        function Accion(strIdPC, strAction,strRutaAlternaPages)
		{
		        if(typeof(strRutaAlternaPages)=='undefined')
		        {
		            strRutaAlternaPages = "";
		        }
		
			    if (strAction == 'eli')
			        window.location.href= strRutaAlternaPages + 'EliminarProcesoContractual.aspx?Id=' + strIdPC;
			    else if (strAction == 'ver')
			        window.location.href= strRutaAlternaPages + 'verProcesoContractual.aspx?Id=' + strIdPC;
			    else if (strAction == 'verpub')
			        window.location.href= strRutaAlternaPages + 'verProcesoContractual.aspx?Id=' + strIdPC + "&p=1";
			    else if (strAction == 'mod')
			        window.location.href= strRutaAlternaPages + 'ModificarProcesoContractual.aspx?IdProcesoContractual=' + strIdPC;
			    else if (strAction == 'estudios')
			        window.location.href= strRutaAlternaPages + 'CrearEstudiosPrevios.aspx?IdProcesoContractual=' + strIdPC;
			    else if (strAction == 'modificaestudios')
			        //Se utiliza el campo strRutaAlternaPages para almacenar el IdProcesoConstractual encriptado
			        //y se pasa parametro sw=Modificar, indicando que la accion es modificar
                    window.location.href= 'IndiceEstudiosPrevios.aspx?IdEstudio=' + strIdPC + '&IdProcesoContractual=' + strRutaAlternaPages + '&sw=Modificar';
			    else if (strAction == 'eliminaestudios')
			    {
			        if((confirm('Esta Seguro de Eliminar los Estudios Previos')))
                    {
                        window.location.href= strRutaAlternaPages + 'MensajeFinalizacion.aspx?IdEstudio=' + strIdPC + "&m=2";
                    }
                    else
                    {
                        errorPagina('Sistema no elimina los estudios previos del expediente contractual');
                    }
                }
			    else if (strAction == 'con')
			        //window.location.href= strRutaAlternaPages + 'HistorialProcesoContractual.aspx?IdProcesoContractual=' + strIdPC;
	                open(strRutaAlternaPages + "HistorialProcesoContractual.aspx?IdProcesoContractual=" + strIdPC , "Historial","width=700, height=500, status=no, scrollbars=yes, left=0, top=0 , resizable=yes");
	            else if (strAction == 'can')
	            {	
	                document.forms[0].hidIdPC.value = strIdPC;	        
		            if (confirm('Esta seguro de Cerrar el Expediente?'))
		            	__doPostBack('btnCerrar', '');
	            }      
		
		}
		
		//...AC 20080222 (inicio) COSC-3060
		function AccionAP(strIdPC)
		{
          strRutaAlternaPages = "";
	      open("../ProcesoContractual/HistorialProcesoContractual.aspx?p=1&IdProcesoContractual=" + strIdPC , "Historial","width=700, height=550, status=yes, scrollbars=yes, left=50, top=50, resizable=yes");
		}
		//...AC 20080222 (fin)
		
		function validarVerPCPorNumero()
        {

            if (document.getElementById("txtNumero").value =='')
            {
                alert('Sr.usuario, debe ingresar el n&uacute;mero de Expediente para realizar la b&uacute;squeda');
            } 
            else
            {
                document.getElementById('txtNumero').value = trim(document.getElementById('txtNumero').value);
                __doPostBack('btnBuscarPorNumero','');
            }
        }
        
        function trim(s) 
        {
            while (s.substring(0,1) == ' ') {
                s = s.substring(1,s.length);
            }
            while (s.substring(s.length-1,s.length) == ' ') {
                s = s.substring(0,s.length-1);
            }
            return s;
        }

        function ConfirmarEliminarPC(){
            if(esPaginaValida()&&confirm('Esta seguro de eliminar el Expediente?'))__doPostBack('btnConfirmar','');
        }
        
        function volverEliminarPC(){
            window.location.href='ConsultarProcesoContractual.aspx';
        }
        
        /*function imprimirExitoPagina(div,mensaje)
        {
            document.getElementById(div).innerHTML =  sImagenExito + mensaje;
            document.getElementById(div).style.display = '';
        }*/  
        
        function imprimirExitoPagina(mensaje)
        {
            document.getElementById('divMensajeExito').innerHTML =  sImagenExito + mensaje;
            document.getElementById('divMensajeExito').style.display = '';
            document.getElementById('divErrorPagina').style.display = 'none';
        }
        
        function ctrmaxlen(c,l) 
        {
            if(c.value.toString().length==l)event.keyCode = 0;
            return true;
        }
        
        function ctrmaxlenonchange(c,l,div,msg)
        {
            if(c.value.toString().length>l&&l>0){
                if(div!=''){ 
                    document.getElementById(div).style.display = '';
                    document.getElementById(div).innerHTML= sImagenAdvertencia + ' ' + msg;
                    errorPagina('Se encontraron errores o falta de informaci&oacute;n en algunos campos. Por favor verifique los datos indicados en rojo.')
				}
                c.value = c.value.toString().substr(0,l);
                window.location.href='#subir';
            }
            else
                if(div!=''){
                    document.getElementById(div).style.display = 'none';
                    document.getElementById('divErrorPagina').style.display = 'none';
                }
        }
      
        function OcultarError(Objeto)
        {
            document.getElementById(Objeto).style.display = 'none';
        }
        
        function IsNumeric( numstr ) {
            if (numstr+"" == "undefined" || numstr+"" == "null" || numstr+"" == "") 
                return false;
            var MAX_DECIMALES = 4;
            var isValid = true;
            var decCount = 0; // number of decimal points in the string
            // convert to a string for performing string comparisons.
            var numdecimales = 0;
            numstr += ""; 
            // Loop through string and test each character. If any
            // character is not a number, return a false result.
            // Include special cases for negative numbers (first char == '-')
            // and a single decimal point (any one char in string == '.'). 
            for (i = 0; i < numstr.length; i++) 
            {
            // track number of decimal points
                if (decCount > 0) 
                    numdecimales++;
                    
                if (numstr.charAt(i) == ","){
                    decCount++;
                }
                
                if (!((numstr.charAt(i) >= "0") && (numstr.charAt(i) <= "9") || (numstr.charAt(i) == ","))) 
                {
                    isValid = false;
                    break;
                } else 
                    if ((numstr.charAt(i) == "," && numstr.length == 1) ||(numstr.charAt(i) == "," && decCount > 1)) 
                    {
                        isValid = false;
                        break;
                    } 
            
            } // END for 
            
            if (numdecimales > MAX_DECIMALES){
                isValid = false;
            }
            return isValid;
        } // end IsNum
