﻿var IE=false;
navigator.userAgent.indexOf("MSIE")>=0?IE=true:IE=false
	function Is_Exit(){
		if(confirm("您确定要退出[WoDig我顶]吗？")){
			top.location.href="default.asp?action=logout";
		}
	}
//获取ID
function $id(id,obj){
	if(obj==null){return document.getElementById(id)}
	else{return obj.getElementById(id)}
	}
	
//获取tagname
function $tag(tanme,obj){
	if(obj==null){
return document.getElementsByTagName(tanme)}
else{return obj.getElementsByTagName(tanme)}
	}
//顶一下
function Hit(srcid,UserID){
	var iddiv_obj=$id("Src_ID"+srcid);
	var hitdiv_obj=$id("Src_HitNum"+srcid);
	var RetCode,RetDes;
  var xmldocumento=GetXMLContent("doajax.asp?action=hit&src_id="+srcid+"&UserID="+UserID);
  RetCode=xmldocumento.selectSingleNode( "//ReturnStr/RetCode/text()").nodeValue;
  RetDes=xmldocumento.selectSingleNode( "//ReturnStr/RetDes/text()").nodeValue;
  switch(RetCode){
  	case "0000" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)+1).toString();
  	  iddiv_obj.innerHTML="已顶";
  	  break;
  	case "0001" :
  	  alert(RetDes);
  	   break;
	case "0002" :
  	  alert(RetDes);
  	   break;
  	case "0003" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)+1).toString();
  	  iddiv_obj.innerHTML="已顶";
  	  alert(RetDes);
  	  break;
  	}
  	//window.status=Web_StatusKey;
	}

function Hit2(Post_ID,UserID){
	var iddiv_obj=$id("Post_ID"+Post_ID);
	var hitdiv_obj=$id("Group_HitNum"+Post_ID);
	var RetCode,RetDes;
  var xmldocumento=GetXMLContent("doajax.asp?action=groupHit&groupid="+Post_ID+"&UserID="+UserID);
  RetCode=xmldocumento.selectSingleNode( "//ReturnStr/RetCode/text()").nodeValue;
  RetDes=xmldocumento.selectSingleNode( "//ReturnStr/RetDes/text()").nodeValue;
  switch(RetCode){
  	case "0000" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)+1).toString();
  	  iddiv_obj.innerHTML="已支持";
  	  break;
  	case "0001" :
  	  alert(RetDes);
  	   break;
	case "0002" :
  	  alert(RetDes);
  	   break;
  	case "0003" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)+1).toString();
  	  iddiv_obj.innerHTML="已支持";
  	  alert(RetDes);
  	  break;
  	}
  //	window.status=Web_StatusKey;
	}

function Hit3(srcid,UserID){
	var iddiv_obj=$id("aSrc_ID"+srcid);
	var hitdiv_obj=$id("Src_HitNum"+srcid);
	var RetCode,RetDes;
  var xmldocumento=GetXMLContent("doajax.asp?action=hit2&src_id="+srcid+"&UserID="+UserID);
  RetCode=xmldocumento.selectSingleNode( "//ReturnStr/RetCode/text()").nodeValue;
  RetDes=xmldocumento.selectSingleNode( "//ReturnStr/RetDes/text()").nodeValue;
  switch(RetCode){
  	case "0000" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)-1).toString();
  	  iddiv_obj.innerHTML="已埋掉";
  	  break;
  	case "0001" :
  	  alert(RetDes);
  	   break;
	case "0002" :
  	  alert(RetDes);
  	   break;
  	case "0003" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)-1).toString();
  	  iddiv_obj.innerHTML="已埋掉";
  	  alert(RetDes);
  	  break;
  	}
  	//window.status=Web_StatusKey;
	}

function Hit4(Post_ID,UserID){
	var iddiv_obj=$id("aPost_ID"+Post_ID);
	var hitdiv_obj=$id("Group_HitNum"+Post_ID);
	var RetCode,RetDes;
  var xmldocumento=GetXMLContent("doajax.asp?action=groupHit2&groupid="+Post_ID+"&UserID="+UserID);
  RetCode=xmldocumento.selectSingleNode( "//ReturnStr/RetCode/text()").nodeValue;
  RetDes=xmldocumento.selectSingleNode( "//ReturnStr/RetDes/text()").nodeValue;
  switch(RetCode){
  	case "0000" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)-1).toString();
  	  iddiv_obj.innerHTML="已埋掉";
  	  break;
  	case "0001" :
  	  alert(RetDes);
  	   break;
	case "0002" :
  	  alert(RetDes);
  	   break;
  	case "0003" :
  	  hitdiv_obj.innerHTML=(Math.round(hitdiv_obj.innerHTML)-1).toString();
  	  iddiv_obj.innerHTML="已埋掉";
  	  alert(RetDes);
  	  break;
  	}
  //	window.status=Web_StatusKey;
	}

//创建事件
function CtreateEvent(obj,eventname,func){
	if(navigator.userAgent.indexOf("MSIE")>=0){
		var f =new Function("event",func);
		obj.attachEvent(eventname,f);
		}
		else{
			obj.setAttribute(eventname,func);
			}
	}
//获得一个页面的RSS链接
	function getRssUrl(){
		var theurl="";
		var thelinkarray;
		var a=0;
		thelinkarray=$tag("link")
		if(thelinkarray.length>=0){
			for(a=0;a<thelinkarray.length;a++){
				if(thelinkarray[a].type=="application/rss+xml"){
					return thelinkarray[a].href;
					break;
					}
				}
			}
		return theurl;
		}
//在新窗口打开图片
function OpenImg(imjobj){
	imjobj.style.cursor="pointer";
	var thesrc=imjobj.src;
	CtreateEvent(imjobj,"onclick","window.open('"+thesrc+"')")
	}

//重设图片大小
function ResizeImg(obj,theWidth,theHeight){
	if(obj!=null){
		var imglist=$tag("img",obj);
		if(imglist!=null){
			var a;
			for(a=0;a<imglist.length;a++){
				if(imglist[a].width>theWidth){
					imglist[a].height=Math.round(imglist[a].height*(theWidth/imglist[a].width));
					imglist[a].width=theWidth;
				}
				else if(imglist[a].height>theHeight){
					imglist[a].width=Math.round(imglist[a].width*(theHeight/imglist[a].height));
					imglist[a].height=theHeight;
					}
				OpenImg(imglist[a]);
				}
			}
		}
	}
//重设链接目标
function changeTarget(obj,targetname){
	if(obj!=null){
		var alist=obj.getElementsByTagName("a");
		if(alist!=null){
			var a;
			for(a=0;a<alist.length;a++){
				if(alist[a].target.toLocaleLowerCase()!==targetname){
					alist[a].target=targetname;
					}
				}
			}
		}
	}


//查找网页内宽度太大的图片进行缩放以及PNG纠正
 function ReImgSize(){
  for (i=0;i<document.images.length;i++)
   {
   if (document.all){
	if (document.images[i].width>550)
	 {
       document.images[i].width="550"
       try{
	       document.images[i].outerHTML='<a href="'+document.images[i].src+'" target="_blank" title="在新窗口打开图片">'+document.images[i].outerHTML+'</a>'
  	 	}catch(e){}
  	 }
   }
  else{
	if (document.images[i].width>400) {
	  document.images[i].title="在新窗口打开图片"
	  document.images[i].style.cursor="pointer"
	  document.images[i].onclick=function(e){window.open(this.src)}
	}
  }
  }
 }

/*=============给评论翻页===============*/
/*
 * 打开评论页面
 */
function openCommentPage(o){
	setTimeout(function(){loadComment(o.getAttribute("page"));},0);
	o.innerHTML = '<img src="images/Loading.gif" border="0" style="position:absolute"/>&nbsp;&nbsp;&nbsp;&nbsp;';
	o.style.textDecoration = "none"
}

/*
 * 加载评论数据
 */
function loadComment(page,needTips){
	if (window._loadComment) {
		return;
	}
	
	if (needTips) {
		fillComment("<div style='margin-bottom:10px;'>正在加载评论数据...</div>");
	}
	window._loadComment = true;
	var cJS = document.createElement("script");
	cJS.chatset = "utf-8";


	cJS.src = "load_Comment.asp?id=" + g_logID + "&page=" + page + "&	comDesc=" + g_comDesc;
	
	document.getElementsByTagName("HEAD")[0].appendChild(cJS);
}

/*
 * 尝试从hash里加载评论
 */
function tryLoadComment(){
	var hash = location.hash;
	var page = /page=(\d)+/g.exec(hash);
	if (page && page[1]>1) {
		loadComment(page[1],true);
	}
}

/*
 * 填充评论
 */
function fillComment(html){
	var cb = $("commentBox");
	cb.innerHTML = html;
	window._loadComment = false;
}

/**
 * 主人回复
 */
function replyMsg(logId,id,a1,a2,a3){
	var _r = $("reply_" + id);
	if (!_r) {
		_r = document.createElement("div");
		_r.id = "reply_" + id;
		var _c = $("commcontent_" + id);
		_c.appendChild(_r);

		_r.innerHTML = '<br/><div class="UBBPanel replayPanel"><div class="UBBTitle"><img alt="评论回复" style="margin: 0px 2px -3px 0px;" src="images/icon_reply.gif"/> 评论回复</div><div class="UBBContent">' +
				'<form onsubmit="return checkReplyMsg(this)" method="post" action="reply.asp" target="replyFrame_'+id+'">' +
				'<input type="hidden" name="id" value="'+id+'"/><input type="hidden" name="logId" value="'+logId+'"/>' +
				'<input type="hidden" name="a1" value="'+a1+'"/><input type="hidden" name="a2" value="'+a2+'"/><input type="hidden" name="a3" value="'+a3+'"/>' +
				'<textarea name="replay" style="width: 99%; height: 60px;" class="editTextarea" id="edit_'+id+'"></textarea>' +
				'<input type="submit" value="回复" class="userbutton"  id="button_'+id+'"/> <input onclick="removeReplyMsg('+id+')" type="button" value="取消" class="userbutton"/>' +
				'<iframe name="replyFrame_'+id+'" style="display:none"/></form></div></div>';
	}
	$('button_'+id).focus();
	$('edit_'+id).select();
}

function checkReplyMsg(o){
	var msg = Trim(o.replay.value)
	if (msg == "") {
		alert("回复不能为空")
		o.replay.select();
		return false
	}
	return true
}

function removeReplyMsg(id){
	var _r = $("reply_" + id);
	if (_r) {
		_r.parentNode.removeChild(_r);
	}
}
