/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    changePendingStyleRow()
  Date:              20060710
  Purpose:           Change the style of a table row in the pending items table
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   lngID             input       integer ID of the table cell we're updating
	 strNewStyle       input       string	 style we're changing the cell to
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function changePendingStyleRow(lngID, strNewStyle)
{
  document.getElementById('pendCBox_' + lngID).className = strNewStyle + '_cb';
  document.getElementById('pendPayee_' + lngID).className = strNewStyle;
  document.getElementById('pendAmount_' + lngID).className = strNewStyle + '_right';
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      changePendingStyleRow()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    changeRecipeStyleRow()
  Date:              20060710
  Purpose:           Change the style of a table row in the recipe search results table
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   lngID             input       integer ID of the table cell we're updating
	 strNewStyle       input       string	 style we're changing the cell to
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function changeRecipeStyleRow(lngID, strNewStyle)
{
  document.getElementById('name_' + lngID).className = strNewStyle;
  document.getElementById('date_' + lngID).className = strNewStyle;
  document.getElementById('author_' + lngID).className = strNewStyle;
  document.getElementById('type_' + lngID).className = strNewStyle;
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      changeRecipeStyleRow()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    changeScheduleStyleRow()
  Date:              20041029
  Purpose:           Change the style of a table row in the checkbook transaction
										 registry
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   lID                input     integer  ID of the table cell we're updating
	 sNewStyle          input     string	 style we're changing the cell to
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function changeScheduleStyleRow(lID, sNewStyle)
{
  document.getElementById('payee_' + lID).className = sNewStyle;
	document.getElementById('account_' + lID).className = sNewStyle;
	document.getElementById('type_' + lID).className = sNewStyle;
	document.getElementById('amount_' + lID).className = sNewStyle + '_right';
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      changeScheduleStyleRow()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    changeStockStyleRow()
  Date:              20050421
  Purpose:           Change the style of a stock transaction row in the checkbook transaction
										 registry
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   lID                input     integer  ID of the table cell we're updating
	 sNewStyle          input     string	 style we're changing the cell to
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function changeStockStyleRow(lID, sNewStyle)
{
  document.getElementById('date_' + lID).className = sNewStyle;
	document.getElementById('ticker_' + lID).className = sNewStyle;
	document.getElementById('shares_' + lID).className = sNewStyle + '_right';
	document.getElementById('price_' + lID).className = sNewStyle + '_right';
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      changeStockStyleRow()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    changeStyleRow()
  Date:              20041029
  Purpose:           Change the style of a table row in the checkbook transaction
										 registry
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   lID                input     integer  ID of the table cell we're updating
	 sNewStyle          input     string	 style we're changing the cell to
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function changeStyleRow(lID, sNewStyle)
{
  document.getElementById('date_' + lID).className = sNewStyle;
	document.getElementById('payee_' + lID).className = sNewStyle;
	document.getElementById('category_' + lID).className = sNewStyle;
	document.getElementById('amount_' + lID).className = sNewStyle + '_dark_right';
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      changeStyleRow()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    clock()
  Date:              20040810
  Purpose:           Create a digital clock for use on a webpage
  Author:            Phil Hamlin
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   none
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function clock()
{
			var date = new Date();
			var year = date.getFullYear();
			var month = date.getMonth();
			var day = date.getDate();
			var hour = date.getHours();
			var minute = date.getMinutes();
			var second = date.getSeconds();
			var months = new Array("", "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");

			var monthname = months[month+1];

			if (hour > 12) {
			hour = hour - 12;
			}
			if (minute < 10) {
			minute = "0" + minute;
			}

			if (second < 10) {
			second = "0" + second;
			}
		
			document.getElementById('time').innerHTML = monthname + " " + day + ", " + year + "   " + hour + ":" + minute + ":" + second;
			setTimeout("clock()", 1000);
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      clock()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    columnSort()
  Date:              20040810
  Purpose:           Submit column name and sort direction for the checkbook
  Author:            Phil Hamlin
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   sSortColumn       input      string   name of column to be sorted
	 sSortDirection		 input			strnig	 sort direction, ASC, DESC
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function columnSort(sSortColumn, sSortDirection)
{
  document.getElementById('SortColumn').value = sSortColumn;
  document.getElementById('SortDirection').value = sSortDirection;
  document.forms.Checkbook.submit();
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      columnSort()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    editTransaction()
  Date:              20050203
  Purpose:           Set the hidden input values required to post the form and
										 edit a transaction that the user clicked on.
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   lTransactionID     input     integer  ID of the transaction we're editing
	 lPageNumber				input			integer	 page of the recordset that we're viewing
	 lAccountID					input			integer	 ID of the account we are editing
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function editTransaction(lTransactionID, lPageNumber, lAccountID)
{
  document.getElementById('EditTransaction').value = lTransactionID;
	document.getElementById('PageNumber').value = lPageNumber;
	document.getElementById('AccountID').value = lAccountID;
	document.forms.Checkbook.submit();
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      editTransaction()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    getQS()
  Date:              20041129
  Purpose:           Get the values of the elements in the form, and build them
										 into a querystring to send to an ASP page via AJAX
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   lID                input     integer  ID of the table cell we're updating
	 sNewStyle          input     string	 style we're changing the cell to
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function getQS(sFormName){
  var QS = "";
  var currentValue = "";
  var currentType = "";
  var currentName = "";
  if (sFormName.length>0){
    for (var i=0; i<document.forms[sFormName].elements.length;i++){
      currentValue = document.forms[sFormName].elements[i].value;
      currentType = document.forms[sFormName].elements[i].type;
      currentName = document.forms[sFormName].elements[i].name;
      if (currentType!="button" & currentType!="submit"){
        if (currentType=="select-multiple"){
          for (var o=0; o<document.forms[sFormName].elements[i].options.length;o++){
            if (document.forms[sFormName].elements[i].options[o].selected==true){
              QS+="&" + currentName + "=" + escape(document.forms[sFormName].elements[i].options[o].value); 
            }
          }
        }
        else if (currentType=="checkbox"){
          if (document.forms[sFormName].elements[i].checked == true){
            QS+="&" + currentName + "=" + escape(currentValue); 
          }
        }
        else{
          QS+="&" + currentName + "=" + escape(currentValue); 
        }
      }
    }
  }
  QS = Right(QS, QS.length - 1);
  
  return QS;
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      getQS()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    IsArray()
  Date:              20060712
  Purpose:           Check whether the value passed in is an array
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   arr1              input       array   array we are checking
   blnRetVal         output      boolean whether or not the string is an array
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function IsArray(arr1)
{
  var blnRetVal = false;
  
  if (arr1.constructor.toString().indexOf("Array") == -1)
  {
    blnRetVal = true;
  }
  
  return blnRetVal;
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      IsArray()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    IsDate()
  Date:              20060823
  Purpose:           Check whether the value passed in is a date
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   dateStr           input       string  string we are checking
   blnRetVal         output      boolean whether or not the string is a date
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function IsDate(dateStr)
{
  var datePat = /^(\d{1,2})(\/|-)(\d{1,2})(\/|-)(\d{4})$/;
  var matchArray = dateStr.match(datePat); // is the format ok?

  if (matchArray == null)
  {
    alert("Please enter date as either mm/dd/yyyy or mm-dd-yyyy.");
    return false;
  }

  month = matchArray[1]; // p@rse date into variables
  day = matchArray[3];
  year = matchArray[5];

  if (month < 1 || month > 12)
  { // check month range
    alert("Month must be between 1 and 12.");
    return false;
  }

  if (day < 1 || day > 31)
  {
    alert("Day must be between 1 and 31.");
    return false;
  }

  if ((month==4 || month==6 || month==9 || month==11) && day==31)
  {
    alert("Month "+month+" doesn`t have 31 days!")
    return false;
  }

  if (month == 2)
  { // check for february 29th
    var isleap = (year % 4 == 0 && (year % 100 != 0 || year % 400 == 0));
  
    if (day > 29 || (day==29 && !isleap))
    {
      alert("February " + year + " doesn`t have " + day + " days!");
      return false;
    }
  }
  
  return true; // date is valid
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      IsDate()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    IsNumeric()
  Date:              20060710
  Purpose:           Check whether the value passed in is a number
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   strString         input       string  string we are checking
   blnRetVal         output      boolean whether or not the string is a number
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function IsNumeric(strString)	
{
  var strValidChars = "0123456789.-";
  var strChar;
  var blnRetVal = true;

  if (strString.length == 0) return false;

  for (i = 0; i < strString.length && blnRetVal == true; i++)
  {
    strChar = strString.charAt(i);
    if (strValidChars.indexOf(strChar) == -1)
    {
      blnRetVal = false;
    }
  }
  return blnRetVal;
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      IsNumeric()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    IsTime()
  Date:              20060831
  Purpose:           Check whether the value passed in is a time
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   timeStr           input       string  string we are checking
   blnRetVal         output      boolean whether or not the string is a time
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function IsTime(timeStr)
{
  if(timeStr.length!=8)
  {
    alert('Please enter date in hh:mm:ss format');
    return false;
  }

  colon1 = timeStr.charAt(2);
  colon2 = timeStr.charAt(5);
  
  if(colon1 != ':' && colon2 != ':')
  {
    alert('Please enter date in hh:mm:ss format!');
    return false;
  }

  hours = timeStr.charAt(0) + timeStr.charAt(1);
  minutes = timeStr.charAt(3) + timeStr.charAt(4);
  seconds = timeStr.charAt(6) + timeStr.charAt(7);

  var msg = '';

  if(hours >= 0 && hours <= 23)
  {
  }
  else
  {
    msg = msg + 'Please enter valid hours\n';
  }

  if(minutes <= 59 && minutes >= 0)
  {
  }
  else
  {
    msg = msg + 'Please enter valid minutes\n';
  }

  if(seconds <= 59 && seconds >= 0)
  {
  }
  else
  {
    msg = msg + 'Please enter valid seconds\n';
  }

  if (msg != '')
  {
    alert(msg);
    return false;
  }
  else
  {
    return true;
  }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      IsTime()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    Left()
  Date:              20060307
  Purpose:           Return the left N characters of a string
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
	 str			         input	     string	 string to parse
	 n                 input       integer number of characters in return string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function Left(str, n)
{
	if (n <= 0)
	    return "";
	else if (n > String(str).length)
	    return str;
	else
	    return String(str).substring(0,n);
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      Left()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    PromptToClearPendingItems()
  Date:              20051203
  Purpose:           Check to see whether any pending items are checked to be
                     cleared, and if so, ask the user whether they want to do so.
		                 Then, set the hidden input value accordingly, so the app knows
		                 whether to clear the transactions next round trip to the server
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   none
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function PromptToClearPendingItems()
{
  var objCheckBox = document.getElementById('ClearPendingItems');
  
  if (objCheckBox.value > 0)
	{
		if (!(confirm('Do you want to clear the pending items you have checked?')))
		{
		  objCheckBox.value = 0;
		  return false;
		}
		else
		{
		  return true;
		}
	}
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      PromptToClearPendingItems()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    refreshAccountPage()
  Date:              20060626
  Purpose:           Refresh the Ajax sections of the account display page
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   lngTransactionID  input       long    transaction ID
   lngAccountID      input       long    account ID
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function refreshAccountPage(lngAccountID)
{
  document.getElementById('DeleteTransaction').value = '';
  document.getElementById('UpdateTransaction').value = '';
  document.getElementById('EditTransaction').value = 0;
  document.getElementById('btn_Delete').className = 'btn_delete_disabled';
  document.getElementById('btn_Delete').disabled = true;
  
  makeOverBudgetCategoryRequest();
  makePendingTransactionRequest(lngAccountID);
  makeTransactionRegistryRequest(lngAccountID);
  makeCurrentAccountBalanceRequest(lngAccountID);
  makeBalanceFormRequest(lngAccountID);
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      refreshAccountPage()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    refreshStockPage()
  Date:              20060821
  Purpose:           Refresh the Ajax sections of the stock display page
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   none
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function refreshStockPage()
{
  document.getElementById('DeleteTransaction').value = '';
  document.getElementById('UpdateTransaction').value = '';
  document.getElementById('EditTransaction').value = 0;
  document.getElementById('btn_Delete').className = 'btn_delete_disabled';
  document.getElementById('btn_Delete').disabled = true;
  
  makeStockMarketSummaryRequest();
  makeStockRegistryRequest();
  makeStockTransactionFormRequest();
  makeStockBalanceRequest();
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      refreshStockPage()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/


/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    replaceString()
  Date:              20060307
  Purpose:           Return the right N characters of a string
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   str			         input	     string	 string to parse
	 n                 input       integer number of characters in return string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function replaceString(sString, sReplaceThis, sWithThis)
{ 
  if (sReplaceThis != "" && sReplaceThis != sWithThis)
  {
    var counter = 0;
    var start = 0;
    var before = "";
    var after = "";
    while (counter<sString.length)
    {
      start = sString.indexOf(sReplaceThis, counter);
      if (start == -1)
      {
       break;
      }
      else
      {
        before = sString.substr(0, start);
        after = sString.substr(start + sReplaceThis.length, sString.length);
        sString = before + sWithThis + after;
        counter = before.length + sWithThis.length;
      }
    }
  }
  
  return sString;
}
/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      replaceString()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    Right()
  Date:              20060307
  Purpose:           Return the right N characters of a string
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   str			         input	     string	 string to parse
	 n                 input       integer number of characters in return string
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function Right(str, n)
{
  if (n <= 0)
     return "";
  else if (n > String(str).length)
     return str;
  else {
     var iLen = String(str).length;
     return String(str).substring(iLen, iLen - n);
  }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      Right()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'  Procedure Name:    RYouSure()
'  Date:              20040927
'  Purpose:           Confirms the user wants to do what they clicked on, then
'	 										redirects to the appropriate place
'  Author:            Jeff Bottger
'  Version:           1.0
'
'  Arguments:
'   name              in / out   type     description
'  ---------------------------------------------------------------------------
'    mess             input      string   the message to display on the confirm
'		 url							input			 string		URL to redirect to upon confirmation
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function RYouSure(mess, url){
  if(confirm(mess)){
	  window.location.replace(url);
	}else{
	}
}

/*'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' End Procedure:      RYouSure()
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    toggleBudgetTable()
  Date:              20050222
  Purpose:           Check to see whether an element is blocked or hidden, then switch
										 the status to the other one
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   tableID           input      integer  ID of the budget table we're blocking	 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function toggleBudgetTable(tableID) 
{
	if (document.getElementById('budget_' + tableID).style.display == 'block') 
  { 
		document.getElementById('budget_' + tableID).style.display = 'none';
  } 
  else 
  { 
		document.getElementById('budget_' + tableID).style.display = 'block';    
  }	 
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      toggleBudgetTable()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    toggleBlocked()
  Date:              20040810
  Purpose:           Check to see whether an element is blocked or hidden, then switch
										 the status to the other one
  Author:            Phil Hamlin
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   elementID         input      integer  ID of the element we're blocking, 0 or 1 depending
	 									 										 on whether the item is blocked or not
	 TDID							 input			integer	 ID of the TD in the table we're blocking
	 styleName				 input			string	 name of the style we're changing to
	 blockID					 input			integer	 ID that differentiates between table cells	 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function toggleBlocked(elementID, TDID, styleName, blockID) 
{
  if (document.getElementById(elementID).value == 1) 
  { 
  	document.getElementById(elementID).value = 0; 
    document.getElementById(TDID).className = styleName;
		document.getElementById('ssm_' + blockID).style.display = 'none';
  } 
  else 
  { 
		document.getElementById(elementID).value = 1; 
    document.getElementById(TDID).className = styleName;
		document.getElementById('ssm_' + blockID).style.display = 'block';    
  }	 
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      toggleBlocked()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/



/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  Procedure Name:    TogglePendingItemsInput()
  Date:              20051203
  Purpose:           Set the value of the hidden input ClearPendingItems, based
                     on whether the user has checked any checkboxes for pending items
  Author:            Jeff Bottger
  Version:           1.0

  Arguments:
   name              in / out    type    description
  ---------------------------------------------------------------------------
   strCurrent        intput      string  ID of the checkbox that we toggled
   lngTransactionID  input       long    ID of the transaction we are working with
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/

function TogglePendingItemsInput(strCurrent, lngTransactionID)
{
  var arrData = '';
  var strData = '';
  var strValue = '';
  var lngValue = 0;
  
  if (document.getElementById(strCurrent).checked == true)
  {
    lngValue = document.getElementById('ClearPendingItems').value;
    
    if (lngValue.length > 0)
    {
      lngValue = parseInt(lngValue);
      lngValue += 1;
    }
    
    document.getElementById('ClearPendingItems').value = lngValue;
    
    strValue = document.getElementById('ClearTransactions').value;
    strValue += ',';
    strValue += lngTransactionID;
    
    if (Left(strValue, 1) == ',')
    {
      strValue = Right(strValue, strValue.length - 1);    
    }
    
    document.getElementById('ClearTransactions').value = strValue;
  }
  else
  {
    lngValue = document.getElementById('ClearPendingItems').value;
    
    if (lngValue.length > 0)
    {
      lngValue = parseInt(lngValue);
      lngValue -= 1;
    }
    
    document.getElementById('ClearPendingItems').value = lngValue;
    
    strValue = document.getElementById('ClearTransactions').value;
    arrData = strValue.split(',');
    
    for (var i = 0; i < arrData.length; i++)
    {
      if (parseInt(arrData[i]) != lngTransactionID)
      {
        strData += ',';
        strData += arrData[i];
      }
    }
    
    strValue = Right(strData, (strData.length - 1));
    
    document.getElementById('ClearTransactions').value = strValue;
  }
}

/*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 End Procedure:      TogglePendingItemsInput()
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/