
//添加留言
function doLeaveSubmit(isLogin,username,iagentId){

    $("#errorHtml").hide();
   if(isLogin==false){
     $("#errorHtml").html("<font color='red'>请先登录后发表留言！</font>");
     $("#errorHtml").show('slow');
     document.getElementById("sendbutton").focus();
     return false;
   }
   if(rtim($("#leavearea").val())==''){
    $("#errorHtml").html("<font color='red'>请输入留言的内容！</font>");
     $("#errorHtml").show('slow');
     document.getElementById("sendbutton").focus();
     return false;
   }
   if(rtim($("#leavearea").val()).length>400){
   	 $("#errorHtml").html("<font color='red'>留言的内容只能输入400个字！</font>");
     $("#errorHtml").show('slow');
     document.getElementById("sendbutton").focus();
     return false;
   }
   $("#sendbutton").attr("disabled","disabled");
   var contents="content="+escape(encodeURIComponent($("#leavearea").val()))+"&username="+encodeURI(encodeURI(username));
   var queryStr =contents+"&user.id="+iagentId;
   
   $.ajax({
        type: "post",
        contentType:"application/x-www-form-urlencoded;charset=gbk",
        url: "/iagent/leave/AddIndexleaveWord.do",
        data: queryStr,
        success: function(xml) {
        $("#noleave").hide();
        $("#leaveListDiv").html(xml+$("#leaveListDiv").html());
        $("#sendbutton").attr("disabled","");
        var id=$("#leavaddOne").val();
        setTimeout(function(){$("#leave"+id).css({background:""});
        $("#leavaddOne").val("");},1000);
        $("#leavearea").val('');
         $("#errorHtml").hide();
         $("#mb-hintleavearea").html('可以输入400字');
         var num=parseInt($("#leaveNum").html());
        $("#leaveNum").html(num+1)
        },
        error: function(e) {
           	 $("#errorHtml").html("<font color='red'>留言失败！</font>");
    		 $("#errorHtml").show('slow');
    		 document.getElementById("sendbutton").focus();
    		  $("#sendbutton").attr("disabled","");
        }
    });
}

//提交一句话评论用户
function doUserCom(isLogin,username,iagentId){

    $("#minierrorHtml").hide();
   if(isLogin==false){
     $("#minierrorHtml").html("<font color='red'>请先登录后发表评论！</font>");
     $("#minierrorHtml").show('slow');
     document.getElementById("button3").focus();
     return false;
   }
   if(rtim($("#miniblog").val())==''){
    $("#minierrorHtml").html("<font color='red'>请输入评论的内容！</font>");
     $("#minierrorHtml").show('slow');
     document.getElementById("button3").focus();
     return false;
   }
   if(rtim($("#miniblog").val()).length>50){
   	 $("#minierrorHtml").html("<font color='red'>评论的内容只能输入50个字！</font>");
     $("#minierrorHtml").show('slow');
     document.getElementById("button3").focus();
     return false;
   }
   $("#button3").attr("disabled","disabled");
   var contents="content="+escape(encodeURIComponent($("#miniblog").val()))+"&username="+encodeURI(encodeURI(username));
   var queryStr =contents+"&user.id="+iagentId;
   $.ajax({
        type: "post",
        contentType:"application/x-www-form-urlencoded;charset=gbk",
        url: "/userCom/addUserCom.do",
        data: queryStr,
        success: function(xml) {
        $("#userComList").html(xml+$("#userComList").html());
        $("#button3").attr("disabled","");
        var id=$("#UserComOne").val();
        setTimeout(function(){$("#userCom"+id).css({background:""});
        $("#UserComOne").val("");},1000);
        $("#miniblog").val('');
         $("#minierrorHtml").hide();
         $("#mb-mb-hintminiblog").html('可以输入50字');
        },
        error: function(e) {
           	 $("#minierrorHtml").html("<font color='red'>评论失败！</font>");
    		 $("#minierrorHtml").show('slow');
    		 document.getElementById("sendbutton").focus();
    		  $("#button3").attr("disabled","");
        }
    });
}
 //去掉空格
function rtim(ss) {
	ss = ss.replace(/\s/g, "");
	return ss;
}
 //文本域计算字符
  function ismaxlength(obj){

	var mlength=obj.getAttribute? parseInt(obj.getAttribute("maxlength")):""
	if (obj.getAttribute && obj.value.length>mlength)	{
	
	var b=obj.value.length-mlength
	document.getElementById("mb-hint"+obj.id).innerHTML='<font color=red>超出了'+b+'个字</font>';
	}
	if(obj.value.length==mlength)	{
	document.getElementById("mb-hint"+obj.id).innerHTML='<font color=red>只能输入'+mlength+'个字</font>';
	}
	else if(obj.value.length<mlength)	{
	var a=obj.value.length;
	
	a=mlength-a;
		
	document.getElementById("mb-hint"+obj.id).innerHTML="可以输入"+a+"字";
	}
	}
	//快捷键提交
	 function sendtj(event){
   event=event?event:(window.event?window.event:null);
   
  if(event.ctrlKey&&event.keyCode==13){
   
   document.getElementById("sendbutton").disabled="disabled";
   setTimeout(function(){ document.getElementById("sendbutton").disabled="";
  
   document.getElementById("sendbutton").click();
   
   },500);
  }
  	//快捷键提交
}
  	 function sendUserCom(event){
   event=event?event:(window.event?window.event:null);
   
  if(event.ctrlKey&&event.keyCode==13){
   
   document.getElementById("button3").disabled="disabled";
   setTimeout(function(){ document.getElementById("button3").disabled="";
  
   document.getElementById("button3").click();
   
   },500);
   }
   }
   //弹出删除层
 function dodelet(event,Id,type){
   
   event=event?event:(window.event?window.event:null);
   
   var x=document.body.scrollLeft+event.clientX;
   var y=document.body.scrollTop+event.clientY;
   var theTop;
    if   (document.documentElement   &&   document.documentElement.scrollTop)   
           theTop   =   document.documentElement.scrollTop;   
      else   theTop   =   document.body.scrollTop   
   
   var x=event.clientX;
   var y=event.clientY+theTop;
   var left=300;
   if(type==2) left=940;
   $("#confirm").css({top:(y-108)});
    $("#confirm").css({left:(x-left)});
   $("#confirm").show();
   document.getElementById("deId").value=Id;
   document.getElementById("detype").value=type;
   return false;
 }
 //取消弹出层
  function quxiao(){
 document.getElementById("confirm").style.display='none';
}
//删除提交
function dodelesubmit(Id,type){
document.getElementById("debutton").disabled="disabled";
 if(type==2){
 $.ajax({
        type: "post",
        contentType:"application/x-www-form-urlencoded;charset=gbk",
        url: "/userCom/delUserCom.do",
        data: "userCom.id="+Id,
        success: function(xml) {
         document.getElementById("userCom"+Id).style.background="fffbcc" ;
   		 quxiao();
        setTimeout(function(){
        $("#userCom"+Id).fadeOut('slow');
        document.getElementById("debutton").disabled="";
        },2000);
        },
        error: function(e) {
           	alert('删除失败！');
        }
    });
 }else if(type==1){
  $.ajax({
        type: "post",
        contentType:"application/x-www-form-urlencoded;charset=gbk",
        url: "/iagent/leave/delMessage.do",
        data: "leaveword.id="+Id,
        success: function(xml) {
         document.getElementById("leave"+Id).style.background="fffbcc" ;
   		 quxiao();
        setTimeout(function(){
        $("#leave"+Id).fadeOut('slow');
        document.getElementById("debutton").disabled="";
        },1000);
        },
        error: function(e) {
           	alert('删除失败！');
        }
    });
 }
}
function updateCss(obj){
    var offset = $("#colorbg").offset();
	$("#colorselect").css("top", offset.top+35);
	$("#colorselect").css("left", offset.left);
	$("#colorselect").show();
}