// Email Validation Javascript in Spanish
// copyright 23rd March 2003, by Stephen Chapman, Felgall Pty Ltd
// Spanish translation by Nacho

// You have permission to copy and use this javascript provided that
// the content of the script is not changed in any way.
function isValidDate(dateStr) {
// Checks for the following valid date formats:
// MM/DD/YY   MM/DD/YYYY   MM-DD-YY   MM-DD-YYYY
// Also separates date into month, day, and year variables

var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{2}|\d{4})$/;

// To require a 4 digit year entry, use this line instead:
// var datePat = /^(\d{1,2})(\/|-)(\d{1,2})\2(\d{4})$/;

var matchArray = dateStr.match(datePat); // is the format ok?
if (matchArray == null) {
alert("Date is not in a valid format.")
return false;
}
month = matchArray[1]; // parse date into variables
day = matchArray[3];
year = matchArray[4];
if (month < 1 || month > 12) { // check month range
alert("Month must be between 1 and 12.");
return false;
}
if (day < 1 || day > 31) {
alert("Day must be between 1 and 31.");
return false;
}
if ((month==4 || month==6 || month==9 || month==11) && day==31) {
alert("Month "+month+" doesn't have 31 days!")
return false
}
if (month == 2) { // check for february 29th
var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
if (day>29 || (day==29 && !isleap)) {
alert("February " + year + " doesn't have " + day + " days!");
return false;
   }
}
return true;  // date is valid
}
function validateWeb(addr)
{
var exp=/^http:\/\/www\.[a-z]+\.(com)|(org)|(edu)|(net)|(co)$/;
if(exp.test(addr))
return false;
return true;
}
function validateEmail(addr,man,db) {
if (addr == '' && man) {
   if (db) alert('email address is mandatory');
   return false;
}
var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('El e-mail contiene caracteres inválidos');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("El e-mail contiene caracteres inválidos (no ASCII)");
      return false;
   }
}
var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert("Your email must have a '@'.");
   return false;
}
if (atPos == 0) {
   if (db) alert('El e-mail no debe empezar por una @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('El e-mail sólo debe contener una @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('El e-mail debe contener un punto en el dominio');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('No puede haber un punto justo después de la @');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('No puede haber un punto justo antes de la @');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('No puede haber dos puntos juntos en la arroba');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('Dominio de primer nivel incorrecto: .com, .es ...');
   return false;
}
return true;
}


/**
 * DHTML phone number validation script. Courtesy of SmartWebby.com (http://www.smartwebby.com/dhtml/)
 */

// Declaring required variables
var digits = "0123456789";
// non-digit characters which are allowed in phone numbers
var phoneNumberDelimiters = "()- ";
// characters which are allowed in international phone numbers
// (a leading + is OK)
var validWorldPhoneChars = phoneNumberDelimiters + "+";
// Minimum no of digits in an international phone no.
var minDigitsInIPhoneNumber = 10;

function isInteger(s)
{   var i;
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character is number.
        var c = s.charAt(i);
        if (((c < "0") || (c > "9"))) return false;
    }
    // All characters are numbers.
    return true;
}
function trim(s)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not a whitespace, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (c != " ") returnString += c;
    }
    return returnString;
}
function stripCharsInBag(s, bag)
{   var i;
    var returnString = "";
    // Search through string's characters one by one.
    // If character is not in bag, append to returnString.
    for (i = 0; i < s.length; i++)
    {   
        // Check that current character isn't whitespace.
        var c = s.charAt(i);
        if (bag.indexOf(c) == -1) returnString += c;
    }
    return returnString;
}

function checkInternationalPhone(strPhone){
var bracket=3
strPhone=trim(strPhone)
if(strPhone.indexOf("+")>1) return false
if(strPhone.indexOf("-")!=-1)bracket=bracket+1
if(strPhone.indexOf("(")!=-1 && strPhone.indexOf("(")>bracket)return false
var brchr=strPhone.indexOf("(")
if(strPhone.indexOf("(")!=-1 && strPhone.charAt(brchr+2)!=")")return false
if(strPhone.indexOf("(")==-1 && strPhone.indexOf(")")!=-1)return false
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}





function validateEmail1(addr,man,db) {

var invalidChars = '\/\'\\ ";:?!()[]\{\}^|';
for (i=0; i<invalidChars.length; i++) {
   if (addr.indexOf(invalidChars.charAt(i),0) > -1) {
      if (db) alert('El e-mail contiene caracteres inválidos');
      return false;
   }
}
for (i=0; i<addr.length; i++) {
   if (addr.charCodeAt(i)>127) {
      if (db) alert("El e-mail contiene caracteres inválidos (no ASCII)");
      return false;
   }
}
var atPos = addr.indexOf('@',0);
if (atPos == -1) {
   if (db) alert("Your email must have a '@'.");
   return false;
}
if (atPos == 0) {
   if (db) alert('El e-mail no debe empezar por una @');
   return false;
}
if (addr.indexOf('@', atPos + 1) > - 1) {
   if (db) alert('El e-mail sólo debe contener una @');
   return false;
}
if (addr.indexOf('.', atPos) == -1) {
   if (db) alert('El e-mail debe contener un punto en el dominio');
   return false;
}
if (addr.indexOf('@.',0) != -1) {
   if (db) alert('No puede haber un punto justo después de la @');
   return false;
}
if (addr.indexOf('.@',0) != -1){
   if (db) alert('No puede haber un punto justo antes de la @');
   return false;
}
if (addr.indexOf('..',0) != -1) {
   if (db) alert('No puede haber dos puntos juntos en la arroba');
   return false;
}
var suffix = addr.substring(addr.lastIndexOf('.')+1);
if (suffix.length != 2 && suffix != 'com' && suffix != 'net' && suffix != 'org' && suffix != 'edu' && suffix != 'int' && suffix != 'mil' && suffix != 'gov' & suffix != 'arpa' && suffix != 'biz' && suffix != 'aero' && suffix != 'name' && suffix != 'coop' && suffix != 'info' && suffix != 'pro' && suffix != 'museum') {
   if (db) alert('Dominio de primer nivel incorrecto: .com, .es ...');
   return false;
}
return true;
}

