function timestamp ( date )
{
  var Stamp = new Date (date);
  return parseInt(Stamp.getTime(),10);
}

function DateDiference( date1, date2 )
{
  var Date1 = new Date( date1 );
  var Date2 = new Date( date2 );
  return (Date2 - Date1);
}

function isValidDate( varDate )
{
  arrayDate = varDate.value.match(/^((?:19|20)\d\d)[ /.](0[1-9]|1[012])[ /.](0[1-9]|[12][0-9]|3[01])$/);
  // Parte la fecha en 4 elementos [0] => La fecha, [1]=> El año, [2] => Mes, [3] => Dia

  if ( arrayDate == null)
    return false;

  if ( arrayDate[3] == 31 && (arrayDate[2] == 4 || arrayDate[2] == 6 || arrayDate[2] == 9 || arrayDate[2] == 11)) {
    return false; // 31st of a month with 30 days
  } else if (arrayDate[3] >= 30 && arrayDate[2] == 2) {
    return false; // February 30th or 31st
  } else if (arrayDate[2] == 2 && arrayDate[3] == 29 && !(arrayDate[1] % 4 == 0 && (arrayDate[1] % 100 != 0 || arrayDate[1] % 400 == 0))) {
    return false; // February 29th outside a leap year
  } else {
    return true; // Valid date
  }
}

function isValidPassword(id)
{
  var campo = document.getElementById(id);
  var regexp = /^\w*(?=.{8,16})(?=\w*\d)(?=\w*[a-z])\w*$/;
  return regexp.test(campo.value)
}

function isValidEmail(id)
{
  var campo = document.getElementById(id);
  var regexp = /^([a-zA-Z0-9_'+*$%\^&!\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9:]{2,4})+$/;
  return regexp.test(campo.value)
}

function isImage(id)
{
  var campo = document.getElementById(id);
  var regexp = /^.*(\.(gif|jpg|jpeg|png|GIF|PNG|JPG|JPEG))$/;
  return regexp.test(campo.value)
}

function isXLSFile(id)
{
  var campo = document.getElementById(id);
  var regexp = /^.*(\.(xls|XLS))$/;
  return regexp.test(campo.value)
}

function isValidURL(id) {
  var campo = document.getElementById(id);
  var regexp = /^http:\/\/\w+(\.\w+)*\.\w{2,3}$/;
  return regexp.test(campo.value);
}

/**
* function isEmpty( string id )
*
* parametros .-
*   id: nombre del elemento en el documento, debe ser unico
*
* valor de retorno: regresa true si el elemento indicado esta vacio, false en caso contario
* comentario: valida mediante una expresion regular el contenido del elemento
*/

function isEmpty(id){

  var campo = document.getElementById(id);
  var exp = /[^\s\t\n\r\f\v]/;
  return !exp.test(campo.value);
}

function haveSpaces( id )
{
  var campo = document.getElementById(id);
  var exp = /[\s\t\n\r\f\v]/;
  return exp.test(campo.value);
}

function isEmployeeId ( id )
{
  var campo = document.getElementById(id);
  return true;

}



/**
* function isAccount ( string id , boolean requerido )
*
* parametros .-
*   id: nombre del elemento en el documento, debe ser unico
*   requerido: indica si el elemento del documento es requerido
*
* valor de retorno: regresa true si es una cuenta valida, falso en caso contrario
* comentarios: valida una cuenta valida de 8 digitos
*/

function isAccount(id,requerido){

  var campo = document.getElementById(id);
  var exp = /[\D]/;     /*  [\D] = cualquier caracter que no se numerico  */

  if(requerido){
    if ( isEmpty(id) )
      return false;
  }

  if (exp.test(campo.value))
      return false;

  return !(campo.value.length < 8);
}

function isAccountReg5(id,requerido){

  var campo = document.getElementById(id);
  var exp = /[\D]/;     /*  [\D] = cualquier caracter que no se numerico  */

  if(requerido){
    if ( isEmpty(id) )
      return false;
  }

  if (exp.test(campo.value))
      return false;

  if(campo.value.substr(0,1) != "5")
	  return false;

  return !(campo.value.length < 8);
}

/**
* function isCellphone( string id, boolean requerido )
*
* parametros .-
*   id: nombre del elemento en el documento, debe ser unico
*   requerido: indica si el elemento del documento es requerido
*
* valor de retorno: regresa true si es un celular valido, false en caso contrario
* comentarios:
*/

function isCellphone(id, requerido){

  var campo = document.getElementById(id);
  var exp = /[\D]/;     /*  [\D] = cualquier caracter que no se numerico  */

  if(requerido){
    if ( isEmpty(id) )
      return false;
  }

  if (exp.test(campo.value))
      return false;

  return !(campo.value.length < 10);
}

/**
* function isNumber( string id, boolean requerido )
*
* parametros .-
*   id: nombre del elemento en el documento, debe ser unico
*   requerido: indica si el elemento del documento es requerido
*
* valor de retorno: regresa true si es un numero valido, false en caso contrario
* comentarios:
*/

function isNumber(id, requerido){

  var campo = document.getElementById(id);

  var exp = /[\D]/;     /*  [\D] = cualquier caracter que no se numerico  */

  if(requerido){
    if ( isEmpty(id) )
      return false;
  }
  return !exp.test(campo.value);
}

/**
* fucntion foco( string id )

*	paranetros .-
*		id: nombre del elemento en el documento, debe ser unico
*
* valor de retorno: no regresa nada
* comentario: coloca el cursor en el campo indicado
*/

function isCreditCard( id, requerido){

	var campo = document.getElementById(id);

	if(requerido){
	  if(isEmpty(id))
		return false;
	}

	if(isNaN(campo.value))
	  return false;

	return (campo.value.length == 15 || campo.value.length == 16);
}


/**
 * function isFloat( string id, boolean requerido )
 * parametros .-
 *   id: nombre del elemento en el documento, debe ser unico
 *   requerido: indica si el elemento del documento es requerido
 *
 * valor de retorno: regresa true si es un numero con 2 decimales, false en caso contrario
 * comentarios:
 */

function isFloat(id, requerido){

  var campo = document.getElementById(id);

  var exp = /^\d+\.\d\d$/; // numero flotante con dos decimales

  if(requerido){
    if ( isEmpty(id) )
      return false;
  }

  return (exp.test(campo.value));

}

/**
 * function trimString ( str )
 * parametros
 *  str: cadena a la que se le removeran los espacios en blanco al inicio y al final
 *
 * valor de retorno: cadena
 */
function trimString (str)
{
  str = this != window? this : str;
  return str.replace(/^\s+/g, '').replace(/\s+$/g, '');
}


/**
 * function isRFC ( string id, boolean requerido )
 * parametros .-
 *   id: nombre del elemento en el documento, debe ser unico
 *   requerido: indica si el elemento del documento es requerido
 *
 * valor de retorno: regresa true si es un rfc valido formado por 4 letras y 6 numeros, false en caso contrario
 * comentarios:
 */
function isRFC(id, requerido){

  var campo = document.getElementById(id);

  //var exp = /([a-zA-Z]){4}\d{6}/;		// rfc con 4 letras y 6 digitos
  var exp = /([a-z]){4}\d{6}/i;		// rfc con 4 letras y 6 digitos

  if(requerido){
    if ( isEmpty(id) )
      return false;
  }

  return (exp.test(campo.value));
}

function YUICalendarDateToANSIDate( args )
{
  var dates = args[0];
  var date = dates[0];
  var year = date[0], month = date[1], day = date[2];

  return year + "/" + ( (month <10) ? "0"+month : month ) + "/" + ( ( day <10) ? "0" + day : day );
}

function HumanReadableDateToANSIDate( date )
{
  var year  = date.getFullYear();
  var month = date.getMonth() + 1;
  var day   = date.getDate();

  return year + "/" + ( (month <10) ? "0"+month : month ) + "/" + ( ( day <10) ? "0" + day : day );
}



function isIP(id){

  var campo = document.getElementById(id);

  var exp = /(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/

  return (exp.test(campo.value));

}
