var whitespace = " \t\n\r";
var defaultEmptyOK = false;
var decimalPointDelimiter = ".";

function trim(s) {
  var rgexpi = /^ +/; var rgexpf = / +$/;
  tstr = s.replace(rgexpi,'');
  tstr = tstr.replace(rgexpf,'');
  return tstr;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}

function isWhitespace (s)
{   var i;
  if (isEmpty(s)) return true;
  for (i = 0; i < s.length; i++) {
  var c = s.charAt(i);
  if (whitespace.indexOf(c) == -1) return false;
  }
  return true;
}

function isEmail (s)
{   if (isEmpty(s))
       if (isEmail.arguments.length == 1) return defaultEmptyOK;
       else return (isEmail.arguments[1] == true);

    // is s whitespace?
    if (isWhitespace(s)) return false;

    // there must be >= 1 character before @, so we
    // start looking at character position 1
    // (i.e. second character)
    var i = 1;
    var sLength = s.length;

    // look for @
    while ((i < sLength) && (s.charAt(i) != "@"))
    { i++
    }

    if ((i >= sLength) || (s.charAt(i) != "@")) return false;
    else i += 2;

    // look for .
    while ((i < sLength) && (s.charAt(i) != "."))
    { i++
    }

    // there must be at least one character after the .
    if ((i >= sLength - 1) || (s.charAt(i) != ".")) return false;
    else return true;
}

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function isInteger (s)

{   var i;

    if (isEmpty(s))
       if (isInteger.arguments.length == 1) return defaultEmptyOK;
       else return (isInteger.arguments[1] == true);

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);

        if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

function isFloat (s)

{   var i;
    var seenDecimalPoint = false;

    if (isEmpty(s))
       if (isFloat.arguments.length == 1) return defaultEmptyOK;
       else return (isFloat.arguments[1] == true);

    if (s == decimalPointDelimiter) return false;

    // Search through string's characters one by one
    // until we find a non-numeric character.
    // When we do, return false; if we don't, return true.

    for (i = 0; i < s.length; i++)
    {
        // Check that current character is number.
        var c = s.charAt(i);

        if ((c == decimalPointDelimiter) && !seenDecimalPoint) seenDecimalPoint = true;
        else if (!isDigit(c)) return false;
    }

    // All characters are numbers.
    return true;
}

//CREATE AN ARRAY
function SetNameArray(item)
{
this.length = item
return this
}
//SET MONTH AND DAY NAME ARRAYS
Month = new SetNameArray(12)
Month[1] = "enero"
Month[2] = "febrero"
Month[3] = "marzo"
Month[4] = "abril"
Month[5] = "mayo"
Month[6] = "junio"
Month[7] = "julio"
Month[8] = "agosto"
Month[9] = "septiembre"
Month[10] = "octubre"
Month[11] = "noviembre"
Month[12] = "diciembre"
Day = new SetNameArray(7)
Day[1] = "Domingo"
Day[2] = "Lunes"
Day[3] = "Martes"
Day[4] = "Miércoles"
Day[5] = "Jueves"
Day[6] = "Viernes"
Day[7] = "Sábado"
//CALC THE DATE INFORMATION
function TodaysDate(theDate)
{
var thisday = Day[theDate.getDay() + 1]
var thismonth = Month[theDate.getMonth() + 1]
var todayDate=new Date()
var thisdate=todayDate.getDate()
var thisyear=todayDate.getYear()
thisyear = thisyear % 100;
thisyear = ((thisyear < 50) ? (2000 + thisyear) : (1900 + thisyear))
return thisday + " " + thisdate + " de " + thismonth + " de "  + thisyear
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_setTextOfLayer(objName,x,newText) { //v4.01
  if ((obj=MM_findObj(objName))!=null) with (obj)
    if (document.layers) {document.write(unescape(newText)); document.close();}
    else innerHTML = unescape(newText);
}

function trim(s) {
  var rgexpi = /^ +/; var rgexpf = / +$/;
  tstr = s.replace(rgexpi,'');
  tstr = tstr.replace(rgexpf,'');
  return tstr;
}

function sendval(whichform) {
  var i; var o;
  var dosubmit = (1==1);
  if (whichform == null || whichform == '') whichform = 'TrueForm';
  o = document.forms[whichform]; /*o = MM_findObj(whichform);*/ if (!o) return;
  // regresar valores originales, en caso de que haya un BackButtonReload
  // o.idcat.value = of_idcat; o.idprod.value = of_idprod; o.iddist.value = of_iddist; o.letra.value = of_letra;
  // o.search.value = of_search; o.mov.value = of_mov; o.page.value = of_page;
  for (i= 1; i<sendval.arguments.length; i+=2) {
    if (sendval.arguments[i] == 'clear') {
      for (var i2=0; i2<o.elements.length; i2++) if (o.elements[i2].value && o.elements[i2].name != 'idusuario' && o.elements[i2].name != 'iddist') o.elements[i2].value = '';
      i++;
      continue;
    }
    else if (sendval.arguments[i] == 'nosubmit') {
      i++;
      dosubmit = (1==0);
    } else {
      var item = o[sendval.arguments[i]]; if (!item) continue;
      if (item.type=="select-one") {
        for (var j=0; j<item.length; j++) {
          if (item[j].value == sendval.arguments[i+1]) {
            item[j].selected=true;
          }
        }
      }
      else {
        item.value = sendval.arguments[i+1];
      }
    }
  }
  if (dosubmit) o.submit();
}

function sendvalpage(page,whichform) {
  var tstr = 'sendval(\'' + whichform + '\'';
  for (var i=2; i<sendvalpage.arguments.length; i++)
    tstr += ', \'' + sendvalpage.arguments[i] + '\'';

  tstr += ')';
  var o = document.forms[(whichform==''?'TrueForm':whichform)];
  o.action = page;
  eval (tstr);
}

function checafecha(ds,ms,as) {
  var days = new Array();
  var d,m,a;
  days[1] = 31; days[2] = 28; days[3] = 31; days[4] = 30; days[5] = 31; days[6] = 30;
  days[7] = 31; days[8] = 31; days[9] = 30; days[10] = 31; days[11] = 30; days[12] = 31;
  if (isNaN(parseInt(ds)) || isNaN(parseInt(ms)) || isNaN(parseInt(as)) ) return (1==0);
  else { d = parseInt(ds); m = parseInt(ms); a = parseInt(as) }

  if (a < 1900) return (1==0);
  if (m < 1 || m > 12) return (1==0);
  if ( (a % 4 == 0 && !(a % 100 == 0)) || a % 400 == 0 ) days[2] = 29;
  if ( d < 0 || d > days[m]) return (1==0);
  return (1==1);
}

function nwnd(url) {
  var s1=self;
  var nw = window.open('','','location=no, resizable=yes');
  if (nw != null) {
    nw.focus();
    nw.opener = s1;
    nw.location=url;
  }
  return nw;
}

function inOver(who) {
    var clase = who.className;
    if (clase == 'whiteblur')  who.className='whiteover';
    else if (clase == 'whitemnyblur')  who.className='whitemnyover';
    else {
      who.interfazBG = new Array;
      who.interfazBG[0] = who.style.backgroundColor;
      who.style.backgroundColor='#DFDFDF';
    }
}
function inOut(who) {
    var clase = who.className;
    if (clase == 'whiteover')  who.className='whiteblur';
    else if (clase == 'whitemnyover')  who.className='whitemnyblur';
    else {
      if (who.interfazBG) who.style.backgroundColor=who.interfazBG[0];
    }
}