// logging
var debugging = false; // or true

if(typeof console == "undefined")
{
  var console = { log: function(){} };
}
else if(!debugging || typeof console.log == "undefined")
{
  console.log = function(){};
}

/**
 * AJAX call to php script to check user 
 * login status from Answers
 */
jQuery(document).ready(function(){
  
  console.log('DOC READY');
  
  // look for cookie
  var fc_hash_cookie = $.cookie('fc_hash');
  var fc_uuid_cookie = $.cookie('fc_uuid');
  
  console.log('COOKIES: '+fc_hash_cookie+'|'+fc_uuid_cookie);
  
  // get environment
  if(jQuery('#devNotice').length == 1)
  {
    var env = 'http://dev.foodconnect.com';
  }
  else
  {
    var env = 'http://www.foodconnect.com';
  }
  
  console.log('ENV: '+env);
  
  if(fc_hash_cookie != '' && fc_uuid_cookie != '')
  {
    console.log('JSON CALL: '+env+'/answersValidation.php');
        
    $.getJSON(
      env+'/answersValidation.php?environment='+env+'&fc_hash='+fc_hash_cookie+'&fc_uuid='+fc_uuid_cookie+'&jsoncallback=?',
      function(data){
        
        console.log('JSON RESPONSE: '+data.valid);
        
        if(data.valid == 1)
        {
          $('div#login').replaceWith(data.html);
        }
      }
    );
    
  }
  else
  {
    console.log('NO COOKIES!');
  }
  
  console.log('END');
  
});
