﻿function addFavorite(site, url) {
	if(window.sidebar) {
		window.sidebar.addPanel(site, url, "");
	}
	else if(window.document) {
		window.external.AddFavorite(url, site);
	}
}
function fontZoom(id, size) {
	$(id).style.fontSize = size;
}
function encodeURL(url) {
	var index = url.indexOf("?");
	var paramstring = index == -1 ? "" : url.substring(index + 1);
	if(paramstring !== "") {
		var paramArray = paramstring.split("&");
		paramstring = "";
		for(var i = 0; i < paramArray.length; i += 1) {
			var temp = paramArray[i].split("=");
			paramstring += temp[0] + "=" + encodeURIComponent(temp[1]);
			if(i != paramArray.length - 1) {
				paramstring += "&";
			}
		}
		url = url.substring(0, index + 1) + paramstring;
	}
	return url;
}
function sendRequest(url, loadFunc, completeFunc, params, method, asyn) {
	url = encodeURL(url);
	params = params === undefined ? "" : params;
	method = method === undefined ? "get" : method;
	asyn = asyn === undefined ? true : asyn;
	new Ajax.Request(url, {
			method: method,
			parameters: params,
			onCreate: loadFunc,
			onComplete: completeFunc,
			asynchronous: asyn, 
			evalJS: true
		}
	);
}
function getYMD(date) {
	return date.getFullYear() + "-" + 
		(date.getMonth() < 9 ? "0" + (date.getMonth() + 1) : date.getMonth() + 1) + "-" + 
		(date.getDate() < 10 ? "0" + date.getDate() : date.getDate());
}
function getTodayYMD() {
	return getYMD(new Date());
}
function getWeekStartYMD() {
	var today = new Date();
	var weekDay = today.getDay();
	var num = (weekDay + 6) % 7;
	today.setTime(today.getTime() - num * 24 * 60 * 60 * 1000);
	return getYMD(today);
}
function getWeekEndYMD() {
	var today = new Date();
	var weekDay = today.getDay();
	var num = 6 - (weekDay + 6) % 7;
	today.setTime(today.getTime() + num * 24 * 60 * 60 * 1000);
	return getYMD(today);
}
function getMonthStartYMD() {
	var today = new Date();
	var monthDay = today.getDate();
	var num = monthDay - 1;
	today.setTime(today.getTime() - num * 24 * 60 * 60 * 1000);
	return getYMD(today);
}
function getMonthEndYMD() {
	var today = new Date();
	var monthDay = today.getDate();
	var num = 31 - monthDay;
	today.setTime(today.getTime() + num * 24 * 60 * 60 * 1000);
	return getYMD(today);
}
function getTodayString() {
	var today = new Date();
	return getDateString(today);
}
function getDateString(date) {
	if(typeof(date) == "string") {
		date = new Date(date.replace(/[-]/g, "/"));
	}
	var weekdays = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
	return date.getFullYear() + "年 " + (date.getMonth() + 1) + "月" + date.getDate() + "日 " + weekdays[date.getDay()];
}
function MM_jumpMenu(targ, selObj, restore) {
	eval(selObj.options[selObj.selectedIndex].value);
	if (restore) {
		selObj.selectedIndex = 0;
	}
}
function getFirstChildFromParent(parent, tagName) {
	var objArray = new Array(2);
	for(var i = 0; i < parent.childNodes.length; i += 1) {
		var child = parent.childNodes[i];
		if(child.nodeName.toLowerCase() == tagName) {
			objArray[0] = i;
			objArray[1] = child;
			return objArray;
		}
	}
}
function removeChildren(parent, fromIndex) {
	for(var i = fromIndex; i < parent.childNodes.length; i += 1) {
		parent.removeChild(parent.childNodes[i]);
	}
}
function createWaitingImage() {
	var TABLE = document.createElement("table");
	var TBODY = document.createElement("tbody");
	var TR = document.createElement("tr");
	var TD = document.createElement("td");
	var IMG = new Image();
	TABLE.align = "center";
	TABLE.width = "100%";
	TD.vAlign = "middle";
	TD.align = "center";
	TD.height = 65;
	IMG.src = "image/loading.gif";
	IMG.style.width = 39;
	IMG.style.height = 39;
	TD.appendChild(IMG);
	TR.appendChild(TD);
	TBODY.appendChild(TR);
	TABLE.appendChild(TBODY);
	return TABLE;
}
function homeNoticeRequestOnLoad() {
	var TABLE = $("right_1_table");
	var TBODY = getFirstChildFromParent(TABLE, "tbody");
	var firstTR = getFirstChildFromParent(TBODY[1], "tr");
	removeChildren(TBODY[1], firstTR[0] + 1);
	var TR = document.createElement("tr");
	var TD = document.createElement("td");
	TD.colSpan = 2;
	TD.appendChild(createWaitingImage());
	TR.appendChild(TD);
	TBODY[1].appendChild(TR);
}
function homeAcademicRequestOnLoad() {
	var DIV = $("right_2");
	var firstDIV = getFirstChildFromParent(DIV, "div");
	removeChildren(DIV, firstDIV[0] + 1);
	DIV.appendChild(createWaitingImage());
}
function respHomeNoticeRequest(transport) {
	$("right_1").innerHTML = transport.responseText;
	onloadBool1 = true;
}
function respHomeAcademicRequest(transport) {
	$("right_2").innerHTML = transport.responseText;
	onloadBool2 = true;
}
function getListRequestOnLoad() {
	var DIV = $("right");
	DIV.innerHTML = "";
	DIV.appendChild(createWaitingImage());
}
function getfootOnLoad() {

	var DIV = $("bottom");
	DIV.innerHTML = "";
	//DIV.appendChild(createWaitingImage());
}
function respGetListRequest(transport) {
	$("right").innerHTML = transport.responseText;
	hash += 1;
	if(hash > 10) {
		historyStorage.reset();
		hash = 0;
	}
	dhtmlHistory.add(hash,transport.responseText);
}
function resfootRequest(transport) {
	$("bottom").innerHTML = transport.responseText;
	
}
