﻿// Interface AJAX functions
function getTransactionHTML(xml_program, userid, customer_number, program_code, fund_code, container_id) 
{
	// Initiate AJAX call to the transaction REST service
	var url = '/admin/transaction_list.aspx';
    $('#'+container_id).html('<img src=\'/images/spinner.gif\'> Loading...');
    
    $.ajax({
      type: 'get',
      url: url,
      data: 'xml_program=' + xml_program + '&userid=' + userid + '&customer_number=' + customer_number + '&program_code=' + program_code + '&fund_code=' + fund_code,
      success: function(message) {
		$('#'+container_id).html(message);
		
      }
    });
}

var magicButton = {
	
	  initialize: function(button_id) {
	    this.button = $(button_id);
		
		// We should pre-load the various state images here
		this.normalState = this.button.readAttribute("src");
		
		// Parse the filename
		var pos1 = this.normalState.lastIndexOf('/') + 1;
		var pos2 = this.normalState.lastIndexOf('.');
		
		var imgNameRoot = this.normalState.substring(pos1, pos2);
		var urlRoot = this.normalState.substring(0, pos1);
		var ext = this.normalState.substring(pos2, this.normalState.length);
		
		// State images are defined here
		this.hoverState = urlRoot + imgNameRoot + '_over' + ext;
		this.clickedState = urlRoot + imgNameRoot + '_down' + ext;
		
	    this.button.onmouseup = this.swapToNormalState.bindAsEventListener(this);
		this.button.onmousedown = this.swapToClickedState.bindAsEventListener(this);
		this.button.onmouseover = this.swapToHoverState.bindAsEventListener(this);
		this.button.onmouseout = this.swapToNormalState.bindAsEventListener(this);
	  },
	  
	  	swapToClickedState: function(evt) {
			this.button.setAttribute("src", this.clickedState);
		},
		
		swapToNormalState: function(evt) {
			this.button.setAttribute("src", this.normalState);
		},
		
		swapToHoverState: function(evt) {
			this.button.setAttribute("src", this.hoverState);
		}
	};
		 	
function makeMagicButtons() {
   if(!document.getElementsByTagName) return false;
   var buttons = $('.magic-button');
   
   for (var i=0; i < buttons.length; i++) {
		new magicButton(buttons[i]);
   }
}

function highlightTableRows() 
{
    if (!document.getElementsByTagName) return false;
       
    var rows = $('.report tbody tr');

    for (var i = 0; i < rows.length; i++) 
    {
        try
        {
           if (rows[i].getAttribute("class").indexOf('noHover') > 0) 
           {
               return;
           }
        }
        catch(Error)
        {
        }
        rows[i].onmouseover = function() { $(this).addClass('highlight');}
        rows[i].onmouseout = function() { $(this).removeClass('highlight');}
    }
}