// JScript 文件
var _shopID;
var _shopOwnerID;
var _controlID;
var url = "../../WebService/ShopService.ashx";
function ShowShopMsg(ShopID,ShopOwnerID,ControlID)
{
    _shopID=ShopID;
    _shopOwnerID=ShopOwnerID;
    _controlID=ControlID;
    var MsgObj=$(ControlID);
    if(MsgObj!=null && ShopID>0)
    {
        var s = "Action=GetShopMsg&ShopID=" + ShopID + "&ShopOwnerID="+ShopOwnerID+"&rnd="+Math.random();               
        
        var xmlHttp = XmlHttp.create();
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-Length", s.length);
        xmlHttp.setRequestHeader("CONTENT-TYPE", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = function(){
            if(xmlHttp.readyState == 4)
            {
                MsgObj.innerHTML=xmlHttp.responseText;
               
            }
        };
        xmlHttp.send(s);
    }

}
function submitComment()
{
    var actionObj = $("h_action");
    var msgIDObj = $("h_msgID");
    var txtValidate = $("CheckCode");
    var txtCommentBody = $("TxtMessage");
    var shop_id = $("h_shop_id").value;
    var saler_id = $("h_saler_id").value;
    var saler_name = $("h_saler_name").value;
    var product_id =  "0";  
    if(txtValidate != null && txtCommentBody != null)
    {
        if(txtValidate.value.length != 5)
        {
            alert("没有填写验证码！");
            txtValidate.focus();
            return;
        }
        if(txtCommentBody.value == "")
        {
            alert("没有填写评论内容！");
            txtCommentBody.focus();
            return;
        }
        else if(txtCommentBody.value.length>400)
        {
            alert("当前字数为"+txtCommentBody.value.length+"填写评论内容超出字数限制！");
            txtCommentBody.focus();
            return;
        }
    
        var s = "Action=LeaveMsg&h_action=" + actionObj.value + "&msgID=" + msgIDObj.value              
              + "&product_id="+product_id+"&saler_name="+encodeURIComponent(saler_name)+"&saler_id="+saler_id+"&shop_id="+shop_id
              + "&checkcode=" + encodeURIComponent(txtValidate.value) + "&content=" + txtCommentBody.value;      
       
        var xmlHttp = XmlHttp.create();
        xmlHttp.open("POST", url, true);
        xmlHttp.setRequestHeader("Content-Length", s.length);
        xmlHttp.setRequestHeader("CONTENT-TYPE", "application/x-www-form-urlencoded");
        xmlHttp.onreadystatechange = function(){
            if(xmlHttp.readyState == 4)
            {
                var t = parseInt(xmlHttp.responseText);
                if(t == -1)
                {
                    alert("验证码错误！");
                    changeControlStatus(false);
                }
                else if(t == -2)
                    alert("发表留言失败");
                else if(t == -4)
                    alert("发表留言失败，有被禁用词汇！");
                else if(t > 0)
                {
                    alert("发表留言成功");
                    txtValidate.value = "";
                    txtCommentBody.value = "";                   
                    ShowShopMsg(_shopID,_shopOwnerID,_controlID);                    
                }
            }
        };
        xmlHttp.send(s);
        
        changeControlStatus(true);
        setTimeout('changeControlStatus(false);', 15000)
    }
}

function changeControlStatus(disable)
{
    var c0 = $("btnCommitComment"), c1 = $("CheckCode"), c2 = $("Message_Content");
    var actionObj = $("h_action");
    var msgIDObj = $("h_msgID");
    var msgTitle=$("leave_message_title");
    var showMsgDIV=$("ShowLeaveMesageDiv");
    if(c0 != null)
        c0.disabled = disable;
    if(c1 != null)
        c1.disabled = disable;
    if(c2 != null)
        c2.disabled = disable;
    if(actionObj!=null)
        actionObj.value="";
    if(msgIDObj!=null)
        msgIDObj.value="";  
        
    if(msgTitle!=null)
       msgTitle.innerHTML="发表留言"; 
    if(disable == false)
    {      
       reloadValidateImage();   
    }
    if(showMsgDIV!=null)
       showMsgDIV.style.display="none";   
    
}

function reloadValidateImage()
{
    var img = $("imgValidate");
    if(img != null)
    {
        img.src = "../../../Passport/CheckCode.aspx?rnd=" + Math.random();
    }
}

function leaveShopMessage(ID,SenderName,e){     
   
     var actionObj=$("h_action");
     var msgIDObj=$("h_msgID");
     var msgTitleObj=$("leave_message_title"); 
     if(actionObj!=null && msgIDObj!=null)
     {
        msgTitleObj.innerHTML="回复 [<span style=\"color:red\">"+SenderName+"</span>] 留言：";           
        actionObj.value="replay";
        msgIDObj.value=ID;
        
     }
     ShowLeaveMesage('display',e);
//    var LeaveMessageObj=document.getElementById('ShowLeaveMesageDiv');
//    if(LeaveMessageObj!=null)
//    {
//         LeaveMessageObj.style.display="";    
//         var showDiv=e.target||e.srcElement;
//         var pos=getPosXY(showDiv,[-50,-220]);     
//         LeaveMessageObj.style.left=pos[0]+'px';
//	     LeaveMessageObj.style.top=pos[1]+'px';
//       
//       
//    }
 
   
}

