var aCookie = document.cookie.split("; ");
function createCookie(name,value,days) {
	if (days) {
		var date = new Date();
		date.setTime(date.getTime()+(days*24*60*60*1000));
		var expires = "; expires="+date.toGMTString();
	}
	else var expires = "";
	document.cookie = name+"="+value+expires+"; path=/";
}

function readCosBetaCookie(CookieEleName)
{
  var cookieValue = "";
  for (var i=0; i < aCookie.length; i++){
	  var CookieArray = aCookie[i].split("=");
	  if (CookieEleName == CookieArray[0]){
			  cookieValue = unescape(decodeURI(CookieArray[1]));
	  }
}
  return cookieValue;
}
var sider_status ='';
function ShowHid(obj){
	var obj2= "." + obj ;
	if(  $("#"+obj).html().indexOf('▼') != -1 ) {
		$("#"+obj).html( $("#"+obj).html().replace('▼','▲') );
		$(obj2).show('slow');
		sider_status = sider_status.replace(obj+',','')
	}else{
		$("#"+obj).html( $("#"+obj).html().replace('▲','▼') );
		$(obj2).hide('slow');
		if( sider_status.indexOf(obj) == -1 )sider_status += obj+ ','
	}
      createCookie('c_sider_status',sider_status,30);

}
var emotion_txt = new Array('MM','yeah','一无所有','七窍生烟','不可以','不好意思','不懂', '不行了','不要拉','乖','什么','你好','保键','偷偷','偷懒','偷窥','傻笑','免谈','冒失','冰冻','冲锋','凄凉','凶手','切','刷牙','努力','包子','北斗神拳','升仙','午夜凶铃','卡烟囱','卯上','发傻','发光','发呆','发嗲','发情','发抖', '发现MM','受惊','可怜i','可爱','吃','吃饭','吐血','吵闹','吸烟','吼','呕吐','呼','哈哈','喷','喷血','嗨','嘘嘘','嘲笑','嘻嘻','嘿嘿','回眸','困','够意思','大哭','大喇叭','天哪','太好','太极','女友','女巫','好喜欢','好郁闷','好香','妈的','委屈','害羞','寒','小样','小狗','尴尬','差的还远','帅','帅哥','广播操','庆祝','得意的笑','心虚','必胜','忐忑不安','快跑','思考','恭喜','悄悄','情人节','情人节礼物','感冒','憋','我不','打我','打电话','投降','拍照','拜托','拜拜','挑逗','挠屁股','挨打','搜索','散花','敬礼','无敌','无知','无聊','晕','欺负','气死','沙发','没睡醒','没门','泪奔','洗澡','游戏','潜水','灵魂','点头','烦躁','爆发','爱情','牛奶','犯贱','犯错','猛','猫王','献花','玩','生气','疑问','看招','睡觉','瞌睡','礼物','祝贺','私奔','耍性子','耍赖','自恋','色急','芭蕾','花痴','蔑视','虚脱','觉悟','诅咒','谢谢','贞子','赶工','路过','踢','逮捕','逼我','郁闷','鄙视','酷','钱啊','闪电','闭嘴','阴笑','难为情','鬼','鬼脸','鼻血');

function emotionIT(ele){
	var gbooktxt = $("#"+ele).html();
	if( gbooktxt == null )return false;
	for (i=0;i<emotion_txt.length ;i++ ){
			var img = "<img src='/emotions/" + i + ".gif' border='0'/>";
			var reg=new RegExp(emotion_txt[i],"g"); //创建正则RegExp对象
			gbooktxt = gbooktxt.replace(reg,emotion_txt[i]+img);
		}
	if( gbooktxt.length > 10 )$("#"+ele).html(gbooktxt);
}


var global_form_txt;
var blogurl="/wp";
var reply_id =0;
function moveForm(a) {
	$("#commentFormDiv").prependTo("#reform-"+a);
	$('#comment_reply_ID').val(a);
	if( a>0 )$('#reRoot').show();else $('#reRoot').hide();
	reply_id = a;
	if(a==0)	window.location= "#reform-"+a;
}
function AjaxSendComment(){  
	var comment = $('#comment').val().replace(/\r\n\r\n/g, "</p><p>");
	comment = comment.replace(/\r\n/g, "<br />");
	comment = comment.replace(/\n\n/g, "</p><p>");
	comment = comment.replace(/\n/g, "<br />");
	var author = $('#author').val()+"";
	var email = $('#email').val()+"";
	var dateObj = new Date();
	if( author.length < 1  ){
		$('#author').addClass("highlight");$('#author').focus();return false;
	}
	if( email.length < 1  ){
		$('#email').addClass("highlight");$('#email').focus();return false;
	}
	if( comment.length < 1 ){
		$('#comment').addClass("highlight");$('#comment').focus();return false;
	}
	var tmp_id = "tmp-"+encodeURI(new Date().getTime());
	$('input.subbt').attr('disabled',true);
	$('#commentFormDiv').before("<div style='border:1px solid #ccc' class='commentlist' id='"+tmp_id+"'><div class='commenthead newcomment'>At "+dateObj.toLocaleString()+", <span class='author'>you just</span> said: </div><div class='body'><p>"  + comment+ "</p></div><div class='meta' id='stat'>服务器正在处理...</div></div>");
	$.ajax({
		  type: "POST",
		  timeout: 100000,
		  url: $("#commentform").attr("action"),
		  data: $("#commentform").serialize(),
		  error:function(emsg){		
			alert("评论失败:" + emsg)	;		
			  $('input.subbt').attr('disabled',false);
				$('#'+tmp_id).remove();
			  },
		  success: function(msg){
			$('#stat').html('数据提交成功');
			$('input.subbt').attr('disabled',false);
			$('#comment').val('');
			$('#stat').hide('slow',function(){$(this).remove();});
		  }
		}); 
	
   return true;
}
function ajaxLink(url,id){
	if(!confirm('你确定这样做？'))return false;
	$(id).fadeOut("slow");
	$.ajax({url: url,
			type: 'GET',
			timeout: 60000,
			error: function(e){
				alert('处理出错啦，请重新尝试!'+e);
				$(id).fadeIn("slow");
			},
			success: function(xml){
				$(id).fadeOut("slow");
			}
		});
	return false;
}
