﻿

//function FBConnect_Login(nama, email, uid, gender, birthdate) {
//    WCFOthers.JSON_FBConnect_Login(nama, email, uid, gender, birthdate, signUpReturn);
//}

//    function signUpReturn(result) {
//        if (result == "ERR") {
//            //GAGAL
//            //kasi notif gagal
//            alert("GAGAL");
//        } else if (result == "PSS") {
//            //belum ada pass
//            document.getElementById("divFB_isiPassword").style.display = '';
//        
//        } else {
//            //window.location.reload();                    
//            //OK
//        }
//    }



function FBConnect_Login(nama, email, id, gender, birthday) {
    WCFOthers.JSON_FBConnect_Login(nama, email, id, gender, birthday, signUpReturn);
}
    function signUpReturn(result) {
        if (result == "0") {
            // belum register
            // pindah ke halaman register
            window.location.href = _rootPath + "sign.up.fb";
        } else {
            //sudah register
            //pindah ke home, session dibuat di WCF
            window.location.href = _rootPath + "Default.aspx";
        }
    }



function fb_login() {
             document.getElementById('fb_loggedOut').style.display = '';



                FB.login(function(response) {
                    if (response.status == 'connected') {
                       FB.api('/me', function(user) {
                            if (user.id != null) {
                                document.getElementById('fb_loggedOut').style.display = 'none';
                                document.getElementById('fb_loading').style.display = '';
                                //                                var email = user.email;
                                //                                FBConnect_Login(email, user.id);

                                var nama = user.name;
                                var id = user.id;
                                var gender = user.gender;
                                var email = user.email;
                                var birthday = user.birthday;
                                FBConnect_Login(nama, email, id, gender, birthday);
                            }
                        });
                    } else {
                    document.getElementById('fb_loggedOut').style.display = '';
                    document.getElementById('fb_loading').style.display = 'none';                           
                    }
                }, { scope: 'read_stream,publish_stream,email,offline_access,user_birthday' });
            }


            function fb_logout() {
                FB.logout(function(response) {
                    alert("Kamu sudah terlogout");
                    window.location.reload();
                });
            }
            
