﻿function js_changePage(page) {
	document.frmOpenLocal.page.value = page;
	document.frmOpenLocal.submit();
}

function js_loadBook(idBook, page) {
    document.frmMain.idBook.value = idBook;
    document.frmMain.page.value = page;
	document.frmMain.submit();
}

function js_redirect(idBook, idMessage) {
	document.frmRedirect.idBook.value = idBook;
	document.frmRedirect.idMessage.value = idMessage
	document.frmRedirect.submit();
	return false;
}

function js_open(idBook, idMessage, file) {
    document.frmOpen.idBook.value = idBook;
	document.frmOpen.idMessage.value = idMessage
	document.frmOpen.file.value = file
	document.frmOpen.submit();
	return false;
}

function js_openLocal(pageName) {
    document.frmOpenLocal.pageName.value = pageName;
    document.frmOpenLocal.submit()
    return false;
}

function js_download(idBook, idMessage, typeFile, idUser, file) {
	document.frmDownload.idBook.value = idBook;
	document.frmDownload.idMessage.value = idMessage;
	document.frmDownload.typeFile.value = typeFile;
	document.frmDownload.idUser.value = idUser;
	document.frmDownload.file.value = file;
	document.frmDownload.submit();
	return false;
}

function js_intranetLogin() {
    ret = Login.Process(document.frmOpenLocal.idUser.value + ":" + document.frmOpenLocal.passwordUser.value, js_onLoginComplete, js_onLoginTimeout, js_onLoginError);
    return true;
}

function js_onLoginComplete(arg) {
    if (arg == "success") {
	    document.frmIntranet.idUser.value = document.frmOpenLocal.idUser.value;
	    document.frmIntranet.passwordUser.value = document.frmOpenLocal.passwordUser.value;
	    document.frmIntranet.submit();
    }
    else {
        js_intranetReset();
        window.alert("登入失敗 / Login failed.");
    }
}

function js_onLoginTimeout(arg) {
    window.alert("登入逾時 / Login timeout.");
}

function js_onLoginError(arg) {
    window.alert("登入出現錯誤 / Login error.");
}

function js_intranetReset() {
	document.frmIntranet.idUser.value = "";
	document.frmIntranet.passwordUser.value = "";
	document.frmOpenLocal.idUser.value = "";
	document.frmOpenLocal.passwordUser.value = "";
	document.frmOpenLocal.idUser.focus();
}

function js_onKeyDown(e) {		
    var keyCode = window.event ? event.keyCode : e.which;
    
    switch (keyCode) {
	    case 13: // ENTER
		    js_intranetLogin();
    }
    
    return true;
}

function js_false() {
    return false;
}
function js_onLoad() {
    var col = document.getElementsByTagName("A")
    var i;
    
    for (i = 0; i < col.length; i++) {
        if (col[i].href == "javascript:__doPostBack('mnuMain','行政組織')" || col[i].href == "javascript:__doPostBack('mnuMain','相關連結')") {
            col[i].removeAttribute("href");           
            col[i].style.color = "#005798";
        }
    }
            
    if (document.frmOpenLocal.passwordUser) {
        document.frmOpenLocal.idUser.focus();
        document.frmOpenLocal.passwordUser.onkeydown = js_onKeyDown;
    }
}

var flgLoad = false;