function check_fecha(Pfecha)
{
  var Vre;
  var Vret;
  Vre = /^\d{1,2}(-|\/)\d{1,2}(-|\/)(\d{2}|\d{4})$/;
  Vret = Pfecha.search(Vre);
  if (Vret == 0)
    {return(check_fecha_1(Pfecha));}
  else
    {return(-1)};
}

function check_fecha_1(Pfecha)
{
  var Vre;
  var Vret;
  Vre = /-|\//;
  Vret = Pfecha.split(Vre);
  if ((Vret[0] < 1) || (Vret[0] > 12))
    {return(-1);};
  if ((Vret[1] < 1) || (Vret[1] > 31))
    {return(-1);};
  else
    {return(check_fecha_2(Pfecha));};
}

function check_fecha_2(Pfecha)
{
  var Vfecha1;
  var Vfecha2;
  var Vstrfecha;
  var Vre;
  var Vret;
  Vre = /-|\//;
  Vret = Pfecha.split(Vre);
  Vfecha1 = new Date();
  Vfecha2 = new Date();
  Vfecha1.setDate(1);
  Vfecha2.setDate(1);
  if (Vret[2].length == 2)
    {Vret[2] = "20" + Vret[2];};
  Vfecha1.setYear(parseInt(Vret[2], 10));
  Vfecha2.setYear(parseInt(Vret[2], 10));
  Vfecha1.setMonth(parseInt(Vret[0], 10) - 1);
  Vfecha2.setMonth(parseInt(Vret[0], 10) - 1);
  Vfecha1.setDate(parseInt(Vret[1], 10));
  if (Vfecha1.getMonth() != Vfecha2.getMonth())
    {return(-1);}
  else
    {return(0);};
}

function orden_fecha(Pfecha)
{
  var Vfecha;
  var Vstrfecha;
  var Vre;
  var Vret;
  Vre = /-|\//;
  Vret = Pfecha.split(Vre);
  Vfecha = new Date();
  Vfecha.setDate(1);
  if (Vret[2].length == 2)
    {Vret[2] = "20" + Vret[2];};
  Vfecha.setYear(parseInt(Vret[2], 10));
  Vfecha.setMonth(parseInt(Vret[0], 10) - 1);
  Vfecha.setDate(parseInt(Vret[1], 10));
  Lyear = Vfecha.getFullYear();
  Lyear = Lyear.toString(10);
  if (Lyear.length == 2)
    {Lyear = "20" + Lyear;}
  Lmonth = Vfecha.getMonth() + 1;
  Lmonth = Lmonth.toString(10);
  if (Lmonth.length == 1)
    {Lmonth = "0" + Lmonth;}
  Lday = Vfecha.getDate();
  Lday = Lday.toString(10);
  if (Lday.length == 1)
    {Lday = "0" + Lday;}
  Vstrfecha = Lyear + "-" + Lmonth + "-" + Lday;
  return(Vstrfecha); 
}

function get_hoy()
{
  Lhoy = new Date();
  Lyear = Lhoy.getYear();
  Lyear = Lyear.toString(10);
  if (Lyear.length == 2)
    {Lyear = "20" + Lyear;}
  Lmonth = Lhoy.getMonth() + 1;
  Lmonth = Lmonth.toString(10);
  if (Lmonth.length == 1)
    {Lmonth = "0" + Lmonth;}
  Lday = Lhoy.getDate();
  Lday = Lday.toString(10);
  if (Lday.length == 1)
    {Lday = "0" + Lday;}
  var Lstrhoy = Lyear + "-" + Lmonth + "-" + Lday;
  return Lstrhoy;
}

function check_hora(Phora)
{
  if (check_int(Phora, 2, 23) == 0)
    {return(0)};
  var Vre;
  var Vret;
  Vre = /^\d{1,2}(:|\.)\d{1,2}$/;
  Vret = Phora.search(Vre);
  if (Vret == 0)
    {return(check_hora_1(Phora));}
  else
    {return(-1)};
}

function check_hora_1(Phora)
{
  var Vre;
  var Vret;
  Vre = /:|\./;
  Vret = Phora.split(Vre);
  if ((Vret[0] < 0) || (Vret[0] > 23))
    {return(-1);};
  if ((Vret[1] < 0) || (Vret[1] > 59))
    {return(-1);};
  else
    {return(0);};
}

function orden_hora(Phora)
{
  var Vstrhora;
  if (check_int(Phora, 2, 23) == 0)
    {
    if (Phora.length == 1)
      {Phora = "0" + Phora;}
    Vstrhora = Phora + ":00";
    return(Vstrhora); 
    }  
  var Vre;
  var Vret;
  Vre = /:|\./;
  Vret = Phora.split(Vre);
  if (Vret[0].length == 1)
    {Vret[0] = "0" + Vret[0];}
  if (Vret[1].length == 1)
    {Vret[1] = "0" + Vret[1];}
  Vstrhora = Vret[0] + ":" + Vret[1];
  return(Vstrhora); 
}

function get_ahora()
{
  Lhoy = new Date();
  Lhoras = Lhoy.getHours();
  Lhoras = Lhoras.toString(10);
  if (Lhoras.length == 1)
    {Lhoras = "0" + Lhoras;}
  Lminutos = Lhoy.getMinutes();
  Lminutos = Lminutos.toString(10);
  if (Lminutos.length == 1)
    {Lminutos = "0" + Lminutos;}
  var Lstrahora = Lhoras + ":" + Lminutos;
  return Lstrahora; 
}

function check_int(Pnum, Plen, Pmax)
{
  var Vre;
  var Vret;
  var Vlen;
  var Vregexp;
  Vregexp = "^\\d{1," + Plen + "}$";
  Vre = new RegExp(Vregexp);
  Vret = Pnum.search(Vre);
  if (Vret == -1)
    {return(-1);};
  if (Pnum > Pmax)
    {return(-1);};
  return(0);
}

function valid_email(Paddress)
  {
  var Vre;
  var Vret;
  Vre = /^[a-zA-Z0-9_\.\-]+@[a-zA-Z0-9_\-]+\.[a-zA-Z0-9_\-\.]+$/;
  Vret = Paddress.search(Vre);
  if (Vret == 0)
    {
    return true
    }
  else
    {
    return false
    }
  }

var VtourW;
function tour(Pkey)
  {
  if (VtourW)
    {VtourW.close();}
  var Vleft, Vtop, Vheight, Vwidth, Vfeatures;
  var Pscroll = "yes";
  Vwidth = 600;
  Vheight = 450;
  Vleft = Math.round((screen.availWidth / 2) - (Vwidth / 2));
  Vtop = Math.round((screen.availHeight / 2) - (Vheight / 2));
  Vfeatures = "left=" + Vleft + ", " +
              "top=" + Vtop + ", " +
              "Width=" + Vwidth + ", Height=" + Vheight + ", resizable=yes";
  if (Pscroll == "no")
    Vfeatures = Vfeatures + ", scrollbars=no"
  else
    Vfeatures = Vfeatures + ", scrollbars=yes";
  Vpage = "tour.php?key=" + Pkey;
  VtourW = window.open(Vpage, "ktktour", Vfeatures);
  VtourW.focus();
  }

var VhelpW;
function get_help(Pkey)
  {
  if (VhelpW)
    {VhelpW.close();}
  var Vleft, Vtop, Vheight, Vwidth, Vfeatures;
  var Pscroll = "yes";
  Vwidth = 600;
  Vheight = 450;
  Vleft = Math.round((screen.availWidth / 2) - (Vwidth / 2));
  Vtop = Math.round((screen.availHeight / 2) - (Vheight / 2));
  Vfeatures = "left=" + Vleft + ", " +
              "top=" + Vtop + ", " +
              "Width=" + Vwidth + ", Height=" + Vheight + ", resizable=yes";
  if (Pscroll == "no")
    Vfeatures = Vfeatures + ", scrollbars=no"
  else
    Vfeatures = Vfeatures + ", scrollbars=yes";
  Vpage = "help.php?key=" + Pkey;
  VhelpW = window.open(Vpage, "ktkhelp", Vfeatures);
  VhelpW.focus();
  }

