var submitReg = function( form ) {
	
	form = $( form );
	action = $( form ).attr( 'action' );
	form.find( '.error' ).removeClass( 'error' );
	form.find( '.error_checkbox' ).removeClass( 'error_checkbox' );
	
	$.ajax( {
		url : action,
		data : form.serializeArray(),
		dataType : 'json',
		type : 'POST',
		success : function( response ) {
			
			if ( !response ) {
				
				form.find( '.action' ).html( '' );
				return false;
			}
			
			if ( !response.result && typeof( response.error_msg ) != 'undefined' ) {
				
				form.find( '.action' ).addClass( 'error' ).html( response.error_msg );
				
				return false;
			}
			
			if ( !response.result && typeof( response.error_fields ) != 'undefined' ) {
				
				$.each( response.error_fields, function( index, key ){
					
					if ( key == 'rules' ) {
						
						$( 'div.' + key ).parent().addClass( 'error_checkbox' );
					} else {
					
						$( '#reg_' + key ).parent().parent().addClass( 'error' );
					}
				} );
				
				return false;
			}
			
			form.find( '.action' ).addClass( 'success' ).html( response.message );
			
			var leadNumber = Math.round( ( new Date().getTime() * Math.random() ) );
			var protocol = window.location.protocol;
			
			if ( protocol.indexOf( ":" ) ) {
				
				protocol = protocol.substring(0,protocol.indexOf(":"));
			}
			form.find( '.action' ).append( "<img src=\""+protocol+"://tbl.tradedoubler.com/report?organization=388014&event=192904&leadNumber=" + leadNumber + "\" border=\"0\">" );
			pageTracker._trackPageview("/lead_ok_track");
			
			return true;
		}
	} );
}