
//Pop-it menu- By Dynamic Drive - Modified by Wbird
//For full source code and more DHTML scripts, visit http://www.dynamicdrive.com
//This credit MUST stay intact for use
var menuOffX=0	//菜单距连接文字最左端距离
var menuOffY=18	//菜单距连接文字顶端距离
var vBobjects = new Array();
var fo_shadows=new Array();
var linkset=new Array();
var boardid=0;
////No need to edit beyond here
var ie4=document.all&&navigator.userAgent.indexOf("Opera")==-1
var ns6=document.getElementById&&!document.all
var ns4=document.layers

/* *********** Common Utility Scripts ***********
 * create: 2007-12-26 by 小点
 * lastupdate: 2007-12-26 by 小点
 * all right reserved 2007 dvbbs.net
/* *********** Common Utility Scripts ***********/

// 显示tips提示
function tips(obj,str,w,target)
{
	if(null == target){target = "tips";}
	if(null == w){w = 120;}

	var l = getOffsetLeft(obj) + w;
	var t = getOffsetTop(obj);	
	
	$(target).innerHTML = "提示：" + str;
	$(target).style.left = l + "px";
	$(target).style.top = t + "px";
	$(target).style.display="";
}
// 隐藏tips提示
function outtips(){
   $("tips").style.display='none';
}

// 展开关闭事件
function divdisplay(obj){
	if (obj){
		obj.style.display = (obj.style.display=="none") ? "block":"none";
	}
}

// 根据鼠标或焦点事件，设置文本框和按钮样式,此函数会与样式相关
function IEvent(sType,oInput)
{
	var onStyle,offStyle,eleType;
	eleType = oInput.type;
	// 设置关联样式
	if("button" == eleType || "submit" == eleType || "reset" == eleType || "textarea" == oInput.tagName)
	{
		onStyle = "button_on";
		offStyle = "button_off";
	}
	else
	{
		onStyle = "input_on";
		offStyle = "input_off";
	}
	// 根据事件选择样式
	switch (sType)
	{
		case "focus" :
			oInput.isfocus = true;
		case "mouseover" :
			oInput.className = onStyle;
			break;
		case "blur" :
			oInput.isfocus = false;
		case "mouseout" :
			if(!oInput.isfocus)
			{
				oInput.className = offStyle;
			}
			break;
	}
}

// 根据ID获取页面元素
function $(id)
{	
	return document.getElementById(id);
}
//单选表单选取 Obj 表单名，VAL所选的值
function chkradio(Obj,Val)
{
	if (Obj)
	{
	for (i=0;i<Obj.length;i++){
		if (Obj[i].value==Val){
		Obj[i].checked=true;
		break;
		}
	}
	}
}
/* 字符检测 */
function isInteger(str)
{  
	var regu = /^[-]{0,1}[0-9]{1,}$/;
	return regu.test(str);
}
function trim(str)
{
	return str.replace(/(^[\s　]*)|([\s　]*$)/g, '');
}
String.prototype.trim = function()
{
	return this.replace(/(^[\s　]*)|([\s　]*$)/g, '');
}

///图像不存在 时指定默认图像。
///防止默认图像也不存在时造成内存溢出。
function ImageOnError(imgobj,reurl)
{
   if(typeof(imgobj.getAttribute('FirstErr',1))==='undefined' || imgobj.getAttribute('FirstErr',1)==null)
   {
      imgobj.setAttribute('FirstErr','NotFirst',1);
      imgobj.src=reurl;
   }
   else
   {
     return ;
   }
}
function imgresize(o){
	var parentNode=o.parentNode;
	if (parentNode){
		if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
		}else{
		var parentNode=o.parentNode
		if (parentNode){
			if (o.offsetWidth>=parentNode.offsetWidth) o.style.width='98%';
			}
		}
}
function resizeimage(img)    
{
	var w=img.width,h=img.height; 
	var maxHeight=760,maxWidth=760;
	if (h>maxHeight)    
	{    
		img.height=maxHeight;    
		img.width=(maxHeight/h)*w;    
		w=img.width;   
		h=img.height;   
	}    
	if (w>maxWidth)    
	{    
		img.width=maxWidth;    
		img.height=(maxWidth/w)*h;    
	}    
}   


function Html2Txt(htmlText) 
{ 
    str = htmlText.replace(/\r\n/g, " "); 
    str = str.replace(/\r/g, " ");  
    str = str.replace(/\n/g, " ");  
    str = str.replace(/\t/g, ""); 
    str = str.replace(/<BR>/gi,"\r\n"); 
    str = str.replace(/<[^>]+?>/g,""); 
    str = str.replace(/&nbsp;/g, " "); 
    str = str.replace(/&gt;/g, ">"); 
    str = str.replace(/&lt;/g, "<"); 
    str = str.replace(/&amp;/g, "&"); 
    return str; 
}
//复制数据到剪切板	
var copytoclip=1;
function copyToClipboard(theField,isalert) {
	var tempval=$(theField);	
	if (navigator.appVersion.match(/\bMSIE\b/)){
		tempval.select();
		if (copytoclip==1){
			therange=tempval.createTextRange();
			therange.execCommand("Copy");
			if(isalert!=false)alert("复制成功。现在您可以粘贴（Ctrl+v）到Blog 或 BBS中了。");
		}
		return;
	}else{
		alert("您使用的浏览器不支持此复制功能，请使用Ctrl+C或鼠标右键。");
		tempval.select();
	}
}
//新窗口
function openScript(url, width, height){
	var Win = window.open(url,"openScript",'width=' + width + ',height=' + height + ',resizable=1,scrollbars=yes,menubar=no,status=no' );
}

// 获取元素距窗口顶部的像素值
function getOffsetTop(elm) {
	var mOffsetTop = elm.offsetTop;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent){
		mOffsetTop += mOffsetParent.offsetTop;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetTop;
}

//获取元素距窗口左部的像素值
function getOffsetLeft(elm) {
	var mOffsetLeft = elm.offsetLeft;
	var mOffsetParent = elm.offsetParent;
	while(mOffsetParent) {
		mOffsetLeft += mOffsetParent.offsetLeft;
		mOffsetParent = mOffsetParent.offsetParent;
	}
	return mOffsetLeft;
}
//Board Jump
function boardJump(obj,url)
{
	var selectedValue = obj.options[obj.selectedIndex].value;
	if (selectedValue.indexOf(',') != -1 || selectedValue == -1)
	{
		obj.options[0].selected = true;
		return;
	}
	location.href = url + 'board.aspx?boardid=' + selectedValue;
}
function fetch_object(idname, forcefetch)
{
	if (typeof(vBobjects[idname]) == "undefined")
	{
		vBobjects[idname] = MM_findObj(idname);
	}
	return vBobjects[idname];
}
//showmenu vmenu:内容，允许为空,vmenuobj DIV数据ID，MOD 0=关闭浏览器自适应，用于版面导航菜单
function showmenu(e,vmenu,vmenuobj,mod){
	if (!document.all&&!document.getElementById&&!document.layers)
		return
	var which=vmenu;
	
	if (vmenuobj)
	{
		var MenuObj = fetch_object(vmenuobj);
		if (MenuObj)
		{
			which = MenuObj.innerHTML;
		}
	}
	if (!which)
	{
		return
	}
	clearhidemenu();
	ie_clearshadow();
	menuobj=ie4? document.all.popmenu : ns6? document.getElementById("popmenu") : ns4? document.popmenu : ""
	//menuobj=(ie4 || ns6) ? document.getElementById("popmenu") : ns4? document.popmenu : ""
	menuobj.thestyle=(ie4||ns6)? menuobj.style : menuobj
	if (ie4||ns6)
		menuobj.innerHTML=which
	else{
		menuobj.document.write('<layer name=gui bgcolor="#E6E6E6" width="165" onmouseover="clearhidemenu()" onmouseout="hidemenu()">'+which+'</layer>')
		menuobj.document.close()
	}
	menuobj.contentwidth=(ie4||ns6)? menuobj.offsetWidth : menuobj.document.gui.document.width
	menuobj.contentheight=(ie4||ns6)? menuobj.offsetHeight : menuobj.document.gui.document.height
	eventX=ie4? event.clientX : ns6? e.clientX : e.x
	eventY=ie4? event.clientY : ns6? e.clientY : e.y
	var rightedge=ie4? document.body.clientWidth-eventX : window.innerWidth-eventX
	var bottomedge=ie4? document.body.clientHeight-eventY : window.innerHeight-eventY
	var getlength
		if (rightedge<menuobj.contentwidth){
			getlength=ie4? document.body.scrollLeft+eventX-menuobj.contentwidth+menuOffX : ns6? window.pageXOffset+eventX-menuobj.contentwidth : eventX-menuobj.contentwidth
		}else{
			getlength=ie4? ie_x(event.srcElement)+menuOffX : ns6? window.pageXOffset+eventX : eventX
		}
		menuobj.thestyle.left=getlength+'px'
		if (bottomedge<menuobj.contentheight&&mod!=0){
			getlength=ie4? document.body.scrollTop+eventY-menuobj.contentheight-event.offsetY+menuOffY-23 : ns6? window.pageYOffset+eventY-menuobj.contentheight-10 : eventY-menuobj.contentheight
		}	else{
			getlength=ie4? ie_y(event.srcElement)+menuOffY : ns6? window.pageYOffset+eventY+10 : eventY
		}
	menuobj.thestyle.top=getlength+'px'
	menuobj.thestyle.visibility="visible"
	ie_dropshadow(menuobj,"#999999",3)
	return false
}

function ie_y(e){  
	var t=e.offsetTop;  
	while(e=e.offsetParent){  
		t+=e.offsetTop;  
	}  
	return t;  
}  
function ie_x(e){  
	var l=e.offsetLeft;  
	while(e=e.offsetParent){  
		l+=e.offsetLeft;  
	}  
	return l;  
}  
function ie_dropshadow(el, color, size)
{
	var i;
	for (i=size; i>0; i--)
	{
		var rect = document.createElement('div');
		var rs = rect.style
		rs.position = 'absolute';
		rs.left = (el.style.posLeft + i) + 'px';
		rs.top = (el.style.posTop + i) + 'px';
		rs.width = el.offsetWidth + 'px';
		rs.height = el.offsetHeight + 'px';
		rs.zIndex = el.style.zIndex - i;
		rs.backgroundColor = color;
		var opacity = 1 - i / (i + 1);
		rs.filter = 'alpha(opacity=' + (100 * opacity) + ')';
		//el.insertAdjacentElement('afterEnd', rect);
		fo_shadows[fo_shadows.length] = rect;
	}
}
function ie_clearshadow()
{
	for(var i=0;i<fo_shadows.length;i++)
	{
		if (fo_shadows[i])
			fo_shadows[i].style.display="none"
	}
	fo_shadows=new Array();
}


function contains_ns6(a, b) {
	while (b.parentNode)
		if ((b = b.parentNode) == a)
			return true;
	return false;
}

function hidemenu(){
	if (window.menuobj && window.menuobj.thestyle)
		window.menuobj.thestyle.visibility=(ie4||ns6)? "hidden" : "hide"
	ie_clearshadow()
}

function dynamichide(e){
	if (ie4&&!menuobj.contains(e.toElement))
		hidemenu()
	else if (ns6&&e.currentTarget!= e.relatedTarget&& !contains_ns6(e.currentTarget, e.relatedTarget))
		hidemenu()
}

function delayhidemenu(){
	if (ie4||ns6||ns4)
		delayhide=setTimeout("hidemenu()",500)
}

function clearhidemenu(){
	if (window.delayhide)
		clearTimeout(delayhide)
}

function highlightmenu(e,state){
	if (document.all)
		source_el=event.srcElement
	else if (document.getElementById)
		source_el=e.target
	if (source_el.className=="menuitems"){
		source_el.id=(state=="on")? "mouseoverstyle" : ""
	}
	else{
		while(source_el.id!="popmenu"){
			source_el=document.getElementById? source_el.parentNode : source_el.parentElement
			if (source_el.className=="menuitems"){
				source_el.id=(state=="on")? "mouseoverstyle" : ""
			}
		}
	}
}

if (ie4||ns6)
document.onclick=hidemenu
function doSClick() {
	var targetId, srcElement, targetElement, imageId, imageElement;
	srcElement = window.event.srcElement;
	targetId = srcElement.id + "content";
	targetElement = document.all(targetId);
	imageId = srcElement.id;
	imageId = imageId.charAt(0);
	imageElement = document.all(imageId);
	if (targetElement.style.display == "none") {
		imageElement.src = "Skins/Default/minus.gif"
		targetElement.style.display = "";
	} else {
		imageElement.src = "Skins/Default/plus.gif"
		targetElement.style.display = "none";
	}
}
function doClick() {
	var targetId, srcElement, targetElement;
	srcElement = window.event.srcElement;
	targetId = srcElement.id + "_content";
	targetElement = document.all(targetId);
	if (targetElement.style.display == "none") {
		srcElement.src = "Skins/Default/minus.gif"
		targetElement.style.display = "";
	} else {
		srcElement.src = "Skins/Default/plus.gif"
		targetElement.style.display = "none";
	}
}


function New_BoardJumpList(destBoardId, boardList)
{
	if (destBoardId < 0 || !boardList)
	{
		return '';
	}
	
	var dest_list = {};
	if (0 == destBoardId)
	{
		dest_list = boardList;
	}
	else
	{
		for (var boardid in boardList)
		{
			if (!boardList[boardid])
			{
				continue;
			}
			if (destBoardId == boardList[boardid].ParentId)
			{
				dest_list['' + boardid] = boardList[boardid];
			}
		}
	}
	if (!dest_list)
	{
		return '';
	}
	
	var retvl = '';
	for (var boardid in dest_list)
	{
		if (0 == boardid || !dest_list[boardid])
		{
			continue;
		}
		if (0 == dest_list[boardid].Depth)
		{
			retvl += '╋<a href="' + dest_list[boardid].urlpath + '" style="padding-left: 1px;">' + dest_list[boardid].BoardType + '</a><br />';
		}
		else
		{
			var repeat_str = RepeatString('&nbsp;', 2);
			retvl += repeat_str + '├<a href="'+ dest_list[boardid].urlpath +'" style="padding-left: 1px;" >' + dest_list[boardid].BoardType + '</a>' + repeat_str + '<br />';
		}
	}
	if ('' !== retvl)
	{
		retvl = '<div class="menuitems">' + retvl + '</div>';
	}
	return retvl;
}

function RepeatString(str, repeatCount)
{
	if (typeof(str) != 'string')
	{
		return '';
	}
	if (typeof(repeatCount) != 'number' || repeatCount <= 0)
	{
		return '';
	}
	var retvl = str;
	for (var i = 0; i < repeatCount; i++)
	{
		retvl += retvl;
	}
	return retvl;
}


function setCookie(name,value)
{
	var Days = 30; //此 cookie 将被保存 30 天
	var exp = new Date(); //new Date("December 31, 9998");
	exp.setTime(exp.getTime() + Days*24*60*60*1000);
	document.cookie = name + "="+ escape(value) +";expires="+ exp.toGMTString();
}
function getCookie(name)
{
	var arr = document.cookie.match(new RegExp("(^| )"+name+"=([^;]*)(;|$)"));
	if(arr != null) return unescape(arr[2]); return null;
}
//Collapse Or Expand Tablebody
function collapse(img, objName)
{
	
	var cateid = objName.replace("cate","");
	var cateids= getCookie("closedcateids");
	if(cateids == null)
		cateids = "";
//	alert(cateids);
	//specially, invoke another function. (topic.aspx)
	if (objName == 'loopedreplies')
	{
		collapseTables(img);
		return;
	}

	var obj = document.getElementById(objName);
	if (!obj){return;}
	if (obj.style.display!='none'){
		obj.style.display = 'none';
		img.src = img.src.replace('open', 'close');
		//write cate id to cookie 
		setCookie("closedcateids",cateids.replace("[" + cateid + "]", "") + "[" + cateid + "]");
	}
	else{
		obj.style.display = 'block';
		img.src = img.src.replace('close', 'open');
		setCookie("closedcateids",cateids.replace("[" + cateid + "]", ""));
	}
}

function contract(o,target,str1,str2)
{
	var obj = document.getElementById(target);
	if (!obj){return;}
	if (obj.style.display!='none'){
		obj.style.display = 'none';
		o.innerText = (str2!=null ? str2 : "展开");
	}
	else{
		obj.style.display = 'block';
		o.innerText = (str1!=null ? str1 : "隐藏")
	}
}

//Byte Counter
function len(str)
{
	var bytes = 0;
	for(i=0; i<str.length; i++)
	{
		ascii = str.charCodeAt(i);
		bytes += (ascii < 255 ? 1 : 2);
	}
	return bytes;
}

function addTitleHead(obj, tovalue){	//modified by caoxin03 2007 0816
	var x = eval('obj.form.' + tovalue);
	if (obj.options.selectedIndex > 0 && x.value.length < 46 && len(x.value) < 64)
	{
		x.value = obj.options[obj.options.selectedIndex].text + x.value;
		obj.options.selectedIndex = 0;
	}
}

function PostShowTime(stat){
	if(1 == stat){
		document.getElementById("uncertainstarttime").style.display = 'block';
		document.getElementById("certainstarttime").style.display = 'none';
	}else{
		document.getElementById("uncertainstarttime").style.display = 'none';
		document.getElementById("certainstarttime").style.display = 'block';
	}
}


function onpagekeydown()
{
	if (window.event)
	{
		if(window.event.keyCode == 13)
		{
			//ongoto();
			//直接用ongoto()时，在线列表分页的文本框中输入页数后回车会在新窗口中打开
			var page = document.getElementById("gotopage").value;
	if (isNaN(page))
	{
		page = "1";
	}
	if(originUrl=='undefined'||originUrl==null||originUrl=='')originUrl = document.getElementById("originUrl").value;

	if(arguments.length==1&&arguments[0]!='_self'&&arguments[0]!='_target'&&arguments[0]!='_parent'&&arguments[0]!='_top')
	{
		var w = eval(arguments[0]);
		w.location.href = setPage(originUrl, page);
	}else 
	{
		location.href = setPage(originUrl, page);
	}
			event.returnValue = false;
		}
	}
}
var originUrl
//Pager
function setPage(s, i)
{
	return s.replace('{p}', i.toString());
}
function pager(url, page, maxPage, total, per, countsIsVisible)
{
	originUrl = url;
	var first		= "<font style='font-size:12px'>首页</font>";
	var previous	= "<font style='font-size:12px'>上一页</font>";
	var next		= "<font style='font-size:12px'>下一页</font>";
	var last		= "<font style='font-size:12px'>尾页</font>";

	var s = "<div class='pager-block' style='width:100%;text-align:right'><div class='pager-links' style='float:left; text-align:left; font-family:courier new,sans-serif'>";
	if (page == 1)
	{
		s += (first + " " + previous + " <b>");
	}
	else
	{
		if (first != "") s += ("<a href='" + setPage(url, 1) + "'>" + first + "</a> ");
		s += ("<a href='" + setPage(url, (page-1)) + "'>" + previous + "</a> <b>");
	}

	var j = (page-5 < 1) ? 1 : page-5;
	var k = (page+5 > maxPage) ? maxPage : page+5;

	if (j > 1) s += " <a href='" + setPage(url, 1) + "'>1</a> ... ";
	for (var i=j; i<k+1; i++)
	{
		if (page == i)
		{
			s += ("<span class='t2'>" + i + "</span> ");
			continue;
		}
		s += ("<a href='" + setPage(url, i) + "'>" + i + "</a> ");
	}
	if (maxPage > k) s += " ... <a href='" + setPage(url, maxPage) + "'>" + maxPage + "</a> ";
	if (page == maxPage)
	{
		s += ("</b>" + next + " " + last);
	}
	else
	{
		s += ("</b><a href='" + setPage(url, page+1) + "'>" + next + "</a> ");
		if (last != "") s += ("<a href='" + setPage(url, maxPage) + "'>" + last + "</a>");
	}
	s += " 转到 <input type='text' name='gotopage' value='" + page + "' size='3' onkeydown='onpagekeydown();'/> <input type='button' value='Go' style='height:19px;' onclick='ongoto()' />";
	s += ("</div>");
	
	if (countsIsVisible)
	{
		s += ("<div class='pager-stat' style='float:lift;'>");
		s += ("总记录:<span class='t2'>" + total + "</span>　");
		s += ("每页:<span class='t2'>" + per + "</span>　");
		s += ("总页数:<span class='t2'>" + maxPage + "</span></div>");
	}
	s += "</div>";

	return s;
}
function ongoto()
{
	var page = document.getElementById("gotopage").value;
	if (isNaN(page))
	{
		page = "1";
	}
	if(originUrl=='undefined'||originUrl==null||originUrl=='')originUrl = document.getElementById("originUrl").value;

	if(arguments.length==1&&arguments[0]!='_self'&&arguments[0]!='_target'&&arguments[0]!='_parent'&&arguments[0]!='_top')
	{
		var w = eval(arguments[0]);
		w.location.href = setPage(originUrl, page);
	}else 
	{
		location.href = setPage(originUrl, page);
	}
}

//Submit Once
function submitonce(f)
{
	if (document.all || document.getElementById)
	{
		for (i=0; i<f.elements.length; i++)
		{
			var ctl = f.elements[i];
			var ctlType = ctl.type.toLowerCase();
			if (ctlType == 'submit' || ctlType == 'button' || ctlType == 'reset')
			{
				ctl.disabled = true;
			}
		}
	}
}
function checktrade(){
	if($(tratuser).length<=0)
	{
		alert('收货人不能为空。');
		return false;
	 }
	return true;
}

function AddFrend(url,para) 
{ 
	var dvajax = new DvAjax();

		dvajax.Request("get",url,para,function(xmlhttp)
		{
			try
			{	
				alert(xmlhttp.responseText);
			}
			finally
			{
				xmlhttp.abort();
			} 
				
		},true);
   
}