var uagent=navigator.userAgent.toLowerCase();
var win = window;
var n = 0;
var isIE, isGecko, isOpera, isSafari, isKonqueror, isWin, isMac, uaVers;
	isIE=(uagent.indexOf("msie")!=-1 && document.all);
	t2g2_bIsIE5=(uagent.indexOf("msie")!=-1 && document.all);
	isGecko = (uagent.indexOf("gecko") != -1);
	isOpera = (uagent.indexOf("opera") !=-1); 
	isSafari = (uagent.indexOf("safari") != -1);
	isKonqueror = (uagent.indexOf("konqueror") != -1);
	isWin    =  ( (uagent.indexOf("win") != -1) || (uagent.indexOf("16bit") !=- 1) );
	isMac    = ( (uagent.indexOf("mac") != -1) || (navigator.vendor == "Apple Computer, Inc.") );
	uaVers   = parseInt(navigator.appVersion);
function get_cookie( name ) {
	cname =  name + '=';
	cpos  = document.cookie.indexOf( cname );
	if ( cpos != -1 ) {
		cstart = cpos + cname.length;
		cend   = document.cookie.indexOf(";", cstart);
		if (cend == -1) {
			cend = document.cookie.length;
		}
		return unescape( document.cookie.substring(cstart, cend) );
	}
	return null;
}
function togglediv( id, show )
{
	if ( show ) {
		my_show_div( my_getbyid(id) );
	} else {
		my_hide_div( my_getbyid(id) );
	}
	return false;
}
function set_cookie( name, value, cookiedate ) {
	expire = "";
	domain = "";
	path   = "/";
	if ( cookiedate ) {
		expire = "; expires=Wed, 1 Jan 2020 00:00:00 GMT";
	}
	document.cookie =  name + "=" + value + "; path=" + path + expire + domain + ';';
}
function multi_page_jump( url_bit, totalposts, perpage ) {
	pages = 1;
	cur_pp = current_page;
	curpage  = 1;
	if ( totalposts % perpage == 0 ) {
		pages = totalposts / perpage;
	} else 	{
		pages = Math.ceil( totalposts / perpage );
	}
	msg = " 页数 "+pages;
	if ( cur_pp > 0 ) {
		curpage = cur_pp / perpage;
		curpage = curpage -1;
	}
	show_page = 1;
	if ( curpage < pages ) {
		show_page = curpage + 1;
	}
	if ( curpage >= pages ) {
		show_page = curpage - 1;
	} else 	{
 		show_page = curpage + 1;
 	}
	userPage = prompt( msg, show_page );
	if ( userPage > 0  ) {
		if ( userPage < 1 ) {
			userPage = 1;
		}
		if ( userPage > pages ) { 
			userPage = pages;
		}
		if ( userPage == 1 ) {
			start = 0;
		} else {
			start = (userPage - 1) * perpage;
		}
		window.location = url_bit + "&page=" + start;
	}
}
function showHide(id1, id2) {
	if (id1 != '') toggleview(id1);
	if (id2 != '') toggleview(id2);
}
function my_getbyid(id) {
	itm = null;
	if (document.getElementById) {
		itm = document.getElementById(id);
	} else if (document.all)	{
		itm = document.all[id];
	} else if (document.layers) {
		itm = document.layers[id];
	}
	return itm;
}
function toggleview(id) {
	if ( ! id ) return;
	if ( itm = my_getbyid(id) ) {
		if (itm.style.display == "none") {
			my_show_div(itm);
		} else {
			my_hide_div(itm);
		}
	}
}
function my_hide_div(id) {
	if ( ! id ) return;	
	id.style.display = "none";
}
function my_show_div(id) {
	if ( ! id ) return;
	id.style.display = "";
}
function change_cell_color( id, cl ) {
	itm = my_getbyid(id);
	if ( itm )	{
		itm.className = cl;
	}
}
function PopUp(url, name, width,height,center,resize,scroll,posleft,postop) {
	showx = "";
	showy = "";
	if (posleft != 0) { X = posleft }
	if (postop  != 0) { Y = postop  }
	if (!scroll) { scroll = 1 }
	if (!resize) { resize = 1 }
	if ((parseInt (navigator.appVersion) >= 4 ) && (center)) {
		X = (screen.width  - width ) / 2;
		Y = (screen.height - height) / 2;
	}
	if ( X > 0 )	{ showx = ',left='+X; }
	if ( Y > 0 )	{ showy = ',top='+Y; }
	if (scroll != 0) { scroll = 1 }
	var Win = window.open( url, name, 'width='+width+',height='+height+ showx + showy + ',resizable='+resize+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no');
}
function stacksize(thearray) {
	for (i = 0 ; i < thearray.length; i++ ) {
		if ( (thearray[i] == "") || (thearray[i] == null) || (thearray == 'undefined') ) return i;
	}
	return thearray.length;
}
function pushstack(thearray, newval) {
	arraysize = stacksize(thearray);
	thearray[arraysize] = newval;
}
function popstack(thearray) {
	arraysize = stacksize(thearray);
	theval = thearray[arraysize - 1];
	delete thearray[arraysize - 1];
	return theval;
}
function CheckAll(fmobj) {
	for (var i=0;i<fmobj.elements.length;i++) {
		var e = fmobj.elements[i];
		if ((e.name != 'allbox') && (e.type=='checkbox') && (!e.disabled)) {
			e.checked = fmobj.allbox.checked;
		}
	}
}
function HighlightAll(str) {
    if (document.all){
        var rng = document.body.createTextRange();
        rng.moveToElementText(str);
        rng.scrollIntoView();
        rng.select();
        rng.execCommand("Copy");
        rng.collapse(false);
		setTimeout("window.status=''",1800)
    }
}
function redirlocate(object) {
	if(object.options[object.selectedIndex].value != '') {
		window.location = (object.options[object.selectedIndex].value);
	}
}
function SelectTag(){
	var target = my_getbyid('selectall').checked;
	if (target == true)
	{
		SelectAll();
	} else {
		NoneAll();
	}
}
function SelectAll(){
	var rows = document.profile.getElementsByTagName('tr');
	var unique_id;
	var marked_row = new Array;
    var checkbox;
	for ( var i = 0; i < rows.length; i++ ) {
        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            if ( checkbox.disabled == false ) {
                checkbox.checked = true;
                if ( typeof(marked_row[unique_id]) == 'undefined' || !marked_row[unique_id] ) {
                    rows[i].className += ' marked';
                    marked_row[unique_id] = true;
                }
            }
	    }
	}
}
function NoneAll(){
	var rows = document.profile.getElementsByTagName('tr');
    var unique_id;
    var checkbox;
	var marked_row = new Array;
	for ( var i = 0; i < rows.length; i++ ) {

        checkbox = rows[i].getElementsByTagName( 'input' )[0];

        if ( checkbox && checkbox.type == 'checkbox' ) {
            unique_id = checkbox.name + checkbox.value;
            checkbox.checked = false;
            rows[i].className = rows[i].className.replace(' marked', '');
            marked_row[unique_id] = false;
        }
	}

	return true;
} 
function pop_win(theUrl, winName, theWidth, theHeight)
{
	if (winName == '') { winName = 'Preview'; }
	if (theHeight == '') { theHeight = 400; }
	if (theWidth == '') { theWidth = 400; }
	window.open(theUrl,winName,'width='+theWidth+',height='+theHeight+',resizable=yes,scrollbars=yes');
}
function togglediv( id, show )
{
	if ( show ) {
		my_show_div( my_getbyid(id) );
	} else {
		my_hide_div( my_getbyid(id) );
	}
	return false;
}
function togglemenucategory( fid, add )
{
	saved = new Array();
	clean = new Array();
	if ( tmp = get_cookie('cpcollapseprefs') ) {
		saved = tmp.split(",");
	}
	for( i = 0 ; i < saved.length; i++ ) {
		if ( saved[i] != fid && saved[i] != "" ) {
			clean[clean.length] = saved[i];
		}
	}
	if ( add ) {
		clean[ clean.length ] = fid;
		my_show_div( my_getbyid( 'fc_'+fid  ) );
		my_hide_div( my_getbyid( 'fo_'+fid  ) );
	} else {
		my_show_div( my_getbyid( 'fo_'+fid  ) );
		my_hide_div( my_getbyid( 'fc_'+fid  ) );
	}
	set_cookie( 'cpcollapseprefs', clean.join(','), 1 );
}

function expandmenu()
{
	saved = new Array();
	joined = new Array();
	clean = new Array();
	if ( tmp = get_cookie('cpcollapseprefs') ) {
		saved = tmp.split(",");
	}
	joined = menu_ids.split(",");
	for( c = 0 ; c < joined.length; c++ ) {
		clean[clean.length] = joined[c];
	}
	set_cookie( 'cpcollapseprefs', clean.join(','), 1 );
	window.location=window.location;
}
function collapsemenu()
{
	set_cookie( 'cpcollapseprefs', '', 1 );
	window.location=window.location;
}

function checkcol(IDnumber,status)
{
	var f = document.cpform;
	str_part = '';
	if (IDnumber == 1) { str_part = 'read' }
	if (IDnumber == 2) { str_part = 'repl' }
	if (IDnumber == 3) { str_part = 'star' }
	if (IDnumber == 4) { str_part = 'uplo' }
	if (IDnumber == 5) { str_part = 'show' }
	for (var i = 0 ; i < f.elements.length; i++) {
		var e = f.elements[i];
		if ( e.type == 'checkbox' ) {
			s = e.name;
			a = s.substring(0, 4);
			if (a == str_part) {
				if ( status == 1 ) {
					e.checked = true;
				} else {
					e.checked = false;
				}
			}
		}
	}
}

function checkrow(IDnumber,status)
{
	var f = document.cpform;
	str_part = '';
	if ( status == 1 ) {
		mystat = 'true';
	} else {
		mystat = 'false';
	}
	eval( 'f.read_'+IDnumber+'.checked='+mystat );
	eval( 'f.reply_'+IDnumber+'.checked='+mystat );
	eval( 'f.start_'+IDnumber+'.checked='+mystat );
	eval( 'f.upload_'+IDnumber+'.checked='+mystat );
	eval( 'f.show_'+IDnumber+'.checked='+mystat );
}

function updatepreview()
{
	var formobj  = document.cpform;
	var dd_weekday  = new Array();
	dd_weekday[0]   = '周日';
	dd_weekday[1]   = '周一';
	dd_weekday[2]   = '周二';
	dd_weekday[3]   = '周三';
	dd_weekday[4]   = '周四';
	dd_weekday[5]   = '周五';
	dd_weekday[6]   = '周六';
	var output       = '';
	chosen_min   = formobj.minute.options[formobj.minute.selectedIndex].value;
	chosen_hour  = formobj.hour.options[formobj.hour.selectedIndex].value;
	chosen_weekday  = formobj.weekday.options[formobj.weekday.selectedIndex].value;
	chosen_monthday  = formobj.monthday.options[formobj.monthday.selectedIndex].value;
	var output_min   = '';
	var output_hour  = '';
	var output_day   = '';
	var timeset      = 0;
	if ( chosen_monthday == -1 && chosen_weekday == -1 ) {
		output_day = '';
	}
	if ( chosen_monthday != -1 ) {
		output_day = '在每月 '+chosen_monthday+' 号，';
	}
	if ( chosen_monthday == -1 && chosen_weekday != -1 ) {
		output_day = '于' + dd_weekday[ chosen_weekday ]+'.';
	}
	if ( chosen_hour != -1 && chosen_min != -1 ) {
		output_hour = '在 '+chosen_hour+':'+formatnumber(chosen_min)+' 的时候运行';
	} else {
		if ( chosen_hour == -1 ) {
			if ( chosen_min == 0 ) {
				output_hour = '每小时运行一次';
			} else {
				if ( output_day == '' ) {
					if ( chosen_min == -1 ) {
						output_min = '每分钟运行一次';
					} else {
						output_min = '每隔 '+chosen_min+' 分钟运行一次。';
					}
				} else {
					output_min = '第一个 '+formatnumber(chosen_min)+' 分钟的时候执行';
				}
			}
		} else {
			if ( output_day != '' ) {
				output_hour = '到 ' + chosen_hour + ':00' + ' 运行';
			} else {
				output_hour = '每隔 ' + chosen_hour + ' 小时运行';
			}
		}
	}
	output = output_day + ' ' + output_hour + ' ' + output_min;
	formobj.showcron.value = output;
}
							
function formatnumber(num)
{
	if ( num == -1 ) {
		return '00';
	}
	if ( num < 10 ) {
		return '0'+num;
	} else {
		return num;
	}
}

function findInPage(tmpl, str)
{
	var txt, i, found;
	if (str == '') {
		return false;
	}
	if (isGecko) {
		if (!win.find(str, false, true)) {
			while(win.find(str, false, true)) {
				n++;
			}
		} else {
			n++;
		}
		if (n == 0) {
			alert('未找到要搜索的字符');
		}
	}
	if (isIE) {
		txt = tmpl.createTextRange();
		for (i = 0; i <= n && (found = txt.findText(str)) != false; i++) {
			txt.moveStart('character', 1);
			txt.moveEnd('textedit');
		}
		if (found) {
			txt.moveStart('character', -1);
			txt.findText(str);
			txt.select();
			txt.scrollIntoView(true);
			n++;
		} else {
			if (n > 0) {
				n = 0;
				findInPage(tmpl, str);
			}
			else { alert('未找到要搜索的字符'); }
		}
	}
	return false;
}
var postmaxchars = "20000";
var postminchars = "4";
function getMessageLength() {
	mxeGet();
	return calculate_byte(mxeTxH.value); 
}
function checklength() {
	if (postmaxchars != 0) message = "最大允许的长度为 "+postmaxchars+" 个字符。";
	else message = "";
	var messageLength = getMessageLength();
	alert("现在你已经输入了 "+messageLength+" 个字符。" + message);
}
function calculate_byte( sTargetStr ) { 
	var sTmpStr, sTmpChar; 
	var nOriginLen = 0; 
	var nStrLength = 0; 

	sTmpStr = new String(sTargetStr); 
	nOriginLen = sTmpStr.length; 

		for ( var i=0 ; i < nOriginLen ; i++ ) { 
		sTmpChar = sTmpStr.charAt(i); 
			if (escape(sTmpChar).length > 4) { 
			nStrLength += 2; 
			} else if (sTmpChar!='\r') { 
			nStrLength ++; 
			} 
		} 
	return nStrLength; 
}
function submit_form(){
	var subform = document.subform;
	mxeGet();
	var length = calculate_byte(mxeTxH.value);
	if (length < 4 && length > 20000) {
		alert("输入内容字数不符。");
		return false;
	}
}

function selectAll(formObj)
{
	if(formObj){
		var formGet = my_getbyid(formObj);
	}else{
		var formGet = my_getbyid("mainform");
	}
	for (var i=0;i<formGet.elements.length;i++) 
	{
		var e = formGet.elements[i];
		if ((e.name == 'cmdid[]')&&(e.type=='checkbox')) 
		{
			if(e.checked == true){
				e.checked = false;
			}else{
				e.checked = true;
			}
		}
	}
}

function jumpMenu(targ,selObj,restore){
	eval(targ+".location='?"+LimitedOder+"&area=1&id="+selObj.options[selObj.selectedIndex].value+"'");
	if (restore) selObj.selectedIndex=0;
}

function Login(){
	var sHTML = '<div style="padding:5px 0px 0px 0px; width:100%;" align=center height:20px;>&nbsp;</div>'+
		'<table border="0" cellpadding="0" cellspacing="10" style="margin-left:10px;"><tr><td align="right" width:25%;>用户名:&nbsp;&nbsp;&nbsp;</td><td align="left"><input type="text" name="username_ajax" id="username_ajax" class="bginput" onMouseOver = "focus()"></td><td rowspan=2><img src="./images/style_1/log_b.gif" align="absmiddle" onclick="PostUser()" style="cursor:hand;" /></td></tr><tr><td valign="middle" align="right">密&nbsp;&nbsp;&nbsp;码:&nbsp;&nbsp;&nbsp;</td><td valign="middle" align="left"><input type="password" name="password_ajax" id="password_ajax" class="bginput" size=20 onkeydown="if( event.keyCode==13){PostUser()}"></td></tr><tr><td colspan=2><strong>Cookies 时效:</strong>&nbsp;&nbsp;<input type="radio" name="cookiedate" value="31536000" checked="checked" /> 一年 &nbsp;<input type="radio"  name="cookiedate" value="2592000" /> 一个月 &nbsp;<input type="radio"  name="cookiedate" value="86400" /> 一天  &nbsp;<input type="radio"  name="cookiedate" value="0" /> 浏览器进程  </td></tr></table><div id="warning" style="width:100%;height:20px;padding-top:7px;margin:0;" align="center"></div><div style="background-color:#f3f3f3;height:20px;padding-top:10px;" align="left"><div style="float:right;"><img src="./images/style_1/MeegoLogo-F.gif" align="absmiddle" />&nbsp;&nbsp;&nbsp;</div>&nbsp;&nbsp;&nbsp;<a href="register.php">注册新用户</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="login.php?action=forget">忘记密码</a>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:window.neatDialog.close();">取消</a></div>';
	new NeatDialog(sHTML, "用户登录", false, 100, 20);
}

function loading(){
	var sHTML = '<div style="padding:5px 0px 0px 0px; width:100%;" align=center height:20px;>&nbsp;</div>'+
		'<table border="0" cellpadding="0" cellspacing="10" style="margin-left:10px;"><tr><td align="center" width:100%;><img src="images/ajax/loading.gif"><div style="width:80%;padding-top:20px;color:#FF6600;font-size:14px;font-weight:bold;">正在上传图片，请耐心等候，上传时间取决与你的网速和图片大小。</div></td></tr></table><div id="warning" style="width:100%;height:20px;padding-top:7px;margin:0;" align="center"></div><div style="background-color:#f3f3f3;height:20px;padding-top:10px;" align="left"><div style="float:right;"><img src="./images/style_1/MeegoLogo-F.gif" align="absmiddle" />&nbsp;&nbsp;&nbsp;</div>&nbsp;&nbsp;&nbsp;&nbsp;<a href="javascript:window.neatDialog.close();">取消</a></div>';
	new NeatDialog(sHTML, "正在上传图片......", false, 100, 20);
}

