    function fb_login(){        
        FB.login(function(response){
            if (response.perms.length>2) {
            // user is logged in and granted some permissions.
            // perms is a comma separated list of granted permissions
                document.location.href=document.location.href;
            } else {
            // user is logged in, but did not grant any permissions
                //alert(response.perms.length);
                if(response.perms.length>1){
                    alert('Login Failed! Viakeo needs your facebook permission to login successfully.');
                    document.location.href=document.location.href;
                }
                
            }

        },{perms:'email,user_birthday,publish_stream,read_stream'});
    }
    
    function fb_login2(){        
        //close_popup('login_div');
        //clear_popup();
        $.fancybox.close();
        FB.login(function(response){
            
            if (response.perms.length>2) {
            // user is logged in and granted some permissions.
            // perms is a comma separated list of granted permissions
                document.location.href=document.location.href;
            } else {
            // user is logged in, but did not grant any permissions
                //alert(response.perms.length);
                if(response.perms.length>1){
                    alert('Login Failed! Viakeo needs your facebook permission to login successfully.');
                    document.location.href=document.location.href;
                }
                
            }

        },{perms:'email,user_birthday,publish_stream,read_stream, offline_access'});
    }
    
    function fb_login_share(){
        Delete_Cookie('ind_id', '/new_viakeo/', '');    
        Delete_Cookie('userPlanner', '/new_viakeo/', '');
        Delete_Cookie('currenttrip', '/new_viakeo/', '');   
        Delete_Cookie('tripelements', '/new_viakeo/', '');          
        var url = geturl()+"/authenticate.php";
        url = url + "?signout=yes";
        url += "&"+ dps_ajax_timer(); 
        dps_ajax_req('GET', url, null, '', 'text/html');        
        fb_login();
    }    
    
    function facebook_share(uid, fb_msg){
        var trip_url = window.location.href;
        var fid = uid;        
        $.ajax({
        type: "POST",
        url: geturl()+"/facebook_share.php",
        data: {fid: fid, msg: fb_msg, turl: trip_url},
        success: function(theResponse){
            var result = trim(theResponse);
            //alert(result);
            close_popup('facebook_share_div');
        }
        
        
        });        
    }
    function facebook_ask(uid, fb_msg){
        var trip_url = window.location.href;
        var fid = uid;        
        $.ajax({
        type: "POST",
        url: geturl()+"/facebook_ask.php",
        data: {fid: fid, msg: fb_msg, turl: trip_url},
        success: function(theResponse){
            var result = trim(theResponse);
            //alert(result);
            close_popup('facebook_ask_div');
        }
        
        
        });        
    }
