/****************************************************************************************
* Función que verifica que la fecha pasada sea correcta.
* la función recibe la fecha en formato dd/mm/aaaa
****************************************************************************************/
function isDate(dateStr) {
var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
var matchArray = dateStr.match(datePat); // is the format ok?

	// Verifica que la fecha tenga datos.
	if (matchArray == null) return false;

	day = matchArray[1];
	month = matchArray[3]; 
	year = matchArray[5];

	// Verifica que el mes sea correcto
	if (month < 1 || month > 12) return false;

	// Verifica el día.
	if (day < 1 || day > 31) return false;
	if ((month==4 || month==6 || month==9 || month==11) && day==31) return false;

	// Febrero.
	if (month == 2) { // check for february 29th
		var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
		if (day > 29 || (day==29 && !isleap)) return false;
	}

	return true; 

}

/****************************************************************************************
* Función que verifica que el Email pasado tenga formato correcto y no esté en blanco.
****************************************************************************************/
function ValidarEmail(checkThisEmail){
var myEMailIsValid = true;
var myAtSymbolAt = checkThisEmail.indexOf('@');
var myLastDotAt = checkThisEmail.lastIndexOf('.');
var mySpaceAt = checkThisEmail.indexOf(' ');
var myLength = checkThisEmail.length;


// at least one @ must be present and not before position 2
// @yellow.com : NOT valid
// x@yellow.com : VALID

if (myAtSymbolAt < 1 ) 
 {myEMailIsValid = false}


// at least one . (dot) afer the @ is required
// x@yellow : NOT valid
// x.y@yellow : NOT valid
// x@yellow.org : VALID

if (myLastDotAt < myAtSymbolAt) 
 {myEMailIsValid = false}

// at least two characters [com, uk, fr, ...] must occur after the last . (dot)
// x.y@yellow. : NOT valid
// x.y@yellow.a : NOT valid
// x.y@yellow.ca : VALID

if (myLength - myLastDotAt <= 2) 
 {myEMailIsValid = false}


// no empty space " " is permitted (one may trim the email)
// x.y@yell ow.com : NOT valid

if (mySpaceAt != -1) 
 {myEMailIsValid = false}

return myEMailIsValid;

}
