/**
 * @name jQuery checkPhoneNumber
 * @author Rifat Çağrı Ekin <cagri.ekin@gmail.com>
 */

(function( $ ){
	$.fn.checkPhoneNumber = function(options) {
		var defaults = {

		};
		var options = $.extend(defaults, options);

		return this.each(function() {
			$(this).keyup(function(){
				var value = $(this).val();
				value = value.replace(/^0/,"");
				value = value.replace(/([^\d]+)/gi,"");

				if(value.length < 4) $(this).val(value);
				else {
					var out = "";
					value.replace(/([\d]{3})([\d]{0,3})([\d]{0,4})/gi, function(strfull,str1,str2,str3){
						if(str1) out += "("+str1+")";
						if(str2) out += " "+str2;
						if(str3) out += " "+str3;
					})
					$(this).val(out);
				}
			});
		});

	};
})( jQuery );
