﻿

///提交回复 
function sendBack(tid,content)
{
    	 var url = "/sendrequest.aspx";
		 var pars ="action=sendback&tid="+tid+"&content="+content; 
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendBack_CallBack(req,tid); } });

} 
///处理返回值
function sendBack_CallBack(req,tid)
{
    var rev = eval("obj="+req.responseText);  
   if(rev>0)
   {         
        window.top.location.href='portal/eakiasendbackok.aspx?topicid='+tid;
   } 
}
//顶贴
function sendDing(tid)
{
    	 var url = "/sendrequest.aspx";
		 var pars ="action=dingi&tid="+tid; 
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendDing_CallBack(req); } });
}
///处理返回值 
function sendDing_CallBack(req)
{ 
    
   var rev = eval("obj="+req.responseText);    
   
   if(rev>0)
   { 
        $("DigNum").innerHTML= parseFloat($("DigNum").innerHTML)+1;
   } 
   else 
   {
    alert("您已经顶过此贴.");
   }
}


//收藏帖子
function sendCollect(tid)
{
    	 var url = "/sendrequest.aspx";
		 var pars ="action=collect&tid="+tid; 
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendCollect_CallBack(req); } });
}
///处理返回值 
function sendCollect_CallBack(req)
{     
   var rev = eval("obj="+req.responseText);       
   if(rev>0)
   { 
        alert("收藏成功..");
   } 
   else 
   {
    if(rev==-2)
    {
        alert("请您登陆后收藏此帖子.");
    }
    else
    alert("您已经收藏此帖子.");
   }
}


function correctPNG() 
{
        for(var i=0; i<document.images.length; i++)
        {
            var img = document.images[i]
            var imgName = img.src.toUpperCase()
            if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
            {
                var imgID = (img.id) ? "id='" + img.id + "' " : ""
                var imgClass = (img.className) ? "class='" + img.className + "' " : ""
                var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
                var imgStyle = "display:inline-block;" + img.style.cssText 
                    if (img.align == "left") imgStyle = "float:left;" + imgStyle
                    if (img.align == "right") imgStyle = "float:right;" + imgStyle
                    if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle 
                    var strNewHTML = "<span "+ imgID + imgClass + imgTitle + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";" + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader" + "(src='" + img.src + "', sizingMethod='scale');\"></span>" 
                    img.outerHTML = strNewHTML
                    i = i-1
             }
        }
}

window.attachEvent("onload", correctPNG); 

//用户登录网站
function userlogin()
{
    
        var username = $("txtname");
        var pwd = $("txtpwd"); 
        var ifreme = $("che_rememberme").checked?1:0;
        if(username.value =="")
        {
            alert("请输入用户名.");
            username.focus();
            return false;
        }
        if(pwd.value =="")
        {
              alert("请输入密码.");
                pwd.focus();
                return false;
        }  
        
        sendlogin(username.value,pwd.value,ifreme);   
}

///登录网站 
function sendlogin(username,pwd,ifreme)
{
    	 var url = "/sendrequest.aspx";
		 var pars ="action=userlogin&username="+username+"&pwd="+pwd+"&ifreme="+ifreme; 	
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendlogin_CallBack(req,username); } });
 		 
} 
/// 登录网站 处理返回值
function sendlogin_CallBack(req,username)
{
  var req = req.responseText;
  
   if(req>0)
  {
         $("divnologin").style.display="none";
         $("divlogin").style.display="";                         
         $("linkuname").innerHTML=username; 
         
         $("divaccount").innerHTML=username;
         
         $("tr_uploadpic").style.display="";
  } 
  else if(req ==-1)
  {
        alert("用户名和密码错误.");
        return false;
  }  
}



//用户退出登录处理
function loginout()
{
    if(confirm("您确定退出吗?"))
    {
        sendloginout();
   }
}

///退出网站 
function sendloginout()
{     
    	 var url = "/sendrequest.aspx";
		 var pars ="action=loginout"; 	 		
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendloginout_CallBack(req); } });
 	 
} 
/// 退出网站 处理返回值
function sendloginout_CallBack(req)
{
   var req = req.responseText;
   if(req>0)
       {  
                         $("divnologin").style.display="";
                         $("divlogin").style.display="none";                          
                         $("txtname").value="";
                         $("txtpwd").value="";                             
                         $("divaccount").innerHTML="";
                         $("divexpresslogin").style.display="";
                         $("divlogin").style.display="none";  
                         $("tr_uploadpic").style.display="none";
        }
  
}

////////////////////////////////////////////////////////////////用户登录网站 底部的功能实现
//用户登录网站
function userlogin_b()
{    
        var username = $("txtusername_b");
        var pwd = $("txtuserpwd_b"); 
       
        if(username.value =="")
        {
            alert("请输入用户名.");
            username.focus();
            return false;
        }
        if(pwd.value =="")
        {
              alert("请输入密码.");
              pwd.focus();
              return false;
        }        
        sendlogin_b(username.value,pwd.value);   
}


///登录网站 
function sendlogin_b(username,pwd)
{
    	 var url = "/sendrequest.aspx";
		 var pars ="action=userlogin&username="+username+"&pwd="+pwd; 	
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendlogin_b_CallBack(req,username); } });

} 
/// 登录网站 处理返回值
function sendlogin_b_CallBack(req,username)
{
  var req = req.responseText;
  
   if(req>0)
  {
         $("divnologin").style.display="none";
         $("divlogin").style.display="";                         
         $("linkuname").innerHTML=username; 
         $("divexpresslogin").style.display="none";
         $("divaccount").innerHTML=username;
         $("tr_uploadpic").style.display="";
  } 
  else if(req ==-1)
  {
        alert("用户名和密码错误.");
        return false;
  }  
}



//////////////////////////////////////////////////////////////

//版主删除帖子

///版主删除帖子 
function sendDeleteTopic(tid)
{
  if (window.confirm('您确实要删除此帖子吗？ 如果删除，他的跟帖也会同时删除.'))
        {

    	 var url = "/sendrequest.aspx";
		 var pars ="action=deletetopicbybanzhu&tid="+tid; 	 
		
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendDeleteTopic_CallBack(req); } });
 		 
 		 }

} 


///版主设置帖子为精华 
function sendDigestTopic(tid,value)
{ 
    	 var url = "/sendrequest.aspx";
		 var pars ="action=setdigest&tid="+tid+"&value="+value; 	 		
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendDigestTopic_CallBack(req); } }); 
 		  
} 
/// 版主设置帖子为精华 处理返回值
function sendDigestTopic_CallBack(req)
{
  var req = req.responseText;
   if(req>0)
    {  
       alert("设置成功.刷新页面可以看到状态改变。");
    }
    else
    alert("您没有权限操作.");   
}



///版主设置帖子为热帖 
function sendBestTopic(tid,value)
{ 
    	 var url = "/sendrequest.aspx";
		 var pars ="action=setbest&tid="+tid+"&value="+value; 	 		
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendBestTopic_CallBack(req); } }); 
 		  
} 
/// 版主设置帖子为热帖 处理返回值
function sendBestTopic_CallBack(req)
{
  var req = req.responseText;
   if(req>0)
    {  
       alert("设置成功.刷新页面可以看到状态改变。");
    }
    else
    alert("您没有权限操作.");   
}

///版主设置帖子为推荐 
function sendRecommandTopic(tid,value)
{ 
    	 var url = "/sendrequest.aspx";
		 var pars ="action=setrecommand&tid="+tid+"&value="+value; 	 		
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendRecommandTopic_CallBack(req); } }); 
 		  
} 
/// 版主设置帖子为推荐 处理返回值
function sendRecommandTopic_CallBack(req)
{
  var req = req.responseText;
   if(req>0)
    {  
       alert("设置成功.刷新页面可以看到状态改变。");
    }
    else
    alert("您没有权限操作.");   
}


///版主删除回复
function sendDeletePost(tid,pid)
{ 
    if(window.confirm("您确定删除此回复吗? 删除之后不能恢复."))
    {
    	 var url = "/sendrequest.aspx";
		 var pars ="action=deletepost&tid="+tid+"&pid="+pid; 	 		
 		 var myAjax = new Ajax.Request(url, {method: "post", parameters: pars, onComplete: function (req) { sendDeletePost_CallBack(req,pid); } }); 
 		  
    }
} 
/// 版主删除回复 处理返回值
function sendDeletePost_CallBack(req,pid)
{
  var req = req.responseText;
   if(req>0)
    {  
       alert("删除成功.。");
       
       $("showpost"+pid).style.display="none";
    }
    else
    alert("您没有权限操作.");   
}

//缩放图片到合适大小
function ResizeImages()
{
   var myimg,oldwidth,oldheight;
   var maxwidth=600;
   var maxheight=700
   var imgs = document.getElementById('divcontenttopic').getElementsByTagName('img');   //如果你定义的id不是article，请修改此处

   for(i=0;i<imgs.length;i++){
     myimg = imgs[i];

     if(myimg.width > myimg.height)
     {
         if(myimg.width > maxwidth)
         {
            oldwidth = myimg.width;
            myimg.height = myimg.height * (maxwidth/oldwidth);
            myimg.width = maxwidth;
         }
     }else{
         if(myimg.height > maxheight)
         {
            oldheight = myimg.height;
            myimg.width = myimg.width * (maxheight/oldheight);
            myimg.height = maxheight;
         }
     }
   }
}

//引用回复 
function yinyf(divid)
{
    var html="<div style='border:solid 1px #f0f0f0; line-height:23px; height:100px; background-color:#f0f0f0; width:80%; margin:5px;'>";
    comment_editor.insertHTML(html+ $("divbackcontent"+divid).innerHTML+"</div>");
    comment_editor.getFocus();
}
//插入图像
function myinsertFace(imgobj)
{
    comment_editor.insFace(imgobj.src);
}
    
//回车提交登录
function keyDownLogin() 
    { 
        var e=event.srcElement; 
       
        if(event.keyCode==13) 
        { 
                document.getElementById("linklogin").click();
        }
     }

