function isEmpty(inputStr){ 
    if (null == inputStr || "" == inputStr ){ 
        return true; 
    } 
    return false; 
}
function showMessage(user_id,timeout){
  $.sound.play('/sounds/trans.wav');
  $("#object").animate({top: "7px"}, 2000).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100).fadeOut(100).fadeIn(100);
  $("#close_message").click(function(){
     $("#object").fadeOut("slow");
     setTimeout('checkAlerts('+user_id+','+timeout+')',timeout);
  });
};
function checkAlerts(user_id,timeout){
        $("#object").fadeOut("fast");
        $.post('/ajax/profile/checkalerts',{user_id:user_id},function (data){
            if (!isEmpty(data)){
                var title = '';
                var message = '';
                var data_array = data.split('|');
                if (data_array[0]=='new_message'){
                    title = 'You have a new message';
                    message = 'You received a new message. Please <a href="/messaging/inbox">click here</a> to go to your inbox.';
                    var current_message_count = $('#message_count').html();
                    current_message_count = current_message_count.replace('(','');
                    current_message_count = current_message_count.replace(')','');
                    var int_current_message_count = parseInt(current_message_count)+1;
                    $('#message_count').html('('+int_current_message_count.toString()+')');
                }else if (data_array[0]=='new_friendship_request'){
                    title = 'You have a new friendship request';
                    message = 'You received a new friendship request. Please <a href="/profile/requests">click here</a> to see it.';                
                }else if (data_array[0]=='friend_online'){
                    title = '';
                    message = '<b><a href="/profile/view/user/'+data_array[1]+'">'+data_array[1]+'</a></b> is online now';                                
                }else if (data_array[0]=='friend_offline'){
                    title = '';
                    message = '<b><a href="/profile/view/user/'+data_array[1]+'">'+data_array[1]+'</a></b> is offline now';                                
                }
                var html = '<div id="object" class="message" style="color:black;"><img id="close_message" style="float:right;cursor:pointer" src="/images/12-em-cross.png" /><strong>'+title+'</strong><p>'+message+'</p></div>';
                $('#header').prepend(html);
                showMessage(user_id);
            }else{
                setTimeout('checkAlerts('+user_id+','+timeout+')',timeout);
            }
    });
}


function showLocationChooser(user_id){
  $.sound.play('/sounds/trans.wav');
  $("#address_chooser").animate({top: "150px"}, 2000);
  $("#close_message3").click(function(){
        $("#address_chooser").fadeOut("slow");
     });
  $('#send_it').bind('click',function(){
      var country_id = $('#country_id').val();
      var city_id = $('#city_id').val();
      $.post('/ajax/profile/savelocation',{user_id:user_id,country_id:country_id,city_id:city_id},function(data){
            $("#address_chooser").html('<div style="font-size:15px; font-weight:bold;text-align:center;">Thank you!</div>');
            $("#address_chooser").animate({top: "-150px"}, 2000);       
      });
  });
}
  