function Comparar_Fecha(Obj1,Obj2)
{
   String1 = Obj1;
   String2 = Obj2;
   if (String1.substring(1,2)=="/") 
    String1="0"+String1
   
   if (String1.substring(4,5)=="/")
    String1=String1.substring(0,3)+"0"+String1.substring(3,9)

   if (String2.substring(1,2)=="/") 
    String2="0"+String2

   if (String2.substring(4,5)=="/")
    String2=String2.substring(0,3)+"0"+String2.substring(3,9)

   dia1=String1.substring(0,2);
   mes1=String1.substring(3,5);
   anyo1=String1.substring(6,10);
   dia2=String2.substring(0,2);
   mes2=String2.substring(3,5);
   anyo2=String2.substring(6,10);

   if (dia1 == "08") // parseInt("08") == 10 base octogonal
   dia1 = "8";
   if (dia1 == '09') // parseInt("09") == 11 base octogonal
   dia1 = "9";
   if (mes1 == "08") // parseInt("08") == 10 base octogonal
   mes1 = "8";
   if (mes1 == "09") // parseInt("09") == 11 base octogonal
   mes1 = "9";
   if (dia2 == "08") // parseInt("08") == 10 base octogonal
   dia2 = "8";
   if (dia2 == '09') // parseInt("09") == 11 base octogonal
   dia2 = "9";
   if (mes2 == "08") // parseInt("08") == 10 base octogonal
   mes2 = "8";
   if (mes2 == "09") // parseInt("09") == 11 base octogonal
   mes2 = "9";

   dia1=parseInt(dia1);
   dia2=parseInt(dia2);
   mes1=parseInt(mes1);
   mes2=parseInt(mes2);
   anyo1=parseInt(anyo1);
   anyo2=parseInt(anyo2);

   if (anyo1>anyo2)
    return false;

   if ((anyo1==anyo2) && (mes1>mes2))
    return false;
  
   if ((anyo1==anyo2) && (mes1==mes2) && (dia1>dia2))
     return false;

    return true;
 }

 
function validacion_fechas_reservas()
 {
  
  var desde=document.envio_fechas.fecha_llegada.value;
  var hasta=document.envio_fechas.fecha_salida.value;
  miFechaActual = new Date();
  dia = miFechaActual.getDate();
  mes = parseInt(miFechaActual.getMonth()) + 1;
  ano = miFechaActual.getFullYear();
  hoy = dia + "/" + mes + "/" + ano;
  
  if (document.envio_fechas.fecha_llegada.value == "")
   {
    alert ('No ha seleccionado Fecha de Llegada');
	return false;
   }
  
  if (document.envio_fechas.fecha_salida.value == "")
   {
    alert ('No ha seleccionado Fecha de Salida');
    return false;
   }
  
  if (!Comparar_Fecha(desde,hasta))
   {
    alert('La Fecha de Llegada NO debe ser SUPERIOR a la Fecha de Salida');
    return false;
   }
   
  if (!Comparar_Fecha(hoy,desde))
   {
    alert('No puede seleccionar una fecha INFERIOR a HOY');
    return false;
   }
  
  return true;
 }

function reservas_valores(opt)
 {
  switch (opt) 
   {
	case "1":
	         document.reservas.action='club_reservas_guardar.php';
		     break;
	
	case "2":
	         document.reservas.action='club_reservas_fechas.php';
		     break;
	
	case "3":
	         document.reservas.action='club_reservas_detalle.php';
		     break;
	
	case "4":
	         document.reservas.action='';
		     break;
	    
	default:
		     break;
  }
 
  document.reservas.submit();
  return false;
 }

function validacion_reservas()
 {
  if (document.reservas.telefono_asociado.value =="")
   {
    alert('Debe ingresar un telefono de contacto');
	document.reservas.telefono_asociado.focus();
	return false;
   }
  
  var cont=0;
  var asosciado=0;
  p = parseInt(document.reservas.cant.value);
  for(i=0; i<p; i++)
   {
    var tipo =eval("document.reservas.tipus"+i+".value");
    var sexo =eval("document.reservas.sexo"+i);
    var documento =eval("document.reservas.docu"+i+".value");
    var edad =eval("document.reservas.edad"+i+".value");
	if(tipo==0 && i==0)
     {
      alert('Debe escoger por lo menos un usuario de la lista y comenzar desde el primero');
      eval ("document.reservas.tipus"+i+".focus()");
      return false;
     }
	else
	 {	
	  if(tipo != 0)
	   {
		 var f = sexo[0].checked;
	     var m = sexo[1].checked;
	     if (!f && !m)
          {
	       alert('Debe escoger el sexo del usuario');
           return false;
          }
	     
		 if (tipo == 1)
		  asosciado++;

		 
	     if (documento == "")
          {
           alert('Debe ingresar el documento del usuario');
           eval ("document.reservas.docu"+i+".focus()");
		   return false;
          }
	  
		 if (edad==0)
		  {
            alert('Debe seleccionar la edad del usuario');
            eval ("document.reservas.edad"+i+".focus()");
		    return false;
          }
		cont++;  
	   }   
	 }
   }
 
  /*if (asosciado>1)
   {
    alert('No deben seleccionar mas de un asociado');	
	return false;
   }*/
  
  var tipo_cab=document.reservas.tipo_cab.value;
  if (tipo_cab==2 && cont<5)
   {
    alert('Debe seleccionar minimo 5 usuarios');
	eval ("document.reservas.tipus"+cont+".focus()");
	return false;
   }
  
  if (tipo_cab==3 && cont<4)
   {
    alert('Debe seleccionar minimo 4 usuarios');
	eval ("document.reservas.tipus"+cont+".focus()");
	return false;
   }
 
  return true;
 }
