$.extend({
	//notify插件的简化版.显示在中上端.example: $.tip('滚');
	tip : function(str, time, url){
		var options = {str: str};
		if(typeof time == 'number') options.time = time;
		if(typeof time == 'string') options.url = time;
		if(typeof url == 'number') options.time = url;
		if(typeof url == 'string') options.url = url;
		options.place = ['center','top'];
		$.notify(options);
	},
	//notify插件的简化版.显示在屏幕中间.example: $.tip('滚');
	center : function(str, time, url){
		var options = {str: str};
		if(typeof time == 'number') options.time = time;
		if(typeof time == 'string') options.url = time;
		if(typeof url == 'number') options.time = url;
		if(typeof url == 'string') options.url = url;
		options.padding = '20px 50px',
		$.notify(options);
	},
	/**
	 * 简单提示框底层实现.如果只需要修改基本参数,可以使用简化版的$.tip和$().tip方法
	 * 依赖$.pageSize, $.scroll,$.autoCenter,$.timing方法,String.prototype.width返回字符串真实长度
	 * 
	 */
	notify : function(options){
		//设置参数的默认值
		p = $.extend({
			str:'',				//内容
			time:2000,			//延时自动消失,单位为毫秒,设为0不消失,按esc键时才消失
			url:'',				//提示消失后转向的url
			color: '#D00',			//字体颜色
			background: '#F8FFE8',		//背景
			border: '1px solid #5AB500',	//边框
			textAlign: 'left',		//对齐方式
			zIndex: 1500,			//z轴
			padding: '3px 40px',		//内间距
			place:['center','middle']	//1.jquery对象: $('#abc'); 2.定位数组: ['left','top'] 3.定位数组: [150,400]
		}, options || {});
		//清除上次信息的延时
		if(typeof ti != 'undefined') clearInterval(ti);
		//取页面尺寸信息
		var pageSize = $.pageSize();
		var scroll = $.scroll();
		//创建容器
		if(!$('.jqMsg').length) {
			var style="z-index:"+p.zIndex+";color:"+p.color+";background:"+p.background+";border:"+p.border+";";
			style += "text-align:"+p.textAlign+";padding:"+p.padding+";";
			$('body').append('<div class="jqMsg" style="padding:3px 40px;position:fixed;display:none;'+style+'"></div>');
		}
		var my = $('.jqMsg');
		
		//根据内容长度调整宽度及对齐方式.
		var leng = p.str.width();	//字符串真实长度
		if(leng > 64) my.width(400);
		my.html(p.str);
		my.show();
		//开始定位.p.place可以是jquery对象,也可以是['center','middle']或[200,200]这样的数组
		var top = 0; left = 0;
		if(typeof p.place[0] == 'object') {
			var place = p.place.offset();
			top = place.top - scroll.y;
			left = place.left - scroll.x + p.place.width()+10;
		}else{
			if(p.place[0] == 'center') left = (pageSize.x - my.width() - 30)/2;
			else if(p.place[0] == 'left') left = 2;
			else if(p.place[0] == 'right') left = pageSize.x - my.width() - 85;
			else left = p.place[0];
			if(p.place[1] == 'middle') top = (pageSize.y - my.height()-40)/2;
			else if(p.place[1] == 'top') top = 2;
			else if(p.place[1] == 'bottom') top = pageSize.y - my.height() - 20;
			else top = p.place[1];
		}
		//对IE6的修正
		if(/msie 6/i.test(navigator.userAgent)) {
			$('.jqMsg').css('position', 'absolute');
			top += scroll.y;
			left += scroll.x;
		}
		my.css('top',top).css('left', left);
		/********************************************* 定位结束 **************************************/
		
		var endTime = +new Date + p.time;
		if(p.time != 0) ti = setInterval("$.timing("+endTime+")", 1000);
		if(p.url && p.time > 0) setTimeout("location.href='"+p.url+"'", p.time);
		$(document).one('keydown', p.url, $.esc);
		$(window).bind('resize',my, $.autoCenter);
	},
	//扩展ui.dialog插件，增加prepend(前置内容),append(后置内容),url(load url),o(load此对象内容),cb选项,自适应宽高
	//依赖: jquery,jquery.core,dialog,draggable,resizable,autoSize方法,scroll方法
	dialog : function (options){
		if(options == 'close') return $('#dialog').dialog('close');
		if($('#dialog').length) $('#dialog').dialog('close');
		$('.ui-dialog').remove();
		//扩展参数默认值(标准参数的默认值由ui#dialog负责)
		if(typeof options == 'string') options = {prepend: options};
		param = $.extend({url: null, o: null, prepend: null, append: null, cb: function (){},speed: 300}, options || {});
		if(param.modal && /msie 6/i.test(navigator.userAgent)) {
			param.overlay = null;
		}
		//添加dialog容器
		if(!$('#dialog').length) $('body').append('<div id="dialog" style="display:none;"><div></div></div>');
		//载入内容
		if(param.url) {
			$.loading();
			return $('#dialog>div').load(param.url, $.show);
		}
		if(param.o) {
			$('#dialog>div').html(param.o.html());
		}
		$.show();
	},
	//显示内容并做好善后工作
	show : function () {
		if(param.prepend) $('#dialog>div').prepend(param.prepend);
		if(param.append) $('#dialog>div').append(param.append);
		$('#dialog').dialog(param).show();
		$('.jqMsg').remove();
		param.cb.call();
		setTimeout($.autoSize, 10);
		$(window).bind('resize', $('#dialog').parent().parent(), $.autoCenter);
	},
	loading : function (){
		var img = '/res/css/images/loading.gif';	//如不显示图片,请自行修改路径
		$.notify({str:'<img src="'+img+'">',time:0});
		//esc to close
		$(document).one('keydown', $.esc);	    
	},
	esc : function (e){
		if (e.keyCode == 27) {
			if(e.data) {
				location.href = e.data;
			}
			$('.jqMsg').remove();
			return false;
		}
	},
	//元素自动置中.example: $(window).bind('resize',$(this), $.autoCenter);
	autoCenter : function (e){
		var e = e.data;
		if(!e.width()) return;
		var pageSize = $.pageSize();
		var scroll = $.scroll(); 
		var left = (pageSize.x - e.width()) /2 + scroll.x - 35;
		var top = (pageSize.y - e.height()) /2 + scroll.y - 20;
		if(left < scroll.x) left = scroll.x;
		if(top < scroll.y) top = scroll.y;
		e.css('left', left).css('top',top);
	},
	//dialog autosize
	autoSize : function ()
	{
		if(param.width && param.height) return;
		var son = false;
		if($('#dialog>div').length) {
			var son = $('#dialog>div');
		}
		var scroll = $.scroll();
		var p = $('#dialog').parent().parent();
		var size = {};
		if(!param.width) {
			var w = p.width();
			var W = son.width() + 50;
			var left = parseInt(p.css('left')) - (W - w) / 2;
			if(left < scroll.x) left = scroll.x;
			size.width = W;
			size.left = left;
		}
		if(!param.height) {
			var h = p.height();
			var H = son.height() + 70;
			var top = parseInt(p.css('top')) - (H - h) / 2;
			if(top < scroll.y) top = scroll.y;
			size.height = H;
			size.top = top;
		}
		p.animate(size, param.speed);
	},
	timing : function (endTime){
		if(+new Date > endTime) {
			$('.jqMsg').remove();
			clearInterval(ti);
		}
	},
	//弹出框。依赖$.pageSize方法.如果用对象对位，还依赖scroll方法 place=o 根据o对象定位
	//例子：$.box({o:$('.mainItem .itemContent'), width: 580, height: 430});	$.box({url: 'http://www.xinye.com/?m=music&a=form&s_id=34', width: 580, height: 430});
	box : function(options)
	{
		param = $.extend({width: '600',height: '400', title: '', bc:function(){}}, options || {});
		$('#jqBox').remove();
		var jqBox = '<div id="jqBox" style="overflow: auto; border: 3px solid #ab6; z-index: 100; position: fixed; width: '+param.width+'px; height: '+param.height+'px; background: #fff;"></div>';
		$('body').append(jqBox);
		if($.browser.ie6) {
			$('#overlay').css('position', 'absolute');
			$('#jqBox').css('position', 'absolute');
			$('html').css('overflow', 'hidden');
		}
		var page = $.pageSize();
		if (!param.place) {
			//覆盖层
			var overlay = '<div id="overlay" style="top: 0;left: 0;z-index: 99; width: 100%; height: 100%; background: #000; opacity: 0.5; position: fixed;FILTER: alpha(opacity=50);"></div>';
			$('body').append(overlay);
			var top = (page.y-$('#jqBox').height())/2;
			var left = (page.x-$('#jqBox').width())/2;
		}else{
			var scroll = $.scroll();
			var offset = param.place.offset();
			var top = offset.top - param.height -scroll.y -5;
			if(top < 0) {
				top += param.height+20;
				if($.browser.ie6) top += scroll.y;
			}
			var left = offset.left;
			if(left + param.width > page.x) left = offset.left - param.width;
		}
		
		$('#jqBox').css('top', top);
		$('#jqBox').css('left', left);
		$('#jqBox').html(
			'<div style="height: 20px; line-height: 20px; text-align: right; background: #efe;">'	//标题行
				+'<div style="float:left;color: #369;">&nbsp;'+param.title+'</div><a href="javascript:;" id="jqBoxClose">关闭</a> 或 Esc键&nbsp;<hr/>'
			+'</div>'
			+'<div style="padding: 10px;height: '+(param.height-60)+'px;" id="jqBoxMain">' //主容器
				+'<img style="margin-left: '+(param.width/2-15)+'px; margin-top: '+(param.height/2-37)+'px;" alt="loading..." src="/res/css/images/loading.gif"/>' //loading图片
			+'</div>'
		);
		$('#jqBoxClose').click(function (){
			$('#overlay').remove(); 
			$('#jqBox').remove();
			if($.browser.ie6) $('html').css('overflow-y', 'auto');
			return false;
		});
		//esc关闭,并取消默认动作
		$(document).one('keydown', function(e){
			if (e.keyCode == 27) {
				$('#jqBoxClose').click();
				return false;
			}
		});
		if(param.url != undefined){
			$('#jqBoxMain').load(param.url, param.bc);
		}
		if(param.o != undefined) {
			$('#jqBoxMain').html(param.o.html());
		}
	},
	//保存cookie.expires为秒数,secure为是否通过https连接
	setCookie : function(name, value, expires, path, domain, secure){
		if(!name) return false;
		if(name == "") return false;
		if(!expires) expires = 3600;	//默认保存一小时
		//秒数转为GMT时间
		var today = new Date();
		expires = new Date(today.getTime()+expires*1000).toGMTString();
		//组合参数串
		var 	cv = name+"="+escape(value)+";"
			+ ((expires) ? " expires="+expires+";" : "")
			+ ((path) ? "path="+path+";" : "")
			+ ((domain) ? "domain="+domain+";" : "")
			+ ((secure && secure != 0) ? "secure" : "");
		if(cv.length > 4096) return false;
		document.cookie = cv;
		return true;
	},
	//取得cookie.没有做删除cookie方法,用set空值代替吧
	getCookie : function(name){
		var cv = document.cookie.split("; ");//使用"; "分割Cookie
		var cva = [], temp;
		for(i=0; i<cv.length; i++){
			temp = cv[i].split("=");
			cva[temp[0]] = unescape(temp[1]);
		}
		if(name) return cva[name]; //输出单个或所有
		return cva;
	},
	//取url参数 例：alert($.getPara('id')); 省略第二个参数则取当前页面url
	getPara : function(para, url){
		if(!url) var url = location.href;
		var rs = new RegExp('[\&|\?]{1}'+para+'=([\\w]+)').exec(url);
		if(rs == null) return null;
		return rs[1];
	},
	//取FCK的值 参数是FCK的name
	getFckVal : function (name){
		return getFck(name).GetXHTML(true);
	},
	pageSize : function (){
		var xScroll,yScroll;if(window.innerHeight&&window.scrollMaxY){
			xScroll=window.innerWidth+window.scrollMaxX;
			yScroll=window.innerHeight+window.scrollMaxY;
		}else if(document.body.scrollHeight>document.body.offsetHeight){
			xScroll=document.body.scrollWidth;yScroll=document.body.scrollHeight;
		}else{
			xScroll=document.body.offsetWidth;yScroll=document.body.offsetHeight;
		}
		var windowWidth,windowHeight;
		if(self.innerHeight){
			if(document.documentElement.clientWidth){
				windowWidth=document.documentElement.clientWidth;
			}else{
				windowWidth=self.innerWidth;
			}
			windowHeight=self.innerHeight;
		}else if(document.documentElement&&document.documentElement.clientHeight){
			windowWidth=document.documentElement.clientWidth;
			windowHeight=document.documentElement.clientHeight;
		}else if(document.body){
			windowWidth=document.body.clientWidth;
			windowHeight=document.body.clientHeight;
		}
		if(yScroll<windowHeight){
			pageHeight=windowHeight;
		}else{
			pageHeight=yScroll;
		}
		if(xScroll<windowWidth){
			pageWidth=xScroll;
		}else{
			pageWidth=windowWidth;
		}
		return {X:pageWidth, Y:pageHeight, x:windowWidth, y:windowHeight};
	},
	scroll :  function (){
		var xScroll,yScroll;
		if(self.pageYOffset){
			yScroll=self.pageYOffset;xScroll=self.pageXOffset;
		}else if(document.documentElement&&document.documentElement.scrollTop){
			yScroll=document.documentElement.scrollTop;xScroll=document.documentElement.scrollLeft;
		}else if(document.body){
			yScroll=document.body.scrollTop;
			xScroll=document.body.scrollLeft;
		}
		arrayPageScroll=new Array(xScroll,yScroll);
		return {x:xScroll, y:yScroll};
	},
	//延时
	delay : function (ms){
		var date=new Date();
		curDate=null;
		do{
			var curDate=new Date();
		}
		while(curDate-date<ms);
	},
	/**
	 * jquery只有getJSON,没有postJSON.大概觉得post时不常用json格式吧.没关系自己弄一个
	 * $.postJSON('abc.php', $(this).getPost(), function (data){
	 *	 alert(data);
	 * });
	 */
	postJSON: function (url,data,cb)
	{
		if(typeof cb != 'function') cb = function (){};
		$.ajax({
			type: "POST",
			dataType: 'json',
			url: url,
			data: data,
			success: cb
		});
	},
	//生成随机字符串(11位)
	uid : function()
	{
		return (new Date().getTime()*10000+Math.random(1)*10000).toString(32);
	},
	/**
	 * 加入书签(收藏夹)
	 * @example $('#addMark').click( function(){$.bookmark('http://ouk.cn', 'ouk');} );
	 */
	bookmark : function(url, title)
	{
		if (window.sidebar) window.sidebar.addPanel(title, url, "");
		else if (window.opera && window.print) {
			var mbm = document.createElement('a');
			mbm.setAttribute('rel','sidebar');
			mbm.setAttribute('href',url);
			mbm.setAttribute('title',title);
			mbm.click();
		}
		else if (document.all) window.external.AddFavorite(url, title);
	},
	/**
	 * 列举对象, DEBUG用
	 */
	listObj : function(o)
	{
		var str = '';
		for (i in o) {
			if (typeof o[i] == 'string') {
				var val = o[i].replace(/&/g, '&amp;').replace(/</g,'&lt;').replace(/>/g,'&gt;');
			} else {
				var val = o[i];
			}
			str += '<strong>' + i + '</strong>' + '\t' + val + '<br>';
		}
		$('body').prepend(str);
	},
	/**
	 * 动态载入js文件,如果设置了函数名则自动运行函数.
	 * example: $.runJs('/res/abc.js','test','参数'); //载入abc.js文件,并且运行其中的test函数,并传入参数
	 * 如果要使用多参数,可把data设成对象形式. 在abc.js文件中,可以使用本页的资源
	 */
	runJs: function (url, fnName, data)
	{
		$.ajax({
			url : url,
			dataType: 'script',
			async : false
		});
		if(fnName) {
			eval(fnName+"(data)");
		}
	}
});
$.fn.extend({
	/**
	 * $('#btn').hoverClass('btnHover');
	 */
	hoverClass : function(c)
	{
		this.each(function(){
			$(this).hover(
				function() { $(this).addClass(c);  },
				function() { $(this).removeClass(c); }
			);
		});
		return this;
	},
	//$.notify插件的简化版.显示在触发事件的元素旁边 example: $(this).tip('滚');
	tip: function (str,time,url)
	{
		var options = {str: str};
		if(typeof time == 'number') options.time = time;
		if(typeof time == 'string') options.url = time;
		if(typeof url == 'number') options.time = url;
		if(typeof url == 'string') options.url = url;
		options.place = $(this);
		$.notify(options);
	},
	/**
	 * 判断鼠标是否在元素内部 
	 * if($('#jqBox').hasMouse()) alert('在');
	 */
	hasMouse : function(e){
		var bool = false;
		this.each(function(){
			var o = $(this);
			if(!o[0]) return false;
			var offset = o.offset();
			var left = parseInt(offset.left);
			var top = parseInt(offset.top);
			if(e.clientX > left && e.clientX < left+o.width() && e.clientY > top && e.clientY < top+o.height()) {
				bool=true;
			}
		});
		return bool;
	},
	/**
	 * jquery的serialize方法扩展,兼容FCK.为解决FF下多FCK只能获取首个实例的BUG,需要函数FCKeditor_OnComplete和getFck的支持.用getFck获取实例
	 * 例: var post = $('form').getPost();	//post即表单序列化后的值.接着可以被当作普通POST丢给PHP处理
	 * 例: $.post(url, post, callback);	//丢给url处理
	 */
	getPost: function ()
	{
		$.each($(this).find('input:hidden'), function (i,e){
			if($('#'+e.id+'___Config').length == 1) {	//如果存在id___Config控件,则id是FCK的name
				var val = getFck(e.id).GetXHTML(false);
				$('input[name='+e.id+']:hidden, textarea[name='+e.id+']:hidden').val(val);
			}
		});
		return $(this).serialize();
	},
	/**
	 * 禁止或者激活表单元素。
	 * example: 
	 * 1.禁止或激活整个表单：$('form').disable();	$('form').disable(false);
	 * 2.禁止或激活某些元素 $('input').disable();
	 */
	disable: function (action){
		if(action == undefined) action = true;
		var items = this;
		if($(this).attr('tagName') == 'FORM') {
			items = this.find('input[type=text],input[type=radio],input[type=checkbox],textarea,select');
		}
		items.each(function (i,e){
			e.disabled = action;
		});
		return this;
	},
	/*
	 * 直接发送$.postJSON请求.
	 * 例: 
	 */
	postJSON: function (cb)
	{
		$.postJSON($(this).attr('action'), $(this).getPost(), cb);
		return this;
	},
	/**
	 * 对复选框的操作.action可以是choose,cancel,reverse三种,对应全选,全取消,反选三种.默认全选.参数写错归于reverse
	 * 例: $('input[type=checkbox]').checkbox();	//全选
	 *	$('input[type=checkbox]').checkbox('reverse');	//反选
	 */
	checkbox: function (action)
	{
		if(!action) action = 'choose';
		this.each(function (i, e){
			if(action=='choose') {
				e.checked = true;
			}else if(action=='cancel') {
				e.checked = false;
			}else{
				e.checked = !e.checked;
			}
		});
		return this;
	},
	/**
	 * 获取checkbox的值.mod可以是字符串'array'或'str',空参数或写错参数都归为str方式.
	 * 例: var val = $('input[type=checkbox]').checkboxVal();
	 */
	checkboxVal: function (mod)
	{
		if(!mod) mod = 'str';
		var array = new Array(), str = '';
		this.each(function (i, e){
			if(mod=='array') {
				if(e.checked) array.push(e.value);
			}else{
				if(e.checked) str += e.value+',';
			}
		});
		if(mod=='array') return array;
		if(!str) return '';
		return str.substring(0, str.length - 1);
	}
});
//普通js函数 g(id) 相当于 document.getElementById("lrc");
function g(id) {
	return document.getElementById(id);
}
//IE与opera需要在编辑时记住坐标与选中文本，因为一点击提交已经失去焦点了.textObj=js对象
function setCaret(textObj)
{
	if(textObj.createTextRange){
		textObj.caretPos = document.selection.createRange().duplicate();  
	}  
}
//在当前光标处插入文本。textObj是文本区对象，text是要插入的文本。必须在编辑区加入onfocus="setCaret(this)";配合setCaret函数使用
function insertAtCaret(textObj,text)
{
	if(textObj.createTextRange && textObj.caretPos){
		//IE,opera 选中的最后一个字符 caretPos.text.charAt(caretPos.text.length - 1)
		textObj.caretPos.text = text;
	}else if(textObj.setSelectionRange){
		//FF,safari
		var rangeStart = textObj.selectionStart;  
		var rangeEnd = textObj.selectionEnd;  
		var tempStr1 = textObj.value.substring(0,rangeStart);  
		var tempStr2 = textObj.value.substring(rangeEnd);  
		textObj.value = tempStr1 + text + tempStr2;  
	}else{
		alert("编辑区没有焦点或浏览器不支持文本操作");  
	}  
}
//解决火狐下多FCK实例获取不到的问题.以后使用getFck(name)来获取FCK实例.
var __fckEditorInstance_  = new Array();
function FCKeditor_OnComplete( editorInstance ){
    __fckEditorInstance_[editorInstance.Name] = editorInstance;
}
function getFck(idname){
    return __fckEditorInstance_[idname];
}
/**
 * 返回字符串的真实长度(一个全角字符的长度为2)
 * @example str.width()
 */
String.prototype.width = function()
{
	return this.replace(/[^\x00-\xff]/g, "**").length;
};