//Detremina si vacio es Ok
var defaultEmptyOK = false
// decimal point character differs by language and culture
var decimalPointDelimiter = "."

function validateEmail(emailStr) {
	  var emailexpr = new RegExp("^[A-Za-z_0-9\.\-]+@[A-Za-z_0-9\.\-]+\.[a-zA-Z]{2,3}$")
	  if (emailStr.match(emailexpr)!=null)
		return false
	  else
		return true
	}

function validateSpaces(item) {
	var num = " ";
	for (var intLoop = 0; intLoop < item.value.length; intLoop++) {
		if (num.indexOf(item.value.charAt(intLoop)) != -1) return true;
	}
	return false;
}

function validateNumber(item) {
	var num = "0123456789";
	for (var intLoop = 0; intLoop < item.value.length; intLoop++) {
		if (num.indexOf(item.value.charAt(intLoop)) == -1) return true;
	}
	return false;
}

function validateFloatNumber(item) {
	var num = ".0123456789";

	for (var intLoop = 0; intLoop < item.value.length; intLoop++) {
		if (num.indexOf(item.value.charAt(intLoop)) == -1) return true;
	}
	if (item.value.indexOf(".")!=item.value.lastIndexOf(".")) return true;
	return false;
}

function validateDate(item) {
	var s = item.value;
	s = s.substr(0,10);
	//item.value = s;
	var result = true;
	var parts = new Array();

	if (s == "") return true;
	if (s.indexOf("/")!= -1) ch = "/"; 
	else if (s.indexOf("-") != -1 ) ch = "-";
	else result = false;
	if (result) {
		parts = s.split(ch);
		if (parts[0].length < 4) return false;
		if (parts.length == 3) {
			var objDate = new Date (s);
			if (parts[1] != objDate.getMonth() + 1) return false;
			if (parts[2] != objDate.getDate()) return false;
			if (parts[0] != objDate.getFullYear()) return false;
			result = true;
		} else result = false;
	}
	return result;
}

function PTAcheckDigit(item)
{		
	//Base para calcular el checkDigit
	var base = 7;
	var strNum = item.value
	//Le quita el último digito parea hacer el calculo
	//Ya que el último digito debe ser el digito de chequeo
	strNum = strNum.substring(0,strNum.length - 1);
	//Redondea el residuo de dividir el número en la base
	return Math.round(strNum % base);
}

//Funcion Que permite abrir una ventana Nueva
function openNewWindow(theURL,winName,features) 
{ //v2.0
var objLst = window.open(theURL,winName,features);  
}

// isFloat (STRING s [, BOOLEAN emptyOK])
// 
// True if string s is an unsigned floating point (real) number. 
//
// Also returns true for unsigned integers. If you wish
// to distinguish between integers and floating point numbers,
// first call isInteger, then call isFloat.
//
// Does not accept exponential notation.
//
// For explanation of optional argument emptyOK,
// see comments of function isInteger.

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;
}

function isEmpty(s)
{   return ((s == null) || (s.length == 0))
}


// Returns true if character c is a digit 
// (0 .. 9).

function isDigit (c)
{   return ((c >= "0") && (c <= "9"))
}

function trim(inputString) {
   // Removes leading and trailing spaces from the passed string. Also
   // removes consecutive spaces and replaces it with one space.
   var retValue = inputString;
   var ch = retValue.substring(0, 1);
   while (ch == " ") { // Check for spaces at the beginning of the string
      retValue = retValue.substring(1, retValue.length);
      ch = retValue.substring(0, 1);
   }
   ch = retValue.substring(retValue.length-1, retValue.length);
   while (ch == " ") { // Check for spaces at the end of the string
      retValue = retValue.substring(0, retValue.length-1);
      ch = retValue.substring(retValue.length-1, retValue.length);
   }
   while (retValue.indexOf("  ") != -1) { // Note that there are two spaces in the string - look for multiple spaces within the string
      retValue = retValue.substring(0, retValue.indexOf("  ")) + retValue.substring(retValue.indexOf("  ")+1, retValue.length); // Again, there are two spaces in each of the strings
   }
   return retValue; // Return the trimmed string back to the user
} // Ends the "trim" function
