	var ieFlag = ( (navigator.appName).match(/Internet Explorer/) == null ) ? false : true;

	function getURLParams()
	{
		var urlString = new String(window.location);
		var urlIndex = urlString .indexOf('?');
		if(urlIndex == -1)
			return null;

		var paramStr = urlString .substr(urlIndex+1);
		var args = paramStr.split('&');
		for(var i=0; i<args.length; i++)
			args[i] = args[i].split('=');

		return args;
	}

	function getURLParamValue(key)
	{
		if(key == null)
			return ;

		var args = getURLParams();
		if(args == null)
			return args;

		for(var i=0; i< args.length; i++)
			if(args[i][0] == key)
				return args[i][1];
	}

	

	//開啟日期選擇器
	function DoCal(elTarget,elRoot) {

		var addiStr = (DoCal.arguments.length > 2 && DoCal.arguments[1]) ? '?mod=datetime' : '';
		var dialogHeight = (DoCal.arguments.length > 2 && DoCal.arguments[1]) ? '200' : '180';

		if (window.showModalDialog)
		{
			var sRtn;
			if (elRoot!="1")
			   sRtn = showModalDialog("../include/calendar.php"+addiStr,"","center=yes;dialogWidth=250pt;dialogHeight="+dialogHeight+"pt");
			else
			   sRtn = showModalDialog("include/calendar.php"+addiStr,"","center=yes;dialogWidth=250pt;dialogHeight="+dialogHeight+"pt");

			if (sRtn!="")
				elTarget.value = sRtn;
		}
		else
		{
			//alert("Internet Explorer 4.0 or later is required.")
			var sRtn;
			if (elRoot!="1")
			   sRtn = window.open("../include/calendar.php"+addiStr,"","center=yes;width=250px;height="+dialogHeight+"px");
			else
			   sRtn = window.open("include/calendar.php"+addiStr,"","center=yes;width=250px;height="+dialogHeight+"px");
			if (sRtn!="")
				elTarget.value = sRtn;
		}
	}

	function term(str)
	{
		if(str == null)
			return '';
		return str.replace(/(^\s+)|(\s+$)/g, '');
	}

	function toClassSearch()
	{
		location.href = './info_class_behalf.php';

	}

	function floatWindow(bgColor, innerObj, innerObjWidth, innerObjHeight, titleStr)
	{
		var innerObjX = innerObjWidth;
		var innerObjY = innerObjHeight;

		//判斷瀏覽器版本
		var ieFlag = ( (navigator.appName).match(/Internet Explorer/) == null ) ? false : true;
		var floatDiv = document.createElement('DIV');
		var focusDiv = document.createElement('DIV');
		var bottomDiv = document.createElement('DIV');
		var toolsDiv = document.createElement('DIV');
		var contentDiv = document.createElement('DIV');

		//判斷浮動視窗是否已存在
		if(document.getElementById('floatWindowObj') == null)
		{
			//宣告變數
			var opacity = 5;
			var clientWidth = parseInt(getBodyAttr('clientWidth'), 10);
			var clientHeight = parseInt(getBodyAttr('clientHeight'), 10);
			var divWidth = clientWidth;
			//var divHeight = clientHeight;
			var divHeight = parseInt(getBodyAttr('scrollHeight'), 10);
			divHeight = (divHeight > clientHeight) ? divHeight : clientHeight;
			//設定浮動Div屬性
			floatDiv.id = 'floatWindowObj';
			floatDiv.style.width = divWidth;
			floatDiv.style.height = divHeight;
			floatDiv.style.position = 'absolute';
			floatDiv.style.top = 0;
			floatDiv.style.left = 0;
			floatDiv.style.zIndex = 1;
			//設定視覺效果
			bgColor = (bgColor==null || bgColor=='') ? '#6699FF' : bgColor;
			floatDiv.style.backgroundColor = bgColor;
			if(ieFlag)
			{
				floatDiv.style.filter  = 'alpha(opacity='+parseInt(opacity*4);
				floatDiv.style.filter += '    , finishopacity='+parseInt(opacity * 18);
				floatDiv.style.filter += '    , style='+1;
				floatDiv.style.filter += '    , startx='+0;
				floatDiv.style.filter += '    , starty='+0;
				floatDiv.style.filter += '    , finishx='+clientWidth;
				floatDiv.style.filter += '    , finishy='+clientHeight;
				floatDiv.style.filter += ')';
			}
			else
				floatDiv.style.MozOpacity = opacity / 10;
			document.body.appendChild(floatDiv);

			//設定作用Div屬性
			focusDiv.id = 'focusDiv';
			focusDiv.style.backgroundColor = '#FFFFFF';
			focusDiv.style.borderWidth = 1;
			focusDiv.style.borderStyle = 'solid';
			focusDiv.style.borderColor = '#000000';
			focusDiv.style.width = ( innerObjX==null || innerObjX=='' || isNaN(parseInt(innerObjX, 10)) ) ? clientWidth*0.6 : parseInt(innerObjX, 10);
			focusDiv.style.height = ( innerObjY==null || innerObjY=='' || isNaN(parseInt(innerObjY, 10)) ) ? clientHeight*0.6 : parseInt(innerObjY, 10);
			focusDiv.style.position = 'absolute';
			//作用Div放置位置
			var position_top = clientHeight - parseInt(focusDiv.style.height);
			var position_left = clientWidth - parseInt(focusDiv.style.width);
			focusDiv.style.top = position_top/2;
			focusDiv.style.left = position_left/2;
			focusDiv.style.zIndex = 13;
			document.body.appendChild(focusDiv);

			//設定作用Div底的屬性
			bottomDiv.id = 'bottomDiv';
			bottomDiv.style.backgroundColor = '#808080';
			bottomDiv.style.position = 'absolute';
			bottomDiv.style.width = parseInt(focusDiv.style.width, 10);
			bottomDiv.style.height = parseInt(focusDiv.style.height, 10) + 20;
			bottomDiv.style.top = parseInt(focusDiv.style.top, 10)+3;
			bottomDiv.style.left = parseInt(focusDiv.style.left, 10)+3;
			bottomDiv.style.zIndex = 12;
			document.body.appendChild(bottomDiv);
		}

		//工具列
		toolsDiv.id = 'toolsDiv';
		toolsDiv.align = 'center';
		toolsDiv.style.background = '#DEBF87';
		toolsDiv.style.height = '20px';
		var leftDiv = document.createElement('div');
		leftDiv.style.styleFloat = 'left';
		leftDiv.innerHTML = '　◎'+titleStr;
		var rightDiv = document.createElement('div');
		rightDiv.style.styleFloat = 'right';
		rightDiv.innerHTML = '<span title="關閉視窗" style="cursor: pointer;" onclick="closeFloatWindow();">[關閉視窗]<img src="./img/admin_iconDel.gif" border=0 /></span>';
		toolsDiv.appendChild(leftDiv);
		toolsDiv.appendChild(rightDiv);
		focusDiv.appendChild(toolsDiv);

		//加入內容
		contentDiv.id = 'contentDiv';
		focusDiv.appendChild(contentDiv);
		contentDiv.style.backgroundColor = '#FFFFFF';
		contentDiv.style.width = '100%';
		contentDiv.style.height = parseInt(innerObjY, 10);
		contentDiv.style.overflowX = 'hidden';
		contentDiv.style.overflow = 'auto';
		if(innerObj != null)
			contentDiv.innerHTML = innerObj;

		focusDiv.focus();

		//回傳內容視窗
		return contentDiv;
	}

	//關閉視窗
	function closeFloatWindow() {
		var nodes = new Array('floatWindowObj', 'focusDiv', 'bottomDiv');
		for(var i=0; i<nodes.length; i++)
			if(document.getElementById(nodes[i]) != null)
			{
				var obj = $(nodes[i]);
				//刪除根節點
				var pnObj = obj.parentNode;
				if(pnObj != null) pnObj.removeChild(obj);
			}

		//window.location.reload();
	}

	function removeObjChilds(obj)
	{
		if(obj != null) {
			var nodeList = obj.childNodes;
			for(var i=0; i<nodeList.length; i++) {
				removeObjChilds(nodeList[i]);
				obj.removeChild(nodeList[i]);
			}
		}
	}

	function resizeFloatWindow()
	{
		var floatDiv = document.getElementById('floatWindowObj');
		var focusDiv = document.getElementById('focusDiv');
		var bottomDiv = document.getElementById('bottomDiv');
		var clientWidth = parseInt(getBodyAttr('clientWidth'), 10);
		var clientHeight = parseInt(getBodyAttr('clientHeight'), 10);
		var divWidth = clientWidth;
		var divHeight = parseInt(getBodyAttr('scrollHeight'), 10);

		if(floatDiv != null)
		{
			divHeight = (divHeight > clientHeight) ? divHeight : clientHeight;
			floatDiv.style.width = divWidth;
			floatDiv.style.height = divHeight;

			if(focusDiv != null)
			{
				var position_top = clientHeight - parseInt(focusDiv.style.height);
				var position_left = clientWidth - parseInt(focusDiv.style.width);
				focusDiv.style.top = position_top/2;
				focusDiv.style.left = position_left/2;

				if(bottomDiv!=null)
				{
					bottomDiv.style.top = parseInt(focusDiv.style.top, 10)+3;
					bottomDiv.style.left = parseInt(focusDiv.style.left, 10)+3;
				}
			}
		}
	}

	function getBodyAttr(attrName)
	{
		var result = null;
		var obj = window.document.body;
		for(var i in obj)
			if(i.indexOf(attrName) != -1)
			{
				result = obj[i];
				break;
			}

		return result;
	}

	//取得新增科目表單
	function requireNewCoursesForm(callBackFun)
	{
		var contentObj = floatWindow('#6699FF', null, 650, 220, '即時新增科目資料');
		var imgObj = document.createElement('IMG');	//建立圖片標籤
		imgObj.src = './img/20-0.gif';
		imgObj.border = 0;
		var newText = document.createTextNode('產生新增科目表單, 請稍後.....');	//建立字串物件
		contentObj.appendChild(imgObj);
		contentObj.appendChild(newText);

		//取得表單資料
		var URL = './info_course_add_main.php?mod=getNewCourseForm';
		var requestObj = new Ajax.Request(URL, {
			method: 'post',
			parameters: 'target='+contentObj.id,
			onSuccess: function(transport) {

				contentObj.style.backgroundColor = '#EAE4C5';
				var ieFlag = ( (navigator.appName).match(/Internet Explorer/) == null ) ? false : true;
				if(ieFlag)
					contentObj.innerHTML = transport.responseText;
				else {
					$('requireContent').innerHTML = transport.responseText;
					closeFloatWindow();
				}

				//執行後續Function
				callBackFun();
			}
		});
	}

	//取得新增講師表單
	function requireNewForm(URL, formSize, formTitle, callBackFun, targetSpace)
	{
		//如果URL沒有資料, 無法要求表單被產生
		if(URL == null || URL == '') return false;

		if(formSize == null || formSize.size() < 2) {
			formSize = [650, 300];
		}

		var contentObj = floatWindow('#6699FF', null, formSize[0], formSize[1], formTitle);
		var imgObj = document.createElement('IMG');	//建立圖片標籤
		imgObj.src = './img/20-0.gif';
		imgObj.border = 0;
		var newText = document.createTextNode('產生'+formTitle+'表單, 請稍後.....');	//建立字串物件
		contentObj.appendChild(imgObj);
		contentObj.appendChild(newText);

		//取得表單資料
		var requestObj = new Ajax.Request(URL, {
			method: 'post',
			parameters: 'target='+contentObj.id,
			onSuccess: function(transport) {
				var ieFlag = ( (navigator.appName).match(/Internet Explorer/) == null ) ? false : true;
				if(ieFlag) {
					//contentObj.innerHTML = transport.responseText;
				}
				else {
					targetSpace = (targetSpace == null || targetSpace == '') ? 'requireContent' : targetSpace;
					//$(targetSpace).innerHTML = transport.responseText;
					contentObj = $(targetSpace);
					closeFloatWindow();
				}

				contentObj.style.backgroundColor = '#EAE4C5';
				contentObj.innerHTML = '';

				var form = document.createElement('FORM');
				form.id = form.name = 'newForm';
				form.target = 'hiddenFrame';
				form.action = 'info_teacher_add_main.php';
				form.method = 'post';
				contentObj.appendChild(form);

				form.innerHTML = transport.responseText;

				//執行後續Function
				if(callBackFun!=null) {callBackFun(form);}
			}
		});
	}

	//取得與關鍵字相關資料
	function getLikeObjs(obj, postURL) {
		if(obj == null) return false;
		var coursename = obj.value;
		if(coursename == '' || coursename == null)
			return ;

		var pnObj = obj.parentNode;
		var nameList = $('nameList');
		var flag = (nameList==null);
		if(flag)
		{
			nameList = document.createElement('div');
			nameList.id = 'nameList';
			nameList.className = 'smallList';
		}
		else
			nameList.show();
		nameList.innerHTML = '檢查中...';
		nameList.onmouseout = nameList.onblur = function () {
			//this.timer = setTimeout("($('"+this.id+"').parentNode).removeChild($('"+this.id+"'));", 0.2*1000);
			this.timer = setTimeout("$('"+this.id+"').hide();", 0.2*1000);
		}
		nameList.onmouseover = function () {
			clearTimeout(this.timer);
		}

		if(flag)
			pnObj.appendChild(nameList);

		//取得與關鍵字相關的資料
		var URL = './'+postURL+'?mod=getRowDataByKeyword';
		var requestObj = new Ajax.Updater('ID_NOUS', URL, {
			method: 'post',
			parameters: 'target=name_list'+'&keyword='+coursename,
			evalScripts: true,
			onSuccess: function(transport) {
				//alert(transport.responseText);
				if(transport.responseText == '')
					($('nameList').parentNode).removeChild($('nameList'));
				$('nameList').innerHTML = '<div style="background-color: #FFFFFF;">'+transport.responseText+'</div>';
				$('nameList').focus();
			}
		});
	}
	//取得科目修改資料
	function getRowData(code)
	{
		if(code == null) return false;
		code = code.substring(code.lastIndexOf('#')+1, code.length+1);

		//取得與關鍵字相關的資料
		var URL = './info_course_behalf.php?mod=getRowData';
		var requestObj = new Ajax.Request(URL, {
			method: 'post',
			parameters: 'code='+code+'&target=cn,cs,cd',
			onSuccess: function(transport) {
				//alert(transport.responseText);
				var values = (transport.responseText).split('(-,-)');
				$('cn').value = values[0];
				$('cs').value = values[1];
				$('cd').value = values[2];
				//加入按鈕
				var pnObj = $('sdb').parentNode;
				pnObj.innerHTML = '';	//清空按鈕
				pnObj.innerHTML += '<input disabled id="sdb" type="submit" value="另存新檔(科目)" onclick="$(\'newRow\').value = 1 ;">';
				pnObj.innerHTML += '<input value="修改科目" type="submit" onclick="$(\'newRow\').value = 0 ; $(\'cs\').value = \''+values[1]+'\'">';
			}
		});

		//alert('目前狀態已變更為修改另存視窗');
	}

	//取得講師修改資料
	function getRowTeacherData(code)
	{
		if(code == null) return false;
		code = code.substring(code.lastIndexOf('#')+1, code.length+1)
		//取得與關鍵字相關的資料
		var URL = './info_teacher_behalf.php?mod=getRowData';
		var requestObj = new Ajax.Updater('ID_NOUS', URL, {
			method: 'post',
			parameters: 'code='+code+'&target=name,teacode,idno,sorname,sex,title,tel1,ext1,tel2,ext2,email',
			evalScripts: false,
			onSuccess: function(transport) {
				//alert(transport.responseText);
				var values = (transport.responseText).split('(-,-)');
				$('name').value = values[0];
				$('teacode').value = values[1];
				$('idno').value = values[2];
				$('sorname').value = values[3];
				$('sex').value = values[4];
				$('title').value = values[5];
				$('tel1').value = values[6];
				$('ext1').value = values[7];
				$('tel2').value = values[8];
				$('ext2').value = values[9];
				$('email').value = values[10];
				//加入按鈕
				var pnObj = $('sdb').parentNode;
				pnObj.innerHTML = '';	//清空按鈕
				pnObj.innerHTML += '<input id="sdb" type="submit" value="另存新檔(講座)" onclick="$(\'newRow\').value = 1 ;">';
				pnObj.innerHTML += '<input value="修改講座" type="submit" onclick="$(\'newRow\').value = 0 ;">';
			}
		});
	}

	//將科目資料存檔
	function courseSaveData(flag, coursecode, coursename, coursedescr, callBackFun)
	{
		if(coursecode == '' || coursecode == null || coursename == '' || coursename == null)
			return false;

		if(flag)
		{
			//新增檔案或另存新檔
			var URL = './info_course_add_main.php?mod=newData';
			var requestObj = new Ajax.Updater('ID_NOUS', URL, {
				method: 'post',
				parameters: 'coursecode='+coursecode+'&coursename='+coursename+'&coursedescr='+coursedescr+'&target=',
				evalScripts: true,
				onSuccess: function(transport) {
					if(callBackFun != null) callBackFun(coursecode, coursename);
					closeFloatWindow();
					//alert(transport.responseText);
				}
			});
		}
		else
		{
			//修改科目
			var URL = './info_course_add_main.php?mod=updData';
			var requestObj = new Ajax.Updater('ID_NOUS', URL, {
				method: 'post',
				parameters: 'coursecode='+coursecode+'&coursename='+coursename+'&coursedescr='+coursedescr+'&target=',
				evalScripts: true,
				onSuccess: function(transport) {
					if(callBackFun != null) callBackFun(coursecode, coursename);
					closeFloatWindow();
					//alert(transport.responseText);
				}
			});
		}
	}

	//將講師資料存檔
	function teacherSaveData(formObj, callBackFun)
	{
//		if(code == '' || code == null || name == '' || name == null) {
//			alert('請輸入必填欄位');
//			return false;
//		}
		//設定參數
		var paramers = new Array();
		for(var i=0; i<formObj.length; i++)
			paramers[i] = formObj[i].name + '=' + formObj[i].value;

		var URL = './info_teacher_add_main.php';
		var requestObj = new Ajax.Updater('ID_NOUS', URL, {
			method: 'post',
			parameters: paramers.join('&'),
			evalScripts: true,
			onSuccess: function(transport) {
				//alert(transport.responseText);
				if(callBackFun != null) callBackFun(code, name);
				closeFloatWindow();
			}
		});
	}

	//判斷索引值是否存在
	function checkIdExist(mudle, value) {
		if(mudle == 'COURSE') {
			var URL = './info_course_behalf.php?mod=check_id_exist';
			var requestObj = new Ajax.Updater('ID_NOUS', URL, {
				method: 'post',
				parameters: 'code='+value+'&target=idm,sdb',
				evalScripts: true
			});
		}
		else if(mudle == 'TEACHER') {
			var URL = './info_teacher_behalf.php?mod=check_id_exist';
			var requestObj = new Ajax.Updater('ID_NOUS', URL, {
				method: 'post',
				parameters: 'code='+value+'&target=idm,NT',
				evalScripts: true
			});
		}
	}

//將月曆值傳回下拉式選單
function getData2Where(obj)
{
	if(obj == null && name == null)
		return ;

	var oid = obj.id;

	//alert(obj.name);
    //將傳入值拆開存成陣列
	var values = obj.value.split('-');
	//判斷是什麼時間
	if(obj.name=='postdateS'){ // 張貼時間開始
		var demo_year = $('s_pyy');
		var demo_month = $('s_pmm');
		var demo_Date = $('s_pdd');
	}
	else if(obj.name=='postdateE'){	// 張貼時間結束
		var demo_year = $('e_pyy');
		var demo_month = $('e_pmm');
		var demo_Date = $('e_pdd');
	}
	else if(obj.name=='onlinedateS'){
		var demo_year = $('s_oyy');
		var demo_month = $('s_omm');
		var demo_Date = $('s_odd');
	}
	else if(obj.name=='onlinedateE'){
		var demo_year = $('e_oyy');
		var demo_month = $('e_omm');
		var demo_Date = $('e_odd');
	}
	else if(obj.name=='offlinedateS'){
		var demo_year = $('s_ofyy');
		var demo_month = $('s_ofmm');
		var demo_Date = $('s_ofdd');
	}
	else if(obj.name=='offlinedateE'){
		var demo_year = $('e_ofyy');
		var demo_month = $('e_ofmm');
		var demo_Date = $('e_ofdd');
	}

		demo_year.value = values[0];

		for(var i=0; i<demo_month.length; i++)
		   if(demo_month[i].value == eval(values[1]) )
			  demo_month[i].selected = true;


		for(var j=0; j<demo_Date.length; j++)
			if(demo_Date[j].value == eval(values[2]) )
				demo_Date[j].selected = true;

    //obj.value = (obj.value).replace(/\//g, '-');
    //alert(obj.value);
}

function checkdate(StartTime,EndTime){
	if(parseInt(StartTime) > parseInt(EndTime)){
		alert('下線時間不可早於上線時間');
		return false;
	}else
		return true;
}

//判斷是否有選項被勾選
//判斷目標範圍的選擇控制項是否都沒被選擇
function isSelected(targetId)
{
	targetId = (targetId==null || targetId == '') ? 'listData' : targetId;
	var flag = false;
	//取得目標內容所有的目標物件
	$$('#'+targetId+' input[type="checkbox"]').each(function(s) {
		if(s.checked) {
			flag = true;
			throw $break;
		}
	});
	return flag;
}
