//
String.prototype.clear = function() { 
	return this.replace(/[`~!@#$%\^&*()+=|\\\{}\[\]:;"'<>?,.\/\x22]+/g,""); 
};
String.prototype.trim = function() { 
	return this.replace(/(^\s*)|(\s*$)/g,""); 
};
String.prototype.trims = function() { 
	return this.replace(/(\s*)/g,""); 
};
//去掉前空格
String.prototype.lTrim = function() { 
	return this.replace(/(^\s*)/g, ""); 
}
//去掉后空格
String.prototype.rTrim = function() { 
	return this.replace(/(\s*$)/g, ""); 
} 
String.prototype.cutHTML = function() { 
	return this.replace(/<\/?[^>]+>/g,""); 
};
String.prototype.reHTML = function(b){
	var s=this+"";
	if(!b){
		s=s.replace(/</g,"&lt;");
		s=s.replace(/>/g,"&gt;");
	}
	s=s.replace(/\r\n/g, "<br/>");
	s=s.replace(/\n/g, "<br/>");
	s=s.replace(" ", "&nbsp; ");
	s=s.replace("　", "&nbsp; &nbsp; ");
	return s;
};
function getJSON(text){
	if(!text) return false;
	if (/^[\],:{}\s]*$/.test(text.replace(/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g, '@').replace(/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g, ']').replace(/(?:^|:|,)(?:\s*\[)+/g, ''))) {
		return eval('('+text+')');
	}
	return false;
};

function addMyVocabulary(vid){
	var e=event?event:window.event;
	var posx=e.clientX+document.documentElement.scrollLeft+10;
	var posy=e.clientY+document.documentElement.scrollTop-20;
	$.get(ctx + "/app/myvocabulary/a/my-word!add.do", {
		'vid' : vid,
		'r': Math.random()
	}, function(msg) {
		$("#info").text(msg);
		$("#showInfo").css({left:posx+"px",top:posy+"px"});
		$("#showInfo").fadeIn(1000); 
		$("#showInfo").fadeOut("slow"); 
		//$("#showInfo").hide();
	}, "txt");
};

function delMyVocabulary(mvid){
	var e=event?event:window.event;
	var posx=e.clientX+document.documentElement.scrollLeft+10;
	var posy=e.clientY+document.documentElement.scrollTop-20;
	$.get(ctx + "/app/myvocabulary/a/my-word!delete.do", {
		'mvid' : mvid,
		'r': Math.random()
	}, function(msg) {
		$("#info").text(msg);
		$("#showInfo").css({left:posx+"px",top:posy+"px"});
		$("#showInfo").fadeIn(1000); 
		$("#showInfo").fadeOut("slow",function(){
			location.reload();
		 });
	}, "txt");
};

function digBlog(bid){
	$.get(ctx + "/app/blog/a/support.do", {
		'bid' : bid,
		'r': Math.random()
	}, function(msg) {
		$("#dig_"+bid).text(msg);
	}, "txt");
};

function buryBlog(bid){
	$.get(ctx + "/app/blog/a/oppose.do", {
		'bid' : bid,
		'r': Math.random()
	}, function(msg) {
		$("#bury_"+bid).text(msg);
	}, "txt");
};

function showFeed(obj,type){
	$("#feedType > li").removeClass("hover");
	$(obj.parentNode).addClass("hover");
	$("#feeds").html("正在读取，请稍候...");
	$.get(ctx + "/feed/a/show-feed.do", {
		'type' : type,
		'r': Math.random()
	}, function(feeds) {
		if(feeds){
			$("#feeds").html(feeds);
		}else{
			$("#feeds").html("<div class=\"tip\">我的朋友好像没有啥动静哦:-(</div>");
		}
	}, "txt");
}
/**
 * 发布评论
 * @return
 */
function addComment(){
	if(!hasLogin){
		alert("请先登录，才能发布评论！");
		return;
	}
	var text=$("#commentTxt").val();
	if(text==""){
		alert("评论不能为空！");
		return;
	}
	$.post(ctx + "/comment/a/add.do", {
		'type' : dtype,
		'did':did,
		'text' : text
	}, function(msg) {
		$("#commentTxt").val("");
		$("#cmtResult").text("评论发布成功!");
		$("#cmtResult").show();
		$("#cmtResult").fadeOut("3000");
	}, "text");
}