/* 
 * this file will contain all functions related to facebook conntect
 */

var site_url = "/fbapp/latinfighters/index.php/";

//this function will be called when user logged in via facebook connect

function InitializeFacebook(){
    FB.init("cb12862febfc8e0ba9f49050cb451333","http://www.iqvis.com/fbapp/latinfighters/xd_receiver.htm",{"ifUserConnected" : PerformLoginOnLoad});
}

function PerformLogin(){    
    $("#user_app_id").val(FB.Facebook.apiClient.get_session().uid);
    //alert(FB.Facebook.apiClient.get_session().uid);
    window.location = site_url + "performAppLogin/" +  $("#user_app_id").val();

    /*var user_box = document.getElementById("user_information");
    // add in some XFBML. note that we set useyou=false so it doesn't display "you"
    user_box.innerHTML = "<span>" +
                        "<fb:profile-pic uid=loggedinuser facebook-logo=true></fb:profile-pic>" +
                        "Welcome, <fb:name uid=loggedinuser useyou=false></fb:name>." +
                        "</span>";
    // because this is XFBML, we need to tell Facebook to re-process the document
    FB.XFBML.Host.parseDomTree();*/
}


function PerformLoginOnLoad(){
	 
	
	
    //$("#user_app_id").val(FB.Facebook.apiClient.get_session().uid);
}

function performLogout(value){
    if(value == 1){
        FB.Connect.logoutAndRedirect(site_url + "login/logout");
    }
    else{
        window.location = site_url + "login/logout";
    }
}

function GetUserInformation(){
	
    var user_id = $("#user_app_id").val();
    var user_box = document.getElementById("user_information");
    // add in some XFBML. note that we set useyou=false so it doesn't display "you"
    user_box.innerHTML = "<div style='width:60px; float: left;'>" +
                        "<fb:profile-pic uid=loggedinuser facebook-logo=true></fb:profile-pic>" +
                        "</div><div style='float: left; padding-left: 10px;'>" +
                        "<fb:name uid=loggedinuser useyou=false linked=false></fb:name>" +
                        "</div>" + user_box.innerHTML;
    // because this is XFBML, we need to tell Facebook to re-process the document
    FB.XFBML.Host.parseDomTree();
    $("#user_information").fadeIn();
}
//this function is use to get profile info of the user
//who connect with facebook.
function showProfileinfo()
{
	
        var uid = $("#user_app_id").val();
        var user_img_box = document.getElementById("facebook_img");
        var user_info_box = document.getElementById("facebook_info");

        user_img_box.innerHTML ="<fb:profile-pic uid='" + uid +  "' facebook-logo=true width=150 height=150></fb:profile-pic>";
        user_info_box.innerHTML ="<h3>Basic Information:</h3>"+
                         "<span style=line-height:18px;>"+
                         "<table cellpadding='3' cellspacing='0'  width='100%'>"+
                         "<tr><td><b>First Name&nbsp;:</b>&nbsp;<fb:name uid='" + uid +  "' useyou=false firstnameonly=true linked=false></fb:name><td><td>&nbsp;</td></tr>"+
                         "<tr><td><b>Last Name&nbsp;:</b>&nbsp;<fb:name uid='" + uid +  "' useyou=false lastnameonly=true linked=false></fb:name></td><td>&nbsp;</td></tr>"+
                         "</table></span>";
                     
        FB.XFBML.Host.parseDomTree();
        $("#user_img_box.innerHTML").fadeIn();
        $("#facebook_info").fadeIn();

    // array of the profile values
    /*var field_arr = new Array("first_name","last_name","birthday_date","current_location","pic_big");
    var  result ;
    var res;
    var first_name;
    var last_name;
    var birthday_date;
    var location;
    var city,state,zip,country,pic;
    
    
	function getfieldValues()
	{
		first_name = res[0].first_name;
		last_name = res[0].last_name;
		pic = res[0].pic_big;
		birthday_date = res[0].birthday_date;
		location = res[0].current_location;
		city =location.city; 
		state =location.state; 
		zip =location.zip; 
		country =location.country; 
		
		if(!pic)
		{
			var url_pic ="<img src='media/images/noimage.gif' width=150 height=150>";
		}else{
			  url_pic = pic;
		}
		//alert(first_name+','+last_name+','+birthday_date+','+city+','+state+','+zip+','+country+','+pic+'ddd');
		//alert("<img src="+pic+">");
		user_img_box.innerHTML ="<img src="+url_pic+" width=150 height=150>";
		user_info_box.innerHTML ="<h3>Basic Information:</h3>"+	
                                 "<span style=line-height:18px;>"+
                                 "<table cellpadding='3' cellspacing='0'  width='100%'>"+
                                 "<tr><td><b>First Name&nbsp;:</b>&nbsp;"+first_name+"<td><td>&nbsp;</td></tr>"+
                                 "<tr><td><b>Last Name&nbsp;:</b>&nbsp;"+last_name+"</td><td>&nbsp;</td></tr>"+
                                 "<tr><td><b>DOB&nbsp;:</b>&nbsp;"+birthday_date+"</td><td>&nbsp;</td></tr>"+
                                 "<tr><td><b>Address&nbsp;:</b>&nbsp;"+city+'&nbsp;,&nbsp;'+state+'&nbsp;'+zip+'&nbsp;,&nbsp;'+country+"<td><td>&nbsp;</td></tr>"+
                                 "</table></span>";

                 InitializeFacebook();
		                         
                FB.XFBML.Host.parseDomTree();
                $("#user_img_box.innerHTML").fadeIn();
                $("#facebook_info").fadeIn();
		                         	
            }
        InitializeFacebook();

	FB.Facebook.apiClient.users_getInfo([uid],[field_arr], function(result,ex){
			 res=result;
			 getfieldValues();
			 
		}
	);*/
}
	
