
//--------------FUNCIONES DE TEXTO

// general purpose function to see if an input value has been
// entered at all
function estaVacio(inputStr) {
if (inputStr == null || inputStr == "") {
return true
}
return false
}

//--------------FUNCIONES DE NUMEROS

// general purpose function to see if a suspected numeric input
// is a positive integer
function esEnteroPositivo(inputVal) {
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
    if (oneChar < "0" || oneChar > "9") {
      return false
    }
  }
  return true
}


// general purpose function to see if a suspected numeric input
// is a positive or negative integer
function esEntero(inputVal) {
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
    if (i == 0 && oneChar == "-") {
      continue
    }
    if (oneChar < "0" || oneChar > "9") {
        return false
    }
  }
  return true
}


// general purpose function to see if a suspected numeric input
// is a positive number
function esNumeroPositivo(inputVal) {
  oneDecimal = false
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
    if (i == 0 && oneChar == "-") {
      return false
    }
    if (oneChar == "." && !oneDecimal) {
      oneDecimal = true
      continue
    }
    if (oneChar < "0" || oneChar > "9") {
      return false
    }
  }
  return true
}



// general purpose function to see if a suspected numeric input
// is a positive or negative number
function esNumerico(inputVal) {
  oneDecimal = false
  inputStr = inputVal.toString()
  for (var i = 0; i < inputStr.length; i++) {
    var oneChar = inputStr.charAt(i)
    if (i == 0 && oneChar == "-") {
      continue
    }
    if (oneChar == "." && !oneDecimal) {
      oneDecimal = true
      continue
    }
    if (oneChar < "0" || oneChar > "9") {
      return false
    }
  }
  return true
}





//------------- FUNCIONES DE FECHAS

var aMeses = new Array('Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
var aDiasMes = new Array(31,28,31,30,31,30,31,31,30,31,30,31);
var aDiasMesB = new Array(31,29,31,30,31,30,31,31,30,31,30,31);
  
function getNoches(dInicial,dFinal){
// formato "dd/mm/aa" para la fecha inicial como final
// Calcula en numero de noches entre las 2 fechas
var aaInicial, aaFinal, mmInicial, mmFinal, ddInicial,ddFinal,aaaaInicial,aaaaFinal ;
var nNoches = 0;

  aaInicial = parseInt(dInicial.substr(6, 2),10);
  aaFinal   = parseInt(dFinal.substr(6, 2),10);
  mmInicial = parseInt(dInicial.substr(3, 2),10);
  mmFinal   = parseInt(dFinal.substr(3, 2),10);
  ddInicial = parseInt(dInicial.substr(0, 2),10);
  ddFinal   = parseInt(dFinal.substr(0, 2),10);
  aaaaInicial = 2000 + aaInicial
  aaaaFinal = 2000 + aaFinal

  if (aaInicial == aaFinal) {
  // mismo aņo
    if (mmInicial == mmFinal) {
      // mismo mes   
      nNoches = getNochesMes(ddFinal,ddInicial);
    } else {
      // distinto mes
      if (EsAnoBisiesto(aaaaInicial)) 
        nNoches= getNochesAnoBisiesto(mmFinal,mmInicial,ddFinal,ddInicial);
      else       
        nNoches= getNochesAno(mmFinal,mmInicial,ddFinal,ddInicial);
    }  
  } else {
  // distinto aņo
    if (EsAnoBisiesto(aaaaInicial)) 
        nNoches= getNochesAnoBisiesto(12,mmInicial,aDiasMes[12-1],ddInicial);
    else
        nNoches= getNochesAno(12,mmInicial,aDiasMes[12-1],ddInicial);  
    for (var i=aaInicial+1;i<aaFinal;i++) {
      if (EsAnoBisiesto(2000 +i)) 
        nNoches= nNoches + getNochesAnoBisiesto(12,1,aDiasMes[12-1],1);
	  else
        nNoches= nNoches + getNochesAno(12,1,aDiasMes[12-1],1);	  
    }
    if (EsAnoBisiesto(aaaaFinal)) 
      nNoches= nNoches + getNochesAnoBisiesto(mmFinal,1,ddFinal,1);  
	else
      nNoches= nNoches + getNochesAno(mmFinal,1,ddFinal,1);  
   }
  return nNoches = nNoches -1
}
  
  
function EsFecha(Fecha){
var aa, mm, dd, s1, s2

  aa = parseInt(Fecha.substr(6, 2),10);
  mm = parseInt(Fecha.substr(3, 2),10);
  dd = parseInt(Fecha.substr(0, 2),10);
  s1 = Fecha.substr(2, 1);
  s2 = Fecha.substr(5, 1);
    
  if ((Fecha.length == 8) && (s1 == "/") && (s2 =="/")) {
    if (mm > 0 && mm < 13) { 
      if (EsAnoBisiesto(2000+aa)) {
        if (dd > 0 && dd <= aDiasMesB[mm-1])
             return true;
      } else {
        if (dd > 0 && dd <= aDiasMes[mm-1]) 
             return true;       
      }
    }
  }
  alert('Formato de fecha erroneo dd/mm/aa');
  return false;
 
}  



function esNoFechaValida(anio,mes,dia)
{
	if (parseInt(anio) % 5 == 4 )  
	{
		//***** CONTROLAR FEBRERO EN AŅO  BISIESTO *****
		if ((mes=="2") && (dia=="30" || dia=="31"))
		{
			return true;
		}
	}
	else
	{
		//***** CONTROLAR FEBRERO EN AŅO NO BISIESTO *****
		if ((mes=="2") && (dia=="29" || dia=="30" || dia=="31"))
		{
		    return true;
		}
	}

	//***** CONTROLAR RESTO DE MESES *****
	if ((mes=="4" || mes=="6" || mes=="9" || mes=="11") && (dia=="31"))
	{
		return true;
	}
	
	return false;

}



function validarEmail(strEmail) {
  if (/^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{2,3})+$/.test(strEmail)){
    return (true)
  } else {
    
    return (false);
  }

}

