$(function() {
      $('#btn-feedback').toggle(function(e) {
            $('#frm-feedback').animate( { height: 'show' } );
            $('#txt-name').focus();
            e.preventDefault();
        }, function(e) {
            $('#frm-feedback').animate( { height: 'hide' } );
            e.preventDefault();
      });
      
      $('#btn-close').click(function() {
          $('#btn-feedback').click();
      });
      
      $('#btn-send-form').click(function() {
          var txtName = $('#txt-name').val();
          var txtEmail = $('#txt-email').val();
          var txtUrl = $('#txt-url').val();
          var txtCom = $('#txt-comment').val();
          
          if (!txtName || !txtCom) {
            $('#fb-msg').text('Please enter name and comments.');
          }
          else {
            $.post('http://vietmap.info/geoip/fb.php', { txtName: txtName, txtEmail: txtEmail, txtUrl: txtUrl, txtCom: txtCom }, function(response) {
              if (response) {
                  $('#fb-msg').text('Thanks for your feedback!');
                  window.setTimeout('toggleFB()', 1000);
              }
            });
          }
          
      });
      
      currPage();
      
      /*
      window.onbeforeunload = function() {
        $.get('http://batchiplocator.webatu.com/byebye.php');
        if (map) {GUnload();}
      };
      */
 
});

function toggleFB() {
  $('#btn-feedback').click();
}

function currPage() {
  var curr = window.location.pathname;
  curr = curr.split('/');
  i1 = curr.length-2;
  i2 = curr.length-3;
  rel = curr[i1];
  
  if (curr == 'default.php') {
    rel = curr[i2];
  }
    
  $('#main-tabs a[rel="' + rel + '"]').addClass('selected');
  
}