/*****************************************************************
 *                                                               *
 *  [SalasBBS]                                                   * 
 *  $Revision: 1.84.2.1 $                                        *
 *                                                               *
 ****************************************************************/

// define a few variables that are required
var vbmenu_usepopups = false;
var ignorequotechars = 0;

// #############################################################################
// lets define the browser we have instead of multiple calls throughout the file
var userAgent = navigator.userAgent.toLowerCase();
var is_opera  = (userAgent.indexOf('opera') != -1);
var is_saf    = ((userAgent.indexOf('applewebkit') != -1) || (navigator.vendor == "Apple Computer, Inc."));
var is_webtv  = (userAgent.indexOf('webtv') != -1);
var is_ie     = ((userAgent.indexOf('msie') != -1) && (!is_opera) && (!is_saf) && (!is_webtv));
var is_ie4    = ((is_ie) && (userAgent.indexOf("msie 4.") != -1));
var is_moz    = ((navigator.product == 'Gecko') && (!is_saf));
var is_kon    = (userAgent.indexOf('konqueror') != -1);
var is_ns     = ((userAgent.indexOf('compatible') == -1) && (userAgent.indexOf('mozilla') != -1) && (!is_opera) && (!is_webtv) && (!is_saf));
var is_ns4    = ((is_ns) && (parseInt(navigator.appVersion) == 4));


// catch possible bugs with WebTV and other older browsers
var is_regexp = (window.RegExp) ? true : false;

// #############################################################################
// let's find out what DOM functions we can use
var vbDOMtype = '';
if (document.getElementById)
{
	vbDOMtype = "std";
}
else if (document.all)
{
	vbDOMtype = "ie4";
}
else if (document.layers)
{
	vbDOMtype = "ns4";
}

// make an array to store cached locations of objects called by fetch_object
var vBobjects = new Array();

// #############################################################################
// function to emulate document.getElementById


//###########################################################################
// Check if is logined
var loginStr = "";
var prefix = "gxnewspassport_";
var passport_username = GetCookie(prefix + "username");
var passport_userid = fetch_cookie(prefix + "userid");
var passport_money = fetch_cookie(prefix + "money");
var passport_wordhash = fetch_cookie(prefix + "wordhash");
var sso_auth = fetch_cookie("sso_auth");

//alert(passport_username);
var passport_pms = fetch_cookie(prefix + "pms");
var passport_pm = new Array();
if(passport_pms != null && passport_pms != ''){
	passport_pm = passport_pms.split("|");
}
var msgimg = '';
if(passport_pm[0]>0) msgimg = '&nbsp;<img src="/images/message.gif" border=0 /> ';
if(passport_username != null && passport_username != '' && passport_userid != null && passport_userid != ''){
	loginStr = msgimg+"&nbsp;<a target=_parent href=/private.php>"+passport_pm[0]+" 条新消息</a> &nbsp;<strong>欢迎您，"+passport_username+"</strong>&nbsp;现在绿豆"+passport_money+"颗&nbsp;<a id=\"myctrl\" onMouseOver=\"showMenu(this.id)\" target=_parent href=/usercp.php>[控制面板]</a> <a target=_parent href=/banlist.php>[思过崖]</a> <a href=/login.php?do=logout&u="+passport_userid+">[退出]</a>";
}else{
	loginStr = "<!-- login form --><table width=100% border=0  cellpadding=0 cellspacing=0><tr><td width=390>&nbsp;用户名 <input class='myinput' type='text' name='vb_login_username' id='navbar_username' size='15' accesskey='u' tabindex='1' value=''  >&nbsp;密码  <input class='myinput' type='password' name='vb_login_password' size='15' accesskey='p' tabindex='2' ><label for='cb_cookieuser_navbar'><input type='checkbox' name='cookieuser' value='1' tabindex='3' id='cb_cookieuser_navbar' accesskey='c'  >记住我? &nbsp;</label> <input type=hidden name=theurl value=></td><td width=120 valign=bottom> <input  type='image' src='/images/login_button.gif' tabindex='4'  accesskey='s'>&nbsp;<a href=/register.php><img src='/images/reg_button.gif' border=0 /></a></td><td valign=bottom>忘记密码？</td><input type='hidden' name='s' value='sessionhash'><input type='hidden' name='do' value='login'><input type='hidden' name='forceredirect' value='1'><input type='hidden' name='vb_login_md5password'></tr></table><!-- end login form -->";
}


function fetch_object(idname, forcefetch)
{
	if (forcefetch || typeof(vBobjects[idname]) == "undefined")
	{
		switch (vbDOMtype)
		{
			case "std":
			{
				vBobjects[idname] = document.getElementById(idname);
			}
			break;

			case "ie4":
			{
				vBobjects[idname] = document.all[idname];
			}
			break;

			case "ns4":
			{
				vBobjects[idname] = document.layers[idname];
			}
			break;
		}
	}
	return vBobjects[idname];
}

// #############################################################################
// function to handle the different event models of different browsers
// and prevent event bubbling
function do_an_e(eventobj)
{
	if (!eventobj || is_ie)
	{
		window.event.returnValue = false;
		window.event.cancelBubble = true;
		return window.event;
	}
	else
	{
		eventobj.stopPropagation();
		eventobj.preventDefault();
		return eventobj;
	}
}

// #############################################################################
// function to open a generic window
function openWindow(url, width, height)
{
	var dimensions = "";
	if (width)
	{
		dimensions += ",width=" + width;
	}
	if (height)
	{
		dimensions += ",height=" + height;
	}
	window.open(url, "vBPopup", "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes" + dimensions);
	return false;
}

// #############################################################################
// function to open an IM Window
function imwindow(imtype, userid, width, height)
{
	return openWindow("sendmessage.php?" + SESSIONURL + "do=im&type=" + imtype + "&userid=" + userid, width, height);
}

// newvbb 修改开始
// #############################################################################
function buyerswindow(postid, width, height)
{
	return openWindow("buypost.php?" + SESSIONURL + "do=viewbuyers&p=" + postid, width, height);
}
// newvbb 修改结束

// #############################################################################
// function to show list of posters in a thread
function who(threadid)
{
	return openWindow("misc.php?" + SESSIONURL + "do=whoposted&threadid=" + threadid, 230, 300);
}

// #############################################################################
// function to open the reputation window
function reputation(postid)
{
	window.open("reputation.php?" + SESSIONURL + "p=" + postid, "Reputation", "toolbar=no, scrollbars=yes, resizable=yes, width=400, height=241");
	return false;
}

// #############################################################################
function manageattachments(url, width, height, hash)
{
	window.open(url, "Attach" + hash, "statusbar=no,menubar=no,toolbar=no,scrollbars=yes,resizable=yes,width=" + width + ",height=" + height);
	return false;
}

// #############################################################################
// function to do a single-line conditional
function iif(condition, trueval, falseval)
{
	return condition ? trueval : falseval;
}

// #############################################################################
// function to search an array for a value
function in_array(ineedle, haystack, caseinsensitive)
{
	var needle = new String(ineedle);

	if (caseinsensitive)
	{
		needle = needle.toLowerCase();
		for (i in haystack)
		{
			if (haystack[i].toLowerCase() == needle)
			{
				return i;
			}
		}
	}
	else
	{
		for (i in haystack)
		{
			if (haystack[i] == needle)
			{
				return i;
			}
		}
	}
	return -1;
}

function js_toggle_all(formobj, formtype, option, exclude, setto)
{
	for (var i =0; i < formobj.elements.length; i++)
	{
		var elm = formobj.elements[i];
		if (elm.type == formtype && in_array(elm.name, exclude, false) == -1)
		{
			switch (formtype)
			{
				case "radio":
					if (elm.value == option) // option == '' evaluates true when option = 0
					{
						elm.checked = setto;
					}
				break;
				case "select-one":
					elm.selectedIndex = setto;
				break;
				default:
					elm.checked = setto;
				break;
			}
		}
	}
}

function js_select_all(formobj)
{
	exclude = new Array();
	exclude[0] = "selectall";
	js_toggle_all(formobj, "select-one", '', exclude, formobj.selectall.selectedIndex);
}

function js_check_all(formobj)
{
	exclude = new Array();
	exclude[0] = "keepattachments";
	exclude[1] = "allbox";
	exclude[2] = "removeall";
	js_toggle_all(formobj, "checkbox", '', exclude, formobj.allbox.checked);
}

function js_check_all_option(formobj, option)
{
	exclude = new Array();
	exclude[0] = "useusergroup";
	js_toggle_all(formobj, "radio", option, exclude, true);
}

function checkall(formobj) // just an alias
{
	js_check_all(formobj);
}
function checkall_option(formobj, option) // just an alias
{
	js_check_all_option(formobj, option);
}

// #############################################################################
// function to check message length before form submission
function validatemessage(messageText, subjectText, minLength, maxLength, ishtml, tForm)
{
	// bypass Safari and Konqueror browsers with Javascript problems
	if (is_kon || is_saf || is_webtv)
	{
		return true;
	}
	
	
	// attempt to get a code-stripped version of the text
	var strippedMessage = stripcode(messageText, ishtml, ignorequotechars);
	
    var stripdTitle = subjectText;
	// check for completed subject
	if (subjectText.length < 1)
	{   
		alert(vbphrase["must_enter_subject"]);
		return false;
	}
	if (stripdTitle.length < 5)
	{
		alert("标题太短，必须4个字以上!");
		return false;
	}

	if (stripdTitle.length > 80)
	{
		alert("标题太长!");
		return false;
	}
	// check for minimum message length
	else if (strippedMessage.length < minLength)
	{
		//alert(construct_phrase(vbphrase["message_too_short"], minLength));
		//return false;
		//Don't check this again . foxmx modified 2009-9-13
		return true;
	}
	// everything seems okay
	else
	{
		return true;
	}
}

// #############################################################################
// function to trim quotes and vbcode tags
function stripcode(str, ishtml, stripquotes)
{
	if (!is_regexp)
	{
		return str;
	}

	if (stripquotes)
	{
		var quote1 = new RegExp("(\\[QUOTE\\])(.*)(\\[\\/QUOTE\\])", "gi");
		var quote2 = new RegExp("(\\[QUOTE=(&quot;|\"|\\'|)(.*)\\1\\])(.*)(\\[\\/QUOTE\\])", "gi");

		while(str.match(quote1))
		{
			str = str.replace(quote1, '');
		}

		while(str.match(quote2))
		{
			str = str.replace(quote2, '');
		}
	}

	if (ishtml)
	{
		var html1 = new RegExp("<(\\w+)[^>]*>", "gi");
		var html2 = new RegExp("<\\/\\w+>", "gi");

		str = str.replace(html1, '');
		str = str.replace(html2, '');

		var html3 = new RegExp("&nbsp;");
		str = str.replace(html3, '');
	}
	else
	{
		var bbcode1 = new RegExp("\\[(\\w+)[^\\]]*\\]", "gi");
		var bbcode2 = new RegExp("\\[\\/(\\w+)\\]", "gi");

		str = str.replace(bbcode1, '');
		str = str.replace(bbcode2, '');
	}
	return str;
}

// #############################################################################
// emulation of the PHP version of vBulletin's construct_phrase() sprintf wrapper
function construct_phrase()
{
	if (!arguments || arguments.length < 1 || !is_regexp)
	{
		return false;
	}

	var args = arguments;
	var str = args[0];
	var re;

	for (var i = 1; i < args.length; i++)
	{
		re = new RegExp("%" + i + "\\$s", "gi");
		str = str.replace(re, args[i]);
	}
	return str;
}

// #############################################################################
// set control panel frameset title
function set_cp_title()
{
	if (typeof(parent.document) != "undefined" && typeof(parent.document) != "unknown" && typeof(parent.document.title) == "string")
	{
		if (document.title != '')
		{
			parent.document.title = document.title;
		}
		else
		{
			parent.document.title = "vBulletin";
		}
	}
}

// #############################################################################
// open control panel help window
function js_open_help(scriptname, actiontype, optionval)
{
	window.open("/help.php?s=" + SESSIONHASH + "&do=answer&page=" + scriptname + "&pageaction=" + actiontype + "&option=" + optionval, "helpwindow", "toolbar=no,scrollbars=yes,resizable=yes,width=600,height=450");
}

// #############################################################################
function switch_styleid(selectobj)
{
	var styleid = selectobj.options[selectobj.selectedIndex].value;

	if (styleid == "")
	{
		return;
	}

	var url = new String(window.location);
	var fragment = new String("");

	// get rid of fragment
	url = url.split("#");

	// deal with the fragment first
	if (url[1])
	{
		fragment = "#" + url[1];
	}

	// deal with the main url
	url = url[0];

	// remove styleid=x& from main bit
	if (url.indexOf("styleid=") != -1 && is_regexp)
	{
		re = new RegExp("styleid=\\d+&?");
		url = url.replace(re, "");
	}

	// add the ? to the url if needed
	if (url.indexOf("?") == -1)
	{
		url += "?";
	}
	else
	{
		// make sure that we have a valid character to join our styleid bit
		lastchar = url.substr(url.length - 1);
		if (lastchar != "&" && lastchar != "?")
		{
			url += "&";
		}
	}
	window.location = url + "styleid=" + styleid + fragment;
}

// #############################################################################
// simple function to toggle the 'display' attribute of an object
function toggle_display(idname)
{
	obj = fetch_object(idname);
	if (obj)
	{
		if (obj.style.display == "none")
		{
			obj.style.display = "";
		}
		else
		{
			obj.style.display = "none";
		}
	}
	return false;
}

// #############################################################################
// ##################### vBulletin Cookie Functions ############################
// #############################################################################

// #############################################################################
// function to set a cookie
function set_cookie(name, value, expires)
{
	if (!expires)
	{
		expires = new Date();
	}
	document.cookie = name + "=" + escape(value) + "; expires=" + expires.toGMTString() +  "; path=/";
}

// #############################################################################
// function to retrieve a cookie
function fetch_cookie(name)
{
	cookie_name = name + "=";
	cookie_length = document.cookie.length;
	cookie_begin = 0;
	while (cookie_begin < cookie_length)
	{
		value_begin = cookie_begin + cookie_name.length;
		if (document.cookie.substring(cookie_begin, value_begin) == cookie_name)
		{
			var value_end = document.cookie.indexOf (";", value_begin);
			if (value_end == -1)
			{
				value_end = cookie_length;
			}
			return unescape(document.cookie.substring(value_begin, value_end));
		}
		cookie_begin = document.cookie.indexOf(" ", cookie_begin) + 1;
		if (cookie_begin == 0)
		{
			break;
		}
	}
	return null;
}

// #############################################################################
// function to delete a cookie
function delete_cookie(name)
{
	var expireNow = new Date();
	document.cookie = name + "=" + "; expires=Thu, 01-Jan-70 00:00:01 GMT" +  "; path=/";
}

// #############################################################################
// ##################  Collapse HTML Functions ########################
// #############################################################################

function hideQuickReply(tag){
	if (!is_regexp)
	{
		return false;
	}
	
	obj = fetch_object("collapseobj_quickreply" );	
	if(tag==0)
		obj.style.display = "none";
	else
		obj.style.display = "";
}


// #############################################################################
// function to toggle the collapse state of an object, and save to a cookie
function toggle_collapse(objid)
{
	if (!is_regexp)
	{
		return false;
	}
	
	obj = fetch_object("collapseobj_" + objid);	
	img = fetch_object("collapseimg_" + objid);
	cel = fetch_object("collapsecel_" + objid);
	
	if (!obj)
	{
		// nothing to collapse!
		if (img)
		{
			// hide the clicky image if there is one
			img.style.display = "none";
		}
		return false;
	}

	if (obj.style.display == "none")
	{
		obj.style.display = "";
		save_collapsed(objid, false);
		if (img)
		{
			img_re = new RegExp("_collapsed\\.gif$");
			img.src = img.src.replace(img_re, '.gif');
		}
		if (cel)
		{
			cel_re = new RegExp("^(thead|tcat)(_collapsed)$");
			cel.className = cel.className.replace(cel_re, '$1');
		}
	}
	else
	{
		obj.style.display = "none";
		save_collapsed(objid, true);
		if (img)
		{
			img_re = new RegExp("\\.gif$");
			img.src = img.src.replace(img_re, '_collapsed.gif');
		}
		if (cel)
		{
			cel_re = new RegExp("^(thead|tcat)$");
			cel.className = cel.className.replace(cel_re, '$1_collapsed');
		}
	}
	return false;
}

// #############################################################################
// update vbulletin_collapse cookie with collapse preferences
function save_collapsed(objid, addcollapsed)
{
	var collapsed = fetch_cookie("vbulletin_collapse");
	var tmp = new Array();

	if (collapsed != null)
	{
		collapsed = collapsed.split("\n");

		for (i in collapsed)
		{
			if (collapsed[i] != objid && collapsed[i] != "")
			{
				tmp[tmp.length] = collapsed[i];
			}
		}
	}

	if (addcollapsed)
	{
		tmp[tmp.length] = objid;
	}

	expires = new Date();
	expires.setTime(expires.getTime() + (1000 * 86400 * 365));
	set_cookie("vbulletin_collapse", tmp.join("\n"), expires);
}

// #############################################################################
// function to register a menu for later initialization
function vbmenu_register(controlid, nowrite, datefield)
{
	if (vbmenu_usepopups)
	{
		vbmenu_doregister(controlid, nowrite, datefield);
	}
}

// #############################################################################
// functions to handle active cells

// active cell mouse-over
function activecells_mouseover(e)
{
	this.className = this.swapclass;
	if (is_ie)
	{
		this.style.cursor = "hand";
	}
	else
	{
		this.style.cursor = "pointer";
	}
	return true;
}

// active cell mouse-out
function activecells_mouseout(e)
{
	this.className = this.origclass;
	this.style.cursor = "default";
	return true;
}

// active cell click
function activecells_click(e)
{
	this.className = this.origclass;
	var script = '';
	if (r = this.id.match(/^([a-z]{1})([0-9]+)$/))
	{
		switch (r[1])
		{
			case "u": // user
				script = "/member.php?" + SESSIONURL + "u=";
				break;
			
			case "f": // forum
				script = "/forumdisplay.php?" + SESSIONURL + "f=";
				break;
			
			case "t": // thread
				script = "/showthread.php?" + SESSIONURL + "t=";
				break;
			
			case "p": // post
				script = "/showthread.php?" + SESSIONURL + "p=";
				break;
			
			case "m": // private message
				script = "/private.php?" + SESSIONURL + "pmid=";
				break;
			
			default:
				return;
		}
		window.location = script + r[2];
	}
}

// newvbb 修改开始
// #############################################################################
function switch_gal_forumid(selectobj)
{
	forumid = selectobj.options[selectobj.selectedIndex].value;

	if (forumid == "")
	{
		return;
	}

	url = new String(window.location);
	fragment = new String("");

	// get rid of fragment
	url = url.split("#");

	// deal with the fragment first
	if (url[1])
	{
		fragment = "#" + url[1];
	}

	// deal with the main url
	url = url[0];

	// remove styleid=x& from main bit
	if (url.indexOf("forumid=") != -1 && is_regexp)
	{
		re = new RegExp("forumid=\\d+&?");
		url = url.replace(re, "");
	}

	// add the ? to the url if needed
	if (url.indexOf("?") == -1)
	{
		url += "?";
	}
	else
	{
		// make sure that we have a valid character to join our styleid bit
		lastchar = url.substr(url.length - 1);
		if (lastchar != "&" && lastchar != "?")
		{
			url += "&";
		}
	}
	window.location = url + "forumid=" + forumid + fragment;
}

// #############################################################################
function switch_gal_order(selectobj)
{
	order = selectobj.options[selectobj.selectedIndex].value;

	if (order == "")
	{
		return;
	}

	url = new String(window.location);
	fragment = new String("");

	// get rid of fragment
	url = url.split("#");

	// deal with the fragment first
	if (url[1])
	{
		fragment = "#" + url[1];
	}

	// deal with the main url
	url = url[0];

	// remove styleid=x& from main bit
	if (url.indexOf("order=") != -1 && is_regexp)
	{
		re = new RegExp("order=\\d+&?");
		url = url.replace(re, "");
	}

	// add the ? to the url if needed
	if (url.indexOf("?") == -1)
	{
		url += "?";
	}
	else
	{
		// make sure that we have a valid character to join our styleid bit
		lastchar = url.substr(url.length - 1);
		if (lastchar != "&" && lastchar != "?")
		{
			url += "&";
		}
	}
	window.location = url + "order=" + order + fragment;
}

function quick_manage_select( tid )
{
	saved = new Array();
	clean = new Array();
	add   = 1;
		
	tmp = document.qmthreads.selectedtids.value;
	
	saved = tmp.split(",");
	
	for( i = 0 ; i < saved.length; i++ )
	{
		if ( saved[i] != "" )
		{
			if ( saved[i] == tid )
			{
				 add = 0;
			}
			else
			{
				clean[clean.length] = saved[i];
			}
		}
	}
		
	if ( add )
	{
		clean[ clean.length ] = tid;
		eval("document.qm"+tid+".src=selectedimg");
	}
	else
	{
		eval(" document.qm"+tid+".src=unselectedimg");
	}
	
	newvalue = clean.join(',');
		
	newcount = getsize(clean);

	document.qmthreads.selectedtids.value = newvalue;	
	
	document.qmthreads.gobutton.value = gobuttontext + '(' + newcount + ')';
	
	return false;
}

function getsize(thearray)
{
	for (i = 0 ; i < thearray.length; i++ )
	{
		if ( (thearray[i] == "") || (thearray[i] == null) || (thearray == 'undefined') )
		{
			return i;
		}
	}
	
	return thearray.length;
}

function suredelete()
{
	if ( ! document.qmthreads.selectedtids.value )
	{
		return false;
	}
	
	tmp = document.qmthreads.qmact.options[document.qmthreads.qmact.selectedIndex].value;
	
	if (tmp == 'deletethread')
	{
		check = confirm( suredeletetext );
		
		if (check == true)
		{
			return true;
		}
		else
		{
			return false;
		}
	}
}
// newvbb 修改结束

// #############################################################################
// ############## Main vBulletin Javascript Initialization #####################
// #############################################################################

function SalasBBS_init()
{
	if (is_webtv)
	{
		return true;
	}
	var imgs = null;
	switch (vbDOMtype)
	{
		case "std": imgs = document.getElementsByTagName("img"); break;
		case "ie4": imgs = document.all.tags("img");             break;
		default:    imgs = false;                                break;
	}
	if (imgs)
	{
		// set 'title' tags for image elements
		for (var i = 0; i < imgs.length; i++)
		{
			if (!imgs[i].title && imgs[i].alt != "")
			{
				imgs[i].title = imgs[i].alt;
			}
		}
	}

	// init registered menus
	if (vbmenu_usepopups && vbmenu_registered.length > 0)
	{
		for (i in vbmenu_registered)
		{
			vbmenu_init(vbmenu_registered[i]);
		}

		// close all menus on mouse click
		document.onclick = vbmenu_close;
	}
	
	return true;
}

// #############################################################################
// function to initialize active cells
function activecells_init()
{
	// hide this functionality from browsers that break it
	if (is_webtv || is_opera)
	{
		return;
	}
	
	// init active alt color classes
	tds = document.getElementsByTagName("td");
	for (var i = 0; i < tds.length; i++)
	{
		switch (tds[i].className)
		{
			case "alt1Active":
			case "alt2Active":
			{
				tds[i].origclass = tds[i].className;
				tds[i].swapclass = iif(tds[i].className == "alt1Active", "alt2Active", "alt1Active");
				tds[i].onmouseover = activecells_mouseover;
				tds[i].onmouseout = activecells_mouseout;
				tds[i].onclick = activecells_click;
			}
			break;
		}
	}
}

//设置cookie
function SetCookie(sName, sValue)
{
  document.cookie = sName + "=" + escape(sValue) + ";path=/;";
}
function SetLongCookie(sName, sValue){
	//获取当前时间
	var date=new Date();
	var expireDays=10;
	//将date设置为10天以后的时间
	date.setTime(date.getTime()+expireDays*24*3600*1000);
	document.cookie = sName + "=" + escape(sValue) + ";path=/;expires="+date.toGMTString();
}
//设置关闭swf的cookie
function SetClose(){
	SetCookie('isCloseflash','1');
}
//取得cookie
function GetCookie(sName)
{
  // cookies are separated by semicolons
  var aCookie = document.cookie.split("; ");
  for (var i=0; i < aCookie.length; i++)
  {
    // a name/value pair (a crumb) is separated by an equal sign
    var aCrumb = aCookie[i].split("=");
    if (sName == aCrumb[0]) 
      return unescape(aCrumb[1]);
  }

  // a cookie with the requested name does not exist
  return null;
}

/*
	以下是弹出框的JS start
*/



function $(id) {
	return document.getElementById(id);
}

function doane(event) {
	e = event ? event : window.event;
	if(is_ie) {
		e.returnValue = false;
		e.cancelBubble = true;
	} else if(e) {
		e.stopPropagation();
		e.preventDefault();
	}
}

function isUndefined(variable) {
	return typeof variable == 'undefined' ? true : false;
}

var jsmenu = new Array();
var ctrlobjclassName;
jsmenu['active'] = new Array();
jsmenu['timer'] = new Array();
jsmenu['iframe'] = new Array();

function initCtrl(ctrlobj, click, duration, timeout, layer) {
	if(ctrlobj && !ctrlobj.initialized) {
		ctrlobj.initialized = true;
		ctrlobj.unselectable = true;

		ctrlobj.outfunc = typeof ctrlobj.onmouseout == 'function' ? ctrlobj.onmouseout : null;
		ctrlobj.onmouseout = function() {
			if(this.outfunc) this.outfunc();
			if(duration < 3) jsmenu['timer'][ctrlobj.id] = setTimeout('hideMenu(' + layer + ')', timeout);
		}

		ctrlobj.overfunc = typeof ctrlobj.onmouseover == 'function' ? ctrlobj.onmouseover : null;
		ctrlobj.onmouseover = function(e) {
			doane(e);
			if(this.overfunc) this.overfunc();
			if(click) {
				clearTimeout(jsmenu['timer'][this.id]);
			} else {
				for(var id in jsmenu['timer']) {
					if(jsmenu['timer'][id]) clearTimeout(jsmenu['timer'][id]);
				}
			}
		}
	}
}

function initMenu(ctrlid, menuobj, duration, timeout, layer, drag) {
	var doinit = 0;
	if(ctrlid.indexOf('pagemore')>=0){
		doinit = 1;
	}
	if((menuobj && !menuobj.initialized) || (doinit==1)) {
		menuobj.initialized = true;
		menuobj.ctrlkey = ctrlid;
		menuobj.onclick = ebygum;
		menuobj.style.position = 'absolute';
		if(duration < 3) {
			if(duration > 1) {
				menuobj.onmouseover = function() {
					clearTimeout(jsmenu['timer'][ctrlid]);
				}
			}
			if(duration != 1) {
				menuobj.onmouseout = function() {
					jsmenu['timer'][ctrlid] = setTimeout('hideMenu(' + layer + ')', timeout);
				}
			}
		}
		menuobj.style.zIndex = 50;
		if(is_ie) {
			menuobj.style.filter += "progid:DXImageTransform.Microsoft.shadow(direction=135,color=#CCCCCC,strength=2)";
		}
		if(drag) {
			menuobj.onmousedown = function(event) {try{menudrag(menuobj, event, 1);}catch(e){}};
			menuobj.onmousemove = function(event) {try{menudrag(menuobj, event, 2);}catch(e){}};
			menuobj.onmouseup = function(event) {try{menudrag(menuobj, event, 3);}catch(e){}};
		}
	}
}




function showMenu(ctrlid, click, offset, duration, timeout, layer, showid, maxh, drag) {
	var ctrlobj = $(ctrlid);
	if(!ctrlobj) return;
	//加上此句防止ie出错
	if(is_ie){
		if (document.readyState!="complete") return ;
	}
	
	if(isUndefined(click)) click = false;
	if(isUndefined(offset)) offset = 0;
	if(isUndefined(duration)) duration = 2;
	if(isUndefined(timeout)) timeout = 500;
	if(isUndefined(layer)) layer = 0;
	if(isUndefined(showid)) showid = ctrlid;
	var showobj = $(showid);
	var menuobj = $(showid + '_menu');
	if(showid.indexOf('pagemore')>=0){
		menuobj = $('pagemore_menu');
	}
	if(!showobj|| !menuobj) return;
	if(isUndefined(maxh)) maxh = 500;
	if(isUndefined(drag)) drag = false;

	if(click && jsmenu['active'][layer] == menuobj) {
		hideMenu(layer);
		return;
	} else {
		hideMenu(layer);
	}

	var len = jsmenu['timer'].length;
	if(len > 0) {
		for(var i=0; i<len; i++) {
			if(jsmenu['timer'][i]) clearTimeout(jsmenu['timer'][i]);
		}
	}

	initCtrl(ctrlobj, click, duration, timeout, layer);
	ctrlobjclassName = ctrlobj.className;
	ctrlobj.className += ' hover';
	initMenu(ctrlid, menuobj, duration, timeout, layer, drag);

	menuobj.style.display = '';
	if(!is_opera) {
		menuobj.style.clip = 'rect(auto, auto, auto, auto)';
	}

	setMenuPosition(showid, offset);

	if(is_ie && is_ie < 7) {
		if(!jsmenu['iframe'][layer]) {
			var iframe = document.createElement('iframe');
			iframe.style.display = 'none';
			iframe.style.position = 'absolute';
			iframe.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0)';
			$('append_parent') ? $('append_parent').appendChild(iframe) : menuobj.parentNode.appendChild(iframe);
			jsmenu['iframe'][layer] = iframe;
		}
		jsmenu['iframe'][layer].style.top = menuobj.style.top;
		jsmenu['iframe'][layer].style.left = menuobj.style.left;
		jsmenu['iframe'][layer].style.width = menuobj.w;
		jsmenu['iframe'][layer].style.height = menuobj.h;
		jsmenu['iframe'][layer].style.display = 'block';
	}

	if(maxh && menuobj.scrollHeight > maxh) {
		menuobj.style.height = maxh + 'px';
		if(is_opera) {
			menuobj.style.overflow = 'auto';
		} else {
			menuobj.style.overflowY = 'auto';
		}
	}

	if(!duration) {
		setTimeout('hideMenu(' + layer + ')', timeout);
	}

	jsmenu['active'][layer] = menuobj;
}

function setMenuPosition(showid, offset) {
	var showobj = $(showid);
	var menuobj = $(showid + '_menu');
	if(showid.indexOf('pagemore')>=0){
		menuobj = $('pagemore_menu');
	}
	if(isUndefined(offset)) offset = 0;
	if(showobj) {
		showobj.pos = fetchOffset(showobj);
		showobj.X = showobj.pos['left'];
		showobj.Y = showobj.pos['top'];
		showobj.w = showobj.offsetWidth;
		showobj.h = showobj.offsetHeight;
		menuobj.w = menuobj.offsetWidth;
		menuobj.h = menuobj.offsetHeight;
		if(offset < 3) {
			menuobj.style.left = (showobj.X + menuobj.w > document.body.clientWidth) && (showobj.X + showobj.w - menuobj.w >= 0) ? showobj.X + showobj.w - menuobj.w + 'px' : showobj.X + 'px';
			menuobj.style.top = offset == 1 ? showobj.Y + 'px' : (offset == 2 || ((showobj.Y + showobj.h + menuobj.h > document.documentElement.scrollTop + document.documentElement.clientHeight) && (showobj.Y - menuobj.h >= 0)) ? (showobj.Y - menuobj.h) + 'px' : showobj.Y + showobj.h + 'px');
		} else if(offset == 3) {
			menuobj.style.left = (document.body.clientWidth - menuobj.clientWidth) / 2 + document.body.scrollLeft + 'px';
			menuobj.style.top = (document.body.clientHeight - menuobj.clientHeight) / 2 + document.body.scrollTop + 'px';
		}
		else if(offset == 4) {
			menuobj.style.left = showobj.X + showobj.w + 11 +'px';
			menuobj.style.top = showobj.Y - 10 +'px';
		}
		else if(offset == 5) {
			showid = 'viewforumsub';
			showobj = $(showid);
			showobj.pos = fetchOffset(showobj);
			showobj.X = showobj.pos['left'];
			showobj.Y = showobj.pos['top'];
			menuobj.style.left =showobj.X + 0 +'px';
			menuobj.style.top = showobj.Y + 16 +'px';
		}
		else if(offset == 6) {
			showid = 'menu_' + showid;
			showobj = $(showid);
			showobj.pos = fetchOffset(showobj);
			showobj.X = showobj.pos['left'];
			showobj.Y = showobj.pos['top'];
			menuobj.style.left =showobj.X + 0 +'px';
			menuobj.style.top = showobj.Y + 16 +'px';
		}
		if(menuobj.style.clip && !is_opera) {
			menuobj.style.clip = 'rect(auto, auto, auto, auto)';
		}
	}
}


function showMenu2(ctrlid, click, offset, duration, timeout, layer, showid, maxh, drag) {
	layer=0;
	var showmenu = false;
	if(jsmenu['active'][layer]) {
		try {
			$(jsmenu['active'][layer].ctrlkey).className = ctrlobjclassName;
		} catch(e) {}
		
		if(jsmenu['active'][layer].style.display != 'none'){
				showmenu = true;
		}
		if(is_ie && is_ie < 7 && jsmenu['iframe'][layer]) {
			if(jsmenu['iframe'][layer].style.display != 'none'){
				showmenu = true;
			}
		}
		
		if(showmenu) {
				//alert('fc');
				showMenu(ctrlid, click, offset, duration, timeout, layer, showid, maxh, drag);
		}
	}
	
}



function hideMenu(layer) {
	if(isUndefined(layer)) layer = 0;
	if(jsmenu['active'][layer]) {
		try {
			$(jsmenu['active'][layer].ctrlkey).className = ctrlobjclassName;
		} catch(e) {}
		clearTimeout(jsmenu['timer'][jsmenu['active'][layer].ctrlkey]);
		jsmenu['active'][layer].style.display = 'none';
		if(is_ie && is_ie < 7 && jsmenu['iframe'][layer]) {
			jsmenu['iframe'][layer].style.display = 'none';
		}
		jsmenu['active'][layer] = null;
	}
}

function fetchOffset(obj) {
	var left_offset = obj.offsetLeft;
	var top_offset = obj.offsetTop;
	while((obj = obj.offsetParent) != null) {
		left_offset += obj.offsetLeft;
		top_offset += obj.offsetTop;
	}
	return { 'left' : left_offset, 'top' : top_offset };
}

function ebygum(eventobj) {
	if(!eventobj || is_ie) {
		window.event.cancelBubble = true;
		return window.event;
	} else {
		if(eventobj.target.type == 'submit') {
			eventobj.target.form.submit();
		}
		eventobj.stopPropagation();
		return eventobj;
	}
}

/*
	以上是弹出框的JS end
*/

// 设置不可见
function setDisable(prefix,id){
	var span = document.getElementById("imgplus_"+prefix+id);
	if (document.getElementById(prefix+id)!=null)
    {   
        if(document.getElementById(prefix+id).style.display=="none"){
			document.getElementById(prefix+id).style.display = "";
			span.innerHTML = "<img src='/images/buttons/cp_collapse.gif' border=0 />";
		}
		else{ 
			document.getElementById(prefix+id).style.display = "none";
			span.innerHTML = "<img src='/images/buttons/cp_expand.gif' border=0 />";
		}
    }
	

}
//打开收缩所有
function showAllDisplay(prefix,op){
	for(i=1;i<100;i++){	
		if (document.getElementById(prefix+i)!=null)
		{    if(op==1){
				document.getElementById(prefix+i).style.display = "";
				document.getElementById("imgplus_"+prefix+i).innerHTML = "<img src='/images/buttons/cp_collapse.gif' border=0 />";
			 }else{
				document.getElementById(prefix+i).style.display = "none";
				document.getElementById("imgplus_"+prefix+i).innerHTML = "<img src='/images/buttons/cp_expand.gif' border=0 />";
			 }
			
		}
	}
}

//设置内容
function setInnerHTML(objId, html){
	try{
	  var obj = document.getElementById(objId);
	   obj.innerHTML = html;
	}catch(exception){
	   //alert("Make sure the object id is correct!");
	}
}

//ajax
function createXmlHttp() {
    try {
        return new XMLHttpRequest();
    } catch(e1) { try {
        return new ActiveXObject("Msxml2.XMLHTTP");
    } catch(e2) { try {
        return new ActiveXObject("Microsoft.XMLHTTP");
    } catch(e3) {
        return null;
    } } }
}
function setInnerHtmlFormTxt(objId,path) {
    var req = createXmlHttp();
    if (req) {		
        req.open("GET", path, false);
        //禁示读缓存，以免取不到header
		req.setRequestHeader("If-Modified-Since","0");
		req.send(null);
        if (req.status == "200") {
            try{
			  var obj = document.getElementById(objId);
			   obj.innerHTML = req.responseText; 
			}catch(exception){
			   alert("Make sure the object id is correct!");
			}
        } else {
            alert( path + "出错!");
        }
    } else {
            alert("浏览器不支持!");
    }
}


function showPageMore(threadid,pagecount){
	var pages = '';
	var pagesize = 10;
	var mod = id2mod(threadid);
	if(pagecount>pagesize){
		pages = "[第 ";
		for(j=1;j<=pagesize;j++){
			pages += "<a href=/viewthread-"+threadid+"-"+j+".html>"+j+"</a>&nbsp;";
		}
		if(pagecount==(pagesize+1)) tag = "";
		else tag = '...';
		pages += tag +  "<a href=/viewthread-"+threadid+"-"+pagecount+".html>"+pagecount+"</a>&nbsp; 页]";
		
	}else if(pagecount<=pagesize && pagecount>1){
		pages = "[第 ";
		for(j=1;j<=pagecount;j++){
			pages +="<a href=/viewthread-"+threadid+"-"+j+".html>"+j+"</a>&nbsp;";
		}
		pages +=" 页]";
	}else{
		pages = "";
	}
	pages += '';
	setInnerHTML("pagemore_menu",pages);
	showMenu("pagemore_"+threadid);
}

function num2e(num){
	    var str  = '';
		switch(num){
			case '0': str='z'; break; case '1': str='a'; break; case '2': str='b'; break; 
			case '3': str='c'; break; case '4': str='d'; break; case '5': str='e'; break; 
			case '6': str='f'; break; case '7': str='g'; break; case '8': str='h'; break; 
			case '9': str='i'; break;
		}
		return str;
}

function nums2e(num){
	var snum = num + "";
	var str = '';
	for(var i=0;i<snum.length;i++){
		str = str + num2e(snum.charAt(i));
	}
	return str;
}

function id2mod(num){
	var mod = num % 512;
	mod = nums2e(mod);
	return mod;
}


 function resizeIframe(obj) {
	var frm = document.getElementById(obj);   
	var subWeb = document.frames ? document.frames[obj].document : frm.contentDocument;   
	if(frm != null && subWeb != null) {
	   frm.height = subWeb.body.scrollHeight;
	}   
}


//show div menu functions mx 2009-3-10
var MX_DivCnt = 0 ;
function jias(a,b){
mar.setAttribute("direction",a);
mar.setAttribute("scrollAmount",b);
}
function MX_reloadPage(init) {  //reloads the window if Nav4 resized
  if (init==true) with (navigator) {if ((appName=="Netscape")&&(parseInt(appVersion)==4)) {
    document.MX_pgW=innerWidth; document.MX_pgH=innerHeight; onresize=MX_reloadPage; }}
  else if (innerWidth!=document.MX_pgW || innerHeight!=document.MX_pgH) location.reload();
}
MX_reloadPage(true);

function MX_findObj(n) { //v4.01
	  x=document.getElementById(n); 
	  return x;
}

function MX_showHideLayers(mxdiv,show) { //v6.0
  var i,p,v,ifshow,obj;
  for (i=1; i<200; i++){
	  //if(i!=mxdiv)continue;
	  if ((obj=MX_findObj("MX_Layer_"+i))!=null) { 
			if (obj.style) { 
				obj=obj.style;
				ifshow = (show==1)?'visible':'hidden';
				 
				if(i==mxdiv)v=ifshow;
				else v='hidden';
			
			 }
             obj.visibility=v;
		}else{
			break;
		}
	}
}

function MX_printFloat(menu,str){
	MX_DivCnt++;
	str = str.replace('none','');//必须去掉display:none
	return "<DIV  onmouseover=\"MX_showHideLayers("+MX_DivCnt+",1)\"><span style=\"cursor:pointer\">"+menu+"</span><BR>       <table border=0 cellpadding=0 cellspacing=0 onmouseout=\"MX_showHideLayers("+MX_DivCnt+",0)\" id=MX_Layer_"+MX_DivCnt+"       style=\"Z-INDEX: 100; VISIBILITY: hidden; WIDTH: 100px; POSITION: absolute; \"><tr><td align=center>"+str+"</td></tr></table></DIV>";
}

 function jias(a,b){
 mar.setAttribute("direction",a);
 mar.setAttribute("scrollAmount",b);
 }

 function picsize(id,awidth,aheight)
{
	var imgid=id;
	if (awidth>0 && imgid.width>awidth) imgid.width=awidth;
	if (aheight>0 && imgid.height>aheight) imgid.height=aheight; 
}
/*======================================================================*\
|| ####################################################################
|| #
|| # CVS: $RCSfile: global.js,v $ - $Revision: 1.89 $
|| ####################################################################
\*======================================================================*/
