﻿
/****************************************************************************************
 * utility.js: 
 * common functions to support javascript functionality.
 *
 * This module includes the following functions:
 * 
 * StringBuffer(): string manipulation functions similiar to the string builder in c#.
 * PostbackFlag(): helps identify the expected postbacks as opposed to page refreshes.
 * id(): wrapper function for document.GetElementById - returns the element based on the id.
 *
 ****************************************************************************************/
 

/*  
 * - description -
 * array used to perform string manipulation behavior similar to
 * to the string builder in c#. string buffer accepts a string value
 * and stores the information inside the array and concatenates the
 * preserved values with the tostring method. 
 * - history -
 * 6/1/09 - created (pjl)
 */
function StringBuffer() { 
    this.buffer = []; 
} 

StringBuffer.prototype.append = function append(string) { 
    this.buffer.push(string); 
    return this; 
}; 

StringBuffer.prototype.toString = function toString() { 
    return this.buffer.join(""); 
};



/*  
 * - description -
 * For non-ajax element id lookups - finds the element by the id, 
 * or returns the element as an object.
 * - parameters -
 * x: (string or object) element id or an actual element.
 * - history -
 * 6/1/09 - created (pjl)
 */      
function FindId(x) {
    // lookup the element id if x is a string.
    if (typeof x == "string") return document.getElementById(x);
    // otherwise, assume x is an element.
    return x;

}


/*  
 * - description -
 * increments the postback hidden field to identify true postbacks
 * as opposed to a page refresh or the naviation buttons. 
 * - history -
 * 6/1/09 - created (pjl)
 */      
function PostbackFlag() { 
            
    // Increment the postback Id.
    document.getElementById("ctl00_PostbackFlag").value++;         
}  