/* ======================= | login status handler | ======================= */ /* object definition */ function loginObj() { this.control = 0; this.status = 0; this.setControl = function() { this.control = 1; } this.clearControl = function() { this.control = 0; } this.setStatus = function() { this.status = 1; } this.clearStatus = function() { this.status = 0; } } function bitSet() { this.topObj = new loginObj(); this.appObj = new loginObj(); } /* default login and logout function */ function login_top() { } function logout_top() { } function login_app() { } function logout_app() { } /* == start of handler == */ /* global variables */ var hkec_topbar_lockFlag = 0; var hkec_topbar_isInit = 0; function hkec_topbar_addInit() { hkec_topbar_isInit ++; } function hkec_topbar_setCookie(cname, bitsetObj) { cvalue = bitsetObj.topObj.control + ''; cvalue += bitsetObj.topObj.status + ''; cvalue += bitsetObj.appObj.status + ''; cvalue += bitsetObj.appObj.control + ''; //alert("setCookie: " + cvalue); //document.cookie = cname + "=" + cvalue; hkec_topbar_set_cookie( cname, cvalue, 0, '/', '.hkedcity.net', 0 ); } function hkec_topbar_set_cookie( name, value, expires, path, domain, secure ) { domain = document.domain; // set time, it's in milliseconds var today = new Date(); today.setTime( today.getTime() ); /* if the expires variable is set, make the correct expires time, the current script below will set it for x number of days, to make it for hours, delete * 24, for minutes, delete * 60 * 24 */ if ( expires ) { expires = expires * 1000 * 60 * 60 * 24; } var expires_date = new Date( today.getTime() + expires ); document.cookie = name + "=" + escape( value ) + ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) + ( ( path ) ? ";path=" + path : "" ) + ( ( domain ) ? ";domain=" + domain : "" ) + ( ( secure ) ? ";secure" : "" ); //alert("set_cookie: " + document.cookie); } function hkec_topbar_getCookie(name) { var nameEQ = name + "="; var ca = document.cookie.split(';'); for(var i=0;i < ca.length;i++) { var c = ca[i]; while (c.charAt(0)==' ') c = c.substring(1,c.length); if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length); } return "0000"; } /* handler variable */ var currentBit = new bitSet(); function hkec_topbar_setTopObj(obj) { currentBit.topObj = obj; } function hkec_topbar_setAppObj(obj) { currentBit.appObj = obj; } function hkec_topbar_getTopObj() { return currentBit.topObj; } function hkec_topbar_getAppObj() { return currentBit.appObj; } /* handler function */ function hkec_topbar_setIFrameURL() { appendStr = "#logFlag##" + hkec_topbar_lockFlag + "#isInit##" + hkec_topbar_isInit +"#bitset##"; cvalue = currentBit.topObj.control + ''; cvalue += currentBit.topObj.status + ''; cvalue += currentBit.appObj.status + ''; cvalue += currentBit.appObj.control + ''; appendStr += cvalue; currentIframeSrc = document.getElementById('myLoginBar').src; if (navigator.appName == "Netscape") { window.myLoginBar.location.href = currentIframeSrc + escape(appendStr); }else{ document.frames['myLoginBar'].location.href=currentIframeSrc+escape(appendStr); } } function hkec_topbar_handle() { if(hkec_topbar_isInit==2) { // if both App and Topbay init hkec_topbar_lockFlag = 1; // lock hkec_topbar_setIFrameURL(); bitSetString = hkec_topbar_getCookie("loginCookie"); cookieBit = new bitSet(); cookieBit.topObj.control = parseInt(bitSetString.charAt(0)); cookieBit.topObj.status = parseInt(bitSetString.charAt(1)); cookieBit.appObj.status = parseInt(bitSetString.charAt(2)); cookieBit.appObj.control = parseInt(bitSetString.charAt(3)); // looping to get equil. if(cookieBit.topObj.status != currentBit.topObj.status) { cookieBit.topObj.status = currentBit.topObj.status; currentBit.topObj.control = 1; }else if(cookieBit.appObj.status != currentBit.appObj.status) { cookieBit.appObj.status = currentBit.appObj.status; currentBit.appObj.control = 1; } hkec_topbar_setCookie("loginCookie", cookieBit); hkec_topbar_lockFlag = 0; // unlock hkec_topbar_setIFrameURL(); } } function hkec_topbar_getLoginStatus() { if (!hkec_topbar_lockFlag && hkec_topbar_isInit==2) { // if both App and Topbar init AND unlock /* debug msg */ strBit = currentBit.topObj.control + ''; strBit += currentBit.topObj.status+ ''; strBit += currentBit.appObj.status+ ''; strBit += currentBit.appObj.control+ ''; var date = new Date(); //document.getElementById('divTime').innerText = strBit + " " + date.toTimeString(); /* end of debug msg */ return currentBit; } return null; } /* end of login status handler */ /* ======================= | display top bar fn | ======================= */ function hkec_topbar_display(param_obj) { hkec_topbar_init(); var topbar_str = ''; topbar_str += ""; document.write(topbar_str); return; } function hkec_topbar_get_url() { var curr_url = new String(self.location.href); curr_url = curr_url.replace(/casticket=[^&]&?/, ''); curr_url = curr_url.replace(/[&\?]$/, ''); return curr_url; } function hkec_topbar_create_param_obj() { var param_obj = new Object(); param_obj.login = 0; param_obj.lang = ''; param_obj.locale = 'utf-8'; return param_obj; } var hkec_topbar_param_obj = hkec_topbar_create_param_obj(); /* end of display topbar */ /* ======================= | top bar section | ======================= */ topObj = new loginObj(); function hkec_topbar_init(){ topObj.clearStatus(); hkec_topbar_setTopObj(topObj); hkec_topbar_addInit(); hkec_topbar_handle(); selfCheck_t(); } // regular check for topbar function selfCheck_t() { //cBit = parseToBitSet(parseURL()); cBit = self.hkec_topbar_getLoginStatus(); if(cBit!= null && cBit.appObj.control) { if(cBit.topObj.status != cBit.appObj.status) { if(cBit.appObj.status){ cBit.topObj.setStatus(); hkec_topbar_setCookie("loginCookie", cBit); login_top(); }else{ cBit.topObj.clearStatus(); hkec_topbar_setCookie("loginCookie", cBit); logout_top(); } } else{ cBit.appObj.clearControl(); hkec_topbar_setCookie("loginCookie", cBit); } } setTimeout("selfCheck_t()", 1000); } selfCheck_t(); function login_top() { // customise here var curr_url = hkec_topbar_get_url(); var new_url = "http://www.hkedcity.net/tools/topbar/caslogin.php?url=" + escape(curr_url); this.location.href = new_url; return; //document.getElementById('divBit').innerText +="\ntopbar login"; } function logout_top() { // customise here var curr_url = hkec_topbar_get_url(); var new_url = "http://www.hkedcity.net/tools/topbar/caslogout.php?url=" + escape(curr_url); this.location.href = new_url; return; //document.getElementById('divBit').innerText +="\ntopbar logout"; } /* ======================= | application section | ======================= */ // regular check for application function selfCheck() { cBit = self.hkec_topbar_getLoginStatus(); if(cBit!= null && cBit.topObj.control) { if(cBit.topObj.status != cBit.appObj.status) { if(cBit.topObj.status){ cBit.appObj.setStatus(); hkec_topbar_setCookie("loginCookie", cBit); login_app(); }else{ cBit.appObj.clearStatus(); hkec_topbar_setCookie("loginCookie", cBit); logout_app(); } } else{ cBit.topObj.clearControl(); hkec_topbar_setCookie("loginCookie", cBit); } } else if (cBit!=null) { if(cBit.topObj.control==cBit.appObj.control && cBit.topObj.status != cBit.appObj.status) { if(cBit.topObj.status){ cBit.appObj.setStatus(); hkec_topbar_setCookie("loginCookie", cBit); login_app(); }else{ cBit.appObj.clearStatus(); hkec_topbar_setCookie("loginCookie", cBit); logout_app(); } } } setTimeout("selfCheck()", 1000); } appObj = new loginObj();