var is_initialized = false; var apikey = "09e85a94ecc2500cb3b3622dfe06ad34"; var fbconnect_logout = 0; function ensure_init(callback) { if(!apikey) { window.alert("api_key is not set"); } if(window.is_initialized) { callback(); } else { FB_RequireFeatures(["XFBML", "CanvasUtil"], function() { FB.Facebook.init(apikey, "http://asia.cnet.com/connect/xd_receiver.htm"); FB.XFBML.Host.get_areElementsReady().waitUntilReady(function() { window.is_initialized = true; callback(); }); }); } } function facebook_onload(already_logged_into_facebook) { // user state is either: has a session, or does not. // if the state has changed, detect that and reload. ensure_init(function() { FB.Facebook.get_sessionState().waitUntilReady(function(session) { var is_now_logged_into_facebook = session ? true : false; // if the new state is the same as the old (i.e., nothing changed) // then do nothing if (is_now_logged_into_facebook == already_logged_into_facebook) { return; } // otherwise, refresh to pick up the state change refresh_page(); }); }); } /* * "Session Ready" handler. This is called when the facebook * session becomes ready after the user clicks the "Facebook login" button. * In a more complex app, this could be used to do some in-page * replacements and avoid a full page refresh. For now, just * notify the server the user is logged in, and redirect to home. * * @param link_to_current_user if the facebook session should be * linked to a currently logged in user, or used * to create a new account anyway */ function facebook_button_onclick() { ensure_init(function() { FB.Facebook.get_sessionState().waitUntilReady(function() { var user = FB.Facebook.apiClient.get_session() ? FB.Facebook.apiClient.get_session().uid : null; // probably should give some indication of failure to the user if (!user) { return; } // The Facebook Session has been set in the cookies, // which will be picked up by the server on the next page load // so refresh the page, and let all the account linking be // handled on the server side // This could be done a myriad of ways; for a page with more content, // you could do an ajax call for the account linking, and then // just replace content inline without a full page refresh. refresh_page(); }); }); } /* * Do a page refresh after login state changes. * This is the easiest but not the only way to pick up changes. * If you have a small amount of Facebook-specific content on a large page, * then you could change it in Javascript without refresh. */ function refresh_page(location) { if(location == null){ window.location.reload(true); }else{ window.location = location; } } /* * Prompts the user to grant a permission to the application. */ function facebook_prompt_permission(permission) { ensure_init(function() { FB.Connect.showPermissionDialog(permission); }); } /* // Is used? Disabled as caused JS error warning FB.Connect.showPermissionDialogCallback=function FB_Connect$showPermissionDialogCallback(permission, callback) { FB.Facebook.get_sessionState().waitUntilReady( Delegate.create(null,function(result) { FB.IFrameUtil.CanvasUtilServer.run(true); var singleton=FB.Connect._singleton; var iframeDom=FB.XdComm.Server.singleton.createNamedHiddenIFrame('dialogContent','','fb_permission_iframe',null); iframeDom.style.height='173px'; singleton._permissionDialog=new FB.UI.PopupDialog('Allow Extended Access?',iframeDom,true,false); iframeDom.src=FBIntern.Utility.getFacebookUrl('www')+'connect/prompt_permission.php'+'?api_key='+FB.Facebook.apiKey+'&v=' +FB.Facebook.version +'&next='+encodeURIComponent(singleton._permissionDialog._createCrossDomainClosingLink()) +'&cancel='+encodeURIComponent(singleton._permissionDialog._createCrossDomainClosingLink()) +'&channel_url='+encodeURIComponent(FB.XdComm.Server.singleton.get_receiverUrl()) +'&ext_perm='+permission;singleton._permissionDialog.show(); //GM: call the callback on closing event singleton._permissionDialog.add_closing( Delegate.create(null,function(closingResult) { singleton._permissionDialog=null; if(callback){callback.invoke();} }) ); //END modifications }) ); } */ function FBLogout(fb_logout) { var file = '/members/logout.htm'; fbconnect_logout = fb_logout; request.open( "POST", file, true ); request.onreadystatechange = FBupdateLogout; request.send(null); //document.getElementById('ajres').innerHTML = '
'; } function FBupdateLogout() { if (request.readyState == 4) { if (request.status == 200) { //alert(request.responseText); var doRefresh = globalRefresh; if (doRefresh == 1) { if(fbconnect_logout == 1){ FB.Connect.logout(window.location.reload(true)); } else { window.location.reload(true); } } else { if(fbconnect_logout == 1){ FB.Connect.logout(); } else { if(window.postlogout){postlogout();} } } } else ;//alert("status is " + request.status); } } function FBInit() { if(!apikey) { window.alert("api_key is not set."); } else { if(window.is_initialized) { } else { FB_RequireFeatures(["XFBML"], function() { FB.init("09e85a94ecc2500cb3b3622dfe06ad34", "xd_receiver.htm",{"ifUserConnected":FBChkStatus}); window.is_initialized = true; }); } } } function FBDoLogin() { FB.ensureInit(function() { FB.Facebook.get_sessionState().waitUntilReady(function() { var user = FB.Facebook.apiClient.get_session() ? FB.Facebook.apiClient.get_session().uid : null; if(!user) { window.alert("Login failed."); } else { FBChkStatus(); } }); }); } function FBNativeLogin(formName, email, pass, load, err) { var userMail = document.forms[formName].elements[email]; var userPass = document.forms[formName].elements[pass]; if(userMail.value == "") { alert("Please fill in your e-mail/username"); exit(0); } if(userPass.value == "") { alert("Please fill in your password"); exit(0); } var divLoad = document.getElementById(load); var divErr = document.getElementById(err); var xmlHttp = initXMLHttp(); if(xmlHttp) { var url = "/connect/ajMemberLogin.htm"; var params = "mail="+userMail.value+"&pass="+userPass.value; xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { var rspTxt = xmlHttp.responseText; if(rspTxt.length > 1) { userMail.value = ""; userPass.value = ""; divLoad.innerHTML = ""; divErr.innerHTML = rspTxt; } else { refresh_page(); } } else { divLoad.innerHTML = ""; } } //Calling the page to perform xmlHttp.open("POST",url,true); //Send the proper header information along with the request xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xmlHttp.setRequestHeader("Content-length", params.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(params); } } function FBChkMember(divID) { FB.ensureInit(function() { FB.Facebook.apiClient.requireLogin(function() { var xmlHttp = initXMLHttp(); if(xmlHttp) { var url = "/connect/verify.htm"; var params = ""; xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { var rspTxt = xmlHttp.responseText; if(rspTxt.length > 1) { var strDivID = "divFBDialog"; FBCreateElement("div", strDivID, "divModal"); document.getElementById(strDivID).innerHTML = xmlHttp.responseText; } else { FBChkStatus(divID); } } } //Calling the page to perform xmlHttp.open("POST",url,true); //Send the proper header information along with the request xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xmlHttp.setRequestHeader("Content-length", params.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(params); } }); }); } function FBChkStatus(divID) { FB.ensureInit(function() { FB.Connect.get_status().waitUntilReady(function(status) { switch(status) { case FB.ConnectState.appNotAuthorized: // Logged in and NOT yet authorized the apps break; case FB.ConnectState.connected: // Logged in and has authorized the apps // FBUpdateProfile(divID); refresh_page(); break; case FB.ConnectState.userNotLoggedIn: // Not Logged in to Facebook break; } }); }); } function FBUpdateProfile(divID) { var xmlHttp = initXMLHttp(); if(xmlHttp) { var url = "/connect/ajFBLogin.htm"; var params = ""; xmlHttp.onreadystatechange = function() { if(xmlHttp.readyState == 4) { var rspTxt = xmlHttp.responseText; document.getElementById(divID).innerHTML = rspTxt; FB.XFBML.Host.parseDomTree(); } } //Calling the page to perform xmlHttp.open("POST",url,true); //Send the proper header information along with the request xmlHttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded; charset=UTF-8"); xmlHttp.setRequestHeader("Content-length", params.length); xmlHttp.setRequestHeader("Connection", "close"); xmlHttp.send(params); } } function FBSetExtPermission(strPermission) { FB.ensureInit(function() { FB.Facebook.get_sessionState().waitUntilReady(function() { FB.Facebook.apiClient.users_hasAppPermission(strPermission, function(result) { if(result == 0) { FB.Connect.showPermissionDialog(strPermission); } else { // permission has been granted alert("Permission [" + strPermission + "] has been granted."); } }); }); }); } function FBCreateElement(elType, elID, elClass) { var el = document.createElement(elType); el.id = elID; el.className = elClass; document.body.appendChild(el); } function FBRemoveElement(elID) { var el = document.getElementById(elID); document.body.removeChild(el); } function FBRenderLoginButton(divID, regionID) { FB.ensureInit(function() { FB.XFBML.Host.autoParseDomTree = false; var container = document.getElementById(divID); container.setAttribute("size", "medium"); container.setAttribute("background", "light"); container.setAttribute("length", "short"); container.setAttribute("onlogin", "FBChkMember('"+regionID+"')"); var loginButton = new FB.XFBML.LoginButton(container); FB.XFBML.Host.addElement(loginButton); }); } function initXMLHttp() { var obj = false; try { obj = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { obj = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { try { obj = new XMLHttpRequest(); } catch(e) { return false; } } } return obj; } function submit_reg_form() { document.loginForm.action.value = "regacc"; document.loginForm.submit(); }