
function refresh_page() {
    window.location.href = unescape(window.location.href);
}


//$(document).ready(function() {
//
//
//  $('.packageid_button').click(function() {
//  
//      var packageId   = $('#packageid_var').val();
//      var packageCode   = $('#packagecode_var').val();
//      var user   = '#userid_' + packageId;
//      var packsend = '#pack_send_' + packageId;
//      var progress = '#pack_progress_' + packageId;
//      
//      var userId      = $(user).val();
//      var send_panel    = $(packsend);
//      var progress_panel  = $(progress);
//      
//      if (userId.blank()) {
//      
//        alert("User ID field required!");
//      
//      } else {
//      
//        send_panel.hide();
//        progress_panel.show();
//        
//        var urlstring = "packageid=" + packageId + "&packagecode=" + packageCode + "&userid=" + userId;
//        
//        $.ajax({ 
//          type: "POST", 
//          url: "staff_donationpacks_give.php", 
//          data: urlstring,  
//          success: function(transport){    
//            progress_panel.hide();
//            send_panel.show();
//            alert(transport);
//          },
//          error: function(transport){
//              alert('An Error has occurred.');
//          }   
//        }); // end ajax
//      } // end if-else
//  }); // end function
//  
//}); // end document ready


function UpdateUserPofileBox() {
  
  var _url = 'service_profile_box.php?v=' + Math.random();
  
  $.ajax({ 
    type: "GET", 
    url: _url, 
    success: function(transport){    
      $('#main-profile-box').html(transport);
    }   
  }); // end ajax
} // end function

function doRefill(refill) {
  
  var urlstring = 'what=' + refill;
  
  $.ajax({ 
    type: "POST", 
    url: "refill.php", 
    data: urlstring,  
    success: function(transport){    
        response = transport.split("|");
        if($.trim(response[0]) =="ok"){
          
          UpdateUserPofileBox();

        } else {            
            //alert('An Error has occurred.');
            alert(response[1]);
        }
    },
      error: function(transport){
        alert('An Error has occurred.');
    }   
  }); // and ajax
}

function doRefill2(refill) {
  
  var urlstring = 'what=' + refill;
  
  $.ajax({ 
    type: "POST", 
    url: "refill.php", 
    data: urlstring,  
    success: function(transport){    
        response = transport.split("|");
        if($.trim(response[0]) =="ok"){
          
          UpdateUserPofileBox();
          refresh_page();

        } else {            
            //alert('An Error has occurred.');
            alert(response[1]);
        }
    },
      error: function(transport){
        alert('An Error has occurred.');
    }   
  }); // and ajax
}

// shout mini JS

function doShoutMini() {

    $('#shout_progress_mini').show();

    $('#shout_submit_mini').attr('disabled', true);
    $('#shout_submit_mini').val('Wait for 5 sec.');
    var shoutMsg = $('#shout_msg').val();
    
    $.ajax({ 
      type: "GET", 
      url: "shoutbox_post_db.php?shout_msg=" + shoutMsg,
       
      complete: function(transport){
              if ( transport== "*banned*" ) {
                alert("You are banned from posting to the shout box!");
              }

            $('#shout_msg').val('');
            RefreshShoutsMini();
            $('#shout_submit_mini').attr('disabled', false);
            $('#shout_submit_mini').val('SHOUT NOW!');
        }   
    });        
}; // end function

function RefreshShoutsMini() {
  
  var chattype = $('#chattype').val();
  
  if(chattype==''){
    chattype ='ca';
  }	  
  // check if the eleme exist
  var shoutMini = $('#user_shouts_mini');
  
  if (shoutMini) {
  
     var url = 'shoutbox_mini_content_db.php?chattype='+chattype;
    $('#shout_progress_mini').show();

    $.ajax({ 
      type: "GET", 
      url: url,       
      success: function(transport){
        $('#user_shouts_mini').html(transport);
        $('#shout_progress_mini').hide();     
      }   
    }); // end ajax  
  } // end if 
}; // end function


function setChat(val){
	
 if(val==1){
	$('#chattype').val('w');
	RefreshShoutsMini();
 }else{
	$('#chattype').val('ca');
	RefreshShoutsMini();
 }
}





function SendDonationPack(packageId, packageCode) {
    
    userId = $('#userid_' + packageId).val();
    send_panel = $('#pack_send_' + packageId);
    progress_panel = $('#pack_progress_' + packageId);
    
  
    
    if (userId == '') {
        
        alert("User ID field required!");
        
    } else {
    
        send_panel.hide();
        progress_panel.show();
        
       
        
        var urlstring = "packageid=" + packageId + "&packagecode=" + packageCode + "&userid=" + userId;
        
        $.ajax({ 
          type: "GET", 
          url: "staff_donationpacks_give.php", 
          data: urlstring,  
          success: function(transport){    
            progress_panel.hide();
            send_panel.show();
            alert(transport);
          },
          error: function(transport){
              alert('An Error has occurred.');
          }   
        });        
        

    }
    
    return false;
    
}

function SendSubscriptionPack(packageId, packageCode) {
    
    userId = $('#userid_' + packageId).val();
    send_panel = $('#pack_send_' + packageId);
    progress_panel = $('#pack_progress_' + packageId);
    
  
    
    if (userId == '') {
        
        alert("User ID field required!");
        
    } else {
    
        send_panel.hide();
        progress_panel.show();
        
       
        
        var urlstring = "subscriptionId=" + packageId + "&subscriptionCode=" + packageCode + "&userid=" + userId;
        
        $.ajax({ 
          type: "GET", 
          url: "staff_subscriptionpacks_give.php", 
          data: urlstring,  
          success: function(transport){    
            progress_panel.hide();
            send_panel.show();
            alert(transport);
          },
          error: function(transport){
              alert('An Error has occurred.');
          }   
        });        
        

    }
    
    return false;
        
}
