var listenMsg=0;
var g_blinkswitch = 0; 
var g_blinktitle = document.title; 
//新消息提示
function getmsg() {
        if(listenMsg==0){
		player = '<embed style="position:absolute;top:-100000px" width="0" height="0" type="application/x-shockwave-flash" swliveconnect="true" allowscriptaccess="sameDomain" menu="false" flashvars="sFile='+web_url+'csdj/js/notification.mp3" src="'+web_url+'csdj/js/soundplayer.swf" />';		
		$("#newsmsg").html(player);
		listenMsg = 1;
                setInterval(blinkNewMsg, 1000); 
        }
	return false;
}
function blinkNewMsg() { 
    if (g_blinkswitch % 2 == 0) {
        document.title = "【新消息】" + g_blinktitle
    }else{
        document.title = "【　】" + g_blinktitle
    }
    g_blinkswitch=g_blinkswitch+1;
} 

//复制地址
function copyToClipboard(url,title){
   window.clipboardData.setData("Text",url);
   do_alert(title);setTimeout('close_alert()', 2000);
}

//批量选择图片删除
function getpicdel(_op) {
    var v =0;
　　var ids=$("input[name='id[]']");  

    if(_op=='all'){
　　     for(var i=0;i<ids.length;i++){   
            if(ids[i].checked==true){
　　　　        ids[i].checked="";  
            }else{
　　　　        ids[i].checked="checked";  
            }
         }
    }else{
　　        for(var i=0;i<ids.length;i++){   
                if (ids[i].checked==true) { v++; }
            }
            if (v==0){ 
			do_alert('至少选择一张图片才能进行操作！'); setTimeout('close_alert()', 2000);
			return;  
	    }else{
		   document.formp.submit();
	    }
    }
}


//留言回复
function gbookhf(_id){
     var cura=document.getElementById("gbook_"+_id).style.display;
     if(cura=='none'){
           $("#cs_content"+_id).emotEditor({emot:true});
           document.getElementById("gbook_"+_id).style.display='';
     }else{
           document.getElementById("gbook_"+_id).style.display='none';
     }
}

//动态切换
function getdt(_ac,_id){
    document.getElementById("feed").innerHTML='<div class="load" id="load"></div>';
    if(_ac=='all'){
          document.getElementById("feed_all").className='on';
          document.getElementById("feed_my").className='';
          document.getElementById("a_all").style.display='';
          document.getElementById("a_my").style.display='none';
          for (var i = 0; i < 8; i++) {
               if(_id==i){
                      document.getElementById("all_"+i).className='current';
               }else{
                      document.getElementById("all_"+i).className='';
               }
          }
    }else{
          document.getElementById("feed_all").className='';
          document.getElementById("feed_my").className='on';
          document.getElementById("a_all").style.display='none';
          document.getElementById("a_my").style.display='';
          for (var i = 0; i < 8; i++) {
               if(_id==i){
                      document.getElementById("my_"+i).className='current';
               }else{
                      document.getElementById("my_"+i).className='';
               }
          }
    }
    $.get(web_url+"index.php/user/ajax/dt?ac="+_ac+"&cid="+_id,function(data) {
           if(data){
		document.getElementById('feed').innerHTML = unescape(data);
           }else{
                do_alert('网络连接失败！');setTimeout('close_alert()', 2000);
           }
    });
}

function so_tabs(){
      document.getElementById("seh_sort").style.display='';
}

function so_tab(){
      var cur=document.getElementById("seh_sort").style.display;
      if(cur=='none'){
          document.getElementById("seh_sort").style.display='';
      }else{
          document.getElementById("seh_sort").style.display='none';
      }
}

function getsearch(type,text){
          so_tab();
          document.getElementById("keytype").value=type;
          document.getElementById("keytxt").innerHTML=text;
}

function search_ok(){
      var key=document.getElementById("cscms_key").value;
      var type=document.getElementById("keytype").value;
      if(key==''){
            do_alert('请输入要搜索的关键字');setTimeout('close_alert()', 2000);
      }else{
	    var url=web_url+"index.php/"+type+"/so/key?key="+encodeURIComponent(key);
	    window.open(url);
      }
}

//第三方登入
function getdenglu(id){
      if(id==1){
          document.getElementById("dl_id1").className='selected';
          document.getElementById("dl_id2").className='';
          document.getElementById("denglu_1").style.display='';
          document.getElementById("denglu_2").style.display='none';
          document.getElementById("denglu").value='reg';
      }else{
          document.getElementById("dl_id1").className='';
          document.getElementById("dl_id2").className='selected';
          document.getElementById("denglu_2").style.display='';
          document.getElementById("denglu_1").style.display='none';
          document.getElementById("denglu").value='login';
      }
}

$(document).ready(function(){
        //--------------注册----------------------
	$("#regsubmit").click(function(){
		var username=$("#username").val();
		var userpass=$("#userpass").val();
		var usernichen=$("#usernichen").val();
		var useremail=$("#useremail").val();
		var codes=$("#codes").val();

                $("#username").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
	        $("#userpass").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                $("#usernichen").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		$("#useremail").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		$("#codes").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");

                $("#name_msg").text("帐号应该由6~15位之内的数字、下划线、英文字母组成").css("color","#666");
                $("#pass_msg").text("6位以上数字、字母或者符号的组合").css("color","#666");
                $("#nichen_msg").text("请输入您的昵称。").css("color","#666");
                $("#email_msg").text("重要！找回密码用，推荐使用QQ邮箱。").css("color","#666");
                $("#code_msg").text("输入4位验证码。").css("color","#666");

	    	if(username==""){
			$("#username").css("border","1px solid #666");
			$("#name_msg").text("账号不能为空！").css("color","red");
                        return false;
                } else if((len(username)<4)||(len(username)>16)){
			$("#username").css("border","1px solid #666");
			$("#name_msg").text("账号限制4-16位！").css("color","red");
                        return false;
                } else if(/.*[\u4e00-\u9fa5]+.*$/.test(username)){ 
			$("#username").css("border","1px solid #666");
			$("#name_msg").text("用户名不允许中文注册！").css("color","red");
                        return false;
                } else if(isID(username)==false){
			$("#username").css("border","1px solid #666");
			$("#name_msg").text("用户名不允许特殊字符！").css("color","red");
                        return false;
                } else if(userpass==""){
			$("#userpass").css("border","1px solid #666");
			$("#pass_msg").text("登陆密码不能为空！").css("color","red");
                        return false;
                } else if(len(userpass)<6){
			$("#userpass").css("border","1px solid #666");
			$("#pass_msg").text("登陆密码限制6位以上！").css("color","red");
                        return false;
                } else if(usernichen==""){
			$("#usernichen").css("border","1px solid #666");
			$("#nichen_msg").text("请输入您的呢称！").css("color","red");
                        return false;
                } else if(useremail==""){
			$("#useremail").css("border","1px solid #666");
			$("#email_msg").text("邮箱不能为空！").css("color","red");
                        return false;
                } else if(isEmail(useremail)==false){
			$("#useremail").css("border","1px solid #666");
			$("#email_msg").text("邮箱格式错误！").css("color","red");
                        return false;
                } else if(codes==""){
			$("#codes").css("border","1px solid #666");
			$("#code_msg").text("验证码不能为空！").css("color","red");
                        return false;
                }
	})

        //--------------登入----------------------
	$("#loginsubmit").click(function(){
		var username=$("#username").val();
		var userpass=$("#userpass").val();

                $("#username").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
	        $("#userpass").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                $("#name_msg").text("帐号应该由6~15位之内的数字、下划线、英文字母组成").css("color","#666");
                $("#pass_msg").text("6位以上数字、字母或者符号的组合").css("color","#666");

	    	if(username==""){
			$("#username").css("border","1px solid #666");
			$("#name_msg").text("账号不能为空！").css("color","red");
                        return false;
                } else if(userpass==""){
			$("#userpass").css("border","1px solid #666");
			$("#pass_msg").text("登陆密码不能为空！").css("color","red");
                        return false;
                }
	})

        //--------------找回密码----------------------
	$("#passsubmit").click(function(){
		var username=$("#username").val();
		var useremail=$("#useremail").val();
		var codes=$("#codes").val();

                $("#username").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		$("#useremail").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		$("#codes").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                $("#name_msg").text("帐号应该由6~15位之内的数字、下划线、英文字母组成").css("color","#666");
                $("#email_msg").text("请输入您在注册时填写的邮箱。").css("color","#666");
                $("#code_msg").text("输入4位验证码。").css("color","#666");

	    	if(username==""){
			$("#username").css("border","1px solid #666");
			$("#name_msg").text("账号不能为空！").css("color","red");
                        return false;
                } else if(useremail==""){
			$("#useremail").css("border","1px solid #666");
			$("#email_msg").text("邮箱不能为空！").css("color","red");
                        return false;
                } else if(isEmail(useremail)==false){
			$("#useremail").css("border","1px solid #666");
			$("#email_msg").text("邮箱格式错误！").css("color","red");
                        return false;
                } else if(codes==""){
			$("#codes").css("border","1px solid #666");
			$("#code_msg").text("验证码不能为空！").css("color","red");
                        return false;
                }
	})

        //--------------修改新密码----------------------
	$("#passtosubmit").click(function(){
		var userpass=$("#userpass").val();
		var userpass2=$("#userpass2").val();

                $("#userpass").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		$("#userpass2").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                $("#pass_msg").text("请输入您的新密码。").css("color","#666");
                $("#pass2_msg").text("新密码确定。").css("color","#666");

	    	if(userpass==""){
			$("#userpass").css("border","1px solid #666");
			$("#pass_msg").text("新密码不能为空！").css("color","red");
                        return false;
                } else if(len(userpass)<6){
			$("#userpass").css("border","1px solid #666");
			$("#pass_msg").text("新密码限制6位以上！").css("color","red");
                        return false;
                } else if(userpass!=userpass2){
			$("#userpass2").css("border","1px solid #666");
			$("#pass2_msg").text("两次密码不一直！").css("color","red");
                        return false;
                }
	})

        //--------------第三放登入----------------------
	$("#denglusubmit").click(function(){
		var denglu=$("#denglu").val();

		var usernichen=$("#usernichen").val();
		var useremail=$("#useremail").val();

		var username=$("#username").val();
		var userpass=$("#userpass").val();

                if(denglu=='reg'){ //新注册

                       $("#usernichen").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#useremail").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#nichen_msg").text("请输入您的昵称。").css("color","#666");
                       $("#email_msg").text("请输入您的邮箱。").css("color","#666");

	    	       if(usernichen==""){
			       $("#usernichen").css("border","1px solid #666");
			       $("#nichen_msg").text("请输入您的呢称！").css("color","red");
                               return false;
                       } else if(useremail==""){
			       $("#useremail").css("border","1px solid #666");
			       $("#email_msg").text("请输入您的邮箱！").css("color","red");
                               return false;
                       } else if(isEmail(useremail)==false){
			       $("#useremail").css("border","1px solid #666");
			       $("#email_msg").text("邮箱格式错误！").css("color","red");
                               return false;
                       }

                }else{ //绑定登陆

                       $("#username").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#userpass").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#name_msg").text("您在本站注册的帐号。").css("color","#666");
                       $("#pass_msg").text("您在本站注册的密码。").css("color","#666");

	    	       if(username==""){
			       $("#username").css("border","1px solid #666");
			       $("#name_msg").text("请输入帐号！").css("color","red");
                               return false;
                       } else if(userpass==""){
			       $("#userpass").css("border","1px solid #666");
			       $("#pass_msg").text("请输入密码！").css("color","red");
                               return false;
                       }
                }
	})

        //--------------歌曲发表----------------------
	$("#danceadd").click(function(){
		var cs_name=$("#cs_name").val();
		var cs_cid=$("#cs_cid").val();
		var cs_cion=$("#cs_cion").val();
		var cs_playurl=$("#cs_playurl").val();


                       $("#cs_name").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_cid").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_cion").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_name").text("作为歌曲名字请您认真填写，合理的名字审核才会通过。").css("color","#666");
                       $("#msg_cid").text("歌曲所属的类型，请正确选择。").css("color","#666");
                       $("#msg_cion").text("歌曲下载需要金币。").css("color","#666");


	    	       if(cs_name==""){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入合理的歌曲名字！").css("color","red");
                               return false;
                       } else if((len(cs_name)<8)){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入合理的歌曲名字！").css("color","red");
                               return false;
                       } else if(cs_cid==0){
			       $("#cs_cid").css("border","1px solid #666");
			       $("#msg_cid").text("请选择歌曲分类！").css("color","red");
                               return false;
                       } else if(cs_cion==""){
			       $("#cs_cion").css("border","1px solid #666");
			       $("#msg_cion").text("请输入歌曲下载金币！").css("color","red");
                               return false;
                       } else if(cs_cion>500){
			       $("#cs_cion").css("border","1px solid #666");
			       $("#msg_cion").text("金币不能大于500！").css("color","red");
                               return false;
                       } else if(cs_playurl==""){
			       $("#msg_upload").text("请先上传歌曲！").css("color","red");
                               return false;
                       }
	})

        //--------------发送消息----------------------
	$("#msgadd").click(function(){
		var cs_usera=$("#cs_usera").val();
		var cs_name=$("#cs_name").val();
		var cs_neir=$("#cs_neir").val();

		       $("#cs_usera").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#cs_name").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_neir").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_usera").text("接收会员名，一定要真实。").css("color","#666");
                       $("#msg_name").text("消息标题,50个字以内。").css("color","#666");
                       $("#msg_neir").text("消息内容，200字以内。").css("color","#666");


	    	       if(cs_usera==""){
			       $("#cs_usera").css("border","1px solid #666");
			       $("#msg_usera").text("请输入接收会员！").css("color","red");
                               return false;
                       } else if(cs_name==""){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入消息标题！").css("color","red");
                               return false;
                       } else if(cs_neir==""){
			       $("#cs_neir").css("border","1px solid #666");
			       $("#msg_neir").text("请输入消息内容！").css("color","red");
                               return false;
                       } else if(len(cs_neir)>200){
			       $("#cs_neir").css("border","1px solid #666");
			       $("#msg_neir").text("消息内容200字以内！").css("color","red");
                               return false;
                       }
	})

        //--------------分享视频----------------------
	$("#vodadd").click(function(){
		var cs_name=$("#cs_name").val();
		var cs_pic=$("#cs_pic").val();
		var cs_cid=$("#cs_cid").val();
		var cs_laiy=$("#cs_laiy").val();
		var cs_laiyuan=$("#cs_laiyuan").val();
		var cs_playurl=$("#cs_playurl").val();
                var uploadhtml=$("#msg_upload").html();

                       $("#cs_name").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#cs_cid").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_laiy").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_playurl").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_name").text("作为视频名字请您认真填写，合理的名字审核才会通过。").css("color","#666");
                       $("#msg_cid").text("视频所属的类型，请正确选择。").css("color","#666");
                       $("#msg_laiy").text("选择视频来源。").css("color","#666");
                       $("#msg_upload").html(uploadhtml);


	    	       if(cs_name==""){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入合理的视频名称！").css("color","red");
                               return false;
                       } else if((len(cs_name)<8)){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入合理的视频名称！").css("color","red");
                               return false;
                       } else if(cs_cid=="0"){
			       $("#cs_cid").css("border","1px solid #666");
			       $("#msg_cid").text("请选择视频分类！").css("color","red");
                               return false;
                       } else if(cs_pic==""){
			       //$("#cs_pic").css("border","1px solid #666");
			       $("#msg_pic").text("请上传视频图片！").css("color","red");
                               return false;
                       } else if(cs_laiyuan=="0"){
			       $("#cs_laiy").css("border","1px solid #666");
			       $("#msg_laiy").text("请先选择视频来源！").css("color","red");
                               return false;
                       } else if((cs_laiyuan=="flv" || cs_laiyuan=="media") && cs_playurl==""){
			       $("#msg_upload").text("请先上传视频！").css("color","red");
                               return false;
                       }else if(cs_playurl==""){
			       $("#msg_upload").text("请输入对应的视频地址！").css("color","red");
                               return false;
                       }
	})

        //--------------发表文章----------------------
	$("#newsadd").click(function(){
		var cs_name=$("#cs_name").val();
		var cs_cid=$("#cs_cid").val();
		var cs_content=$("#cs_content").val();

                       $("#cs_name").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#cs_cid").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_content").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_name").text("作为文章标题请您认真填写，合理的名字审核才会通过。").css("color","#666");
                       $("#msg_cid").text("文章所属的分类，请正确选择。").css("color","#666");
                       $("#msg_content").text("文章内容。").css("color","#666");


	    	       if(cs_name==""){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入文章标题！").css("color","red");
                               return false;
                       } else if((len(cs_name)<8)){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入合理的文章标题！").css("color","red");
                               return false;
                       } else if(cs_cid=="0"){
			       $("#cs_cid").css("border","1px solid #666");
			       $("#msg_cid").text("请选择文章分类！").css("color","red");
                               return false;
                       }else if(cs_content==""){
			       $("#cs_content").css("border","1px solid #666");
			       $("#msg_content").text("请编写文章内容！").css("color","red");
                               return false;
                       }else if((len(cs_content)<40)){
			       $("#cs_content").css("border","1px solid #666");
			       $("#msg_content").text("文章内容太少了！").css("color","red");
                               return false;
                       }
	})

        //--------------制作专题----------------------
	$("#topicadd").click(function(){
		var cs_name=$("#cs_name").val();
		var cs_pic=$("#cs_pic").val();
		var cs_content=$("#cs_content").val();

                       $("#cs_name").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_content").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_name").text("作为专题名称请您认真填写，合理的名字审核才会通过。").css("color","#666");
                       $("#msg_pic").text("请上传专题图片。").css("color","#666");
                       $("#msg_content").text("请编写专题介绍。").css("color","#666");


	    	       if(cs_name==""){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入专题名称！").css("color","red");
                               return false;
                       } else if((len(cs_name)<4)){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入合理的专题名称！").css("color","red");
                               return false;
                       } else if(cs_pic==""){
			       $("#cs_pic").css("border","1px solid #666");
			       $("#msg_pic").text("请上传专题图片！").css("color","red");
                               return false;
                       }else if(cs_content==""){
			       $("#cs_content").css("border","1px solid #666");
			       $("#msg_content").text("请编写专题介绍！").css("color","red");
                               return false;
                       }else if((len(cs_content)<15)){
			       $("#cs_content").css("border","1px solid #666");
			       $("#msg_content").text("专题介绍也太少了！").css("color","red");
                               return false;
                       }
	})

        //--------------发布图片----------------------
	$("#picadd").click(function(){
		var cs_name=$("#cs_name").val();
		var cs_pic=$("#cs_pic").val();
		var cs_content=$("#cs_content").val();

                       $("#cs_name").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_content").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_name").text("作为图片标题请您认真填写，合理的名字审核才会通过。").css("color","#666");
                       $("#msg_pic").text("请上传图片。").css("color","#666");
                       $("#msg_content").text("请编写图片介绍。").css("color","#666");


	    	       if(cs_name==""){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入图片标题！").css("color","red");
                               return false;
                       } else if((len(cs_name)<4)){
			       $("#cs_name").css("border","1px solid #666");
			       $("#msg_name").text("请输入合理的图片标题！").css("color","red");
                               return false;
                       } else if(cs_pic==""){
			       $("#cs_pic").css("border","1px solid #666");
			       $("#msg_pic").text("请上传图片！").css("color","red");
                               return false;
                       }else if(cs_content==""){
			       $("#cs_content").css("border","1px solid #666");
			       $("#msg_content").text("请编写图片标题介绍！").css("color","red");
                               return false;
                       }else if((len(cs_content)<6)){
			       $("#cs_content").css("border","1px solid #666");
			       $("#msg_content").text("图片标题介绍也太少了！").css("color","red");
                               return false;
                       }
	})

        //--------------修改资料----------------------
	$("#ziliaoedit").click(function(){
		var cs_nichen=$("#cs_nichen").val();
		var cs_email=$("#cs_email").val();

                       $("#cs_nichen").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_email").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_nichen").text("您的昵称。").css("color","#666");
                       $("#msg_email").text("您的邮箱,找回密码用的，必须真实。").css("color","#666");


	    	       if(cs_nichen==""){
			       $("#cs_nichen").css("border","1px solid #666");
			       $("#msg_nichen").text("请输入您的昵称！").css("color","red");
                               return false;
                       } else if((len(cs_nichen)>20)){
			       $("#cs_nichen").css("border","1px solid #666");
			       $("#msg_nichen").text("请输入合理的昵称！").css("color","red");
                               return false;
                       } else if(cs_email==""){
			       $("#cs_email").css("border","1px solid #666");
			       $("#msg_email").text("请输入您的邮箱！").css("color","red");
                               return false;
                       } else if(isEmail(cs_email)==false){
			       $("#cs_email").css("border","1px solid #666");
			       $("#msg_email").text("邮箱格式错误！").css("color","red");
                               return false;
                       }
	})

        //--------------修改密码----------------------
	$("#passedit").click(function(){
		var cs_pass=$("#cs_pass").val();
		var cs_pass1=$("#cs_pass1").val();
		var cs_pass2=$("#cs_pass2").val();

                       $("#cs_pass").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#cs_pass1").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
		       $("#cs_pass2").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_pass").text("6到20个字符，请使用英文字母（区分大小写）、符号或数字。").css("color","#666");
                       $("#msg_pass1").text("同上。").css("color","#666");
                       $("#msg_pass2").text("同上。").css("color","#666");

	    	       if(cs_pass==""){
			       $("#cs_pass").css("border","1px solid #666");
			       $("#msg_pass").text("请输入您的原密码！").css("color","red");
                               return false;
	    	       } else if(cs_pass1==""){
			       $("#cs_pass1").css("border","1px solid #666");
			       $("#msg_pass1").text("请输入您的新密码！").css("color","red");
                               return false;
                       } else if(len(cs_pass1)<6){
			        $("#cs_pass1").css("border","1px solid #666");
			        $("#msg_pass1").text("登陆密码限制6位以上！").css("color","red");
                                return false;
                       } else if(cs_pass2!=cs_pass1){
			       $("#cs_pass2").css("border","1px solid #666");
			       $("#msg_pass2").text("两次密码不一直！").css("color","red");
                               return false;
                       }
	})

        //--------------金币充值----------------------
	$("#topay").click(function(){
		var cs_rmb=$("#cs_rmb").val();

                       $("#cs_rmb").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_rmb").text("请填写要充值的整数。").css("color","#666");

	    	       if(cs_rmb==""){
			       $("#cs_rmb").css("border","1px solid #666");
			       $("#msg_rmb").text("请输入要充值的数量！").css("color","red");
                               return false;
                       } else if(cs_rmb<10){
			        $("#cs_rmb").css("border","1px solid #666");
			        $("#msg_rmb").text("最少要充值10元！").css("color","red");
                                return false;
                       }
	})

        //--------------升级VIP----------------------
	$("#tovip").click(function(){
		var cs_vip=$("#cs_vip").val();

                       $("#cs_vip").css("border-color","#DCDCDC #DCDCDC #DCDCDC #DCDCDC");
                       $("#msg_vip").text("请选择要升级的会员组。").css("color","#666");

	    	       if(cs_vip=="" || cs_vip==0){
			       $("#cs_vip").css("border","1px solid #666");
			       $("#msg_vip").text("请选择要升级的会员组！").css("color","red");
                               return false;
                       }
	})

        $('form').submit(function() {
             if(typeof jQuery.data(this, "disabledOnSubmit") == 'undefined') {
                 jQuery.data(this, "disabledOnSubmit", { submited: true });
                 $('input[type=submit], input[type=button]', this).each(function() {
                      $(this).attr("disabled", "disabled");
                 });
                 return true;
             } else {
                 return false;
             }
        });
})

//回复留言
function gbooksave(_id,_user){
	var cs_neir=$("#cs_content"+_id).emotEditor("content");
	if(cs_neir==""){
		$("#msg_gbook_"+_id).text("请输入回复内容！").css("color","red");
                return false;
        }else{
		$.ajax({
			type: "POST",
			global: false,// 禁用全局Ajax事件.
			url: web_url+"index.php/user/ajax/gbookhf",
			data:{'cs_neir': cs_neir,'cs_fid': _id, 'cs_usera':_user},
			dataType: "text",
			success: function(data){
				if(data=='10001'){
                                       do_alert('参数错误，回复ID为空！');setTimeout('close_alert()', 2000);
				}
				else if(data=='10002'){
                                       do_alert('参数错误，回复会员为空！');setTimeout('close_alert()', 2000);
				       return false;
				}
				else if(data=='10003'){
                                       do_alert('参数错误，回复内容为空！');setTimeout('close_alert()', 2000);
				       return false;
				}
				else if(data=='10004'){
                                       do_alert('参数错误，回复会员不存在！');setTimeout('close_alert()', 2000);
				       return false;
				}
				else if(data=='10004'){
                                       do_alert('抱歉，留言回复失败！');setTimeout('close_alert()', 2000);
				       return false;
				}
				else{
                                       do_alert('恭喜您，留言回复成功！');setTimeout('location.replace(location);', 2000);
				       return false;
				}
			}
		});
        }
}

function len(s) {
     var l = 0;
     var a = s.split("");
     for (var i=0;i<a.length;i++) {
	if (a[i].charCodeAt(0)<299) {
	     l++;
	}else{
             l+=2;
	}
     }
     return l;
}

//判断特殊字符---------------------
function isID(str){
	res = /^(?!_)(?!.*?_$)[a-zA-Z0-9\u4e00-\u9fa5]+$/;
	var re = new RegExp(res);
	return !(str.match(re) == null);
};
//判断EMAIL----------------------
function isEmail(str){
       res = /^[0-9a-zA-Z_\-\.]+@[0-9a-zA-Z_\-]+(\.[0-9a-zA-Z_\-]+)*$/;
       var re = new RegExp(res);
       return !(str.match(re) == null);
};

//个人中心微博发布-------------------------------------------------------------
var miniblogLib = {
	miniblogTimer: 0,
	miniblogHomeAddInit:function(){
		var $note = $("#note");//微博内容
		var noteContent = "发一条说说, 让大家知道你在做什么...";
		$note.emotEditor({emot:true, charCount:true, defaultText:noteContent, defaultCss: 'default_color'});
		$(".send").click(function(){
			var op = $(this).attr('op');
			var validCharLength = $note.emotEditor("validCharLength");
			if(validCharLength<1 || $note.emotEditor("content")==""){
                                do_alert('请输入您的微博内容！');setTimeout('close_alert()', 2000);
				$note.emotEditor("focus");
				return false;
			}
			$.ajax({
				type: "POST",
				global: false,// 禁用全局Ajax事件.
				url: web_url+"index.php/user/ajax/blogadd",
				data:{'neir': $note.emotEditor("content")},
				dataType: "text",
				success: function(data){
					if(data==10001){
                                                do_alert('请输入您的微博内容！');setTimeout('close_alert()', 2000);
						$note.emotEditor("focus");
						return false;
					}
					else if(data==10002){
                                                do_alert('微博内容不能超过140个字！');setTimeout('close_alert()', 2000);
						$note.emotEditor("focus");
						return false;
					}
					else if(data==10003){
                                                do_alert('您需要先登录才能进行操作！');setTimeout('close_alert()', 2000);
					}
					else if(data==10004){
                                                do_alert('您操作的太频繁，请稍后再试！');setTimeout('close_alert()', 2000);
						$note.emotEditor("focus");
						return false;
					}
					else if(data==10005){
                                                do_alert('抱歉，发表失败，请稍后再试！');setTimeout('close_alert()', 2000);
						$note.emotEditor("focus");
						return false;
					}
					else{
                                                $note.emotEditor("");
                                                if(op=='all'){
						    getdt('all','0');
                                                }else{
                                                    location.replace(location);
                                                }
					}
				}
			});
			return false;
		});
	}
	
}


//表情编辑器----------------------------------------------------------------------
//1.0.3
var isPad='';
var browser = {};
var ua = navigator.userAgent.toLowerCase();
var browserStr;
(browserStr = ua.match(/msie ([\d]+)/)) ? browser.ie = browserStr[1] :
(browserStr = ua.match(/firefox\/([\d]+)/)) ? browser.firefox = browserStr[1] :
(browserStr = ua.match(/chrome\/([\d]+)/)) ? browser.chrome = browserStr[1] :
(browserStr = ua.match(/opera.([\d]+)/)) ? browser.opera = browserStr[1] :
(browserStr = ua.match(/version\/([\d]+).*safari/)) ? browser.safari = browserStr[1] : 0;
var isPad = navigator.userAgent.match(/iPad|iPhone|iPod|Android/i) != null;
(function($) {
	var emotRegStr = "<img([^\<\>(src=)])*src=\""+ web_url +"csdj/images/faces/e([0-9]{0,}).gif\"([^\<\>])*>";
	var emotReg = new RegExp(emotRegStr, "ig");
	var methods = {
		init : function(options) {
			var defaults = {
				emot: false,
				charCount: false,
				focus: false,
				newLine: false,
				allowed: 140,
				warning: 25,
				emotPrefix: 'emot_',
				css: 'countercss',
				counterElement: 'span',
				warningCss: 'warning',
				exceededCss: 'exceeded',
				counterText: '',
				defaultText:'',
				defaultCss: ''
			};
			var options = $.extend(defaults, options);
			
			if(options.emot){
				var emotHtml = '<ul onselectstart="return false">';
				for (i = 1; i <= 56; i++) {
					emotHtml += '<li emotId=' + i + '><img src="'+ web_url +'csdj/images/faces/e' + i + '.gif" class=\"emot_img\" /></li>'
				}
				emotHtml += '</ul>';
			}
			
			//更新字符统计
			function calculate($obj) {
				var $counterObj = $obj.next();
				var count = contentLength($obj.html());
				var available = options.allowed - count;
				if (available <= options.warning && available >= 0) {
					$counterObj.addClass(options.warningCss)
				} else {
					$counterObj.removeClass(options.warningCss)
				}
				if (available < 0) {
					$counterObj.addClass(options.exceededCss)
				} else {
					$counterObj.removeClass(options.exceededCss)
				}
				$counterObj.html(options.counterText + available)
			};
			
			return this.each(function(e) {
				var $obj = $(this);
				var obj = this;
				var objId = $obj.attr('id');
				var $baseObj = $obj.prev();
				var baseObj = $baseObj[0];
				var $emotObj = '';
				var emotMenuOpen = false;
				var isKeydown = false;
				var isCtrl = false;
				var pasting = false;
				var clicking = false;
				var defaultCss = '';
				var caretPos = -1;
				var objRange = [];
				if(options.defaultCss!=''){
					defaultCss = ' ' + options.defaultCss
				}
				else{
					defaultCss = '';
				}
				
				//转为编辑模式
				var j = 0;
				if($baseObj.length==0 || $baseObj.attr('edit') != 'editor_'+objId){
					if(isPad){
						$obj.hide().before('<textarea edit="editor_'+objId+'" class="' + $obj.attr("class") + defaultCss + '">'+options.defaultText+'</textarea>');
						$obj.attr("contenteditable", false);
						$baseObj = $obj.prev();
						baseObj = $baseObj[0];
						$baseObj.bind("focus", function(){
							if($baseObj.val()==options.defaultText){
								$baseObj.val('').removeClass(defaultCss);
							}
						})
						.bind("blur", function(){
							if($baseObj.val()==''){
								$baseObj.val(options.defaultText).addClass(defaultCss);
							}
						});
					}
					else{
						$obj.hide().before('<div edit="editor_'+objId+'" class="' + $obj.attr("class") + defaultCss + '" contenteditable="true">'+options.defaultText+'</div>');
						$obj.attr("contenteditable", false);
						$baseObj =  $obj.prev();
						$baseObj.bind("focus", function(){
							$baseObj.html(options.defaultText).attr("contenteditable", false).hide();
							$obj.attr("contenteditable", true).show();
							obj.focus();
							objRange = getRange(obj, objRange);
						});
						
						$baseObj[0].ondragover = function (e) {
							var e = e || window.event;
							e.dataTransfer.dropEffect = 'none';
							return false;
						};
					}
					
					
					//字符计数
					if(options.charCount){
						$obj.after('<' + options.counterElement + ' class="' + options.css + '">' + options.counterText + '</' + options.counterElement + '>');
						//预载一次字符统计
						calculate($obj);
					}
					
					//表情
					if(options.emot){
						$emotObj = $("#"+options.emotPrefix+$obj.attr('id'));
						var $emotMenu = null;
						$emotObj.click(function(e) {
							$(".emotMenu").hide();
							emotMenuOpen = true;
							if($emotMenu==null){
								$emotMenu = jQuery('<div />').addClass('emotMenu');
								$emotObj.after($emotMenu);
								$emotMenu.html(emotHtml).click(function(e){
									e.stopPropagation();
								})
								.find("ul>li").click(function(e) {
									var id = $(this).attr("emotId");
									
									if(isPad){
										baseObj.focus();
										var str = $baseObj.val();
										$baseObj.val();
										$baseObj.val(str+'[em:'+id+']');
										$obj.html(str+'[em:'+id+']');
									}
									else{
										var sHtml = "&nbsp;<img src=\""+ web_url +"csdj/images/faces/e"+id+".gif\">&nbsp;";
										if(!objRange['range'] || $obj.is(":hidden") == true){
											$baseObj.attr("contenteditable", false).hide();
											$obj.attr("contenteditable", true).show();
											obj.focus();
											objRange = getRange(obj, objRange);
											if(browser.ie){
												var range = document.selection.createRange();
												range.pasteHTML(sHtml+'<br>');
												with(range){
													moveStart("character", -1);
													collapse();
													select();
												}
											}else{
												document.execCommand('InsertHtml', false, sHtml);
											}
										}
										else{
											obj.focus();
											if(document.activeElement != obj){
												objRange = getRange();
											}
											if(browser.ie){
												if(!objRange['range'].length==1){
													objRange['range'].select();
													objRange['range'].collapse(false);
													objRange['range'].pasteHTML(sHtml);
													objRange['range'].select();
													var str = $obj.html();
													var reg = new RegExp("([\S\s]*)("+emotRegStr+"&nbsp;)$", "ig");
													if(reg.test(str)){
														objRange['range'].pasteHTML('<br>');
														with(objRange['range']){
															moveStart("character", -1);
															collapse();
															select();
														}
													}
													else if(!/([\S\s]*)(<br>)$/i.test(str)){
														caretPos = getcaretPos(obj);
														$obj.append('<br>');
														setcaretPos(obj, caretPos);
														objRange = getRange(obj, objRange);
													}
												}
												else{
													objRange['range'](0).src = web_url +"csdj/images/faces/e"+id+".gif";
													objRange['range'].select();
												}
											}else{
												var fragment = objRange['range'].createContextualFragment(sHtml);
												var oLastNode = fragment.lastChild;
												objRange['range'].collapse(false);
												//objRange['range'].deleteContents();
												objRange['range'].insertNode(fragment);
												objRange['range'].setEndAfter(oLastNode);//设置末尾位置
												objRange['range'].collapse(false);//合并范围至末尾
												objRange['sel'].removeAllRanges();//清除range 
												objRange['sel'].addRange(objRange['range']);//设置range
											}
										}
										objRange = getRange(obj, objRange);
									}
									
									$emotMenu.css("display", "none");
									if(options.charCount){
										calculate($obj);
									}
									e.stopPropagation();
								});
							}
							else{
								$emotMenu.css("display", "block");
							}
							e.stopPropagation();
						});
					}
					
					if(isPad){
						baseObj.onkeyup = function(){
							$obj.html($baseObj.val());
							if(options.charCount){
								calculate($obj);
							}
						}
						
						baseObj.onkeydown = function(e) {
							if(e.keyCode===13 && !options.newLine){
								return false;
							}
						}
					}
					else{
						var j = 0;
						
						obj.onclick = function(e){
							if(e && e.stopPropagation){
								e.stopPropagation();
							}
							else {
								window.event.cancelBubble = true;
							}
							
							if ( e && e.preventDefault ){
								e.preventDefault();
							}
							else {
								window.event.returnValue = false;
							}
							
							if(clicking){
								return false;
							}
							clicking = true;
							if(browser.ie){
								setTimeout(function(){ //ie下onclick获取焦点需要延时处理
									objRange = getRange(obj, objRange);
									$(".emotMenu").hide();
									clicking = false;
								},400);
							}
							else{
								objRange = getRange(obj, objRange);
								clicking = false;
							}
							if(emotMenuOpen){
								$emotMenu.css("display", "none");
								emotMenuOpen = false;
							}
							if(options.charCount){
								calculate($obj);
							}
							return false;
						}
						
						obj.onfocus = function(e) {
							//焦点负担太重，尽量不做任何处理
						};
						
						obj.onkeyup = function(e) {
							var e = e || event;
							var keyCode = e.keyCode;
							
							if(keyCode===17){ //ctrl
								isCtrl = false;
							}
							
							setTimeout(function(){
								if(keyCode>=32){
									objRange = getRange(obj, objRange);
									
									if(options.charCount){
										calculate($obj);
									}
								}
							},1);	
						};
						
						obj.onpaste = function(e){
							if(pasting){
								return false;
							}
							pasting = true;
							//ie webkit
							if(ua.match(/msie ([\d]+)/) || ua.match(/applewebkit\//)){
								var newNode = document.createElement("textarea");
								newNode.style.top = ($(document).scrollTop() + 30)+"px";
								newNode.style.left = "-10000px";
								newNode.style.height = "500px";
								newNode.style.width = "500px";
								newNode.style.position = "absolute";
								newNode.style.overflow = "hidden";
								$("body").append(newNode);
								if(ua.match(/msie ([\d]+)/)){
									var range = document.selection.createRange();
									newNode.focus();
									document.execCommand("paste");
									var str = $(newNode).val();

									if(range.length==1){
										var newNode = document.createTextNode(str);
										range(0).parentNode.replaceChild(newNode, range(0));//直接替换标签
										newNode = null;
									}
									else{
										obj.focus();
										str = str.replace(/&/g, "&amp;");
										str = str.replace(/</g, "&lt;");
										str = str.replace(/>/g, "&gt;");
										range.pasteHTML(str);
										range.select();
									}
									
									$(newNode).remove();
									setTimeout(function(){
										pasting = false;
										objRange = getRange(obj, objRange);
										if(options.charCount){
											calculate($obj);
										}
									},1);
									return false;
								}
								else if(ua.match(/applewebkit\//)) {
									var selection = window.getSelection();
									var range = selection.getRangeAt(0).cloneRange();
									
									newNode.focus();
									setTimeout(function(){
										var str = $(newNode).val();
										str = str.replace(/&/g, "&amp;");
										str = str.replace(/</g, "&lt;");
										str = str.replace(/>/g, "&gt;");
										
										$(newNode).remove();
										selection.removeAllRanges();//清除range
										selection.addRange(range);//设置range
										document.execCommand('InsertHtml', false, str);
										pasting = false;
										objRange = getRange(obj, objRange);
										if(options.charCount){
											calculate($obj);
										}
									},1);
								}
							}
							else{
								var selection = window.getSelection();
								var range = selection.getRangeAt(0).cloneRange();
								var newNode = document.createElement("div");
								newNode.innerHTML='\uFEFF\uFEFF';
								range.deleteContents();
								range.insertNode(newNode);
								range.selectNodeContents(newNode);
								range.collapse(false);//合并范围至末尾
								selection.removeAllRanges();//清除range 
								selection.addRange(range);//设置range
								setTimeout(function(){
									var str = newNode.innerHTML;
									str = str.replace(/<[^>]+>/g, "");
									obj.removeChild(newNode);
									document.execCommand('InsertHtml', false, str);
									pasting = false;
									objRange = getRange(obj, objRange);
									if(options.charCount){
										calculate($obj);
									}
								},1);
							}
						}
						
						obj.ondragstart = function (e) {
							return false;
						};
						
						obj.ondragover = function (e) {
							var e = e || window.event;
							e.dataTransfer.dropEffect = 'none';
							return false;
						};
						
						obj.onkeydown = function(e) {
							var e = e || event;
							if(isKeydown){
								return false;
							}
							isKeydown = true;
							//alert(e.keyCode);
							if(e.keyCode===17){ //ctrl
								isCtrl = true;
							}
							
							if(e.keyCode===13 || e.keyCode===32){
								if(browser.ie){
									var range = document.selection.createRange();
									var str = '';
									if(range.length==1){
										if(e.keyCode===13){
											if(!options.newLine){alert(1);isKeydown = false;return false;}
											var newNode = document.createElement("<br>");//创建br标签
										}
										else{
											var newNode = document.createTextNode("\u00a0");
										}
										range(0).parentNode.replaceChild(newNode, range(0));//直接替换标签
										newNode = null;
									}
									else{
										if(e.keyCode===13){
											if(!options.newLine){isKeydown = false;return false;}
											range.pasteHTML('<br>');
										}
										else{
											range.pasteHTML('&nbsp;');
										}
										range.select();
									}
									str = $obj.html();
									if(str!='' && !/([\S\s]*)(<br>)$/i.test(str)){
										caretPos = getcaretPos(obj);
										$obj.append('<br>');
										setcaretPos(obj, caretPos);
										objRange = getRange(obj, objRange);
									}
								}
								else{
									var selection = window.getSelection();
									if(selection.focusNode=="[object HTMLBodyElement]"){
										isKeydown = false;
										return false;
									}
									var range = selection.getRangeAt(0);
									if(e.keyCode===13){
										if(!options.newLine){isKeydown = false;return false;}
										var fragment = range.createContextualFragment('<br>\n');
									}
									else{
										var fragment = range.createContextualFragment('&nbsp;');
									}

									var oLastNode = fragment.lastChild;
									range.deleteContents();
									range.insertNode(fragment);
									if(e.keyCode===13){
										var str = $obj.html();
										if(!/([\S\s]*)(\n<br\>)$/i.test(str) && !/([\S\s]*)(<br\><br\>)$/i.test(str)){
											$obj.append('<br>');
										}
									}
									range.setEndAfter(oLastNode);//设置末尾位置
									range.collapse(false);//合并范围至末尾
									selection.removeAllRanges();//清除range 
									selection.addRange(range);//设置range
								}
								setTimeout(function(){
									objRange = getRange(obj, objRange);
									isKeydown = false;
									if(options.charCount){
										calculate($obj);
									}
								},1);
								return false;
							}
							else if(e.keyCode===8){ //退格键
								if(browser.ie){
									setTimeout(function(){
										str = $obj.html();
										if(str!='' && !/([\S\s]*)(<br>)$/i.test(str)){
											caretPos = getcaretPos(obj);
											$obj.append('<br>');
											setcaretPos(obj, caretPos);
											objRange = getRange(obj, objRange);
										}
									},1);						
								}
								setTimeout(function(){
									objRange = getRange(obj, objRange);
									isKeydown = false;
									if(options.charCount){
										calculate($obj);
									}
								},1);
							}
							else if(isCtrl &&e.keyCode===86){
								if(browser.opera){
									$.tipMessage('opera浏览器下，暂时不支持粘贴!', 2, 3000);
									isKeydown = false;
									return false;
								}
								isKeydown = false;
							}
							else{
								isKeydown = false;
							}
						}
						
						obj.oncontextmenu = function(){
							if(browser.opera){
								$.tipMessage('编辑器右键已被禁用!', 2, 3000);
								return false;
							}
						}
						
						if(options.focus){
							if($obj.is(":hidden") == true){
								$baseObj.attr("contenteditable", false).hide();
								$obj.attr("contenteditable", true).show();
							}
							obj.focus();
						}
						
						//卸载编辑器对像
						if(browser.ie==6){
							$(window).unload(function(){
								obj = null;
								$obj = null;
								$emotObj = null;
								$baseObj = null;
							});
						}
						
						$(document).bind('click', function(e){
							if(browser.ie && clicking){
								obj.focus();
							}
							if(emotMenuOpen){
								$emotMenu.css("display", "none");
								emotMenuOpen = false;
							}
						});
					}
				}
				else{
					if($obj.is(":hidden") == true){
						$obj.prev().attr("contenteditable", false).hide();
						$obj.attr("contenteditable", true).show();
					}
					if(isPad){
						baseObj.focus();
					}
					else{
						moveFocusEnd(obj);
					}
				}
			});
		},
		content: function(){
			var str = $(this).html();
			if(!isPad){
				str = str.replace(/(\t|\r|\n)+/ig, ""); //替换制表符
				str = str.replace(emotReg, '[em:$2]'); //替换表情
				
				str = str.replace(/<br>/ig, "\n"); //替换换行符
				str = str.replace(/&nbsp;/g, " ");//转换空格标记
				str = str.replace(/<[^>]+>/g, "");//去掉所有的html标记
				str = str.replace(/&lt;/g, "<"); //替换左尖括号
				str = str.replace(/&gt;/g, ">"); //替换右尖括号
			}
			return str;
		},
		focus: function(){
			var $obj = $(this);
			
			if(isPad){
				var $baseObj = $obj.prev();
				$baseObj[0].focus();
			}
			else{
				var obj = $obj[0];
				var caretPos = 0;
				if($obj.is(":hidden") == true){
					$obj.prev().attr("contenteditable", false).hide();
					$obj.attr("contenteditable", true).show();
					obj.focus();
				}
				else{
					obj.focus();
					if(getcaretPos(obj)<1){
						moveFocusEnd(obj);
						setTimeout(function(){ //webkit下触发click需要延时处理，才能获取正确位置
							$obj.triggerHandler('click');
						},100);
					}
				}
			}
			return this;
		},
		reset: function() {
			var $obj = $(this);
			var $baseObj = $obj.prev();
			if(isPad){
				$baseObj.val('');
				$obj.triggerHandler('blur');
			}
			else{
				$obj.hide().empty().blur().attr("contenteditable", false);
				$baseObj.attr("contenteditable", true).show();
				$obj.triggerHandler('click');
			}
			return this;
		},
		validCharLength: function(){
			return contentLength($(this).html(), 'stripping');
		}
	};
	
	$.fn.emotEditor = function(method) {
		if (methods[method]) {
			return methods[method].apply(this, Array.prototype.slice.call(arguments, 1));
		}
		else if (typeof method === 'object' || !method) {
			return methods.init.apply(this, arguments);
		}
		else {
			alert('错误调用！');
		}
	}
	
	function contentLength(str, type){
		var strLength = 0;
		var lastBr = 0;
		if(isPad){
			str = str.replace(/\[em:([0-9])+\]/ig, " "); //剥离表情
			if(type=="stripping"){
				str = str.replace(/\s/ig, '');
			}
			strLength = str.length;
		}
		else{
			if(str.toLowerCase()!='<br>'){
				if(!browser.ie && /([\S\s]+)(<br>)$/i.test(str)){
					lastBr = 1;
				}
				str = str.replace(/(\t|\r|\n)+/ig, "");
				str = str.replace(/( )+/ig, ""); //转换空格标记
				str = str.replace(emotReg, ""); //剥离表情
				str = str.replace(/<br>/ig, "");
				str = str.replace(/&nbsp;/ig, ""); //转换空格标记
				str = str.replace(/<[^>]+>/g, "");//去掉所有的html标记
				str = str.replace(/&lt;/g, "<"); //替换左尖括号
				str = str.replace(/&gt;/g, ">"); //替换右尖括号
				
				if(str.length==0){
					strLength = 0;
				}
				else if(type=="stripping"){
					strLength = str.replace(/\s/ig, '').length;
				}
				else if(browser.ie){
					strLength = str.length;
				}
				else{
					strLength = str.length-lastBr;
				}
			}
			else{
				if(!type=="stripping" && browser.ie){
					strLength = 1;
				}
			}
		}
		return strLength;
	}
	
	function countEmot(str){
		var emotMatches = lineMatches = new Array();
		var emotLength = 0;
		var lineLength = 0;

		emotMatches = str.match(emotReg);
		lineMatches = str.match(/(<br>)/ig);
		if(emotMatches==null){
			emotLength = 0;
		}
		else{
			emotLength = emotMatches.length;
		}
		if(lineMatches==null){
			lineLength = 0;
		}
		else{
			lineLength = lineMatches.length;
		}
		
		return emotLength + lineLength;
	}
	
	function moveFocusEnd(obj){
		var $obj = $(obj);
		var str = $obj.html();
		if(str!='' && str!='<br>'){
			//ie特殊处理
			if(browser.ie){
				var strLength = $obj.text().length + countEmot(str);
				if(str.substring(str.length-4).toLowerCase()=='<br>'){
					--strLength;
				}
			}
			else{
				var strLength = $obj.text().length;
			}
			
			setTimeout(function(){
				setcaretPos(obj, strLength);
			},100);
		}
		else{
			setTimeout(function(){
				obj.focus();
			},100);
		}
	}
	
	function getRange(obj, oldRange){
		var arr = [];
		if(document.activeElement != obj){
			return oldRange;
		}
		else{
			if(document.selection){//ie
				arr['range'] = document.selection.createRange();
				if(arr['range'].length==1){
					return oldRange;
				}
			}
			else{
				arr['sel'] = window.getSelection();
				if(arr['sel'].focusNode=="[object HTMLBodyElement]"){
					return oldRange;
				}
				arr['range'] = arr['sel'].getRangeAt(0).cloneRange();
			}
			return arr;
		}
	}

	function getcaretPos(element) {
		var caretPos = 0;
		if (document.selection) { // IE Support
			element.focus(); //将焦点至于element，并且光标位置不会发生改变
			var range = document.body.createTextRange();
			range.moveToElementText(element);
			var sel = document.selection.createRange();
			if(!sel.length==1){
				sel.setEndPoint("StartToStart", range);
				caretPos = contentLength(sel.htmlText);
			}
			else{
				var str = $(element).html();
				var strLength = $(element).text().length + countEmot(str);
				if(str.substring(str.length-4).toLowerCase()=='<br>'){
					--strLength;
				}
				caretPos = strLength;
			}
			return caretPos;
		}
		else if (window.getSelection) {
			var sel = window.getSelection();
			var rng = sel.getRangeAt(0).cloneRange();
			rng.setStart(element, 0);
			caretPos = rng.toString().length;
		}
		return caretPos;
	}
	
	function setcaretPos(element, location) {
		if(document.body.createTextRange) {
			var range = document.body.createTextRange();
			range.moveToElementText(element);
			range.collapse(true);
			range.move('character', location);
			range.select();
		}
		else if(window.getSelection) {
			var nodes = [];
			var getTextNode = function(node) {
				for (var i = 0; i < node.childNodes.length; i++) {
					if (node.childNodes[i].nodeType == 3) {
						nodes.push(node.childNodes[i]);
					} else {
						getTextNode(node.childNodes[i]);
					}
				}
			}

			getTextNode(element);
			var length = 0;
			for (var i = 0; i < nodes.length; i++) {
				length += nodes[i].textContent.length;
				if (length >= location) {
					length -= nodes[i].textContent.length;
					break;
				}
			}
			var sel = window.getSelection();
			sel.collapse(nodes[i], location - length);
			element.focus();
		}
	}
})(jQuery);