function fnSearchCheck(oForm){
	var sErr = "";
	if(oForm.key.value=="" || oForm.key.value == "請輸入關鍵字")
		sErr += "請輸入關鍵字\n"
	if(sErr != ""){
		alert(sErr);
		return false;
	}else{
		var sTemp = encodeURI(oForm.key.value);
		oForm.key_utf8.value = sTemp;
		if(oForm.fun.value == "job")
			oForm.action = "/cfdocs/edu/certify/certify_jsearch.cfm";
		else
			oForm.action = "/cfdocs/edu/certify/certify_ksearch.cfm";
		oForm.submit();
		return true;
	}
}
function fnCateFormCheck(oForm){
	var cert_no = "";
	if(oForm.bcate.value != "") cert_no = oForm.bcate.value;
	if(oForm.mcate.value != "") cert_no = oForm.mcate.value;
	if(oForm.scate.value != "") cert_no = oForm.scate.value;
	if(cert_no == ""){
		alert("請至少選擇一項證照大類！");
		oForm.bcate.focus();
		return false;
	}else{
		oForm.cert_no.value = cert_no;
		return true;
	}
}
function fnSearchInit(){
	var searchTabs = new Learn.mod.tabs("searchTab");
	searchTabs.sTabTag = "span";
	searchTabs.sSearchName = "searchbox";
	searchTabs.initTabs();
	searchTabs.oSearch.oForm = document.search_form;
}
function fnIndexInit(){	
	/*var infoTabs = new Learn.mod.tabs("infotab");
	infoTabs.sActionMode = "content";
	infoTabs.sContentName = "infoblock";
	infoTabs.initTabs();*/
	fnStoryInit();
	
}
var http = Learn.util.getHTTPObject();
function fnCateOnChange(oAct,oCateM,oCateS,ilvl){
	var cert_no = oAct.options[oAct.selectedIndex].value;
	oCateS.options.length = 0;
	var oOption=new Option("請選擇證照名稱","");
	oCateS.options[oCateS.length]=oOption;
	if(cert_no==""){
		if(ilvl==1){
			oCateM.options.length = 0;
			var oOption=new Option("請選擇證照中類","");
			oCateM.options[oCateM.length]=oOption;
		}			
	}else{
		var url = "/cfdocs/edu/certify/ajax_certify.cfm?cert_no="+cert_no; // The server-side script
		http.open("GET", url , true);
		if(ilvl==1){
			var handleHttpResponse = function(){
				getMcate(oCateM,oCateS);
			}
		}else{
			var handleHttpResponse = function(){
				getScate(oCateS);
			}
		}
		http.onreadystatechange = handleHttpResponse;
		http.send(null);
	}
}

function getMcate(oCateM,oCateS) {
	if (http.readyState == 4) {		
		 var results = http.responseText.split("@@");
		 if(results[1] == "true"){
			var arrCate = results[2].split(",");
			oCateM.options.length = 0;
			var oOption=new Option("請選擇證照中類","");
			oCateM.options[oCateM.length]=oOption;
			for(i=0;i<arrCate.length;i++){
				var arrText = arrCate[i].split("^");
				var oOption=new Option(arrText[1],arrText[0]);
        			oCateM.options[oCateM.length]=oOption;
			}
			
		}else{
			oCateM.options.length = 0;
			var oOption=new Option("請選擇證照中類","");
			oCateM.options[oCateM.length]=oOption;
		}
	}
}	
function getScate(oCateS) {
	if (http.readyState == 4) {		
		 var results = http.responseText.split("@@");
		 if(results[1] == "true"){
			var arrCate = results[2].split(",");
			oCateS.options.length = 0;
			var oOption=new Option("請選擇證照名稱","");
			oCateS.options[oCateS.length]=oOption;
			for(i=0;i<arrCate.length;i++){
				var arrText = arrCate[i].split("^");
				var oOption=new Option(arrText[1],arrText[0]);
        			oCateS.options[oCateS.length]=oOption;
			}
		}else{
			oCateS.options.length = 0;
			var oOption=new Option("請選擇證照名稱","");
			oCateS.options[oCateS.length]=oOption;
		}
	}
}
function fnCateInit(oCateB,oCateM,oCateS){
	oCateB.selectedIndex = 0;
	oCateM.options.length = 0;
	var oOption=new Option("請選擇證照中類","");
	oCateM.options[oCateM.length]=oOption;
	oCateS.options.length = 0;
	var oOption2=new Option("請選擇證照名稱","");
	oCateS.options[oCateS.length]=oOption2;
}
function js_ShowMsg(ev,argmsg,iLeft,iTop){	
	var event = ev||window.event;
	var oActive = event.srcElement||event.target;
	oMsg = document.getElementById(argmsg)	
	oMsg.style.left =  Learn.util.calculateLocation(oActive,"offsetLeft") + iLeft + "px";
	oMsg.style.top = Learn.util.calculateLocation(oActive,"offsetTop") + oActive.offsetHeight + iTop  + "px" ;
	oMsg.style.visibility="visible";
}
function js_HideMsg(argmsg){
	document.getElementById(argmsg).style.visibility="hidden";
}

module_story = function(sModuleName,sLastBtnName,sNextBtnName){
	this.sModuleName = sModuleName;
	this.sLastBtnName= sLastBtnName;
	this.sNextBtnName = sNextBtnName;	
	this.iTotalStory = 0;
	this.iCurrStoryIndex = 0;
	this.oCurrStory = 0;
	this.timeoutID = null;
	this.iSpeed = 7000;
}
module_story.prototype.init = function(){
	var oModule = document.getElementById(this.sModuleName);
	var oTemp = oModule.getElementsByTagName("DIV");
	this.iTotalStory = oTemp.length;
	this.oCurrStory = oTemp[0];
	var oLastBtn = document.getElementById(this.sLastBtnName);
	var oNextBtn = document.getElementById(this.sNextBtnName);
	var self = this;
	var fAction1 = function(e){
		if(e){
			Learn.util.Event.stopEvent(e);
		}
		self.last(self);
		return false;
	}
	Learn.util.Event.addListener(oLastBtn,"click",fAction1);
	var fAction2 = function(e){
		if(e){
			Learn.util.Event.stopEvent(e);
		}
		self.next(self);
		return false;
	}
	Learn.util.Event.addListener(oNextBtn,"click",fAction2);
}
module_story.prototype.last = function(oSelf){
	var iNextIndex = 0;
	if(oSelf.iCurrStoryIndex == 0)
		iNextIndex = oSelf.iTotalStory - 1;
	else
		iNextIndex = oSelf.iCurrStoryIndex - 1;
	Learn.util.removeClass(oSelf.oCurrStory,"on");
	var oTemp = document.getElementById(this.sModuleName).getElementsByTagName("DIV");
	oSelf.oCurrStory = oTemp[iNextIndex];
	Learn.util.addClass(oSelf.oCurrStory,"on");
	oSelf.iCurrStoryIndex = iNextIndex;
}
module_story.prototype.next = function(oSelf){
	var iNextIndex = 0;
	if((oSelf.iCurrStoryIndex+1) == oSelf.iTotalStory)
		iNextIndex = 0;
	else
		iNextIndex = oSelf.iCurrStoryIndex + 1;
	Learn.util.removeClass(oSelf.oCurrStory,"on");
	var oTemp = document.getElementById(this.sModuleName).getElementsByTagName("DIV");
	oSelf.oCurrStory = oTemp[iNextIndex];
	Learn.util.addClass(oSelf.oCurrStory,"on");
	oSelf.iCurrStoryIndex = iNextIndex;
}
var oStoryt;
var intStep;
function doBlur(){
	var oDIV = document.getElementById("story_content");
	if(document.all)
		intStep = intStep -10;
	else
		intStep = intStep -4;
	if(intStep >= 0){
		if(document.all){
			oDIV.style.filter = "progid:DXImageTransform.Microsoft.Alpha( style=1,opacity="+intStep+",finishOpacity="+intStep+")";
		}else{
			var iOpacity = intStep/100;
			oDIV.style.opacity = iOpacity;
		}
	}else if(window.intervalID2){
		clearInterval(intervalID2);
		oStoryt.next(oStoryt);
		intervalID2 = setInterval("doClear()",20);
	}
}
function doClear(){
	var oDIV = document.getElementById("story_content");
	if(document.all)
		intStep = intStep +10;
	else
		intStep = intStep +4;
	if(intStep <= 100){
		if(document.all){
			oDIV.style.filter = "progid:DXImageTransform.Microsoft.Alpha( style=1,opacity="+intStep+",finishOpacity="+intStep+")";
		}else{
			var iOpacity = intStep/100;
			oDIV.style.opacity = iOpacity;
		}
	}else if(window.intervalID2){
		clearInterval(intervalID2);
		oStoryt.timeoutID = setTimeout("fnInterval()",oStoryt.iSpeed);
	}
	
}
function fnInterval(){
	intStep = 100;
	intervalID2 = setInterval("doBlur()",20);
}
function fnStoryInit(){	
	var oModule = document.getElementById("story_block");
	if(oModule){
	oStoryt = new module_story("story_content","bt_last","bt_next")
	oStoryt.init();	
	fAction1 = function(e){
		if(e){
			Learn.util.Event.stopEvent(e);
		}
		clearTimeout(oStoryt.timeoutID);
		return false;
	}
	Learn.util.Event.addListener(oModule,"mouseover",fAction1);	
	fAction2 = function(e){
		if(e){
			Learn.util.Event.stopEvent(e);
		}
		clearTimeout(oStoryt.timeoutID);	
		oStoryt.timeoutID = setTimeout("fnInterval()",oStoryt.iSpeed);
		return false;
	}	
	Learn.util.Event.addListener(oModule,"mouseout",fAction2);
	oStoryt.timeoutID = setTimeout("fnInterval()",oStoryt.iSpeed);
	}
}
Learn.mod.treeview = function(sModuleName){
	this.sModuleName = sModuleName;
	this.sNodeTag = "DIV";
	this.sRootClassName = "";
	this.sClickClassName = "b_name";
	this.sOpenClassName = "branch_o";
	this.sCloseClassName = "branch";
	this.sTrigger = "click";
}
Learn.mod.treeview.prototype.nodeAction = function(e, oSelf){
	var oNode = e.srcElement||e.target;
	var oBranch = null;
	var oTemp = oNode;
	while(true){
		if(oTemp.parentNode){
			oTemp = oTemp.parentNode;
			if(oTemp.parentNode && oTemp.parentNode.id == oSelf.sModuleName){
				oBranch = oTemp;
				break;
			}
		}else
			break;
	}
	if(oBranch != null){
		if(oBranch.id.substr(0,1)=="c" || oBranch.id.substr(0,1)=="l"){
			getSmallCategory(oBranch.id);
		}
		if(Learn.util.hasClass(oBranch,oSelf.sOpenClassName)){
			Learn.util.removeClass(oBranch,oSelf.sOpenClassName);
			Learn.util.addClass(oBranch,oSelf.sCloseClassName);
		}else{
			Learn.util.removeClass(oBranch,oSelf.sCloseClassName);
			Learn.util.addClass(oBranch,oSelf.sOpenClassName);
		}
	}
}
Learn.mod.treeview.prototype.initTree = function(){
	var oNodesTemp = document.getElementById(this.sModuleName).getElementsByTagName(this.sNodeTag);
	if(oNodesTemp!=null){
		var iTemp = 0;
		for(i=0; i<oNodesTemp.length; i++){
			if(oNodesTemp[i].className==this.sClickClassName){
				var self = this;
				var fAction = function(e){
					if(e){
						Learn.util.Event.stopEvent(e);
					}
					self.nodeAction(e,self);
					return false;
				}
				Learn.util.Event.addListener(oNodesTemp[i],this.sTrigger,fAction);
			}
		}
	}
}
function fnRootClick(sTreeId,cate_no,sClickId,sClassName){
	var oNode = document.getElementById(sTreeId);
	var obj = document.getElementById(sClickId);
	if(oNode != null){		
		if(Learn.util.hasClass(oNode,"root")){
			Learn.util.removeClass(oNode,"root");
			Learn.util.addClass(oNode,"root_c");
			obj.className = sClassName;
		}else{
			if(oNode.getElementsByTagName("DIV").length==0){				
				getMidCategory(sTreeId,cate_no);
			}
			Learn.util.removeClass(oNode,"root_c");
			Learn.util.addClass(oNode,"root");
			obj.className = "r_title_open";
		}
	}
}
var http = Learn.util.getHTTPObject();
function getMidCategory(sTreeId,cate_no){
	var url = "/cfdocs/edu/certify/ajax_certify.cfm?cert_no="+cate_no;
	http.open("GET", url , true);
	var handleHttpResponse = function(){
		getMidcate(sTreeId);
	}
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}
function getSmallCategory(sBranchId){
	var cate_no;
	var bLast = false;
	if(sBranchId.substr(0,1)=="c")
		cate_no = sBranchId.replace("c_","");
	if(sBranchId.substr(0,1)=="l"){
		cate_no = sBranchId.replace("l_","");
		bLast = true;
	}
	var url = "/cfdocs/edu/certify/ajax_certify.cfm?cert_no="+cate_no;
	http.open("GET", url , true);
	var handleHttpResponse = function(){
		getSmallcate(sBranchId,cate_no,bLast);
	}
	http.onreadystatechange = handleHttpResponse;
	http.send(null);
}
function getMidcate(sTreeId) {
	if (http.readyState == 4) {
		 var results = http.responseText.split("@@");
		 if(results[1] == "true"){
			var oTree = document.getElementById(sTreeId);		
			var arrCate = results[2].split(",");
			var sClassAtt = "class";
			if(document.all){
				if(navigator.appVersion.indexOf("MSIE 8")==-1)
					sClassAtt = "className";
			}
			if(results[3].length<500){
				var arrText = results[3].split("^");
				var oLeaf = document.createElement("DIV");
				oLeaf.setAttribute(sClassAtt,"root_leaf");
				var oImg1 = document.createElement("DIV");
				oImg1.setAttribute(sClassAtt,"l_img1");
				var oLink = document.createElement("A");
        			oLink.setAttribute("href","/cfdocs/edu/certify/certify_cate.cfm?cert_no="+arrText[0]);
        			oLink.innerHTML = arrText[1]+"全部";
        			oLeaf.appendChild(oImg1);
        			oLeaf.appendChild(oLink);
        			oTree.appendChild(oLeaf);
			}
			for(i=0;i<arrCate.length;i++){
				var arrText = arrCate[i].split("^");
				var oBranch = document.createElement("DIV");
				oBranch.setAttribute(sClassAtt,"branch");
				var oHead = document.createElement("DIV");
				oHead.setAttribute(sClassAtt,"b_head");				
				var oName = document.createElement("DIV");
				oName.setAttribute(sClassAtt,"b_name");				
				var oImg = document.createElement("DIV");
				if((i+1) == arrCate.length){
					oImg.setAttribute(sClassAtt,"f_img_last");
					oBranch.setAttribute("id","l_"+arrText[0]);
				}else{
					oImg.setAttribute(sClassAtt,"f_img");
					oBranch.setAttribute("id","c_"+arrText[0]);
				}
        			var oLink = document.createElement("A");
        			oLink.setAttribute("href","javascript:");
        			oLink.innerHTML = arrText[1];
        			oName.appendChild(oImg);
        			oName.appendChild(oLink);
        			oHead.appendChild(oName);
        			oBranch.appendChild(oHead);
        			oTree.appendChild(oBranch);
			}
			var oTree = new Learn.mod.treeview(sTreeId);
			oTree.initTree();
		}else{
			alert("error");
		}
	}
}
function getSmallcate(sBranchId,cate_no,bLast){
	if (http.readyState == 4) {
		 var results = http.responseText.split("@@");
		 if(results[1] == "true"){
			var oBranch = document.getElementById(sBranchId);		
			var arrCate = results[2].split(",");
			var sClassAtt = "class";
			if(document.all){
				if(navigator.appVersion.indexOf("MSIE 8")==-1)
					sClassAtt = "className";
			}
			if(results[3].length<500){
				var arrText = results[3].split("^");
				var oLeaf = document.createElement("DIV");
				oLeaf.setAttribute(sClassAtt,"leaf");				
				var oImg1 = document.createElement("DIV");
				var oImg2 = document.createElement("DIV");
				if(bLast)
					oImg1.setAttribute(sClassAtt,"l_img1_last");
				else
					oImg1.setAttribute(sClassAtt,"l_img1");
				oImg2.setAttribute(sClassAtt,"l_img2");
        			var oLink = document.createElement("A");
        			oLink.setAttribute("href","/cfdocs/edu/certify/certify_cate.cfm?cert_no="+arrText[0]);
        			oLink.innerHTML = arrText[1]+"全部";
        			oLeaf.appendChild(oImg1);
        			oLeaf.appendChild(oImg2);
        			oLeaf.appendChild(oLink);
        			oBranch.appendChild(oLeaf);
			}
			for(i=0;i<arrCate.length;i++){
				var arrText = arrCate[i].split("^");
				var oLeaf = document.createElement("DIV");
				oLeaf.setAttribute(sClassAtt,"leaf");				
				var oImg1 = document.createElement("DIV");
				var oImg2 = document.createElement("DIV");
				if(bLast)
					oImg1.setAttribute(sClassAtt,"l_img1_last");
				else
					oImg1.setAttribute(sClassAtt,"l_img1");
				if((i+1) == arrCate.length)
					oImg2.setAttribute(sClassAtt,"l_img2_last");
				else					
					oImg2.setAttribute(sClassAtt,"l_img2");
        			var oLink = document.createElement("A");
        			oLink.setAttribute("href","/cfdocs/edu/certify/certify.cfm?cert_no="+arrText[0]);
        			oLink.innerHTML = arrText[1];
        			oLeaf.appendChild(oImg1);
        			oLeaf.appendChild(oImg2);
        			oLeaf.appendChild(oLink);
        			oBranch.appendChild(oLeaf);
			}
			oBranch.setAttribute("id","o_"+cate_no);
		}else{
			alert("error");
		}
	}
}
function fnOnMouseOver(obj){
	if(obj.className != "r_title_open"){
		obj.className = "r_title_key";
	}	
}
function fnOnMouseOut(obj,sClassName){
	if(obj.className != "r_title_open"){
		obj.className = sClassName;
	}
}