/**
  * Generic Functions
  *
  * Place functions in this file that are resuable
  *
  *
  */

/////////////
// decode JSON array into 
// something js can use 
/////////////
function json_decode(jsonstr) 
{
  data = eval('('+jsonstr+')');

  return data;
}

/* var int debug count 
   counts the number of lines of debug that
   been outputted 
*/
var debug_count=0;


/* display debug to the 'debug' element */
function debug(text)
{
    if (!show_debug) return;
   	
	d=document.getElementById("debug");
	
    debug_count++;

    d.innerHTML = d.innerHTML + text + "<br/>";
}

/**
  * function get_prev_month
  * returns the prev month in reference
  * to MONTH.
  *
  * @param MONTH current month
  */
function get_prev_month(MONTH)
{
	MONTH--;
	if (MONTH==0) return (12); else return (MONTH);
}

/**
  * function get_next_month
  * returns the next month in reference
  * to MONTH.
  *
  * @param MONTH current month
  */
function get_next_month(MONTH)
{
	MONTH++;

	if (MONTH==13) return (1); else return (MONTH);
}

/**
  * function get_prev_year
  * returns the prev YEAR in reference
  * to MONTH & YEAR.
  *
  * @param YEAR current YEAR
  * @param MONTH current MONTH
  */
function get_prev_year(MONTH,YEAR)
{
    MONTH--;

    if (MONTH==0) return (parseInt(YEAR) -1); else return(YEAR);
}

/**
  * function get_next_year
  * returns the next YEAR in reference
  * to MONTH & YEAR.
  *
  * @param YEAR current YEAR
  * @param MONTH current MONTH
  */
function get_next_year(MONTH,YEAR)
{
 
    MONTH++;

    if (MONTH==13) return (parseInt(YEAR) +1 ); else return(YEAR);
}

/**
  * function cloneObject
  * generic clone object method
  */
function cloneObject(what) {

    for (i in what) {

        this[i] = what[i];

    }

}
