(function($) {
	
	var inputElementValue = function(el, val) {	
		var setting = typeof(val) != 'undefined';
		switch(el.attr('type')) {
	        case 'checkbox':
				if(setting)
	            	el[0].checked = val;
				else 
					return el[0].checked;
	            break;
	        case 'text':
	        case 'hidden':
	        case 'password':
	        case 'file': //?                     
				if(setting)
	            	el.val(val);
				else 
					return el.val();
	            break;
	        default:
				throw new Error("Cannot get value from element of type: '" + el[0].tagName + "' of type '" + el.attr('type') + "'");                                     
	    }
	};
	
	$.fn.extend({
		novuvalue: function(val) {
			var setting = typeof(val) != 'undefined';
			if(setting) {
			    val = val == null ? "" : val;   
			}			
			if(this.length > 0) {
				switch(this[0].tagName) {
					case 'INPUT':
							return inputElementValue(this, val);
						break;
					case 'SELECT':
						if (setting) {
						    if($("option[value='" + val + "']", this).length > 0) {	//only select from select if the value is present
							    this.val(val);
							}
						} else {
							return this.val() == "" ? null : this.val(); //assume that an empty string is null 
					    }
					    break;					
					default:
						if(typeof(this.val) == 'function') {
							if (setting)
								this.val(val);
							else
								return this.val(); 
						} else {
							throw new Error("Cannot get value from element of type: '" + el[0].tagName + "'");  
						}					
				} //switch 		
			} //if			
		} //function	
	});
	
})(jQuery);