 
 
//******************  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_calendario(theform)
<!-- Validacion de Formulario INGRESO CALENDARIO -->
{
	var checkStr = theform.tituloevento.value;
 
//alert(checkStr5);
  if (checkStr.length==0)
	{
    alert("Ingrese su Titulo, por favor.");
    theform.tituloevento.focus();
    return (false);
	}	
	
 
	
	//*****************  validacion de textarea
theform.descripcionevento.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;
	}
}
//************************************ 
 
 
 var checkStr = theform.urlevento.value;
 
   if (checkStr=='http://')
	{
    alert("Ingrese URL de Novedades, por favor.");
    theform.urlevento.focus();
    return (false);
	}	
   
//Valido las fechas**********************************
if (theform.diaini.value=="")
  {	alert("Ingrese Día de Inicio, por favor.");
		theform.diaini.focus();
		return false;
	 }
	if (theform.mesini.value=="")
   {alert("Ingrese Mes de Inicio, por favor.");
		theform.mesini.focus();
		return false;
	}
	if (theform.anoini.value=="") {
		alert("Ingrese Año de Inicio, por favor.");
		theform.anoini.focus();
		return false;
	}
  	d=theform.diaini.value;
  	m=theform.mesini.value;
  	a=theform.anoini.value;
	
  	if (!check_date(d,m,a))
    {  alert ("Fecha no permitida.");
		   theform.diaini.focus();
		   return false;
  	}

   if (theform.diafin.value=="")
    {
		alert("Ingrese Día Fin, por favor.");
		theform.diafin.focus();
		return false;
	  }
	  if (theform.mesfin.value=="")
    {
		 alert("Ingrese Mes Fin, por favor.");
		 theform.mesfin.focus();
		 return false;
	   }
	  if (theform.anofin.value=="")
    {
		alert("Ingrese Año Fin, por favor.");
		theform.anofin.focus();
		return false;
	  }
  	d=theform.diafin.value;
  	m=theform.mesfin.value;
  	a=theform.anofin.value;
  	if (!check_date(d,m,a)){
		alert ("Fecha no permitida.");
		theform.diafin.focus();
		return false;
  	}
    d=theform.diaini.value;
  	m=theform.mesini.value;
  	a=theform.anoini.value;
  	
  	df=theform.diafin.value;
  	mf=theform.mesfin.value;
  	af=theform.anofin.value;
  	
  	if (!MayorFecha(d,m,a,df,mf,af))
    {
  		alert ("La Fecha de Inicio no debe ser mayor a la Fecha Fin.");
  		theform.diaini.focus();
  		return false;
   	 }
 
		 
 return (true);
}

/*************************/
/************************   OPCIONES VER GENERAL **************/ 
/*************************/
 

function Ir_derecho(VER,DERECHO)
{
 //alert(VER);
    window.document.formulario.ver_opt.value="";
    window.document.formulario.ver_opt.value=VER;
//	window.document.formulario.nom_seccion.value=NOM_SECCION;
	window.document.formulario.derecho.value=DERECHO;
	//alert(VER);
	//alert(NOM_SECCION);
	//alert(DERECHO);
	window.document.formulario.submit();

} 


/*************************/
/************************  OPCIONES DE USUARIO **************/ 
/*************************/

function EDITAR_CALENDARIO(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_calendario(CODIGO,ENVIAR,VER){ 
   if (confirm('¿Estas seguro de ELIMINAR este EVENTO?')){ 
 
	 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_CALENDARIO(VER,CODIGO,ENVIAR)
{
if (Validar_calendario(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_CALENDARIO(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_CALENDARIO_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_CALENDARIO(VER,ENVIAR)
{
if (Validar_calendario(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_CALENDARIO(CODIGO)
{
 
  window.document.frm_home_calendario.id_pre.value=CODIGO;
	//window.document.frm_home_calendario.ver_opt.value=VER;
	//alert(ENVIAR);
  //alert(CODIGO);
  window.document.frm_home_calendario.action='interna.php';
	window.document.frm_home_calendario.submit();
}

function SGT(MES,ANIO)
{
 
  window.document.frm_home_calendario.mes.value=MES;
  window.document.frm_home_calendario.anio.value=ANIO;
	//window.document.frm_home_calendario.ver_opt.value=VER;
	//alert(ENVIAR);
  //alert(CODIGO);
  window.document.frm_home_calendario.action='index.php';
	window.document.frm_home_calendario.submit();
}
/************************   **************/ 
/*************************/

function focus(){
	window.document.formulario.login.focus();
}
