/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

var t="test";


var LAM = LAM || {};
	LAM.fb_login_and_call = function(callback)
	{
		FB.getLoginStatus(function(response) {
		  if (response.session) {
		    // logged in and connected user, someone you know
				callback();
		  } else {
		    // no user session available, someone you dont know
					FB.login(function(response) {
					  if (response.session) {
					    if (response.perms) {
					      // user is logged in and granted some permissions.
					      // perms is a comma separated list of granted permissions
								callback();
					    } else {
					      // user is logged in, but did not grant any permissions
								// alert('Вы не разрешили нам доступ к вашему аккаунту.');
					    }
					  } else {
					    // user is not logged in
							// alert('Вы не авторизованы в facebook.');
					  }
					}, {perms:'email,user_birthday,publish_stream,offline_access'});
		  }
		});
	}


function process_login()
{
    $.ajax({
       type: "POST",
       data: "",
       answ: {is_autoriz:"is_autoriz", sussed: "sussed", is_no_base: "is_no_base"},
       dataType: 'json',
       url: "/login/login_ajax.php",
       async: false,
       success: function(answ){
          if (answ.is_autoriz=="is_autoriz")
             {
               //location.replace("http://thefirstclass.ru/login/loginsussed.php");
               window.location.reload(true)
             }
             else if (answ.is_autoriz=="" && answ.sussed!="")
             {
                //alert("is_bitrix");
                //location.replace("http://thefirstclass.ru/login/loginsussed.php");
                window.location.reload(true)
              }
              else if (answ.is_autoriz=="" && answ.is_no_base!="")
              {
                  //alert("is_no_bitrix")
                  $("#overley").show();
                  $("#fb_connect_select").show();
                  $("#fb_form2").hide();
                  $("#fb_form1").show();
              }
              else
              {
                   //alert("Чего-то не то");
                   LAM.fb_login_and_call();
              }
       }
    });
}

function step_2()
{
    $("#fb_form1").hide();
    $("#err_user_info").html("");
    $("#fb_form2").show();
}

function link_akk()
{
   $("#err_user_info").html("");
   fields_form=$("#form_login_fb").serializeArray();
   $.ajax({
       type: "POST",
       data: fields_form,
       answ: {link:"link", error: "error"},
       dataType: 'json',
       url: "/login/link.php",
       async: false,
       success: function(answ){
          if (answ.error!="")
             {
                 $("#err_user_info").html("Неверное имя пользователя или пароль");
             }
             else if (answ.error=="" && answ.link=="Ok")
             {
                location.replace("http://thefirstclass.ru/login/loginsussed.php");
             }
              else
              {
                   alert("Чего-то не то");
              }
       }
    });
}

$(document).ready(function() {
    //alert (t);
    $(".b_close").click(function(){
                  $("#overley").hide();
                  $("#fb_connect_select").hide();
            });
});




