// -*- coding: utf-8 -*-

// お気に入りブランド登録
function addMyBrand(brand_id) {
  $.ajax({
           type: 'POST',
           url: '/mypage/brands/add',
           data: {brand_id: brand_id},
           async: true,
           timeout: 5000,
           cache: false,
           success: function(data, status) {
             switch (data) {
             case "OK":
               addMyBrandOK();
               break;
             case "NG":
               addMyBrandNG();
               break;
             case "DUP":
               addMyBrandDUP();
               break;
             case "NOT_LOGIN":
               addMyBrandLOGIN();
               break;
             }
           },
           error: function (XHR, status, errorThrown) {
             addMyBrandNG();
           }
         });
}

// お気に入りアイテム登録
function addMyItem(item_id) {
  $.ajax({
           type: 'POST',
           url: '/mypage/products/add',
           data: {item_id: item_id},
           async: true,
           timeout: 5000,
           cache: false,
           success: function(data, status) {
             switch (data) {
             case "OK":
               addMyItemOK();
               break;
             case "NG":
               addMyItemNG();
               break;
             case "DUP":
               addMyItemDUP();
               break;
             case "NOT_LOGIN":
               addMyItemLOGIN();
               break;
             }
           },
           error: function (XHR, status, errorThrown) {
             addMyItemNG();
           }
         });
}

// お気に入りスナップ登録
function addMySnap(street_snap_id) {
  $.ajax({
           type: 'POST',
           url: '/mypage/snaps/add',
           data: {street_snap_id: street_snap_id},
           async: true,
           timeout: 5000,
           cache: false,
           success: function(data, status) {
             switch (data) {
             case "OK":
               addMySnapOK();
               break;
             case "NG":
               addMySnapNG();
               break;
             case "DUP":
               addMySnapDUP();
               break;
             case "NOT_LOGIN":
               addMySnapLOGIN();
               break;
             }
           },
           error: function (XHR, status, errorThrown) {
             addMySnapNG();
           }
         });
}


function logged_in() {
  var loginFlag;
  $.ajaxSetup({async:false});
  $.get('/mypage/logged_in',
        {},
        function(data){
          if (data == "true") {
            loginFlag = true;
          }
          else {
            loginFlag = false;
          }
        });
  if (loginFlag) {
    return true;
  }
  else {
    return false;  
  }
}

