
//PNG背景透明
var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

function fixPNG(myImage) 
{
    if ((version >= 5.5) && (version < 7) && (document.body.filters)) 
    {
       var img = myImage
	   var imgID = (myImage.id) ? "id='" + myImage.id + "' " : ""
	   var imgClass = (myImage.className) ? "class='" + myImage.className + "' " : ""
	   var imgTitle = (myImage.title) ?  "title='" + myImage.title  + "' " : "title='" + myImage.alt + "' "
	   var imgStyle = "display:inline-block;" + myImage.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:" + myImage.width 
                  + "px; height:" + myImage.height 
                  + "px;" + imgStyle + ";"
                  + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
                  + "(src=\'" + myImage.src + "\', sizingMethod='scale');\"></span>"
	   myImage.outerHTML = strNewHTML	  
    }
}


function GetObj(objName){
	if(document.getElementById){
		return eval('document.getElementById("' + objName + '")');
	}else if(document.layers){
		return eval("document.layers['" + objName +"']");
	}else{
		return eval('document.all.' + objName);
	}
}




//更改字体大小
var status0='';
var curfontsize=12;
var curlineheight=15;
function fontZoomA(){
  if(curfontsize>8){
    document.getElementById('container').style.fontSize=(--curfontsize)+'pt';
   // document.getElementById('newsbody').style.lineHeight=(--curlineheight)+'pt';
  //document.getElementById('newshome').style.fontSize=(--curfontsize)+'pt';
 document.getElementById('container').style.lineHeight=(--curlineheight)+'pt';
  }
}
function fontZoomB(){
  if(curfontsize<64){
    document.getElementById('container').style.fontSize=(++curfontsize)+'pt';
 document.getElementById('container').style.lineHeight=(++curlineheight)+'pt';
 // document.getElementById('newshome').style.fontSize=(++curfontsize)+'pt';
// document.getElementById('newshome').style.lineHeight=(++curlineheight)+'pt';
  }
}





var xmlobj;                                     //定义XMLHttpRequest对象
function CreateXMLHttpRequest()
{
  if(window.XMLHttpRequest)
{//Mozilla浏览器
    xmlobj=new XMLHttpRequest();
    if(xmlobj.overrideMimeType)
    {//设置MIME类别
       xmlobj.overrideMimeType("text/xml");
    }
}
else if(window.ActiveXObject)
{                     //IE浏览器
   try
   {
    xmlobj=new ActiveXObject("Msxml2.XMLHttp");
   }
   catch(e)
   {
    try
    {
     xmlobj=new ActiveXobject("Microsoft.XMLHttp");
    }
    catch(e)
    {
    }
   }
}

}

function Validate()                             //主程序函数

{
    CreateXMLHttpRequest();                     //创建对象
 var showurl = "showtitle.php?wjmc=" + document.getElementById ("wjmc").value;           //构造URL
   xmlobj.open("GET", showurl, true);          //调用validate.php

    xmlobj.onreadystatechange = StatHandler;    //判断URL调用的状态值并处理
    xmlobj.send(null);                          //设置为不发送给服务器任何数据
}

function StatHandler() {                         //用于处理状态的函数
if(xmlobj.readyState == 4 && xmlobj.status == 200)  //如果URL成功访问，则输出网页                                                                     
{
document.getElementById("msg").innerHTML=xmlobj.responseText ;//替换，即输出结果。
    }

}


function checkpost(itm) {	

  if(!itm.elements && itm.form){
  	itm = itm.form;
  }

	if (itm.wjmc.value=='') {
		alert('请填写文件标题');
		itm.elements['wjmc'].focus();
		return false;
	}

	if (!(itm.email.value=='')) {
	if(!/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(itm.email.value)) 
             {
                 alert("请输入格式正确的 e-mail 地址！");
				 itm.elements['email'].focus();
				 return false;
				 
				 }
				 }

	var _item = itm.elements['code'].parentNode;


	if (_item.parentNode.style.display=='none'){
		
					_item.parentNode.style.display='block';
					_item.childNodes[(_item.childNodes.length-1)].src='/captcha.php';
					itm.elements['code'].value = '';		
			return false;
	}else{
		if(itm.elements['code'].value.length == 0){
					alert('请填写验证码后再发表');
					itm.elements['code'].focus();
			return false;
		}else{
			return true;
			}
	}
}


function _ShowReply(ReplyID,sID){

			var ReplyDiv = GetObj('Reply'+ReplyID);
			GetObj('AxajTip3'+ReplyID).style.display='none';
			//document.getElementById('AxajTip'+ReplyID).style.display='none';
			ReplyDiv.style.display='block';
		
			if(ReplyDiv.innerHTML.length == 0){
				replydivHtml = '<div class="Header"><div class="commretle">快速回复此评论</div></div>';
				//replydivHtml += '<form name="comment' + ReplyID + '" action="/comment.php" method="post" onsubmit="return checkReply(this,'+ReplyID+')">'
				replydivHtml += '<input name="aid" type="hidden"  value="'+ ReplyID +'" /><input type="hidden" name="sid" value="' + sID + '"/>'
				replydivHtml += '<div class="Content">'
	      	 	//replydivHtml += '<div class="commtext"><label>评论主题:</label><input class="comminput" name="nowsubject" type="text" id="subject' + ReplyID + '" value="' + ReTitle + '"/></div>'
	      	 	replydivHtml += '<div class="commtext"><label>您的大名:</label><input class="comminput" name="FullName" type="text" id="FullName' + ReplyID + '" value="' + readCookie('cbGuestName') + '"/></div>'
	      	 	replydivHtml += '<div class="commtext"><label>您的主页:</label><input class="comminput" name="Website" type="text" id="Website' + ReplyID + '" value="http://"/></div>'
	      	 	replydivHtml += '<div class="commtext"><label>您的邮箱:</label><input class="comminput" name="Email" type="text" id="Email' + ReplyID + '"/></div>'
	      	 	replydivHtml += '<div class="commtext"><label>您的评论:</label><textarea name="CommentText" id="CommentText' + ReplyID + '" onfocus="getCodeIMG(\'' + ReplyID + '\');"></textarea></div>'
	      	 	replydivHtml += '<div class="commtext" style="display:none;" id="commcodeimg' + ReplyID + '"><label>　验证码:</label><input type="text" class="comminput" name="code" id="code' + ReplyID + '" style="width: 40px;"/><img src="" name="safecode" style="cursor:pointer" align="absbottom" id="imgcode' + ReplyID + '" alt="更换一张验证码图片" onclick="refreshimg(\''+ ReplyID + '\');"> [<a href="javascript:refreshimg(\'' + ReplyID + '\');">刷新验证码</a>] </div>'
	      	 	//<span class="tip" id="tip_comment' + ReplyID + '"></span>
	      	 	replydivHtml += '<div id="AxajTip' + ReplyID + '" class="comming" style="display:none;"></div>'
	      	 	//replydivHtml += '<div class="commtext" id="bottom' + ReplyID + '" style="text-align:right;"><input type="button" class="commbutton" value="递交" id="button' + ReplyID + '" onClick="checkform(\'' + ReplyID + '\',' + sID +')"/><input type="button" class="commButton" value="关闭快速回复" onclick="_HideReply(\'' + ReplyID +'\')"></div></div>'
				replydivHtml += '<div class="commtext" id="bottom' + ReplyID + '" style="text-align:right;"><input type="button" class="commbutton" value="发表评论" name="send" id="send' + ReplyID + '" onClick="checkform(\'' + ReplyID + '\',' + sID +')"/><input type="button" class="commbutton" value="关闭快速回复" onclick="_HideReply(\'' + ReplyID +'\')"></div></div>'
	      	 	//replydivHtml += '</form>';
	            //热门评论特别处理
	      	 	if (isNaN(ReplyID)){
	      	 		ReplyDiv.style.width='320px';
	      	 		replydivHtml = replydivHtml.replace(/\<input class="comminput"/g,'<input class="comminput" style="width: 150px;"');
	      	 		replydivHtml = replydivHtml.replace('<textarea name="CommentText"','<textarea name="CommentText" style="width: 212px;"');
	      	 		}
	      	 	ReplyDiv.innerHTML = replydivHtml;
	      	 	
      	 	}else{
      	 		//_HideReply(ReplyID);
      	 		}
}



function getCodeIMG(ReplyID){
	var Valdiv = document.getElementById('commcodeimg'+ReplyID);
	if (Valdiv.style.display=='none'){
			Valdiv.style.display='block';
			refreshimg(ReplyID);
			}
  //Valdiv.style.display = "";
}

function refreshimg(ReplyID)
{
	document.getElementById('imgcode'+ReplyID).src = '/captcha.php?'+ Math.random();
}


//隐藏快速回复表单
function _HideReply(ReplyID){
	var ReplyDiv = GetObj('Reply'+ReplyID);
	ReplyDiv.style.display='none';
	//ReplyDiv.innerHTML = '';
}






//Axaj回复
function checkform(ReplyID,sID) {
	GetObj('AxajTip3'+ReplyID).style.display = 'none';
    GetObj('AxajTip'+ReplyID).style.display = 'none';
	GetObj('AxajTip2'+ReplyID).style.display = 'none';

		var inobj = GetObj('Email'+ReplyID);
		if (!(inobj.value=='')) {
		if(!/(\S)+[@]{1}(\S)+[.]{1}(\w)+/.test(inobj.value)){
               _Showcommts('AxajTip'+ReplyID,'请输入格式正确的 e-mail 地址！','comming');
				 inobj.focus(); return false;}
		}
var inobj = GetObj('CommentText'+ReplyID);
		if(inobj.value==''){	
			_Showcommts('AxajTip'+ReplyID,'请填写评论后再发表','comming');
			inobj.focus();return false;}
		
		var inobj = GetObj('code'+ReplyID);
		if(inobj.value==''){	_Showcommts('AxajTip'+ReplyID,'请填写验证码后再发表','comming');inobj.focus();return false;}


	StopButton('send'+ReplyID,5);

   var x = new Ajax('AxajTip2'+ReplyID,'HTML','comming');

   //tid sid valimg_main comment nowsubject
   var queryString = "CommentID="+_FixHotReplyID(ReplyID) +"&FullName="+GetObj('FullName'+ ReplyID).value+"&code="+GetObj('code'+ ReplyID).value+"&CommentText="+fixText(Replace(GetObj('CommentText'+ ReplyID).value))+"&Website="+GetObj('Website'+ ReplyID).value+"&Email="+GetObj('Email'+ ReplyID).value+"&aid="+sID;
	//记忆访客信息
	createCookie('cbGuestName', GetObj('FullName'+ReplyID).value, 1);
	createCookie('cbGuestPage', GetObj('Website'+ReplyID).value, 1);
	createCookie('cbGuestEmail', GetObj('Email'+ReplyID).value, 1);
	//alert(queryString);
	var ajaxReq = '',reqClass='comming';
   x.post('/scomment.php?ver=new',queryString,function(r){
		switch(r.substr(0,1)){
		case '0':
		        ajaxReq = '您要评论的新闻不存在';
		        break;
		case '1':
		        ajaxReq = '验证码不正确';
		        break;
		case '2':
		       ajaxReq = '30秒内不允许再次评论';
		        break;
		case "3":
		        ajaxReq = '请填写评论后再提交';
		        break;
		case "4":
		        ajaxReq = '评论字数超过限制';
		        break;
		case "5":
		        ajaxReq = '发送评论成功.';
		        reqClass = 'commingok';
		        GetObj('normal').innerHTML = r.substr(1);
		        _Showcommts('AxajTip3'+ReplyID,ajaxReq,reqClass);
				try{GetObj('CommentText'+ReplyID).value='';GetObj('commcodeimg'+ReplyID).style.display='none';}catch(e){}
				return true;
		        break;
		case "6":
			    ajaxReq = 'CBFW检测到您输入了不适当字词，请纠正';
		        break;
		case "7":
			    ajaxReq = '您的评论需审核后才能显示';
		        reqClass = 'AjaxTipdelay';
		        _Showcommts('AxajTip3'+ReplyID,ajaxReq,reqClass);
				try{GetObj('CommentText'+ReplyID).value='';GetObj('commcodeimg'+ReplyID).style.display='none';}catch(e){}
				return true;
		        break;
		case "8":
			    ajaxReq = '由于种种原因，这条新闻不开放评论，请见谅';
		        break;
		default:
		        ajaxReq = '未知错误' + r;
		}
		//_Showcommts('AxajTip'+ReplyID,'请输入格式正确的 e-mail 地址！','comming');
		_Showcommts('AxajTip'+ReplyID,ajaxReq,reqClass);
 		refreshimg(ReplyID);
		
	});
}


function _HideAxajTip(myobj){
	myobj.parentNode.parentNode.style.display='none';
}

function _Showcommts(divobj,ajaxReq,reqClass){
		var commtsDiv = GetObj(divobj);
		ajaxReq = '<div style="float: right"><img src="/images/'+ reqClass +'.gif" style="margin: 7px 7px;" onclick="_HideAxajTip(this);"></div><div>' + ajaxReq + '<div>';
		commtsDiv.className = reqClass;
		commtsDiv.innerHTML = ajaxReq;
		commtsDiv.style.display = 'block';
	}
/*
function _Showcommts(divobj,ajaxReq,reqClass){
		var commtsDiv = document.getElementById(divobj);
		ajaxReq = '<div style="float: right"><img src="/images/'+ reqClass +'.gif" style="margin: 7px 7px;" onclick=this.parentNode.parentNode.style.display="none"></div><div>' + ajaxReq + '</div>';
		commtsDiv.className = reqClass;
		commtsDiv.innerHTML = ajaxReq;
		commtsDiv.style.display = 'block';
	}
*/




//针对热门回复的快速恢复处理
function _FixHotReplyID(ReplyID){
     		if (isNaN(ReplyID)){
     			return ReplyID.substr(1);
     		}else{
     			return ReplyID;
     		}
}

//针对回复的Ajax投票
function _ReplyVote(ReplyID,mode){
		GetObj('AxajTip3'+ReplyID).style.display = 'none';
	     var x = new Ajax('AxajTip2'+ReplyID,'HTML','comming');

     		x.get('/f.vote.php?aid=' + _FixHotReplyID(ReplyID) + '&' + mode + '=1',function(r){
     			if(r.substr(0,1) == '0'){
     				if(r.substr(1,1) == '0'){
     					GetObj('support'+ReplyID).innerHTML = r.substr(2)
     					}else{
     						GetObj('against'+ReplyID).innerHTML = r.substr(2,10)
     						};
				/*alert('谢谢您的参与');
     			}else{alert('你已经投过票了');}
     			})*/
     			_Showcommts('AxajTip3'+ReplyID, '谢谢您的参与','commingok');
     			}else{
     				_Showcommts('AxajTip3'+ReplyID, '你已经投过票了','comming');
     				}
     			})
}








 function StopButton(id,min)
 { 
  GetObj(id).disabled='disabled';
  GetObj(id).value="发表评论("+min+")";
if(--min>0) setTimeout("StopButton('"+id+"',"+min+")",1000);
if(min<=0){GetObj(id).value='发表评论';
           GetObj(id).disabled='';}
}


//读取Cookie
createCookie = function(nm,val,y){var exp='';if(y){var dt=new Date();dt.setTime(dt.getTime()+(y*86400000));exp='; expires='+dt.toGMTString();}document.cookie=nm+'='+escape(val)+exp+';path=/';}
//读取Cookie
readCookie = function(nm){var m='';if(window.RegExp){var re=new RegExp(';\\s*'+nm+'=([^;]*)','i');m=re.exec(';'+document.cookie);}return(m?unescape(m[1]):'');}



function Arcomment(sid,pos){
	GetObj('loading_'+pos).style.display = 'block';
	var x = new Ajax('text_'+pos,'HTML','');
	var url = '/comment/'+pos+'/'+sid+'.html';
	 x.get(url,function(r){
   GetObj('loading_'+pos).style.display = 'none';
   GetObj(pos).innerHTML=r;

  },0);
}


function Ncomment(method,url,rep){
  //GetObj('textloading').style.display = 'block';
  //alert(url);
  var x = new Ajax('textloading','HTML','');
  x.get(url,function(r){
   GetObj('textloading').style.display = 'none';
   GetObj(rep).innerHTML=r;

  });

}




function dig(sid){

  var x = new Ajax('loading'+sid,'HTML','');
  url='/f_dig.php?aid='+sid;
  
  x.get(url,function(r){

   //GetObj('dig'+sid).style.display = 'none';
   if(r.substr(0,1) == '0'){
     				
     						GetObj('dig'+sid).innerHTML = r.substr(1,10);
     		     			GetObj('action'+sid).innerHTML = '谢谢参与';
     			}else if(r.substr(0,1) == '1'){
					GetObj('action'+sid).innerHTML = '已顶成';
     				
     				}
					else{
					GetObj('reply'+sid).innerHTML = 'Error';
     				}
  });
}


///-----------------------------------------------------------
//Ajax类
function Ajax(statusId,recvType,statusClass,cache) {
	
	
	var aj = new Object();
	aj.statusId = GetObj(statusId);
	if(statusClass!==''){aj.statusId.className = statusClass;}
	aj.targetUrl = '';
	aj.sendString = '';
	aj.recvType = recvType ? recvType : 'HTML';//HTML XML
	aj.resultHandle = null;

	aj.createXMLHttpRequest = function() {
		var request = false;
		if(window.XMLHttpRequest) {
			request = new XMLHttpRequest();
			if(request.overrideMimeType) {
				request.overrideMimeType('text/xml');
			}
		} else if(window.ActiveXObject) {
			var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
			for(var i=0; i<versions.length; i++) {
				try {
					request = new ActiveXObject(versions[i]);
					if(request) {
						return request;
					}
				} catch(e) {
					//alert(e.message);
				}
			}
		}
		return request;
	}

	aj.XMLHttpRequest = aj.createXMLHttpRequest();

	aj.processHandle = function() {
		aj.statusId.style.display = 'block';
		if(aj.XMLHttpRequest.readyState == 1) {
			aj.statusId.innerHTML = '正在建立连接...';
			
		} else if(aj.XMLHttpRequest.readyState == 2) {
			aj.statusId.innerHTML = '正在发送数据...';
		} else if(aj.XMLHttpRequest.readyState == 3) {
			aj.statusId.innerHTML = '正在接受数据...';
		} else if(aj.XMLHttpRequest.readyState == 4) {
			if(aj.XMLHttpRequest.status == 200) {
				aj.statusId.innerHTML = '正在处理数据...';
				if(aj.recvType == 'HTML') {
					aj.resultHandle(aj.XMLHttpRequest.responseText);
				} else if(aj.recvType == 'XML') {
					aj.resultHandle(aj.XMLHttpRequest.responseXML);
				}
			aj.statusId.style.display = 'none';
			} else {
				aj.statusId.innerHTML = '';
			}
		}
	}

	aj.get = function(targetUrl, resultHandle,cache) {
		/*if(cache==''){
		cache=1;
		}
		if(cache==1){
		if (targetUrl.indexOf("?") > 0)
                {
                    targetUrl += "&randnum=" + Math.random();
                }
                else
                {
                    targetUrl += "?randnum=" + Math.random();
                }
		}*/
		aj.targetUrl = targetUrl;
		aj.XMLHttpRequest.onreadystatechange = aj.processHandle;
		aj.resultHandle = resultHandle;
		if(window.XMLHttpRequest) {
			aj.XMLHttpRequest.open('GET', aj.targetUrl);
			aj.XMLHttpRequest.send(null);
		} else {
		        aj.XMLHttpRequest.open("GET", targetUrl, true);
		        aj.XMLHttpRequest.send();
		}
	}

	aj.post = function(targetUrl, sendString, resultHandle) {
		if (targetUrl.indexOf("?") > 0)
                {
                    targetUrl += "&randnum=" + Math.random();
                }
                else
                {
                    targetUrl += "?randnum=" + Math.random();
                }
		aj.targetUrl = targetUrl;
		aj.sendString = sendString;
		aj.XMLHttpRequest.onreadystatechange = aj.processHandle;
		aj.resultHandle = resultHandle;
		aj.XMLHttpRequest.open('POST', targetUrl);
		aj.XMLHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		aj.XMLHttpRequest.setRequestHeader("charset","gb2312");
		aj.XMLHttpRequest.send(aj.sendString);
	}
	return aj;
}


function Replace(str){
 
   re = /%/g;             // 创建正则表达式模式。
   str = str.replace(re, "％");    //  替换 
   re = /\+/g;
   str = str.replace(re, "＋");
   return(str);                   // 返回替换后的字符串。
}
