
// class containing general validation methods

function rf () {
	
  
  
  
  /*
  *
  *  FUNCTION: contains_url : checks if a string contains a valid url
  *  PARAM: str : the string to check
  *
  */
  this.contains_url = function (str) {
    var v = new RegExp(); 
    v.compile("[A-Za-z]+://[A-Za-z0-9-_]+\\.[A-Za-z0-9-_%&\?\/.=]+");
    if (!v.test(str)) {
      return false;
    } else {
      return true;
    }

  } // end contains_url
  
  /*
  *
  *  FUNCTION: jscss : manipulates css classes assigned to elements
  *
  *  a:  action to perform.
  *  o:  the object in question.
  *  c1:  the name of the first class
  *  c2:  the name of the second class
  *  Possible actions:
  *  swap:  replaces class c1 with class c2 in object o.
  *  add:  adds class c1 to the object o.
  *  remove:  removes class c1 from the object o.
  *  check:  test if class c1 is already applied to object o and returns true or false.
  */
  this.jscss = function (a,o,c1,c2) {
    switch (a){
      case 'swap':
        o.className=!this.jscss('check',o,c1)?o.className.replace(c2,c1): o.className.replace(c1,c2);
        break;
      case 'add':
        if(!this.jscss('check',o,c1)){o.className+=o.className?' '+c1:c1;}
        break;
      case 'remove':
        var rep=o.className.match(' '+c1)?' '+c1:c1;
        o.className=o.className.replace(rep,'');
        break;
      case 'check':
        return new RegExp('\\b'+c1+'\\b').test(o.className)
        break;
    }
  }



  /*
  *
  *  FUNCTION: trim : trims whitespace off the ends of a given string
  *  PARAM: str : the string to trim
  *
  */
  this.trim = function  (str) {
	return str.replace(/^\s+|\s+$/g,"");
  }

  /*
  *
  *  FUNCTION: isValidEmail : checks if a given string is a valid email address
  *  PARAM: strEmail : the email address to check
  *  PARAM: valid_if_empty : boolean : if an empty string is valid
  *
  */
  this.isValidEmail = function (strEmail, valid_if_empty){
	if (valid_if_empty == null) { valid_if_empty = false; }
     var emailReg = "^[\\w-_\.]*[\\w-_\.]\@[\\w]\.+[\\w]+[\\w]$";
     var regex = new RegExp(emailReg);   
	 
    if (valid_if_empty && strEmail == '') {
	   return true
    } else if (regex.test(strEmail) == false)  {
       return false;
    } else {
       return true; 
    }
  }
  
  /*
  *
  *  FUNCTION: isValidPhone : checks if a given string is a valid phone number
  *  PARAM: strPhonenum : the phone number to check
  *  PARAM: valid_if_empty : boolean : if an empty string is valid
  *
  */
  this.isValidPhone = function (strPhonenum, valid_if_empty){
		
	return true; // not implemented yet
	
  }  
  


};
