var panelNameFormat = "panel";
var imageToggleFormat = "openCloseImage";

/**  Accepts a panel, assuming panelNameFormat as id indicator of panel with incrementing index,
 *  if panel is closed will toggle open and vice versus.
 *   
 *  @params panel
 *  @return none
**/
function showHidePanel(panel) {
    
    var id = (panel.id.substring(panel.id.lastIndexOf("_")+1, panel.id.length));
    var panelStrId = panelNameFormat + "_" + id;
    var openCloseImageId = imageToggleFormat + "_" + id; 
    
    var obj = (document.all) ? document.all[panelStrId] : (document.getElementById) ? document.getElementById(panelStrId) : document.layers[panelStrId];
    var img = (document.all) ? document.all[openCloseImageId] : (document.getElementById) ? document.getElementById(openCloseImageId) : document.images[openCloseImageId];
    
    var leClass = (obj.style.display == "" || obj.style.display == "block") ? "none" : "block";
    var imgSrc = (leClass == "block") ? "images/panel_open.gif" : "images/panel_closed.gif";
    
    obj.style.display = leClass;

    if (img != null) {
        img.src = imgSrc;
    }
}

/** Checks obj.value for length in chars and returns true if 
 *  still allowed input, false otherwise 
 *  
 *  @param obj
 *  @param <code>String</code> max char limit 
 *  @return <code>boolean</code> true if char limit not exceeded, false otherwise 
**/
function textareaMaxLength(obj, maxLength) {

    var result = true;
    var disp = (obj.form && obj.form[obj.name + "_maxLenDisp"]) ? obj.form[obj.name + "_maxLenDisp"] : null; 
    
    if (obj != null) {  
        if (disp != null) {
            if (obj.value.length == 0) {
                disp.value = maxLength;
            } else if (obj.value.length > 0) {
                disp.value = (parseInt(maxLength)-obj.value.length);
            } else {
                disp.value = maxLength;
            }
        }
    
        if (obj.value.length >= maxLength) {
            result = false;
        }    
    }
    
    return result;
}