/*
 * jQuery for sov sunshine functions
 */
; (function($){
	
	// prevent the following chars from being enter: ' " ; : , ? % $ { }  & < > / \ [space]
	var BLOCKED = ["'",'"',";",":",",","?","%","$","{","}","&","<",">","/","\\"," "];
	var MSGID	= "jquerySovsunshineIllegalCharater";
	
	var __preventClick	= false;
	
	$.extend
	({
		sovsun : {
				restrictUsername	: function( e )
				{
					var returnValue = true;
					
					for( var i = 0 ; i < BLOCKED.length ; i ++)
					{
						returnValue	= ( e.which != BLOCKED[ i ].charCodeAt(0) );
						if( !returnValue )
						{
							if( $( "#"+MSGID ).length == 0 )//add it if it's not lready there
							{
								//show error message
								var msg =  $('<span style="font-weight:bold;color:red;" id="'+MSGID+'">Illegal Character!</span>');
								msg.insertAfter( this );
							}
							$( "#"+MSGID  ).show().fadeOut(1200);
							
							break;//now jump out
						} 
					}	
					
					
					return returnValue;
				}	
			,	preventDoubleClick : function ( e )
				{
					var returnValue	= true;
				
					returnValue = !__preventClick;

					__preventClick	= true;
					
					setTimeout( $.sovsun.removePreventDoubleClick , 5000 );//delay to allow them to click again

					return returnValue;
				}
			,	removePreventDoubleClick : function( a )
				{
					__preventClick = false;
				}
		}
	});
	
})( jQuery );

jQuery( document ).ready( function(){
	
	$('.restrictUsername').bind('keypress', jQuery.sovsun.restrictUsername );//bind to any input with class restrictUsername
	
	$(".preventDoubleClick,.submit").bind('click' , jQuery.sovsun.preventDoubleClick );
	
});

