﻿
    
var hidEmotionImg = document.getElementById("default_emotion");

function change_emotion_img(index,obj)
{
    if(typeof(hidEmotionImg) != "undefined")
    {
        hidEmotionImg.parentNode.className = "" ;
    }
    hidEmotionImg = obj ;
    document.getElementById ('hidEmotion').value = index ;
    
    hidEmotionImg.parentNode.className = "hover";
}
    

 var addreltive_panel ;
 var myjscheck = new ValidatorClass() ;
 
    function addreltive_panelShow(html){

        var obj = document.getElementById("addreltive_panel");
        obj.innerHTML = html ;
        if(!addreltive_panel)
        {
            addreltive_panel = new MamShare.Panel("addreltive_panel", {
                iframe: true,
                visible: false,
                modal: true,
                draggable: true,
                draghandle: "panel_head"
            });
        }
        addreltive_panel.render();
        addreltive_panel.show();
        addreltive_panel.center();
    }    
    
    function closeaddreltive_panel()
    {
        addreltive_panel.hide();
    }
    
    function ajxaaddrelative(userid){
    
        var callback = {
            success: function(o){
                if(o.responseText != "")
                {
                    // 错误提示
                    addreltive_panelShow(o.responseText);
                    
                }
                else {
                    window.location.reload();
                }
                
            },
            failure: function(o){
            
                //errshow.innerHTML = o.responseText;
            }
        }
        
        var conn = YAHOO.util.Connect.asyncRequest("GET", "/admin/relationship/addRelationship.do?userId="+userid, callback);
    }  
   
    

    
    function not_know_him_click()
    {
        var not_know_him = document.getElementById("not_know_him");
        var relation_pass_tip = document.getElementById("relation_pass_tip");
        var relation_submit_btn = document.getElementById("relation_submit_btn");
        if(not_know_him.checked)
        {
            relation_submit_btn.value = "关注他";
             relation_pass_tip.style.display = "" ;
            
        }else
        {
            relation_submit_btn.value = "确定";
            relation_pass_tip.style.display = "none" ;
           
        }
    }
    

    
    var Dom = YAHOO.util.Dom;
    var Event = YAHOO.util.Event;
    var Connect = YAHOO.util.Connect;
    var lang = YAHOO.lang;
    
    var commentText 
   
	
	function submitCommentSuccess(o)
	{
		if (o.responseText == 1)
		{
			//alert("添加成功！");
			
			EmotionPanelClick();
			
			var hidEmotionContent = Dom.get("hidEmotionContent");
			hidEmotionContent.innerHTML = commentText ;
			
			//var my_emotion_img = Dom.get("my_emotion_img");
			//my_emotion_img.src = hidEmotionImg.src ;
			
			
		}
		else
		{
			alert("添加失败！");
		}
 
	}
	function EmotionPanelClick()
	{
	    var obj = document.getElementById("EmotionPanel");
	    if(obj.style.display == "") 
	    {
	        obj.style.display = "none";
	    }else
	    {
	        obj.style.display = "" ;
	    }
	   
	   
	}
	
	function addmessage_onclick(userid)
    {
        
         var callback = {
            success: function(o){
                if(o.responseText != "")
                {
                    addmessage_panelShow(o.responseText);
                }
                else {
                    window.location.reload();
                }
                
            },
            failure: function(o){
                alert(o.responseText);
               
            }
        }
        
        var conn = YAHOO.util.Connect.asyncRequest("POST", "/admin/message/addmessage.do?userId="+userid, callback);
    }
    
    function addmessage_panelShow(html){

        if(html == "您被对方加入了黑名单，不能进行此操作!")
        {
            alert(html);
            return ;
        }
        var obj = document.getElementById("addreltive_panel");
        obj.innerHTML = html ;
        if(!addreltive_panel)
        {
            addreltive_panel = new MamShare.Panel("addreltive_panel", {
                iframe: true,
                visible: false,
                modal: true,
                draggable: true,
                draghandle: "panel_head"
            });
        }
        addreltive_panel.render();
        addreltive_panel.show();
        addreltive_panel.center();

    }
    
    function addmessage_submit()
    {

      if( !myjscheck.Validator.Validate(document.getElementById("addmessage"),1,false) )
           return ;
       
       var postdata = MamShare.Form.serialize("addmessage");
       postdata=postdata.replace('titleText','Title');
       YAHOO.util.Connect.asyncRequest("POST", "/admin/Message/CheckBlackWord.do?"+postdata,{success:checkBlackWordSuccess});  
    }
    
    function checkBlackWordSuccess(o)
      {    
          var postdata = MamShare.Form.serialize("addmessage");
          var callback = {
            success: function(o){
                if(o.responseText != "")
                {
                    // 错误提示
                    //addreltive_panelShow(o.responseText);
                    alert(o.responseText)
                }
                else {
                    alert("发送成功！");
                    closeaddreltive_panel();
                }
                
            },
            failure: function(o){
                alert(o.responseText);
            }
        };
        
          if (o.responseText == 0)
		  { 
			 alert('对不起，您填写的内容中存在黑词！');
			 return false ;
		  }	
		  else if(o.responseText == 1){   
	         var conn = YAHOO.util.Connect.asyncRequest("POST", "/admin/message/doaddmessage.do", callback,postdata);        
		  }
      }
      
function addrelative_onclick()
    {
       if( !myjscheck.Validator.Validate(document.getElementById("addrelative"),1,false) )
           return ;
       var not_know_him = document.getElementById("not_know_him");
       var postdata = MamShare.Form.serialize("addrelative");
       var callback = {
            success: function(o){
                if(o.responseText != "")
                {
                    alert(o.responseText);
                    closeaddreltive_panel();
                }
                else {
                
                    if(not_know_him.checked)
                    {
                       alert("添加关注成功！");;
                    }else
                    {
                       alert("您的添加好友请求已经提交，请耐心等待对方通过！");;
                    }
                    
                    closeaddreltive_panel();
                }
                
            },
            failure: function(o){
            
               // errshow.innerHTML = o.responseText;
            }
        }
        
       
        if(not_know_him.checked)
        {
            var conn = YAHOO.util.Connect.asyncRequest("POST", "/admin/relationship/doseehime.do", callback,postdata);
        }else
        {
            var conn = YAHOO.util.Connect.asyncRequest("POST", "/admin/relationship/doaddRelationship.do", callback,postdata);
        }

    }
    
    function submitComment()
	{
		var commentTextEl = Dom.get("NoteText");
		var Emotion = Dom.get("hidEmotion");
		var hidEmotion = Emotion.value;
		commentText = lang.trim(commentTextEl.value);
		if (commentText == ""||commentText == "今天的心情如何呢？")
		{
			alert("内容不能为空！");
			commentTextEl.focus();
			return;
		}
		
		if(commentText.length > 100)
		{
		    alert("长度不能超过100个字符！");
		    return false;
		}
		//Dom.get("submitNoteBtn").disabled = true;
		Connect.asyncRequest("POST",
		                                "/Admin/Note/InsertNote.do", 
		                                {success:submitCommentSuccess}, 
		                                MamShare.Util.ToQueryString({NoteText:commentText,hidEmotion:hidEmotion}));
	}
