
window.alert = function(message, callback, options)
{
	window.addEvent('domready', function() {
		DialogBox.alert(message, '确定', callback, $extend({title: '系统提示信息', autoclose: true}, options || {}));
	});
};

window.confirm = function(message, after)
{
	window.addEvent('domready', function() {
		DialogBox.confirm(message, '确定', '取消', after, {title: '系统提示信息'});
	});
};

//询问模式：删除按钮用
window.ask = function(message, btnAsk, after, x, y)
{
	window.addEvent('domready', function() {
		DialogBox.ask(message, btnAsk, '取消', after, {x: x, y: y});
	});
};

//下载页面信息并显示
window.ajaxDialog = function(title, url, behavior, options)
{
	window.addEvent('domready', function() {
		DialogBox.load( url, $extend({title: title, fixed: false, behavior : behavior || $empty}, options || {}));
	});
};

//显示普通文本框
window.showDialog = function(title, content, options)
{
	window.addEvent('domready', function() {
		DialogBox.show(content, $extend({title: title}, options || {}));
	});
};

//显示右下角的提示信息
window.showNotice = function(title, content)
{
	window.addEvent('domready', function() {
		if(!title || title.trim() == '') {
			title = '提示';
		}
		new noticebox(title, content).show();
	});
};

CS.implement({
	showLoginDialog : function(afterLogin) {
		ajaxDialog('登录', '/web/system/login.aspx', afterLogin, {
			fixed: true,
			afterShow : function(){
				try{
					$('loginPage').getElement('input[name=txtUsername]').focus();
				}catch(e){}
			}
		});
	},
		
	//弹出式登录对话框用:弹出式对话框和页面上的登录框共用,dialog非空则弹出式
	login : function(containter) {
		//验证
		if(!checkNotNull(containter.getElement('input[name=txtUsername]'), '用户名必须填写'))
		{
			return false;
		}
		
		if(!checkNotNull(containter.getElement('input[name=txtPassword]'), '密码必须填写'))
		{
			return false;
		}
		
		//ajax loading 开始
		AjaxLoading.show(containter);

		ChinSoftProject.Ajax.AjaxServer.Login(
			containter.getElement('input[name=txtUsername]').value,
			containter.getElement('input[name=txtPassword]').value,
			containter.getElement('input[name=cbRememberMe]').checked, function(data){
			
			var resp = data.value;

			if(resp.Code == resp.SUCCESS)
			{
				//转向到框架页
				var url = '/index.aspx';
				if(containter.getElement('input[id=redirecturl]').value != '') {
					url = containter.getElement('input[id=redirecturl]').value;
				}

				top.location.href = url;
			}
			else
			{
				//显示错误信息
				alert(resp.Message);
			}

			//ajax loading 结束
			AjaxLoading.hide(containter);
		});

		return true;
	},

	//退出
	quit : function(btnQuit) {
		//非IE浏览器
		if(!Browser.Engine.trident) {
			chinsoft.signOut(btnQuit);
		}

		//设置退出按钮不可用
		if(btnQuit) {
			btnQuit.disabled = true;
		}

		ChinSoftProject.Ajax.AjaxServer.SignOut(function(data){
			var resp = data.value;

			if(resp.Code == resp.SUCCESS)
			{
				window.close();
			}
			else
			{
				//设置退出按钮可用
				if(btnQuit) {
					btnQuit.disabled = false;
				}

				alert(resp.Message);
			}
		});

		return false;
	},
		
	searchTopic : function()
	{
		var txtTopics = $('search').getElement('input[id$=txtTopics]');
		if(!checkNotNull(txtTopics, '$keywordnotnull$'))
		{
			return false;
		}

		top.location.href = '/web/information/info.aspx?keyword='+ encodeURIComponent(txtTopics.value.replace('<', '').replace('>', ''));
	},


	deleteUploadFile : function(event, delFileIDs, fileID) {
		var event = new Event(event);
		
		ask('您确定要删除当前的信息吗?', '确定', function() { 
				$(delFileIDs).set('value', $(delFileIDs).value + ',' + fileID);
				$$('.fileupload tr[id=' + fileID + ']').dispose();
			}, 
			event.page.x,
			event.page.y
		);
	}
});
    