function StrValidate() {
  /*
  Functions for validating strings and form input values.  
  */

  this.LTrim=function(value) {
    /*
    Left-trims a string, removing all whitespaces.
    value (string): String to trim.
    Returns (string): Left-trimmed string.
    */
    
  	var re = /\s*((\S+\s*)*)/;
  	return value.replace(re, "$1");
  };

  this.RTrim=function(value) {
    /*
    Right-trims a string, removing all whitespaces.
    value (string): String to trim.
    Returns (string): Right-trimmed string.
    */  
    
  	var re = /((\s*\S+)*)\s*/;
  	return value.replace(re, "$1");
  }

  this.trim=function(value) {
    /*
    Trims a string, removing all trailing/tailing whitespaces.
    value (string): String to trim.
    Returns (string): Trimmed string.
    */
    
  	return this.LTrim(this.RTrim(value));
  }

  this.regexValidate=function(regex, value) {
    /*
    Validates a string according to a regex and returns TRUE/FALSE based on regex success.
    regex: Regular expression.
    value (string): Value to validate.
    Returns (bool): TRUE/FALSE.
    */
    
    return (regex.exec(this.trim(value))!=null);
  }

  this.textFieldNotEmpty=function(value) {
    /*
    Returns TRUE if text 'value' is not empty, FALSE if empty.
    */
    
    return(this.trim(value).length>0);
  }

  this.isEmailAddress=function(value) {
    /*
    Returns TRUE if 'value' is an e-mail address, FALSE if not.
    */
    
    var reg=/^[A-Z0-9._%-øæåØÆÅ]+@[A-Z0-9.-øæåØÆÅ]+\.[A-Z]{2,4}$/i;
    return this.regexValidate(reg, value);
  }

  this.dropdownNotFirstSelected=function(index) {
    /*
    Returns TRUE if first element in drop down menu is not selected, FALSE if it is.
    */
    
    return(index>0);
  }

  this.radioIsSelected=function(radioGroup) {
    /*
    Returns TRUE if a radio button in group 'radioGroup' is selected, FALSE if none are selected.
    */
    
    var ret=false;
    for(i=0; i<radioGroup.length; i++) {
    	if(radioGroup[i].checked) {
    	  ret=true;
    	}
    }
    return ret;
  }

  this.checkboxIsChecked=function(checkboxValue) {
    /*
    Returns TRUE if checkbox with value 'checkboxValue' is checked, FALSE if it is not checked.
    */
    
    if(!checkboxValue) return false;
    else return checkboxValue;
  }

  this.minLength=function(value, minLength) {
    /*
    Checks if a string is of a minimum length.
    value (string): String to check
    minLength (int): Minimum length.
    Returns (bool): TRUE if string is equal to or longer than the minimum length. FALSE if not.
    */
    
    return(this.trim(value).length>=minLength);
  }

  this.maxLength=function(value, maxLength) {
    /*
    Checks if a string is below a maximum length.
    value (string): String to check
    minLength (int): Maximum length length.
    Returns (bool): TRUE if string is equal to or shorter than the maximum length. FALSE if not.
    */
    
    return(this.trim(value).length<=maxLength);
  }

  this.withinLength=function(value, min, max) {
    /*
    Checks if the length of a string is within a range.
    value (string): String to check.
    min, max (int): Minimum and maximum allowed string size.
    Returns (bool): TRUE if within range, FALSE if not.
    */
    
    return((this.minLength(value,min))&&(this.maxLength(value,max)));
  }

  this.isRegCharOnly=function(value) {
    /*
    Checks if a string consists only of characters A-Z and 0-9. (Case insensitive).
    value (string): String to check.
    Returns (bool): TRUE/FALSE.
    */
    
    var reg=/^[A-Z0-9]+$/i;
    return this.regexValidate(reg, value);
  }

  this.isNumOnly=function(value) {
    /*
    Checks if a string consists only of numeric characters (0-9).
    value (string): String to check.
    Returns (bool): TRUE/FALSE.    
    */
    
    var reg=/^[-+]?[0-9]+$/i;
    return this.regexValidate(reg, value);
  }
  
  this.isLeapYear=function(year) {
    /*
    Checks if an integer is a leap year.
    year (int): Integer value to check.
    Returns (bool): TRUE if value is a leap year, FALSE if not.
    */
    return (((year%4==0)&&(year%100!=0))||(year%400==0));
  }

  this.removeHTMLTags=function(s) {
    /*
    Removes all HTML tags from a string.
    s (string): The string.
    Returns (string): s with all HTML tags removed.
    */
    
    var ret=s.replace(/<\/?[^>]+(>|$)/g, "");
    ret=ret.replace(">","");
    ret=ret.replace("<","");
    return ret;
  }

}