// JavaScript Document
var isChrome = /Chrome/.test(navigator.userAgent);
var isOpera = /Opera/.test(navigator.userAgent), $_ID = [];
var isFF = /Gecko\/\d* Firefox/g.test(navigator.userAgent);
var isIE = /compatible; MSIE/g.test(navigator.userAgent);

Function.prototype.toString = function () { return '程序内容由“昊玄”编写完成，有事请与他联系(QQ:57659930)！'; }
String.prototype.Trim = function () { return this.replace(/^\s\s*/, '').replace(/\s\s*$/, ''); }
String.prototype.LTrim = function () { return this.replace(/^\s\s*/, ''); }
String.prototype.RTrim = function () { return this.replace(/\s\s*$/, ''); }

function clear_focus() {
	var a_Array = ['a', 'area'], i = j = 0, x;
	var nul = function () { this.blur(); }
	for (; i < a_Array.length; i++) {
		for (j = 0, x = document.getElementsByTagName(a_Array[i]); x && j < x.length; j++) {
			if (isIE) x[j].onfocus = nul; //attachEvent('onfocus', nul);
			else x[j].addEventListener('focus', nul, false);
		}
	}
	nul = a_Array = null;
}

function ID_ini() {
	var input = document.getElementsByTagName('input');
	if (! input.length) return;
	for (var i = j = 0; i < input.length; i++) if ((input[i].name == 'ID' || input[i].name == 'ID[]') && input[i].type == 'checkbox') $_ID[j++] = input[i];
	var sAll = document.getElementById('sAll');
	if (sAll) {
		var change = function () {
			var sAll = document.getElementById('sAll');
			var c = sAll.checked, i = 0;
			for (; i < $_ID.length; i++) $_ID[i].checked = c;
		}
		var click = function () {
			for (var i = 0, logic = true; i < $_ID.length; i++) {
				if (! $_ID[i].checked) { logic = false; break; }
			}
			document.getElementById('sAll').checked = logic;
		}
		for (i = 0; i < $_ID.length; i++) {
			if (isIE) $_ID[i].attachEvent('onclick', click);
			else $_ID[i].addEventListener('click', click, false);
		}
		if (isIE) sAll.attachEvent('onclick', change);
		else sAll.addEventListener('click', change, false);
	}
	if (document.forms['list']) {
		var CurrentPage = document.forms['list'].elements['CurrentPage'];
		if (CurrentPage && CurrentPage.length) {
			var change = function () { document.forms['list'].submit(); }
			if (isIE) CurrentPage.attachEvent('onchange', change);
			else CurrentPage.addEventListener('change', change, false);
		}
	}
}

function page(x) {
	var objForm = document.forms['list'];
	if (! objForm) { alert('警告：未找到指定的翻页域！'); return; }
	var obj = objForm.elements;
	if (! obj['CurrentPage'] || ! obj['CurrentPage'].length) return;
	var i = 0, MIN, MAX, Pages = obj['CurrentPage'].length ? +obj['CurrentPage'].value : 0;
	MAX = obj['CurrentPage'].length ? +obj['CurrentPage'][obj['CurrentPage'].length - 1].value : 0;
	MIN = obj['CurrentPage'].length ? +obj['CurrentPage'][0].value : 0;
	switch (x) {
		case 1: Pages = MIN; break; case 2: Pages++; break;
		case 3: Pages--; break; case 4: Pages = MAX; break;
	}
	if (Pages < MIN || Pages > MAX) return;
	for (; i < obj['CurrentPage'].length; i++) {
		if (+obj['CurrentPage'][i].value == Pages) { obj['CurrentPage'][i].selected = true; break; }
	}
	obj = null; listForm.submit();
}

function version() {
	var info = navigator.userAgent, ver;
	if (isIE) {
		ver = info.substr(info.indexOf('MSIE') + 5);
		ver = parseFloat(ver.substr(0, ver.indexOf(';')));
	}
	else if (isFF) ver = info.substr(info.lastIndexOf('/') + 1);
	else if (isOpera) ver = parseFloat(info.substr(0, info.indexOf(' ')).replace('Opera/', ''));
	else if (isChrome) {
		ver = info.substr(info.indexOf('Chrome') + 7);
		ver = ver.substr(0, ver.indexOf(' '));
	}
	return ver;
}

function fixPNG() {
	var ver = version();
	if (! isIE || (isIE && (ver < 5.5 || ver > 6))) return;
	var img = document.images, i = 0, imgName, width, height;
	for (; i < img.length; i++) {
		imgName = img[i].src.toUpperCase();
		if (imgName.substr(imgName.length - 4) !== '.PNG') continue;
		width = img[i].width; height = img[i].height;
		img[i].runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + img[i].src + "', sizingMethod='scale')";
		img[i].src = '/images/null.gif';
		img[i].width = width; img[i].height = height;
	}
}

function swf_move(width, visual_height, text_height, pics, links, texts, ID, src) {
	if (width == null) return 1;
	if (visual_height == null) return 2;
	if (text_height == null) return 3;
	if (pics == null) return 4;
	src = src == null ? 'focus.swf' : src;
	var height = visual_height + text_height;
	var swf = '\r\n<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,0,0" width="' + width + '" height="' + height + '">\r\n';
	swf += '  <param name="allowScriptAccess" value="sameDomain" />\r\n  <param name="movie" value="' + src + '" />\r\n  <param name="quality" value="high" />\r\n  <param name="bgcolor" value="#FFFFFF" />\r\n  <param name="menu" value="false" />\r\n  <param name="wmode" value="opaque" />\r\n';
	swf += '  <param name="FlashVars" value="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + width + '&borderheight=' + visual_height + '&textheight=' + text_height + '" />\r\n';
	swf += '  <embed src="' + src + '" wmode="opaque" FlashVars="pics=' + pics + '&links=' + links + '&texts=' + texts + '&borderwidth=' + width + '&borderheight=' + visual_height + '&textheight=' + text_height + '" menu="false" bgcolor="#F0F0F0" quality="high" width="' + width + '" height="' + visual_height + '" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer" />\r\n</object>\r\n';
	if (ID == null || ID == '') document.write(swf); else document.getElementById(ID).innerHTML = swf;
}

window.onload = function () {
	clear_focus(); fixPNG(); ID_ini();
	if (typeof(autorun) == 'function') autorun();
}
