﻿	   

if(window.addEventListener){
		window.addEventListener('load', function(){pageload()},false);
}else if(window.attachEvent){
		window.attachEvent('onload', function(){pageload()});
}else if(document.getElementById){
		window.onload=function(){pageload()};
}

function pageload()
{

       var nVer = navigator.appVersion;
       var nAgt = navigator.userAgent;
       
 
       // In Firefox, the true version is after "Firefox"
       if ((nAgt.indexOf("Firefox"))!=-1) {
           alert('因安全限制，請使用 IE 瀏覽器 !');
           window.location.href='http://www.microsoft.com/taiwan/windows/ie/downloads/default.mspx' ;
            
        }
	if(typeof(HideWait)=="function")
	{
		HideWait();
	}
	if(document.getElementById('LoginID')){	   
		document.getElementById('LoginID').focus();
	}
}

document.onkeydown = keyDown;
function keyDown(evt){
	var evt = evt ? evt : (window.event ? window.event : null);
	if(document.getElementById('LoginID') && evt.keyCode==13){
		if(document.getElementById('LoginID').value!='' && document.getElementById('LoginPW').value!=''){
			document.getElementById('LOGIN').click();
		}else{
			if(document.getElementById('LoginID').value!=''){
				document.getElementById('LoginPW').focus();
			}
			return false;
		}
	}
	if(evt.keyCode==13){return false;}
}

function LoginCheck(){
    var Msg=document.getElementById('LoginMsg');
    Msg.innerHTML="驗証中...";
    var id=document.getElementById('LoginID');
    var pw=document.getElementById('LoginPW');
    var Sta=document.getElementById('Status');
    if(!id || !pw || !Sta){
        document.getElementById('Login').disabled=false;
        Msg.innerHTML="控制項發生錯誤...";
        return false;
    }
    var StaStr=document.getElementById('Status').value;
    var idStr=document.getElementById('LoginID').value;
    var pwStr=document.getElementById('LoginPW').value;
    if(StaStr=='' || idStr=='' || pwStr==''){
        document.getElementById('Login').disabled=false;
        Msg.innerHTML="請輸入帳號及密碼...";
         return false;
   }
	xmlHttp		= _createHttpRequestg();
	var path= SESSIONURL + "Service/LoginCheck.asmx/verify?_Status="+ StaStr +"&_id="+ idStr +"&_pw="+ pwStr +"&t="+new Date().getTime();
	xmlHttp.open('GET',path,true);
	xmlHttp.onreadystatechange=function(){checkSta()};
	xmlHttp.send(null);
    function checkSta(){
	    if (xmlHttp.readyState==4){
		    xml=xmlHttp.responseXML;
		    if (xmlHttp.status == 200) {
					    var root = _clean(xmlHttp.responseXML.documentElement);
					    if(root.text==1){
					        Msg.innerHTML="驗証成功,載入頁面...";
					        switch(StaStr){
					        case "A":
					            top.location.href= SESSIONURL + 'Course/OverView.aspx';
					            break;
					        case "B":
					            //20090703修正登入可查詢未繳交課程進度表教師
					            top.location.href= SESSIONURL + 'Course/LearningMsg.aspx';
					            //top.location.href= SESSIONURL + 'Course/CourseProgress.aspx';
					            break;
					        case "C":
					            top.location.href= SESSIONURL + 'Knowledge/KnowledgeUrl.aspx';
					            break;
					        }
					    }else{
                            document.getElementById('Login').disabled=false;
					        Msg.innerHTML=root.text ;
					    }
		    }else{
			    //alert(xmlHttp.status);
			    Msg.innerHTML="伺服器維護中,請稍後再登入...";
			    document.getElementById('Login').disabled=false;
		    }
	    }
    }
}

function MM_openCourse(theURL,winName){
    MM_openBrWindow(theURL,winName,'resizable=yes,scrollbars=yes,status=yes');
}

//==============開起視窗============================
var w=null;
function MM_openBrWindow(theURL,winName,features,e){
 if(w!=null){
		try{
				w.status;
				w.focus();
		}catch(e){
				w=null;
				MM_openBrWindow(theURL,winName,features);
		}
	}else{
	    try{
	        w=window.open(theURL,winName,features);
	        w.resizeTo(screen.availWidth,screen.availHeight);
	        w.moveTo(0,0); 
	        w.focus();
	        w=null;
	    }catch(e){}
	}
}

function chkallsel(_id,_bo){
    if(!document.getElementById(_id)){return false;}
    var allchk = document.getElementById(_id).getElementsByTagName("input");
    for (i=0;i<allchk.length;i++ ){
	    if (allchk[i].type=="checkbox"){
			allchk[i].checked=_bo==0?false:true;
	    }
    }
}