
function Validar_bus_noticia(theForm)
<!-- Validacion de Formulario BUSQUEDA DE NOTICIAS	-->
{
var checkStr1 = theForm.txt_titulonoticia.value;
var checkStr2 = theForm.f_dia.value;
var checkStr3 = theForm.f_mes.value;
var checkStr4 = theForm.f_anio.value;
 
  if (checkStr1.length==0 && checkStr2=='' && checkStr3=='' && checkStr4=='')
	{
    alert("Ingrese al menos una opcion de Búsqueda, por favor.");
    theForm.txt_titulonoticia.focus();
    return (false);
	}	
	
	if (checkStr1.length!=0) {
	if (checkStr1.replace(/ /g, '') == '')
	{
		alert("No se aceptan espacios en blanco.");
		theForm.txt_titulonoticia.focus();
		theForm.txt_titulonoticia.select();
		return (false);
		}
	}
  
	
 
if (checkStr2!='' && checkStr3=='' && checkStr4=='')
	{
    alert("Ingrese una fecha corresta , por favor.");
    theForm.txt_titulonoticia.focus();
    return (false);
	}

	
	// validacion de fecha para meses con diaz
 
var d= theForm.f_dia.value;
var m = theForm.f_mes.value;
var a = theForm.f_anio.value;
  	if (!check_date(d,m,a)){
		alert ("Fecha no permitida.");
		//theform.f_dia.focus();
		return false;
  	}
	//if ( (checkStr2=='29' || checkStr2=='30' || checkStr2=='31') && checkStr3=='Febrero' && checkStr4!='año')
	//if (  checkStr2=='29' && checkStr3=='Febrero' && checkStr4!='año')
	//{
   // alert("Ingrese un dia del mes de enero corresto , por favor.");
   //// theForm.f_dia.focus();
   // return (false);
	//}
	
	
 return (true);
}

//******************  check_date


function check_date(day,month,year){
var leap = 0;
var err = 0;
  /* Validation leap-year / february / day */
   if ((year % 4 == 0) || (year % 100 == 0) || (year % 400 == 0)) { leap = 1;  }
   if ((month == 2) && (leap == 1) && (day > 29)) {  err = 23;  }
   if ((month == 2) && (leap != 1) && (day > 28)) {  err = 24;  }
   /* Validation of other months */
   if ((day > 31) && ((month == 1) || (month == 3) || (month == 5) || (month == 7) || (month == 8) || (month == 10) || (month == 12))) {
      err = 25;
   }
   if ((day > 30) && ((month == 4) || (month == 6) || (month == 9) || (month == 11))) {
      err = 26;
   }
   if (err == 0) {	return true;  }
   else {		return false;  }
}

function MayorFecha(di,mi,ai,df,mf,af){
di=di*1;
mi=mi*1;
ai=ai*1;
df=df*1;
mf=mf*1;
af=af*1;
if (ai>af) return false;
else {
  if(ai<af) return true;
  else{
   if (mi>mf) return false;
   else{
     if(mi<mf) return true;
     else{
      if(di>df) return false;
      else{
        return true;
      }
     }
   }
  }
}
}

//******************

function Validar_noticia(theForm)
<!-- Validacion de Formulario INGRESO NOTICIAS -->
{var checkStr = theForm.titulonoticia.value;
  if (checkStr.length==0)
	{
    alert("Ingrese su Titulo de Noticia, por favor.");
    theForm.titulonoticia.focus();
    return (false);
	}	

//*****************  validacion de textarea
theForm.descripcionnoticia.required = "true"; 
for (i = 0; i <theForm.elements.length; i++){
if ((theForm.elements[i].type == "textarea") &&  theForm.elements[i].required=="true" && theForm.elements[i].value=='')
{
  alert('Por favor, complete el campo de descripcion'); 
		 return (false);
		break;
	}
}

if (Trim(theForm.descripcionnoticia.value)=='<P>&nbsp;</P>')
	{
    alert("No dejar en blanco la descripcion, por favor.");
 
    return (false);
	}
	
//************************************ 
 var checkStr = theForm.urlnoticia.value;
  if (checkStr=='http://')
	{
    alert("Ingrese URL de Noticias, por favor.");
    theForm.urlnoticia .focus();
    return (false);
	}	
 var checkStr = theForm.fuentenoticia.value;
	if (checkStr.length==0)
	{
    alert("Ingrese fuente de la Noticia, por favor.");
    theForm.fuentenoticia.focus();
    return (false);
	}	

   // validacion de fecha para meses con diaz
 
var d= theForm.f_dia.value;
var m = theForm.f_mes.value;
var a = theForm.f_anio.value;
  	if (!check_date(d,m,a)){
		alert ("Fecha no permitida.");
		//theform.f_dia.focus();
		return false;
  	}
  var checkStr4 = theForm.codprioridad; 
  if (checkStr4[0].selected == true )
	{
    alert("Selecciones una Prioridad, por favor.");
    theForm.codprioridad.focus();
    return (false);
	}	
		 
 return (true);
}

/*************************/

 


/************************   OPCIONES VER GENERAL **************/ 
/*************************/
 

/*************************/
/*************************/
/************************  OPCIONES DE USUARIO **************/ 
/*************************/

function EDITAR_NOTICIA(VER,CODIGO,ENVIAR)
{
//if (Validar_noticia(window.document.formulario))
//{

 window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
 	window.document.formulario.id_pre.value=CODIGO;
 	/// alert(VER);
 //alert(CODIGO);
 window.document.formulario.submit();
//}
} 
 /*************************/
function pregunta_elimina_noticia(CODIGO,ENVIAR,VER){ 
   if (confirm('¿Estas seguro de ELIMINAR esta NOTICIA?')){ 
 
	 document.formulario.enviar.value=ENVIAR;   
 document.formulario.id_pre.value=CODIGO;
  window.document.formulario.ver_opt.value=VER;
// alert(ENVIAR);
 //alert(CODIGO);
 document.formulario.submit();
    } 
} 
/*************************/
function GUARDAR_MODI_USUARIO(VER,CODIGO,ENVIAR)
{
if (Validar_usuario(window.document.formulario))
{
	window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
 	window.document.formulario.id_pre.value=CODIGO;
 //	 alert(ENVIAR);
 //alert(VER);
 //alert(CODIGO);
 window.document.formulario.submit();

}

}

 /*************************/
function DETALLE_NOTICIA(VER,CODIGO,ENVIAR)
{

 window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
 	window.document.formulario.id_pre.value=CODIGO;
 //	 alert(VER);
 //alert(CODIGO);
 window.document.formulario.submit();

}

 /*************************/
function DETALLE_NOTICIA_HOME(VER,CODIGO,ENVIAR)
{

 window.document.frm_home_noticia.enviar.value=ENVIAR;
	window.document.frm_home_noticia.ver_opt.value=VER;
 	window.document.frm_home_noticia.id_pre.value=CODIGO;
 
 //  alert(ENVIAR);
 //alert(VER);
 //alert(CODIGO);
 window.document.frm_home_noticia.submit();

}
/*************************/
/*************************/
function GUARDAR_NOTICIA(VER,ENVIAR)
{
if (Validar_noticia(window.document.formulario))
{

	//window.document.formulario.enviar.value=AREGLO;
	window.document.formulario.enviar.value=ENVIAR;
//	window.document.formulario.nom_seccion.value=SECCION;
	window.document.formulario.ver_opt.value=VER;
// 	window.document.formulario.id_pre.value=CODIGO;
 //	 alert(ENVIAR);
 //alert(VER);
 //alert(CODIGO);
 window.document.formulario.submit();

}
}

function BUSCAR_NOTICIA(VER,ENVIAR)
{
 if (Validar_bus_noticia(window.document.formulario))
 {
  window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
	//alert(ENVIAR);
// alert(VER);
	window.document.formulario.submit();

 }
}
/************************   **************/ 
/*************************/
function Datos(VER)
{
	 
if (Validar(window.document.formulario))
	window.document.formulario.ver_opt.value=VER;
	//window.document.formulario.submit();

}

function Datos_usuario()
{
if (Validar_usuario(window.document.formulario))
	window.document.formulario.submit();

}



function Datos_bus_usuario()
{
if (Validar_bus_usuario(window.document.formulario))
	window.document.formulario.submit();

}

function enviar_derechos()
{
//if (Validar_bus_perfil(window.document.formulario))
	window.document.formulario.submit();

}

function focus(){
	window.document.formulario.login.focus();
}
 
 

function pregunta_elimina_usuario_XXX(CODIGO){ 
    if (confirm('¿Estas seguro de ELIMINAR este USUARIO?')){ 
 document.formulario.codigo_id_pres.value=CODIGO;
 document.formulario.submit();
    } 
} 


