var AJAXPATH = '/ajax.php';
function tofmac(){};
tofmac.prototype = {
	name          : 'TM',
	copyRight     : '1999-2009 TM',
	init : function(e){
		document.getElementById('dialog')?'':$('body').append('<div id="dialog" title="'+this.name+this.copyRight+'"></div>');
	},
	error:function(code,message){
		var n = null;
		message = message?message:'这个错误未指明';
		switch(code){
			case 1:
				n = '缺少插件';
				break;
			case 2:
				n = 'AJAX运行错误';
				break;
			case 3:
				n = '操作错误';
				break;
			case 4:
				n = '系统错误';
				break;
			default:
				n = '未知错误';
				break;
		}
		this.dialog('alert','抛出错误','<p style="text-align:left"><span class="ui-icon ui-icon-alert" style="float:left; margin:5px 7px 50px 0;"></span><strong>'+n+':</strong></p><p class="ui-state-error">'+message+'</p><p>请联系 <a href="http://www.macnie.com/about">站长小石</a> 或者 <a href="tencent://message/?uin=80569410&Menu=yes"><img src="/ui/images/icons/QQ.gif" width="20px" title="QQ在线" /></a></p>');
	},
	/** 
	 * dialog接口
	 * Type:alert,confirm,form
	 */
	dialog:function(type,title,content,fun){
		$("#dialog").attr("title",title).html(content);
		if(type == 'alert'){
			$("#dialog").dialog({
				bgiframe: true,
				autoOpen: false,
				modal: true,
				buttons: {
					Ok: function() {
						$(this).dialog('close');
						if(fun)fun();
					}
				}
			});
			$('#dialog').dialog('open');
			return false;
		}else if(type == 'confirm'){
			$("#dialog").dialog({
				bgiframe: true,
				autoOpen: false,
				modal: true,
				buttons: {
					Cancel: function() {
						$(this).dialog('close');
	
					},
					'Continue': function() {
						$(this).dialog('close');
						if(fun)fun();
					}
				}	
			});
			$('#dialog').dialog('open');
			return false;
		}
		
	},
	checkLength:function(o,n,min,max){
		if ( $(o).val().length > max || $(o).val().length < min ) {
				$(o).addClass('ui-state-error');
				this.dialog('alert','警告','<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 50px 0;"></span>'+n+'的长度必须在'+min+'与'+max+'之间。</p><p>换一个好听的名字试试 :)</p>');
				$('#dialog').dialog('open');
				return false;
			} else {
				$(o).removeClass('ui-state-error');
				return true;
			}
	},
	isNull:function(string,n){
		if(string===undefined || string=='' || string == null){
			this.dialog('alert','警告','<p><span class="ui-icon ui-icon-alert" style="float:left; margin:0 7px 50px 0;"></span>'+n+'的值不能为空。</p>');
			$('#dialog').dialog('open');
			return true;
		}else{
			return false;
		}
	},
	block:function(o,message){
		message = message?message:'处理中……';
		if(typeof($.blockUI)!='undefind'){
			try{
				if(o){
					$(o).block({ 
			                message: '<h3>'+message+'</h3>', 
			                css: { border: '3px solid #858585',backgroundColor:'#999',fontSize:'12px',padding:'2px 5px' } 
			        });
				}else{
					$.blockUI({ 
			                message: '<h3>'+message+'</h3>', 
			                css: { border: '0px solid #858585',backgroundColor:'#999',fontSize:'12px',padding:'2px 5px' } 
			        });
				}
			}catch(e){
				this.error(1,e.message);
			}
		}else{
			$(o).find("input").attr("visible","visibled");
		}
	},
	unblock:function(o){
		try{
			o?$(o).unblock():$.unblockUI();
		}catch(e){
			this.error(1,e.message);
		}
	}
}
