﻿// JScript 文件
$(function(){
newsPageInit();
var docLinkCon =  document.getElementById("docLinkCon");
if(docLinkCon != null)
rendLinkCon();
});

var Account;
var niceName;

function setPinfStyle(){
$("div#Pinfos").css({"color":"#666"});
$("div#Pinfos span a").css({"color":"#1648AB"});
$("div#Pinfos span.num strong").css({"font-size":"16px","color":"#1648AB"});
}

function initDocAD(){
var boxDiv = $("#comBox");
if(boxDiv.html() != null){
boxDiv.before('<div><a href="http://www.576tv.com/CFolders/ad/2009/kbd/" target="_blank" ><img src="/images/ad/200909/kbd2.jpg" alt="ad" /></a></div>');
}
}


function newsPageInit(){
var did = location.href;
var getid =/^([\w:\.\/]+)\-([\d]+)(-([\d]+))*\.shtml$/gi;
did = did.replace(getid,'$2');

var boxDiv = $("#comBox");
if(boxDiv.html() != null)
boxDiv.html('<img src="/images/loading2.gif" alt="loading" style="width:20px; height:20px; margin:3px;" />正在读取网友评论');

//返回阅读次数
var sendatas;
sendatas ="cmd=donews&did="+did;
$.ajax({ type: "POST", url: "/contrl/donews.aspx",data:sendatas,dataType:"json",success: function(callback){doback(callback,did);},error:function(){return false;}});
}

var rplist = new Array();

function doback(json,did){
$("#news_m .infs span").html(json.hits);
//----------------------------
if(json.rps !="")
eval('rplist='+json.rps);

$("#news_m div.dsc").css({"text-align":"right","color":"#999","font-size":"12px","filter":"glow(Color=#ffffff, Strength=2)"});
resizeimg();
setPinfStyle();//设置样式
initDocAD();//加载广告
//----------------------------
Account =json.uname;
niceName = json.nicename;
initComBox(did,json.rpct);
}

function initComBox(did,rpct){
var boxDiv = $("#comBox");
if(boxDiv.html() != null){
boxDiv.html("·····正在加载评论功能·····");
var comBoxHtml ='';
//-评论列表------------------------
var i =0;
var rplen =rplist.length;

comBoxHtml +='<ul><li class="title">网友点评 <span id="rpct"></span> <li></ul>';

if(rplen > 0 ){
//-评论列表------------------------
comBoxHtml +='<div id="rplist">';
var rpcon;
//:em01
for(i=0;i<rplen;i++){
rpcon = rplist[i].rpcon;

rpcon =rpcon.replace(/:em(\d{2})/gi,'<img src="/images/em/$1.gif" alt="$1" width="25" heigth="25" />');
rpcon =rpcon.replace(/\[BR\]/gi,'<br/>');

var showname = rplist[i].uname;
if(rplist[i].account !='')
showname = '<a href="/ufolders/'+rplist[i].account+'" style="color:#1DB6EF; text-decoration:underline;" target="_blank" >'+showname+'</a>';


comBoxHtml +='<ul>';
comBoxHtml +='<li><span style="color:#1DB6EF">'+showname+'</span> <span  style="color:#999">('+rplist[i].rptime+' 发表评论)</span></li>';
comBoxHtml +='<li>'+rpcon+'</li>';
comBoxHtml +='</ul>';
}
comBoxHtml +='</div>';
//-评论列表------------------------
}
comBoxHtml +='<ul>';

//---登录用户---------------------------------------
var login = Account !="-"?true:false;
var nmbox ='';
if(login)
nmbox ='<input type="checkbox" id="nm"  /> 匿名(隐藏个人信息)';

//---登录用户---------------------------------------
comBoxHtml +='<li>昵称：<input id="uname" type="text" maxlength="30" value="'+niceName+'" /> <span id="ckuname" style="color:red;display:none;">*</span> '+nmbox+' <li>';
comBoxHtml +='<li class="emlist" style="width:540px;margin-top:0px;">';

var emname;
for(i=1;i<=50;i++){
emname = i<10 ? "0"+i:i;
comBoxHtml +='<img src="/images/em/'+emname+'.gif" alt="em'+emname+'" width="25" heigth="25" style="border:1px solid #fff;" /> ';
}
comBoxHtml +='</li>';
comBoxHtml +='<li><textarea id="cominf" cols="65" rows="6"></textarea> <span id="ckcominf" style="color:red;display:none;">*</span> </li>';
comBoxHtml +='<li>验证码：<input id="rcode" type="text" maxlength="5" size="5" /> <span id="rcodePic"></span> &nbsp; <input id="doComBtn" type="button" class="btn"  value="发表评论" />  <input id="showComBtn" class="btn" type="button" value="全部评论" /> <li>';
comBoxHtml +='</ul>';

boxDiv.html(comBoxHtml);
//---重定义LI CSS-------------------------------
if(rplen > 0 )
$("#comBox li.title").css({"margin-bottom":"-15px"});
else
$("#comBox li.title").css({"margin-bottom":"-5px"});


$("div#rplist").css({"margin-bottom":"10px","border-bottom":"1px solid #333","padding":"10px"});
$("div#rplist ul").css({"padding":"5px","border-bottom":"1px dashed #ccc"});
$("div#rplist li").css({"padding":"0px","margin":"0px","width":"100%","overflow":"hidden"});

//----------------------------------
//载入界面完成，初始化功能
$("li.emlist img").mouseover(function(){ $(this).css({"border":"1px solid #333"});});
$("li.emlist img").mouseout(function(){ $(this).css({"border":"1px solid #fff"});});

$("li.emlist img").click(function(){ 
var cominf = $("#cominf").val()+":\\"+this.alt ; 
$("#cominf").val(cominf); 
$("#cominf")[0].className =""; 
});

$("#rpct").html(' (目前共有'+rpct+'条评论) ');

$("#cominf")[0].className ="warn";
$("#cominf").focus(function(){
this.className ="";
});
$("#cominf").blur(function(){
if(this.value == "")
this.className ="warn";
});

$("#rcode").focus(function(){
if($("#rcodePic").html() == "")
createRcodePic();
});

$("#uname").blur(function(){
if($("#uname").val() != "")
$("#ckuname").fadeOut();
});

$("#cominf").blur(function(){
if($("#cominf").val() != "")
$("#ckcominf").fadeOut();
});

//--发表评论----------------
$("#doComBtn").click(function(){
var uname = $("#uname").val();
uname =uname.replace(/\s+/gi,'');

var cominf =  $("#cominf").val();
cominf =cominf.replace(/(\n)+/gi,'[BR]');
cominf =cominf.replace(/\s+/gi,'');

var rcode =  $("#rcode").val();
doCom(uname,cominf,rcode,did);
});

//--查看评论----------------
$("#showComBtn").click(function(){
window.open("/CFolders/ShowNewsRps.aspx?did="+did,"","");
});
}


}

function doCom(uname,cominf,rcode,id){
var uick = true;

if(uname == ""){
alert("请输入昵称");
uick =false;
$("#uname").focus();
$("#ckuname").fadeIn();
return false;
}else
$("#ckuname").fadeOut();

if(cominf == ""){
alert("请输入评论内容");
uick =false;
$("#cominf").focus();
$("#ckcominf").fadeIn();
return false;
}else
$("#ckcominf").fadeOut();

if(rcode == ""){
alert("请输入验证码");
uick =false;
$("#rcode").focus();
return false;
}

if(uick){
var nm =false;
if(Account !='-')
nm = document.getElementById("nm").checked;
var sendatas;
sendatas ="cmd=donewscom&uname="+uname+"&cominf="+cominf+"&rcode="+rcode+"&id="+id+"&Account="+Account+"&nm="+nm;
$.ajax({ type: "POST", url: "/contrl/donews.aspx",data:sendatas,dataType:"json",success: function(callback){docomback(callback);},error:function(){return false;}});
}

}

function resizeimg(){
$("#news_m img").each(function(){ 
if(this.className !="fuiPic"){
  var my_w = 540;
  var my_h = 600;
  var image=new Image(); 
  image.src=this.src; 
  if(image.width>0 && image.height>0){ 
  flag=true; 
  if(image.width/image.height>= my_w/my_h){ 
   if(image.width>my_w){
    this.width=my_w; 
    this.height=(image.height*my_w)/image.width; 
    this.onclick=function(){window.open("/picShow.shtml?picurl="+this.src+"&alt=","","")};
   }else{ 
    this.width=image.width;
    this.height=image.height; 
   } 
  } 
  else{ 
   if(image.height>my_h){
    this.height=my_h; 
    this.width=(image.width*my_h)/image.height; 
    this.onclick=function(){window.open("/picShow.shtml?picurl="+this.src+"&alt=","","")};
   }else{ 
    this.width=image.width;
    this.height=image.height; 
   } 
  } 
 } }//fuipic check
 
 });//each
 }


function docomback(json){
var errid = json.errid;
if(errid == '0'){
alert("评论发表成功,需审核");
$("#uname").val('');
$("#cominf").val('');
$("#rcode").val('');
createRcodePic();
location.href = location.href;
}
else{
switch (errid){
case "2":
alert("输入验证码错误");
createRcodePic();
$("#rcode").val('');
break;

case "3":
alert("评论中含有非法信息！");
location.href = location.href;
break;

}
}
}


function createRcodePic(){
var picPath ="/contrl/main.aspx?cmd=getcode&do=docom&sn="+Math.random();
if($("#rcodePic").html()==''){
var picHtml ='<img src="'+picPath+'" alt="点击更换验证码" onclick="createRcodePic()" style="cursor:hand;vertical-align:text-bottom;" />';
$("#rcodePic").html(picHtml);
}else
$("#rcodePic img")[0].src=picPath;

}

