(function(){

	var Ajax = window.Ajax = {
		
		/**
		 * 发送POST请求
		 * 
		 * @author dengxh at 2009-6-21
		 * @return void
		 */
		post: function(url, params, callback){
			$.post(window.url+url, $.extend(params, {caller: 'ajax'}), callback, 'json');
		},

		/**
		 * 发送GET请求
		 *
		 * @author dengxh at 2009-6-21
		 * @return void
		 */
		get: function(url, params, callback){
			$.get(window.url+url, $.extend(params, {caller: 'ajax'}), callback, 'json');
		},

		/**
		 * 发送ajax post表单请求
		 *
		 * @author dengxh at 2009-3-30
		 * @param string formID 表单ID
		 * @param function fn 回调函数
		 * @return void
		 */
		postForm: function(formId, fn){
			//			this.setTimer();
			//			Tip.showLoading();
			fn = fn || this.success;
			var callback = function(d){
				//				Ajax.clearTimer();
				fn(d);
			};
			$('#' + formId).ajaxSubmit({
				success: callback,
				data: {
					caller: 'ajax'
				},
				dataType : 'json'
			});
		}
	};
	
	var Tip = window.Tip = {

		/**
		 * 显示提示信息
		 *
		 * @author dengxh at 2009-9-30
		 * @param string msg 提示信息
		 * @param function fn 回调函数
		 * @return void
		 */
		alert: function(msg, fn){
			alert(msg);
			if(fn)
				fn();
		},

		/**
		 * 显示确认框
		 *
		 * @author dengxh at 2009-9-30
		 * @param string msg 提示信息
		 * @param function fn 回调函数
		 * @return void
		 */
		confirm: function(msg, fn){
			fn(confirm(msg));
		},

		init: function(width, height, options){
			$('#dialog').dialog($.extend({
				modal: true,
				width: width || 'auto',
				height: height || 'auto',
				overlay: {
					opacity: 0.5,
					background: 'black'
				}
			}, options));
			$(function(){
				$("#dialog").dialog('open');
			});
		},

		/**
		 * 弹出窗口
		 *
		 * @author dengxh at 2009-9-29
		 * @param string title 标题
		 * @param string content 内容
		 * @param int width 宽度
		 * @param int height 高度
		 * @param int options 扩展设置
		 * @return void
		 */
		panel: function(title, content, width, height, options){
			$('#dialog').remove();
			$(document.body).append('<div id="dialog" title="'+title+'"><p>'+content+'</p></div>');
			this.init(width, height, options);
		},

		/**
		 * 弹出窗口
		 *
		 * @author dengxh at 2009-9-29
		 * @param string title 标题
		 * @param string url 地址
		 * @param int width 宽度
		 * @param int height 高度
		 * @param object options 扩展设置
		 * @return void
		 */
		popPage: function(title, url, width, height, options){
			$('#dialog').remove();
			$(top.window.document.body).append('<div id="dialog" title="'+title+'"><p><iframe width="100%" height="100%" scrolling="auto" frameborder="0" src="'+window.url+url+'"></iframe></p></div>');
			this.init(width, height, options);
		},

		/**
		 * 关闭提示
		 * 
		 * @author dengxh at 2009-9-30
		 * @return void
		 */
		close: function(){
			$('#dialog').dialog('close');
		}
	};
	
	var redirect = window.redirect = function(url){
		document.location.href = window.url + url;
	};
	
	/**
	 * POST方式跳转并
	 */
	var postRedirect = window.postRedirect = function(url, data){
		var form = '<form action="'+window.url + url+'" method="post"></form>';
		for(i in data){
			form.append($('<input type="hidden" name="'+i+'" id="'+i+'" />').val(data[i]));
		}
		$(document.body).append(form);
		form.submit();
	};
	
	var nTabs = window.nTabs = function(thisObj,Num){
		if(thisObj.className == "active")return;
		var tabObj = thisObj.parentNode.id;
		var tabList = document.getElementById(tabObj).getElementsByTagName("li");
		for(i=0; i <tabList.length; i++)
		{
			if (i == Num)
			{
				thisObj.className = "active";
				document.getElementById(tabObj+"_Content"+i).style.display = "block";
			}else{
				tabList[i].className = "normal";
				document.getElementById(tabObj+"_Content"+i).style.display = "none";
			}
		}
	}
})();
