//合并到publicjs\visit_log.js

var visit_log_req;
var visit_log_flag=false;
//js延迟执行
setTimeout(visit_log,7000);
if(typeof(onContent)=="function"){
	onContent(visit_log);
}
else{
	if (document.all) {
		window.attachEvent('onload',visit_log);
	}
	else {
		window.addEventListener('load',visit_log, false);
	}
}

/*
  Description:根据flag判断被访问的类型，并取其点击数，评论数等信息
  Input: flag标志位
*/
function visit_log(flag){
	if(visit_log_flag){
		return false;
	}
	if(typeof(objid)!="undefined"){
	if(flag==null||flag!="0")
		flag="1";
	var v_vuserid=userid;//被访问者id
	var v_objectid=objid;//被访问对象
	var v_pobjectid="";//被访问博客id
	var v_rtype="";//被访问对象类型
	var v_ptype="";//被访问博客类型
	if(typeof(htmltype)=="undefined"){
		htmltype = 	"diary_browse";
	}
	if(typeof(activityid)!="undefined"){
		v_rtype=6;//活动
		v_ptype=2;
		v_pobjectid=blogid;
	}
	else if(htmltype=="diary_browse"||typeof(diaryid)!="undefined"){
		v_ptype=(blogtype=="2")?2:1;
		v_pobjectid=blogid;
		if(v_ptype=="2")
			v_rtype=5;//话题
		else
			v_rtype=1;//日志
	}
	else if(htmltype=="music_browse")
		v_rtype=7;//音乐
	else if(htmltype=="photo_browse")
		v_rtype=2;//图片
	else if(htmltype=="video_browse")
		v_rtype=8;//视频
	else{
		v_rtype=(blogtype=="2")?9:3;
		v_objectid = blogid;
	}
	var v_userid="";
	var v_username="";
	var v_nickname="";
	var v_ouserid="";
	var v_state="0";
	if(public_islogin()){
		var cookies = GetUserinfoCookie();
		//for(var i=0;i<cookies.length;i++){
		//	alert(cookies[i]);
		//}
		v_userid=cookies[1].split("=")[1];
		v_username=cookies[2].split("=")[1];
		v_nickname=cookies[3].split("=")[1];
		v_ouserid=cookies[6].split("=")[1];
		if(cookies.length>7){
			v_state=cookies[7].split("=")[1];
		}
	}
	var v_url = window.location.href;
	if((v_rtype==9||v_rtype==3)&&v_url.indexOf("diary,")!=-1){
		v_ptype=(blogtype=="2")?2:1;
		v_pobjectid=blogid;
		if(v_ptype=="2")
			v_rtype=5;//话题
		else
			v_rtype=1;//日志
	}
	var v_urltitle = objtitle;
	if(v_rtype==5||v_rtype==1){
		var diarytitle = document.getElementById("remaildiarytitle_"+diaryid);
		if(diarytitle!=null){
	 		v_urltitle = diarytitle.value;
	 	}
	}
	var args =new Array(v_vuserid,v_objectid,v_pobjectid,v_rtype,v_ptype,v_url,flag,v_userid,v_username,v_nickname,v_ouserid,v_urltitle,v_state);
	var callback = visitServer;
	Blog.getStatinfo("","",args,callback);
	visit_log_flag=true;
	}
}


/*
  Description:显示日志，博客等的评论数，点击数，引用数
  Input:date状态信息
*/
function visitServer(date){
	if(date!=null){
		var rtype = date.rtype;
		var countDIV = document.getElementById("count_page");
		if(countDIV!=null&&date!=null&&date.blogcncount.length!=0){
			var html = "";
			var hits = date.blogcncount.toString();
			for(var i=0;i<hits.length;i++){
				html=html+"<img src=\"http://style.blogcn.com/blogcnpage/dyncommentimg/counts/"+counttype+"/"+hits.substring(i, i + 1)+".gif\">";
			}
			countDIV.innerHTML=html;
		}
		if(rtype==1||rtype==5){//日志或话题
			var diarypopulartotalDIV = document.getElementById("diarypopulartotal");
			if(diarypopulartotalDIV!=null){
				diarypopulartotalDIV.innerHTML = date.hits;
			}
			var diarycommentDIV = document.getElementById("diarycomment");
			if(diarycommentDIV!=null&&diarycommentDIV.innerHTML==""){
				diarycommentDIV.innerHTML = date.commentcout;
			}
			var diarytrackbackDIV = document.getElementById("diarytrackback");
			if(diarytrackbackDIV!=null){
				diarytrackbackDIV.innerHTML = date.hrefcount;
			}
		}
		else if(rtype==2){//图片
			var albumPicHitsDIV = document.getElementById("albumPicHits");
			if(albumPicHitsDIV!=null){
				albumPicHitsDIV.innerHTML = date.hits;
			}
			var commentsDIV = document.getElementById("div_Comments");
			if(commentsDIV!=null&&commentsDIV.innerHTML==""){
				commentsDIV.innerHTML = date.commentcout;
			}
		}
		else if(rtype==6){//活动
			var diarypopulartotalDIV = document.getElementById("diarypopulartotal");
			if(diarypopulartotalDIV!=null){
				diarypopulartotalDIV.innerHTML = date.hits;
			}
			var diarycommentDIV = document.getElementById("diarycomment");
			if(diarycommentDIV!=null&&diarycommentDIV.innerHTML==""){
				diarycommentDIV.innerHTML = date.commentcout;
			}
			var diarytrackbackDIV = document.getElementById("diarytrackback");
			if(diarytrackbackDIV!=null){
				diarytrackbackDIV.innerHTML = "0";//date.hrefcount;
			}
		}
		else if(rtype==7){//音乐
			showStatistics(date);
		}
		else if(rtype==8){//视频
			showStatistics(date);
		}
	}
}
