﻿//Get string from URL
function gup( name ){
    name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
    var regexS = "[\\?&]"+name+"=([^&#]*)";
    var regex = new RegExp( regexS );
    var results = regex.exec( window.location.href );
    if( results == null )
      return "";
    else
      return results[1];
}

//Update the div ("user") for Facebook
function FBuserConnected() { 
    //alert("going to connect");
    var user_box = document.getElementById("FBdisplay"); 
    user_box.innerHTML = "Welcome <fb:name uid='loggedinuser' useyou='false'></fb:name>. You are signed in with your Facebook account." 
    + "<br/>";
    FB.XFBML.Host.parseDomTree(); 
    /*
     var searchPhrase = gup("q");   //Get keyword from URL 
     if (searchPhrase != ""){
         if (gup("fbpublish") == "true"){
             document.getElementById("publish_feed").checked = true;
             searchPhrase=decodeURI(searchPhrase);
             var template_data = {"query": searchPhrase}
    	     FB.Connect.showFeedDialog(107383539756, template_data);
         }             
     }else{ //On Homepage always checkbox=true
            document.getElementById("publish_feed").checked = true;
     }*/
}
function connect(){
   alet("connect");
}
function notConnect(){
    alert("not connect");
}
function publishToFacebook_showShareDialog(){
    //if (gup("lid") != ""){
        //var song_title = document.getElementById("songTitle").innerHTML;
        //var song_lyrics = document.getElementById("songLyrics").innerHTML;
        //song_lyrics=song_lyrics.replace(/<(.|\n)+?>/gi,'');
        //var template_post = {"query":song_title, "lyrics": song_lyrics};  
    	//FB.Connect.showFeedDialog(107422504756, template_post);
    	var browser = navigator.appName;
    	    if (browser == "Netscape")
    	        FB.Connect.showShareDialog(window.location.href);
    	    else
    	        FB.Connect.showShareDialog(window.location);
    	//FB.Connect.showShareDialog(window.location.href);
    	//FB.Connect.streamPublish(song_lyrics);
   //}
}

/* 
This must be in the fotter:
<script type="text/javascript">//Initial Facebook
FB.init("04a0f9db71f37fab8445980a3dee842c","xd_receiver.htm", {"ifUserConnected" : update_user_box}); 
</script>

This must be in the header:
<script type="text/javascript" src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"></script>
*/

 
