function getCookie(c_name)
					{
					if (document.cookie.length>0)
					  {
					  c_start=document.cookie.indexOf(c_name + "=");
					  if (c_start!=-1)
						{
						c_start=c_start + c_name.length+1;
						c_end=document.cookie.indexOf(";",c_start);
						if (c_end==-1) c_end=document.cookie.length;
						return unescape(document.cookie.substring(c_start,c_end));
						}
					  }
					return "";
					}

					function setCookie(c_name,value,expiredays)
					{
						var exdate=new Date();
						exdate.setDate(exdate.getDate()+expiredays);
						document.cookie=c_name+ "=" +escape(value)+
						((expiredays==null) ? "" : ";expires="+exdate.toUTCString());
					}			


				window.fbAsyncInit = function() {
                FB.init({appId: '116030005101914', status: true, cookie: true, xfbml: true});
 
                /* All the events registered */
                FB.Event.subscribe('auth.login', function(response) {
                    // do something with response
                    login();
                });
                FB.Event.subscribe('auth.logout', function(response) {
                    // do something with response
                    logout();
					setCookie(userid,userid,-1);
                });
 
                FB.getLoginStatus(function(response) {
                    if (response.session) {
                        // logged in and connected user, someone you know
                        login();
                    }
                });
            };

			(function() {
                var e = document.createElement('script');
                e.type = 'text/javascript';
                e.src = document.location.protocol +
                    '//connect.facebook.net/en_US/all.js';
                e.async = true;
                document.getElementById('fb-root').appendChild(e);
            }());

            function login(){
                FB.api('/me', function(response)
					{
						document.getElementById('login').style.display = "block";
						//document.getElementById('login').innerHTML =  "<B>Welcome, "+response.first_name +"</B>";
						document.getElementById('bs_welcome').innerHTML = "Welcome, <B>"+response.first_name+"</b>";
						document.getElementById('bs_logout').innerHTML="";
						document.getElementById('bs_login').innerHTML="";
						userid=response.id;
						userid_coo=getCookie(userid);
						
						if (userid_coo=="")
							{//	alert(userid_coo);
								setCookie(userid,userid,365);
								fqlQuery();
								getintoData();
							}
						});
            }
            function logout(){
                document.getElementById('login').style.display = "none";
				document.getElementById('bs_welcome').innerHTML = "Welcome, <B>Guest</b>";
				document.getElementById('bs_login').innerHTML="<a href='/india/common/bslogin.php' class='link' '>Login</a><span class='linebar'>|</span> <span><a href='/india/common/bsregistration.php' class='link'>Register</a></span>";
            }
            //stream publish method
            function streamPublish(name, description, hrefTitle, hrefLink, userPrompt){
                FB.ui(
                {
                    method: 'stream.publish',
                    message: '',
                    attachment: {
                        name: name,
                        caption: '',
                        description: (description),
                        href: hrefLink
                    },
                    action_links: [
                        { text: hrefTitle, href: hrefLink }
                    ],
                    user_prompt_message: userPrompt
                },
                function(response) {
                });
             }
            function showStream(){
                FB.api('/me', function(response) {
                    //console.log(response.id);
                    streamPublish(response.name, 'http://www.business-standard.com contains News stuff', 'hrefTitle', 'http://www.business-standard.com', "www.business-standard.com");
                });
            }
             function share(){
                var share = {
                    method: 'stream.share',
                    u: 'http://www.business-standard.com'
                };
                 FB.ui(share, function(response) { console.log(response); });
            }
             function graphStreamPublish(){
                var body = 'BS Integration';
                FB.api('/me/feed', 'post', { message: body }, function(response) {
                    if (!response || response.error) {
                        alert('Error occured');
                    } else {
                       alert('Post ID: ' + response.id);
                    }
                });
            }
           function fqlQuery(){
                FB.api('/me', function(response) {
                     var query = FB.Data.query('select uid,first_name,middle_name,last_name,name,pic_small,pic_big,pic_square,pic,affiliations,profile_update_time,timezone,religion,birthday,birthday_date,sex,hometown_location,meeting_sex,meeting_for,relationship_status,significant_other_id,political,current_location,activities,interests,is_app_user,music,tv,movies,books,quotes,about_me,hs_info,education_history,work_history,notes_count,wall_count,status,has_added_app,online_presence,locale,proxied_email,profile_url,email_hashes,pic_small_with_logo,pic_big_with_logo,pic_square_with_logo,pic_with_logo,allowed_restrictions,verified,profile_blurb,family,username,website,is_blocked,contact_email,email from user where uid={0}', response.id);
                     query.wait(function(rows) {
				var htmlContent="";	 
				htmlContent="<form name='frmFb_Facebook' method='post' action='FB_getdata.php'>";
				htmlContent+="<input type='hidden' name='FB_uid' value='"+rows[0].uid+"' >";
				htmlContent+="<input type='hidden' name='FB_first_name' value='"+rows[0].first_name+"' >";
				htmlContent+="<input type='hidden' name='FB_middle_name' value='"+rows[0].middle_name+"' >";
				htmlContent+="<input type='hidden' name='FB_last_name' value='"+rows[0].last_name+"' >";
				htmlContent+="<input type='hidden' name='FB_name' value='"+rows[0].name+"' >";
				htmlContent+="<input type='hidden' name='FB_pic_small' value='"+rows[0].pic_small+"' >";
				htmlContent+="<input type='hidden' name='FB_pic_big' value='"+rows[0].pic_big+"' >";
				htmlContent+="<input type='hidden' name='FB_pic_square' value='"+rows[0].pic_square+"' >";
				htmlContent+="<input type='hidden' name='FB_pic' value='"+rows[0].pic+"' >";
				htmlContent+="<input type='hidden' name='FB_affiliations' value='"+rows[0].affiliations+"' >";
				htmlContent+="<input type='hidden' name='FB_profile_update_time' value='"+rows[0].profile_update_time+"' >";
				htmlContent+="<input type='hidden' name='FB_timezone' value='"+rows[0].timezone+"' >";
				htmlContent+="<input type='hidden' name='FB_religion' value='"+rows[0].religion+"' >";
				htmlContent+="<input type='hidden' name='FB_birthday' value='"+rows[0].birthday+"' >";
				htmlContent+="<input type='hidden' name='FB_birthday_date' value='"+rows[0].birthday_date+"' >";
				htmlContent+="<input type='hidden' name='FB_sex' value='"+rows[0].sex+"' >";
				htmlContent+="<input type='hidden' name='FB_relationship_status' value='"+rows[0].relationship_status+"' >";
				htmlContent+="<input type='hidden' name='FB_significant_other_id' value='"+rows[0].significant_other_id+"' >";
				htmlContent+="<input type='hidden' name='FB_political' value='"+rows[0].political+"' >";
				htmlContent+="<input type='hidden' name='FB_activities' value='"+rows[0].activities+"' >";
				htmlContent+="<input type='hidden' name='FB_interests' value='"+rows[0].interests+"' >";
				htmlContent+="<input type='hidden' name='FB_is_app_user' value='"+rows[0].is_app_user+"' >";
				htmlContent+="<input type='hidden' name='FB_music' value='"+rows[0].music+"' >";
				htmlContent+="<input type='hidden' name='FB_tv' value='"+rows[0].tv+"' >";
				htmlContent+="<input type='hidden' name='FB_movies' value='"+rows[0].movies+"' >";
				htmlContent+="<input type='hidden' name='FB_books' value='"+rows[0].books+"' >";
				htmlContent+="<input type='hidden' name='FB_quotes' value='"+rows[0].quotes+"' >";
				htmlContent+="<input type='hidden' name='FB_about_me' value='"+rows[0].about_me+"' >";
				htmlContent+="<input type='hidden' name='FB_notes_count' value='"+rows[0].notes_count+"' >";
				htmlContent+="<input type='hidden' name='FB_wall_count' value='"+rows[0].wall_count+"' >";
				htmlContent+="<input type='hidden' name='FB_status' value='"+rows[0].status+"' >";
				htmlContent+="<input type='hidden' name='FB_has_added_app' value='"+rows[0].has_added_app+"' >";
				htmlContent+="<input type='hidden' name='FB_online_presence' value='"+rows[0].online_presence+"' >";
				htmlContent+="<input type='hidden' name='FB_locale' value='"+rows[0].locale+"' >";
				htmlContent+="<input type='hidden' name='FB_proxied_email' value='"+rows[0].proxied_email+"' >";
				htmlContent+="<input type='hidden' name='FB_profile_url' value='"+rows[0].profile_url+"' >";
				htmlContent+="<input type='hidden' name='FB_pic_small_with_logo' value='"+rows[0].pic_small_with_logo+"' >";
				htmlContent+="<input type='hidden' name='FB_pic_big_with_logo' value='"+rows[0].pic_big_with_logo+"' >"
				htmlContent+="<input type='hidden' name='FB_pic_square_with_logo' value='"+rows[0].pic_square_with_logo+"' >";
				htmlContent+="<input type='hidden' name='FB_pic_with_logo' value='"+rows[0].pic_with_logo+"' >";
				htmlContent+="<input type='hidden' name='FB_allowed_restrictions' value='"+rows[0].allowed_restrictions+"' >";
				htmlContent+="<input type='hidden' name='FB_verified' value='"+rows[0].verified+"' >";
				htmlContent+="<input type='hidden' name='FB_profile_blurb' value='"+rows[0].profile_blurb+"' >";
				htmlContent+="<input type='hidden' name='FB_username' value='"+rows[0].username+"' >";
				htmlContent+="<input type='hidden' name='FB_website' value='"+rows[0].website+"' >";
				htmlContent+="<input type='hidden' name='FB_is_blocked' value='"+rows[0].is_blocked+"' >";
				htmlContent+="<input type='hidden' name='FB_contact_email' value='"+rows[0].contact_email+"' >";
				htmlContent+="<input type='hidden' name='FB_email' value='"+rows[0].email+"' >"
				htmlContent+="</form>";
				document.getElementById('name').innerHTML =htmlContent;
                     });
                });
            }
            function setStatus(){
                status1 = document.getElementById('status').value;
                FB.api(
                  {
                    method: 'status.set',
                    status: status1
                  },
                  function(response) {
                    if (response == 0){
                        alert('Your facebook status not updated. Give Status Update Permission.');
                    }
                    else{
                        alert('Your facebook status updated');
                    }
                  }
                );
            }
			function getintoData()
			{
			document.frmFb_Facebook.action="http://www.business-standard.com/fb/FB_getdata.php";
			document.frmFb_Facebook.submit();
		}



