// 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 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){
s=stripCharsInBag(strPhone,validWorldPhoneChars);
return (isInteger(s) && s.length >= minDigitsInIPhoneNumber);
}

function validEmail(email) {
			invalidChars = " /:,#'`$~!%^&*()+\"\;<>?\\|	"
			
			if (email == "") {						// cannot be empty
				return false
			}
			for (i = 0; i < invalidChars.length; i++) {	// does it contain any invalid characters?
				badChar = invalidChars.charAt(i)
				if (email.indexOf(badChar,0) > -1) {
					return false
				}
			}
			atPos = email.indexOf("@",1)			// there must be one "@" symbol
			if (atPos == -1) {
				return false
			}
			if (email.indexOf("@",atPos+1) != -1) {	// and only one "@" symbol
				return false
			}
			periodPos = email.indexOf(".",atPos)
			if (periodPos == -1) {					// and at least one "." after the "@"
				return false
			}
			if (periodPos+3 > email.length)	{		// must be at least 2 characters after the "."
				return false
			}
			return true
	}
	
function Validator(form1)
{
	var chkPhone=document.form1.officePhone
	var chkFax=document.form1.fax


  if (form1.firstName.value == "")
  {
    alert("Please enter a value for the \"First Name\" field.");
    form1.firstName.focus();
    return (false);
  }
  if (form1.lastName.value == "")
  {
    alert("Please enter a value for the \"Last Name\" field.");
    form1.lastName.focus();
    return (false);
  }
  if (form1.email.value == "")
  {
    alert("Please enter a value for the \"Email Address\" field.");
    form1.email.focus();
    return (false);
  }
  if ((form1.email.value.length < 7) && (form1.email.value.length !=0))
  {
    alert("Please enter at least 7 characters in the \"E-mail Address\" field.");
    form1.email.focus();
    return (false);
  }
  if (!(validEmail(form1.email.value)))
      {
         alert("Invalid Email Address")
         form1.email.focus()
         return (false)
      }
  if (form1.officePhone.value == "")
  {
    alert("Please enter a value for the \"Phone\" field.");
    form1.officePhone.focus();
    return (false);
  }
  if (form1.officePhone.value != "")
  {
	if (checkInternationalPhone(chkPhone.value)==false){
		alert("Please Enter a Valid Phone Number.\nXXX-XXX-XXXX")
		//Phone.value=""
		chkPhone.focus()
		return (false);
	}
  }
  if (form1.fax.value != "")
  {
	if (checkInternationalPhone(chkFax.value)==false){
		alert("Please Enter a Valid Fax Number.\nXXX-XXX-XXXX")
		//fax.value=""
		chkFax.focus()
		return (false);
	}
  }
/*
-- Selection box
if (form1.classify.selectedIndex == 0)
  {
    alert("Por favor díganos \"Como usted se clasificaria\".");
    form1.classify.focus();
    return (false);
  }
*/
  if (!form1.question_1.checked && !form1.question_2.checked && !form1.question_3.checked && !form1.question_4.checked && !form1.question_5.checked)
  {
    alert("Please select a \"Main Question Topic\".");
    //form1..focus();
    return (false);
  }
	return (true);
}



