/**
 *
 * Website      :  Businessclub de Betuwe
 * Programmeur  :  Sem Evers
 * Bedrijf      :  Media Solutions
 * Datum        :  14-04-2010
 *
 **/
 
(function($){

	$(document).ready(function(){
		$('input[name=telefoon]').each(function(){
			if($(this).val() == "") $(this).val("        - ");
			
			$(this).bind('focus', function(){
				if($(this).val() == "        - ") $(this).val("");
			}).bind('blur', function(){
				if($(this).val() == "") $(this).val("        - ");
			}).bind('keydown', function(e){
				var keyArray = [9, 16, 37, 39];
				
				if(e.keyCode >= 48 && e.keyCode <= 57 || e.keyCode >= 96 && e.keyCode <= 105 ||($.inArray(e.keyCode, keyArray) != -1)){
					if($(this).val().length == 4){
						$(this).val( $(this).val() + " - " );
					}
					else if($(this).val().length == 9){
						$(this).val( $(this).val() + " " );
					}
					else if($(this).val().length == 12){
						$(this).val( $(this).val() + " " );
					}
					else if($(this).val().length >= 15){
						value = $(this).val();
						$(this).val( value.substr(0,14) );
					}
				}
				else if(e.keyCode == 8){
					var value = $(this).val();
					
					if($(this).val().length == 8){
						value = value.substr(0,5);
						$(this).val( value );
					}
					else if($(this).val().length == 14){
						value = value.substr(0,13);
						$(this).val( value );
					}
					else if($(this).val().length == 11){
						value = value.substr(0,10);
						$(this).val( value );
					}
				} 
				else { e.preventDefault(); }
			});
		});
	});
	
})(jQuery);
