/**
 * 紫斑马软件
 * @author afan
 * @link http://www.zibanma.com
 */
(function(window){
	var editor;
	var language = {'delete':'确定删除？'};
	function button_disable(){
		alert('button_disable')
	}
	window.zibanma = {
		//list sort
		adminListSort : function(json, url){
			if(json && url){
				$.post(url, json, function(data){
					try{var json=eval(data);}catch(e){}
					if(json.status=='success'){
						window.location.href = window.location.href;
					}
				});
			}
		},
		adminDeleteIterm : function(url){
			if(confirm(language.delete)){
				window.location.href = url;
			}
		},
		adminCheckFromIsNull : function(obj){
			if(obj.value == ''){
				this.adminCheckFormButtonTrue(obj.id);
			}else{
				this.adminCheckFormButtonFalse(obj.id);
			}
		},
		adminCheckFormButtonTrue : function(id){
			$('#'+id).css('border-color','#ff3333');
			$('#submit').attr('disabled', true);
		},
		adminCheckFormButtonFalse : function(id){
			$('#'+id).css('border-color','');
			$('#submit').attr('disabled', false);
		},
		adminLoadEditer : function(){
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					allowFileManager : true,
					width : 680,
					height : 250,
				});
			});
		},
		adminLoadSimpleEditer : function(){
			KindEditor.ready(function(K) {
				editor = K.create('textarea[name="content"]', {
					resizeType : 1,
					allowPreviewEmoticons : false,
					allowImageUpload : false,
					width : 680,
					height : 200,
					items : [
						'fontname', 'fontsize', '|', 'forecolor', 'hilitecolor', 'bold', 'italic', 'underline',
						'removeformat', '|', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
						'insertunorderedlist', '|', 'emoticons', 'link']
				});
			});
		},
		adminLoadMultiImageEditer : function(){
			KindEditor.ready(function(K) {
				editor = K.editor({
					allowFileManager : true
				});
				K('#zibanma_select_image').click(function() {
					editor.loadPlugin('multiimage', function() {
						editor.plugin.multiImageDialog({
							clickFn : function(urlList) {
								var div = K('#zibanma_image_view');
								div.html('');
								var graph = [];
								K.each(urlList, function(i, data) {
									div.append('<img src="' + data.url + '">');
									graph.push(data.url);
								});
								editor.hideDialog();
								$('#graph').val(graph.join(','));
								$('#upload_image_list').css('display','');
							}
						});
					});
				});
			});
		},
		adminLoadSingleUpload : function(){
			KindEditor.ready(function(K) {
				editor = K.editor({
					allowFileManager : true
				});
				K('#zibanma_select_image').click(function() {
					editor.loadPlugin('image', function() {
						editor.plugin.imageDialog({
							showRemote : false,
							clickFn : function(url, title, width, height, border, align) {
								K('#image').val(url);
								K('#image_view').html(url);
								editor.hideDialog();
							}
						});
					});
				});
			});
		}
	};
})(window);