///////////////////////////////////////////////////////
// JavaScript form validation functions script.  
///////////////////////////////////////////////////////
function isBlank(Ctrl) {  // returns true if blank
   if (Ctrl.value.length < 1) return true;
   else if (isEmpty(Ctrl.value)) return true;
   return false; }
function isEmpty(s) { // prevents entering empty strings
   for (var i = 0; i < s.length; i++) {
      var c = s.charAt(i);
      if ((c != ' ') && (c != '\n') && (c != '\t')) return false; 
   }
   return true; }
function isChecked(Ctrl) {
   if (Ctrl.checked) return true;
   return false; }
function isSelected(Ctrl, index){  // returns true if the index indicated is selected
   if (Ctrl.options[index].selected) return true;
   return false; }
function testSimpleEmail(Ctrl){  // returns true if invalid email
   var err=0;
   emailString = Ctrl.value;
   if (window.RegExp) {
      var regexEmail = /^[_a-zA-Z0-9-]+(\.[_a-zA-Z0-9-]+)*@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*\.(([a-zA-Z]{2,3})|(aero|coop|info|museum|name))$/;
      return !regexEmail.test(emailString);
   } else {
      if (emailString.indexOf("@",1) == -1) err=1;  // need @ symbol
      if (emailString.indexOf("@",1) != emailString.lastIndexOf("@")) err=1;  // only one @ symbol
      if (emailString.indexOf(".",3) == -1) err=1;  // need at least one "."
      if (emailString.lastIndexOf(".") == (emailString.length-1)) err=1;  // can't end with a "."
      // check length
      if (err==0) {
         var at = (emailString.indexOf("@"))+1;
         var lastDot = (emailString.lastIndexOf("."))+1;
         // test to make sure there's at least one character between "at" and "lastDot"
         if (lastDot - at == 1) err=1;
      }
   }
   if (err==1) return true;
   return false;
}   // end testSimpleEmail()
function onlyNumbers(str) {
	// clean number
	if (window.RegExp) return str.replace(/[^0-9]*/g,"");
	else {
		var a = '';  var allnum =  '1234567890';
		for (var i = 0; i < str.length; i++) {
			var c = str.charAt(i);
			if (allnum.indexOf(c) > -1) a += c;
		}
	}
	return a;
}

function isNotANumber(Ctrl) {  // returns true if not a number
   if (isNaN(Ctrl.value)) return true;
   else
	{
 	 i=0;
	 var micadena=(Ctrl.value);
	 while (i < micadena.length)
	  {
          car=micadena.substring(i, i+1);
	  if (car=='.' || car==',')
	  {
	  return true;
	  break;
	  }
	  i++;		
	  }	
	}

   return false; }

function czero(Ctrl) {  // returns true if not a number
   if (!isEmpty(Ctrl.value))
   {
       if (!isNaN(Ctrl.value))
       {
       var chkzero=Ctrl.value;
       if (chkzero==0 || chkzero<1900) return true;
       else return false;
       }
   }
}

function errorAlert(e) {
    // If ErrorString "e" has content, there was at least one error; let them know.
   if (e.length > 0) {
      msg  = "____________________________________________________\n\n";
      msg += "  Para continuar usted debe completar: \n";
      msg += "____________________________________________________\n";
      alert(msg + e);
      return false;
   } 
   return true;
} // end errorAlert()

