function isBlank(s) {
	
  if (s==null) {return true;}
  for (var i = 0; i < s.length; i++) {
    var c = s.charAt(i);
    if ((c != ' ') && (c != '\n') && (c != '\r')) return false;
  }
  return true;
}

function isNotBlank(s) {
  if (s.length>1) return true;
  else return false;
}

function isEmail(string) {
    return (string.search(/^\w+((-\w+)|(\.\w+)|('\w+))*\@[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)+$/) != -1);
}


function trim(string) {
// removes spaces at the beginning of a string
    string = string.replace(/^\s*/, "");
// removes spaces anywhere else in the string
// (I'd rather only remove them at the end, but I can't
//  get that to work.)
    string = string.replace(/(\S*)\s*/g, "$1");

// This should work, but doesn't
//    string = string.replace(/\s$/, "");

    return string;
}


function isProper(string) {
    return (string.search(/^[a-zA-Z']+[a-zA-Z' -]*$/) != -1);
}

// Checks that a string contains a number with 10 or more digits
// and any number of dashes, spaces, and parentheses.
function isPhoneNumber(string) {
    // remove all spaces and dashes and parentheses
    var stringx = string.replace(/[)( -]/g, "");
    // may begin with one '+' character and contain 10 or more digits
    if (stringx.search(/\d{4}/) == -1) {
      return false;
    }
    return true;
}

// Checks for at least 4 letters and numbers
function isProperFour(string) {
   if (string.search(/^\w\w\w\w+$/) == -1) return false;
   else return true;
}

function isWord(string) {
   if (string.search(/^[ a-zA-Z0-9_.;:,!@'-]+[ a-zA-Z0-9_.;:,!@'-]*$/) == -1) return false;
}
function isNumber(string){
	for(var i=0;i<string.length;i++)
	{
		if(isNaN(string.charAt(i)))
		{
		return true;
		}
	}

}
/*function isNumber(string){
 alert('hi');
   if (string.search(/\d{3}[0-9]/) == -1) return false;
   else
   return true;
}*/

function isUnselected(string) {
   if (string.indexOf("Select") > -1) return true;
}

function isReady(form) {
	
  if (isBlank(form.Name.value)) {
    alert("Please enter your Name.");
        form.Name.focus();
        return false;
  }
  
  if (isProper(form.Name.value) == false) {
    alert(form.Name.value+" is not a valid value for Name.");
        form.Name.focus();
    return false;
  }
  
  if (isBlank(form.Organization.value)) {
    alert("Please enter your Organization.");
        form.Organization.focus();
    return false;
  }
  
  if (isProper(form.Organization.value) == false) {
    alert(form.Organization.value+" is not a valid value for Name.");
        form.Organization.focus();
    return false;
  } 
  
  if (isBlank(form.Email.value)) {
    alert("Please enter your Email address.");
        form.Email.focus();
    return false;
  }
  
  if (isNotBlank(form.Email.value)) {
    if (isEmail(form.Email.value) == false) {
      alert("'"+form.Email.value+"' is not a valid e-mail address.\n"+
              "Please enter a valid Email address.");
      form.Email.focus();
      return false;
    }
  }
  
  if (isBlank(form.Countrycode.value)) {
    alert("Please enter your Country code.\n");
    form.Countrycode.focus();
	return false;
  }
  
  if (isNotBlank(form.Countrycode.value)) {
	if(isNumber(form.Countrycode.value))
		{
			alert("'"+form.Countrycode.value+"' is not valid\n"+
				  "Please enter a valid Countrycode address.");
		 	form.Countrycode.focus();
		  	return false;
     	}	
 }
 
  if (isBlank(form.Areacode.value)) {
    alert("Please enter your Area code.\n");
    form.Areacode.focus();
	return false;
  }
  
  if (isNotBlank(form.Areacode.value)) {
	if (isNumber(form.Areacode.value)) {
      alert("'"+form.Areacode.value+"' is not valid\n"+
              "Please enter a valid Areacode address.");
      form.Areacode.focus();
      return false;
	}
  } 
  
  if (isBlank(form.Phone.value)) {
    alert("Please enter your Phone Number.\n"+
          "It must contain 4 digits, and any\n"+
          "number of spaces, dashes, and parentheses are not allowed.\n");
    form.Phone.focus();
    return false;
  }
  
  if (isNumber(form.Phone.value)) {
				alert(form.Phone.value+" is not a valid Phone Number.\n"+
				  "It must contain 4 digits, and any\n"+
				  "number of spaces, dashes, and parentheses are not allowed.\n");
			form.Phone.focus();
			return false;
	  }
	  else if (isPhoneNumber(form.Phone.value) == false) {
		  alert(form.Phone.value+" is not a valid Phone Number.\n"+
				  "It must contain 4 digits");
			form.Phone.focus();
			return false;
  }
  
  if (isUnselected(form.Source.value)) {
    alert("How did you come to know about us?\n");
    form.Source.focus();
    return false;
  } 
  
   if (isBlank(form.security_code.value)) {
    alert("Please enter your security_code.");
        form.security_code.focus();
    return false;
  }

  return true;
}

