var offX = 4;
var offY = 4;
var width = 0;
var height = 0;
var scrollX = 0;
var scrollY = 0;  
var x = 0;
var y = 0;

//图片

	
function tagshow(e, tagname) {
	tipXY(e);
	var url = siteUrl + "/tagshow.php?x=" + x + "&y=" + y + "&w=" + width + "&h=" + height + "&sx=" + scrollX + "&sy=" + scrollY + "&tagname=" + tagname;
	run(url);
}

function taghide() {
	var tip = document.getElementById("tipDiv");
	tip.style.display = 'none';
}

function tipXY(e) {
	
	offX = 4;
	offY = 4;
	width = 0;
	height = 0;
	scrollX = 0;
	scrollY = 0;  
	x = 0;
	y = 0;
	
	if (window.innerWidth) width = window.innerWidth - 18;
	else if (document.documentElement && document.documentElement.clientWidth) 
		width = document.documentElement.clientWidth;
	else if (document.body && document.body.clientWidth) 
		width = document.body.clientWidth;
	

	if (window.innerHeight) height = window.innerHeight - 18;
	else if (document.documentElement && document.documentElement.clientHeight) 
		height = document.documentElement.clientHeight;
	else if (document.body && document.body.clientHeight) 
		height = document.body.clientHeight;


	if (typeof window.pageXOffset == "number") scrollX = window.pageXOffset;
	else if (document.documentElement && document.documentElement.scrollLeft)
		scrollX = document.documentElement.scrollLeft;
	else if (document.body && document.body.scrollLeft) 
		scrollX = document.body.scrollLeft; 
	else if (window.scrollX) scrollX = window.scrollX;
			
  
	if (typeof window.pageYOffset == "number") scrollY = window.pageYOffset;
	else if (document.documentElement && document.documentElement.scrollTop)
		scrollY = document.documentElement.scrollTop;
	else if (document.body && document.body.scrollTop) 
		scrollY = document.body.scrollTop; 
	else if (window.scrollY) scrollY = window.scrollY;
	
	x=e.pageX?e.pageX:e.clientX+scrollX;
	y=e.pageY?e.pageY:e.clientY+scrollY;
}

function promptfriends(e, uid) {
	tipXY(e);
	var url = siteUrl + "/batch.common.php?action=promptfriends&x=" + x + "&y=" + y + "&w=" + width + "&h=" + height + "&sx=" + scrollX + "&sy=" + scrollY + "&uid=" + uid;
	run(url);
}

function joinfriends(uid, grade) {
	var tip = document.getElementById("tipDiv");
	tip.style.display = 'none';
	var url = siteUrl + "/batch.common.php?action=joinfriends&uid=" + uid + "&grade=" + grade;
	run(url);
}


function joinfavorites(itemid) {
	var url = siteUrl + "/batch.common.php?action=joinfavorites&itemid=" + itemid;
	run(url);
}

function deletecomment(cid) {
	if(confirm("您确定要删除此条留言吗？")) {
		var url = siteUrl + "/batch.common.php?action=deltecomment&cid=" + cid;
		run(url);
	}
}

/**
 * 删除操作
 * 
 * @param string actionstr ：请求类型与batch.common.php中的case一一对应
 * @param int delid　：删除的ID号
 */
function deleteannal(actionstr,delid) {
	if(confirm("您确定要删除吗？")) {
		var url = siteUrl + "/batch.common.php?action="+actionstr+"&delid=" + delid;
		run(url);
	}
}

function showguestbook(gid) {
	var url = siteUrl + "/batch.common.php?action=showguestbook&gid=" + gid;
	run(url);
}

function run(url) {
	var pf = document.getElementById("phpframe");
	pf.src = url;
}

function postcomment() {
	var frm = document.getElementById("commentform");
	var btn = document.getElementById("btncomment");
	btn.value = "请稍等...";
	btn.disabled = true;
	
	frm.target = "phpframe";
	frm.submit();
	return false;
}

function postthread(itemid, tid) {
	var frm = document.getElementById("commentform");
	//var btn = document.getElementById("btncomment");
	//btn.value = "请稍等...";
	//btn.disabled = true;
	
	if(itemid && tid) {
		var url = siteUrl + "/batch.common.php?action=postthread&itemid=" + itemid + "&tid=" + tid;
		run(url);
	}

	frm.target = "phpframe";
	frm.submit();
	return false;
}

function findobj(n, d) {
	var p, i, x;
	if(!d) d = document;
	if((p = n.indexOf("?"))>0 && parent.frames.length) {
		d = parent.frames[n.substring(p + 1)].document;
		n = n.substring(0, p);
	}
	if(x != d[n] && d.all) x = d.all[n];
	for(i = 0; !x && i < d.forms.length; i++) x = d.forms[i][n];
	for(i = 0; !x && d.layers && i < d.layers.length; i++) x = findobj(n, d.layers[i].document);
	if(!x && document.getElementById) x = document.getElementById(n);
	return x;
}


function copycode(obj) {
	var rng = document.body.createTextRange();
	rng.moveToElementText(obj);
	rng.scrollIntoView();
	rng.select();
	rng.execCommand("Copy");
	rng.collapse(false);
}

function imgzoom(o) {
	if(event.ctrlKey) {
		var zoom = parseInt(o.style.zoom, 10) || 100;
		zoom -= event.wheelDelta / 12;
		if(zoom > 0) {
			o.style.zoom = zoom + '%';
		}
		return false;
	} else {
		return true;
	}
}

//复制URL地址
function setCopy(_sTxt){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		clipboardData.setData('Text',_sTxt);
		alert ("网址“"+_sTxt+"”\n已经复制到您的剪贴板中\n您可以使用Ctrl+V快捷键粘贴到需要的地方");
	} else {
		prompt("请复制网站地址:",_sTxt); 
	}
}

//加入收藏
function addBookmark(site, url){
	if(navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
		window.external.addFavorite(url,site)
	} else if (navigator.userAgent.toLowerCase().indexOf('opera') > -1) {
		alert ("请使用Ctrl+T将本页加入收藏夹");
	} else {
		alert ("请使用Ctrl+D将本页加入收藏夹");
	}
}

/**
 * 获取一个对象
 * @param string id: 标答ID或name名称
 * @return object
 */
function getbyid(id) {
	if (document.getElementById) {
		return document.getElementById(id);
	} else if (document.all) {
		return document.all[id];
	} else if (document.layers) {
		return document.layers[id];
	} else {
		return null;
	}
}

//显示隐藏媒体
function showmedia(Obj, mWidth, mHeight) {
	var mediaStr;
	var mFile = Obj.href;
	var mFileType = Obj.className.toLowerCase();

	switch(mFileType){
		case "showflash":
			mediaStr="<object codeBase='http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0' classid='clsid:D27CDB6E-AE6D-11cf-96B8-444553540000' width='"+mWidth+"' height='"+mHeight+"'><param name='movie' value='"+mFile+"'><param name='quality' value='high'><param name='AllowScriptAccess' value='never'><embed src='"+mFile+"' quality='high' pluginspage='http://www.macromedia.com/go/getflashplayer' type='application/x-shockwave-flash' width='"+mWidth+"' height='"+mHeight+"'></embed></OBJECT>";
			break;
		case "showvideo":
			mediaStr="<object width='"+mWidth+"' height='"+mHeight+"' classid='CLSID:6BF52A52-394A-11d3-B153-00C04F79FAA6'><param name='url' value='"+mFile+"' /><embed width='"+mWidth+"' height='"+mHeight+"' type='application/x-mplayer2' src='"+mFile+"'></embed></object>";
	}
	
	var mediaDiv = document.getElementById(escape(mFile.toLowerCase()));
	
	if (mediaDiv) {
		Obj.parentNode.removeChild(mediaDiv);
	} else {
		mediaDiv = document.createElement("div");
		mediaDiv.id = escape(mFile.toLowerCase());
		mediaDiv.innerHTML = mediaStr;
		Obj.parentNode.insertBefore(mediaDiv,Obj.nextSibling);
	}
	return false;
}

//重置大图片
function resizeimage() {
	var msgareas=document.getElementsByTagName("div");
	for (i=0; i<msgareas.length; i++) {
		if (msgareas[i].className=="itemmessage" || msgareas[i].id=="articlebody" || msgareas[i].id=="comment") {
			var imgsinlog=msgareas[i].getElementsByTagName("img");
			for(j=0; j<imgsinlog.length; j++) {
				if (imgsinlog[j].width>'500') {
					imgsinlog[j].width="500";
					imgsinlog[j].style.cursor= 'pointer';
					imgsinlog[j].onclick = function() {window.open(this.src);}
					if (navigator.userAgent.toLowerCase().indexOf('ie') > -1) {
						imgsinlog[j].title = '请使用Ctrl+鼠标滚轮缩放图片，点击图片可在新窗口打开';
							imgsinlog[j].onmousewheel = function img_zoom()    
							{
							  var zoom = parseInt(this.style.zoom, 10) || 100;
							  zoom += event.wheelDelta / 12;
							  if (zoom > 0 && event.ctrlKey) this.style.zoom = zoom + '%';
							  return false;
							}
					} else {
						imgsinlog[j].title = '点击图片可在新窗口打开';
					}
				}
			}
		}
	}
} 



//Tab切换
function settab(area,id) {
	var divid = new Array('day','week','all');
	var tabarea = document.getElementById(area);
	var acttab = document.getElementById(id);
	var tabtext = document.getElementById("hotarticle");
	var tabinarea = tabarea.getElementsByTagName("span");
	var textshow = tabtext.getElementsByTagName("div");
	for(var i=0; i<tabinarea.length; i++) {
		tabinarea[i].className = '';
	}
	for(var j=0;j<textshow.length;j++) {
		textshow[j].id = divid[j]+"_hidden";
	}
	acttab.className = 'active';
	document.getElementById(id+"_hidden").id = "hotarticlelist";
}

//显示工具条
function hidetoolbar() {
	window.parent.document.getElementById("toolbarframe").style.display="none";
}
function hidetoolbarOpera() {
	if (navigator.userAgent.toLowerCase().indexOf('opera') > -1) {
		window.parent.document.getElementById("toolbarframe").style.display="none";
	}
}

function showtoolbar() {
	document.getElementById("toolbarframe").style.display = "block";
}
//显示、隐藏menu
function showhidemenu() {
	var menu = document.getElementById('menu');
	if (menu.style.height=='' || menu.style.height=='31px') {
		menu.style.height = 'auto';
		menu.style.height = 'auto';
	} else {
		menu.style.height = '31px';
	}
}


//投票
var showvotetime, hidevotetime;
function showvote() {
	clearTimeout(hidevotetime);
	
	var votearea = document.getElementById('vote');
	
	var vh = votearea.style.height;
	if (vh=='') {vh='80px'}
	var vhLen = vh.length-2;
	var vhNum = parseInt(vh.substring(0,vhLen));
	
	if (vhNum<315) {
		votearea.style.height = (vhNum+60)+'px';
		showvotetime = setTimeout("showvote()",1);
	} else {
		clearTimeout(showvotetime);
		votearea.className = 'open';
	}
}
function hidevote() {
	clearTimeout(showvotetime);
	var votearea = document.getElementById('vote');
	var vh = votearea.style.height;
	var vhLen = vh.length-2;
	var vhNum = parseInt(vh.substring(0,vhLen));
	//alert (vhNum);
	if (vhNum>80) {
		votearea.style.height = (vhNum-60)+'px';
		hidevotetime = setTimeout("hidevote()",1);
	} else {
		votearea.className = '';
		clearTimeout(hidevotetime);
	}
}


//改变字体大小
function doZoom(size){
	document.getElementById('articlebody').style.fontSize=size+'px';
}


function doPrint(){
	var csslink = document.getElementsByTagName('link');
	for (i=0; i<csslink.length; i++) {
		if (csslink[i].rel=='stylesheet') {
			csslink[i].disabled=true;
		}
	}

	printCSS = document.createElement("link");
	printCSS.id = 'printcss';
	printCSS.type = 'text/css';
	printCSS.rel = 'stylesheet';
	printCSS.href = siteUrl+'/css/print.css';
	
	var docHead = document.getElementsByTagName('head')[0];
	var mainCSS = csslink[0];
	docHead.insertBefore(printCSS,mainCSS);
	
	var articlectrl = document.getElementById('articlectrl');
	articlectrl.innerHTML = "<a href='javascript:;' onclick='cancelPrint();'>返回</a>&nbsp;&nbsp;<a href='javascript:;' onclick='window.print();'>打印</a>";
	
	window.print();
}
function cancelPrint() {
	if (printCSS) {
		document.getElementsByTagName('head')[0].removeChild(printCSS);
	}
	
	var csslink = document.getElementsByTagName('link');
	for (i=0; i<csslink.length; i++) {
		if (csslink[i].rel=='stylesheet') {
			csslink[i].disabled=false;
		}
	}

	var articlectrl = document.getElementById('articlectrl');
	articlectrl.innerHTML = "字体:&nbsp;<a href='javascript:;' onclick='doZoom(12);'>小</a>&nbsp;<a href='javascript:;' onclick='doZoom(14);'>中</a>&nbsp;<a href='javascript:;' onclick='doZoom(16);'>大</a>&nbsp;<a href='javascript:;' onclick='doPrint();' class='btnprint'>打印</a>";
	
}

function adclick(id) {
	var url = siteUrl + "/batch.common.php?action=adclick&id=" + id;
	var pf = document.getElementById("phpframe");
	if(pf) pf.src = url;
}
