window.fbAsyncInit = function() { FB.init({appId: '105402769490147', status: true, cookie: true, xfbml: true, oauth: true}); activate_spootnic_facebook(); }; (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 connection_spootnic_facebook() { FB.getLoginStatus(function(response) { if (response.authResponse) { check_connection_spootnic_facebook(); } }); FB.Event.subscribe('auth.login', function(response) { check_connection_spootnic_facebook(); }); } function check_connection_spootnic_facebook() { FB.api('/me', function(response) { var id_user = escape(response.id); check_facebook_user(id_user); }); } function activate_spootnic_facebook() { var id_register_form = document.getElementById('register_form'); if (id_register_form !== undefined && id_register_form !== null) { FB.getLoginStatus(function(response) { if (response.authResponse) { check_login_spootnic_facebook(); } }); FB.Event.subscribe('auth.login', function(response) { check_login_spootnic_facebook(); }); document.getElementById('register_pwd').value = ''; } var id_facebook_invite_on = document.getElementById('facebook_invite_on'); if (id_facebook_invite_on !== undefined && id_facebook_invite_on !== null) { FB.getLoginStatus(function(response) { if (response.authResponse) { invite_facebook_onlogin(); } }); FB.Event.subscribe('auth.login', function(response) { window.location.href = window.location.href; }); } } function check_login_spootnic_facebook(){ FB.api('/me', function(response) { var id_user = escape(response.id); check_facebook_user(id_user); document.getElementById('button_facebook_prefill').style.display = "none"; document.getElementById('button_facebook_unfill').style.display = "block"; fill_form_spootnic_facebook(response); }); } function fill_form_spootnic_facebook(response) { var birthday = escape(response.birthday); var tab_birthday = birthday.split('/'); var month_birthday = tab_birthday[0] ; var day_birthday = tab_birthday[1] ; var year_birthday = tab_birthday[2] ; day_birthday = format_date(day_birthday); month_birthday = format_date(month_birthday); var id_user = escape(response.id); document.getElementById('user_facebook').value = id_user; var email = escape(response.email); format_text(escape(response.last_name),escape(response.first_name)); if(email != 'undefined') document.getElementById('register_email').value = email; document.getElementById('register_birthdateD').value = day_birthday; document.getElementById('register_birthdateM').value = month_birthday; document.getElementById('register_birthdateY').value = year_birthday; document.getElementById('button_facebook_prefill').style.display = "none"; document.getElementById('button_facebook_prefill_again').style.display = "none"; document.getElementById('button_facebook_unfill').style.display = "block"; var query = FB.Data.query('SELECT current_location FROM user WHERE uid={0}', id_user); query.wait(function(rows) { if(rows[0].current_location !== null) get_country(rows[0].current_location.country); else verifcountry(); }); verifpass(); verifemail(); verifbirthdate(); verifpolicy(); } function get_country(country) { var xhr_get_country = getXhr(); xhr_get_country.onreadystatechange = function() { if(xhr_get_country.readyState == 4 && xhr_get_country.status == 200) { var country_code = xhr_get_country.responseText; if(country_code == '0') { document.getElementById('register_country').value = ''; } else { document.getElementById('register_country').value = country_code; } verifcountry(); }; } country = escape(country); xhr_get_country.open("POST",'ajax_facebook_registration.php',true); xhr_get_country.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); xhr_get_country.send("country="+country); } function format_text(last,first) { var xhr_format_text = getXhr(); xhr_format_text.onreadystatechange = function() { if(xhr_format_text.readyState == 4 && xhr_format_text.status == 200) { var login = xhr_format_text.responseText; if(login == '0') { document.getElementById('register_login').value = ''; } else { document.getElementById('register_login').value = login; } veriflogin(); }; } last = escape(last); first = escape(first); xhr_format_text.open("POST",'ajax_facebook_registration.php',true); xhr_format_text.setRequestHeader('Content-Type','application/x-www-form-urlencoded'); xhr_format_text.send("last="+last+"&first="+first); } function form_register_clear(){ document.getElementById('register_login').value = ""; document.getElementById('register_email').value = ""; document.getElementById('register_country').value = ""; document.getElementById('register_birthdateD').value = ""; document.getElementById('register_birthdateM').value = ""; document.getElementById('register_birthdateY').value = ""; document.getElementById('button_facebook_prefill_again').style.display = "block"; document.getElementById('button_facebook_prefill').style.display = "none"; document.getElementById('button_facebook_unfill').style.display = "none"; veriflogin(); verifemail(); verifcountry(); verifbirthdate(); } function format_date(date) { if (date <= 9) new_date = date.charAt(1); else new_date = date; return new_date; }