charset = 'utf-8';

var userAgent = navigator.userAgent.toLowerCase();
var is_opera = userAgent.indexOf('opera') != -1 && opera.version();
var is_moz = (navigator.product == 'Gecko') && userAgent.substr(userAgent.indexOf('firefox') + 8, 3);
var is_ie = (userAgent.indexOf('msie') != -1 && !is_opera) && userAgent.substr(userAgent.indexOf('msie') + 5, 3);

var ajaxdebug = 1;

var BROWSER = {};
var USERAGENT = navigator.userAgent.toLowerCase();
browserVersion({'ie':'msie','firefox':'','chrome':'','opera':'','safari':'','mozilla':'','webkit':'','maxthon':'','qq':'qqbrowser'});
if(BROWSER.safari) {
	BROWSER.firefox = true;
}
BROWSER.opera = BROWSER.opera ? opera.version() : 0;

var ctrlobjclassName;
var jsmenu = new Array();
jsmenu['active'] = new Array();
jsmenu['timer'] = new Array();
jsmenu['iframe'] = new Array();

function falseTextMenu(obj)
{
    obj.oncontextmenu=function(e){ alert('感谢支持陌上！'); return false;}//屏蔽右键菜单
}

// add Browser
function addFavorite(url, title)
{
	try
    {
		window.external.addFavorite(url, title);
	} 
    catch (e)
    {
		try
        {
            window.sidebar.addPanel(title, url, '');
        } 
        catch (e)
        {
            alert("请按 Ctrl+D 键添加到收藏夹");
		}
	}
}

/*
 * 页面滚动时出现返回顶部的链接
 */
function showTopLink(position)
{
	if (document.getElementById(position))
    {
		var viewPortHeight = parseInt(document.documentElement.clientHeight);
		var scrollHeight = parseInt(document.body.getBoundingClientRect().top);
		var basew = parseInt(document.getElementById(position).clientWidth);
		var sw = document.getElementById('scrolltop').clientWidth;
		if (basew < 1000) {
			var left = parseInt(fetchOffset(document.getElementById(position))['left']);
			left = left < sw ? left * 2 - sw : left;
			document.getElementById('scrolltop').style.left = ( basew + left ) + 'px';
		} else {
			document.getElementById('scrolltop').style.left = 'auto';
			document.getElementById('scrolltop').style.right = 0;
		}

		if (BROWSER.ie && BROWSER.ie < 7) {
			document.getElementById('scrolltop').style.top = viewPortHeight - scrollHeight - 150 + 'px';
		}
		if (scrollHeight < -100) {
			document.getElementById('scrolltop').style.visibility = 'visible';
		} else {
			document.getElementById('scrolltop').style.visibility = 'hidden';
		}
	}
}

function ReadBg()
{
	var bgColor1 = getCookie('iwmsContBg');

	var obj=document.getElementById("bodyTd");
	obj.style.backgroundColor=bgColor1;
}
function WriteBg()
{
	var a=["#f3f4ff","#ffffed","#E5F3CB","#fcefff","#fff1e1","#efefef"]
	var b=["blue","yellow","green","purple","pink","black"]

	var j='';
	var bgColor1 = getCookie('iwmsContBg');
	for (var i = 0;i < a.length; i++)
	{
		j = i + 1;
		document.write("<span id=\"theme"+j+"\" class=\""+(bgColor1==a[i] ?'current':(i==2?'current':''))+"\" alt='"+(i==a.length-1?"默认":b[i])+"' onclick='ContentBg(\""+(i==a.length?"":a[i])+"\","+j+","+a.length+")'>"+b[i]+"</span>");//,"+fcolor[i]+"
	}
}
function ContentBg(color,id,idlength)
{
	var obj=document.getElementById("bodyTd");
	obj.style.backgroundColor=color;
	//alert(arguments.length);
	if (arguments.length==3)
	{
		setCookie("iwmsContBg",color,color.length==0?-1:1);
	}
	for(var i=1;i<=idlength;i++){
		if(i!=id){
			document.getElementById("theme"+i).className = '';
		}else{
		    document.getElementById("theme"+i).className = 'current';	
		}
		
	}
}

// 内容样式 ===== begin =====
function ContentSize(size)
{
	var obj=document.getElementById("article-content");
	obj.style.fontSize=size>0 ? size+"px" : "";
	if (arguments.length==1)
	{
		setCookie("iwmsFontSize",size,size==0?-1:1);
	}
	
	if(size==14 || size == null)
	{
		document.getElementById('current2').className='';
		document.getElementById('current3').className='';		
		document.getElementById('current1').className='current';

	}
	else if(size==16)
	{
		document.getElementById('current1').className='';
		document.getElementById('current3').className='';		
		document.getElementById('current2').className='current';
		
	}
	else if(size==18)
	{
        document.getElementById('current2').className='';
		document.getElementById('current1').className='';
		document.getElementById('current3').className='current';
	}
	
}

function showStringLength(s)
{   
	s =  s.replace(/\s+/g,"").replace(/[\u3000]/g,"");
	alert('字数：' + s.length + " 包括符号\r\n\r\n系统在保存的时候符号不计数。");
} 

function getStringLength(strValue)
{   
	var len = 0;   
	for (var loop = 0; loop < strValue.length; loop++)
	{   
		len++;   
		if (strValue.charCodeAt(loop) > 255)
		{   
			len++;   
		}
	}

	return len;   
}

var app = app ? app : {};
app.inface = function (face){ insertAtCursor(document.getElementById("comment_message"), face);}
function insertAtCursor(myField, myValue)
{   
    //IE support   
    if (document.selection)
	{   
        myField.focus();   
        sel = document.selection.createRange();   
        sel.text = myValue;   
        sel.select();   
    }   
    //MOZILLA/NETSCAPE support   
    else if (myField.selectionStart || myField.selectionStart == '0')
	{   
        var startPos = myField.selectionStart;   
        var endPos = myField.selectionEnd;   
        // save scrollTop before insert   
        var restoreTop = myField.scrollTop;   
        myField.value = myField.value.substring(0, startPos) + myValue + myField.value.substring(endPos, myField.value.length);   
        if (restoreTop > 0)
		{   
			myField.scrollTop = restoreTop;   
        }   
        myField.focus();   
        myField.selectionStart = startPos + myValue.length;   
        myField.selectionEnd = startPos + myValue.length;   
    } 
	else 
	{   
        myField.value += myValue;   
        myField.focus();   
    }   
}

function editorsize(op, v)
{
    var obj = document.getElementById('comment_message');
	var editorheight = obj.clientHeight;
	if (!v)
    {
		if (op == '+')
        {
			editorheight += 100;
		} 
        else
        {
			editorheight -= 100;
		}
	} 
    else 
    {
		editorheight = v;
	}
    
    editorcurrentheight = editorheight > 80 ? editorheight : 80;
    obj.style.height = editorcurrentheight + 'px';
}

function showMsgItem(action, nu)
{
	if (action == 'long')
	{
		document.getElementById('i_arrow_short-' + nu).style.display = 'none';
		document.getElementById('i_arrow_long-' + nu).style.display = '';
		document.getElementById('m_arrow_short-' + nu).style.display = 'none';
		document.getElementById('m_arrow_long-' + nu).style.display = '';
	}
	else
	{
		document.getElementById('i_arrow_short-' + nu).style.display = '';
		document.getElementById('i_arrow_long-' + nu).style.display = 'none';
		document.getElementById('m_arrow_short-' + nu).style.display = '';
		document.getElementById('m_arrow_long-' + nu).style.display = 'none';
	}
}

function showReply(k, commentid)
{
	deleteRep();

	document.getElementById('pcid').value = commentid;

	var obj = document.getElementById('rep_' + k);
	if (obj.style.display == '' || obj.style.display == 'none')
	{
		obj.style.display = 'block';
	}
	else
	{
		obj.style.display = 'none';
	}

	obj.innerHTML = document.getElementById('reply_box').innerHTML;
}
function replySubmit(f)
{
	if (f.message.value.length > 500)
	{
		alert('回复的内容太长了，不能大于500个字');
		return false;
	}
	return true;
}
function doOne(type, id, clk)
{
	if (clk.innerHTML == '已送出')
	{
		clk.href = "javascript:window.alert('您已经送过鲜花了');";
		return false;
	}
	if (clk.innerHTML=='已扔出')
	{
		clk.href = "javascript:window.alert('您已经砸过砖头了');";
		return false;
	}

	var do_val = 0;
	var obj = document.getElementById(type + '_' + id);
	do_val = parseInt(obj.innerHTML) + 1;
	obj.innerHTML = do_val;
	
	if (type == 'flower')
	{
		clk.innerHTML = '已送出';
	}
	else if (type == 'egg')
	{
		clk.innerHTML = '已扔出';
	}
}
function deleteRep()
{ 
	for (var i = 0; i <= 10; i ++)
	{ 
		if (document.getElementById('rep_' + i))
		{
			document.getElementById('rep_' + i).innerHTML = '';
		}		
	} 
}

var cookiedomain = isUndefined(cookiedomain) ? '' : cookiedomain;
var cookiepath = isUndefined(cookiepath) ? '' : cookiepath;
// 设置 cookie
function setCookie(cookieName, cookieValue, seconds, path, domain, secure)
{
	var expires = new Date();
	if (cookieValue == '' || seconds < 0)
    {
		cookieValue = '';
		seconds = -2592000;
	}
	expires.setTime(expires.getTime() + seconds * 1000);
	domain = !domain ? cookiedomain : domain;
	path = !path ? cookiepath : path;
	document.cookie = escape(cookieName) + '=' + escape(cookieValue)
		+ (expires ? '; expires=' + expires.toGMTString() : '')
		+ (path ? '; path=' + path : '/')
		+ (domain ? '; domain=' + domain : '')
		+ (secure ? '; secure' : '');
}

// 获取 cookie
function getCookie(name, nounescape)
{
	var cookie_start = document.cookie.indexOf(name);
	var cookie_end = document.cookie.indexOf(";", cookie_start);
	if (cookie_start == -1)
    {
		return '';
	} 
    else 
    {
		var v = document.cookie.substring(cookie_start + name.length + 1, (cookie_end > cookie_start ? cookie_end : document.cookie.length));
		return !nounescape ? unescape(v) : v;
	}
}

function tab(mod, cursor, n)
{
	var classname = arguments[3] ? arguments[3] : "current";

	for(i = 1; i <= n; i++)
	{
		var nav = document.getElementById(mod + i);
		var cont=document.getElementById(mod + "_" + "cont" + i);
		nav.className = (i == cursor) ? classname :"";
		cont.style.display = ( i == cursor) ? "block" : "none";
	}
}

function tab3(mod, cursor, n)
{
	var classname = arguments[3] ? arguments[3] : "current";

	for(i = 1; i <= n; i++)
	{
		var nav = document.getElementById(mod + i);
		var pic = document.getElementById(mod + "_" + "pic" + i);
		var cont = document.getElementById(mod + "_" + "cont" + i);
		nav.className = (i == cursor) ? classname : "";
		pic.style.display = ( i == cursor) ? "block" : "none";
		cont.style.display = ( i == cursor) ? "block" : "none";
	}
}

function switch2TabsRem(showId, hiddenId)
{
	document.getElementById(showId).style.display = '';
	document.getElementById(hiddenId).style.display = 'none';
	document.getElementById(showId + 'Head').className = 'tabrem2_head tabrem2_active';
	document.getElementById(hiddenId + 'Head').className = 'tabrem2_head';
}

function switch3TabsRem(showId, hiddenId, hiddenId2)
{
	document.getElementById(showId).style.display = '';
	document.getElementById(hiddenId).style.display = 'none';
	document.getElementById(hiddenId2).style.display = 'none';

	document.getElementById(showId + 'Head').className = 'tabrem2_head tabrem2_active';
	document.getElementById(hiddenId + 'Head').className = 'tabrem2_head';
	document.getElementById(hiddenId2 + 'Head').className = 'tabrem2_head';
}

function switch3Tab(showId, hiddenId, hiddenId2)
{
	document.getElementById(showId).style.display = '';
	document.getElementById(hiddenId).style.display = 'none';
	document.getElementById(hiddenId2).style.display = 'none';
	
	document.getElementById(showId + 'Head').className = 'tab3_head tab3_active';
	document.getElementById(hiddenId + 'Head').className = 'tab3_head';
	document.getElementById(hiddenId2 + 'Head').className = 'tab3_head';
}

function checkall(form, prefix, checkall)
{
	var checkall = checkall ? checkall : 'chkall';
	count = 0;

	for (var i = 0; i < form.elements.length; i++)
	{
		var e = form.elements[i];
		if (e.name && e.name != checkall && (!prefix || (prefix && e.name.match(prefix))))
		{
			e.checked = form.elements[checkall].checked;

			if (e.checked)
			{
				count++;
			}
		}
	}

	return count;
}

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 };
}

//FloatWin
var hiddenobj = new Array();
var floatwinhandle = new Array();
var floatscripthandle = new Array();
var floattabs = new Array();
var floatwins = new Array();
var InFloat = '';
var floatwinreset = 0;
var floatwinopened = 0;
allowfloatwin = 1;
function floatwin(action, script, w, h, scrollpos)
{
	var floatonly = !floatonly ? 0 : 1;
	var actione = action.split('_');
	action = actione[0];
	if((!allowfloatwin || allowfloatwin == 0) && action == 'open' && in_array(actione[1], ['edit']) && w >= 600)
	{
		location.href = script;
		return;
	}
	
	var handlekey = actione[1];
	var layerid = 'floatwin_' + handlekey;
	if (is_ie)
	{
		var objs = document.getElementById('wrap').getElementsByTagName("OBJECT");
	} 
	else
	{
		var objs = document.getElementById('wrap').getElementsByTagName("EMBED");
	}
	
	if (action == 'open')
	{
		floatwinhandle[handlekey + '_0'] = layerid;
		
		if (!floatwinopened)
		{
			document.getElementById('wrap').onkeydown = floatwin_wrapkeyhandle;
			for (i = 0;i < objs.length; i ++)
			{
				if (objs[i].style.visibility != 'hidden')
				{
					objs[i].setAttribute("oldvisibility", objs[i].style.visibility);
					objs[i].style.visibility = 'hidden';
				}
			}
		}

		scrollpos = !scrollpos ? '' : 'floatwin_scroll(\'' + scrollpos + '\');';
		var clientWidth = document.body.clientWidth;
		var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
		var scrollTop = document.body.scrollTop ? document.body.scrollTop : document.documentElement.scrollTop;
		
		if (script && script != -1) 
		{
			if (script.lastIndexOf('/') != -1)
			{
				script = script.substr(script.lastIndexOf('/') + 1);
			}
			var scriptfile = script.split('?');
			scriptfile = scriptfile[0];
			if (floatwinreset || floatscripthandle[scriptfile] && floatscripthandle[scriptfile][0] != script)
			{
				if (!isUndefined(floatscripthandle[scriptfile]))
				{
					document.getElementById('append_parent').removeChild(document.getElementById(floatscripthandle[scriptfile][1]));
					document.getElementById('append_parent').removeChild(document.getElementById(floatscripthandle[scriptfile][1] + '_mask'));
				}
				floatwinreset = 0;
			}
			floatscripthandle[scriptfile] = [script, layerid];
		}
		
		if (!document.getElementById(layerid))
		{
			floattabs[layerid] = new Array();
			div = document.createElement('div');
			div.className = 'floatwin';
			div.id = layerid;
			div.style.width = w + 'px';
			div.style.height = h + 'px';
			div.style.left = floatwinhandle[handlekey + '_1'] = ((clientWidth - w) / 2) + 'px';
			div.style.position = 'absolute';
			div.style.zIndex = '999';
			div.onkeydown = floatwin_keyhandle;
			
			document.getElementById('append_parent').appendChild(div);
			document.getElementById(layerid).style.display = '';
			document.getElementById(layerid).style.top = floatwinhandle[handlekey + '_2'] = ((clientHeight - h) / 2 + scrollTop) + 'px';
			document.getElementById(layerid).innerHTML = '<div><h3 class="float_ctrl"><em><img src="/public/images/loading.gif"> 加载中...</em><span><a href="javascript:;" class="float_close" onclick="floatwinreset = 1;floatwin(\'close_' + handlekey + '\');">&nbsp</a></span></h3></div>';
			
			divmask = document.createElement('div');
			divmask.className = 'floatwinmask';
			divmask.id = layerid + '_mask';
			divmask.style.width = (parseInt(document.getElementById(layerid).style.width) + 14) + 'px';
			divmask.style.height = (parseInt(document.getElementById(layerid).style.height) + 14) + 'px';
			divmask.style.left = (parseInt(document.getElementById(layerid).style.left) - 6) + 'px';
			divmask.style.top = (parseInt(document.getElementById(layerid).style.top) - 6) + 'px';
			divmask.style.position = 'absolute';
			divmask.style.zIndex = '998';
			divmask.style.filter = 'progid:DXImageTransform.Microsoft.Alpha(opacity=90,finishOpacity=100,style=0)';
			divmask.style.opacity = 0.9;
			document.getElementById('append_parent').appendChild(divmask);
			
			if (script && script != -1)
			{				
				script += (script.search(/\?/) > 0 ? '&' : '?') + 'handlekey=' + handlekey;
				try
				{
					ajaxget(script, layerid, '', '', '', scrollpos);
				} 
				catch(e)
				{
					setTimeout("ajaxget('" + script + "', '" + layerid + "', '', '', '', '" + scrollpos + "')", 1000);
				}
			} 
			else if(script == -1)
			{
				document.getElementById(layerid).innerHTML = '<div><h3 class="float_ctrl"><em id="' + layerid + '_title"></em><span><a href="javascript:;" class="float_close" onclick="floatwinreset = 1;floatwin(\'close_' + handlekey + '\');">&nbsp</a></span></h3></div><div id="' + layerid + '_content"></div>';
				document.getElementById(layerid).style.zIndex = '1099';
				document.getElementById(layerid + '_mask').style.zIndex = '1098';
			}
		} 
		else 
		{
			document.getElementById(layerid).style.width = w + 'px';
			document.getElementById(layerid).style.height = h + 'px';
			document.getElementById(layerid).style.display = '';
			document.getElementById(layerid).style.top = floatwinhandle[handlekey + '_2'] = ((clientHeight - h) / 2 + scrollTop) + 'px';
			document.getElementById(layerid + '_mask').style.width = (parseInt(document.getElementById(layerid).style.width) + 14) + 'px';
			document.getElementById(layerid + '_mask').style.height = (parseInt(document.getElementById(layerid).style.height) + 14) + 'px';
			document.getElementById(layerid + '_mask').style.display = '';
			document.getElementById(layerid + '_mask').style.top = (parseInt(document.getElementById(layerid).style.top) - 6) + 'px';
		}
		floatwins[floatwinopened] = handlekey;
		floatwinopened++;
	} 
	else if (action == 'close' && floatwinhandle[handlekey + '_0'])
	{
		floatwinopened--;
		for (i = 0;i < floatwins.length; i++)
		{
			if (handlekey == floatwins[i])
			{
				floatwins[i] = null;
			}
		}
		if (!floatwinopened)
		{
			for (i = 0;i < objs.length; i ++) 
			{
				if (objs[i].attributes['oldvisibility']) 
				{
					objs[i].style.visibility = objs[i].attributes['oldvisibility'].nodeValue;
					objs[i].removeAttribute('oldvisibility');
				}
			}
			document.getElementById('wrap').onkeydown = null;
		}
		hiddenobj = new Array();
		document.getElementById(layerid + '_mask').style.display = 'none';
		document.getElementById(layerid).style.display = 'none';
	} 
	else if (action == 'size' && floatwinhandle[handlekey + '_0'])
	{
		if (!floatwinhandle[handlekey + '_3'])
		{
			var clientWidth = document.body.clientWidth;
			var clientHeight = document.documentElement.clientHeight ? document.documentElement.clientHeight : document.body.clientHeight;
			var w = clientWidth > 800 ? clientWidth * 0.9 : 800;
			var h = clientHeight * 0.9;

			floatwinhandle[handlekey + '_3'] = document.getElementById(layerid).style.left;
			floatwinhandle[handlekey + '_4'] = document.getElementById(layerid).style.top;
			floatwinhandle[handlekey + '_5'] = document.getElementById(layerid).style.width;
			floatwinhandle[handlekey + '_6'] = document.getElementById(layerid).style.height;

			document.getElementById(layerid).style.left = floatwinhandle[handlekey + '_1'] = ((clientWidth - w) / 2) + 'px';
			document.getElementById(layerid).style.top = floatwinhandle[handlekey + '_2'] = ((document.documentElement.clientHeight - h) / 2 + document.documentElement.scrollTop) + 'px';
			document.getElementById(layerid).style.width = w + 'px';
			document.getElementById(layerid).style.height = h + 'px';
		} 
		else 
		{
			document.getElementById(layerid).style.left = floatwinhandle[handlekey + '_1'] = floatwinhandle[handlekey + '_3'];
			document.getElementById(layerid).style.top = floatwinhandle[handlekey + '_2'] = floatwinhandle[handlekey + '_4'];
			document.getElementById(layerid).style.width = floatwinhandle[handlekey + '_5'];
			document.getElementById(layerid).style.height = floatwinhandle[handlekey + '_6'];
			floatwinhandle[handlekey + '_3'] = '';
		}
		document.getElementById(layerid + '_mask').style.width = (parseInt(document.getElementById(layerid).style.width) + 14) + 'px';
		document.getElementById(layerid + '_mask').style.height = (parseInt(document.getElementById(layerid).style.height) + 14) + 'px';
		document.getElementById(layerid + '_mask').style.left = (parseInt(document.getElementById(layerid).style.left) - 6) + 'px';
		document.getElementById(layerid + '_mask').style.top = (parseInt(document.getElementById(layerid).style.top) - 6) + 'px';
	}
}

function floatwin_scroll(pos)
{
	var pose = pos.split(',');
	try
	{
		pagescroll.defaultleft = pose[0];
		pagescroll.defaulttop = pose[1];
		pagescroll.init();
	} catch(e) {}
}

function floatwin_wrapkeyhandle(e)
{
	e = is_ie ? event : e;
	if (e.keyCode == 9)
	{
		doane(e);
	} 
	else if (e.keyCode == 27)
	{
		for (i = floatwins.length - 1;i >= 0; i--)
		{
			floatwin('close_' + floatwins[i]);
		}
	}
}

function floatwin_keyhandle(e)
{
	e = is_ie ? event : e;
	if (e.keyCode == 9)
	{
		doane(e);
		var obj = is_ie ? e.srcElement : e.target;
		var srcobj = obj;
		j = 0;
		while (obj.className.indexOf('floatbox') == -1)
		{
			obj = obj.parentNode;
		}

		obj.id = obj.id ? obj.id : 'floatbox_' + Math.random();

		if (!floattabs[obj.id])
		{
			floattabs[obj.id] = new Array();
			var alls = obj.getElementsByTagName("*");
			for (i = 0;i < alls.length;i++)
			{
				if (alls[i].getAttribute('tabindex') == 1)
				{
					floattabs[obj.id][j] = alls[i];
					j++;
				}
			}
		}

		if (floattabs[obj.id].length > 0)
		{
			for (i = 0;i < floattabs[obj.id].length;i++)
			{
				if (srcobj == floattabs[obj.id][i])
				{
					j = e.shiftKey ? i - 1 : i + 1;
					break;
				}
			}

			if (j < 0)
			{
				j = floattabs[obj.id].length - 1;
			}

			if (j > floattabs[obj.id].length - 1)
			{
				j = 0;
			}

			do
			{
				focusok = 1;
				try
				{ 
					floattabs[obj.id][j].focus(); 
				} 
				catch(e) 
				{
					focusok = 0;
				}

				if (!focusok)
				{
					j = e.shiftKey ? j - 1 : j + 1;
					if (j < 0)
					{
						j = floattabs[obj.id].length - 1;
					}

					if (j > floattabs[obj.id].length - 1)
					{
						j = 0;
					}
				}
			} while(!focusok);
		}
	}
}

function ajaxmenu(e, ctrlid, timeout, func, offset)
{
	var box = 0;
	showloading();
	if(jsmenu['active'][0] && jsmenu['active'][0].ctrlkey == ctrlid)
	{
		hideMenu();
		doane(e);
		return;
	} 
	else if(is_ie && is_ie < 7 && document.readyState.toLowerCase() != 'complete')
	{
		return;
	}
	cache = 0;
	divclass = 'popupmenu_popup';
	optionclass = 'popupmenu_option';
	if(isUndefined(timeout)) timeout = 3000;
	if(isUndefined(func)) func = '';
	if(isUndefined(offset)) offset = 0;
	duration = timeout > 10000 ? 3 : 0;
	executetime = duration ? 2000: timeout;
	if(offset == -1)
	{
		divclass = 'popupmenu_centerbox';
		box = 1;
	}
	
	var div = document.getElementById(ctrlid + '_menu');
	if(cache && div)
	{
		showMenu(ctrlid, e.type == 'click', offset, duration, timeout, 0, ctrlid, 500, 1);
		if(func) setTimeout(func + '(' + ctrlid + ')', executetime);
		doane(e);
	} 
	else 
	{
		if(!div) 
		{
			div = document.createElement('div');
			div.ctrlid = ctrlid;
			div.id = ctrlid + '_menu';
			div.style.display = 'none';
			div.className = divclass;
			document.getElementById('append_parent').appendChild(div);
		}

		var x = new Ajax();
		var href = !isUndefined(document.getElementById(ctrlid).href) ? document.getElementById(ctrlid).href : document.getElementById(ctrlid).attributes['href'].value;
		x.div = div;
		x.etype = e.type;
		x.optionclass = optionclass;
		x.duration = duration;
		x.timeout = timeout;
		x.executetime = executetime;
		x.get(href + '/inajax/1/ajaxmenuid/'+ctrlid+'_menu/popupmenu_box/'+box, function(s) {
			evaled = false;
			if(s.indexOf('ajaxerror') != -1) 
			{
				evalscript(s);
				evaled = true;
				if(!cache && duration != 3 && x.div.id) setTimeout('document.getElementById("append_parent").removeChild(document.getElementById(\'' + x.div.id + '\'))', timeout);
			}
			if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror))
			{
				if(x.div) x.div.innerHTML = '<div class="' + x.optionclass + '">' + s + '</div>';
				showMenu(ctrlid, x.etype == 'click', offset, x.duration, x.timeout, 0, ctrlid, 500, 1);
				if(func) setTimeout(func + '("' + ctrlid + '")', x.executetime);
			}
			if(!evaled) evalscript(s);
			ajaxerror = null;
			showloading('none');
		});
		doane(e);
	}
	showloading('none');
	doane(e);
}

/*
 *@ url: 需求请求的 url
 *@ showidid : 显示的 id
 *@ waitid: 等待的 id，默认为显示的 id，如果 waitid 为空字符串，则不显示 loading...， 如果为 null，则在 showid 区域显示
 *@ linkid: 是哪个链接触发的该 ajax 请求，该对象的属性(如 ajaxdisplay)保存了一些 ajax 请求过程需要的数据。
*/
function ajaxget(url, showid, waitid, loading, display, recall)
{
	waitid = typeof waitid == 'undefined' || waitid === null ? showid : waitid;	
	
	var x = new Ajax();

	x.setLoading(loading);
	x.setWaitId(waitid);

	x.display = typeof display == 'undefined' || display == null ? '' : display;
	x.showId = document.getElementById(showid);
	if (x.showId) x.showId.orgdisplay = typeof x.showId.orgdisplay === 'undefined' ? x.showId.style.display : x.showId.orgdisplay;
	
	if (url.substr(strlen(url) - 1) == '#')
	{
		url = url.substr(0, strlen(url) - 1);
		x.autogoto = 1;
	}

	var connector = "?";
    if (url.indexOf('?') != -1)
    {
       var connector = "&"; 
    }

	var url = url + connector + 'inajax=1&ajaxtarget=' + showid + '&tmp=' + Math.random();
	x.get(url, function (s, x){
		evaled = false;		
		if (s.indexOf('ajaxerror') != -1)
		{
			evalscript(s);
			evaled = true;
		}

		if(!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror))
		{
			if (x.showId)
			{
				x.showId.style.display = x.showId.orgdisplay;
				x.showId.style.display = x.display;
				x.showId.orgdisplay = x.showId.style.display;
				ajaxinnerhtml(x.showId, s);
				ajaxupdateevents(x.showId);
				if (x.autogoto) scroll(0, x.showId.offsetTop);
			}
		}

		if (!evaled)evalscript(s);
		ajaxerror = null;
		if (recall) {eval(recall);}
	});
}

var ajaxpostHandle = 0;
function ajaxpost(formid, showid, waitid, showidclass)
{
	showloading();
	var waitid = typeof waitid == 'undefined' || waitid === null ? showid : (waitid !== '' ? waitid : '');
	var showidclass = !showidclass ? '' : showidclass;

	if (ajaxpostHandle != 0)
	{
		return false;
	}

	var ajaxframeid = 'ajaxframe';
	var ajaxframe = document.getElementById(ajaxframeid);
	if(ajaxframe == null)
	{
		if (is_ie && !is_opera)
		{
			ajaxframe = document.createElement("<iframe name='" + ajaxframeid + "' id='" + ajaxframeid + "'></iframe>");
		} 
		else
		{
			ajaxframe = document.createElement("iframe");
			ajaxframe.name = ajaxframeid;
			ajaxframe.id = ajaxframeid;
		}

		ajaxframe.style.display = 'none';
		document.getElementById('append_parent').appendChild(ajaxframe);
	}
	document.getElementById(formid).target = ajaxframeid;
	
	ajaxpostHandle = [showid, ajaxframeid, formid, document.getElementById(formid).target, showidclass];

	if (ajaxframe.attachEvent)
	{		
		ajaxframe.detachEvent('onload', ajaxpost_load);
		ajaxframe.attachEvent('onload', ajaxpost_load);
	} 
	else
	{
		document.removeEventListener('load', ajaxpost_load, true);
		ajaxframe.addEventListener('load', ajaxpost_load, false);
	}

	var action = document.getElementById(formid).getAttribute("action");
    var connector = "?";
    if (action.indexOf('?') != -1)
    {
       var connector = "&"; 
    }

    document.getElementById(formid).action = action.replace(/\&inajax\=1/g, '')+connector+'inajax=1';
	document.getElementById(formid).submit();
	
	return false;
}

function ajaxpost_load()
{	
	showloading('none');
	var s = '';

	try 
	{
        s = document.getElementById(ajaxpostHandle[1]).contentWindow.document.XMLDocument.text;
	} 
	catch(e)
	{
        try
        {
            s = document.getElementById(ajaxpostHandle[1]).contentWindow.document.documentElement.firstChild.wholeText;
        }
        catch (e)
        {
            try
            {
                s = document.getElementById(ajaxpostHandle[1]).contentWindow.document.documentElement.firstChild.nodeValue;
            }
            catch (e)
            {
                if (ajaxdebug)
                {
                    var error = mb_cutstr(document.getElementById(ajaxpostHandle[1]).contentWindow.document.body.innerText.replace(/\r?\n/g, '\\n').replace(/"/g, '\\\"'), 200);
                    s = '<root>ajaxerror<script type="text/javascript" reload="1">alert(\'Ajax Error: \\n' + error + '\');</script></root>';
                }
            }
        }
	}

	evaled = false;
	if (s != '' && s.indexOf('ajaxerror') != -1)
	{
		evalscript(s);
		evaled = true;
	}
	
	if (ajaxpostHandle[4])
	{
		document.getElementById(ajaxpostHandle[0]).className = ajaxpostHandle[4];
		if (ajaxpostHandle[5])
		{
			ajaxpostHandle[5].disabled = false;
		}
	}

	if (!evaled && (typeof ajaxerror == 'undefined' || !ajaxerror))
	{
		ajaxinnerhtml(document.getElementById(ajaxpostHandle[0]), s);
		if (!evaled) evalscript(s);
		setMenuPosition(document.getElementById(ajaxpostHandle[0]).ctrlid, 0);
		setTimeout("hideMenu()", 3000);
	}

	ajaxerror = null;
	if (document.getElementById(ajaxpostHandle[2]))
	{
		document.getElementById(ajaxpostHandle[2]).target = ajaxpostHandle[3];
	}
	ajaxpostHandle = 0;
}

function ajaxinnerhtml(showid, s)
{
	if (showid.tagName != 'TBODY')
	{
		showid.innerHTML = s;
	}
	else
	{
		while (showid.firstChild)
		{
			showid.firstChild.parentNode.removeChild(showid.firstChild);
		}
		var div1 = document.createElement('DIV');
		div1.id = showid.id+'_div';
		div1.innerHTML = '<table><tbody id="'+showid.id+'_tbody">'+s+'</tbody></table>';
		document.getElementById('append_parent').appendChild(div1);
		var trs = div1.getElementsByTagName('TR');
		var l = trs.length;
		for (var i=0; i<l; i++)
		{
			showid.appendChild(trs[0]);
		}
		var inputs = div1.getElementsByTagName('INPUT');
		var l = inputs.length;
		for (var i=0; i<l; i++)
		{
			showid.appendChild(inputs[0]);
		}
		div1.parentNode.removeChild(div1);
	}
}

var evalscripts = new Array();
function evalscript(s)
{
	if (s.indexOf('<script') == -1) return s;
	var p = /<script[^\>]*?>([^\x00]*?)<\/script>/ig;
	var arr = new Array();
	while (arr = p.exec(s))
	{
		var p1 = /<script[^\>]*?src=\"([^\>]*?)\"[^\>]*?(reload=\"1\")?(?:charset=\"([\w\-]+?)\")?><\/script>/i;
		var arr1 = new Array();
		arr1 = p1.exec(arr[0]);
		if (arr1)
		{
			appendscript(arr1[1], '', arr1[2], arr1[3]);
		} 
		else 
		{
			p1 = /<script(.*?)>([^\x00]+?)<\/script>/i;
			arr1 = p1.exec(arr[0]);
			appendscript('', arr1[2], arr1[1].indexOf('reload=') != -1);
		}
	}

	return s;
}

function appendscript(src, text, reload, charset)
{
	var id = hash(src + text);
	if (!reload && in_array(id, evalscripts)) return;
	if (reload && document.getElementById(id))
	{
		document.getElementById(id).parentNode.removeChild(document.getElementById(id));
	}

	evalscripts.push(id);
	var scriptNode = document.createElement("script");
	scriptNode.type = "text/javascript";
	scriptNode.id = id;
	scriptNode.charset = charset ? charset : (is_moz ? document.characterSet : document.charset);
	try 
	{
		if (src)
		{
			scriptNode.src = src;
		} 
		else if (text)
		{
			scriptNode.text = text;
		}
		document.getElementById('append_parent').appendChild(scriptNode);
	} catch(e) {}
}

function stripscript(s)
{
	return s.replace(/<script.*?>.*?<\/script>/ig, '');
}

function newfunction(func)
{
	var args = new Array();
	for(var i=1; i<arguments.length; i++) args.push(arguments[i]);
	return function(event)
	{
		doane(event);
		window[func].apply(window, args);
		return false;
	}
}

function ajaxupdateevents(obj, tagName)
{
	tagName = tagName ? tagName : 'A';
	var objs = obj.getElementsByTagName(tagName);
	for(k in objs)
	{
		var o = objs[k];
		ajaxupdateevent(o);
	}
}

function ajaxupdateevent(o)
{
	if (typeof o == 'object' && o.getAttribute)
	{
		if (o.getAttribute('ajaxtarget'))
		{
			if (!o.id) o.id = Math.random();
			var ajaxevent = o.getAttribute('ajaxevent') ? o.getAttribute('ajaxevent') : 'click';
			var ajaxurl = o.getAttribute('ajaxurl') ? o.getAttribute('ajaxurl') : o.href;
			_attachEvent(o, ajaxevent, newfunction('ajaxget', ajaxurl, o.getAttribute('ajaxtarget'), o.getAttribute('ajaxwaitid'), o.getAttribute('ajaxloading'), o.getAttribute('ajaxdisplay')));
			if (o.getAttribute('ajaxfunc'))
			{
				o.getAttribute('ajaxfunc').match(/(\w+)\((.+?)\)/);
				_attachEvent(o, ajaxevent, newfunction(RegExp.D1, RegExp.D2));
			}
		}
	}
}

/**
 * 截取字符串长度
 */
function mb_cutstr(str, maxlen, dot)
{
	var len = 0;
	var ret = '';
	var dot = !dot ? '...' : '';
	maxlen = maxlen - dot.length;
	for (var i = 0; i < str.length; i++)
	{
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
		if (len > maxlen)
		{
			ret += dot;
			break;
		}
		ret += str.substr(i, 1);
	}
	return ret;
}

//得到一个定长的hash值， 依赖于 stringxor()
function hash(string, length)
{
	var length = length ? length : 32;
	var start = 0;
	var i = 0;
	var result = '';
	filllen = length - string.length % length;
	for (i = 0; i < filllen; i++)
	{
		string += "0";
	}

	while (start < string.length)
	{
		result = stringxor(result, string.substr(start, length));
		start += length;
	}
	return result;
}

function stringxor(s1, s2)
{
	var s = '';
	var hash = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var max = Math.max(s1.length, s2.length);
	for (var i=0; i<max; i++)
	{
		var k = s1.charCodeAt(i) ^ s2.charCodeAt(i);
		s += hash.charAt(k % 52);
	}
	return s;
}

var Ajaxs = new Array();
var AjaxStacks = new Array(0, 0, 0, 0, 0, 0, 0, 0, 0, 0);
var attackevasive = isUndefined(attackevasive) ? 0 : attackevasive;

/**
 * recvType 文件类型 (XML/HTML), 
 * waitId 表单显示 Ajax 结果的 Id
 */
function Ajax(recvType, waitId)
{
	for(var stackId = 0; stackId < AjaxStacks.length && AjaxStacks[stackId] != 0; stackId++);
	AjaxStacks[stackId] = 1;

	// 建立一个对象
	var aj = new Object();

	aj.loading = '加载中...';//public
	aj.recvType = recvType ? recvType : 'XML';//public
	aj.waitId = waitId ? document.getElementById(waitId) : null;//public

	aj.resultHandle = null;//private
	aj.sendString = '';//private
	aj.targetUrl = '';//private
	aj.stackId = 0;
	aj.stackId = stackId;

	aj.setLoading = function(loading)
	{
		if (typeof loading !== 'undefined' && loading !== null)
		{
			aj.loading = loading;
		}
	}

	aj.setRecvType = function(recvtype)
	{
		aj.recvType = recvtype;
	}

	aj.setWaitId = function(waitid)
	{
		aj.waitId = typeof waitid == 'object' ? waitid : document.getElementById(waitid);
	}
	
	// 创建一个 XML 对象
	aj.createXMLHttpRequest = function()
	{
		var xmlhttp = false;
		// 如果 IE 以外的浏览器 则直接创建 XML 对象
		if (window.XMLHttpRequest)
		{
			xmlhttp = new XMLHttpRequest();
			// 设置 MIME 类型
			if (xmlhttp.overrideMimeType)
			{
				xmlhttp.overrideMimeType('text/xml');
			}
		} 
		else if (window.ActiveXObject)
		{
			// IE 的浏览器 各版本均可
			var versions = ['Microsoft.XMLHTTP', 'MSXML.XMLHTTP', 'Microsoft.XMLHTTP', 'Msxml2.XMLHTTP.7.0', 'Msxml2.XMLHTTP.6.0', 'Msxml2.XMLHTTP.5.0', 'Msxml2.XMLHTTP.4.0', 'MSXML2.XMLHTTP.3.0', 'MSXML2.XMLHTTP'];
			for (var i = 0; i < versions.length; i++)
			{
				// 尝试
				try
				{
					xmlhttp = new ActiveXObject(versions[i]);
					// 成功则返回
					if (xmlhttp){ return xmlhttp; }
				} 
				catch(e){}
			}
		}

		return xmlhttp;
	}		
	//
	aj.XMLHttpRequest = aj.createXMLHttpRequest();

	aj.showLoading = function()
	{
		if (aj.waitId && (aj.XMLHttpRequest.readyState != 4 || aj.XMLHttpRequest.status != 200))
		{
			aj.waitId.style.display = '';
			aj.waitId.innerHTML = '<span><img src="/public/images/default/loading.gif"> ' + aj.loading + '</span>';
		}
	}
	
	/**
	 * 运行句柄
	 */
	aj.processHandle = function()
	{
		if (aj.XMLHttpRequest.readyState == 4 && aj.XMLHttpRequest.status == 200)
		{
			for (k in Ajaxs)
			{
				if (Ajaxs[k] == aj.targetUrl)
				{
					Ajaxs[k] = null;
				}
			}
			if (aj.waitId)
			{
				aj.waitId.style.display = 'none';
			}
			
			// 判断处理类型 XML/HTML
			if (aj.recvType == 'HTML')
			{
				aj.resultHandle(aj.XMLHttpRequest.responseText, aj);
			} 
			else if (aj.recvType == 'XML')
			{
				if (aj.XMLHttpRequest.responseXML.lastChild)
				{
					aj.resultHandle(aj.XMLHttpRequest.responseXML.lastChild.firstChild.nodeValue, aj);
				} 
				else
				{
					if (ajaxdebug)
					{
						var error = mb_cutstr(aj.XMLHttpRequest.responseText.replace(/\r?\n/g, '\\n').replace(/"/g, '\\\"'), 200);
						aj.resultHandle('<root>ajaxerror<script type="text/javascript" reload="1">alert(\'Ajax Error: \\n' + error + '\');</script></root>', aj);
					}
				}
			}

			AjaxStacks[aj.stackId] = 0;
		}
	}

	/**
	 * get 方式
	 * targetUrl 请求地址
	 * resultHandle 结果句柄
	 */
	aj.get = function(targetUrl, resultHandle)
	{
		setTimeout(function(){aj.showLoading()}, 250);
		if (in_array(targetUrl, Ajaxs))
		{
			return false;
		} 
		else 
		{
			Ajaxs.push(targetUrl);
		}
		
		aj.targetUrl = targetUrl;
		aj.XMLHttpRequest.onreadystatechange = aj.processHandle;
		aj.resultHandle = resultHandle;
		var delay = attackevasive & 1 ? (aj.stackId + 1) * 1001 : 100;

		if (window.XMLHttpRequest)
		{
			setTimeout(function(){
			aj.XMLHttpRequest.open('GET', aj.targetUrl);
			aj.XMLHttpRequest.send(null);}, delay);
		} 
		else
		{
			setTimeout(function(){
			aj.XMLHttpRequest.open("GET", targetUrl, true);
			aj.XMLHttpRequest.send();}, delay);
		}
	}
	
	/**
	 * post 方式
	 */
	aj.post = function(targetUrl, sendString, resultHandle)
	{		
		setTimeout(function(){aj.showLoading()}, 250);
		if(in_array(targetUrl, Ajaxs))
		{
			return false;
		} 
		else
		{
			Ajaxs.push(targetUrl);
		}
		aj.targetUrl = targetUrl;
		aj.sendString = sendString;
		aj.XMLHttpRequest.onreadystatechange = aj.processHandle;
		aj.resultHandle = resultHandle;
		aj.XMLHttpRequest.open('POST', targetUrl);
		aj.XMLHttpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
		aj.XMLHttpRequest.send(aj.sendString);
	}

	return aj;
}

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);
   }

   if(click && duration) {
    ctrlobj.clickfunc = typeof ctrlobj.onclick == 'function' ? ctrlobj.onclick : null;
    ctrlobj.onclick = function (e) {
     doane(e);
     if(jsmenu['active'][layer] == null || jsmenu['active'][layer].ctrlkey != this.id) {
      if(this.clickfunc) this.clickfunc();
      else showMenu(this.id, true);
     } else {
      hideMenu(layer);
     }
    }
   }

   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) {
if(menuobj && !menuobj.initialized) {
   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)";
   }
}
}

function showMenu(ctrlid, click, offset, duration, timeout, layer, showid, maxh) {
e = window.event ? window.event : showMenu.caller.arguments[0];
var ctrlobj = document.getElementById(ctrlid);
if(!ctrlobj) 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 = document.getElementById(showid);
var menuobj = document.getElementById(showid + '_menu');
if(!showobj|| !menuobj) return;
if(isUndefined(maxh)) maxh = 400;

hideMenu(layer);

for(var id in jsmenu['timer']) {
   if(jsmenu['timer'][id]) clearTimeout(jsmenu['timer'][id]);
}

initCtrl(ctrlobj, click, duration, timeout, layer);
ctrlobjclassName = ctrlobj.className;
ctrlobj.className += ' hover';
initMenu(ctrlid, menuobj, duration, timeout, layer);

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)';
    document.getElementById('append_parent') ? document.getElementById('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 = document.getElementById(showid);
var menuobj = document.getElementById(showid + '_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;
   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');
   if(menuobj.style.clip && !is_opera) {
    menuobj.style.clip = 'rect(auto, auto, auto, auto)';
   }
}
}

function hideMenu(layer) {
if(isUndefined(layer)) layer = 0;
if(jsmenu['active'][layer]) {
   try {
    document.getElementById(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;
}
}

function menuoption_onclick_function(e) {
this.clickfunc();
hideMenu();
}

function menuoption_onclick_link(e) {
choose(e, this);
}

function menuoption_onmouseover(e) {
this.className = 'popupmenu_highlight';
}

function menuoption_onmouseout(e) {
this.className = 'popupmenu_option';
}

function choose(e, obj) {
var links = obj.getElementsByTagName('a');
if(links[0]) {
   if(is_ie) {
    links[0].click();
    window.event.cancelBubble = true;
   } else {
    if(e.shiftKey) {
     window.open(links[0].href);
     e.stopPropagation();
     e.preventDefault();
    } else {
     window.location = links[0].href;
     e.stopPropagation();
     e.preventDefault();
    }
   }
   hideMenu();
}
}

/**
 * AJAX 载入中
 */
function showloading(display, waiting)
{
	var display = display ? display : 'block';
	var waiting = waiting ? waiting : '页面加载中...';
	document.getElementById('ajaxwaitid').innerHTML = waiting;
	document.getElementById('ajaxwaitid').style.display = display;
}

/**
 * 是否 undefined
 */
function isUndefined(variable)
{
	return typeof variable == 'undefined' ? true : false;
}

/**
 * 计算长度
 */
function strlen(str)
{
	return (is_ie && str.indexOf('\n') != -1) ? str.replace(/\r?\n/g, '_').length : str.length;
}

function mb_strlen(str)
{
	var len = 0;
	for (var i = 0; i < str.length; i++)
    {
		len += str.charCodeAt(i) < 0 || str.charCodeAt(i) > 255 ? (charset == 'utf-8' ? 3 : 2) : 1;
	}
	return len;
}

/**
 * 去除前后空格
 */
function trim(str)
{
	return str.replace(/^\s*(.*?)[\s\n]*D/g, 'D1');
}

/**
 * 检查数组中是否存在某个值
 */
function in_array(needle, haystack)
{
	if (typeof needle == 'string' || typeof needle == 'number')
	{
		for (var i in haystack)
		{
			if (haystack[i] == needle)
			{
				return true;
			}
		}
	}
	return false;
}

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 _attachEvent(obj, evt, func, eventobj)
{
	eventobj = !eventobj ? obj : eventobj;
	if(obj.addEventListener)
	{
		obj.addEventListener(evt, func, false);
	} 
	else if(eventobj.attachEvent)
	{
		obj.attachEvent("on" + evt, func);
	}
}

/*
 * 获取浏览器版本
 */
function browserVersion(types)
{
	var other = 1;
	for (i in types)
    {
		var v = types[i] ? types[i] : i;
		if (USERAGENT.indexOf(v) != -1)
        {
			var re = new RegExp(v + '(\\/|\\s)([\\d\\.]+)', 'ig');
			var matches = re.exec(USERAGENT);
			var ver = matches != null ? matches[2] : 0;
			other = ver !== 0 && v != 'mozilla' ? 0 : other;
		}
        else
        {
			var ver = 0;
		}
		eval('BROWSER.' + i + '= ver');
	}
	BROWSER.other = other;
}

