
function resetForm(frm)
{
  document.forms[frm].reset();
}

function Trim(inString)
{
  while (inString.length > 0) 
  {
    if (inString.substring(0, 1) != " ")
      break;
    inString = inString.substring(1, inString.length);
  }
  
  while (inString.length > 0) 
  {
    if (inString.substring(inString.length - 1, inString.length) != " ")
      break;
    inString = inString.substring(0, inString.length - 1);
  }

  return inString;
}

function IsPhone(phone_text)
{
  var s=phone_text;
  var re=/^(\d{3}-\d{3}-\d{4}|\d{3}-\d{4})$/;
  return re.test(s);  
}

function IsAlphaNumeric(inString)
{
	var nChar, i;
	for (i = 0;i < inString.length;i++)
	{
		nChar = (inString.toLowerCase()).charCodeAt(i);
		if (!((nChar > 47 && nChar < 58) || (nChar > 96 && nChar < 123) || nChar == 32))
			return false;
	}
	return true;
}

function StripNonNumeric(strTemp)
{
	var i, sNumeric;
	sNumeric="";
	for (i = 0;i < strTemp.length;i++)
		if ( (strTemp.charCodeAt(i)==46) || ((strTemp.charCodeAt(i) > 47) && (strTemp.charCodeAt(i) < 58)) )
			sNumeric += strTemp.charAt(i);	
	return sNumeric;
}

function IsDate(inString)
{
inString += "    "; //add some padding so call is not made out of bounds
outString = "";
endString = "";
if (Trim(inString).length == 2)
	return false;
if (inString.indexOf("/") == 0)
    outString = "00/";
if (inString.indexOf("/") == 1)
    outString = "0" + inString.charAt(0) + "/";
if (inString.indexOf("/") == 2)
    outString = inString.substr(0,3);
endString = inString.substring(inString.indexOf("/") + 1,inString.length);
if (endString.indexOf("/") == 0)
    outString += "00/";
if (endString.indexOf("/") == 1)
    outString += "0" + endString.charAt(0) + "/";
if (endString.indexOf("/") == 2)
    outString += endString.substr(0,3);
endString = endString.substring(endString.indexOf("/") + 1,endString.length);
endString = Trim(endString);
outString += endString;
if (isDate(outString.substr(3,2),outString.substr(0,2),outString.substr(6,4)))
	return true;
return false;
}

function y2k(number) { return (number < 1000) ? number + 1900 : number; }

function isDate (month,day,year) 
{
    var today = new Date();
    year = ((!year) ? y2k(today.getYear()):year);
    month = ((!month) ? today.getMonth():month-1);
    if (!day) return false
    var test = new Date(year,month,day);
    if ( (y2k(test.getYear()) == year) &&
         (month == test.getMonth()) &&
         (day == test.getDate()) )
        return true;
    else
        return false
}

function IsEmail(strValue) 
{
if (strValue.indexOf(" ") != -1)
    return false;
if (strValue.indexOf("@") == -1)
    return false;
if (strValue.indexOf("@") == 0)
    return false;
if (strValue.indexOf("@") == (strValue.length-1))
    return false;
if (strValue.length > 1)
	endString = strValue.substring(strValue.indexOf("@") + 1,strValue.length); 
else
	return false;
if (endString.indexOf("@") > -1)
    return false;
if (endString.indexOf(".") == -1)
    return false;
if (endString.indexOf(".") == 0)
    return false;
while(endString.indexOf(".") > -1)
	if (endString.length > 1)
		endString = endString.substring(endString.indexOf(".") + 1,endString.length);
if (endString.length < 2 || endString.length > 3)
    return false;

return true;
}

function IsCedula(cedula)
{
  var valor = cedula+"";
  var re=/\d{3}-\d{7}-\d{1}/;
  var total=0;
  var count=0;
  
  if(!re.test(valor))   
   return false;
 
  
  for(var i=0; i < valor.length; i++)
  {
    if (valor.charAt(i) != '-')
    {
      if(count++ % 2 == 0)
        total += parseInt(""+valor.charAt(i));
      else
      {
        total += Splitit(parseInt(""+valor.charAt(i))*2);
      }  
    }
  }

  return (total % 10) == 0;
}

function Splitit(valor)
{
 return valor%10 + Math.floor(valor/10);
}