//Trim leading and trailing spaces in a string
String.prototype.trim=function (s) {
	s = this != window? this : s;
	return s.replace(/^\s+/g, '').replace(/\s+$/g, '');
}

//Check if the string is of zero length
function isBlank(s){
	s= s.trim();
	var len=s.length;
	if(s.length==0){return true;}
	return false;
}

//Validate e-mail address
function validateEmail(str){
	if(str.length>0){
		if(!checkEmail(str)){
			return false;
		}
	}
	return true;
}
function checkEmail(email){
    var splitted = email.match("^(.+)@(.+)$");
	 if(splitted == null) return false;
    if(splitted[1] != null ){
      var regexp_user=/^\"?[\w-_\.]*\"?$/;
      if(splitted[1].match(regexp_user) == null) return false;
    }
    if(splitted[2] != null){
      var regexp_domain=/^[\w-\.]*\.[A-Za-z]{2,4}$/;
      if(splitted[2].match(regexp_domain) == null){
	    var regexp_ip =/^\[\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\]$/;
	    if(splitted[2].match(regexp_ip) == null) return false;
      }// if
      return true;
    }
	return false;
}
