
function Validar_bus_eventop(theForm)
{

var checkStr1 = theForm.txt_tituloeventop.value;
var checkStr2 = theForm.f_dia.value;
var checkStr3 = theForm.f_mes.value;
var checkStr4 = theForm.f_anio.value;
 
if (checkStr1.length!=0) {
	if (checkStr1.replace(/ /g, '') == '')
	{
		alert("No se aceptan espacios en blanco.");
		theForm.txt_tituloeventop.focus();
		theForm.txt_tituloeventop.select();
		return (false);
	}
}

if (checkStr1.length==0 && checkStr2=='' && checkStr3=='' && checkStr4=='')
	{
    alert("Ingrese al menos una opcion de Búsqueda, por favor.");
    theForm.txt_tituloeventop.focus();
    return (false);
	}	
	
if (checkStr2!='' && checkStr3=='' && checkStr4=='')
	{
    alert("Ingrese una fecha correcta , por favor.");
    theForm.f_mes.focus();
    return (false);
	}
if (checkStr2!='' && checkStr3=='' && checkStr4!='')
	{
    alert("Ingrese una fecha correcta , por favor.");
    theForm.f_mes.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;
  	}

 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_eventop(theForm)
{
	var checkStr = theForm.tituloeventop.value;
	if (checkStr.length!=0) {
		if (checkStr.replace(/ /g, '') == '')
		{
			alert("No se aceptan espacios en blanco.");
			theForm.tituloeventop.focus();
			theForm.tituloeventop.select();
			return (false);
		}
	}
	
    var checkStr = theForm.tituloeventop.value;
    if (checkStr.length==0)
	{
    alert("Ingrese un Titulo, por favor.");
    theForm.tituloeventop.focus();
    return (false);
	}	
	
	
	var checkStr = theForm.descripcioneventop.value.length;
	if (checkStr==0) 
	{
    alert("Ingrese una descripcion, por favor.");
    return (false);
	}	
 
   // validacion de fecha para meses con diaz
var d1= theForm.f_dia1.value;
var m1 = theForm.f_mes1.value;
var a1 = theForm.f_anio1.value;
  	if (!check_date(d1,m1,a1)){
		alert ("Fecha no permitida.");
		//theform.f_dia.focus();
		return false;
  	}
	
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 (!MayorFecha(d1,m1,a1,d,m,a)){
		alert ("Fecha no permitida.");
		//theform.f_dia.focus();
		return false;
  	}
	
 return (true);
}
/*************************/
 
function Ir_derecho(VER,DERECHO)
{
    window.document.formulario.ver_opt.value="";
    window.document.formulario.ver_opt.value=VER;
	window.document.formulario.derecho.value=DERECHO;
	window.document.formulario.submit();

} 

/*************************/

function EDITAR_EVENTOP(VER,CODIGO,ENVIAR)
{
 window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
 	window.document.formulario.id_pre.value=CODIGO;
 window.document.formulario.submit();
} 
 /*************************/
function MODIFICAR_EVENTOP(VER,ENVIAR)
{
if (Validar_eventop(window.document.formulario))
{
	window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
 window.document.formulario.submit();

}
} 
 /*************************/
function pregunta_elimina_eventop(CODIGO,ENVIAR,VER){ 
   if (confirm('¿Estas seguro de ELIMINAR este registro?')){ 
 
	 document.formulario.enviar.value=ENVIAR;   
 document.formulario.id_pre.value=CODIGO;
  window.document.formulario.ver_opt.value=VER;
 document.formulario.submit();
    } 
} 

function LIMPIAR_AGENDAP()
{
  window.document.formulario.tituloeventop.value="";
  window.document.formulario.urleventop.value="http://";

}
/*************************/

function Limpiar_bus_agendap()
{
  window.document.formulario.txt_tituloeventop.value="";
  window.document.formulario.f_dia.value="";
  window.document.formulario.f_mes.value="";
  window.document.formulario.f_anio.value="";
  window.document.formulario.txt_tituloeventop.focus();

}
/*************************/

function DETALLE_EVENTOP(VER,CODIGO,ENVIAR,SECCION)
{

 window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
 	window.document.formulario.id_pre.value=CODIGO;
	window.document.formulario.seccion.value=SECCION;
 window.document.formulario.submit();

}

/*************************/
function GUARDAR_EVENTOP(VER,ENVIAR)
{
if (Validar_eventop(window.document.formulario))
{
	window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
 window.document.formulario.submit();
}
}

function BUSCAR_EVENTOP(VER,ENVIAR)
{
 if (Validar_bus_eventop(window.document.formulario))
 {
  window.document.formulario.enviar.value=ENVIAR;
	window.document.formulario.ver_opt.value=VER;
	window.document.formulario.submit();
 }
}
/************************   **************/ 

