var forIE = true;
var currentTab = null;

var i = 5;
var infoDlg;
var objWindow;
var urlRedirect;

function Goto(url)
{
	window.location.href = url;
}

function DialogBase(urlDlg, options)
{
	return window.showModalDialog('/scl2006/dialog.htm?' + urlDlg, window, options);
}
function Dialog(urlDlg, width, height)
{
	options = "center:yes;help:no;resizable:no;status:no;scroll:no;dialogWidth:" +
				width + ";dialogHeight:" + height;
	return DialogBase(urlDlg, options);
}

function ModelessDialogBase(urlDlg, options)
{
	return window.showModelessDialog('/scl2006/dialog.htm?' + urlDlg, window, options);
}
function ModelessDialog(urlDlg, width, height)
{
	options = "center:yes;help:no;resizable:no;status:no;scroll:no;dialogWidth:" +
				width + "px;dialogHeight:" + height + "px";
	return ModelessDialogBase(urlDlg, options);
}

function SetDialogTitle(txtTitle)
{
	var HexA0s = "%A0 %A0 %A0 %A0";
	SetTitle(txtTitle + unescape(HexA0s));
}
function SetTitle(txtTitle)
{
	document.title = txtTitle;
}

function DisplayInfo(info)
{
	var divInfo = document.getElementById("infoServerMessage");
	if (divInfo == null) return;

	divInfo.attachEvent("onclick", ClearInfo);
	divInfo.style.display = "inline-block";
	divInfo.innerHTML = info;
}
function AppendInfo(info)
{
	var divInfo = document.getElementById("infoServerMessage");
	if (divInfo == null) return;

	divInfo.innerHTML += info;
}
function ClearInfo()
{
	var divInfo = document.getElementById("infoServerMessage");
	if (divInfo == null) return;

	divInfo.style.display = "none";
	divInfo.innerHTML = "";
}

function CloseDialog(info)
{
	i = 5;
	infoDlg = info;
	clock();
}
function clock()
{
	i = i - 1;
	if (i > 0)
		setTimeout("clock();", 1000);
	else
		close();

	DisplayInfo(infoDlg + "<br/>关闭倒计时：" + i + "秒");
}

function Modify(formId)
{
	var src = event.srcElement;
	
	var readonly = false;
	if (src != null && src.type == "checkbox")
		readonly = !src.checked;
		
	var form = document.getElementById(formId);
	var textareas = form.getElementsByTagName("textarea");
	for (i = 0; i < textareas.length; i ++)
	{
		textareas[i].readOnly = readonly;
	}
	var inputs = form.getElementsByTagName("input");
	for (i = inputs.length - 1; i >= 0; i --)
	{
		if (inputs[i].type == "text" ||
			inputs[i].type == "radio" ||
			inputs[i].type == "checkbox" ||
			inputs[i].type == "password")
		{
			inputs[i].readOnly = readonly;
			if (inputs[i] != src) inputs[i].focus();
		}
		else
		{
			if (inputs[i].name != "close")inputs[i].disabled = readonly;
		}
	}
}

function CloseDialogAndRedirect(info, windowOpener, url)
{
	i = 5;
	infoDlg = info;
	objWindow = windowOpener;
	urlRedirect = url;
	Redirect();
}

function Redirect()
{
	DisplayInfo(infoDlg);

	if (i > 0)
	{
		AppendInfo("<br/>离开此页面剩余时间：" + i + "秒");
		setTimeout("Redirect()", 1000);
		i = i - 1;
	}
	else
	{
		if (objWindow == null)
		{
			if (urlRedirect.length > 0) window.document.location.href = urlRedirect;
		}
		else
		{
			objWindow.document.location.reload();
		}
	}

}

function initTabs(evt, currentTabId)
{
	evt = evt ? evt : (window.event ? window.event : null);
	if (evt != null && evt.target) forIE = false;
	currentTab = document.getElementById(currentTabId);
}
function tabOn(idTabPage, evt)
{
	evt = evt ? evt : (window.event ? window.event : null);
	tabPage = document.getElementById(idTabPage);
	tabPage.style.display = "block";
	if (currentTab != null)
		setClass((forIE ? currentTab.parentElement : currentTab.parentNode), "");
	if (evt == null) return;
	currentTab = (forIE ? evt.srcElement : evt.target);
	setClass((forIE ? currentTab.parentElement : currentTab.parentNode), "current");
}
function tabOff(idTabPage)
{
	tabPage = document.getElementById(idTabPage);
	tabPage.style.display = "none";
}
function setClass(element, cssClass)
{
	if (element == null) return;
	if (forIE)
		element.className = cssClass;
	else
		element.setAttribute("class", cssClass);
}

function SetFrameWidth(parentWindow, frameId, width)
{
	if (parentWindow == null) return;
	frame = parentWindow.document.getElementById(frameId);
	if (frame == null) return;
	frame.width = width;
}

function SetFrameHeight(parentWindow, frameId, height)
{
	if (parentWindow == null) return;
	frame = parentWindow.document.getElementById(frameId);
	if (frame == null) return;
	frame.height = height;
}

function SetTermsDisplay(displayMode)
{
	var funcs = document.getElementById("funcs");
	var terms = funcs.getElementsByTagName("ul");
	for (i = 0; i < terms.length; i ++)
	{
		var term = terms[i];
		if (term.className == "terms")
		{
			term.style.display = displayMode;
		}
		else if (term.className == "classes")
		{
			for (n = 0; n < term.childNodes.length; n ++)
			{
				term.childNodes[n].className = displayMode;
			}
		}
	}
}

function ShowTerms(button, toggleButtonOnly)
{
	if (toggleButtonOnly == null || toggleButtonOnly)
		SetTermsDisplay("block");
	if (button != null)
	{
		button.className = "ButtonHideTerms";
		button.innerHTML = "更细分类";
	}
}

function HideTerms(button, toggleButtonOnly)
{
	if (toggleButtonOnly == null || toggleButtonOnly)
		SetTermsDisplay("none");
	if (button != null)
	{
		button.className = "ButtonShowTerms";
		button.innerHTML = "更细分类";
	}
}

function ToggleTermsDisplayMode(buttonId, toggleButtonOnly)
{
	var button = GetButton(buttonId);
	if (button == null) return;

	if (button.className == "ButtonShowTerms")
	{
		ShowTerms(button, toggleButtonOnly);
	}
	else
	{
		HideTerms(button, toggleButtonOnly);
	}
}

function GetButton(buttonId)
{
	if (buttonId == null)
	{
		if (event == null) return null;
		return event.srcElement;
	}
	return document.getElementById(buttonId);
}

function InitButtonTermsDisplayMode(buttonId)
{
	HideTerms(GetButton(buttonId));
}

var marquee;
var marContent;
var marOutput;
var MyMar;
var marqueeHeight = 200;

function Marquee()
{
	if((marOutput.offsetTop - marquee.scrollTop) <= marqueeHeight - marContent.offsetHeight)
	{
		marquee.scrollTop -= marContent.offsetHeight;
	}
	else
		marquee.scrollTop ++;

	return;

}

function InitMarquee(idMarquee, idMarqueeContent, idMarqueeOutput, delay, height)
{
	if (height >= 0) marqueeHeight = height;
	
	marquee = document.getElementById(idMarquee);
	if (marquee == null) return;
	marquee.style.height = marqueeHeight + "px";
	marContent = document.getElementById(idMarqueeContent);
	if (marContent == null) return;
	marOutput = document.getElementById(idMarqueeOutput);
	if (marOutput == null) return;
	marOutput.innerHTML = marContent.innerHTML;

	MyMar = setInterval(Marquee, delay);
	marquee.onmouseover = function() { clearInterval(MyMar); };
	marquee.onmouseout = function() { MyMar = setInterval(Marquee, delay); };
}
