// cookie 选项
var cookie_options = { path: '/', expires: 365 };
// form 选项
var comment_form_options = {
	beforeSubmit:	checkComment,
	success:		showComment,
	dataType:		'json',
	url:			'/ajax.asp?action=savecomment',
	timeout:		10000
};
var gbook_form_options = {
	beforeSubmit:	checkGbook,
	success:		showGbook,
	dataType:		'json',
	url:			'/ajax.asp?action=savegb'
};

var BlogPath = '/';
/**
 * 当页面装载完成后开始执行
 */
$(document).ready(function() {
	/*返回顶部*/
	var width = ($('body').width() - $('#container').width()) / 2 + $('#sidebars').width() + 15;
	var $backToTopTxt = "返回顶部", $backToTopEle = $('<div class="backToTop"></div>').appendTo($("#page")).text($backToTopTxt).attr("title", $backToTopTxt).css('right', width + 'px'), $backToTopFun = function() {
		var st = $(document).scrollTop(), winh = $(window).height();
		(st > 0)? $backToTopEle.fadeIn('500'): $backToTopEle.fadeOut('500');
		//IE6下的定位
		if (!window.XMLHttpRequest) {
			$backToTopEle.css("top", st + winh - 166);
		}
		$backToTopEle.css('right', width + 'px');
	};
	$(window).bind("scroll", $backToTopFun);
	$(function() { $backToTopFun(); });

	/**
	 * 读取 cookie 并赋值
	 */
	if ($.cookie('author') != null && $.cookie('author') != '')
		$('#author').val($.cookie('author'));
	if ($.cookie('email') != null && $.cookie('email') != '')
		$('#email').val($.cookie('email'));
	if ($.cookie('url') != null && $.cookie('url') != '')
		$('#url').val($.cookie('url'));
	
	$('#url').focus(function() {
		if ($(this).val()=="")
		{
			$(this).val("http:\/\/");
		}
	}).blur(function(){
		if ($(this).val()=="http:\/\/")
		{
			$(this).val("");
		}
	});
	
	$('#comments #comment').keydown(function(event) {
		if ((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) {
			$('#commentform').submit();
			return false;
		}
	});

	$('#gbook #comment').keydown(function(event) {
		if ((event.ctrlKey && event.keyCode == 13) || (event.altKey && event.keyCode == 83)) {
			$('#gbookform').submit();
			return false;
		}
	});
	
	/**
	 * 绑定 commentform 表单的 submit 事件
	 */
	$('#commentform').ajaxForm(comment_form_options);

	$('#commentform #author').next().append(' <div class="a_hint" style="display:none;color:red; float:right;">请留下您的称呼！</div>');
	$('#commentform #email').next().append(' <div class="e_hint" style="display:none;color:red; float:right;">请留下您的邮箱！</div>');
	$('#commentform #comment').before(' <div class="c_hint" style="display:none;color:red;">必须填写评论内容！</div><br />');

	$('#commentform #author').blur(function() { check_author(); });
	$('#commentform #email').blur(function() { check_email(); });
	$('#commentform #comment').blur(function() { check_comment(); });
	/**
	 * 绑定 gbookform 表单的 submit 事件
	 */
	$('#gbookform').ajaxForm(gbook_form_options);

	$('#gbookform #author').next().append(' <div class="a_hint" style="display:none;color:red; float:right;">请留下您的称呼！</div>');
	$('#gbookform #email').next().append(' <div class="e_hint" style="display:none;color:red; float:right;"></div>');
	$('#gbookform #comment').before(' <div class="c_hint" style="display:none;color:red;">必须填写留言内容！</div><br />');

	$('#gbookform #author').blur(function() { check_gbook_author(); });
	$('#gbookform #email').blur(function() { check_gbook_email(); });
	$('#gbookform #comment').blur(function() { check_gbook_comment(); });


	// 显示 回复 字样
	$('#comments dd').hover(
		function() {
			var id = /^comment-content-(\d+)/;
			var commentid;
			var commentauthor;
			if (id.test($(this).attr('id')))
				commentid = RegExp.$1;
			commentauthor = $(this).prev('dt').find('.comment_author').text();
			$(this).append('<div style=" position:absolute; " class="reply"><div style=" position:relative; top: -20px; "><a href="#respond" onclick="return reply('+commentid+', \''+commentauthor+'\')">回复</a></div></div>');
		},
		function() {
			$(this).find('.reply').remove();
		}
	);
	$('#comments dt').hover(
		function() {
			var id = /^comment-content-(\d+)/;
			var commentid;
			var commentauthor;
			if (id.test($(this).attr('id')))
				commentid = RegExp.$1;
			commentauthor = $(this).prev('dt').find('.comment_author').text();
			$(this).next('dd').append('<div style=" position:absolute; " class="reply"><div style=" position:relative; top: -20px; "><a href="#respond" onclick="reply('+commentid+', \''+commentauthor+'\')">回复</a></div></div>');
		},
		function() {
			$(this).next('dd').find('.reply').remove();
		}
	);
	
	// 锚点链接加滚动效果
	var scroll = /^#(.*?)/;
	$('#comments a').each(function() {
		if (jQuery(this).attr('href').match(scroll)) {
			jQuery(this).click(function() {
				jQuery(jQuery(this).attr('href')).ScrollTo(800);
				return false;
			});
		}
	});

	$('.backToTop').click(function(){
		$('#container').ScrollTo(1000);
	});

	// 显示侧边信息
	ShowSidePanel();


	// 图片查看
	hs.graphicsDir = "http://zhangqian.me/plugins/lightbox/images/";
	hs.outlineType = "rounded-white";
	hs.outlineWhileAnimating = true;
	hs.showCredits = false;
	hs.restoreTitle = '点击关闭，可拖动';
	
	resizeImage();
	myTips();
	showCmtNum();

	ChiliBook.automatic = true;
	ChiliBook.lineNumbers = true;
});

function scrollSide() {
	var width = $('#sidebars').width();
	var y = ($('body').width() - $('#content_box').width()) / 2 ;
	var top = $('#content_box').offset().top;
	var scrollTop = $('#infscr-loading').offset().top;
	$('#sidebars').attr('style', 'position: absolute; right: '+y+'px; width: '+width+'px;');
	$('#sidebars').animate({top: scrollTop}, 'slow');
	$(window).scroll(function(){
		var tmp = $(window).scrollTop();
		if (tmp < scrollTop) {
			$('#sidebars').css('position', 'fixed');
			if (tmp < top) {
				$('#sidebars').css('top', (top - tmp) + 'px');
			} else {
				$('#sidebars').css('top', 0 + 'px');
			}
		} else {
			$('#sidebars').css('position', 'absolute');
			$('#sidebars').css('top', scrollTop + 'px');
		}
	});
}

function resizeImage() {
	// 限制图片宽度
	for (i = 0; i < $('#content img').length; i++)
	{
		if ($('#content img').get(i).width > 600) {
			$('#content img').get(i).width = 600;
		}
	}
}

/* 表单验证 */
function check_author() {
	$('.a_hint').fadeOut();
	r = 1;
	if ($('#commentform #author').val() == '') {
		r = 0;
		$('.a_hint').fadeIn();
	}
	return r;
}

function check_gbook_author() {
	$('.a_hint').fadeOut();
	r = 1;
	if ($('#gbookform #author').val() == '') {
		r = 0;
		$('.a_hint').fadeIn();
	}
	return r;
}

function check_email() {
	$('.e_hint').fadeOut();
	r = 1;
	if ($('#commentform #email').val() == '') {
		r = 0;
		$('.e_hint').fadeIn();
	} else if (!isEmail($('#commentform #email').val())) {
		r = 0;
		$('.e_hint').html('邮箱格式不正确！').fadeIn();
	}
	return r;
}

function check_gbook_email() {
	$('.e_hint').fadeOut();
	r = 1;
	if ($('#gbookform #email').val() != '') {
		if (!isEmail($('#gbookform #email').val())) {
			r = 0;
			$('.e_hint').html('邮箱格式不正确！').fadeIn();
		}
	}
	return r;
}

function showCmtNum() {
	
	// 显示评论数
	$('.to_comments .cmt').each(function(){
		var comment_id = /^LogCommentNum(\d+)/;
		if (comment_id.test($(this).attr('id')))
		{
			showCmt(RegExp.$1);
		}
	});
}

function check_comment() {
	$('.c_hint').fadeOut();
	r = 1;
	if ($('#commentform #comment').val() == '') {
		r = 0;
		$('.c_hint').fadeIn();0
	} else if ($('#commentform #comment').val().length < 5) {
		r = 0;
		$('.c_hint').html('评论内容不得少于 5 个字符！').fadeIn();
	}
	return r;
}

function check_gbook_comment() {
	$('.c_hint').fadeOut();
	r = 1;
	if ($('#gbookform #comment').val() == '') {
		r = 0;
		$('.c_hint').fadeIn();0
	} else if ($('#gbookform #comment').val().length < 2) {
		r = 0;
		$('.c_hint').html('留言内容不得少于 2 个字符！').fadeIn();
	}
	return r;
}

function myTips() {
	/* tips start */
	$('<div class="tool-tips"><div class="tool-title"></div><div class="tool-text"></div></div>').appendTo('body');
	$('div > abbr,acronym,.tips').hover(
		function(){
			$(this).css('cursor','help');
			$('.tool-tips').fadeIn('slow');
			var xixu = this;
			if(xixu.title){xixu.yishi=xixu.title;xixu.title='';}
			var dual = xixu.yishi.split('::');
			var myTitle,myText;
			if(dual.length>1){
				myTitle = dual[0];
				myText = dual[1];
			}else{
				myTitle = $(this).text();
				myText = xixu.yishi;
			}
			$('.tool-title').html(myTitle);
			$('.tool-text').html(myText);
		},
		function() {
			$('.tool-tips').fadeOut('slow');
		}
	).mousemove(function(e){
		$('.tool-tips').css('top',e.pageY+15);
		$('.tool-tips').css('left',e.pageX+15);
	});
}

jQuery(document).ready(function(){
	var id=/^#comment-(\d+)/;
	var at=/^@/;
	var zid;
	jQuery('#comment_list dd div p a').each(
		function() {
			if(jQuery(this).attr('href').match(id) && jQuery(this).text().match(at)) {
				jQuery(this).addClass('atreply');
			}
		}
	);
	jQuery('.atreply').hover(
		function() {
			jQuery(this).parents('dd').after('<div class="tip hide"></div>');
			jQuery('.tip').append(jQuery(jQuery(this).attr('href')).clone());
			if (id.test(jQuery(this).attr('href'))) {
				zid = RegExp.$1;
				jQuery('.tip').append(jQuery('#comment-content-' + zid).clone());
			}
			jQuery('.tip').fadeIn('fast');
			
		},
		function() {
			jQuery('.tip').fadeOut('fast', function(){jQuery(this).remove();});
		}
	);
	jQuery('.atreply').mousemove(
		function(e) {
			jQuery('.tip').css({left:(e.clientX+18),top:(e.pageY+18)})
		}
	);
});

/**
 * 验证评论提交
 * @return
 */
function checkComment(formData, jqForm, options) {
	
	$('#submit').after(' <span style="color: red; " id="wait-comment">正在提交，请稍候...</span>');
	$('#submit').attr('disabled', 'disabled');
	var r1 = check_author();
	var r2 = check_email();
	var r3 = check_comment();

	if (r1 && r2 && r3) {
		return true;
	}
	$('#submit').removeAttr('disabled');
	$('#wait-comment').remove();
	return false;

}

/**
 * 验证留言提交
 * @return
 */
function checkGbook(formData, jqForm, options) {
	
	$('#submit').after(' <span style="color: red" id="wait-comment">正在提交，请稍候...</span>');
	$('#submit').attr('disabled', 'disabled');
	var r1 = check_gbook_author();
	var r2 = check_gbook_email();
	var r3 = check_gbook_comment();

	if (r1 && r2 && r3) {
		return true;
	}
	$('#submit').removeAttr('disabled');
	$('#wait-comment').remove();
	return false;
}

function showComment(responseText, statusText, xhr, $form) {
	if (statusText == 'success') {
		if (responseText.response == 'ok') {
			// 评论提交成功后才保存cookie
			$.cookie('author', $('#author').val(), cookie_options);
			$.cookie('email', $('#email').val(), cookie_options);
			$.cookie('url', $('#url').val(), cookie_options);
			
			// 还原表单位置
			reply(0);
			
			var id = responseText.comment.id;
			var author = responseText.comment.author;
			var email = responseText.comment.email;
			var url = responseText.comment.url;
			var content = responseText.comment.content;
			var time = responseText.comment.time;
			var pass = responseText.comment.ispass;
			
			if (pass == '0')
				alert('您的评论提交成功了！\n但被程序识别为 spam，因此要等到审核通过后才会显示。');
			$('#comment_list').append('<div id="newcomment-'+id+'" style=" display: none; "></div>');
			$('#newcomment-'+id).append('<dt class="comment even thread-even depth-1" id="comment-'+id+'"></dt>');
			$('#comment-'+id).append('<span class="avatar"><a href="'+url+'" rel="external nofollow"><img alt="'+author+'" title="'+author+'" src="http://gravatar.com/avatar/'+email+'?s=44&amp;d=identicon&amp;r=G" class="avatar avatar-44 photo" height="44" width="44" /></a></span>');
			$('#comment-'+id).append('<span class="comment_author"><a href="'+url+'" rel="external nofollow" class="url">'+author+'</a></span>');
			$('#comment-'+id).append(' <span class="comment_time"><a href="#comment-'+id+'" title="固定链接" rel="nofollow">'+time+'</a></span>');
			$('#newcomment-'+id).append('<dd class="comment odd alt thread-odd thread-alt depth-1"><div class="format_text" id="comment-body-'+id+'"><p>'+content+'</p></div></dd>');
			$('#newcomment-'+id).slideDown(200, function() { $('#comment').val(''); $('#submit').removeAttr('disabled'); $('#wait-comment').remove(); $('#comment-'+id).ScrollTo(800); });
		} else {
			alert('以下是详细出错信息：' + responseText.errors);
			$('#submit').removeAttr('disabled');
			$('#wait-comment').remove();
		}
	}
}

// 留言发表成功后执行
function showGbook(responseText, statusText, xhr, $form) {
	if (statusText == 'success') {
		if (responseText.response == 'ok') {
			// 留言提交成功后才保存cookie
			$.cookie('author', $('#author').val(), cookie_options);
			$.cookie('email', $('#email').val(), cookie_options);
			$.cookie('url', $('#url').val(), cookie_options);
			
			var id = responseText.gbook.id;
			var author = responseText.gbook.author;
			var email = responseText.gbook.email;
			var url = responseText.gbook.url;
			var content = responseText.gbook.content;
			var time = responseText.gbook.time;
			var pass = responseText.gbook.ispass;
			
			if (pass == '0')
				alert('您的留言提交成功了！\n但被程序识别为 spam，因此要等到审核通过后才会显示。');
			$('#comment_list').prepend('<div id="newcomment-'+id+'" style=" display: none; "></div>');
			$('#newcomment-'+id).append('<dt class="comment even thread-even depth-1" id="gbook-'+id+'"></dt>');
			$('#gbook-'+id).append('<span class="avatar"><a href="'+url+'" rel="external nofollow"><img alt="'+author+'" title="'+author+'" src="http://gravatar.com/avatar/'+email+'?s=44&amp;d=identicon&amp;r=G" class="avatar avatar-44 photo" height="44" width="44" /></a></span>');
			$('#gbook-'+id).append('<span class="comment_author"><a href="'+url+'" rel="external nofollow" class="url">'+author+'</a></span>');
			$('#gbook-'+id).append(' <span class="comment_time"><a href="#gbook-'+id+'" title="固定链接" rel="nofollow">'+time+'</a></span>');
			$('#newcomment-'+id).append('<dd class="comment odd alt thread-odd thread-alt depth-1"><div class="format_text" id="gbook-body-'+id+'"><p>'+content+'</p></div></dd>');
			$('#newcomment-'+id).slideDown(200, function() { $('#comment').val(''); $('#submit').removeAttr('disabled'); $('#wait-comment').remove(); $('#gbook-'+id).ScrollTo(800); });
		} else {
			alert('以下是详细出错信息：' + responseText.errors);
			$('#submit').removeAttr('disabled');
			$('#wait-comment').remove();
		}
	}
}

var rpPel = null;

function $s() {
	if (arguments.length == 1)
		return get$(arguments[0]);
	
	var elements = [];
	$c(arguments).each(function(el) { elements.push(get$(el)); });
	return elements;
}

function get$(el){
	if(typeof el == 'string')
		el = document.getElementById(el);
	return el;
}

function $c(array){
	var nArray = [];
	for (i=0;el=array[i];i++) nArray.push(el);
	return nArray;
}

function reply(id, author) {
	var cfm = $s('commentform');
	var replyId = $s('parentID');
	var dp = $s('parentauthor');
	if(replyId == null){
		alert("Error:\nNo form field called 'postID'.");
		return false;
	}
	
	if (id > 0) {
		if ($('.changereply').val() == undefined)
			$('#parentID').parent('p').after('<p class="changereply"><a href="javascript:void(0);" onclick="reply(0)">取消回复</a></p>');
		
		var OId = $s('comment-content-'+id);
		replyId.value = id;
		
		if (dp)
			dp.value = author;
		
		if($s("cfmguid") == null){
			var c = document.createElement("div");
			c.id = "cfmguid";
			c.style.display = "none";
			cfm.parentNode.insertBefore(c,cfm);
		}
		
		cfm.parentNode.removeChild(cfm);
		OId.appendChild(cfm);

		if($s("comment"))
			$s("comment").focus();

		cfm.style.display = "block";
	} else {
		replyId.value = "0";
		if (dp)
			dp = "";
		
		var c = $s("cfmguid");
		if(c){
			cfm.parentNode.removeChild(cfm);
			c.parentNode.insertBefore(cfm,c);
			$('.changereply').remove();
		}

		if($s("comment"))
			$s("comment").focus();
	}
	return false;
}
//==============================
//侧边栏显示ShowSidePanel()
//参数:Calendar-日历;Count-统计;Comment-评论;GB-留言;Link-友情链接;
//undefined
//==============================
function ShowSidePanel() {
	var ActionFile = "Ajax.Asp?Action=SidePanel&Part=";
	if ($("#CalendarSideDiv")	!= null) AjaxUpdate(BlogPath+ActionFile+"Calendar", "CalendarSideDiv");
	if ($("#CountSideDiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"Count", "CountSideDiv");
	if ($("#CommentSideDiv")	!= null) AjaxUpdate(BlogPath+ActionFile+"Comment", "CommentSideDiv");
	if ($("#BlogsSideDiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"Blogs", "BlogsSideDiv");
	if ($("#GBSideDiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"GB", "GBSideDiv");
//	if (document.getElementById("LinkSideDiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"Link", "LinkSideDiv");
//	if (document.getElementById("TagSideDiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"Tag", "TagSideDiv");
//	if (document.getElementById("famousdiv")		!= null) AjaxUpdate(BlogPath+ActionFile+"Famous", "famousdiv");
//	if (document.getElementById("Say")				!= null) AjaxUpdate(BlogPath+ActionFile+"Say", "Say");
}
//按照要求无刷新更新数据,可用于提取数据
function AjaxUpdate(url, updateobj) {
	jQuery.get(
		url,
		function (data) {
			$('#' + updateobj).html(data);
		}
	);
}
// 显示评论数
function showCmt(id) {
	AjaxUpdate('/ajax.asp?action=logcmt&LogID=' + id, 'LogCommentNum' + id);
}
//Ajax显示日历
function showCalendar(theYear,theMonth) {
	AjaxUpdate(BlogPath+"Ajax.Asp?Action=SidePanel&Part=Calendar&TheYear="+theYear+"&TheMonth="+theMonth, "CalendarSideDiv");
}
//预判浏览器边界
function clearEdge(obj,whichedge) {
	var edgeoffset = (whichedge == "rightedge") ? parseInt("9px")*-1 : parseInt("0")*-1;
	if (whichedge == "rightedge") {
		var windowedge = document.body.scrollLeft + document.body.clientWidth - 30;
		tipobj.contentmeasure = tipobj.offsetWidth;
		if (windowedge - tipobj.x < tipobj.contentmeasure)
			edgeoffset = tipobj.contentmeasure + obj.offsetWidth + parseInt("9px");
	} else {
		var windowedge = document.body.scrollTop + document.body.clientHeight - 15;
		tipobj.contentmeasure = tipobj.offsetHeight;
		if (windowedge - tipobj.y < tipobj.contentmeasure)
			edgeoffset = tipobj.contentmeasure - obj.offsetHeight;
	}
	return edgeoffset;
}
// 日历 tip
function showTip(text,pos,tipwidth) {
	var divblock = document.createElement("div");
	divblock.setAttribute("id", "tipbox");
	document.body.appendChild(divblock);
	tipobj = document.getElementById("tipbox");
	if (document.getElementById("tipbox")) {
		tipobj = document.getElementById("tipbox")
		if (tipwidth != "") {
			tipobj.widthobj			= tipobj.style;
			tipobj.widthobj.width	= tipwidth;
		}
		var FinalLeft	= pos.offsetLeft;
		var FinalTop	= pos.offsetTop;
		var parentEl	= pos.offsetParent;
		while (parentEl != null) {
			FinalLeft	= FinalLeft + parentEl.offsetLeft;
			FinalTop	= FinalTop	+ parentEl.offsetTop;
			parentEl	= parentEl.offsetParent;
		}
		tipobj.x				= FinalLeft;
		tipobj.y				= FinalTop;
		tipobj.style.left		= tipobj.x - clearEdge(pos, "rightedge") + pos.offsetWidth + "px";
		tipobj.style.top		= tipobj.y - clearEdge(pos, "bottomedge") + "px";
		//tipobj.style.left		= tipobj.x - ClearEdge(pos, "rightedge") + pos.offsetWidth + 18 + "px";
		//tipobj.style.top		= tipobj.y - ClearEdge(pos, "bottomedge") + 8 + "px";
		tipobj.style.visibility	= "Visible";
		//创建一个iframe,用来遮挡<select>
		iframeStr = "<iframe id='iframebox' frameBorder='0' style='filter:alpha(opacity=0);'></iframe>";
		tipobj.innerHTML = iframeStr + text;
		iframeObj = document.getElementById("iframebox");
		iframeObj.style.visibility	= "inherit";
		iframeObj.style.position	= "absolute";
		iframeObj.style.top			= "0px";//不能占据页面空间
		iframeObj.style.left		= "0px";//不能占据页面空间
		iframeObj.style.marginLeft	= "-1px";
		iframeObj.style.width		= tipobj.clientWidth + 4 + "px";
		iframeObj.style.height		= tipobj.clientHeight + 2 + "px";
		iframeObj.style.zIndex		= "-1";
		pos.onmouseout = function() {
			if (document.getElementById("tipbox")) {
				document.body.removeChild(document.getElementById("tipbox"));
				//if (document.getElementById("TipBox")) {
					//alert("创建的div还没删除呢")
				//}
			}
		}
	}
}


//运行代码
function RunCode(CodeNum) {
	var bodyTag = $('#' + CodeNum).val();
	preWin = window.open('UBB-RunCode','','left=0,top=0,width=550,height=400,resizable=1,scrollbars=1,status=1, toolbar=1,menubar=0');
	preWin.document.open();
	preWin.document.write(bodyTag);
	preWin.document.close();
	preWin.document.title="运行代码窗口";
	preWin.document.charset="UTF-8";
}
//复制代码,兼容FF
function CopyContent(Content) {
	if (window.clipboardData) {
		window.clipboardData.clearData();
		window.clipboardData.setData("Text", Content);
		alert("内容已经复制到剪切板");
	} else if (navigator.userAgent.indexOf("Opera") != -1) {
		alert('不支持Opera复制，请手动复制。');
	} else if (window.netscape) {
		try {
			netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
		} catch (e) {
			alert("您使用的FireFox浏览器安全设置过高,以至于影响程序的正常响应！\n请在浏览器地址栏输入'about:config'并回车\n然后将'signed.applets.codebase_principal_support'设置为'true'");
		}
		var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
		if (!clip) return;
		var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
		if (!trans) return;
		trans.addDataFlavor('text/unicode');
		var str = new Object();
		var len = new Object();
		var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
		var copytext = Content;
		str.data = copytext;
		trans.setTransferData("text/unicode",str,copytext.length*2);
		var clipid = Components.interfaces.nsIClipboard;
		if (!clip) return false;
		clip.setData(trans,null,clipid.kGlobalClipboard);
		alert("内容已经复制到剪切板");
	}
}
