function insert_comment(fo_obj){
	var validator = xe.getApp('validator')[0];
	if(!validator) return false;
	if(!fo_obj.elements['_filter']) jQuery(fo_obj).prepend('<input type="hidden" name="_filter" value="" />');
	fo_obj.elements['_filter'].value = 'insert_comment';
	validator.cast('ADD_CALLBACK', ['insert_comment', function(form){
		var params={}, responses=[], elms=form.elements, data=jQuery(form).serializeArray();
		jQuery.each(data, function(i, field){
			var val = jQuery.trim(field.value);
			if(!val) return true;
			if(/\[\]$/.test(field.name)) field.name = field.name.replace(/\[\]$/, '');
			if(params[field.name]) params[field.name] += '|@|'+val;
			else params[field.name] = field.value;
		});
		responses = ['error','message','mid','document_srl','comment_srl'];
		exec_xml('board','procBoardInsertComment', params, completeInsertComment, responses, params, form);
	}]);
	validator.cast('VALIDATE', [fo_obj,'insert_comment']);
	return false;
};

(function($){
	var validator = xe.getApp('Validator')[0];
	if(!validator) return false;
	validator.cast('ADD_FILTER', ['insert_comment', {
		'document_srl': {required:true},
		'nick_name': {required:true,maxlength:20},
		'password': {required:true},
		'email_address': {maxlength:250},
		'homepage': {maxlength:250},
		'content': {required:true,minlength:1}
	}]);
	validator.cast('ADD_MESSAGE', ['document_srl', 'Doc. No.']);
	validator.cast('ADD_MESSAGE', ['nick_name', 'Nick Name']);
	validator.cast('ADD_MESSAGE', ['password', 'Password']);
	validator.cast('ADD_MESSAGE', ['email_address', 'Email']);
	validator.cast('ADD_MESSAGE', ['homepage', 'Homepage']);
	validator.cast('ADD_MESSAGE', ['content', 'Content']);
	validator.cast('ADD_MESSAGE', ['mid', 'Module Name']);
	validator.cast('ADD_MESSAGE', ['comment_srl', 'comment_srl']);
	validator.cast('ADD_MESSAGE', ['parent_srl', 'parent_srl']);
	validator.cast('ADD_MESSAGE', ['is_secret', 'is_secret']);
	validator.cast('ADD_MESSAGE', ['notify_message', 'notify_message']);
	validator.cast('ADD_MESSAGE', ['isnull', 'Please input a value for %s']);
	validator.cast('ADD_MESSAGE', ['outofrange', 'Please align the text length of %s']);
	validator.cast('ADD_MESSAGE', ['equalto', 'The value of %s is invalid']);
	validator.cast('ADD_MESSAGE', ['invalid_email', 'The format of %s is invalid. ex) zbxe@zeroboard.com']);
	validator.cast('ADD_MESSAGE', ['invalid_userid', 'The format of %s is invalid.\nAll values should consist of alphabets, numbers or underscore(_) and the first letter should be alphabet']);
	validator.cast('ADD_MESSAGE', ['invalid_user_id', 'The format of %s is invalid.\nAll values should consist of alphabets, numbers or underscore(_) and the first letter should be alphabet']);
	validator.cast('ADD_MESSAGE', ['invalid_homepage', 'The format of %s is invalid. ex) http://www.zeroboard.com']);
	validator.cast('ADD_MESSAGE', ['invalid_korean', 'The format of %s is invalid. Please input Korean only']);
	validator.cast('ADD_MESSAGE', ['invalid_korean_number', 'The format of %s is invalid. Please input Korean or numbers']);
	validator.cast('ADD_MESSAGE', ['invalid_alpha', 'The format of %s is invalid. Please input alphabets only']);
	validator.cast('ADD_MESSAGE', ['invalid_alpha_number', 'The format of %s is invalid. Please input alphabets or numbers']);
	validator.cast('ADD_MESSAGE', ['invalid_number', 'The format of %s is invalid. Please input numbers only']);
})(jQuery);
