/* al_jsfunctions.js */

var CurMouseX;
var CurMouseY;
var CurPopupWindow = null;
var helpWindow = null;
var SearchValue;

var App_windows = new Array();

var array_Elements = null;    // array of obj_Element objects that stores
                            // the original values of all airlink "alobj"
                            // elements on the page

var Select_Options_array = new Array();    // array of choicelists for the entire page
                                        // containing all the values for dependent
                                        // choicelists

var new_tab_num = 0;

function aljs_is_toplevel(w)
{
    //alert("loadFrame url=" + url);

    return (w.parent == w);
}

function aljs_loadFrame(frame_index, url)
{
    //alert("loadFrame url=" + url);
    //top.search_results.location=url;
    top.frames[frame_index].location=url;
}

function aljs_loadFrameWithGlobalSearchValue(frame_index, baseURL)
{
    use_url = baseURL + "&fieldvalue=" + aljs_urlencode(SearchValue);
    aljs_loadFrame(frame_index, use_url);
}

function aljs_setGlobalSearchValue(form, field, keyfield) 
{
    //alert("form=[" + form + "]" + "   field=[" + field + "]" + "--going to get current value");
    var found_field = false;

    index = 0;

    tmp_form = "document." + form + ".elements.length";

    //alert("length=" + eval(tmp_form));
                                                //
                                                // because we have pipe symbols in some of the
                                                // form's field name (i.e. ZZOBJ|crm|2534|comp_name)
                                                // there is a problem with accessing the value of
                                                // that form field.  
                                                // 
                                                // To solve that problem, we use the INDEX of that 
                                                // field name as found in the form's elements
                                                // We get that index value in the next for loop
                                                //

    for(ii=0;ii<eval(tmp_form);ii++)
    {
        tmp_element = "document." + form + ".elements[" + ii + "].name";

        if(eval(tmp_element) == field)
        {
            index = ii;
            found_field = true;
            //alert("found field=" + field + "  index=" + index);
            break;
        }
    }

    //alert("setting SearchValue test");
    if(found_field == true)
    {
        tmp_value = "document." + form + ".elements[" + index + "].value";
        SearchValue = eval(tmp_value);
    }
    else
    {
        SearchValue = "Enter search value here";
    }

    if(SearchValue == "")
    {
        SearchValue = "Enter search value here";
    }

    //alert("SearchValue=[" + SearchValue + "]");
}

function aljs_getFieldFormIndex(form, field)
{
    //alert("aljs_getFieldFormIndex----form=[" + form + "]" + "   field=[" + field + "]" + "--going to get current value");

    index = 0;

    tmp_form = "document." + form + ".elements.length";

    //alert("length=" + eval(tmp_form));
                                                //
                                                // because we have pipe symbols in some of the
                                                // form's field name (i.e. ZZOBJ|crm|2534|comp_name)
                                                // there is a problem with accessing the value of
                                                // that form field.  
                                                // 
                                                // To solve that problem, we use the INDEX of that 
                                                // field name as found in the form's elements
                                                // We get that index value in the next for loop
                                                //

    index = -1;

    for(ii=0;ii<eval(tmp_form);ii++)
    {
        tmp_element = "document." + form + ".elements[" + ii + "].name";

        if(eval(tmp_element) == field)
        {
            index = ii;
            //alert("found field=" + field + "  index=" + index);
            break;
        }
    }

    //alert("setting index=" + ii);
    //tmp_value = "document." + form + ".elements[" + index + "].value";
    //SearchValue = eval(tmp_value);
    //alert("SearchValue=[" + SearchValue + "]");

    return(index);
}

function aljs_openSearch(baseURL,modified,searchParam, popupName) 
{
    //if (modified == '1') baseURL = baseURL + searchParam;

    use_url = baseURL + "&fieldvalue=" + SearchValue;

    use_popup_name = "lookup";
     
    if( popupName != "")
    {   
        use_popup_name = popupName
    }

    //alert("use_url=" + use_url);

    aljs_openPopup(use_url, use_popup_name, 800, 450, "width=800,height=450,toolbar=no,status=no,  directories=no,menubar=no,resizable=yes,scrollable=no", true);
}

function aljs_openCalendar(ref, cal_width, cal_height) 
{
    opts = "width=" + cal_width + ",height=" + cal_height + ",dependent=yes,resizable=yes,toolbar=no,status=no,directories=no,menubar=no";

    //aljs_openPopup(ref, "Calendar", cal_width, cal_height, "width=193,height=145, dependent=yes,  resizable=yes,toolbar=no, status=no,directories=no,menubar=no", true);

    aljs_openPopup(ref, "Calendar", cal_width, cal_height, opts, true);
}

function aljs_populateForm(formname, fieldname, value)
{
    top.window.opener.populate(formname, fieldname, value);
}

function aljs_populateFormWithKeyfield(formname, fieldname, value, keyfieldname, keyvalue)
{
    //alert("function-zz4 aljs_populateFormWithKeyfiled -- formname=" + formname + "  fieldname=" + fieldname + "  value=" + value + "  keyfieldname=" + keyfieldname + "  keyvalue=" + keyvalue);

    top.window.opener.populate(formname, keyfieldname, keyvalue);
    top.window.opener.populate(formname, fieldname, value);
}


function aljs_populateFormWithArray(formname, fieldname_string, value_string)
{

    fieldname_array = fieldname_string.split(",");
    value_array     = value_string.split(",");
    field_count = value_array.length;
    //alert("field_count=" + field_count);

    for(jj=0;jj<field_count;jj++)
    {
        fieldname = fieldname_array[jj];
        value     = value_array[jj];

        //alert('fieldname='+fieldname + ' value=' + value);

                 // if this is NOT a popup page, then verify it is or is not a popin

        if(parent != self)
        {   
            //alert("in a popin");

                   // If it is a popin, then use a dom-tree path relative to the current form. Else treat it as a popup

            if( window.frameElement.id.substring(0, 12) == "popin_iframe")
            {
                parent.populate(formname, fieldname, value);
            }
            else
            {
                top.window.opener.populate(formname, fieldname, value);
            }
        }   
        else
        {
            top.window.opener.populate(formname, fieldname, value);
        }
    }

}


function populate(formname,fieldname,value) 
{
    var tmp_object;

    //alert("function populate   -- formname=[" + formname + "]  fieldname=[" + fieldname + "]  value=[" + value  + "]");
    //alert("window.name = [" + window.name + "]");
    
    tmp_object = al_get_object(fieldname);
    
    //alert("tmp_object = [" + tmp_object + "]");
    //alert("tmp_object.type=[" + tmp_object.type);

    if(tmp_object.type == 'select-one')
    {
        //alert("here0");

        var a_length = tmp_object.options.length;

        //alert(" Count of options = " + a_length);

        var select_new_index = 0;

        for(var ii = 0; ii < a_length; ii++)
        {
            //alert("here1");
            if(tmp_object.options[ii].text == value || tmp_object.options[ii].value == value)
            {
                //alert("here2");
                select_new_index = ii;
                break;
            }

        }
        //alert("here3");
        tmp_object.selectedIndex = select_new_index;
        //alert(" Set the selected index to " + select_new_index);
    }
    else
    {
        //alert("hereZ");
        tmp_object.value = value;
    }    

    // execute the onchange method of the field we are populating so that
    // if that field has an onchange event, that event is triggered.  The event
    // is NOT triggered when this is not called explicitly from here.

    //alert("Fieldname = ["+ fieldname +"] \nal_get_object(fieldname) = ["+ al_get_object(fieldname) +"]");
    
    if(tmp_object.type != 'hidden')
    {
        //eval("document."+formname+"[\""+fieldname+"\"].onchange()");
        if(al_get_object(fieldname).onchange != null)
        {
            al_get_object(fieldname).onchange()
        }
    }    
    aljs_closePopup();
    return false;
}

function aljs_setMousePos(event) 
{
    if (navigator.appName.indexOf("Microsoft") != -1) e = window.event;
    //CurMouseX = event.screenX;
    //CurMouseY = event.screenY;
    
    if(!event)            // in the case of an href=mouseclick instead of an onclick, the event does not go
        return;
                        // so we'll just not set it for now, and make that the callers responsibility to
                        // get the mouse event from the onclick


    CurMouseX = event.screenX;
    CurMouseY = event.screenY;
}

function aljs_openPopup(ref, name, winWidth, winHeight, features, placeAtMousePose) 
{
    

    if(name != "_blank")
    {
        aljs_closePopup();
    }

    if (placeAtMousePose) 
    {
        if (CurMouseX - winWidth < 0) 
        {
            CurMouseX = winWidth;
        }
        if (CurMouseY + winHeight > screen.height) 
        {
            CurMouseY -= (CurMouseY + winHeight + 50) - screen.height;
        }
                CurMouseX -= winWidth;
                CurMouseY += 10;
        features +=    ",screenX=" + CurMouseX + ",left=" + CurMouseX + ",screenY=" + CurMouseY + ",top=" + CurMouseY;
    }

    //alert("CurMouseX=" + CurMouseX + ",CurMouseY=" + CurMouseY + ", winWidth=" + winWidth + ", winHeight=" + winHeight + ",placeAtMousePose=" + placeAtMousePose);

    //alert("name = [" + name + "]");

    CurPopupWindow = window.open(ref, name, features, false);        // open a new window

}

function aljs_openWindow(ref, name, winWidth, winHeight, features, placeAtMousePose, focusFlag) 
{

    if(!focusFlag)
    {
        focusFlag = 'TRUE';            // true means we just do focus, false means we reload always
    }
    
    //alert("CurMouseX=" + CurMouseX + ",CurMouseY=" + CurMouseY + ",winWidth=" + winWidth + ",winHeight=" + winHeight + ",placeAtMousePose=" + placeAtMousePose);

    switch (placeAtMousePose)
    {
        case true:
        case "UR":
        case "ur":

            if (CurMouseX - winWidth < 0) 
                CurMouseX = 0;
            else
                CurMouseX = CurMouseX - winWidth - 30;

            if (CurMouseY + winHeight > screen.height) 
                CurMouseY = CurMouseY;
                //CurMouseY -= (CurMouseY + winHeight + 50) - screen.height;
            else
                CurMouseY = CurMouseY + 10;

            break;

        case "LR":
        case "lr":

            if (CurMouseX - winWidth < 0) 
                CurMouseX = 0;
            else
                CurMouseX = CurMouseX - winWidth - 30;

            if (CurMouseY - winHeight < 0)
                CurMouseY = 0;
            else
                CurMouseY = CurMouseY - winHeight - 40;

            break;

        case "LL":
        case "ll":

            if (CurMouseX + winWidth > screen.width) 
                CurMouseX = CurMouseX;
                //CurMouseX = screen.width - winWidth;
            else
                CurMouseX = CurMouseX + 30;

            if (CurMouseY - winHeight < 0)
                CurMouseY = 0;
            else
                CurMouseY = CurMouseY - winHeight - 40;

            break;

        case "UL":
        case "ul":

            if (CurMouseX + winWidth > screen.width) 
                CurMouseX = CurMouseX;
                //CurMouseX = screen.width - winWidth;
            else
                CurMouseX = CurMouseX + 30;

            if (CurMouseY + winHeight > screen.height) 
                CurMouseY = CurMouseY;
                //CurMouseY -= (CurMouseY + winHeight + 50) - screen.height;
            else
                CurMouseY = CurMouseY + 10;
            break;
    }

    features +=    ",screenX=" + CurMouseX + ",left=" + CurMouseX + ",screenY=" + CurMouseY + ",top=" + CurMouseY;
    //alert("features=" + features);

    //alert("calling aljs_get_app_window");

    //alert("CurMouseX=" + CurMouseX + ",CurMouseY=" + CurMouseY + ",winWidth=" + winWidth + ",winHeight=" + winHeight + ",placeAtMousePose=" + placeAtMousePose);

    tmp_curwindow = aljs_get_app_window(name);                    // get appwindow object if window is already open
    //alert("back from aljs_get_app_window");

    if(focusFlag == 'TRUE')            // if we are to try to focus first
    {
                                                                    // if the window DOES exist
        if(tmp_curwindow.window_object && tmp_curwindow.window_object.open && !tmp_curwindow.window_object.closed)
        {
            //alert("Save/Cancel Open Activity First");
            //alert("Window exists-going to move");
            tmp_curwindow.window_object.moveTo(CurMouseX,CurMouseY);
            tmp_curwindow.window_object.focus();
        }
        else                                                // otherwise
        {
            //alert("want to open");
            tmp_curwindow.window_object = window.open(ref, tmp_curwindow.name, features, false);        // open a new window
        }
    }
    else                            // always reload the window
    {
            aljs_closePopup();
            //alert("want to open");
            tmp_curwindow.window_object = window.open(ref, tmp_curwindow.name, features, false);        // open a new window
            tmp_curwindow.window_object.moveTo(CurMouseX,CurMouseY);
            tmp_curwindow.window_object.focus();
    }

}


function aljs_openIframe(href, name, winWidth, winHeight) 
{
    var target_iframe;

    alert("aljs_openIframe href = [" + href + "]\n"
            + "name = [" + name + "]\n"
            + "winWidth = [" + winWidth + "]\n"
            + "winHeight = [" + winHeight + "]");



    target_iframe = al_get_object(name);

//    alert("target_iframe = [" + target_iframe + "]");

    target_iframe.height = winHeight;
    target_iframe.width = winWidth;

    target_iframe.src = href;

}

///////////////////////////////////////////////////////////////////////////////////////////
//
//   Functions to Debug the page - so we don't keep adding and commenting out alerts
//
///////////////////////////////////////////////////////////////////////////////////////////

function aljs_debug_alert(parm_msg)
{
    ///// comment out to turn off the debugs
    //alert(parm_msg);
    ////////////////////////////////////////
}


/////////////////////////////////////////////////////////////////////////////
//
//   END debugging functions
//
///////////////////////////////////////////////////////////////////////////



////////////////////////////////////////////////////////////////////////////
//
//   Functions to RESIZE the iframe based on settings in the form tool
//   Default is dynamic resizing 
//
////////////////////////////////////////////////////////////////////////////



//
// resize a formtool to a specific height by applying styles to the
// html elements generated by formtool.
//

function aljs_resize_formtool_height(parm_height, parm_ft_body_div)
{
    aljs_debug_alert("in aljs_resize_formtool_height");

    current_height = document.body.clientHeight;
    page_body_obj = al_get_object(parm_ft_body_div);

    if(page_body_obj == null)       // if there is no object found, then return
    {
        return;
    }

    aljs_debug_alert("current_height=" + current_height + ", parm_height=" + parm_height + "");
    aljs_debug_alert("page_body_height=" + page_body_obj.clientHeight + "");

    if(current_height > parm_height)
    {
        page_body_obj.style.height = page_body_obj.clientHeight - (current_height - parm_height);
    }

    aljs_debug_alert("out aljs_resize_formtool_height");
}


// this function looks for javascript variables on the page telling us how to
// resize the iframe and what iframe needs to be resized.  


function aljs_change_iframe_size()
{
    aljs_debug_alert("in aljs_change_iframe_size");

    var iframe_id;
    var iframe_width_type; 
    var iframe_height_type;
    var tab_to_change;


	//alert("no resizing - disabled");
	//return;

                            // if this is the top level frame, end
    if(parent == self)
    {
        return;
    }

                           // if the iframe info object is not defined, then we cannot resize-jhj070801
     if(iframe_info_obj == null)
     {
         return;
     }

                                // if we got an iframe_info_obj, resize this iframe
                                // according to width and height parameters given
                                // in that object (as defined in the HTML source of this page)

                                // in the case of tabs, we resize the iframe of the tab
                                // we are loading code in.

    if(iframe_info_obj.tab_to_change != null && parent == top)
    {
        aljs_debug_alert("got a tab_to_change = [" + iframe_info_obj.tab_to_change + "]\n");

        tab_to_change = iframe_info_obj.tab_to_change;

        aljs_change_tab_iframe_size(tab_to_change); 

    }
                                // otherwise if we have an iframe_id specified, then that
                                // iframe is the one we resize
    else if(iframe_info_obj.iframe_id != null)
    {
        aljs_debug_alert("got an iframe_id = [" + iframe_info_obj.iframe_id + "]\n");

        iframe_id = iframe_info_obj.iframe_id;

        iframe_height_type = iframe_info_obj.iframe_height_type;
        iframe_height = iframe_info_obj.iframe_height;
        iframe_min_height = iframe_info_obj.iframe_min_height;
        iframe_max_height = iframe_info_obj.iframe_max_height;

        iframe_width_type = iframe_info_obj.iframe_width_type;
        iframe_width = iframe_info_obj.iframe_width;
        iframe_min_width = iframe_info_obj.iframe_min_width;
        iframe_max_width = iframe_info_obj.iframe_max_width;

                                                    
        aljs_debug_alert("iframe_width_type = [" + iframe_width_type + "]");

        aljs_debug_alert("iframe_height_type = [" + iframe_height_type + "]");

                                        // resize the height based on what info
                                        // we got


                                         // on an exact resize, 
                                         // use an exact height to size the iframe
        if(iframe_height_type == "iframe_resize_height_exact")
        {
            if(iframe_height == null)
            {
                alert("iframe height was null");
            }

            aljs_debug_alert("got iframe_resize_height_exact");
            aljs_resize_iframe_height_exact(iframe_id, iframe_height);

        }
                                         // on an min resize, 
                                         // calculate the height based on the min height
        else if(iframe_height_type == "iframe_resize_height_min")
        {
            if(iframe_min_height == null)
            {
                alert("iframe min height was null");
            }

            aljs_debug_alert("got iframe_resize_height_min");
            aljs_resize_iframe_height_min(iframe_id, iframe_min_height);

        }
                                         // on an max resize, 
                                         // calculate the height based on the max height
        else if(iframe_height_type == "iframe_resize_height_max")
        {
            if(iframe_max_height == null)
            {
                alert("iframe max height was null");
            }

            aljs_debug_alert("got iframe_resize_height_max");
            aljs_resize_iframe_height_max(iframe_id, iframe_max_height);

        }
                                         // on an min/max resize, 
                                         // calculate the height based on the min and max height
        else if(iframe_height_type == "iframe_resize_height_min_max")
        {
            if(iframe_max_height == null)
            {
                alert("iframe max height was null");
            }
            if(iframe_min_height == null)
            {
                alert("iframe min height was null");
            }

            aljs_debug_alert("got iframe_resize_height_min_max");
            aljs_resize_iframe_height_min_max(iframe_id, iframe_min_height, iframe_max_height);

        }
                                    // in all other cases use dynamic resizing
                                    // based on the height of the content
        else 
                      //if(iframe_height_type == iframe_resize_height_dynamic)
        {

            aljs_debug_alert("got iframe_resize_height_dynamic");
            aljs_resize_iframe_height_dynamic(iframe_id);

        }




                                        // resize the width based on what info
                                        // we got


                                         // on an exact resize, 
                                         // use an exact width to size the iframe
        if(iframe_width_type == "iframe_resize_width_exact")
        {
            if(iframe_width == null)
            {
                alert("iframe width was null");
            }

            aljs_debug_alert("got iframe_resize_width_exact");
            aljs_resize_iframe_width_exact(iframe_id, iframe_width);

        }
                                         // on an min resize, 
                                         // calculate the width based on the min width
        else if(iframe_width_type == "iframe_resize_width_min")
        {
            if(iframe_min_width == null)
            {
                alert("iframe min width was null");
            }

            aljs_debug_alert("got iframe_resize_width_min");
            aljs_resize_iframe_width_min(iframe_id, iframe_min_width);

        }
                                         // on an max resize, 
                                         // calculate the width based on the max width
        else if(iframe_width_type == "iframe_resize_width_max")
        {
            if(iframe_max_width == null)
            {
                alert("iframe max width was null");
            }

            aljs_debug_alert("got iframe_resize_width_max");
            aljs_resize_iframe_width_max(iframe_id, iframe_max_width);

        }
                                         // on an min/max resize, 
                                         // calculate the width based on the min and max width
        else if(iframe_width_type == "iframe_resize_width_min_max")
        {
            if(iframe_max_width == null)
            {
                alert("iframe max width was null");
            }
            if(iframe_min_width == null)
            {
                alert("iframe min width was null");
            }

            aljs_debug_alert("got iframe_resize_width_min_max");
            aljs_resize_iframe_width_min_max(iframe_id, iframe_min_width, iframe_max_width);

        }
                           // otherwise use a dynamic resize on the width based on the content
        else 
                       //if(iframe_width_type == iframe_resize_width_dynamic)
        {

            aljs_debug_alert("got iframe_resize_width_dynamic");
            aljs_resize_iframe_width_dynamic(iframe_id);

        }



    }
                       // otherwise there is no iframe to resize
    else
    {
        aljs_debug_alert("no iframe_id or tab to change");
    }



    aljs_debug_alert("about to call the parent aljs_change_iframe_size"); 

                                    // if this frame is not the top level frame
                                    // then resize the parent iframe too.
    if(parent != self)
    {
        aljs_debug_alert("parent = [" + parent + "]\n" + "parent.document = [" + parent.document + "]");

                                    // call the function in the parent frame to resize itself
                                    // if the parent has that function defined.

        if( typeof parent.document.aljs_change_iframe_size != 'undefined' )
        {
            parent.aljs_change_iframe_size();      
        }
    }


}



// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size 
// given as a parameter

function aljs_resize_iframe_height_exact(parm_tab_id, parm_iframe_height)
{
    var target_iframe;

    //alert("height exact parm_tab_id = [" + parm_tab_id + "]\n"
        //+"parm_iframe_height = [" + parm_iframe_height + "]\n");

    target_iframe = parent.document.getElementById(parm_tab_id);


    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }

    //alert("target_iframe = [" + target_iframe + "]");

    var initial_display = target_iframe.style.display;

    //alert("initial_display = [" + initial_display + "]");

    target_iframe.height = parm_iframe_height;
    
}

// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size 
// of the iframe_content with a minimum size given as an argument

function aljs_resize_iframe_height_min(parm_tab_id, parm_min_iframe_height)
{
    var target_iframe;
    var iframe_content_height;

    //alert("height min parm_tab_id = [" + parm_tab_id + "]\n"
    //+"parm_min_iframe_height = [" + parm_min_iframe_height + "]\n");

    target_iframe = parent.document.getElementById(parm_tab_id);

    //alert("target_iframe = [" + target_iframe + "]");

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }

    var hidden_nodes = aljs_set_node_parents_display(target_iframe);

    //JHJ070725//iframe_content_height = self.document.body.clientHeight + 30;
    iframe_content_height = self.document.body.clientHeight;

    //alert("iframe_content_height = [" + iframe_content_height + "]");

    if(iframe_content_height < parseInt(parm_min_iframe_height))
    {
        //alert("using parm_min_iframe_height = [" + parm_min_iframe_height + "]");
        target_iframe.height = parm_min_iframe_height;
    }
    else
    {
        //alert("using iframe_content_height= [" + iframe_content_height + "]");
        target_iframe.height = iframe_content_height;
    }
    
    aljs_set_hide_nodes(hidden_nodes);

}



// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size 
// of the iframe_content with a maximim size given as an argument

function aljs_resize_iframe_height_max(parm_tab_id, parm_max_iframe_height)
{
    var target_iframe;
    var iframe_content_height;

    //alert("height max parm_tab_id = [" + parm_tab_id + "]\n"
    //+"parm_max_iframe_height = [" + parm_max_iframe_height + "]\n");

    target_iframe = parent.document.getElementById(parm_tab_id);

    //alert("target_iframe = [" + target_iframe + "]");

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }

    var hidden_nodes = aljs_set_node_parents_display(target_iframe);

    //JHJ070725//iframe_content_height = self.document.body.clientHeight + 30;
    iframe_content_height = self.document.body.clientHeight;

    //alert("iframe_content_height = [" + iframe_content_height + "]");

    if(iframe_content_height > parm_max_iframe_height)
    {
        //alert("using parm_max_iframe_height = [" + parm_max_iframe_height + "]");
        target_iframe.height = parm_max_iframe_height;
    }
    else
    {
        //alert("using iframe_content_height = [" + iframe_content_height + "]");
        target_iframe.height = iframe_content_height;
    }
    
    aljs_set_hide_nodes(hidden_nodes);

}



// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size 
// of the iframe_content with a minimum size and a maximim size given as an argument

function aljs_resize_iframe_height_min_max(parm_tab_id, parm_min_iframe_height, parm_max_iframe_height)
{
    var target_iframe;
    var iframe_content_height;

    //alert("here height min max parm_tab_id = [" + parm_tab_id + "]\n"
        //+"parm_min_iframe_height = [" + parm_min_iframe_height + "]\n"
        //+"parm_max_iframe_height = [" + parm_max_iframe_height + "]\n"
    //);

    target_iframe = parent.document.getElementById(parm_tab_id);

    //alert("target_iframe = [" + target_iframe + "]");

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }

    var hidden_nodes = aljs_set_node_parents_display(target_iframe);

    //JHJ070725//iframe_content_height = self.document.body.clientHeight + 30;
    iframe_content_height = self.document.body.clientHeight;

    //alert("iframe_content_height = [" + iframe_content_height + "]");

    if(iframe_content_height > parm_max_iframe_height)
    {
        //alert("using parm_max_iframe_height = [" + parm_max_iframe_height + "]");
        target_iframe.height = parm_max_iframe_height;
    }
    else if(iframe_content_height < parm_min_iframe_height)
    {
        //alert("using parm_min_iframe_height = [" + parm_min_iframe_height + "]");
        target_iframe.height = parm_min_iframe_height;
    }
    else
    {
        //alert("using iframe_content_height = [" + iframe_content_height + "]");
        target_iframe.height = iframe_content_height;
    }
    
    aljs_set_hide_nodes(hidden_nodes);

}



// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size of the
// content

function aljs_resize_iframe_height_dynamic(parm_tab_id)
{
    var target_iframe;

    target_iframe = parent.document.getElementById(parm_tab_id);

    aljs_debug_alert("height dynamic parm_tab_id = [" + parm_tab_id + "]\n" + "target_iframe = [" + target_iframe + "]");

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        aljs_debug_alert("target_iframe is null, exiting early");
        return;
    }

    var hidden_nodes = aljs_set_node_parents_display(target_iframe);

    aljs_debug_alert("in aljs_resize_iframe_height_dynamic, self.document.body.clientHeight = [" + self.document.body.clientHeight + "]\n" + "self.document.body.clientWidth = [" + self.document.body.clientWidth + "]\n");


    //JHJ070725//target_iframe.height =  self.document.body.clientHeight + 30;


                // JHJ070827-having a problem here with the scrollbar appearing on a resize of the
                //           height, which causes the clientWidth to shrink by the scrollbar's width
                //           so when we resize dynamic the scrollbar is still there.
                //           resizing to the difference in size (the original plus the additonal
                //           scrollbar width) appears to correct the problem.
    var previous_width = self.document.body.clientWidth;

    if(self.document.body.clientHeight > 0)
    {
        //target_iframe.height =  self.document.body.clientHeight + 10;
 
            // JHJ071219 - reset back to no extra so we can debug this issue some more
        target_iframe.height =  self.document.body.clientHeight;

    }

    var new_width = self.document.body.clientWidth;   
                // apparently if we don't get the next clientWidth the browser will not
                // recalculate it in time to do the next comparisons
                // even though previous_width and new_width are never different.
                // the very next attempt to get the clientWidth WILL be different
                // JHJ070827

//    if(self.document.body.clientWidth != previous_width)
//    {
//        target_iframe.width = previous_width + (previous_width - self.document.body.clientWidth);
//    }
             // NOTE: we decided NOT to do this, because:
             //       if the width of the document is less than that of the iframe
             //       then after resizing the height, the width will stretch to 100%
             //       and the width resize would then add a negative amount.
             //       so if the previous_width was 630, and the iframe was 650
             //       resizing the height would cause the width to become 650
             //       and the little method above would shrink the page by 20
             //       so if you are running into this problem of a scrollbar appearing
             //       you will need to make your iframe larger to fit the content.
             //       the previous case was that the content was 400 and the iframe was 400
             //       and so it resized smaller to fit a scrollbar.
             //       JHJ20070828

    //target_iframe.height =  600 + 30;
    
    aljs_set_hide_nodes(hidden_nodes);

              // trickle up and set the heights to shrink upwards
    // JHJ20070829 - this causes things to have height that shouldn't
    //var tmp_node = target_iframe.parentNode;
    //while(tmp_node != null && tmp_node.nodeType == 1)
    //{
    //    tmp_node.height = target_iframe.height;
    //    tmp_node = tmp_node.parentNode;
    //}

}



// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size 
// given as a parameter

function aljs_resize_iframe_width_exact(parm_tab_id, parm_iframe_width)
{
    var target_iframe;

    //alert("width exact parm_tab_id = [" + parm_tab_id + "]\n"
        //+"parm_iframe_width = [" + parm_iframe_width + "]\n");

    target_iframe = parent.document.getElementById(parm_tab_id);


    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }

    //alert("target_iframe = [" + target_iframe + "]");

    var initial_display = target_iframe.style.display;

    //alert("initial_display = [" + initial_display + "]");

                                     // if the width was not set for some reason, then we need to reset it
                                     // and since we don't know the original value, use the dynamic value.
        if(parm_iframe_width == null || parm_iframe_width == 0)
        {
           aljs_resize_iframe_width_dynamic(parm_tab_id);
        }
        else
        { 
                       // only do this when it is not already 100%
            
            if(target_iframe.width != "100%")
            {
                target_iframe.width = parm_iframe_width;
            }
        } 
    
}

// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size 
// of the iframe_content with a minimum size given as an argument

function aljs_resize_iframe_width_min(parm_tab_id, parm_min_iframe_width)
{
    var target_iframe;
    var iframe_content_width;

    //alert("width min parm_tab_id = [" + parm_tab_id + "]\n"
    //+"parm_min_iframe_width = [" + parm_min_iframe_width + "]\n");

    target_iframe = parent.document.getElementById(parm_tab_id);

    //alert("target_iframe = [" + target_iframe + "]");

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }


    var hidden_nodes = aljs_set_node_parents_display(target_iframe);

    iframe_content_width = self.document.body.clientWidth + 30;

    //alert("iframe_content_width = [" + iframe_content_width + "]");

    if(iframe_content_width < parseInt(parm_min_iframe_width))
    {
        //alert("using parm_min_iframe_width = [" + parm_min_iframe_width + "]");
        target_iframe.width = parm_min_iframe_width;
    }
    else
    {
        //alert("using iframe_content_width= [" + iframe_content_width + "]");
        target_iframe.width = iframe_content_width;
    }
    
    aljs_set_hide_nodes(hidden_nodes);

}


// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size 
// of the iframe_content with a maximim size given as an argument

function aljs_resize_iframe_width_max(parm_tab_id, parm_max_iframe_width)
{
    var target_iframe;
    var iframe_content_width;

    //alert("width max parm_tab_id = [" + parm_tab_id + "]\n"
    //+"parm_max_iframe_width = [" + parm_max_iframe_width + "]\n");

    target_iframe = parent.document.getElementById(parm_tab_id);

    //alert("target_iframe = [" + target_iframe + "]");

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }

    var hidden_nodes = aljs_set_node_parents_display(target_iframe);

    iframe_content_width = self.document.body.clientWidth + 30;

    //alert("iframe_content_width = [" + iframe_content_width + "]");

    if(iframe_content_width > parm_max_iframe_width)
    {
        //alert("using parm_max_iframe_width = [" + parm_max_iframe_width + "]");
        target_iframe.width = parm_max_iframe_width;
    }
    else
    {
        //alert("using iframe_content_width = [" + iframe_content_width + "]");
        target_iframe.width = iframe_content_width;
    }
    
    aljs_set_hide_nodes(hidden_nodes);
}



// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size 
// of the iframe_content with a minimum size and a maximim size given as an argument

function aljs_resize_iframe_width_min_max(parm_tab_id, parm_min_iframe_width, parm_max_iframe_width)
{
    var target_iframe;
    var iframe_content_width;

    //alert("here width min max parm_tab_id = [" + parm_tab_id + "]\n"
        //+"parm_min_iframe_width = [" + parm_min_iframe_width + "]\n"
        //+"parm_max_iframe_width = [" + parm_max_iframe_width + "]\n"
    //);

    target_iframe = parent.document.getElementById(parm_tab_id);

    //alert("target_iframe = [" + target_iframe + "]");

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }

    var hidden_nodes = aljs_set_node_parents_display(target_iframe);

    iframe_content_width = self.document.body.clientWidth + 30;

    //alert("iframe_content_width = [" + iframe_content_width + "]");

    if(iframe_content_width > parm_max_iframe_width)
    {
        //alert("using parm_max_iframe_width = [" + parm_max_iframe_width + "]");
        target_iframe.width = parm_max_iframe_width;
    }
    else if(iframe_content_width < parm_min_iframe_width)
    {
        //alert("using parm_min_iframe_width = [" + parm_min_iframe_width + "]");
        target_iframe.width = parm_min_iframe_width;
    }
    else
    {
        //alert("using iframe_content_width = [" + iframe_content_width + "]");
        target_iframe.width = iframe_content_width;
    }
    
    aljs_set_hide_nodes(hidden_nodes);
}



// this iframe resizes the iframe of the given id in the parent frame.  This call
// will be put in the onload of a frame, and it will resize itself to the size of the
// content

function aljs_resize_iframe_width_dynamic(parm_tab_id)
{
    var target_iframe;

    //alert("width dynamic parm_tab_id = [" + parm_tab_id + "]");

    target_iframe = parent.document.getElementById(parm_tab_id);

    //alert("target_iframe = [" + target_iframe + "]");

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting early");
        return;
    }

    var hidden_nodes = aljs_set_node_parents_display(target_iframe);

    //alert("self.document.body.clientWidth = [" + self.document.body.clientHeight + "]\n"
            //+"self.document.body.clientWidth = [" + self.document.body.clientWidth + "]\n"
    //);

    //target_iframe.width =  self.document.body.clientWidth + 30;
    //JHJTEST1//target_iframe.width =  1024 + 30;
    //target_iframe.width =  750;            // set to 750 because 1054 was too much
    
    aljs_set_hide_nodes(hidden_nodes);

}

// resize the window that we are in to the size of the currently displayed content
function aljs_resize_window(new_width, new_height)
{
    if(new_width == null || new_width == 0
           || new_height == null || new_height == 0)
    {
            width = self.document.body.clientWidth + 30;
        //JHJ070725//height = self.document.body.clientHeight + 30;
        height = self.document.body.clientHeight;
    }
    else
    {
            width = new_width;
        height = new_height;
    }

    //alert("setting width=[" + width + "]");
    //alert("setting height=[" + height + "]");

        // these don't do anything, we depend on the resizeTo method to change the size of the window
    //window.width =  width;
    //window.height =  height;

    //window.resizeBy(width, height);     // resize by represents an amount of increase over the current size
    window.resizeTo(width, height);     // resize to represents a specific size of window

    // both resize methods seem to take into account the actual space to resize the window, which is bounded by 
    // the edge of the monitor (the displayed space), and will not exceed the size of the monitor, even if that
    // means using less than the desired size

}


///////////////////////////////////////////////////////////////////////////////////////////
//
//   END resize functions
//
///////////////////////////////////////////////////////////////////////////////////////////



function aljs_get_app_window(win_name)
{
    //alert("going to open name=" + win_name);

    tmp_count = App_windows.length;                    // get count of # of windows opened

    //alert("tmp_count=" + tmp_count);

    for(ii=0;ii<tmp_count;ii++)                        // loop through and see if inbound window is accounted for already
    {
        if(win_name == "_blank")        // for now on blank, always open a new win
        {
            break;
        }
        if(App_windows[ii].name == win_name)        // if we have the window already acocunted for
        {
            //alert("found name=" + win_name);
            //return(App_windows[ii]);                // return this window object
    

                                                // currently we want to prevent reuse of windows,
                                                // so this is here to stop reuse of windows.
                                                // if you want to re-use a window, you will need to
                                                // add some code to indicate re-use of the window is
                                                // needed when calling for a popup window.
            App_windows[tmp_count] = new Object;
            App_windows[tmp_count].name = win_name + tmp_count;
            return(App_windows[tmp_count]);                    // and return it
        }
    }
    
    //alert("assign app_window object to App_windows");
                                                    // else we need to setup a new window object
    //App_windows[tmp_count] = new app_window;
    App_windows[tmp_count] = new Object;
    App_windows[tmp_count].name = win_name;

    //alert("return App_windows thing");
    return(App_windows[tmp_count]);                    // and return it
}


function aljs_closePopup() {
    if (CurPopupWindow != null) {
       
        if (!CurPopupWindow.closed) {
            CurPopupWindow.close();
        }
        CurPopupWindow = null;
    }
}

function aljs_closeWindow(iframe_id) 
{

    //alert("attempted to close a window!");
    //window.close();
    if(top == self)
    {
        top.close();
    }

    if(window.frameElement != null)
    {
        var iframe_id = window.frameElement.id;
        var div_id = 'div_' + iframe_id;
        var tab_id = iframe_id + '_tab';

        var iframe_element = parent.al_get_object(iframe_id);
        var div_element = parent.al_get_object(div_id);
        var tab_element = parent.al_get_object(tab_id);

        iframe_element.src = 'about:blank';

                        // if this is a tabbed-browsing iframe, close the tab
        if(tab_element != null)
        {
            parent.closeMenus();
            parent.aljs_close_module_tab(tab_id);
        }
                        // if this is a iframe with a button to close, then close out the div
        else if(div_element != null)
        {
            div_element.parentNode.removeChild(div_element);
        }
                        // else close just the iframe and nothing else
        else
        {
            iframe_element.parentNode.removeChild(iframe_element);
        }
    }
    else
    {
        top.close();
    }

}

function aljs_checkCloseWindow(tmp_action, close_action, iframe_id) 
{
    var div_id = "div_" + iframe_id;

    //alert("iframe_id = [" + iframe_id + "]");

    if(parent != self && parent.document.getElementById(div_id) != null)
    {
        alert("in a popin");

        if(tmp_action == close_action)            // if we are to close the window
        {
            alert("closing popin");

            var remove_div;

            remove_div = al_get_object(div_id);

                        // if we're supposed to confirm the close
                        // before closing the window
                                                                al_get_object(iframe_id).src = "about:blank";
            remove_div.parentNode.removeChild(remove_div);
        }


    }
    else
    {



        //alert("check tmp_action=" + tmp_action + " close_action=" + close_action);
        if(tmp_action == close_action)            // if we are to close the window
        {
            window.opener.location.reload();
            aljs_closeWindow(iframe_id);
        }
        else
        {
        }
    }
}
function aljs_checkRefreshWindow(tmp_action, close_action, iframe_id) 
{
    //alert("check tmp_action=" + tmp_action + " close_action=" + close_action);
    if(tmp_action == close_action)            // if we are to close the window
    {
        top.window.location.reload();
    }
    else
    {
    }
}

function aljs_set_div_position(divname, showdiv)
{
    //alert("CurMouseY=" + CurMouseY);

    //alert("document.body.scrollLeft=" + document.body.scrollLeft);
    //alert("document.body.scrollTop=" + document.body.scrollTop);

    // jhj - 8/5/03 - added the scrollLeft (IE only) to handle when
    //                the user has scrolled the window down.  

    al_get_object(divname).style.top=document.body.scrollTop + CurMouseY - 250;
    al_get_object(divname).style.left=100;


    if(showdiv == 1)        // if the flag is set to show the div (because it is hidden)
    {
        al_get_object(divname).style.visibility='visible';

    }

}

//
// function aljs_display_at_mouse_position()
//
// params:  event        = the event that gives us a mouse position
// params:  e_id        = id of the element to show and re-position
// params:  x_off        = an offset value from the mouse position
// params:  y_off        = an offset value from the mouse position
//
// description:   display the element and reposition at the mouse pointer where the click happened
//
function aljs_display_at_mouse_position(event, e_id, y_off, x_off)
{
     //alert("ENTRY-aljs_display_at_mouse_position");

    var vertical_scroll_offset = 0;
    if(document.documentElement.scrollTop > 0)
    {
        vertical_scroll_offset = document.documentElement.scrollTop;
    }
    else if (document.body.scrollTop > 0)
    {
        vertical_scroll_offset = document.body.scrollTop;
    }
    else    
    {
        vertical_scroll_offset = 0;
    }
    
    var horizontal_scroll_offset = 0;
    if(document.documentElement.scrollLeft > 0)
    {
        horizontal_scroll_offset = document.documentElement.scrollLeft;
    }
    else if (document.body.scrollLeft > 0)
    {
        horizontal_scroll_offset = document.body.scrollLeft;
    }
    else
    {
        horizontal_scroll_offset = 0;
    }
                            
    // set the position relative to the mouse in the current window
    al_get_object(e_id).style.top=event.clientY + y_off + vertical_scroll_offset;
    al_get_object(e_id).style.left=event.clientX + x_off + horizontal_scroll_offset;
                                
                              
    // set the display to visible
    al_get_object(e_id).style.visibility='visible';
    al_get_object(e_id).style.display='block';

    
    //alert("EXIT-aljs_display_at_mouse_position");
}


function aljs_set_element_display(element_id, action)
{
    if(action == 'hide')
    {
            al_get_object(element_id).style.visibility = 'hidden';
            al_get_object(element_id).style.display = 'none';
    }

    if(action == 'show')
    {
            al_get_object(element_id).style.visibility = 'visible';
            al_get_object(element_id).style.display = 'block';
    }
}

    

function aljs_swap_div_display(divname, parentdiv)
{
    /*
        alert("visibility = " + al_get_object(divname).style.visibility);
    */

    if(parentdiv != '')
    {
        if(browser.isNS)
        {
            if(document.getElementById(parentdiv).documentgetElementByID(divname).style.visibility == 'visible')
            {
                document.getElementById(parentdiv).documentgetElementByID(divname).style.visibility = 'hidden';
                document.getElementById(parentdiv).documentgetElementByID(divname).style.display = 'none';
            }
            else
            {
                document.getElementById(parentdiv).documentgetElementByID(divname).style.visibility = 'visible';
                document.getElementById(parentdiv).documentgetElementByID(divname).style.display = 'block';
            }
        }
        else
        {
            if(document.all[parentdiv].document.all[divname].style.visibility == 'visible')
            {
                document.all[parentdiv].document.all[divname].style.visibility = 'hidden';
                document.all[parentdiv].document.all[divname].style.display = 'none';
            }
            else
            {
                document.all[parentdiv].document.all[divname].style.visibility = 'visible';
                document.all[parentdiv].document.all[divname].style.display = 'block';
            }
        }
    }
    else
    {
        if(al_get_object(divname).style.visibility == 'visible')
        {
            al_get_object(divname).style.visibility = 'hidden';
            al_get_object(divname).style.display = 'none';
        }
        else
        {
            al_get_object(divname).style.visibility = 'visible';
            al_get_object(divname).style.display = 'block';
        }
    }


}


function aljs_load_form_element_objects()
{
    var obj_Element;            // on the fly object representing an 'alobj' object

    var element_count;
    var element_name;
    var element_name_parts;
    var ii;

    element_count = al_get_content_form().length;

    array_Elements = new Array();

    for(ii=0;ii<element_count;ii++)
    {
        //alert('tag id = ' + al_get_content_form().elements[ii].getAttribute('id'));
        switch(al_get_content_form().elements[ii].tagName)
        {
            case 'INPUT':
            case 'TEXTAREA':
            case 'PASSWORD':
            {


                element_name = al_get_content_form().elements[ii].getAttribute('name');
                element_name_parts = element_name.split('|');

                if(element_name_parts[0] == 'ZZOBJ')
                {
                    obj_Element = new Object();

                    if(al_get_content_form().elements[ii].getAttribute('id'))
                    {
                        obj_Element['id'] = al_get_content_form().elements[ii].getAttribute('id');
                    }

                    obj_Element['type'] = al_get_content_form().elements[ii].type;

                    if(al_get_content_form().elements[ii].type == 'radio'
                        || al_get_content_form().elements[ii].type == 'checkbox')
                    {
                        //alert('tag name = ' + al_get_content_form().elements[ii].getAttribute('name'));
                        //alert('checked value of selectable = ' + al_get_content_form().elements[ii].checked);
                        obj_Element['checked'] = al_get_content_form().elements[ii].checked;

                        //alert("index of array_Elements = [" + (array_Elements.length) + "]");
                    }

                    obj_Element['element_index'] = ii;
                    obj_Element['class'] = element_name_parts[1];
                    obj_Element['instance'] = element_name_parts[2];
                    obj_Element['field_type'] = element_name_parts[3];
                    obj_Element['element_type'] = al_get_content_form().elements[ii].type;
                    obj_Element['node'] = al_get_content_form().elements[ii];

                                        // save either the key field or
                                        // save the name of the field
                    if(element_name_parts[3] != 'KEYVALUE')
                    {
                        obj_Element['field'] = element_name_parts[4];
                    }
                    else
                    {
                        obj_Element['field'] = element_name_parts[3];
                    }
                    obj_Element['value'] = al_get_content_form().elements[ii].value;
                    //alert(element_name_parts[0]);
                    //alert(element_name_parts[1]);
                    //alert(element_name_parts[2]);
                    //alert(typeof(array_Elements) + " equal to Array=" + (array_Elements === Array));
                    //array_Elements.push("Test");
                    array_Elements.push(obj_Element);

                    //alert("size of array_Elements = [" + (array_Elements.length - 1) + "]");
                }    
                break;
            }
            case 'SELECT':
            {
                element_name = al_get_content_form().elements[ii].getAttribute('name');
                element_name_parts = element_name.split('|');

                //alert("loading form element, element name = [" + element_name + "]\n"
                    //+ "element_name_parts = [" + element_name_parts + "]");

                if(element_name_parts[0] == 'ZZOBJ')
                {
                    obj_Element = new Object();
                    obj_Element['element_index'] = ii;
                    obj_Element['type'] = al_get_content_form().elements[ii].type;
                    obj_Element['class'] = element_name_parts[1];
                    obj_Element['instance'] = element_name_parts[2];
                    obj_Element['field_type'] = element_name_parts[3];
                    obj_Element['node'] = al_get_content_form().elements[ii];



                    if(al_get_content_form().elements[ii].getAttribute('id'))
                    {
                        obj_Element['id'] = al_get_content_form().elements[ii].getAttribute('id');
                    }

                                        // save either the key field or
                                        // save the name of the field
                    if(element_name_parts[3] != 'KEYVALUE')
                    {
                        obj_Element['field'] = element_name_parts[4];
                    }
                    else
                    {
                        obj_Element['field'] = element_name_parts[3];
                    }
                    obj_Element['value'] = al_get_content_form().elements[ii].value;
                    //alert(element_name_parts[0]);
                    //alert(element_name_parts[1]);
                    //alert(element_name_parts[2]);
                    //alert(typeof(array_Elements) + " equal to Array=" + (array_Elements === Array));
                    //array_Elements.push("Test");
                    array_Elements.push(obj_Element);
                }    
                break;
            }
            default:
            {
                break;
            }

        }
    }

    //for(ii=0;ii<array_Elements.length;ii++)
    //{
        //alert('object=' + array_Elements[ii]['class'] + ' value=' + array_Elements[ii]['value']);
    //}
    return;
}

function aljs_revert_form_element_objects(class_name, instance_id)
{
    var ii;
    var idx;

    if(array_Elements == null)
    {
        alert("Please wait for the form to completely load before making changes");
        return;
    }

    //alert('in aljs_revert_form_element_objects\n'
        //+ 'reverting for ' + array_Elements.length + ' elements on page');
    
    for(ii=0;ii<array_Elements.length;ii++)        // for each element on the page saved
    {
                                                // if the element is the same class and instance
        if(array_Elements[ii]['class'] == class_name && array_Elements[ii]['instance'] == instance_id)
        {
                                                // then revert the values for that class/instance
            idx = array_Elements[ii]['element_index'];
            //alert('index to reset = ' + idx);
            if( array_Elements[ii]['node'].type == 'checkbox')
            {
                //alert('radio to reset = ' + idx);
                array_Elements[ii]['node'].value = '' + array_Elements[ii]['value'];
                array_Elements[ii]['node'].checked = array_Elements[ii]['checked'];
            }
            else if(array_Elements[ii]['node'].type == 'radio')
            {
                //alert("in radio, ii = [" + ii + "]\n"
                    //+ "value = [" + array_Elements[ii]['value'] + "]\n"
                    //+ "checked = [" + array_Elements[ii]['checked'] + "]\n");


                array_Elements[ii]['node'].value = '' + array_Elements[ii]['value'];
                array_Elements[ii]['node'].checked = array_Elements[ii]['checked'];
            }
            else if(array_Elements[ii]['node'].type == 'select-one')
            {
                if(array_Elements[ii]['node'].value != array_Elements[ii]['value'])
                {
                    //alert("array_Elements[ii]['node'].value = ["+array_Elements[ii]['node'].value + "]\n"
                        //+ "array_Elements[ii]['value'] = [" + array_Elements[ii]['value'] + "]");

                    var field_name = array_Elements[ii]['node'].getAttribute('name');
                    //alert(field_name);

                                        // change the value back
                    //alert("before changing value, array_Elements[ii]['node'].value = [" + array_Elements[ii]['node'].value + "]");

                    array_Elements[ii]['node'].value = '' + array_Elements[ii]['value'];

                    //alert("after changing value, array_Elements[ii]['node'].value = [" + array_Elements[ii]['node'].value + "]");

                                        // whenever the value of a select box is changed,
                                        // then trigger the onchange event for that
                                        // object

                    //alert("got a select box, trying to execute onchange\n"
                        //+ "field_name = [" + field_name + "]");
                    al_get_object(field_name).onchange();
                }
            }
            else
            {
                                // if the value has changed, then change it back

                if(array_Elements[ii]['node'].value != array_Elements[ii]['value'])
                {

                    array_Elements[ii]['node'].value = '' + array_Elements[ii]['value'];
                }    
            }
        }
    }
    return;
}

                // aljs_expand_contract_entire_report - this function goes through all the fields on a
                //                                        report and expands or contracts them if they
                //                                        are not in the first row of a record
                                                        

function aljs_expand_contract_entire_report(action)
{
    var span_array = document.getElementsByTagName('span');

    for (ii=0; ii<span_array.length; ii++)
    {
        var span_obj = span_array[ii];
        var obj_id = span_obj.getAttribute('id');

        if(obj_id)    // if this element has an id
        {
            var prefix = obj_id.substr(0, 6);

            if(prefix == 'span2_' )
            {    
                if(action == 'contract')    // if action is contract, hide the data
                {
                    span_obj.style.display = 'none';
                }
                else if(action == 'expand')    // if action is expand, show the data
                {
                    span_obj.style.display = 'block';
                }
            }
        }
    }
        
                                    // loop through all of the images to find expand
                                    // and contract buttons and set them to the proper
                                    // state

    var img_array = document.getElementsByTagName('img');

    for (ii=0; ii<img_array.length; ii++)
    {
        var img_obj = img_array[ii];
        var obj_id = img_obj.getAttribute('id');

        if(obj_id)    // if this element has an id
        {
            if(obj_id.lastIndexOf('_contract_button') > 0)  // if this is a contract button
            {
                if(action == 'contract')    // hide it if the action is contract
                {
                    img_obj.style.display = 'none';
                }
                else if(action == 'expand')    // show it if the action is expand
                {
                    img_obj.style.display = 'block';
                }

            }
            else if(obj_id.lastIndexOf('_expand_button') > 0) // if this is an expand button
            {
                if(action == 'contract') // show it if the action is contract
                {
                    img_obj.style.display = 'block';
                }
                else if(action == 'expand') // hide it if the action is expand
                {
                    img_obj.style.display = 'none';
                }

            }
        }
    }

                                                    // loop through all the hiddens and find the 
                                                    // ones that keep track of a record's state.
                                                    // set them to the correct value

    var hidden_array = document.getElementsByTagName('input');

    for (ii=0; ii<hidden_array.length; ii++)
    {
        var hid_obj = hidden_array[ii];
        var obj_id = hid_obj.getAttribute('id');

        if(obj_id)    // if this element has an id
        {
            if(hid_obj.type == 'hidden' 
               && obj_id.lastIndexOf('_contract_state') > 0)  // if this is one of the hiddens that keeps track of state
            {
                if(action == 'contract')        // if we are contracted, set hidden value to contracted
                {
                    hid_obj.value = 'contracted';
                }
                else if(action == 'expand')        // if we are expanding, set hidden value to expanded
                {
                    hid_obj.value = 'expanded';
                }
            }
        }
    }    
}

                // aljs_contract_report_object - function that goes through all of the items 
                //                                 passed in by an array and shows or hides the contents
                //                               based on the action and the if they belong to the 
                //                                 correct instance.
                // 
                //                                 instance_id = instance id of the object 
                //                                 field_array = array of field id's that we need to check
                //                                 button_name = id of the button that was clicked
                //



function aljs_contract_report_object(instance_id, field_array)
{
    var action = "";

                                                    // calculate the id's for the expand and
                                                    // contract buttons

    var contract_button_id = instance_id + "_contract_button";
    var expand_button_id = instance_id + "_expand_button";

                                                    // Check the status Hidden object of this instance_id
                                                    // to see what needs to be done
    var state_hidden_id = instance_id + "_contract_state";

    var state_obj = al_get_object(state_hidden_id);



    if(typeof state_obj == "undefined")
    {

        var form = 'forms[0]';
        var field = state_hidden_id;
        var index;
        var jj;

        tmp_form = "document." + form + ".elements.length";

                            //
                            // because we have pipe symbols in some of the
                            // form's field name (i.e. ZZOBJ|crm|2534|comp_name)
                            // there is a problem with accessing the value of
                            // that form field.  
                            // 
                            // To solve that problem, we use the INDEX of that 
                            // field name as found in the form's elements
                            // We get that index value in the next for loop
                            //

        for(jj=0;jj<eval(tmp_form);jj++)
        {
            tmp_element = "document." + form + ".elements[" + jj + "].id";


            if(eval(tmp_element) == field)
            {

                index = jj;
                break;
            }
        }


        tmp_node = "document." + form + ".elements[" + index + "]";
        state_obj = eval("document." + form + ".elements[" + index + "]");


    }

    var current_state = state_obj.value;

                                                    // if current_state is expanded, contract it.  
                                                    // otherwise expand it, display the button that
                                                    // will do the opposite of the current action

    if(current_state == 'expanded')
    {
        action = 'contract';
        state_obj.value = 'contracted';

        al_get_img_object(contract_button_id).style.display = 'none';
        al_get_img_object(expand_button_id).style.display = 'block';
        
    }
    else
    {
        action = 'expand';
        state_obj.value = 'expanded';

        al_get_img_object(contract_button_id).style.display = 'block';
        al_get_img_object(expand_button_id).style.display = 'none';
    }

    for (ii=0; ii<field_array.length; ii++)
    {
        var obj_id = field_array[ii];

        if(obj_id)    // if this element has an id
        {
            var prefix = obj_id.substr(0, 6);

            var correct_instance = obj_id.indexOf(instance_id);

                                            // if the id starts with span2_, set the corresponding field
                                            // to hidden or visible, depending on action

            if(prefix == 'span2_' && correct_instance > 0)
            {
                                            // get the part after span2_

                //alert("obj_id = " + obj_id + "\n object = " + al_get_object(obj_id));
                var submitfieldname = obj_id.substr(6);

                if(action == 'contract')    // if action is contract, hide the data
                {
                    al_get_span_object(obj_id).style.display = 'none';
                }
                else if(action == 'expand')    // if action is expand, set value to the value of the hidden
                {
                    al_get_span_object(obj_id).style.display = 'block';
                }
            }

        }                                        
    }
}

// function aljs_move_list_select_item - This function takes the two select elements and moves
//                                          items between the two of them.  The action describes what
//                                          is done to column b
//
//                                         col_a_select => name of column a input element
//                                         col_b_select => name of column b input element
//                                         action => The action to take.  Either "add" or "remove"
//                                         move_all => boolean, if true move all, if false move selected
                

function aljs_move_list_select_item(col_a_select, col_b_select, action, move_all)
{
    if(action == 'add')
    {
        var moved_array = new Array();

        var a_length = al_get_object(col_a_select).options.length;

        for(var ii = 0; ii < a_length; ii++)
        {

                                            // if the current index is selected or we are moving all

            if(al_get_object(col_a_select).options[ii].selected || move_all)
            {
                                            // keep track of which indexes we moved so we can 
                                            // delete them after moving all of them

                moved_array[moved_array.length] = ii;

                                            // put the item into column b

                with(al_get_object(col_b_select))
                {
                    options[options.length] = new Option(al_get_object(col_a_select).options[ii].text, al_get_object(col_a_select).options[ii].value);
                }
                                                    
                                            // parse the submit_fieldname and recnum out of  the selected
                                            // item's value attribute to name the hidden with

                var string_to_parse = al_get_object(col_a_select).options[ii].value;

                var idx = string_to_parse.lastIndexOf('|');

                var submit_fieldname = string_to_parse.substring(0, idx );    

                var recnum = string_to_parse.substring(idx + 1, string_to_parse.length);    


                                            // create a hidden for recnum on the page

                var new_hidden = document.createElement('input');                                
                new_hidden.type = 'hidden';
                new_hidden.value = recnum;
                new_hidden.name = submit_fieldname;
                new_hidden.id = submit_fieldname;

                al_get_content_form().appendChild(new_hidden);

                                            // create a hidden for addChangeDelete_flag    

                var replace_index = submit_fieldname.indexOf('KEYVALUE');
                var acd_hidden_name = submit_fieldname.substring(0, replace_index);

                acd_hidden_name += 'FIELD|addChangeDelete_flag';


                var new_hidden2 = document.createElement('input');                                
                new_hidden2.type = 'hidden';
                new_hidden2.value = 'Choose...';
                new_hidden2.name = acd_hidden_name;
                new_hidden2.id = acd_hidden_name;

                al_get_content_form().appendChild(new_hidden2);

            }
        }
                                            // looped through the removed array and remove the moved
                                            // items, starting with the largest index first so the 
                                            // array we're removing from doesn't shrink and we try to
                                            // remove an index that isn't there anymore

        for(var ii = moved_array.length -1; ii >= 0; ii--)
        {
                                            // remove the column a listing

            var col_a_remove_index = moved_array[ii];

            al_get_object(col_a_select).options[col_a_remove_index] = null;
        }
    }
    else if(action == 'remove')
    {
        var moved_array = new Array();

        var b_length = al_get_object(col_b_select).options.length;

        for(var ii = 0; ii < b_length; ii++)
        {
                                            // if the current index is selected or we are moving all

            if(al_get_object(col_b_select).options[ii].selected || move_all)
            {
                                            // keep track of which indexes we moved so we can 
                                            // delete them after moving all of them

                moved_array[moved_array.length] = ii;

                                            // add the item to column a

                with(al_get_object(col_a_select))
                {
                    options[options.length] = new Option(al_get_object(col_b_select).options[ii].text, al_get_object(col_b_select).options[ii].value);
                }
                
                                            // calculte the name of hidden on the page that corresponds
                                            // to the selected list item 

                var    hidden_name = al_get_object(col_b_select).options[ii].value;

                var idx = hidden_name.lastIndexOf('|');
                var submit_fieldname = hidden_name.substring(0, idx );    

                                            // delete the hidden from the page


                var current_node = al_get_object(submit_fieldname);

                
                if(typeof current_node.name == "undefined")
                {

                    var form = 'forms[0]';
                    var field = submit_fieldname;
                    var index;
                    var jj;

                    tmp_form = "document." + form + ".elements.length";

                                        //
                                        // because we have pipe symbols in some of the
                                        // form's field name (i.e. ZZOBJ|crm|2534|comp_name)
                                        // there is a problem with accessing the value of
                                        // that form field.  
                                        // 
                                        // To solve that problem, we use the INDEX of that 
                                        // field name as found in the form's elements
                                        // We get that index value in the next for loop
                                        //

                    for(jj=0;jj<eval(tmp_form);jj++)
                    {
                        tmp_element = "document." + form + ".elements[" + jj + "].id";


                        if(eval(tmp_element) == field)
                        {

                            index = jj;
                            break;
                        }
                    }


                    tmp_node = "document." + form + ".elements[" + index + "]";
                    current_node = eval("document." + form + ".elements[" + index + "]");


                }

                current_node.value = '1';
                current_node.name = '1';
                current_node.id = '1';

                                                // erase the addChangeDelete_flag

                var replace_index = submit_fieldname.indexOf('KEYVALUE');
                var acd_hidden_name = submit_fieldname.substring(0, replace_index);

                acd_hidden_name += 'FIELD|addChangeDelete_flag';


                current_node2 = al_get_object(acd_hidden_name);

                if(typeof current_node2.name == "undefined")
                {

                    var form = 'forms[0]';
                    var field = acd_hidden_name;
                    var index;
                    var jj;

                    tmp_form = "document." + form + ".elements.length";

                                        //
                                        // because we have pipe symbols in some of the
                                        // form's field name (i.e. ZZOBJ|crm|2534|comp_name)
                                        // there is a problem with accessing the value of
                                        // that form field.  
                                        // 
                                        // To solve that problem, we use the INDEX of that 
                                        // field name as found in the form's elements
                                        // We get that index value in the next for loop
                                        //

                    for(jj=0;jj<eval(tmp_form);jj++)
                    {
                        tmp_element = "document." + form + ".elements[" + jj + "].id";


                        if(eval(tmp_element) == field)
                        {

                            index = jj;
                            break;
                        }
                    }


                    tmp_node = "document." + form + ".elements[" + index + "]";
                    current_node2 = eval("document." + form + ".elements[" + index + "]");


                }

                current_node2.value = '1';
                current_node2.name = '1';
                current_node2.id = '1';
            }

        }
                                            // looped through the removed array and remove the moved
                                            // items, starting with the largest index first so the 
                                            // array we're removing from doesn't shrink and we try to
                                            // remove an index that isn't there anymore

        for(var ii = moved_array.length -1; ii >= 0; ii--)
        {
                                            // remove the column b listing

            var col_b_remove_index = moved_array[ii];

            al_get_object(col_b_select).options[col_b_remove_index] = null;
        }
    }

}

// function aljs_reorder_list_select - this function reorders items in the list select box
//                  
//                                  = select_element => the id of the html select element
//                                    = direction => direction to move selected item 'up' or 'down'

function aljs_reorder_list_select(select_element_id, direction)
{
    var multi_select= al_get_object(select_element_id);

    var count_selected = 0;    
    var selected_index = -1;

                                    // count the selected items and find which one is selected

    for(var ii = 0; ii < multi_select.options.length; ii++)
    {
        if(multi_select.options[ii].selected)
        {
            count_selected++;
            selected_index = ii;
        }
    }

                                    // exit and maybe give error messages if the options selected and
                                    // the button pressed are not meaningful together

    if(count_selected > 1)
    {
        alert('Please select only one option');
        return;
    }
    if(count_selected == 0)
    {
        alert('Please select an option to move');
        return;
    }

    if(selected_index == 0 && direction == 'up')
    {
        return;
    }

    if(selected_index == multi_select.options.length - 1 && direction == 'down')
    {
        return;
    }


                                    // set up the indexes to do the switch on

    var switch_index;

    if(direction == 'up')
    {
        switch_index = selected_index - 1;
    }
    else if(direction == 'down')
    {
        switch_index = selected_index + 1;
    }
    else
    {
        alert('direction must be \'up\' or \'down\'');
        return;
    }

                                    // switch the items

    var temp_text = multi_select.options[switch_index].text;
    var temp_value = multi_select.options[switch_index].value;

    multi_select.options[switch_index].text = multi_select.options[selected_index].text;
    multi_select.options[switch_index].value = multi_select.options[selected_index].value;

    multi_select.options[selected_index].text = temp_text;
    multi_select.options[selected_index].value = temp_value;

                                    // change which item is selected
    
    multi_select.options[selected_index].selected = false; 
    multi_select.options[switch_index].selected = true; 


}



//
// This function returns a string that gets added to the end of a url
//


function aljs_add_value_from_page_to_url(submit_index, element_id)
{
    var return_value = "";
    var field_value = "";
    var encoded_field_value = "";

    //alert("in aljs_add_value_from_page_to_url\n" 
            //+ "submit_index = [" + submit_index + "]\n"
            //+ "element_id = [" + element_id + "]\n"
        //);

    field_value = al_get_object(element_id).value;

    //alert("here1");

    encoded_field_value = aljs_urlencode(field_value);

    //alert("here2");
    return_value = "&" + submit_index + "=" + encoded_field_value;

    //alert("here3");
    
    return return_value;
}

//
// this is to help get an element's value for multiple element types (radio, checkbox, etc)
//
function aljs_get_element_value(element_id)
{
    var return_value = "";
    var field_value = "";
    var element_obj;
    var encoded_field_value = "";

    //alert("in aljs_get_element_value\n element_id = [" + element_id + "]\n");

    element_obj = al_get_object(element_id);

    if( element_obj == null)    // if the element is null, then we cannot reutnr anything
    {
        return '';
    }

    //alert("element_obj.type=" + element_obj.type);

    if(element_obj.type == 'radio')
    {
        if(array_Elements == null)
        {       
            //alert("here");

            // Only return a value if the radio is checked.  otherwise no value would get submitted
            // so there is no value to return.
            if(element_obj.checked)
            {     
                field_value = element_obj.value;
            }     
            else  
            {     
                field_value = ""; 
            }  
        }       
        else    
        {
            //alert("where I want to be");
            field_value = "0";

            for(ii=0;ii<array_Elements.length;ii++)     // for each element on the page saved
            {

                var  tmp_element_id = array_Elements[ii]['id'];
                //alert('element_id = ' + element_id);

                if(tmp_element_id == element_id && array_Elements[ii]['type'] == 'radio')
                {
                        //alert("here in type = radio\n arrayElements[ii] = [" + array_Elements[ii] + "]" );

                    if(array_Elements[ii]['node'].checked)
                    {
                        field_value = array_Elements[ii]['node'].value;
                        break;
                    }
                }
            }
        }
    }

    else if(element_obj.type == 'checkbox')
    {
        if(array_Elements == null)
        {
            //alert("here");

            // Only return a value if the radio is checked.  otherwise no value would get submitted
            // so there is no value to return.
            if(element_obj.checked)
            {
                field_value = element_obj.value;
            }
            else
            {
                field_value = "";
            }
        }      
        else    
        {     
            //alert("where I want to be");
            field_value = "0";

            for(ii=0;ii<array_Elements.length;ii++)     // for each element on the page saved
            {     

                var  tmp_element_id = array_Elements[ii]['id'];
                //alert('element_id = ' + element_id);

                if(tmp_element_id == element_id && array_Elements[ii]['type'] == 'checkbox')
                {     
                        //alert("here in type = checkbox\n arrayElements[ii] = [" + array_Elements[ii] + "]" );

                    if(array_Elements[ii]['node'].checked)
                    {     
                        field_value = array_Elements[ii]['node'].value;
                        break;
                    }     
                }     
            }     
        }     
    }
    else if(element_obj.type == 'select-one')
    {
        field_value = element_obj.options[element_obj.selectedIndex].value;
    }
    else
    {
        field_value = al_get_object(element_id).value;
    }

    //alert("here1");

    return_value = aljs_urlencode(field_value);

    //alert("here3");

    return return_value;
}

/* ***********************************************************************************
//
// this is to help get an element's value for multiple element types (radio, checkbox, etc)
//
function aljs_get_element_value(element_id)
{
    var return_value = "";
    var field_value = "";
    var element_obj;
    var encoded_field_value = "";

    //alert("in aljs_add_value_from_page_to_url\n" 
            //+ "element_id = [" + element_id + "]\n"
        //);

    element_obj = al_get_object(element_id);

    if(element_obj.type == 'select-one')
    {
        field_value = element_obj.options[element_obj.selectedIndex].value;
    }
    else
    {
        field_value = al_get_object(element_id).value;
    }    

    //alert("here1");

    return_value = aljs_urlencode(field_value);

    //alert("here3");
    
    return return_value;
}
******************************************************************************** */

function aljs_urlencode(string_to_encode)
{
    var encoded_string;

    encoded_string = encodeURIComponent(string_to_encode);


    return(encoded_string);
}











function toggle_slidebar()
{
    if(al_get_object('floatLayer').style.display == 'none')
    {
        al_get_object('floatLayer').style.display = 'block';
    }
    else
    {
        al_get_object('floatLayer').style.display = 'none';
    }
}


//
// aljs_show_hide_button_toggle
// aljs_show_hide_button_hide
// aljs_show_hide_button_show
//
//    These functions take an element id of an element on the page
//  and show, hide or toggle it, depending on what function is
//  called
//


function aljs_show_hide_button_toggle(element_id)
{
    //alert("in aljs_show_hide_button_toggle, element_id = [" + element_id + "]\n"
        //+ "element style.display = [" + al_get_object(element_id).style.display + "]\n"
    //);

    if(al_get_object(element_id).style.display == 'none')
    {
        //al_get_object(element_id).style.display = 'block';
        al_get_object(element_id).style.display = '';
    }
    else
    {
        al_get_object(element_id).style.display = 'none';
    }
}

//
// function aljs_show_hide_array_toggle()
//
// params:  element_id_array        = an argument to tell the array to change to display or hide
//
// description:   iterate through an array of ID's and toggle their values to hide/show them
//
function aljs_show_hide_array_toggle(element_id_array)
{

    //alert("ENTRY-aljs_show_hide_array_toggle");

    if(element_id_array != null)
    {
                            // loop through the array and call the
                            // function that toggles the item for
                            // every item

        for(ii = 0; ii < element_id_array.length; ii++)
        {
            element_id = element_id_array[ii];
            //alert("toggle element=[" + element_id + "]");

            aljs_show_hide_button_toggle(element_id);
        }

    }
    //alert("EXIT-aljs_show_hide_array_toggle");

}

function aljs_show_hide_button_hide(element_id)
{
    //alert("in aljs_show_hide_button_hide, element_id = [" + element_id + "]\n");

    al_get_object(element_id).style.display = 'none';
}


function aljs_show_hide_button_show(element_id)
{
    //alert("in aljs_show_hide_button_show, element_id = [" + element_id + "]\n");

                         // according to forums online, setting to "" is more functional in FF, and works in IE
                         // FF will cause an element to drift into other cells on the "block" type.
    //al_get_object(element_id).style.display = 'block';
    al_get_object(element_id).style.display = '';
}



function aljs_show_hide_button_hide_tabs(tab_id)
{
    //alert("in aljs_show_hide_button_hide_tab, tab_id = [" + tab_id + "]\n");

    for(var current_tab_index in tab_id.tab_array)
    {
        //alert("current_tab_index = [" + current_tab_index + "]");
        al_get_object(current_tab_index).className = tab_id.tab_array[current_tab_index].inactive_style;



        current_tab_content_id = tab_id.tab_array[current_tab_index].tab_content_id;

        //alert("current_tab_content_id = [" + current_tab_content_id + "]");

        current_tab_content = al_get_object(current_tab_content_id);

        //alert("hide 1");
        if(current_tab_content != null)
        {
                    current_tab_content.style.display = "none";
        }       
        //alert("hide 2");
    }

}


function aljs_show_hide_button_show_tabs(tab_id)
{
    //alert("in aljs_show_hide_button_show_tab, tab_id = [" + tab_id + "]\n");

    for(var current_tab_index in tab_id.tab_array)
    {
        //alert("current_tab_index = [" + current_tab_index + "]");
        al_get_object(current_tab_index).className = tab_id.tab_array[current_tab_index].active_style;



        current_tab_content_id = tab_id.tab_array[current_tab_index].tab_content_id;

        //alert("current_tab_content_id = [" + current_tab_content_id + "]");

        current_tab_content = al_get_object(current_tab_content_id);

        //alert("show 1");
        if(current_tab_content != null)
        {
                         // according to forums online, setting to "" is more functional in FF, and works in IE
                         // FF will cause an element to drift into other cells on the "block" type.
            //current_tab_content.style.display = "block";
            current_tab_content.style.display = "";
        }
        //alert("show 2");
    }
}

function aljs_show_hide_button_toggle_tabs(tab_id)
{
    //alert("in aljs_show_hide_button_hide_tab, tab_id = [" + tab_id + "]\n");

    for(var current_tab_index in tab_id.tab_array)
    {
        //alert("current_tab_index = [" + current_tab_index + "]");

        current_tab_content_id = tab_id.tab_array[current_tab_index].tab_content_id;

        //alert("current_tab_content_id = [" + current_tab_content_id + "]");

        current_tab_content = al_get_object(current_tab_content_id);

        if(current_tab_content != null)
        {

            if(current_tab_content.style.display == 'none')
            {
                al_get_object(current_tab_index).className = tab_id.tab_array[current_tab_index].active_style;
                //current_tab_content.style.display = 'block';
                current_tab_content.style.display = '';
            }
            else
            {
                al_get_object(current_tab_index).className = tab_id.tab_array[current_tab_index].inactive_style;
                current_tab_content.style.display = 'none';
            }
        }
    }

}



//
// aljs_absolute_id_show_hide_button_toggle
// aljs_absolute_id_show_hide_button_hide
// aljs_absolute_id_show_hide_button_show
//
// These functions get an array of element id's stored on the page that correspond
// to an absolute id entered in the form language, and hide/show/toggle each
// of the elements in the array based on which function was called
//


function aljs_absolute_id_show_hide_button_toggle(absolute_id)
{
    var element_array;
    var ii;
    var element_id;


                            // get the array of elements

    element_array = eval("absolute_id_array." + absolute_id);


    if(element_array != null)
    {
                            // loop through the array and call the
                            // function that toggles the item for
                            // every item

        for(ii = 0; ii < element_array.length; ii++)
        {
            element_id = element_array[ii];

            aljs_show_hide_button_toggle(element_id);
        }

    }
}


function aljs_absolute_id_show_hide_button_hide(absolute_id)
{
    var element_array; 
    var ii;
    var element_id;


                            // get the array of elements

    element_array = eval("absolute_id_array." + absolute_id);


    if(element_array != null)
    {
                            // loop through the array and call the
                            // function that toggles the item for
                            // every item

        for(ii = 0; ii < element_array.length; ii++)
        {
            element_id = element_array[ii];

            aljs_show_hide_button_hide(element_id);
        }

    }
}


function aljs_absolute_id_show_hide_button_show(absolute_id)
{
    var element_array;
    var ii;
    var element_id;


                            // get the array of elements

    element_array = eval("absolute_id_array." + absolute_id);


    if(element_array != null)
    {
                            // loop through the array and call the
                            // function that toggles the item for
                            // every item

        for(ii = 0; ii < element_array.length; ii++)
        {
            element_id = element_array[ii];

            aljs_show_hide_button_show(element_id);
        }

    }
}



// function aljs_toggle_slidebar_lock_state

function aljs_toggle_slidebar_lock_state()
{
    if(al_get_object('slidebar_lock_state') == null)
    {
        return;        // if its not on the page, dont do anything with it
    }
    var lock_state_hidden = al_get_object('slidebar_lock_state');
    
    if(lock_state_hidden.value == 'locked')
    {
                                // change the state

        lock_state_hidden.value = 'unlocked';

                                // change the lock image

        al_get_object('slidebar_open_lock_image').style.display = 'block';
        al_get_object('slidebar_closed_lock_image').style.display = 'none';
    }
    else
    {
                                // change the state

        lock_state_hidden.value = 'locked';

                                // change the lock image

        al_get_object('slidebar_open_lock_image').style.display = 'none';
        al_get_object('slidebar_closed_lock_image').style.display = 'block';
    }
}

                                // updates the recent activity links display on the slidebar


function aljs_update_recent_activity()
{
    var div_selected = al_get_object('recent_activity_clist').value;

                                // hide all the divs, then display the one that needs to be displayed

    al_get_object('div_new_records').style.display = 'none';
    al_get_object('div_mod_records').style.display = 'none';
    al_get_object('div_new_mod_records').style.display = 'none';
    al_get_object('div_displayed_records').style.display = 'none';
    al_get_object('div_report').style.display = 'none';
    al_get_object('div_query').style.display = 'none';
    al_get_object('div_all_records').style.display = 'none';


    al_get_object(div_selected).style.display = 'block';


    al_get_object('slidebar_recent_down').style.display = 'block';
    al_get_object('slidebar_recent_right').style.display = 'none';
}


function aljs_hide_recent_activity()
{
                                // hide all the divs

    al_get_object('div_new_records').style.display = 'none';
    al_get_object('div_mod_records').style.display = 'none';
    al_get_object('div_new_mod_records').style.display = 'none';
    al_get_object('div_displayed_records').style.display = 'none';
    al_get_object('div_report').style.display = 'none';
    al_get_object('div_query').style.display = 'none';
    al_get_object('div_all_records').style.display = 'none';


    al_get_object('slidebar_recent_right').style.display = 'block';
    al_get_object('slidebar_recent_down').style.display = 'none';
}



                // this function may get called twice in a row because we usually put the call in 
                // the onchange attribute and the onkeyup attribute

                    // display the revert button for this class and instance
function aljs_display_revert_button(event, class_name, instance_id)
{
    var element_count;
    var element_name;
    var revert_button_id;
    var ii;
    var add_flag = true;
    var changed_flag = false;
    var idx;
    var event_source;

    if(array_Elements == null)
    {
        alert("Please wait for the form to completely load before making changes");
        return;
    }
    

    // this was for testing // al_get_content_form();

    revert_button_id = 'button_revert_' + class_name + '_' + instance_id;

    //alert('You have changed a CLASS!');
    //alert('revert button is ' + document.all[revert_button_id]);

    //alert("entering aljs_display_revert_button, class_name = [" + class_name + "] instance_id = [" + instance_id + "]");


    if(al_get_object(revert_button_id) != null)
    {
        //al_get_object(revert_button_id).style.visibility='visible';
        al_get_object(revert_button_id).style.display='inline';
        //al_get_object(revert_button_id).style.display='block';
    }


    //alert("arr elem = " + array_Elements);
    //alert("arr elem count = " + array_Elements.length);

    //var everything;

    // determine if there is any change of the fields for this class
    // and if there is not - take the undo button off
    for(ii=0;ii<array_Elements.length;ii++)        // for each element on the page saved
    {

        
        var  element_id = array_Elements[ii]['id'];
        //alert('element_id = ' + element_id);

        if(array_Elements[ii]['class'] == class_name 
            && array_Elements[ii]['instance'] == instance_id
            && array_Elements[ii]['type'] != 'hidden')
        {
            idx = array_Elements[ii]['element_index'];


            //everything += "aE.val=[" + array_Elements[ii]['value'] + "] elem.val=[" + array_Elements[ii]['node'].value + "]\n";

            if(array_Elements[ii]['type'] == 'radio')
            {
                //alert("here in type = radio\n" 
                        //+ "arrayElements[ii] = [" + array_Elements[ii] + "]" );

                if(array_Elements[ii]['checked'] != array_Elements[ii]['node'].checked)
                {
                    changed_flag = true;
                }
            }
            else if(array_Elements[ii]['type'] == 'checkbox')
            {
                //alert('found checkbox element');
                if(array_Elements[ii]['checked'] != array_Elements[ii]['node'].checked)
                {
                    changed_flag = true;
                }
            }
            else if(array_Elements[ii]['value'] != array_Elements[ii]['node'].value)
            {
                changed_flag = true;
            }
            else
            {
                // do nothing.  The first default is false, but it does not need to be reset
            }

        }
    }
    //alert("everything = " + everything);


                                            // if there's a delete checkbox on the page,
                                            // uncheck it since we just changed a field


    var delete_checkbox_id = "delete_checkbox|" + instance_id + "|0";

    var delete_checkbox_element = al_get_object(delete_checkbox_id);

    if(delete_checkbox_element != null)
    {
        //alert("unchecking delete checkbox");
        delete_checkbox_element.checked = false;
    }




    if(changed_flag == false)
    {
        //alert("undoing change automatically");
        aljs_revert_button_execute(class_name, instance_id);
        return(1);
    }

    // search for the Key Field for this class (KEYVALUE field is recnum)
    for(ii=0;ii<array_Elements.length;ii++)        // for each element on the page saved
    {
                                                // if the element is the same class and 
                                                // instance and field name
        if(array_Elements[ii]['class'] == class_name 
            && array_Elements[ii]['instance'] == instance_id
            && array_Elements[ii]['field_type'] == 'KEYVALUE')
        {    
            if(array_Elements[ii]['value'] != ''
            && array_Elements[ii]['value'] != '0')
            {
                add_flag = false;                // if the value exists, need to update record
            }
            break;
        }                                        // else the value doesn't exist, add the record
    }    

    //alert('add_flag=' + add_flag);

    var element_names;

    // then change the value of the add change delete flag to either
    // Add or Change
    for(ii=0;ii<array_Elements.length;ii++)        // for each element on the page saved
    {
                                                // if the element is the same class and 
                                                // instance and field name
        //if(array_Elements[ii]['class'] == class_name 
        //    && array_Elements[ii]['instance'] == instance_id)
        //{
        //    alert('field name=' + array_Elements[ii]['field']);
        //}
        //element_names += array_Elements[ii]['class'] + "\n";

                                                // if the element is the addChangeDelete_flag
                                                // and the flag is hidden, and not a choice
                                                // on the page, then reset its value to 
                                                // Change or Add, depending on the add_flag
        if(array_Elements[ii]['class'] == class_name
            && array_Elements[ii]['instance'] == instance_id
            && array_Elements[ii]['field'] == 'addChangeDelete_flag'
            && array_Elements[ii]['type'] == 'hidden')
        {
                                                // then change the value to either add
                                                // or change the record
            idx = array_Elements[ii]['element_index'];
            //alert('changing value of ACD flag');
            if(add_flag == false)
            {
                array_Elements[ii]['node'].value = 'Change';
                //alert('changing value of ACD flag to Change');
            }
            else
            {
                array_Elements[ii]['node'].value = 'Add';
                //alert('changing value of ACD flag to Add');
            }

            //alert("New Value = " + array_Elements[ii]['node'].value);
            //alert("For Name  = " + array_Elements[ii]['node'].name);
            //break;
        }
    }    
    //alert("element names = " + element_names);

//    alert("event = [" + event + "]");
//    alert("event = [" + event + "]"
//        + "\nevent.target = [" + event.target + "]"
//        + "\nevent.srcElement = [" + event.srcElement + "]");


    if(event == null)        // in the case that the event is null (a change from another form/page like
    {                        // the popup search page). then there is no way to change multiple fields!
        return;
    }

                                           // we may put the same field on the page more than once,
                                           // if we do, we need to change all of the occurrences to the
                                           // same as the one that we just changed

    var event_target;

    if(browser.isIE == true)
    {
        event_target = event.srcElement;
    }
    else
    {
        event_target = event.target;
    }

    var target_value = event_target.value;
    var target_name  = event_target.name;

//    alert("target_value = [" + target_value
//        + "]\ntarget_name = [" + target_name
//        + "]\nevent_target = [" + event_target + "]");



    for(ii = 0; ii < array_Elements.length;  ii++)
    {
//        alert("target_name = " + target_name
//              +"\narray_Elements[ii]['node'].name = " + array_Elements[ii]['node'].name
//              +"\narray_Elements[ii]['name']= " + array_Elements[ii]['name'] );
                                                // if we're at another node that's the same as the one that changed,
                                                // but is not the changed one
        if(array_Elements[ii]['node'].name == target_name
           && array_Elements[ii]['node'] != event_target)
        {
            //alert("got a match, changing value, array_Elements[" + ii + "] = [" + array_Elements[ii].field + "]");
                                                // change the value

            //array_Elements[ii].value = target_value;


            if( array_Elements[ii]['node'].type == 'checkbox')
            {
                //alert('radio to reset = ' + ii);
                array_Elements[ii]['node'].value = '' + target_value;
                array_Elements[ii]['node'].checked = event_target.checked;
            }
            else if(array_Elements[ii]['node'].type == 'radio')
            {
                                    // do nothing because if we change one radio button, 
                                    // we don't want to set the other ones with the same name
                                    // back, because setting one to true unsets another

                //alert("this is a radio button, so we don't want to update this value");
            }
            else
            {

                array_Elements[ii]['node'].value = '' + target_value;

                                // whenever the value of a select box is changed,
                                // then trigger the onchange event for that
                                // object

                if(array_Elements[ii]['node'].type == 'select-one')
                {
                    var field_name = array_Elements[ii]['node'].getAttribute('name');

                    //al_get_object(field_name).onchange();
                    cl_load_list(array_Elements[ii]['node'].name);
                }
            }

        }
        else if(array_Elements[ii]['node'].name == target_name)
        {
            //alert("current node = [" + ii + "]");
        }
    }

}

function aljs_revert_button_execute(class_name, instance_id)
{
    var revert_button_id;

    revert_button_id = 'button_revert_' + class_name + '_' + instance_id;
    //alert('in aljs_revert_button_execute, class_name = [' + class_name + '], instance_id = [' + instance_id + ']');

                                    // if there is no button, do not attempt this function
    if(browser.isNS)
    {
        if(!document.getElementById(revert_button_id))
        {
            return(1);
        }
    }
    else
    {
        if(!document.all[revert_button_id])
        {
            return(1);
        }
    }

                                            // if there's a delete checkbox on the page,
                                            // uncheck it since we just changed a field


    var delete_checkbox_id = "delete_checkbox|" + instance_id + "|0";

    var delete_checkbox_element = al_get_object(delete_checkbox_id);

    if(delete_checkbox_element != null)
    {
        //alert("unchecking delete checkbox");
        delete_checkbox_element.checked = false;
    }

                                    // reset all the variables to their original
                                    // values or checked status's
    aljs_revert_form_element_objects(class_name, instance_id);

                                    // reset the button to hidden
    //al_get_object(revert_button_id).style.visibility='hidden';
    al_get_object(revert_button_id).style.display='none';


    return(1);
}



function aljs_handle_delete_checkbox_check(class_name, instance_id)
{

    var delete_checkbox_id;
    var delete_checkbox_element;
    var delete_checkbox_checked;
    var acd_flag_id;
    var acd_flag_element;



                                        // figure out the value of the checkbox

    delete_checkbox_id = "delete_checkbox|" + instance_id + "|0";

    delete_checkbox_element = al_get_object(delete_checkbox_id);

    delete_checkbox_checked =  delete_checkbox_element.checked;

    //alert("delete_checkbox id = [" + delete_checkbox_id + "], checked = [" + delete_checkbox_checked + "]");

                                        // get a reference to the addChangeDelete_flag hidden

    acd_flag_id = "ZZOBJ|" + class_name + "|" + instance_id + "|FIELD|addChangeDelete_flag"

    acd_flag_element = al_get_object(acd_flag_id);


    //alert("addChangeDelete_flag id = [" + acd_flag_id + "], element = [" + acd_flag_element + "]");


                                    // if the checkbox is checked

    if(delete_checkbox_checked == true)
    {
                                    // set the addChangeDelete flag to delete
        //alert("item is checked");
        
        acd_flag_element.value = "Delete";


    }
    else                            // otherwise
    {
        //alert("item is not checked");
                                    // run the the function that displays the undo button,
                                    // it will check what the addChangeDelete_flag has to
                                    // be set to, and set it properly

        aljs_display_revert_button(null, class_name, instance_id);
    }

    //alert("acd_value just before exit = [" + acd_flag_element.value + "]");



}



function aljs_richtext_onchange(instance)
{
    //alert("in aljs_richtext_onchange");
    //alert("instance = [" + instance + "]");
    var element_name;
    var element_name_parts;
    var class_name;
    var instance_id;

    var debug_string = "";

    //for(attribute in instance)
    //{
        //debug_string += "attribute [" + attribute + "] did not match\n";
    //}
    
    //alert(debug_string);

    //alert(
        //"attribute targetElement = [" + instance["targetElement"] + "]\n"
        //+"attribute targetElement.name = [" + instance["targetElement"].name + "]\n"
        //+"attribute targetElement.id = [" + instance["targetElement"].id + "]\n"
        //+"attribute formElement = [" + instance["formElement"] + "]\n"
        //+"attribute formElement.name = [" + instance["formElement"].name + "]\n"
        //+"attribute formElement.id = [" + instance["formElement"].id + "]\n"
        //+"attribute iframeElement = [" + instance["iframeElement"] + "]\n"
        //+"attribute editorId = [" + instance["editorId"] + "]\n"
    //);


    //alert("calling tinyMCE.triggerSave()");

    tinyMCE.triggerSave();

    //alert("calling tinyMCE.triggerNodeChange()");

    tinyMCE.triggerNodeChange();



    element_name = instance["formElement"].name;
    element_name_parts = element_name.split('|');

    
    class_name = element_name_parts[1];
    instance_id = element_name_parts[2];

    //alert("class_name = [" + class_name + "]\ninstance_id = [" + instance_id + "]\n");



    aljs_display_revert_button(null, class_name, instance_id);

}


// This function is called to keep multiple instances of the same field on the page in sync 
// with each other

// we may put the same field on the page more than once,
// if we do, we need to change all of the occurrences to the
// same as the one that we just changed

function sync_identical_fields(event)
{

                                    // if the onchange() is called as a method from another javascript,
                                    // then it will not pass the event (not sure at this point how to get
                                    // around that).  So if there is no event, there is nothing to do
                                    // in this function.
    if(event == null)
    {
        return;
    }
    var event_target;

    if(browser.isIE == true)
    {
        event_target = event.srcElement;
    }
    else
    {
        event_target = event.target;
    }

    var target_value = event_target.value;
    var target_name  = event_target.name;

//    alert("target_value = [" + target_value
//        + "]\ntarget_name = [" + target_name
//        + "]\nevent_target = [" + event_target + "]");


    if(array_Elements == null)
    {
        alert("Please wait for the form to completely load before making changes");
        return;
    }

    for(ii = 0; ii < array_Elements.length;  ii++)
    {
//        alert("target_name = " + target_name
//              +"\narray_Elements[ii]['node'].name = " + array_Elements[ii]['node'].name
//              +"\narray_Elements[ii]['name']= " + array_Elements[ii]['name'] );
                                                // if we're at another node that's the same as the one that changed,
                                                // but is not the changed one
        if(array_Elements[ii]['node'].name == target_name
           && array_Elements[ii]['node'] != event_target)
        {
            //alert("got a match, changing value, array_Elements[" + ii + "] = [" + array_Elements[ii].field + "]");
                                                // change the value

            //array_Elements[ii].value = target_value;


            if( array_Elements[ii]['node'].type == 'checkbox')
            {
                //alert('radio to reset = ' + ii);
                array_Elements[ii]['node'].value = '' + target_value;
                array_Elements[ii]['node'].checked = event_target.checked;
            }
            else if(array_Elements[ii]['node'].type == 'radio')
            {
                                    // do nothing because if we change one radio button, 
                                    // we don't want to set the other ones with the same name
                                    // back, because setting one to true unsets another

                //alert("this is a radio button, so we don't want to update this value");
            }
            else
            {

                array_Elements[ii]['node'].value = '' + target_value;

                                // whenever the value of a select box is changed,
                                // then trigger the onchange event for that
                                // object

                if(array_Elements[ii]['node'].type == 'select-one')
                {
                    var field_name = array_Elements[ii]['node'].getAttribute('name');

                    //al_get_object(field_name).onchange();
                    cl_load_list(array_Elements[ii]['node'].name);
                }
            }

        }
        else if(array_Elements[ii]['node'].name == target_name)
        {
            //alert("current node = [" + ii + "]");
        }
    }
}















function aljs_test()
{
    alert('test');
}


//*****************************************************************************
// Do not remove this notice.
//
// Copyright 2001 by Mike Hall.
// See http://www.brainjar.com for terms of use.
//*****************************************************************************

// Determine browser and version.

function Browser() {

  var ua, s, i;

  this.isIE    = false;  // Internet Explorer
  this.isNS    = false;  // Netscape
  this.version = null;

  ua = navigator.userAgent;

  s = "MSIE";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isIE = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  s = "Netscape6/";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = parseFloat(ua.substr(i + s.length));
    return;
  }

  // Treat any other "Gecko" browser as NS 6.1.

  s = "Gecko";
  if ((i = ua.indexOf(s)) >= 0) {
    this.isNS = true;
    this.version = 6.1;
    return;
  }
}

var browser = new Browser();

//=============================================================================
// Window Object
//=============================================================================

function Window(el) {

  var i, mapList, mapName;

  // Get window components.

  this.frame           = el;
  this.titleBar        = winFindByClassName(el, "titleBar");
  this.titleBarText    = winFindByClassName(el, "titleBarText");
  this.titleBarButtons = winFindByClassName(el, "titleBarButtons");
  this.clientArea      = winFindByClassName(el, "clientArea");

  // Find matching button image map.

  mapName = this.titleBarButtons.useMap.substr(1);
  mapList = document.getElementsByTagName("MAP");
  for (i = 0; i < mapList.length; i++)
    if (mapList[i].name == mapName)
      this.titleBarMap = mapList[i];

  // Save colors.

  this.activeFrameBackgroundColor  = this.frame.style.backgroundColor;
  this.activeFrameBorderColor      = this.frame.style.borderColor;
  this.activeTitleBarColor         = this.titleBar.style.backgroundColor;
  this.activeTitleTextColor        = this.titleBar.style.color;
  this.activeClientAreaBorderColor = this.clientArea.style.borderColor;
  if (browser.isIE)
    this.activeClientAreaScrollbarColor = this.clientArea.style.scrollbarBaseColor;

  // Save images.

  this.activeButtonsImage   = this.titleBarButtons.src;
  this.inactiveButtonsImage = this.titleBarButtons.getAttribute("lowsrc");

  // Set flags.

  this.isOpen      = false;
  this.isMinimized = false;

  // Set methods.

  this.open       = winOpen;
  this.close      = winClose;
  this.minimize   = winMinimize;
  this.restore    = winRestore;
  this.makeActive = winMakeActive;

  // Set up event handling.

  this.frame.parentWindow = this;
  this.frame.onmousemove  = winResizeCursorSet;
  this.frame.onmouseout   = winResizeCursorRestore;
  this.frame.onmousedown  = winResizeDragStart;

  this.titleBar.parentWindow = this;
  this.titleBar.onmousedown  = winMoveDragStart;

  this.clientArea.parentWindow = this;
  this.clientArea.onclick      = winClientAreaClick;

  for (i = 0; i < this.titleBarMap.childNodes.length; i++)
    if (this.titleBarMap.childNodes[i].tagName == "AREA")
      this.titleBarMap.childNodes[i].parentWindow = this;

  // Calculate the minimum width and height values for resizing
  // and fix any initial display problems.

  var initLt, initWd, w, dw;

  // Save the inital frame width and position, then reposition
  // the window.

  initLt = this.frame.style.left;
  initWd = parseInt(this.frame.style.width);
  this.frame.style.left = -this.titleBarText.offsetWidth + "px";

  // For IE, start calculating the value to use when setting
  // the client area width based on the frame width.

  if (browser.isIE) {
    this.titleBarText.style.display = "none";
    w = this.clientArea.offsetWidth;
    this.widthDiff = this.frame.offsetWidth - w;
    this.clientArea.style.width = w + "px";
    dw = this.clientArea.offsetWidth - w;
    w -= dw;     
    this.widthDiff += dw;
    this.titleBarText.style.display = "";
  }

  // Find the difference between the frame's style and offset
  // widths. For IE, adjust the client area/frame width
  // difference accordingly.

  w = this.frame.offsetWidth;
  this.frame.style.width = w + "px";
  dw = this.frame.offsetWidth - w;
  w -= dw;     
  this.frame.style.width = w + "px";
  if (browser.isIE)
    this.widthDiff -= dw;

  // Find the minimum width for resize.

  this.isOpen = true;  // Flag as open so minimize call will work.
  this.minimize();
  this.minimumWidth = this.frame.offsetWidth - dw;

  // Find the frame width at which or below the title bar text will
  // need to be clipped.

  this.titleBarText.style.width = "";
  this.clipTextMinimumWidth = this.frame.offsetWidth - dw;

  // Set the minimum height.

  this.minimumHeight = 1;

  // Restore window. For IE, set client area width.

  this.restore();
  this.isOpen = false;  // Reset flag.
  initWd = Math.max(initWd, this.minimumWidth);
  this.frame.style.width = initWd + "px";
  if (browser.isIE)
    this.clientArea.style.width = (initWd - this.widthDiff) + "px";

  // Clip the title bar text if needed.

  if (this.clipTextMinimumWidth >= this.minimumWidth)
    this.titleBarText.style.width = (winCtrl.minimizedTextWidth + initWd - this.minimumWidth) + "px";

  // Restore the window to its original position.

  this.frame.style.left = initLt;
}

//=============================================================================
// Window Methods
//=============================================================================

function winOpen() {

  if (this.isOpen)
    return;

  // Restore the window and make it visible.

  this.makeActive();
  this.isOpen = true;
  if (this.isMinimized)
    this.restore();
  this.frame.style.visibility = "visible";
}

function winClose() {

  // Hide the window.

  this.frame.style.visibility = "hidden";
  this.isOpen = false;
}

function winMinimize() {

  if (!this.isOpen || this.isMinimized)
    return;

  this.makeActive();

  // Save current frame and title bar text widths.

  this.restoreFrameWidth = this.frame.style.width;
  this.restoreTextWidth = this.titleBarText.style.width;

  // Disable client area display.

  this.clientArea.style.display = "none";

  // Minimize frame and title bar text widths.

  if (this.minimumWidth)
    this.frame.style.width = this.minimumWidth + "px";
  else
    this.frame.style.width = "";
  this.titleBarText.style.width = winCtrl.minimizedTextWidth + "px";

  this.isMinimized = true;
}

function winRestore() {

  if (!this.isOpen || !this.isMinimized)
    return;

  this.makeActive();

  // Enable client area display.

  this.clientArea.style.display = "";

  // Restore frame and title bar text widths.

  this.frame.style.width = this.restoreFrameWidth;
  this.titleBarText.style.width = this.restoreTextWidth;

  this.isMinimized = false;
}

function winMakeActive() {

  if (winCtrl.active == this)
    return;

  // Inactivate the currently active window.

  if (winCtrl.active) {
    winCtrl.active.frame.style.backgroundColor    = winCtrl.inactiveFrameBackgroundColor;
    winCtrl.active.frame.style.borderColor        = winCtrl.inactiveFrameBorderColor;
    winCtrl.active.titleBar.style.backgroundColor = winCtrl.inactiveTitleBarColor;
    winCtrl.active.titleBar.style.color           = winCtrl.inactiveTitleTextColor;
    winCtrl.active.clientArea.style.borderColor   = winCtrl.inactiveClientAreaBorderColor;
    if (browser.isIE)
      winCtrl.active.clientArea.style.scrollbarBaseColor = winCtrl.inactiveClientAreaScrollbarColor;
    if (browser.isNS && browser.version < 6.1)
      winCtrl.active.clientArea.style.overflow = "hidden";
    if (winCtrl.active.inactiveButtonsImage)
      winCtrl.active.titleBarButtons.src = winCtrl.active.inactiveButtonsImage;
  }

  // Activate this window.

  this.frame.style.backgroundColor    = this.activeFrameBackgroundColor;
  this.frame.style.borderColor        = this.activeFrameBorderColor;
  this.titleBar.style.backgroundColor = this.activeTitleBarColor;
  this.titleBar.style.color           = this.activeTitleTextColor;
  this.clientArea.style.borderColor   = this.activeClientAreaBorderColor;
  if (browser.isIE)
    this.clientArea.style.scrollbarBaseColor = this.activeClientAreaScrollbarColor;
  if (browser.isNS && browser.version < 6.1)
    this.clientArea.style.overflow = "auto";
  if (this.inactiveButtonsImage)
    this.titleBarButtons.src = this.activeButtonsImage;
  this.frame.style.zIndex = ++winCtrl.maxzIndex;
  winCtrl.active = this;
}

//=============================================================================
// Event handlers.
//=============================================================================

function winClientAreaClick(event) {

  // Make this window the active one.

  this.parentWindow.makeActive();
}

//-----------------------------------------------------------------------------
// Window dragging.
//-----------------------------------------------------------------------------

function winMoveDragStart(event) {

  var target;
  var x, y;

  if (browser.isIE)
    target = window.event.srcElement.tagName;
  if (browser.isNS)
    target = event.target.tagName;

  if (target == "AREA")
    return;

  this.parentWindow.makeActive();

  // Get cursor offset from window frame.

  if (browser.isIE) {
    x = window.event.x;
    y = window.event.y;
  }
  if (browser.isNS) {
    x = event.pageX;
    y = event.pageY;
  }
  winCtrl.xOffset = winCtrl.active.frame.offsetLeft - x;
  winCtrl.yOffset = winCtrl.active.frame.offsetTop  - y;

  // Set document to capture mousemove and mouseup events.

  if (browser.isIE) {
    document.onmousemove = winMoveDragGo;
    document.onmouseup   = winMoveDragStop;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", winMoveDragGo,   true);
    document.addEventListener("mouseup",   winMoveDragStop, true);
    event.preventDefault();
  }

  winCtrl.inMoveDrag = true;
}

function winMoveDragGo(event) {

  var x, y;

  if (!winCtrl.inMoveDrag)
    return;

  // Get cursor position.

  if (browser.isIE) {
    x = window.event.x;
    y = window.event.y;
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS) {
    x = event.pageX;
    y = event.pageY;
    event.preventDefault();
  }

  // Move window frame based on offset from cursor.

  winCtrl.active.frame.style.left = (x + winCtrl.xOffset) + "px";
  winCtrl.active.frame.style.top  = (y + winCtrl.yOffset) + "px";
}

function winMoveDragStop(event) {

  winCtrl.inMoveDrag = false;

  // Remove mousemove and mouseup event captures on document.

  if (browser.isIE) {
    document.onmousemove = null;
    document.onmouseup   = null;
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", winMoveDragGo,   true);
    document.removeEventListener("mouseup",   winMoveDragStop, true);
  }
}

//-----------------------------------------------------------------------------
// Window resizing.
//-----------------------------------------------------------------------------

function winResizeCursorSet(event) {

  var target;
  var xOff, yOff;

  if (this.parentWindow.isMinimized || winCtrl.inResizeDrag)
    return;

  // If not on window frame, restore cursor and exit.

  if (browser.isIE)
    target = window.event.srcElement;
  if (browser.isNS)
    target = event.target;
  if (target != this.parentWindow.frame)
    return;

  // Find resize direction.

  if (browser.isIE) {
    xOff = window.event.offsetX;
    yOff = window.event.offsetY;
  }
  if (browser.isNS) {
    xOff = event.layerX;
    yOff = event.layerY;
  }
  winCtrl.resizeDirection = ""
  if (yOff <= winCtrl.resizeCornerSize)
    winCtrl.resizeDirection += "n";
  else if (yOff >= this.parentWindow.frame.offsetHeight - winCtrl.resizeCornerSize)
    winCtrl.resizeDirection += "s";
  if (xOff <= winCtrl.resizeCornerSize)
    winCtrl.resizeDirection += "w";
  else if (xOff >= this.parentWindow.frame.offsetWidth - winCtrl.resizeCornerSize)
    winCtrl.resizeDirection += "e";

  // If not on window edge, restore cursor and exit.

  if (winCtrl.resizeDirection == "") {
    this.onmouseout(event);
    return;
  }

  // Change cursor.

  if (browser.isIE)
    document.body.style.cursor = winCtrl.resizeDirection + "-resize";
  if (browser.isNS)
    this.parentWindow.frame.style.cursor = winCtrl.resizeDirection + "-resize";
}

function winResizeCursorRestore(event) {

  if (winCtrl.inResizeDrag)
    return;

  // Restore cursor.

  if (browser.isIE)
    document.body.style.cursor = "";
  if (browser.isNS)
    this.parentWindow.frame.style.cursor = "";
}

function winResizeDragStart(event) {

  var target;

  // Make sure the event is on the window frame.

  if (browser.isIE)
    target = window.event.srcElement;
  if (browser.isNS)
    target = event.target;
  if (target != this.parentWindow.frame)
    return;

  this.parentWindow.makeActive();

  if (this.parentWindow.isMinimized)
    return;

  // Save cursor position.

  if (browser.isIE) {
    winCtrl.xPosition = window.event.x;
    winCtrl.yPosition = window.event.y;
  }
  if (browser.isNS) {
    winCtrl.xPosition = event.pageX;
    winCtrl.yPosition = event.pageY;
  }

  // Save window frame position and current window size.

  winCtrl.oldLeft   = parseInt(this.parentWindow.frame.style.left,  10);
  winCtrl.oldTop    = parseInt(this.parentWindow.frame.style.top,   10);
  winCtrl.oldWidth  = parseInt(this.parentWindow.frame.style.width, 10);
  winCtrl.oldHeight = parseInt(this.parentWindow.clientArea.style.height, 10);

  // Set document to capture mousemove and mouseup events.

  if (browser.isIE) {
    document.onmousemove = winResizeDragGo;
    document.onmouseup   = winResizeDragStop;
  }
  if (browser.isNS) {
    document.addEventListener("mousemove", winResizeDragGo,   true);
    document.addEventListener("mouseup"  , winResizeDragStop, true);
    event.preventDefault();
  }

  winCtrl.inResizeDrag = true;
}

function winResizeDragGo(event) {

 var north, south, east, west;
 var dx, dy;
 var w, h;

  if (!winCtrl.inResizeDrag)
    return;

  // Set direction flags based on original resize direction.

  north = false;
  south = false;
  east  = false;
  west  = false;
  if (winCtrl.resizeDirection.charAt(0) == "n")
    north = true;
  if (winCtrl.resizeDirection.charAt(0) == "s")
    south = true;
  if (winCtrl.resizeDirection.charAt(0) == "e" || winCtrl.resizeDirection.charAt(1) == "e")
    east = true;
  if (winCtrl.resizeDirection.charAt(0) == "w" || winCtrl.resizeDirection.charAt(1) == "w")
    west = true;

  // Find change in cursor position.

  if (browser.isIE) {
    dx = window.event.x - winCtrl.xPosition;
    dy = window.event.y - winCtrl.yPosition;
  }
  if (browser.isNS) {
    dx = event.pageX - winCtrl.xPosition;
    dy = event.pageY - winCtrl.yPosition;
  }

  // If resizing north or west, reverse corresponding amount.

  if (west)
    dx = -dx;
  if (north)
    dy = -dy;

  // Check new size.

  w = winCtrl.oldWidth  + dx;
  h = winCtrl.oldHeight + dy;
  if (w <= winCtrl.active.minimumWidth) {
    w = winCtrl.active.minimumWidth;
    dx = w - winCtrl.oldWidth;
  }
  if (h <= winCtrl.active.minimumHeight) {
    h = winCtrl.active.minimumHeight;
    dy = h - winCtrl.oldHeight;
  }

  // Resize the window. For IE, keep client area and frame widths in synch.

  if (east || west) {
    winCtrl.active.frame.style.width = w + "px";
    if (browser.isIE)
      winCtrl.active.clientArea.style.width = (w - winCtrl.active.widthDiff) + "px";
  }
  if (north || south)
    winCtrl.active.clientArea.style.height = h + "px";

  // Clip the title bar text, if necessary.

  if (east || west) {
    if (w < winCtrl.active.clipTextMinimumWidth)
      winCtrl.active.titleBarText.style.width = (winCtrl.minimizedTextWidth + w - winCtrl.active.minimumWidth) + "px";
    else
      winCtrl.active.titleBarText.style.width = "";
  }

  // For a north or west resize, move the window.

  if (west)
    winCtrl.active.frame.style.left = (winCtrl.oldLeft - dx) + "px";
  if (north)
    winCtrl.active.frame.style.top  = (winCtrl.oldTop  - dy) + "px";

  if (browser.isIE) {
    window.event.cancelBubble = true;
    window.event.returnValue = false;
  }
  if (browser.isNS)
    event.preventDefault();
}

function winResizeDragStop(event) {

  winCtrl.inResizeDrag = false;

  // Remove mousemove and mouseup event captures on document.

  if (browser.isIE) {
    document.onmousemove = null;
    document.onmouseup   = null;
  }
  if (browser.isNS) {
    document.removeEventListener("mousemove", winResizeDragGo,   true);
    document.removeEventListener("mouseup"  , winResizeDragStop, true);
  }
}

//=============================================================================
// Utility functions.
//=============================================================================

function winFindByClassName(el, className) {

  var i, tmp;

  if (el.className == className)
    return el;

  // Search for a descendant element assigned the given class.

  for (i = 0; i < el.childNodes.length; i++) {
    tmp = winFindByClassName(el.childNodes[i], className);
    if (tmp != null)
      return tmp;
  }

  return null;
}

//=============================================================================
// Initialization code.
//=============================================================================

var winList = new Array();
var winCtrl = new Object();

function winInit() {
  //alert('in winInit, winList size = ' + winList.length);

  winList = new Array();

  //alert('in winInit, after new Array() winList size = ' + winList.length);

  var elList;

  // Initialize window control object.

  winCtrl.maxzIndex                        =   0;
  winCtrl.resizeCornerSize                 =  16;
  winCtrl.minimizedTextWidth               = 100;
  winCtrl.inactiveFrameBackgroundColor     = "#c0c0c0";
  winCtrl.inactiveFrameBorderColor         = "#f0f0f0 #505050 #404040 #e0e0e0";
  winCtrl.inactiveTitleBarColor            = "#808080";
  winCtrl.inactiveTitleTextColor           = "#c0c0c0";
  winCtrl.inactiveClientAreaBorderColor    = "#404040 #e0e0e0 #f0f0f0 #505050";
  winCtrl.inactiveClientAreaScrollbarColor = "";
  winCtrl.inMoveDrag                       = false;
  winCtrl.inResizeDrag                     = false;

  // Initialize windows and build list.

  elList = document.getElementsByTagName("DIV");
  //alert('loading divs count=' + elList.length);
  for (var i = 0; i < elList.length; i++)
  {
    if (elList[i].className == "window")
    {
        //alert('div #' + i);
      winList[elList[i].id] = new Window(elList[i]);
    }
  }
  //alert('end of winInit, winList size = ' + winList.length);
}

//winInit();  // run initialization code after page loads.
// this is in al_module now. window.onload = winInit;

//////////////////////////////////////////////////////////////////////////////
//    Brainjar code for dynamic menu popups (brainjar.com)
//////////////////////////////////////////////////////////////////////////////
//----------------------------------------------------------------------------
// Code for handling the menu bar and active button.
//----------------------------------------------------------------------------

var activeButton = null;
var disable_menus_flag = 0;

// Capture mouse clicks on the page so any active button can be
// deactivated.


if (browser.isIE)
  document.onmousedown = pageMousedown;
else
  document.addEventListener("mousedown", pageMousedown, true);

function pageMousedown(event) {

  var el;

  // If there is no active button, exit.

  if (activeButton == null)
  {
    return;
  }    

  // Find the element that was clicked on.

  if (browser.isIE)
    el = window.event.srcElement;
  else
    el = (event.target.tagName ? event.target : event.target.parentNode);

  // If the active button was clicked on, exit.


  if (el == activeButton)
  {
    return;
  }    

  // If the element is not part of a menu, reset and clear the active
  // button.

  if (getContainerWith(el, "DIV", "menu") == null) 
  {
    resetButton(activeButton);
    activeButton = null;
  }

}

                        // supplemental function to just close the menus no matter what
function closeMenus() 
{

  if (activeButton == null)
  {
    return;
  }    

  resetButton(activeButton);
  activeButton = null;

  //disable_menus_flag = 1;

}

function buttonClick(event, menuId) {

  var button;

  if(disable_menus_flag == 1)
  {
      return;
  }

  // Get the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // Blur focus from the link to remove that annoying outline.

  //button.blur();

  // Associate the named menu to this button if not already done.
  // Additionally, initialize menu display.

  if (button.menu == null) {
    button.menu = document.getElementById(menuId);
    if (button.menu.isInitialized == null)
      menuInit(button.menu);
  }

  // Reset the currently active button, if any.

  if (activeButton != null)
    resetButton(activeButton);

  // Activate this button, unless it was the currently active one.

  if (button != activeButton) {
    depressButton(button);
    activeButton = button;
  }
  else
    activeButton = null;

  return false;
}

function buttonMouseover(event, menuId) {

  var button;

  // Find the target button element.

  if (browser.isIE)
    button = window.event.srcElement;
  else
    button = event.currentTarget;

  // If any other button menu is active, make this one active instead.

  if (activeButton != null && activeButton != button)
    buttonClick(event, menuId);
}

function depressButton(button) {

  var x, y;

  // Update the button's style class to make it look like it's
  // depressed.

  button.className += " menuButtonActive";

  // Position the associated drop down menu under the button and
  // show it.

  x = getPageOffsetLeft(button);
  y = getPageOffsetTop(button) + button.offsetHeight;

  // For IE, adjust position.

  if (browser.isIE) {
    x += button.offsetParent.clientLeft;
    y += button.offsetParent.clientTop;
  }

  button.menu.style.left = x + "px";
  button.menu.style.top  = y + "px";
  button.menu.style.visibility = "visible";
}

function resetButton(button) {

  // Restore the button's style class.

  removeClassName(button, "menuButtonActive");

  // Hide the button's menu, first closing any sub menus.

  if (button.menu != null) {
    closeSubMenu(button.menu);
    button.menu.style.visibility = "hidden";
  }
}

//----------------------------------------------------------------------------
// Code to handle the menus and sub menus.
//----------------------------------------------------------------------------

function menuMouseover(event) {

  var menu;

  // Find the target menu element.

  if (browser.isIE)
    menu = getContainerWith(window.event.srcElement, "DIV", "menu");
  else
    menu = event.currentTarget;

  // Close any active sub menu.

  if (menu.activeItem != null)
    closeSubMenu(menu);
}

function menuItemMouseover(event, menuId) {

  var item, menu, x, y;

  var tmp_menutop, tmp_itemtop, tmp_itemheight, tmp_item_position;

  // Find the target item element and its parent menu element.

  if (browser.isIE)
    item = getContainerWith(window.event.srcElement, "A", "menuItem");
  else
    item = event.currentTarget;

  menu = getContainerWith(item, "DIV", "menu");

  // Close any active sub menu and mark this one as active.

  if (menu.activeItem != null)
    closeSubMenu(menu);
  menu.activeItem = item;

  // Highlight the item element.

  item.className += " menuItemHighlight";

  // Initialize the sub menu, if not already done.

  if (item.subMenu == null) {
    item.subMenu = document.getElementById(menuId);
    if (item.subMenu.isInitialized == null)
      menuInit(item.subMenu);
  }

  // Get position for submenu based on the menu item.

  // original code is following two lines

  //x = getPageOffsetLeft(item) + item.offsetWidth;
  //y = getPageOffsetTop(item);

  // end orginal code

  // code below lets us make submenus appear in a more left to right manner without going so far down the page

  tmp_menutop = getPageOffsetTop(menu);
  tmp_itemtop = getPageOffsetTop(item);
  tmp_itemheight = item.offsetHeight;

  tmp_item_position = (tmp_itemtop - tmp_menutop) / tmp_itemheight;

  //alert("tmp_menutop=" + tmp_menutop + "\ntmp_itemtop=" + tmp_itemtop + "\ntmp_itemheight=" + tmp_itemheight + "\ntmp_item_position=" + tmp_item_position);


  x = getPageOffsetLeft(item) + item.offsetWidth;
  y = getPageOffsetTop(menu) + (tmp_item_position * 5);      // rg/jj - position top of submenu to top of current menu "block" 

  // end code for left to right......


  // Adjust position to fit in view.

  var maxX, maxY;

  if (browser.isNS) {
    maxX = window.scrollX + window.innerWidth;
    maxY = window.scrollY + window.innerHeight;
  }
  if (browser.isIE) {
    maxX = (document.documentElement.scrollLeft   != 0 ? document.documentElement.scrollLeft    : document.body.scrollLeft)
         + (document.documentElement.clientWidth  != 0 ? document.documentElement.clientWidth   : document.body.clientWidth);
    maxY = (document.documentElement.scrollTop    != 0 ? document.documentElement.scrollTop    : document.body.scrollTop)
         + (document.documentElement.clientHeight != 0 ? document.documentElement.clientHeight : document.body.clientHeight);
  }
  maxX -= item.subMenu.offsetWidth;
  maxY -= item.subMenu.offsetHeight;

  if (x > maxX)
    x = Math.max(0, x - item.offsetWidth - item.subMenu.offsetWidth
      + (menu.offsetWidth - item.offsetWidth));
  y = Math.max(0, Math.min(y, maxY));

  // Position and show it.

  item.subMenu.style.left = x + "px";
  item.subMenu.style.top  = y + "px";
  item.subMenu.style.visibility = "visible";

  // Stop the event from bubbling.

  if (browser.isIE)
    window.event.cancelBubble = true;
  else
    event.stopPropagation();
}

function closeSubMenu(menu) {

  if (menu == null || menu.activeItem == null)
    return;

  // Recursively close any sub menus.

  if (menu.activeItem.subMenu != null) {
    closeSubMenu(menu.activeItem.subMenu);
    menu.activeItem.subMenu.style.visibility = "hidden";
    menu.activeItem.subMenu = null;
  }
  removeClassName(menu.activeItem, "menuItemHighlight");
  menu.activeItem = null;
}

//----------------------------------------------------------------------------
// Code to initialize menus.
//----------------------------------------------------------------------------

function menuInit(menu) {

  var itemList, spanList;
  var textEl, arrowEl;
  var itemWidth;
  var w, dw;
  var i, j;

  // For IE, replace arrow characters.

  if (browser.isIE) {
    menu.style.lineHeight = "2.5ex";
    spanList = menu.getElementsByTagName("SPAN");
    for (i = 0; i < spanList.length; i++)
      if (hasClassName(spanList[i], "menuItemArrow")) {
        spanList[i].style.fontFamily = "Webdings";
        spanList[i].firstChild.nodeValue = "4";
      }
  }

  // Find the width of a menu item.

  itemList = menu.getElementsByTagName("A");
  if (itemList.length > 0)
    itemWidth = itemList[0].offsetWidth;
  else
    return;

  // For items with arrows, add padding to item text to make the
  // arrows flush right.

  for (i = 0; i < itemList.length; i++) {
    spanList = itemList[i].getElementsByTagName("SPAN");
    textEl  = null;
    arrowEl = null;
    for (j = 0; j < spanList.length; j++) {
      if (hasClassName(spanList[j], "menuItemText"))
        textEl = spanList[j];
      if (hasClassName(spanList[j], "menuItemArrow"))
        arrowEl = spanList[j];
    }
    if (textEl != null && arrowEl != null)
      textEl.style.paddingRight = (itemWidth 
        - (textEl.offsetWidth + arrowEl.offsetWidth)) + "px";
  }

  // Fix IE hover problem by setting an explicit width on first item of
  // the menu.

  if (browser.isIE) {
    w = itemList[0].offsetWidth;
    itemList[0].style.width = w + "px";
    dw = itemList[0].offsetWidth - w;
    w -= dw;
    itemList[0].style.width = w + "px";
  }

  // Mark menu as initialized.

  menu.isInitialized = true;
}

//----------------------------------------------------------------------------
// General utility functions.
//----------------------------------------------------------------------------

function getContainerWith(node, tagName, className) {

  // Starting with the given node, find the nearest containing element
  // with the specified tag name and style class.

  while (node != null) {
    if (node.tagName != null && node.tagName == tagName &&
        hasClassName(node, className))
      return node;
    node = node.parentNode;
  }

  return node;
}

function hasClassName(el, name) {

  var i, list;

  // Return true if the given element currently has the given class
  // name.

  list = el.className.split(" ");
  for (i = 0; i < list.length; i++)
    if (list[i] == name)
      return true;

  return false;
}

function removeClassName(el, name) {

  var i, curList, newList;

  if (el.className == null)
    return;

  // Remove the given class name from the element's className property.

  newList = new Array();
  curList = el.className.split(" ");
  for (i = 0; i < curList.length; i++)
    if (curList[i] != name)
      newList.push(curList[i]);
  el.className = newList.join(" ");
}

function getPageOffsetLeft(el) {

  var x;

  // Return the x coordinate of an element relative to the page.

  x = el.offsetLeft;
  if (el.offsetParent != null)
    x += getPageOffsetLeft(el.offsetParent);

  return x;
}

function getPageOffsetTop(el) {

  var y;

  // Return the x coordinate of an element relative to the page.

  y = el.offsetTop;
  if (el.offsetParent != null)
    y += getPageOffsetTop(el.offsetParent);

  return y;
}

//////////////////////////////////////////////////////////////////////////////
// end dynamic menu popups
//////////////////////////////////////////////////////////////////////////////

// ------------------------------------------------------------------------
//   Choicelists - dynamic select boxes and sub-selections
// ------------------------------------------------------------------------
function cl_load_list(my_select_name)
{
    var find_select_name;
    var find_selected_value;
    var find_child_select_name;
    var tmp_select_name;
    var tmp_select_value;
    var find_select_values_array;
    var find_select_text_array;

    var my_select_index=-1;
    var sel_index=-1;
    var my_child_select_index=-1;


    //alert("In the Function cl_load_list my_select_name=" + my_select_name);


    // here is the format of the Select_Options_array:
    //
    // Select_Options_array = Array(
    //                                "my_select_name",        // field name of the select
    //                                "my_child_select_name",    // field name corresponding to the child 
    //                                "my_parent_selected_value",    // value of the parent that selects the child
                                                // data to load into the select box
    //                                Array(
    //                                      values: "1", "2", "3", .....)
    //                                Array(
    //                                      text to display: "Flights", "Cars", "Hotels"...)
    //                                )
    //

    if(Select_Options_array[1] == "")
    {
        return(0);            // there are no children, no need to continue
    }


                    // step 1 - locate the index of my_select (current select)
    for( var ii=0; ii<Select_Options_array.length; ii++)
    {
        find_select_name = Select_Options_array[ii][0];
        find_child_select_name = Select_Options_array[ii][1];
        //alert("find_select_name=" + find_select_name);
        if(find_select_name == my_select_name)
        {
            my_select_index = ii;
            break;
        }
    }
    //alert(my_select_index);

    if(my_select_index == -1)        // if for some reason we don't get a parent, return
    {
        //alert("no parent index found");
        return(-1);
    }    

    if(al_get_object(find_select_name) == null)        // if for some reason we don't get a parent, return
    {
        //alert("no parent_name object found");
        return(-1);
    } 

    sel_index = al_get_object(find_select_name).selectedIndex;
    find_selected_value = al_get_object(find_select_name).options[sel_index].text;

    //alert("selected index = " + sel_index);
    //alert("find selected value = " + find_selected_value);

                    // step 2 - locate the index of the child of my_select
                    //        - where it uses the selected value
    for( var ii=0; ii<Select_Options_array.length; ii++)
    {
        tmp_select_name = Select_Options_array[ii][0];
        tmp_select_parent_value = Select_Options_array[ii][2];
        //alert("tmp_select_name="  + tmp_select_name + "\nfind_child_select_name=" + find_child_select_name +  "\ntmp_select_parent_value=" + tmp_select_parent_value + "\nfind_selected_value=" + find_selected_value);
        if(tmp_select_name == find_child_select_name && tmp_select_parent_value == find_selected_value)
        {
            my_child_select_index = ii;
            break;
        }
    }

    //alert("my child index=" + my_child_select_index);

    if(my_child_select_index == -1)    // if there is no child return
    {
        //cl_unload_list(Select_Options_array[my_select_index][1]);
        // NTBR: the cl_unload_list was running for clists with no parents or children.
        //       and I am not sure of the effect of taking out this call.  It was crashing on the 
        //       clist with no children.   JHJ 1/7/2005

        //alert("no child index found");
        return(-1);
    }

                                    // unload the child and if it has any children, unload
                                    // those as well
    cl_unload_list(Select_Options_array[my_child_select_index][0]);


                                    // load the child index into the select box
    var tmp_value_array = Select_Options_array[my_child_select_index][3];
    var tmp_text_array  = Select_Options_array[my_child_select_index][4];
    for(var ii=0;ii<tmp_value_array.length;ii++)
    {
        var tmp_opt = new Option;
        tmp_opt.value = tmp_value_array[ii];
        tmp_opt.text = tmp_text_array[ii];

        al_get_object(find_child_select_name).options[ii] = tmp_opt;

    }

    //alert("about to execute onchange for item [" + find_child_select_name + "]");
    al_get_object(find_child_select_name).onchange();


    return;
    
}

function cl_unload_list(my_select_name)
{
                            // locate the name of the select above, find out if
                            // it has any children.  unload it.  unload its children.
    var find_select_name;
    var find_child_select_name;
    var my_select_index=-1;
    var my_child_select_index=-1;

                    // step 1 - locate the index of my_select (current select)
    for( var ii=0; ii<Select_Options_array.length; ii++)
    {
        find_select_name = Select_Options_array[ii][0];
        find_child_select_name = Select_Options_array[ii][1];
        //alert("find_select_name=" + find_select_name);
        if(find_select_name == my_select_name)
        {
            my_select_index = ii;
            break;
        }
    }
    if(my_select_index == -1)
    {
        return(-1);
    }

                                    // set the field to 0 Options
    if(browser.isNS)
    {
        window.document.getElementById(find_select_name).length=0;
    }
    else
    {
        window.document.all[find_select_name].length=0;
    }


    var tmp_opt = new Option;
    tmp_opt.value = "0";
    tmp_opt.text = " ";

    if(browser.isNS)
    {
        window.document.getElementById(find_select_name).options[0] = tmp_opt;
        window.document.getElementByID(find_select_name).length=0;
    }
    else
    {
        window.document.all[find_select_name].options[0] = tmp_opt;
        window.document.all[find_select_name].length=0;
    }



    if(find_child_select_name != "")
    {
        cl_unload_list(find_child_select_name);
    }

    return(1);
}

function test_clists()
{
    alert(Select_Options_array.length);
    alert(Select_Options_array[1][1][1]);
}

function al_selectbox_other(my_select_name, my_other_div_name, my_other_field_name, compare_value, hide_flag, expose_flag, blank_flag)
{
    var sel_index;
    var my_select_value;
    var my_select_obj;

                            // if any parameters are not passed, return with no action
    if(!my_other_div_name && !my_other_field_name)
    {
        alert("Div not found.");
        return(0);
    }


    //alert('getting object = ' + my_select_name);
    my_select_obj = al_get_object(my_select_name);
    //alert('got object = ' + my_select_obj);

                                    // set the field to 0 Options
    /*
    if(browser.isNS)
    {
        sel_index = window.document.getElementById(my_select_name).selectedIndex;
        my_select_value = window.document.getElementByID(my_select_name).options[sel_index].text;
    }
    else
    {
        sel_index = window.document.all[my_select_name].selectedIndex;
        my_select_value = window.document.all[my_select_name].options[sel_index].text;
    }
    */

//alert('type of select object = ' + my_select_obj.type);
                                        // radio buttons and checkboxes are different because there
                                        // are multiple fields.
    if(my_select_obj.type == 'radio' || my_select_obj.type == 'checkbox')
    {
        //alert('my_select_obj.checked = ' + my_select_obj.checked);
        //alert('my_select_obj.value = ' + my_select_obj.value);

                                                // if its checked, copy the value to my_select_value
        if(my_select_obj.checked)
        {
            my_select_value = my_select_obj.value;
        }
        else                                    // otherwise use -1 to indicate its not checked
        {
            my_select_value = "-1";
        }

    }
    else
    {
    //alert("my_select_obj = " + my_select_obj);

        sel_index = my_select_obj.selectedIndex;

    //alert("sel_index = " + sel_index);


        my_select_value = my_select_obj.options[sel_index].text;
    }    


    if(my_select_value != compare_value)
    {
        if(hide_flag)
        {
            al_get_object(my_other_div_name).style.visibility='hidden';

        }

        if(blank_flag)
        {
            al_get_object(my_other_field_name).value='';

        }
    }
    else
    {
        if(expose_flag)
        {
            al_get_object(my_other_div_name).style.visibility='visible';
        }    
    }

    return(1);
}



//
// function create_dynamic_form - takes a form stored on the page as a template and copies it 
//                                and replaces some instance_id's so that it will be a valid form
//                                  when it is plaeced on the page
//
//
// form_template_id - the id of the div that the form_template html is stored in
// target_div - the div that the new form needs to be placed in, or 'BOW' for a bride-of-windows
// source_instance_id - the instance_id of the record that we need to relate to

function create_dynamic_form(form_template_id, target_div, source_instance_id)
{

    var tmp_iframe_html;
    var tmp_title_html;
    var title_div_html;
    var popup_div_html;
    var content_div_html;

    var form_template_html;
    var form_template_div;
    var new_form_html;
    var new_form_instance_id;

    var dynamic_form_storage_div;

    var popup_width;
    var popup_height;

    var instance_id_re;
    var parent_id_re;

                            // this.new_form_instance_id_num is a number that we will
                            // use to give all new dynamic forms a unique instance_id

                            

                            // if this.new_form_instance_id_num
    if(this.new_form_instance_id_num)
    {
                            // increment the number and use the new number in
                            // the instance_id that we create

        this.new_form_instance_id_num++;


    }
    else                    // otherwise
    {
                            // we need to initialize that number and then use it

        this.new_form_instance_id_num = 1;
    }


    new_form_instance_id = "js_form_" + this.new_form_instance_id_num;


    //alert("new_form_instance_id = " + new_form_instance_id);




                            // set parameters that may change based on the class
                            // and form being displayed

    popup_width = 300;    // for now just hard-code width
    popup_height = 300;    // for now just hard-code height




                            // get form_html from the div form_template_id, and edit it 
                            // so it has a real instance_id
                            

    form_template_div = al_get_object(form_template_id);

    //alert("form_template_div = " + form_template_div);

    form_template_html = form_template_div.innerHTML;

    //alert("form_template_html = " + form_template_html);


                            // create the regular expression object that contains the
                            // search string that we need to replace

    instance_id_re = new RegExp("template_instance_id", "g");

    
    //alert("instance_id_re = " + instance_id_re);

                            // call the replace method to replace all occurances of
                            // "template_instance_id" with our new 
    new_form_html = form_template_html.replace(instance_id_re, new_form_instance_id);


    //alert("new_form_html = " + new_form_html);

                            // create the regular expression that will replace the instance_id
                            // of the record that will be the target of a relationship

    instance_id_re = new RegExp("dynamic_parent_id", "g");



    new_form_html = new_form_html.replace(instance_id_re, source_instance_id);

    //alert("new_form_html = " + new_form_html);

    //alert("target_div = " + target_div);

    if(target_div == 'BOW')
    {
                                // create the title div for the BOW

        //NTBD fix the id's here
        var tmp_id = 'tmp_id';
        //tmp_id = button_obj->popup_array["id"] ;

        tmp_title_html = '<span class="titleBarText">'
                                            + 'temp title'
                                            +'</span>'
                                            +'<img class="titleBarButtons" alt="" hidefocus="true" src="images/file-control-buttons.gif" usemap="#winMap' + tmp_id + '">'
                                            + '<map name="winMap' + tmp_id + '">'
                                            + '<area shape="rect" coords="0,0,15,13"  href="" alt="" title="Minimize" onclick="this.parentWindow.minimize();return false;">'
                                            + '<area shape="rect" coords="16,0,31,13" href="" alt="" title="Restore"  onclick="this.parentWindow.restore();return false;">'
                                            + '<area shape="rect" coords="34,0,49,13" href="" alt="" title="Close"    onclick="this.parentWindow.close();return false;">'
                                            + '</map>';


        title_div_html = '<DIV ID="' + form_template_id + '|' + new_form_instance_id +  '|title_div" class="titleBar">' + tmp_title_html + '</DIV>';



        //alert("title_div_html = " + title_div_html);

                                // create the content div for the BOW



        //tmp_iframe_html = '<IFRAME name="' + form_template_id + '|' + new_form_instance_id +  '|iframe" id="' + form_template_id + '|' + new_form_instance_id +  '|iframe" noresize="no" height="100%" width="100%"  ><HTML><BODY><FORM NAME="TMP_FORM_NAME" ACTION="SUBMIT">' + new_form_html  +  '</BODY></FORM></HTML></IFRAME>'
        tmp_iframe_html = '<HTML><BODY><FORM METHOD="post" ACTION="http://cppdev.airlink.net/al_module.php?module_class=crm_rolo&session_id=3c4e58e4f19f13b24ff8c1c3cf14dd2d2e&session_name=jhuizingh-airlink&submit_debuglevel=2"  ENCTYPE="multipart/form-data"  NAME="TMP_FORM_NAME" "><INPUT TYPE="SUBMIT">' + new_form_html  +  '</BODY></FORM></HTML>'



        content_div_html = '<DIV ID="' + form_template_id + '|' + new_form_instance_id +  '|content_div" class="clientArea" style="height:' +
 (parseInt(30) +  parseInt(popup_height) ) + 'px;">' + tmp_iframe_html + '</DIV>';







                                // create the div that the new form will go into

        //alert("about to create div");


        //popup_div_html = '<DIV ID="' + form_template_id+ '|popup_div" class="window" style="display:block;visibility:visible;left:75px;top:75px;width:' + (parseInt(30) +  parseInt(popup_width) ) + 'px;" ></DIV>';
        popup_div_html = '<DIV ID="' + form_template_id+'|' + new_form_instance_id +  '|popup_div" class="window" style="position:absolute; display:block; visibility:visible; left:75px; top:75px;width:' + (parseInt(30) +  parseInt(popup_width) ) + 'px;" >'+ title_div_html + content_div_html + '</DIV>';


        //alert("popup_div_html = " + popup_div_html);


                            // put the new html that we just created onto the page in
                            // the div that stores dynamic forms

        dynamic_form_storage_div = al_get_object("dynamic_form_location");
        dynamic_form_storage_div.innerHTML += popup_div_html;
    }
    else
    {
                            // put the new html that we just created onto the page in
                            // the div specified as an argument

        dynamic_form_storage_div = al_get_object(target_div);
        dynamic_form_storage_div.innerHTML += new_form_html;

    }







    
    aljs_load_form_element_objects();

}





function al_display_tab_content(index_to_display, tab_type)
{
    var tab_id;
    var tab_content_id;

    tab_id = "tab_" + index_to_display.toString();

    tab_content_id = "tab_content_" + index_to_display.toString();


                            // if we clicked on an already active tab, we
                            // don't need to do anything.  return
    if(active_tab == tab_id)
    {
        return(0);
    }

                                // change the currently active tab back to inactive
                                // and hide the content



    var current_active_content = al_get_object(active_content);
    var current_active_tab = al_get_object(active_tab);

    current_active_content.style.display = "none"
    current_active_tab.className = active_tab_orig_class;


                                // get the elements that we are switching to active
                                    
    var new_active_content = al_get_object(tab_content_id);
    var new_active_tab = al_get_object(tab_id);

                                // store information to switch tab back to inactive
                                // when another tab is clicked

    active_content = tab_content_id;
    active_tab = tab_id;

    active_tab_orig_class = new_active_tab.className;

                                // update the new tab to active
    if(tab_type == "parent")
    {
        new_active_tab.className = "active_tab_parent";
    }
    else
    {
        new_active_tab.className = "active_tab_child";
    }

    new_active_content.style.display = "block";
}


function aljs_save_tab_set(parm_base_url)
{
    //alert("parm_base_url = [" + parm_base_url + "]");

    var get_url;
    var post_url;


    get_url = parm_base_url;

                                // save_tab_set is an input box on the page with the tab set name in it
                                // but on the auto-save this field is not present.
    if(al_get_object("save_tab_set") != null) 
    {
        get_url += "&tab_set_name=" + al_get_object("save_tab_set").value;
    }
    else    
    {
        get_url += "&tab_set_name=";
    }


    //var debug_string = "";

    for(var index in tab_bar_tab_container.tab_array)
    {
        if(tab_bar_tab_container.tab_array[index].tab_recnum)
        {     
            // save the tr = Tab Recnum
            post_url += "&save_tr[]=" + tab_bar_tab_container.tab_array[index].tab_recnum;

            // save the tt = Tab Title
            post_url += "&save_tt[]=" + aljs_urlencode(tab_bar_tab_container.tab_array[index].tab_title);

            // save the ts = Tab Sequence
            post_url += "&save_ts[]=" + tab_bar_tab_container.tab_array[index].tab_seq;

            // save the tl = Tab Level
            post_url += "&save_tl[]=" + tab_bar_tab_container.tab_array[index].tab_lev;

            //debug_string += "index = [" + index + "], tab_recnum = [" + tab_bar_tab_container.tab_array[index].tab_recnum + "]\n";

        }

    }

    //alert(debug_string);

    //al_get_object("al_module_thread").src = get_url + post_url;
    //
    // JHJ20081126 - Because the URL here can get to a real big size, we cannot depend on a GET request
    //               because at a length of around 2100 bytes, the URL stops getting pushed into traqone.
    //               so we use an async ajax request instead.

    xmlhttp = new_xmlhttp_object();

    use_async = true;

    retval = xmlhttp.open("POST", get_url +"&rdm_sts="+Math.random(), use_async);

    xmlhttp.onreadystatechange =
    function()
    {
    };

    //xmlhttp.send("");
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(post_url);

    //alert("sent the post url, done");

    return;
}




// Some methods for TabContainer class, they must be decared above the
// constructor so they can be added to the object in the constructor

function TabContainer_add_tab(new_tab)
{
    var tmp_tab_id = new_tab.tab_id;

    this.tab_array[tmp_tab_id] = new_tab;

    //alert("adding tab [" + new_tab.tab_id + "]");

}

function TabContainer_make_active(tab_id)
{
    var current_tab_id;
    var tab_content_id;
    var tab_type;

    var current_tab_content;
    var current_tab_content_id;
    var previous_active_tab_index;

    var prev_tab_image_array;
    var previous_tab;

    var prev_tab_image_array;
    var new_active_content;
    var new_active_tab;
    var menu_image;

    var list_obj;

            //alert("in make_active, tab_id = [" + tab_id + "], active_tab=" + this.active_tab + ", iframe_id_array length=" + this.tab_array[tab_id].iframe_id_array.length);

    tab_content_id = this.tab_array[tab_id].tab_content_id;

                            // if we clicked on an already active tab,
                            // change the style to the active_style in case
                            // it is currently something like attention,
                            // then exit
                            // also, resize the iframe that this tab contains
                            // if there is one

    if(this.active_tab == tab_id)
    {
        new_active_content = al_get_object(tab_content_id);
        new_active_tab = al_get_object(tab_id);

        new_active_tab.className = this.tab_array[tab_id].active_style;


                                    // if the active tab contains an iframe that we 
                                    // need to resize, do that now

        if(this.tab_array[tab_id].iframe_id_array.length != 0)
        {
			//alert("resizing iframes part1");
                        //alert("resizing iframes, length = [" + this.tab_array[tab_id].iframe_id_array.length   + "]");

           // for each item in the iframe_id_array


/* *********** this code does not work if the document that is referred to no longer exists
 *             and there does not appear to be any way to tell that the document no longer exists
 *             the iframe_document_ref variable points to a "document" object
 *             but on refresh of the page the document object no longer points to anything
 *             however it is still an "object", it is not null, or undefined.  And so the 
 *             javascript cannot do an if statement to detect that the page no longer exists.
 *             I also tried changing to a reference to the "window" object above the document object
 *             and the same issues are still true.  I was trying to get to the window.closed property
 *             which some documentation indicated would stay in memory after a window closed.  
 *             The error returned in most cases was Permission denied (when trying to access properties of the object)
 *             or that the property did not exist. 9884-4-72-11936

            for(var iframe_id_array_index in this.tab_array[tab_id].iframe_id_array)
            {
				//alert("iframe_id=" + iframe_id_array_index + ", doc_id=" + this.tab_array[tab_id].iframe_id_array[iframe_id_array_index]);

                var tmp_iframe_document_ref = this.tab_array[tab_id].child_iframe_document_ref_array[this.tab_array[tab_id].iframe_id_array[iframe_id_array_index]];
				//alert("tmp_iframe_document_ref=" + tmp_iframe_document_ref);


                              //alert("iframe id = [" + this.tab_array[tab_id].iframe_id_array[iframe_id_array_index] + "]\n"
                                         //+ "document ref = [" + tmp_iframe_document_ref + "]\n");

                // if this is a document reference for a page that got
                // replaced, then skip it and continue to the next one

                if(tmp_iframe_document_ref == null || tmp_iframe_document_ref.body == null )
                {
                    //alert("document reference is null");
                    continue;
                }

                //var target_width = tmp_iframe_document_ref.body.clientWidth + 30;
                var target_width = tmp_iframe_document_ref.body.clientWidth;
                //JHJ070725//var target_height = tmp_iframe_document_ref.body.clientHeight + 30;
                var target_height = tmp_iframe_document_ref.body.clientHeight;

				//alert("resizing the iframe for tab = " + tab_id);

                //alert("target_width = [" + target_width + "]\n"
                      //+ "target_height = [" + target_height + "]");

                                        // change the height and width

							// NTBD: parentWindow needs an equivalent for Firefox

             if(tmp_iframe_document_ref.parentWindow != null)
	     {
                 if(target_height > 0)
		 {
		     tmp_iframe_document_ref.parentWindow.height = target_height;

		 }

		 if(target_width > 0)
		 {
		     tmp_iframe_document_ref.parentWindow.width = target_width;
		 }
             }


                         //
                         // if the tab content has a tab_content_make_active_button
                         // then execute that button
                         // if the tab content does not have the button
                         // then this command returns without doing anything
                         //

                //tmp_iframe_document_ref.parentWindow.aljs_execute_button_onclick('tab_content_make_active_button');
                // If this is already the active tab, then we don't need to reactivate the active tab.
                // because it will resize a tab which may be resized to different than the default by the user.

            }
*********************************************** */

        }


        this.tab_array[tab_id].load_urls_in_iframes();

        return(0);
    }

                                // loop through all of the tabs and set them to
                                // inactive

    var debug_string = "";

    for(var current_tab_index in this.tab_array)
    {
        //alert("current_tab_index = [" + current_tab_index + "]");
        if(current_tab_index == this.active_tab)
        {
            al_get_object(current_tab_index).className = this.tab_array[current_tab_index].inactive_style;
            previous_active_tab_index = current_tab_index;


        }

        //debug_string += "for tab [" + current_tab_index + "], active_style = [" + this.tab_array[current_tab_index].active_style + "], inactive_style = [" + this.tab_array[current_tab_index].inactive_style + "]\n";

        current_tab_content_id = this.tab_array[current_tab_index].tab_content_id;

        //alert("current_tab_content_id = [" + current_tab_content_id + "]");

        current_tab_content = al_get_object(current_tab_content_id);

        if(current_tab_content != null)
        {
            current_tab_content.style.display = "none";
        }
    }

    //alert(debug_string);



                                // get the elements that we are switching to active
                                    
    new_active_content = al_get_object(tab_content_id);		// (IFRAME)
    new_active_tab = al_get_object(tab_id);					// (TAB)


                                // move the new active list item to the front of the
                                // all the list items.

    //list_obj = new_active_tab.parentNode;

    //alert("list_obj = [" + list_obj + "]");

    //list_obj.insertBefore(new_active_tab, list_obj.firstChild) 


                                // store information to switch tab back to inactive
                                // when another tab is clicked

    active_content = tab_content_id;
    this.active_tab = tab_id;

    tab_type = this.tab_array[tab_id].tab_type;

                                // update the new tab to active
    new_active_tab.className = this.tab_array[tab_id].active_style;

    if(new_active_content != null)
    {
        new_active_content.style.display = "block";
    }



    //
    // Get tab ordering method setting
    //
    // 1 - put new tabs at the top of the open-windows list
    // 2 - put new tabs immediately following the current tab
    //

    var tq1_settings_open_windows_ordering_method = aljs_get_element_value("tq1_settings_open_windows_ordering_method");

    //alert("tq1_settings_open_windows_ordering_method=" + tq1_settings_open_windows_ordering_method);

                                //      
                                // move the active tab to the top of the module list
                                //      
            //# 9884-4-22-7809 #//

    if(tab_type != "child")
    {
        module_list = al_get_object("module_tab_list");

        if(module_list != null)
        {
            if(Use_tab_bar_style == 'vertical')
            {
                 //alert("here1");
                 if( tq1_settings_open_windows_ordering_method == "2")
                 {
                    //alert("here2");
                    // do nothing to reorder on method 2
                 }
                 else       // 1 is the default - order the open tab to be the first tab
                 {
                    //alert("here3");
                    module_list.insertBefore(new_active_tab, module_list.firstChild);
                 }
            }
        }
    }


// NOTE: if you put an alert here, the code will break at the 
//       
//    " 5604             tmp_iframe_document_ref.parentWindow.aljs_execute_button_onclick('tab_content_make_active_button');"
//       line.  Not sure why an alert breaks that code, but it does.
//          jhj 20090320
//alert("here1");


            //# 9884-4-22-11428 #//  active tab stays put
/* ******************
    if(tab_type != "child")
    {
        module_list = al_get_object("module_tab_list");

        if(module_list != null)
        {
            if(Use_tab_bar_style == 'vertical')
            {
                 //module_list.insertBefore(new_active_tab, module_list.firstChild);
            }
        }
    }
*********************** */

    if( tq1_settings_open_windows_ordering_method == "2")
    {
                    // do nothing to reposition, since we did not reorder on method 
    }
    else  
    {
                   // make the active tab cause the tab_bar to scroll to the top
        if(al_get_object("tab_bar"))
        {     
             al_get_object("tab_bar").scrollTop=0;           // scroll to the top of the div
        }     
    } 



                                // call change_tab_text on the new active tab so
                                // it gets the full text

    if(this.tab_array[tab_id].tab_title != "")
    {
        aljs_change_tab_text(tab_id, this.tab_array[tab_id].tab_title);
    }

                                // call change_tab_text on the previous active tab so
                                // it gets the shortened text

    if(previous_active_tab_index != null && this.tab_array[previous_active_tab_index].tab_title != "" && this.always_expanded != true)
    {
        aljs_change_tab_text(previous_active_tab_index, this.tab_array[previous_active_tab_index].tab_title);
    }



                                //
                                // set the urls for any iframes in this tab
                                // that need to be loaded
                                //

    this.tab_array[tab_id].load_urls_in_iframes();



                                // if the active tab contains an iframe that we 
                                // need to resize, do that now

    if(this.tab_array[tab_id].iframe_id_array.length != 0)
    {

/* *********** this code does not work if the document that is referred to no longer exists
 *             and there does not appear to be any way to tell that the document no longer exists
 *             the iframe_document_ref variable points to a "document" object
 *             but on refresh of the page the document object no longer points to anything
 *             however it is still an "object", it is not null, or undefined.  And so the 
 *             javascript cannot do an if statement to detect that the page no longer exists.
 *             I also tried changing to a reference to the "window" object above the document object
 *             and the same issues are still true.  I was trying to get to the window.closed property
 *             which some documentation indicated would stay in memory after a window closed.  
 *             The error returned in most cases was Permission denied (when trying to access properties of the object)
 *             or that the property did not exist. 9884-4-72-11936


		//alert("resizing iframes part2");
        //alert("resizing iframes, length = [" + this.tab_array[tab_id].iframe_id_array.length   + "]");
                                // for each item in the iframe_id_array

        for(var iframe_id_array_index in this.tab_array[tab_id].iframe_id_array)
        {
            var tmp_iframe_document_ref = this.tab_array[tab_id].child_iframe_document_ref_array[this.tab_array[tab_id].iframe_id_array[iframe_id_array_index]];

			//alert("tmp_iframe_document_ref=" + tmp_iframe_document_ref);

            //alert("iframe id = [" + this.tab_array[tab_id].iframe_id_array[iframe_id_array_index] + "]\n"
                  //+ "document ref = [" + tmp_iframe_document_ref + "]\n");

                                    // if this is a document reference for a page that got
                                    // replaced, then skip it and continue to the next one
            if(tmp_iframe_document_ref == null || tmp_iframe_document_ref.body == null )
            {
                //alert("document reference or document body is null");
                continue;
            }

            //var target_width = tmp_iframe_document_ref.body.clientWidth + 30;

            //alert("tmp_iframe_document_ref.body.clientWidth = [" +tmp_iframe_document_ref.body.clientWidth  + "]\n"
            //+"tmp_iframe_document_ref.body = [" +tmp_iframe_document_ref.body   + "]\n");

            var target_width = tmp_iframe_document_ref.body.clientWidth;
            //JHJ070725//var target_height = tmp_iframe_document_ref.body.clientHeight + 30;
            var target_height = tmp_iframe_document_ref.body.clientHeight;

            //alert("target_width = [" + target_width + "]\n"
                  //+ "target_height = [" + target_height + "]");

			//alert("resizing new active tab = " + tab_id );
                                    // change the height and width


// NTBD: parentWindow needs an equivalent for Firefox
			if(tmp_iframe_document_ref.parentWindow != null)
			{
			
                                   if(target_height > 0)
                                   {
                                      tmp_iframe_document_ref.parentWindow.height = target_height;

                                   }
                                   if(target_width > 0)
                                   {
                                      tmp_iframe_document_ref.parentWindow.width = target_width;
                                   }
			}


                         //
                         // if the tab content has a tab_content_make_active_button
                         // then execute that button
                         // if the tab content does not have the button
                         // then this command returns without doing anything
                         // and if the document is loaded with the "please_wait.html"
                         // this if statement will prevent an error for load-on-demand tabs.
                         //

            if(new_active_content_document.parentWindow != null && new_active_content_document.parentWindow.aljs_execute_button_onclick != null)
            {
                tmp_iframe_document_ref.parentWindow.aljs_execute_button_onclick('tab_content_make_active_button');
            }

        }
*/


    }

    if(new_active_content != null)
    {

               // here we are handling where a inner tab is an iframe, but the element we're passed is
               // actually a DIV, not a iframe, but the iframe is the element just inside the div.
        if(new_active_content.tagName == "DIV")
        {
            if(new_active_content.childNodes.length > 0)
            {
                new_active_content = new_active_content.firstChild;
                    //alert("new_active_content=" + new_active_content);
            }
        }

             // only execute this code if we locate an iframe.
        if(new_active_content.tagName == "IFRAME")
        {
		// now for some reason, we dont get an iframe_id_array but we still have a tab
		// so we need to do the resize on the iframe which is contained in new_active_content
		var new_active_content_document;
		if (new_active_content.contentDocument) 
		{
			// For NS6
			new_active_content_document = new_active_content.contentDocument; 
		} 
		else if (new_active_content.contentWindow) 
		{
			// For IE5.5 and IE6
			new_active_content_document = new_active_content.contentWindow.document;
		} 
		else if (new_active_content.document) 
		{
			// For IE5
			new_active_content_document = new_active_content.document;
		} 
		//alert("new_active_content=" + new_active_content + ", new_active_content.document="+ new_active_content_document);
		if(new_active_content_document != null && new_active_content_document.body != null)
		{
			//var target_width = new_active_content_document.body.clientWidth;
			var target_height = new_active_content_document.body.clientHeight;

			//alert("resizing active iframe tab = " + tab_id );
                                                  // no resize on the width.  width is never coming out accurately-jhj-20070730
			//new_active_content.width = target_width;
			new_active_content.height = target_height;

                                        // trickle up the node tree to resize downwards when necessary
                           // JHJ20070829 - this causes things to have height that shouldn't
                           //var tmp_node = new_active_content.parentNode;
                           //while(tmp_node != null && tmp_node.nodeType == 1)
                           //{       
                           //    tmp_node.height = target_height;
                           //    tmp_node = tmp_node.parentNode;
                           //} 


                         //
                         // if the tab content has a tab_content_make_active_button
                         // then execute that button
                         // if the tab content does not have the button
                         // then this command returns without doing anything
                         //

                             // make sure the iframe is loaded and the js is loaded prior to executing this button
                             // which will be inside the iframe's content when it has loaded.

                      if(new_active_content.src != "" && new_active_content.contentWindow.aljs_execute_button_onclick != null)
                      { 
                          new_active_content.contentWindow.aljs_execute_button_onclick('tab_content_make_active_button');
                      }
		}
        }
    }	


                                // if we have an active tab menu image, set it on the new active tab

    if(this.tab_array[tab_id].tab_menu_active_image)
    {
        new_tab_image_array = new_active_tab.getElementsByTagName("img");

        //alert("prev_tab_image_array = [" + prev_tab_image_array + "]\n"
        //+ "prev_tab_image_array.length = [" + prev_tab_image_array.length + "]");

        menu_image = new_tab_image_array[1];

        //menu_image.src = this.tab_array[tab_id].tab_menu_active_image;

    }

                                // if the previous active tab has a menu arrow, switch that menu
                                // arrow to be the inactive menu arrow image


    //alert("previous_active_tab_index = [" + previous_active_tab_index + "]");
    //alert("this.tab_array[previous_active_tab_index].tab_menu_inactive_image = [" + this.tab_array[previous_active_tab_index].tab_menu_inactive_image + "]");
    if(previous_active_tab_index != null && this.tab_array[previous_active_tab_index].tab_menu_inactive_image)
    {
        previous_tab = al_get_object(previous_active_tab_index);
        prev_tab_image_array = previous_tab.getElementsByTagName("img");

        //alert("prev_tab_image_array = [" + prev_tab_image_array + "]\n"
        //+ "prev_tab_image_array.length = [" + prev_tab_image_array.length + "]");

        menu_image = prev_tab_image_array[1];

        //menu_image.src = this.tab_array[previous_active_tab_index].tab_menu_inactive_image;

    }



    ///////// Debug only

    //var debug_string = "";

    //for( var item in this.tab_array[tab_id])
    //{
        //debug_string += "tab_use[" + item + "] = [" + this.tab_array[tab_id][item] + "]\n";
    //}
    
    //debug_string += "\n\nthis.tab_array[tab_id].iframe_id_array.length  = [" + this.tab_array[tab_id].iframe_id_array.length + "]";

    //alert(debug_string);


    ///////// End Debug only


    aljs_change_iframe_size();

}

// TabContainer is a class that contains a set of tabs 
// and methods to set them active or inactive

function TabContainer()
{
    this.tab_array = new Array();
    this.active_tab = "";

    // assign methods to this object

    this.add_tab = TabContainer_add_tab;
    this.make_active = TabContainer_make_active;

                            // for tab sets that may have their text contracted,
                            // this will be true if they should stay expanded

    this.always_expanded = false;

                            // flag saying whether a new tab is locked or unlocked
                            // by default

    this.new_tab_default_locked_state = false;

}




function Tab_add_on_select_url(iframe_id, url, load_type)
{

    //alert("in add_on_select_url,\n iframe__id = [" + iframe_id + "]\n"
          //+ "url = [" + url + "]\n"
          //+ "load_type = [" + load_type + "]\n"
          //+ "current iframe id = [" + al_get_object(iframe_id).src  + "]\n"
          //);

    this.on_demand_load_url[iframe_id] = url;
    this.on_demand_load_type[iframe_id] = load_type;

}

function Tab_load_urls_in_iframes()
{
    //alert("in load_urls_in_iframes\n");

    var iframe_id;
    var iframe_obj;

                            // loop through the list of all iframes
                            // that need to be loaded for this tab
                            
    for(iframe_id in this.on_demand_load_url)
    {
        //alert("in load_urls_in_iframes\n"
            //+ "this.on_demand_load_type[iframe_id] = [" + this.on_demand_load_type[iframe_id] + "]\n"
            //+ "this.has_not_been_selected_yet = [" + this.has_not_been_selected_yet + "]\n"
        //);
        iframe_obj = al_get_object(iframe_id);

                            // if this is the first time we are selecting 
                            // this tab and we are supposed to load it on 
                            // the first time, or if we are supposed to 
                            // load the url every time

        if(
            (this.on_demand_load_type[iframe_id] == "first" && this.has_not_been_selected_yet == true )
            || (this.on_demand_load_type[iframe_id] == "all"   )
        )
        {
            //alert("loading url [" + this.on_demand_load_url[iframe_id] + "]");

                            //    
                            // make sure the iframe is loaded and the js is loaded prior to executing this button
                            // which will be inside the iframe's content when it has loaded.
                            // The button is currently set to run the splash screen, but can do anything
                            // within the limit of the time it takes to load the iframe with a new URL.
                            //    

            if(iframe_obj.src != "" && iframe_obj.contentWindow.aljs_execute_button_onclick != null) 
            {     
                iframe_obj.contentWindow.aljs_execute_button_onclick('externally_activated_button');
            }     



                            // set the url for the iframe to the url
                            // from the array for that iframe


            iframe_obj.src = this.on_demand_load_url[iframe_id];


        }


    }

    this.has_not_been_selected_yet = false;
}

// Tab is a class that contains information about a single
// tab in a list of tabs

function Tab(parm_tab_id, parm_tab_content_id, parm_tab_type, parm_active_style, parm_inactive_style)
{
    this.tab_id = parm_tab_id;
    this.tab_content_id = parm_tab_content_id;
    this.tab_type = parm_tab_type;
    this.active_style = parm_active_style;
    this.inactive_style = parm_inactive_style;
    this.tab_recnum = "";
    this.tab_title = "";
    this.tab_seq = 0.0;         // set the defaults here.  these get updated when the tab is drawn on the page
    this.tab_lev = 0;

    this.iframe_id_array = new Array();
    this.child_iframe_document_ref_array = new Object();		// this is an associative array

                        // Array that stores url that goes in iframe
                        //
                        // index = iframe id
                        // value = url
    this.on_demand_load_url = new Array();  

                        // Array that stores when we are supposed to
                        // load  the url (first time or every time)
                        //
                        // index = iframe id
                        // value = "first" or "all"

    this.on_demand_load_type = new Array();    

                        // flag to tell us whether we have looked at this tab yet or not,
                        // used to load a tab's iframe when it is clicked
                        
    this.has_not_been_selected_yet = true;

                        // flag to keep track of if a tab stays always expanded or if it
                        // is contracted when you deselect it

    this.expanded_lock_state = false;


                        // flag that says whether a tab is locked or not.  If it is 
                        // unlocked, then it can be set to a different page.  If it is
                        // locked, then it should not be changed

    this.locked_state = false;


                        //
                        // Member functions
                        //

    this.add_on_select_url = Tab_add_on_select_url;
    this.load_urls_in_iframes = Tab_load_urls_in_iframes;

}


// This method gets the name of the frame we are in, which corresponds to the id of
// the tab in the main page tab_container.

function aljs_get_current_tab_id()
{
    var tab_id = "";


    if(browser.isIE)
    {
        //alert("isIE top.frames.length=" + top.frames.length);
        //alert("isIE top.frames[0].name=" + top.frames[0].name);

                // handling a weird situation here between IE7 and IE8.
                // In IE8, the for-loop "cur_frame in top.frames" crashes on a 
                //         property which cannot be accessed and the iframes 
                //         we are looking for can be accessed through the top.frames[ii].name
                // In IE7, the top.frames[ii].name returns blank on the frames we are looking
                //         for, so we HAVE to use the for-loop "cur_frame in top.frames"
                // To make things work right, I will check for the empty name, and do
                // the second loop if that is the case and see if we can find the iframe there.
                // jhj 20090821-9884-4-72-11885 

                // go through the IE8 version first
        for(var ii=0;ii<top.frames.length;ii++)
        {
            cur_frame = top.frames[ii].name;
            //alert("cur_frame="+cur_frame);

            if(top.frames[ii] == self)
            {
                        // then if the frame name is empty, check in the IE7 version of the code
                if(cur_frame == "")
                {
                    for(var cur_frame in top.frames)
                    {
                        //alert("IE7 cur_frame="+cur_frame);
                        if(top.frames[cur_frame] == self)
                        {
                            tab_id = cur_frame;
                            //alert("IE7 found tab_id = " + tab_id);
                            break;
                        }
                    }
                    break;
                }
                else
                {
                    tab_id = cur_frame;
                    //alert("found tab_id = " + tab_id);
                    break;
                }
            }
        }
    }
    else
    {
        tab_id = window.name;
    }

    tab_id = tab_id + "_tab";

    //alert("tab_id = [" + tab_id + "]");
    return tab_id;
}



// This function loads a url in a tab or a popup based on whether the tab or
// tab section exists.  it accepts all the arguments that were previously
// used from the C code to open in a tab, and uses just the single function call
//  
// so instead of this:
//    onclick="Javascript: 
//                         var start_tab = top.tab_bar_tab_container.active_tab; 
//                         var new_tab_id = top.aljs_create_empty_module_tab('page_tab_loading', 'page_tab_loading', 'new_tab_active'); 
//                         aljs_change_tab_text(new_tab_id, '[List Item 12/12/2007 11:29 AM]-'); 
//                         top.aljs_load_url_in_specified_tab(new_tab_id, 'http://.....5e422b'); 
//                         top.tab_bar_tab_container.make_active(start_tab); "
//
// we will just do this:
//    onclick="Javascript: aljs_open_tabWindwow('new_tab_active', '[List Item 12/12/2007 11:29 AM]-', 'URL...')
//
function aljs_open_tabWindow(parm_tab_type, parm_tab_title, parm_tab_properties, parm_url)
{   
               // if there is no tab container to insert into, then we have to use a popup
    if(top.tab_bar_tab_container == null || top.tab_bar_tab_container == undefined)
    {
        if(event != undefined && event != null)
        {
            aljs_setMousePos(event);
        }  
        parm_url += "&page_type=PT_POPUP"; 
        aljs_openWindow(parm_url, '_blank', '575', '575', 'width=575,height=575, scrollbars=yes,resizable=yes,  status=no,dependent=no, toolbar=no,menubar=no', 'LL','TRUE');
    }
    
    else
    {
        found_reuse_tab = 'false';
        set_reuse_id = '';
        
                //
                // if a tab_reuse_id was specified, then we check the tabs to see if the tab already exists.
                //
                
        // alert("parm_tab_properties['tab_reuse_id']=" + parm_tab_properties['tab_reuse_id']);

        if(parm_tab_properties['tab_reuse_id'] != '' 
           && parm_tab_properties['tab_reuse_id'] !== undefined)
        {  
            var set_reuse_id = parm_tab_properties['tab_reuse_id'];
            
            for(var index in top.tab_bar_tab_container.tab_array)
            {
                current_reuse_id = top.tab_bar_tab_container.tab_array[index].reuse_id;
                
                if(set_reuse_id == current_reuse_id)
                {
                    top.tab_bar_tab_container.make_active(index);
                    found_reuse_tab = 'true';
                }
            }
        }

                // 
                // If no tab to re-use was found, then we just continue as normal and create a new tab.
                //
        if( found_reuse_tab == 'false')
        {
            var start_tab_id = top.tab_bar_tab_container.active_tab;
            var new_tab_id = top.aljs_create_empty_module_tab('page_tab_loading', 'page_tab_loading', parm_tab_properties['tab_level'], parm_tab_type);

            top.tab_bar_tab_container.tab_array[new_tab_id].reuse_id = set_reuse_id;

            aljs_change_tab_text(new_tab_id, parm_tab_title);
            top.aljs_load_url_in_specified_tab(new_tab_id, parm_url);

                          // new_tab_active will already do "make_active" on the empty module tab.
                          // so to get new_tab_inactive, we have to make the original tab the active tab.
            if(parm_tab_type == "new_tab_inactive")
            {
                top.tab_bar_tab_container.make_active(start_tab_id);
            }
        }
    }
}





// This function loads the url given in the specified tab, after
// adding to the url information about which tab to change the title of

function aljs_load_url_in_specified_tab(parm_tab_id, parm_url)
{
    var active_iframe;
    var use_url;

    //alert("parm_tab_id = [" +  parm_tab_id  + "]"
        //+"tab_bar_tab_container.tab_array[parm_tab_id] = [" +  tab_bar_tab_container.tab_array[parm_tab_id]  + "]"
    //);

    active_iframe = top.tab_bar_tab_container.tab_array[parm_tab_id].tab_content_id;

//    alert("active_iframe id = [" +  active_iframe  + "]"
//         + "active_iframe  = [" +  al_get_object(active_iframe)  + "]"
//        );

    use_url = parm_url + "&tab_to_change=" + parm_tab_id + "&module_tab_to_change=" + parm_tab_id;


    al_get_object(active_iframe).src = use_url;
}


// This function figures out which tab is the active tab for the page, and
// loads the given url into that tab

function aljs_load_url_in_active_tab(parm_url)
{
    var active_tab;

    active_tab = top.tab_bar_tab_container.active_tab;

    aljs_load_url_in_specified_tab(active_tab, parm_url);
}


function aljs_change_active_tab_text(tab_text)
{
    var active_tab;

    active_tab = top.tab_bar_tab_container.active_tab;

    aljs_change_tab_text(active_tab, tab_text);

}



function aljs_change_active_tab_icon(tab_icon)
{
    var active_tab;

    active_tab = top.tab_bar_tab_container.active_tab;

    aljs_change_tab_icon(active_tab, tab_icon);

}


function test_function()
{
//    var non_matching_frames;
//        alert("window.id = [" + window.id + "]\n"
//            + "window.name = [" + window.name + "]\n"
//            + "self.id = [" + self.id + "]\n"
//            + "self.name = [" + self.name + "]\n"
//            + "self.parent.name = [" + self.parent.name + "]\n"
//            + "self.parent.id = [" + self.parent.id + "]\n"
//                );
//
//    for(var cur_frame in top.frames)
//    {
//        if(top.frames[cur_frame] == self)
//        {
//            alert("MATCH!!!, frame [" + cur_frame + "] matches");
//        }
//        else
//        {
//            //alert("NO MATCH, frame [" + cur_frame + "] did not match");
//            non_matching_frames += "frame [" + cur_frame + "] did not match\n";
//        }
//    }
//
//    alert(non_matching_frames);

    var height_string = "";

//    if(! this.isIE)
//    {
//
//        height_string += "innerHeight = ["  + innerHeight + "]\n";
//    }
    
    height_string += "self.document.body.clientHeight = ["  + self.document.body.clientHeight + "]\n";
    height_string += "self.document.body.clientWidth = ["  + self.document.body.clientWidth + "]\n";
        
    //alert(height_string);

}


function aljs_change_tab_iframe_size(parm_tab_id)
{
    var target_iframe_id;
    var target_iframe;

	//alert("not resizing on a tab click....");
	//return;

    //alert("in aljs_change_tab_iframe_size, parm_tab_id = [" + parm_tab_id + "]");

    if(top.tab_bar_tab_container == null)            // return if there is no top tab bar
    {
        //alert("tab_bar_tab_container is null, exiting");
        return;    
    }

    if(top.tab_bar_tab_container.tab_array == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }

    if(top.tab_bar_tab_container.tab_array[parm_tab_id] == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }

    target_iframe_id = top.tab_bar_tab_container.tab_array[parm_tab_id].tab_content_id;

    //alert("target_iframe_id = [" + target_iframe_id + "]");


    target_iframe = top.document.getElementById(target_iframe_id);

    if(target_iframe == null)        // do not do this code if there is no element found
    {
        //alert("target_iframe is null, exiting");
        return;
    }

    //alert("target_iframe = [" + target_iframe + "]");

    var initial_display = target_iframe.style.display;

    //alert("initial_display = [" + initial_display + "]");
                                
                                // if the browser is IE and the iframe is currently hidden
                                // (style.display == none), then height and width will
                                // come back as 0.  We need to make it visible temporarily
                                // and switch it back to invisible after we get those 
                                // properties

    if(initial_display == "none")
    {
        //target_iframe.style.display = "block";
        // Dick does not want to do this all the time on the inactive
        // so we're disabling it jhj20070730

               // trickle up to set the height of all the frames above this one
        // JHJ20070829 - this causes things to have height that shouldn't
        //var tmp_node = target_iframe.parentNode;
        //while(tmp_node != null && tmp_node.nodeType == 1)
        //{
        //    tmp_node.height = target_iframe.height;
        //    tmp_node = tmp_node.parentNode;
        //}

        return;   // exit here without setting the size of the iframe.
    }
    

    //alert("clientWidth = [" + self.document.body.clientWidth + "]");

    //alert("height = [" + (self.document.body.clientHeight + 30) + "]\n" 
        //+ "width = [" + (self.document.body.clientWidth + 30) + "]\n"
        //);
            
    //if(self.document.body.clientWidth == 0)
    //{
        //alert("using 1024");
        //JHJTEST1//target_iframe.width =  1024 + 30;
        //target_iframe.width =  750;            // set to 750 because 1054 was too much
    //}
    //else
    //{
        //alert("using clientWidth = [" + self.document.body.clientWidth + "]");
        //target_iframe.width =  self.document.body.clientWidth + 30;
    //}

    //JHJ070725//target_iframe.height =  self.document.body.clientHeight + 30;

    if(self.document.body.clientHeight > 0)
    {
        target_iframe.height =  self.document.body.clientHeight;
    }
    //alert("clientWidth = [" + (self.document.body.clientWidth + 30) + "]");
    
    if(initial_display == "none")
    {
        target_iframe.style.display = "none";
    }

               // trickle up to set the height of all the frames above this one
    // JHJ20070829 - this causes things to have height that shouldn't
    //var tmp_node = target_iframe.parentNode;
    //while(tmp_node != null && tmp_node.nodeType == 1)
    //{
    //    tmp_node.height = target_iframe.height;
    //   tmp_node = tmp_node.parentNode;
    //}

}


// This function stores a reference to the current page's document in the tab object in the 
// parent window.  It uses parm_tab_set_name as the tab set name, parm_tab_to_change as the tab 
// in that set that it should change, and it also stores the parm_iframe_id in the Tab object

function aljs_store_tab_iframe_document_reference(parm_tab_set_name, parm_tab_to_change, parm_iframe_id)
{
    var tab_set_use_code;
    var tab_set_use;
    var tab_use;
    var item_exists;
    var use_iframe_id;

    //alert('in aljs_store_tab_iframe_document_reference');

    tab_set_use_code = "parent." + parm_tab_set_name;

    tab_set_use = eval(tab_set_use_code);

    //alert("tab_set_use name = [" + tab_set_use_code + "]");
    //alert("tab_set_use = [" + tab_set_use + "]");

    if(tab_set_use == null)        // do not do this code if there is no element found
    {
        return;
    }

    tab_use = tab_set_use.tab_array[parm_tab_to_change];


                                // loop through the iframe_id_array to see if 
                                // this item is already there and we can just 
                                // update it.

    use_iframe_id = parm_iframe_id;
    item_exists = false;

    //tab_use.iframe_id_array[use_iframe_id] = use_iframe_id;

    for(var ii = 0; ii < tab_use.iframe_id_array.length; ii++)
    {
        if(tab_use.iframe_id_array[ii] == use_iframe_id)
        {
            item_exists = true;    
        }
    }

    //alert("iframe [" + use_iframe_id + "] tab [" + parm_tab_to_change + "]");
                                // if the item was not in the array yet
    if( ! item_exists)
    {
                                // add the item to the array

        //alert("adding iframe [" + use_iframe_id + "] to tab [" + parm_tab_to_change + "]");
        tab_use.iframe_id_array.push(use_iframe_id);
    }

    tab_use.child_iframe_document_ref_array[use_iframe_id] = self.document;

	//alert("added child_iframe_document_ref_array[" + use_iframe_id + "] = " + tab_use.child_iframe_document_ref_array[use_iframe_id]);

	//alert("iframe_id_array length=" + tab_use.iframe_id_array.length);
	// cant do this // alert("child_iframe_document_ref_array length=" + tab_use.child_iframe_document_ref_array.length);

    ///////// Debug only

    //var debug_string = "";

    //for( var item in tab_use)
    //{
        //debug_string += "tab_use[" + item + "] = [" + tab_use[item] + "]\n";
    //}

    //debug_string += "\n\ntab_use.child_iframe_document_ref_array = [" + tab_use.child_iframe_document_ref_array + "]";
    //debug_string += "\n\ntab_use.iframe_id_array = [" + tab_use.iframe_id_array + "]";

    //alert(debug_string);


    ///////// End Debug only


                            // if the window that this iframe is in isn't the top 
                            // window, store a reference to the document in the 
                            // module tab 
    if(parent != top)
    {
        tab_set_use = top.tab_bar_tab_container;

        //alert("tab_set_use = [" + tab_set_use + "]");

        if(tab_set_use == null)
        {
            //alert("top.tab_bar_tab_container is null");
            return;
        }


						// get the tab id
        if(iframe_info_obj != null && iframe_info_obj.module_tab_to_change != null)
        {
            use_iframe_id = iframe_info_obj.module_tab_to_change;
            //alert("tab_id = [" + use_iframe_id + "]");



        }
        else
        {
            //alert("iframe_info_obj.module_tab_to_change does not exist");
            return;
        }


        tab_use = null;

				// use the tab id to get the iframe
        tab_use = tab_set_use.tab_array[use_iframe_id];

        use_iframe_id = tab_set_use.tab_array[use_iframe_id].tab_content_id;

        if(tab_use == null)
        {
            alert("ERROR, could not find the tab for this iframe. quitting");
            return;
        }




                                    // loop through the iframe_id_array to see if 
                                    // this item is already there and we can just 
                                    // update it.
                                    // store it with the iframe_id of the current iframe (parm_iframe_id),
                                    // NOT the iframe id of the top level iframe (use_iframe_id), because
                                    // there will be multiple's with the top level iframe
                                    // if we do that (one overwrites the other)

        item_exists = false;

        //tab_use.iframe_id_array[use_iframe_id] = use_iframe_id;

        //alert("tab_use.iframe_id_array = [" + tab_use.iframe_id_array + "]");

        for(var ii = 0; ii < tab_use.iframe_id_array.length; ii++)
        {
            if(tab_use.iframe_id_array[ii] == parm_iframe_id)
            {
                item_exists = true;    
            }
        }

                                    // if the item was not in the array yet
        if( ! item_exists)
        {
                                    // add the item to the array

            //alert("adding2 iframe [" + parm_iframe_id + "] to tab [" + parm_tab_to_change + "]");
            tab_use.iframe_id_array.push(parm_iframe_id);
        }



        //tab_use.child_iframe_document_ref_array[use_iframe_id] = self.document;
        tab_use.child_iframe_document_ref_array[parm_iframe_id] = self.document;

		//alert("added2 child_iframe_document_ref_array[" + parm_iframe_id + "] = " + tab_use.child_iframe_document_ref_array[parm_iframe_id]);

		//alert("iframe_id_array length=" + tab_use.iframe_id_array.length);

        //alert("storing document reference in module tab, use_iframe_id = [" + parm_iframe_id + "]\n"
            //+ "new count = [" + tab_use.child_iframe_document_ref_array.length  + "]\n");

    }



}


//
// aljs_lock_tab - this function locks the module tab specified by parm_tab_id
//

function aljs_lock_tab(parm_tab_id)
{
    var target_element;
    var target_child_array;
    var target_td;
    var target_img;


    target_element = top.document.getElementById(parm_tab_id);

    if(target_element == null)        // do not do this code if there is no element found
    {
        return;
    }


                            // get a reference to the right cell, the one that has the
                            // close image in it

    //alert("target_element = [" + target_element + "]");

    target_child_array = target_element.getElementsByTagName("td");

    //alert("target_child_array = [" + target_child_array + "]\n"
    //+ "target_child_array.length = [" + target_child_array.length + "]");

    target_td = target_child_array[2];

    //alert("target_td = [" + target_td + "]");


    target_child_array = target_td.getElementsByTagName("img");

    target_img = target_child_array[0];

    //alert("target_img = [" + target_img + "]");

    
                                            // set the tab's close (x) button to a lock

    target_img.src = code_base_pathname + "images/lock_closed.png";

    target_img.onclick = null;

                                            // set the tab's flag to show that it is locked

    
    top.tab_bar_tab_container.tab_array[parm_tab_id].locked_state = true;

}




//
// aljs_unlock_tab - this function unlocks the module tab specified by parm_tab_id
//

function aljs_unlock_tab(parm_tab_id)
{
    var target_element;
    var target_child_array;
    var target_td;
    var target_img;


    target_element = top.document.getElementById(parm_tab_id);

    if(target_element == null)        // do not do this code if there is no element found
    {
        return;
    }


                            // get a reference to the right cell, the one that has the
                            // close image in it

    //alert("target_element = [" + target_element + "]");

    target_child_array = target_element.getElementsByTagName("td");

    //alert("target_child_array = [" + target_child_array + "]\n"
    //+ "target_child_array.length = [" + target_child_array.length + "]");

    target_td = target_child_array[2];

    //alert("target_td = [" + target_td + "]");


    target_child_array = target_td.getElementsByTagName("img");

    target_img = target_child_array[0];

    //alert("target_img = [" + target_img + "]");

    
                                            // set the tab's lock button to a close (x)

    target_img.src = code_base_pathname + "images/record_close_bttn.gif";

    target_img.onclick = function() { aljs_close_module_tab(parm_tab_id); return(true); };

                                            // set the tab's flag to show that it is locked

    
    top.tab_bar_tab_container.tab_array[parm_tab_id].locked_state = false;

}





//  aljs_change_tab_text - changes the text displayed in a tab
//
// parms -
//        parm_tab_id - id of the tab to change
//        tab_text  - the text we will be putting in the tab
//        condensed_override - an override that allows us to set the
//                            tab to condensed or non-condensed when it
//                            goes against the default behavior
//        

function aljs_change_tab_text(parm_tab_id, tab_text, condensed_override)
{
    var target_element;
    var target_child_array;
    var target_a;
    var icon_target_a;
    var tab_text_use = "";

    //alert("in aljs_change_tab_text\n" 
        //+ "parm_tab_id = [" + parm_tab_id + "]\n"
        //+ " tab_text = [" + tab_text + "]\n"
        //);

    //alert("self.document.title = [" + self.document.title + "]");


    target_element = top.document.getElementById(parm_tab_id);

    if(target_element == null)        // do not do this code if there is no element found
    {
        return;
    }


                                    // store the tab title

    top.tab_bar_tab_container.tab_array[parm_tab_id].tab_title = tab_text;


    //alert("target_element = [" + target_element + "]");

    target_child_array = target_element.getElementsByTagName("a");

    //alert("target_child_array = [" + target_child_array + "]\n"
    //+ "target_child_array.length = [" + target_child_array.length + "]");

    target_a = target_child_array[1];

    //alert("target_a = [" + target_a + "]");
    
                                // if the tab is active, set it to the full text,
                                // otherwise set it to the abbreviated

    if((parm_tab_id == top.tab_bar_tab_container.active_tab && condensed_override != "condensed") || condensed_override == "non_condensed")
    {
        target_a.innerHTML = tab_text;
    }
    else if(condensed_override == "condensed")
    {
        target_a.innerHTML = aljs_get_condensed_text(tab_text);
    }
    else if(top.tab_bar_tab_container.always_expanded == true)
    {
        target_a.innerHTML = tab_text;
    }
    else
    {
        target_a.innerHTML = aljs_get_condensed_text(tab_text);
    }

                            // set the title attribute in the anchor

    target_a.title = tab_text;


    
                            // set the title attribute in the icon anchor

    icon_target_a = target_child_array[0];


    icon_target_a.title = tab_text;

}


// this function takes a full tab title string and returns a shortened version
// containing a couple of letters and then ...

function aljs_get_condensed_text(tab_text)
{

    var condensed_text = tab_text.substr(tab_text, 2) + "..";

    //alert("tab_text = [" + tab_text + "]\n"
            //+ "condensed_text = [" + condensed_text + "]\n");
                        

    return condensed_text;

}

//
// function aljs_condense_all_tab_titles takes all of the module tab
// titles and puts them into their condensed versions
//

function aljs_condense_all_tab_titles()
{
    var tab_text;


    for(var index in top.tab_bar_tab_container.tab_array)
    {
        tab_text = top.tab_bar_tab_container.tab_array[index].tab_title;

        aljs_change_tab_text(index, tab_text, "condensed");
    }
}

//
// function aljs_expand_all_tab_titles takes all of the module tab
// titles and puts them into their expanded versions
//

function aljs_expand_all_tab_titles()
{
    var tab_text;


    for(var index in top.tab_bar_tab_container.tab_array)
    {
        tab_text = top.tab_bar_tab_container.tab_array[index].tab_title;

        aljs_change_tab_text(index, tab_text, "non_condensed");
    }
}

//
// function aljs_set_tabs_always_expanded makes all tabs expand and then
// locks them that way so they don't contract until that option is unset
//

function aljs_set_tabs_always_expanded()
{
    aljs_expand_all_tab_titles();

    top.tab_bar_tab_container.always_expanded = true;
}


//
// function aljs_unset_tabs_always_expanded makes it so module tabs
// begin to shrink again when you deselect them
//

function aljs_unset_tabs_always_expanded()
{
    top.tab_bar_tab_container.always_expanded = false;
}



//
// function aljs_hide_inactive_module_tabs hides all tabs except for
// the currently active one
//

function aljs_hide_inactive_module_tabs()
{

    var target_element;

    aljs_show_all_module_tabs();

                            // loop through all the items in the module tab tab_array

    for(var index in top.tab_bar_tab_container.tab_array)
    {
        target_element = top.document.getElementById(index);

        if(target_element == null)        // do not do this code if there is no element found
        {
            return;
        }

                                        // if this current tab is not the active tab,
                                        // then hide it
        if(index != top.tab_bar_tab_container.active_tab)
        {
                                        // set the li element to be hidden
            target_element.style.display = "none";
        }
    }

}

//
// function aljs_show_all_module_tabs unhides all module tabs that
// were hidden
//

function aljs_show_all_module_tabs()
{
    var target_element;

                            // loop through all the items in the module tab tab_array

    for(var index in top.tab_bar_tab_container.tab_array)
    {
        target_element = top.document.getElementById(index);

        if(target_element == null)        // do not do this code if there is no element found
        {
            return;
        }

                                        // set the li element to be displayed
        target_element.style.display = "inline";
    }
}


//
// function aljs_hide_locked_module_tabs hides any module tabs that have their
// locked flag set to true, leaving only the the unlocked tabs visible
//

function aljs_hide_locked_module_tabs()
{
    var target_element;

    aljs_show_all_module_tabs();

                            // loop through all the items in the module tab tab_array

    for(var index in top.tab_bar_tab_container.tab_array)
    {
        target_element = top.document.getElementById(index);

        if(target_element == null)        // do not do this code if there is no element found
        {
            return;
        }

                                        // if this current tab is locked then hide it
        if( top.tab_bar_tab_container.tab_array[index].locked_state == true)
        {
                                        // set the li element to be hidden
            target_element.style.display = "none";
        }
    }

}


//
// function aljs_hide_unlocked_module_tabs hides any module tabs that have their
// locked flag set to false, leaving only the the locked tabs visible
//

function aljs_hide_unlocked_module_tabs()
{
    var target_element;

    aljs_show_all_module_tabs();

                            // loop through all the items in the module tab tab_array

    for(var index in top.tab_bar_tab_container.tab_array)
    {
        target_element = top.document.getElementById(index);

        if(target_element == null)        // do not do this code if there is no element found
        {
            return;
        }

                                        // if this current tab is locked then hide it
        if( top.tab_bar_tab_container.tab_array[index].locked_state == false)
        {
                                        // set the li element to be hidden
            target_element.style.display = "none";
        }
    }

}



/* ************* this is the old way using cls_icon (no longer have a cls_icon)
function aljs_change_tab_icon(parm_tab_id, tab_icon)
{
    var target_element;
    var target_child_array;
    var target_img;

    //alert("in aljs_change_tab_icon\n" 
        //+ "parm_tab_id = [" + parm_tab_id + "]\n"
        //+ " tab_icon = [" + tab_icon + "]\n"
        //);

    //alert("self.document.title = [" + self.document.title + "]");


    target_element = top.document.getElementById(parm_tab_id);

    if(target_element == null)        // do not do this code if there is no element found
    {
        return;
    }

    //alert("target_element = [" + target_element + "]");

    target_child_array = target_element.getElementsByTagName("img");

    //alert("target_child_array = [" + target_child_array + "]\n"
    //+ "target_child_array.length = [" + target_child_array.length + "]");

              // only update the image that has the name cls_icon, because the position of the img may change
    for(ii=0;ii<target_child_array.length;ii++)
    {
        target_img = target_child_array[ii];
        if(target_img.name == "cls_icon")
        {


            //alert("target_img = [" + target_img + "]");
       
            target_img.src = tab_icon;
        }
 
    }

}
************************* */
//# and here we locate the 5th cell and update it's image./

function aljs_change_tab_icon(parm_tab_id, tab_icon)
{
    var target_element;
    var target_child_array;
    var target_img;
    var target_img_cell;

    //alert("in aljs_change_tab_icon\n" + "parm_tab_id = [" + parm_tab_id + "]\n" + " tab_icon = [" + tab_icon + "]\n" );

    //alert("self.document.title = [" + self.document.title + "]");


    target_element = top.document.getElementById(parm_tab_id);

    if(target_element == null)        // do not do this code if there is no element found
    {
        return;
    }

    target_img_cell = "cell5_" + parm_tab_id;

    //alert("target_img_cell = [" + target_img_cell + "]");

    target_element = top.document.getElementById(target_img_cell);

    if(target_element == null)        // do not do this code if there is no element found
    {
        return;
    }

    target_child_array = target_element.getElementsByTagName("a");

    //alert("target_child_array = [" + target_child_array + "]\n" + "target_child_array.length = [" + target_child_array.length + "]");

              // only update the image that has the name cls_icon, because the position of the img may change
    for(ii=0;ii<target_child_array.length;ii++)
    {
        target_img = target_child_array[ii];

        //alert("target_img.type=" + target_img.type + ", target_img.name="+target_img.name);

        target_child_array2 = target_element.getElementsByTagName("img");
        //alert("target_child_array2 = [" + target_child_array2 + "]\n" + "target_child_array2.length = [" + target_child_array2.length + "]");
        for(jj=0;jj<target_child_array2.length;jj++)
        {
            target_img2 = target_child_array2[ii];
            //alert("target_img2.type=" + target_img2.type + ", target_img2.name="+target_img2.name);

            //alert("target_img2 = [" + target_img2 + "], tab_icon=" + tab_icon);

            target_img2.src = tab_icon;
        }

    }

}


function aljs_change_tab_class(parm_tab_id, parm_tab_class)
{
    var target_element;
    var target_child_array;
    var target_p;

    //alert("in aljs_change_tab_class\n" 
        //+ "parm_tab_id = [" + parm_tab_id + "]\n"
        //+ " parm_tab_class = [" + parm_tab_class + "]\n"
        //);

    if(top.tab_bar_tab_container == null)            // return if there is no top tab bar
    {
        return;    
    }

    if(top.tab_bar_tab_container.tab_array == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }

    if(top.tab_bar_tab_container.tab_array[parm_tab_id] == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }
    target_element = top.document.getElementById(parm_tab_id);

    //alert("target_element = [" + target_element + "]");

    if(target_element == null)        // do not do this code if there is no element found
    {
        return;
    }

    //alert("target_element = [" + target_element + "]");

    target_element.className = parm_tab_class;


}


function aljs_store_tab_recnum(parm_tab_id, parm_tab_recnum)
{

    if(top.tab_bar_tab_container == null)            // return if there is no top tab bar
    {
        return;    
    }

    if(top.tab_bar_tab_container.tab_array == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }

    if(top.tab_bar_tab_container.tab_array[parm_tab_id] == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }
    top.tab_bar_tab_container.tab_array[parm_tab_id].tab_recnum = parm_tab_recnum;


    var debug_string = "";

    //for(var index in top.tab_bar_tab_container.tab_array)
    //{
        //debug_string += "tab_array[" + index + "].tab_recnum = [" + top.tab_bar_tab_container.tab_array[index].tab_recnum + "]\n";
    //}

    //alert(debug_string);

                                    // once the tab is loaded into memory, store it in the session tabset.
    if(top.button_save_session_tabset != null)
    {
        top.button_save_session_tabset.click();
    }

}


function aljs_store_tab_module_class(parm_tab_id, parm_tab_module_class)
{

    if(top.tab_bar_tab_container == null)            // return if there is no top tab bar
    {
        return;    
    }

    if(top.tab_bar_tab_container.tab_array == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }

    if(top.tab_bar_tab_container.tab_array[parm_tab_id] == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }
    top.tab_bar_tab_container.tab_array[parm_tab_id].tab_module_class = parm_tab_module_class;


    //alert(debug_string);
}







function aljs_change_active_tab_properties(parm_active_class, parm_inactive_class, parm_tab_text)
{
//    alert("in aljs_change_active_tab_properties,\n"
//        + "parm_active_class = [" + parm_active_class + "]\n"
//        + "parm_inactive_class = [" + parm_inactive_class + "]\n"
//        + "parm_tab_text = [" + parm_tab_text + "]\n"
//    );

    var active_tab;
                            // get the id of the active iframe to laod the url into

    active_tab = top.tab_bar_tab_container.active_tab;

    aljs_change_tab_properties(active_tab, parm_active_class, parm_inactive_class, parm_tab_text);

}

function aljs_change_tab_properties(parm_tab_id, parm_active_class, parm_inactive_class, parm_tab_text)
{
//    alert("in aljs_change_tab_properties,\n"
//        + "parm_tab_id = [" + parm_tab_id + "]\n"
//        + "parm_active_class = [" + parm_active_class + "]\n"
//        + "parm_inactive_class = [" + parm_inactive_class + "]\n"
//        + "parm_tab_text = [" + parm_tab_text + "]\n"
//    );

    aljs_change_tab_text(parm_tab_id, parm_tab_text);

    aljs_change_tab_classes(parm_tab_id, parm_active_class, parm_inactive_class);

}


function aljs_change_tab_classes(parm_tab_id, parm_active_class, parm_inactive_class)
{
    //alert("changing tab classes for tab_id = [" + parm_tab_id + "] to [" + parm_active_class + "] and [" + parm_inactive_class + "]");
    if(top.tab_bar_tab_container == null)            // return if there is no top tab bar
    {
        return;    
    }

    if(top.tab_bar_tab_container.tab_array == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }

    if(top.tab_bar_tab_container.tab_array[parm_tab_id] == null)
    {
        //alert("no tab at the given index, exiting");
        return;    
    }
    top.tab_bar_tab_container.tab_array[parm_tab_id].active_style = parm_active_class;
    top.tab_bar_tab_container.tab_array[parm_tab_id].inactive_style = parm_inactive_class;

    if(top.tab_bar_tab_container.active_tab == parm_tab_id)
    {
        //alert("changing active tab class classes are to active =[" + parm_active_class + "] and inactive = [" + parm_inactive_class + "]");
        aljs_change_tab_class(parm_tab_id, parm_active_class);
    }
    else
    {
        aljs_change_tab_class(parm_tab_id, parm_inactive_class);
    }
}



// this function creates a new tab in the tab_bar_tab_container tab set.  It adds
// a list item to the list that represents the tabs, and it creates a new iframe
// in the "center_wrapper_middle_body" div

// this function returns the id of the tab item that it creates
//
// parm_active_class is the css stylesheet to use for an active tab
// parm_inactive_class is the css styleshee tto use for an inactive tab
// parm_tab_level is the level to use on this tab instead of the default (that of the active tab)

function aljs_create_empty_module_tab(parm_active_class, parm_inactive_class, parm_tab_level, parm_tab_type)
{

    var module_div;
    var module_list;
    var new_iframe;
    var tab_id;
    var tab_content_id;

    var new_list_item;
    var new_anchor;
    var new_image;
    var new_table;
    var new_tbody;
    var new_row;
    var left_cell;
    var middle_cell;
    var right_cell;

    var cell1;
    var cell2;
    var cell3;
    var cell4;

    var cell1_id;
    var cell2_id;
    var cell3_id;
    var cell4_id;
    var cell5_id;
    var cell6_id;
    var cell7_id;

    var new_menu;

    var menu_string;
    var script_tag;
    var next_tab_id;
    var use_tab_level;

    //
    // Get tab ordering method setting
    //
    // 1 - put new tabs at the top of the open-windows list
    // 2 - put new tabs immediately following the current tab
    //

    var tq1_settings_open_windows_ordering_method = aljs_get_element_value("tq1_settings_open_windows_ordering_method");

    //
    // Get tab_level_0 placement setting
    //
    // 1 - put new tab_level_0 tabs at the top of the open-windows list
    // 2 - put new tab_level_0 tabs at the bottom of the open-windows list
    //

    var tq1_settings_tab_level0_placement = aljs_get_element_value("tq1_settings_tab_level0_placement");

  /* ****
    alert(
          "function=aljs_create_empty_module_tab\n" +
          "parm_active_class=[" + parm_active_class + "]\n" +
          "parm_inactive_class=[" + parm_inactive_class + "]\n" +
          "parm_tab_level=[" + parm_tab_level + "]\n" +
          "tq1_settings_open_windows_ordering_method=[" + tq1_settings_open_windows_ordering_method + "]\n" +
          "tq1_settings_tab_level0_placement=[" + tq1_settings_tab_level0_placement + "]\n" 
          );
  **** */


    //
    // Set up the "use_tab_level" value based on the ordering method
    //

    if( tq1_settings_open_windows_ordering_method == "2")
    {
        if(parm_tab_level === undefined)
        {
            use_tab_level = 1;
        }
        else
        {
            use_tab_level = parm_tab_level;
        }
    }
    else
    {
        use_tab_level = 0; // - this makes it so all new tabs go to top  9884-4-22-11428 #// 
    }



                            // increment the tab index number and use the new number in
                            // the instance_id that we create

    new_tab_num++;


    tab_content_id = "module_" + new_tab_num;
    tab_id = "module_" + new_tab_num + "_tab";

    //alert("new_tab_num = [" + new_tab_num + "]\n"
        //+ "tab_content_id = [" + tab_content_id + "]\n"
        //+ "tab_id = [" + tab_id + "]\n"
        //);

                            // create a new iframe and set its attributes to the defaults

    new_iframe = document.createElement("iframe");
    new_iframe.height = "400px";
    //new_iframe.height = "600px";
    //new_iframe.width = 800;
    //new_iframe.width = 750;        /// set to 750 to match sizing for Serena's stylesheet
    //new_iframe.width = "100%";
    new_iframe.setAttribute("frameBorder", "0");
    new_iframe.setAttribute("marginWidth", "0px");
    new_iframe.setAttribute("marginHeight", "0px");
    new_iframe.style.display = "none";
    new_iframe.id = tab_content_id;
    new_iframe.name = tab_content_id;
    // new_iframe.className = "module_x_iframe";
    new_iframe.className = "center_wrapper_middle_body_iframe_hidden";


                            // put the new iframe in the module div

    module_div = al_get_object("center_wrapper_middle_body");
    module_div.insertBefore(new_iframe, module_div.childNodes[0]);




                                  // if we are using the global setting for vertical tab bars
                                  // then the tabs will be oriented for a vertical format
    if(Use_tab_bar_style == 'vertical')
    {

        new_list_item = document.createElement("li");
        new_list_item.id = tab_id;
        new_list_item.className = parm_inactive_class;

                                                // insert new item into the page

        module_list = al_get_object("module_tab_list");

        //# 9884-4-22-7809 #//   //# 9884-4-22-11428 #//
                         // default to no next tab
        next_tab_id = "0";   



                            // if there are tabs already open, attempt to append this current
                            // tab to the active_tab.  Otherwise just append at the end.
                            // the "active_tab" is the currently open tab.

        if(use_tab_level >= 1 && module_list.childNodes.length > 0)
        {
            var tmp_item = module_list.firstChild;
            var inserted = false;

            use_tab_level = parseInt(tab_bar_tab_container.tab_array[tab_bar_tab_container.active_tab].tab_lev) + 1;

            while(tmp_item != null)
            {
                if(tmp_item.id == tab_bar_tab_container.active_tab)
                {
                    if(tmp_item.nextSibling != null)
                    {
                        next_tab_id = tmp_item.nextSibling.id;

                        module_list.insertBefore(new_list_item, tmp_item.nextSibling);
                        inserted = true; 
                    }
                    else
                    {                           
                        module_list.appendChild(new_list_item);
                        inserted = true;
                    } 
                }
    
                tmp_item = tmp_item.nextSibling;
            }
                                            
            if(inserted == false)
            {
                module_list.appendChild(new_list_item);
                inserted = true;
            }
        }                                       
        else
        {
            //# 9884-4-22-7809 #//  // insert at sub-tab child level as first child

            //    
            // Get tab_level_0 placement setting
            //    
            // 1 - put new tab_level_0 tabs at the top of the open-windows list
            // 2 - put new tab_level_0 tabs at the bottom of the open-windows list
            //    

            if(tq1_settings_tab_level0_placement == "1")
            {     
                module_list.insertBefore(new_list_item, module_list.firstChild);
            }     
            else if(tq1_settings_tab_level0_placement == "2")
            {     
                module_list.appendChild(new_list_item);
            }     
            else  
            {     
                module_list.insertBefore(new_list_item, module_list.firstChild);
            }
        }   

                                                // the table directly inside of the li

        new_table = document.createElement("table");

        if (use_tab_level == 0) 
        {
           new_table.className = "tab_level0_table";
        }
         else
        {
           new_table.className = "tab_level_non0_table";
        }




    
        new_list_item.appendChild(new_table);

        new_tbody = document.createElement("tbody");
        new_table.appendChild(new_tbody);

        new_row = document.createElement("tr");
        new_tbody.appendChild(new_row);


                                                // left table cell

        left_cell = document.createElement("td");
        left_cell.className = "tab_left_vertical";
        new_row.appendChild(left_cell);


        cell1_id = "cell1_" + tab_id;  // cell1 - "+" image
        cell2_id = "cell2_" + tab_id;  // cell2 - "-" image
        cell3_id = "cell3_" + tab_id;  // cell3 - "x" image (close)
        cell4_id = "cell4_" + tab_id;  // cell4 - "^" popup button
        cell5_id = "cell5_" + tab_id;  // cell5 - class icon image
        cell6_id = "cell6_" + tab_id;  // cell6 - text for tab
        cell7_id = "cell7_" + tab_id;  // cell7 - empty

                                            // cell7 - initial table cell

        right_cell = document.createElement("td");

        if (use_tab_level = 0) right_cell.className = "tab_indent_lev0";
        else if (use_tab_level = 1) right_cell.className = "tab_indent_lev1";
        else if (use_tab_level = 2) right_cell.className = "tab_indent_lev2";
        else if (use_tab_level = 3) right_cell.className = "tab_indent_lev3";
        else if (use_tab_level = 4) right_cell.className = "tab_indent_lev4";
        else if (use_tab_level = 5) right_cell.className = "tab_indent_lev5";
        else right_cell.className = "tab_indent_lev6plus";

        right_cell.id = cell7_id;
        new_row.appendChild(right_cell);

                                            // cell1 is the expand button
        cell1 = document.createElement("td");
        cell1.className = "tab_left_vertical";
        cell1.id = cell1_id;
        //cell1.style.display = "inline";
        new_row.appendChild(cell1);

        new_image = document.createElement("img");
        new_image.src = Use_tab_expand_button;
        new_image.id = "show_" + tab_id;
        new_image.title = "Click to Show Options";
        new_image.onclick = function() { closeMenus(); al_get_object(cell1_id).style.display='none'; al_get_object(cell2_id).style.display=''; al_get_object(cell3_id).style.display=''; al_get_object(cell4_id).style.display=''; return(true);};
        new_image.style.display = "inline";
        cell1.appendChild(new_image);

                                            // cell2 is the contract button
        cell2 = document.createElement("td");
        cell2.className = "tab_left_vertical";
        cell2.id = cell2_id;
        cell2.style.display = "none";
        new_row.appendChild(cell2);

        new_image = document.createElement("img");
        new_image.src = Use_tab_contract_button;
        new_image.title = "Click to Hide Options";
        new_image.id = "hide_" + tab_id;
        new_image.onclick = function() { closeMenus(); al_get_object(cell1_id).style.display=''; al_get_object(cell2_id).style.display='none'; al_get_object(cell3_id).style.display='none'; al_get_object(cell4_id).style.display='none'; return(true);};
        new_image.style.display = "inline";
        cell2.appendChild(new_image);
                                                
                                                // cell3 is close box in left table cell
        cell3 = document.createElement("td");
        cell3.className = "tab_left_vertical";
        cell3.id = cell3_id;
        cell3.style.display = "none";
        new_row.appendChild(cell3);
        
        new_image = document.createElement("img");
        new_image.src = Use_tab_close_button;
        new_image.title = "Close This Tab's Open Window.";
        new_image.onclick = function() { closeMenus(); aljs_close_module_tab(tab_id); return(true); };
        new_image.style.display = "inline";
        cell3.appendChild(new_image);


                                                // cell4 - popup middle table cell
        
        cell4 = document.createElement("td");
        cell4.className = "tab_left_vertical";
        cell4.id = cell4_id;
        cell4.style.display = "none";
        new_row.appendChild(cell4);
                                                // popup link in middle table cell

        new_image = document.createElement("img");
        new_image.src = code_base_pathname + "/images/tab_menubtn_up.gif";
        new_image.title = "Open This Window in a Popup";
        // new_image.onclick = function() { aljs_setMousePos(event); aljs_open_tab_in_popup_window(tab_id); return(true); };
        // NTBF: if we get a chance, see why the setMousePos is failing in FireFox.  error is event is not defined.
        new_image.onclick = function() { aljs_open_tab_in_popup_window(tab_id); return(true); };
        new_image.style.display = "inline";
        cell4.appendChild(new_image);


                                                // middle table cell

        middle_cell = document.createElement("td");
        middle_cell.className = "tab_middle_vertical";
        middle_cell.id = cell5_id;
        new_row.appendChild(middle_cell);


                                                // class icon image in middle cell

        new_anchor = document.createElement("a");
        new_anchor.onclick =  function() { tab_bar_tab_container.make_active(tab_id);
                                                 // if the active tab contains a show button, then activate the show button
                                          // this cuts off too much space and the lib35 close button
                                          // replaces the need for it. Per Dick 20070926
                                          // if(al_get_object('show_' + tab_id) != null)
                                          //{
                                          //    al_get_object('show_' + tab_id).onclick();
                                          //}
                                        };

        new_image = document.createElement("img");
        new_image.src = Use_tab_loading_button;
        new_image.align = "center";
        new_image.name = "cls_icon";
        new_anchor.appendChild(new_image);

        middle_cell.appendChild(new_anchor);


                                                // middle table cell 2

        middle_cell = document.createElement("td");
        middle_cell.className = "tab_middle_vertical";
        middle_cell.id = cell6_id;
        new_row.appendChild(middle_cell);

                                                // text for the tab

        new_anchor = document.createElement("a");
        new_anchor.onclick =  function() { tab_bar_tab_container.make_active(tab_id);
                                                 // if the active tab contains a show button, then activate the show button
                                          // this cuts off too much space and the lib35 close button
                                          // replaces the need for it. Per Dick 20070926
                                          //if(al_get_object('show_' + tab_id) != null)
                                          //{
                                          //    al_get_object('show_' + tab_id).onclick();
                                          //}
                                        };

        new_anchor.appendChild(document.createTextNode("Empty " + new_tab_num));
        middle_cell.appendChild(new_anchor);














                                                // get the actual menu and insert it outside of the
                                                // tabs so the styling doesn't get screwed up
        
        new_menu = aljs_get_tab_context_menu(tab_content_id);
        al_get_object("tab_bar").appendChild(new_menu);

    }
    else                      // ELSE use our normal horizontal format for the tabs
    {
                                        // now create the tab element

        new_list_item = document.createElement("li");
        new_list_item.id = tab_id;
        new_list_item.className = parm_inactive_class;

                                                // insert new item into the page

        module_list = al_get_object("module_tab_list");

        next_tab_id = "0";   // default to no next tab

                            // if there are tabs already open, attempt to append this current
                            // tab to the active_tab.  Otherwise just append at the end.
                            // the "active_tab" is the currently open tab.

        if(use_tab_level >= 1 && module_list.childNodes.length > 0)
        {
            var tmp_item = module_list.firstChild;
            var inserted = false;

            use_tab_level = parseInt(tab_bar_tab_container.tab_array[tab_bar_tab_container.active_tab].tab_lev) + 1;

            while(tmp_item != null)
            {
                if(tmp_item.id == tab_bar_tab_container.active_tab)
                {
                    if(tmp_item.nextSibling != null)
                    {
                        next_tab_id = tmp_item.nextSibling.id;

                        module_list.insertBefore(new_list_item, tmp_item.nextSibling);
                        inserted = true; 
                    }
                    else
                    {                           
                        module_list.appendChild(new_list_item);
                        inserted = true;
                    } 
                }
    
                tmp_item = tmp_item.nextSibling;
            }
                                            
            if(inserted == false)
            {
                module_list.appendChild(new_list_item);
                inserted = true;
            }
        }                                       
        else
        {
            module_list.appendChild(new_list_item);
        } 

                                                // the table directly inside of the li

        new_table = document.createElement("table");
        new_table.className = "borderless_table";
        new_list_item.appendChild(new_table);

        new_tbody = document.createElement("tbody");
        new_table.appendChild(new_tbody);

        new_row = document.createElement("tr");
        new_tbody.appendChild(new_row);

                                                // left table cell

        left_cell = document.createElement("td");
        left_cell.className = "tab_left";
        new_row.appendChild(left_cell);

                                                // anchor within left table cell

        new_anchor = document.createElement("a");
        new_anchor.onclick =  function() { tab_bar_tab_container.make_active(tab_id); };
        left_cell.appendChild(new_anchor);

                                                // class icon image in left cell

        new_image = document.createElement("img");
        new_image.src = "images/logo_crm.gif";
        new_image.name = "cls_icon";
        new_image.align = "center";
        new_anchor.appendChild(new_image);

                                                // middle table cell

        middle_cell = document.createElement("td");
        middle_cell.className = "tab_middle";
        new_row.appendChild(middle_cell);

                                                // text for the tab

        new_anchor = document.createElement("a");
        new_anchor.onclick =  function() { tab_bar_tab_container.make_active(tab_id); };
        new_anchor.appendChild(document.createTextNode("Empty " + new_tab_num));
        middle_cell.appendChild(new_anchor);

                                                // right table cell

        right_cell = document.createElement("td");
        right_cell.className = "tab_right";
        new_row.appendChild(right_cell);


                                                // close box in right table cell

        new_image = document.createElement("img");
        new_image.src = code_base_pathname + "/images/record_close_bttn.gif";
        new_image.onclick = function() { closeMenus(); aljs_close_module_tab(tab_id); return(true); };
        new_image.style.display = "inline";
        right_cell.appendChild(new_image);


                                                // anchor in right table cell

        new_anchor = document.createElement("a");
        right_cell.appendChild(new_anchor);





                                                // dropdown menu in right cell

        // old pre-tigra stuff
        ///**********************
        new_image = document.createElement("img");
        new_image.src = code_base_pathname+"/images/tab_menubtn2.gif";
        new_image.align = "center";
        new_image.onclick = function(event) { return(buttonClick(event, tab_content_id + "_menu_1")); } ;
        new_image.onmouseover = function(event) { aljs_change_tab_image_on(event, tab_id); } ;
        new_image.onmouseout = function(event) { aljs_change_tab_image_off(event, tab_id); } ;
        new_anchor.appendChild(new_image);

                                                // get the actual menu and insert it outside of the
                                                // tabs so the styling doesn't get screwed up
        
        new_menu = aljs_get_tab_context_menu(tab_content_id);
        al_get_object("tab_bar").appendChild(new_menu);
        //****************************/
    }

    // new tigra stuff
    //******************

    //menu_string = aljs_get_tigra_tab_context_menu(tab_content_id);

                // open of script tag
    //script_tag = "<" + "script language=\"JavaScript\">\n\t<!--\n"

                // content of the script tag

    //script_tag += "function dyn_create_tigra_menu()\n\t{";
    //script_tag += "\t\tvar " + tab_content_id + "_menu_1 = " + menu_string + ";\n";

    //script_tag += "\t\talert('executing new menu code');\n";
    
    //script_tag += "\t\tnew menu (" + tab_content_id + "_menu_1" + ", MENU_POS_XP, {'frames':[]});\n"

    //script_tag += "\t}";

    
                // close of script tag
    //script_tag += "\n\t//-->\n\t</" + "script" + ">";


                // store the script in the anchor

    //new_anchor.innerHTML = script_tag;


    //dyn_create_tigra_menu();
    //******************//


                            // add the newly created items to the tab set 

    tab_bar_tab_container.add_tab(new Tab(tab_id, tab_content_id, "parent", parm_active_class, parm_inactive_class));
    tab_bar_tab_container.tab_array[tab_id].tab_menu_active_image = code_base_pathname+"/images/tab_menubtn2.gif";
    tab_bar_tab_container.tab_array[tab_id].tab_menu_inactive_image = "/images/tab_menubtn3.gif";

                            // set the level of the next tab to be 1 more than the tab we just
                            // inserted it as a sub-level of, or at a top level of 0
    tab_bar_tab_container.tab_array[tab_id].tab_lev = use_tab_level;

                            // set the sequence number to be either .01 less than the next sibling
                            // or 1 more than the current tab

    //alert("next_tab_id=" + next_tab_id);
    
    /* ********* this sequencing was flawed - if you are in tab seq 1.1 and your next tab is 1.2, then the tabs
                 you add between will repeat numbering.            
    if(next_tab_id != "0"  && next_tab_id != null && next_tab_id != "")
    {
        //alert("next_tab id=" + next_tab_id + ", seq=" + tab_bar_tab_container.tab_array[next_tab_id].tab_seq);
        var new_tab_seq = tab_bar_tab_container.tab_array[next_tab_id].tab_seq - .01;
        tab_bar_tab_container.tab_array[tab_id].tab_seq = new_tab_seq;
    }
    else
    {
        //alert("active_tab id=" + tab_bar_tab_container.active_tab + ", seq=" + tab_bar_tab_container.tab_array[tab_bar_tab_container.active_tab].tab_seq);
        var new_tab_seq = tab_bar_tab_container.tab_array[tab_bar_tab_container.active_tab].tab_seq + 1;
        tab_bar_tab_container.tab_array[tab_id].tab_seq = new_tab_seq;
    }
    *********************************************************************** */

                                                // renumber all the sequences by the order they appear on the page

    module_list = al_get_object("module_tab_list");

    if(module_list.childNodes.length > 0)
    {
        var tmp_item = module_list.firstChild;
        var new_tab_seq = 1.0;


        while(tmp_item != null)
        { 
                   // the first tab could be the "new Tab" button, which does not have an entry in the tab array
            if(tab_bar_tab_container.tab_array[tmp_item.id] != null)
            {
                tab_bar_tab_container.tab_array[tmp_item.id].tab_seq = new_tab_seq;
    
                new_tab_seq = new_tab_seq + 1;
            }

            tmp_item = tmp_item.nextSibling;
        }       
                                                    
    }  

                      // only make this tab active if this is an active tab.
    if(parm_tab_type != "new_tab_inactive")
    {
        tab_bar_tab_container.make_active(tab_id);
    }
    return tab_id;
}


                                    // check the 

function aljs_change_tab_image_on(event, tab_id)
{
    var event_target;
    var li_item;
    var active_image = "";

    if(browser.isIE == true)
    {
        event_target = window.event.srcElement;
    }
    else
    {
        event_target = event.target;
    }

    li_item = event_target;
    
    while(li_item.tagName != "LI")
    {
        li_item = li_item.parentNode;
    }
    //alert("li_item.id = [" + li_item.id + "]\n"
      //+ "li_item.className = [" + li_item.className + "]\n"
      //+ "top.tab_bar_tab_container.tab_array[tab_id].tab_menu_active_image = [" + top.tab_bar_tab_container.tab_array[tab_id].tab_menu_active_image + "]"
      //+ "top.tab_bar_tab_container.tab_array[tab_id].tab_menu_inactive_image = [" + top.tab_bar_tab_container.tab_array[tab_id].tab_menu_inactive_image + "]"
      //);


                            // if the active image src is set
    if(top.tab_bar_tab_container.tab_array[tab_id].tab_menu_active_image )
    {
        event_target.src = top.tab_bar_tab_container.tab_array[tab_id].tab_menu_active_image;
    }

}


function aljs_change_tab_image_off(event, tab_id)
{
    var event_target;
    var li_item;
    var active_image = "";

    if(browser.isIE == true)
    {
        event_target = window.event.srcElement;
    }
    else
    {
        event_target = event.target;
    }

    li_item = event_target;
    
    while(li_item.tagName != "LI")
    {
        li_item = li_item.parentNode;
    }

                            // if the active image src is set
    if(top.tab_bar_tab_container.tab_array[tab_id].tab_menu_inactive_image )
    {
        if(li_item.className != "page_tab_active")
        {
            event_target.src = top.tab_bar_tab_container.tab_array[tab_id].tab_menu_inactive_image;
        }
    }
}



// this method creates the menu that pops up when you click on the the menu icon in one of the 
// module tabs

function aljs_get_tab_context_menu(tab_id_prefix)
{
    var return_div;
    var level1_div;
    var item_anchor;

    var tab_id = "";
    
    tab_id = tab_id_prefix + "_tab";


                                    // create the div that we'll return 

    return_div = document.createElement("div");


                                    // create the top level menu
    level1_div = document.createElement("div");

    level1_div.align = "left";
    level1_div.onmouseover = function(event) { menuMouseover(event); };
    level1_div.id = tab_id_prefix +  "_menu_1";
    level1_div.className = "menu";

    return_div.appendChild(level1_div);

                                    // create the anchor for the close window option

    item_anchor = document.createElement("a");
    item_anchor.align = "left";
    item_anchor.onclick = function() { closeMenus(); aljs_close_module_tab(tab_id); return(true); };
    item_anchor.className = "menuItem";
    item_anchor.appendChild(document.createTextNode("Close Tab"));

    level1_div.appendChild(item_anchor);


                                    // create the anchor for the open in new window option

    item_anchor = document.createElement("a");
    item_anchor.align = "left";
    item_anchor.onclick = function() { closeMenus(); aljs_setMousePos(event); aljs_open_tab_in_new_window(tab_id); return(true); };
    item_anchor.className = "menuItem";
    item_anchor.appendChild(document.createTextNode("Open in New Window"));

    level1_div.appendChild(item_anchor);


                                    // create the anchor for the open in popup window option

    item_anchor = document.createElement("a");
    item_anchor.align = "left";
    item_anchor.onclick = function() { closeMenus(); aljs_setMousePos(event); aljs_open_tab_in_popup_window(tab_id); return(true); };
    item_anchor.className = "menuItem";
    item_anchor.appendChild(document.createTextNode("Open in Popup Window"));

    level1_div.appendChild(item_anchor);


                                    // create the anchor for the lock tab option

    item_anchor = document.createElement("a");
    item_anchor.align = "left";
    item_anchor.onclick = function() { closeMenus(); aljs_setMousePos(event); aljs_lock_tab(tab_id); return(true); };
    item_anchor.className = "menuItem";
    item_anchor.appendChild(document.createTextNode("Lock Tab"));

    level1_div.appendChild(item_anchor);



                                    // create the anchor for the unlock tab option

    item_anchor = document.createElement("a");
    item_anchor.align = "left";
    item_anchor.onclick = function() { closeMenus(); aljs_setMousePos(event); aljs_unlock_tab(tab_id); return(true); };
    item_anchor.className = "menuItem";
    item_anchor.appendChild(document.createTextNode("Unlock Tab"));

    level1_div.appendChild(item_anchor);



                                    // create the anchor for the duplicate tab option

    item_anchor = document.createElement("a");
    item_anchor.align = "left";
    item_anchor.onclick = function() { closeMenus(); return(true); };
    item_anchor.className = "menuItem";
    item_anchor.appendChild(document.createTextNode("XXXXXDuplicate Tab"));

    level1_div.appendChild(item_anchor);


                                    // create the anchor for the reorder tabs option

    item_anchor = document.createElement("a");
    item_anchor.align = "left";
    item_anchor.onclick = function() { closeMenus(); return(true); };
    item_anchor.className = "menuItem";
    item_anchor.appendChild(document.createTextNode("XXXXXReorder Tabs"));

    level1_div.appendChild(item_anchor);



    return return_div;
}



function aljs_get_tigra_tab_context_menu(tab_id_prefix)
{

    var tab_id = "";
    var return_js = "";
    
    tab_id = tab_id_prefix + "_tab";

    //html_options->insert("id", tab_id_prefix +  "_menu_1");


                                    // get the start of the menu string that contains
                                    // information about the part of the menu that is 
                                    // displayed initially (the arrow icon)

    return_js = "\t[[[get_inactive_menu_icon(), get_active_menu_icon(), get_active_menu_icon()], null, null,\n";


                                    // create the anchor for the close window option



    return_js +=  "\t\t[wrap_child('Close Tab'), \"javascript: aljs_close_module_tab('" + tab_id + "');\", null ],\n";

                                    // create the anchor for the open in new window option



    return_js +=  "\t\t[wrap_child('Open in New Window'), \"javascript: aljs_open_tab_in_new_window('" + tab_id + "');\", null ],\n";

                                    // create the anchor for the duplicate tab option



    return_js +=  "\t\t[wrap_child('XXXXX Duplicate Tab'), \"javascript: \", null ],\n";

                                    // create the anchor for the reorder tabs option


    return_js +=  "\t\t[wrap_child('XXXXX Reorder Tabs'), \"javascript: \", null ]\n";


                                    // finish off the menu javascript

    return_js += "]\n]";

    return return_js;
}



// this function removes the tab with the given id from the page.  It removes all elements
// on the page that are related to that particular tab

function aljs_close_module_tab(parm_tab_id)
{
    var tab_to_remove 
    var tab_element;
    var tab_content_element;
    var tab_menu_element;
    var menu_string;
    var ii;
    var new_active_index;
    var current_tab_id;
    var new_tab_array;
    var index_to_remove = -10;
    var tab_array_length = 0;
    
    tab_to_remove = tab_bar_tab_container.tab_array[parm_tab_id];



    ii = 0;
    //var debug_string = "";
    for(current_tab_id in tab_bar_tab_container.tab_array)
    {
        ii++;
        //debug_string += "tab_id [" + ii + "] = [" + current_tab_id + "]\n";
    }
    //alert(debug_string);

    if(ii == 1)
    {
        alert("Sorry, you may not close the last tab");
        return;
    }

                                            // if the tab to delete is the active tab,
                                            // set the one after it to active if there is
                                            // one, otherwise the one before it


    if(tab_bar_tab_container.active_tab == parm_tab_id)
    {
                                                // loop through the tab_container to determine
                                                // if it's ok to remove this tab, and which 
                                                // tab to switch to
        new_active_index = "";
        ii = 0;

        for(current_tab_id in tab_bar_tab_container.tab_array)
        {
                                                // if the tab to remove is at this spot in the array

            if(tab_bar_tab_container.tab_array[current_tab_id] == tab_to_remove)
            {
                                                // store that number
                index_to_remove = ii;
                //alert("found tab to remove at index = [" + current_tab_id + "]");
            }

                                                // if this is the tab after the one to delete,
                                                // set it to active
            if(ii == (index_to_remove + 1))
            {
                //alert("1 setting tab [" + current_tab_id + "] to active\n"
                    //+ "ii = [" + ii + "]\n"
                    //+ "current_tab_id = [" + current_tab_id + "]");
                tab_bar_tab_container.make_active(current_tab_id);
                new_active_index = current_tab_id;
            }

            ii++;
        }
                                                
        tab_array_length = ii;
                                                // if there wasn't a tab after the one we're 
                                                // deleting, set the one before the last one to active

        if(new_active_index == "")
        {
            ii = 0;
            for(current_tab_id in tab_bar_tab_container.tab_array)
            {
                                                    // set it to active
                if((ii == (tab_array_length - 2)))
                {
                    //alert("2 setting tab [" + current_tab_id + "] to active\n"
                        //+ "ii = [" + ii + "]\n"
                        //+ "current_tab_id = [" + current_tab_id + "]");
                    tab_bar_tab_container.make_active(current_tab_id);
                    new_active_index = current_tab_id;
                }

                ii++;
            }
        }

    }

    new_tab_array = new Array();

                                            // copy all items but the one to remove into the 
                                            // new_tab_array and replace the original tab_array

    for(current_tab_id in tab_bar_tab_container.tab_array)
    {
                                            // if this is not the tab_to_remove
        if(current_tab_id != parm_tab_id)
        {
                                            // move the item to the new array
            new_tab_array[current_tab_id] = tab_bar_tab_container.tab_array[current_tab_id];
        }
        else
        {
            //alert("not moving tab at index [" + current_tab_id + "]");
        }
    }
                                            // replace the original tab array

    tab_bar_tab_container.tab_array = new_tab_array;

                                            // remove the tab from the bar

    tab_element = al_get_object(tab_to_remove.tab_id);
    tab_element.parentNode.removeChild(tab_element);


                                            // remove the tab content from the page (the IFRAME)

    tab_content_element = al_get_object(tab_to_remove.tab_content_id);
                     tab_content_element.src = "about:blank";
    tab_content_element.parentNode.removeChild(tab_content_element);
    
                                            // calculate the name of the div containing the
                                            // menus for this tab

    menu_string = parm_tab_id.substr(0, parm_tab_id.length - 4);
    menu_string += "_menu_1";

                                            // delete the div containing the menu div that
                                            // we just calculated the id of
    if(al_get_object(menu_string) != null)
    {
        tab_menu_element = al_get_object(menu_string).parentNode;
        tab_menu_element.parentNode.removeChild(tab_menu_element);
    }

    if(top.button_save_session_tabset != null)
    {
        top.button_save_session_tabset.click();
    }

}

// 
// This function gets the tab recnum for a given tab, adds it onto the base url that is
// stored as a hidden, and then opens the url in the new window
//

function aljs_open_tab_in_new_window(tab_id)
{
    var tab_object;
    var base_url_hidden; 
    var base_url;
    var tab_recnum; 
    var window_object = "";
    var use_url;

    var url_re;

    //alert("new window tab_id = [" + tab_id + "]");

    tab_recnum = top.tab_bar_tab_container.tab_array[tab_id].tab_recnum;

    if(tab_recnum == "")
    {
        alert("Please wait for the tab to finish loading");
        return;
    }

    //alert("tab_recnum = [" + tab_recnum + "]");

    base_url_hidden = al_get_object("base_url");

    //alert("base_url_hidden = [" + base_url_hidden + "]");
    base_url = base_url_hidden.value;

    //alert("url before = [" + base_url + "]");

    use_url = base_url + "&tab_load_flag=TRUE&tab_recnum=" + tab_recnum;


                                        // replace the original module_class in the url with the actual module_class that
                                        // is in the tab currently

    url_re = new RegExp("&module_class=\\w*", "g");

    
    //alert("url_re = " + url_re);

    use_url = use_url.replace(url_re, "&module_class=" + top.tab_bar_tab_container.tab_array[tab_id].tab_module_class);



    //alert("url after = [" + use_url + "]");


    window_object = window.open(use_url, "_blank", "", false);        // open a new window
    window_object.focus();

}


function aljs_open_tab_in_popup_window(tab_id)
{
    var tab_object;
    var base_url_hidden; 
    var base_url;
    var tab_recnum; 
    var window_object = "";
    var use_url;

    var url_re;

    //alert("popup window tab_id = [" + tab_id + "]");

    tab_recnum = top.tab_bar_tab_container.tab_array[tab_id].tab_recnum;

    if(tab_recnum == "")
    {
        alert("Please wait for the tab to finish loading");
        return;
    }

    //alert("tab_recnum = [" + tab_recnum + "]");

    base_url_hidden = al_get_object("base_url");

    //alert("base_url_hidden = [" + base_url_hidden + "]");
    base_url = base_url_hidden.value;

    //alert("url before = [" + base_url + "]");

    use_url = base_url + "&tab_load_flag=TRUE&page_type=PT_POPUP&tab_recnum=" + tab_recnum;


                                        // replace the original module_class in the url with the actual module_class that
                                        // is in the tab currently

    url_re = new RegExp("&module_class=\\w*", "g");

    
    //alert("url_re = " + url_re);

    use_url = use_url.replace(url_re, "&module_class=" + top.tab_bar_tab_container.tab_array[tab_id].tab_module_class);



    //alert("url after = [" + use_url + "]");

    var opts = "width=600,height=600,dependent=yes,resizable=yes, toolbar=no, status=no,  directories=no, menubar=no, scrollbars=yes";
    aljs_openWindow(use_url, "_blank", 600, 600, opts, true);

    //window_object = window.open(use_url, "_blank", "", false);        // open a new window
    //window_object.focus();

}






function aljs_change_tab_text_with_page_title(parm_tab_id)
{
    aljs_change_tab_text(parm_tab_id, self.document.title);
}








// this function works up through the DOM tree and checks to see if items are hidden.
// If they are hidden, it displays them, and then stores them in an array so they can
// be hidden again later.  The function returns the array of items that were changed
// to displayed

function aljs_set_node_parents_display(node_to_display)
{
    var current_node = node_to_display;
    var items_displayed_array = new Array();

    var ii = 0;

    while(current_node != top && ii < 1)
    {
        //alert("current_node = [" + current_node + "]\n"
            //+ "ii = [" + ii + "]\n"
        //);

        if(current_node.style.display == "none")
        {
            //alert("displaying current_node, ii = [" + ii + "]"); 
            items_displayed_array.push(current_node);
            current_node.style.display = "block";
        }

        ii++;
        current_node = current_node.parentNode;
    }
    
    return items_displayed_array;
}

// This function does the opposite of aljs_set_node_parents_display.  You should pass
// it the array of nodes created by that function, and this function will go through
// all of them and set the display to none

function aljs_set_hide_nodes(array_of_nodes)
{
    //alert("array_of_nodes.length = [" + array_of_nodes.length + "]");

    for(current_node in array_of_nodes)
    {
        //alert("array_of_nodes[" + current_node + "] = [" + array_of_nodes[current_node] + "]");
        
        array_of_nodes[current_node].style.display = "none";

    }

}




// ---------------------------------------------------------------------
// al_display_hidden_text
//
// function will load the content of a hidden variable into the display
// of another's content or erase it if it is not empty
//
// expecting the hidden field to be of type "hidden"
// expecting the display fields to be of type "anchor"
// ---------------------------------------------------------------------

function al_display_hidden_text(parm_hidden_text_field, parm_display_text_field)
{
    var tmp_str;

    //alert("hidden=" + parm_hidden_text_field + " \n anchro=" + parm_display_text_field);
    tmp_str = al_get_object(parm_display_text_field).innerHTML;

    //alert ("tmp_str = " + tmp_str);
    if(tmp_str == "" || tmp_str == " ")
    {
        al_get_object(parm_display_text_field).innerHTML = al_get_object(parm_hidden_text_field).value;
    }
    else
    {
        al_get_object(parm_display_text_field).innerHTML = "";

    }
    return(1);
}



// ---------------------------------------------------------------------
// al_get_content_form
//
// Function will return the object that is representative of the <form>
// which appears within the content section of the page
// currently that is represented by a div called content (id=content
//
// ---------------------------------------------------------------------
function al_get_content_form()
{
    var all_forms;
    var div_content;
    var ret_val;


    //if(browser.isNS)
    //{
    //    ret_val = document.getElementById(object_id);
    //}
    //else
    //{
    //    ret_val = document.all[object_id];
    //}

    div_content = document.getElementById("center_wrapper_middle_body");

    //alert("div_content = " + div_content);

    //  forms.0 is null or not an object
    //ret_val = div_content.forms[0];
    //

    //  divs do not support this method
    //all_forms = div_content.getElementsByTagName("form");
    //

    all_forms = div_content.childNodes;

    //alert("all_forms= " + all_forms);

    //alert("all_forms.length() = " + all_forms.length);

    for(ii=0;ii<15;ii++)
    {
        //alert("form name = " + all_forms.item(ii).nodeName);

        if(all_forms.item(ii).nodeName == "form" || all_forms.item(ii).nodeName == "FORM")
        {
            break;
        }
    }    

    ret_val = all_forms.item(ii);

    //alert("div_content.form = " + ret_val);

    return(ret_val);
}



// ---------------------------------------------------------------------
// al_get_object
//
// Function will return the object on the page with the given id
// this should be used rather than document.all[id] so it will be
// compatible with internet explorer and mozilla/netscape
//
// expecting the data to be a string, with the id of the object
// ---------------------------------------------------------------------

function al_get_object(object_id)
{
    var ret_val;


    //if(browser.isNS)
    //{
    //    ret_val = document.getElementById(object_id);
    //}
    //else
    //{
    //    ret_val = document.all[object_id];
    //}

    ret_val = document.getElementById(object_id);

                     // handle the possibility that someone requested a submit-button
                     // because the system automatically adds ICBTN__ before the id on a submit-button
    if(ret_val == null)
    {
        ret_val = document.getElementById("ICBTN__" + object_id);
    }


                // on a radio button we have a special case.
                // the element returned is the first on the page
                // but the actual element that we want for this is the one that is checked
                // so we need to get all the radio buttons and go through
                // and find the first one that is checked
                // so that we check the ACTIVE value of this element
                // and if none are checked, then the first one is returned
    if(ret_val == null || ret_val.type == 'radio')
    {
                         // note in IE the ret_val is returned for a NON-exact matching id
                         //      in FF null is returned unless the ID is an exact match
                         //      so on a null match, we will also check for elements which may be radio elements.
        var radio_list=document.getElementsByName(object_id);
        for(var ii=0;ii<radio_list.length;ii++)
        {
            if(radio_list[ii].type == 'radio' && radio_list[ii].checked)
            {
                ret_val = radio_list[ii];
                break;
            }
        }
    }


    return(ret_val);
}




// ---------------------------------------------------------------------
// al_get_span_object
//
// this function does the same thing as al_get_object, except
// if for some reason accessing the span item doesn't work using
// those methods, it will loop through all spans until it finds
// one with the correct id attribute
//
// expecting the data to be a string, with the id of the object
// ---------------------------------------------------------------------

function al_get_span_object(object_id)
{
    var ret_val;
    var ii;
    var span_array;


    if(browser.isNS)
    {
        ret_val = document.getElementById(object_id);
    }
    else
    {
        ret_val = document.all[object_id];
    }

    if(typeof ret_val == "undefined")
    {
        span_array = document.getElementsByTagName('span');

        for (ii=0; ii<span_array.length; ii++)
        {
            var current_id = span_array[ii].getAttribute('id');

            if(current_id && current_id == object_id)    // if this element has an id
            {
                ret_val = span_array[ii];
            }
        }
    }

    return(ret_val);
}


// ---------------------------------------------------------------------
// al_get_img_object
//
// this function does the same thing as al_get_object, except
// if for some reason accessing the img item doesn't work using
// those methods, it will loop through all imgs until it finds
// one with the correct id attribute
//
// expecting the data to be a string, with the id of the object
// ---------------------------------------------------------------------

function al_get_img_object(object_id)
{
    var ret_val;
    var ii;
    var img_array;


    if(browser.isNS)
    {
        ret_val = document.getElementById(object_id);
    }
    else
    {
        ret_val = document.all[object_id];
    }

    if(typeof ret_val == "undefined")
    {
        img_array = document.getElementsByTagName('img');

        for (ii=0; ii<img_array.length; ii++)
        {
            var current_id = img_array[ii].getAttribute('id');

            if(current_id && current_id == object_id)    // if this element has an id
            {
                ret_val = img_array[ii];
            }
        }
    }

    return(ret_val);
}



var popins_created = 0;

//
// aljs_create_popin_iframe will display the hidden popin location div with the given id
// and then create an iframe, set the iframe's url, and resize it to the given dimensions.
//


function aljs_create_popin_iframe(parm_div_id, parm_url, parm_height, parm_width, parm_show_close_warning)
{
    var target_div;

    var tr_element;
    var td_element;
    var tbody_element;
    var table_element;
    var img_element;
    var div_element;

    var iframe_id;
    var div_id;

    //alert("parm_div_id = [" + parm_div_id + "]\n"
            //+ "parm_url = [" + parm_url + "]\n"
            //+ "parm_height = [" + parm_height + "]\n"
            //+ "parm_width = [" + parm_width + "]\n"
            //);

                            // calculate id's

    iframe_id = "popin_iframe_" + popins_created;
    div_id = "div_" + iframe_id;

    popins_created++;

                            // get the target div
    
    target_div = al_get_object(parm_div_id);

    //target_div.style.display = "block";


                            // create the div

    div_element = document.createElement("div");
    div_element.id = div_id;
    div_element.className = "FT_popin_iframe_div";
    //div_element.width = (parseInt(parm_width) + 15)

    target_div.appendChild(div_element);

                            // create the table
                                    
    table_element = document.createElement("table");
    table_element.className = "FT_popin_iframe_table";

    div_element.appendChild(table_element);
    

    tbody_element = document.createElement("tbody");
    table_element.appendChild(tbody_element);

    tr_element = document.createElement("tr");
    tbody_element.appendChild(tr_element);

                            // table cell with close image

    td_element = document.createElement("td");
    // td_element.style.verticalAlign = "top";
    td_element.className = "FT_popin_iframe_img_cell";

    tr_element.appendChild(td_element);

                            // close image

    img_element = document.createElement("img");
    img_element.className = "FT_popin_iframe_img_content";
    img_element.src = "images/record_close_bttn.gif";
    // img_element.style.cursor = "pointer";

                                    // make the onclick that removes the popin from
                                    // the page 
    img_element.onclick = function()
                  {
                          var remove_div;
                        var confirm_text;

                        remove_div = al_get_object(div_id);

                                    // if we're supposed to confirm the close
                                    // before closing the window

                        if(parm_show_close_warning == true )
                        {
                            confirm_text = "Warning, closing this item will cause any changed, unsaved data to be lost.\n\n";
                            confirm_text += "Click OK to confirm close";

                                    // only close if the user clicked ok

                            if(confirm(confirm_text))
                            {
                                al_get_object(iframe_id).src = "about:blank";
                     remove_div.parentNode.removeChild(remove_div);
                            }
                        }
                        else
                        {
                            al_get_object(iframe_id).src = "about:blank";
                     remove_div.parentNode.removeChild(remove_div);
                        }

                        aljs_change_iframe_size();
                  };

    td_element.appendChild(img_element);

                            // create the cell for the popin data

    td_element = document.createElement("td");
    td_element.className = "FT_popin_iframe_cell";
    // td_element.width="100%";
    tr_element.appendChild(td_element);


                            // create a new iframe and set its attributes to the defaults

    new_iframe = document.createElement("iframe");
    new_iframe.className = "FT_popin_iframe_content";

    new_iframe.id = iframe_id;

    new_iframe.height = parm_height;
    new_iframe.width = parm_width;
    //new_iframe.setAttribute("frameBorder", 0);

    var url_use = parm_url;

    //alert("url_use before = [" + url_use + "]");

    url_use += "&popin_iframe_id=" + new_iframe.id;

    //alert("url_use after = [" + url_use + "]");

    td_element.appendChild(new_iframe);

    new_iframe.src = url_use; 
    //td_element.appendChild(new_iframe);  // order IS important - this here caused a new window on a popin link




    aljs_change_iframe_size();


}



function aljs_create_popin_in_page(parm_div_id, parm_url, parm_height, parm_width, parm_show_close_warning, parent_instance_id, parent_recnum, form_template_id)
{
    var target_div;

    var tr_element;
    var td_element;
    var tbody_element;
    var table_element;
    var img_element;
    var div_element;

    var iframe_id;
    var div_id;


    var tmp_iframe_html;
    var tmp_title_html;
    var title_div_html;
    var popup_div_html;
    var content_div_html;

    var form_template_html;
    var form_template_div;
    var new_form_html;
    var new_form_instance_id;

    var dynamic_form_storage_div;

    var popup_width;
    var popup_height;

    var instance_id_re;
    var parent_recnum_re;
    var parent_instance_id_re;


    //alert("parm_div_id = [" + parm_div_id + "]\n"
            //+ "parm_url = [" + parm_url + "]\n"
            //+ "parm_height = [" + parm_height + "]\n"
            //+ "parm_width = [" + parm_width + "]\n"
            //);

                            // calculate id's

    iframe_id = "popin_iframe_" + popins_created;
    div_id = "div_" + iframe_id;

    popins_created++;

                            // get the target div
    
    target_div = al_get_object(parm_div_id);

    target_div.style.display = "block";


                            // create the div

    div_element = document.createElement("div");
    div_element.id = div_id;

    target_div.appendChild(div_element);

                            // create the table
                                    
    table_element = document.createElement("table");
    div_element.appendChild(table_element);


    tbody_element = document.createElement("tbody");
    table_element.appendChild(tbody_element);

    tr_element = document.createElement("tr");
    tbody_element.appendChild(tr_element);

                            // table cell with close image

    td_element = document.createElement("td");
    tr_element.appendChild(td_element);
    td_element.style.verticalAlign = "top";

                            // close image

    img_element = document.createElement("img");
    img_element.src = "images/record_close_bttn.gif";
    img_element.style.cursor = "pointer";

                                    // make the onclick that removes the popin from
                                    // the page 
    img_element.onclick = function()
                  {
                          var remove_div;
                        var confirm_text;

                        remove_div = al_get_object(div_id);

                                    // if we're supposed to confirm the close
                                    // before closing the window

                        if(parm_show_close_warning == true )
                        {
                            confirm_text = "Warning, closing this item will cause any changed, unsaved data to be lost.\n\n";
                            confirm_text += "Click OK to confirm close";

                                    // only close if the user clicked ok

                            if(confirm(confirm_text))
                            {
                                remove_div.parentNode.removeChild(remove_div);
                            }
                        }
                        else
                        {
                            remove_div.parentNode.removeChild(remove_div);
                        }

                        aljs_change_iframe_size();
                  };

    td_element.appendChild(img_element);


                            // create the cell for the popin data

    td_element = document.createElement("td");
    tr_element.appendChild(td_element);


    /****************
    new_iframe = document.createElement("iframe");




                            // create a new iframe and set its attributes to the defaults

    new_iframe = document.createElement("iframe");

    new_iframe.id = iframe_id;

    new_iframe.height = parm_height;
    new_iframe.width = parm_width;
    //new_iframe.setAttribute("frameBorder", 0);

    var url_use = parm_url;
    //url_use += "&iframe_id=" + new_iframe.id;

    //alert("url_use = [" + url_use + "]");

    new_iframe.src = url_use; 
    td_element.appendChild(new_iframe);
    *****************/

                            // this.new_form_instance_id_num is a number that we will
                            // use to give all new dynamic forms a unique instance_id

                            

                            // if this.new_form_instance_id_num
    if(this.new_form_instance_id_num)
    {
                            // increment the number and use the new number in
                            // the instance_id that we create

        this.new_form_instance_id_num++;


    }
    else                    // otherwise
    {
                            // we need to initialize that number and then use it

        this.new_form_instance_id_num = 1;
    }


    new_form_instance_id = "js_form_" + this.new_form_instance_id_num;


    //alert("new_form_instance_id = " + new_form_instance_id);




                            // set parameters that may change based on the class
                            // and form being displayed

    popup_width = parm_width;    // for now just hard-code width
    popup_height = parm_height;    // for now just hard-code height




                            // get form_html from the div form_template_id, and edit it 
                            // so it has a real instance_id
                            

    form_template_div = al_get_object(form_template_id);

    //alert("form_template_div = " + form_template_div);

    form_template_html = form_template_div.innerHTML;

    //alert("form_template_html = " + form_template_html);


                            // create the regular expression object that contains the
                            // search string that we need to replace

    instance_id_re = new RegExp("template_instance_id", "g");

    
    //alert("instance_id_re = " + instance_id_re);

                            // call the replace method to replace all occurances of
                            // "template_instance_id" with our new 
    new_form_html = form_template_html.replace(instance_id_re, new_form_instance_id);


    //alert("new_form_html = " + new_form_html);

                            // create the regular expression that will replace the parent recnum
                            // of the record that will be the source of a relationship
                            // The c++ code needed this to be an integer, so we chose a large
                            // negative number that would never actually be a real recnum

    //parent_recnum_re = new RegExp("dynamic_parent_id", "g");
    parent_recnum_re = new RegExp("-9999999", "g");

    new_form_html = new_form_html.replace(parent_recnum_re, parent_recnum);


                            // create the regular expression that will replace the parent instance_id
                            // of the record that will be the source of a relationship

    //parent_instance_id_re = new RegExp("dynamic_parent_id", "g");
    parent_instance_id_re = new RegExp("dynamic_parent_instance_id", "g");

    new_form_html = new_form_html.replace(parent_instance_id_re, parent_instance_id);


    //alert("new_form_html = " + new_form_html);

                            // put the new html that we just created onto the page in
                            // the table cell that we created above

    td_element.innerHTML = new_form_html;


    aljs_change_iframe_size();

}







// ---------------------------------------------------------------------
// al_display_status_bar
//
// function will load text passed in into the status bar at top of page.
//
// expecting the data to be a string
// expecting the display field to be of type "anchor"
// ---------------------------------------------------------------------

function al_display_status_bar(parm_data, parm_display_text_field)
{
    var cell_obj;
    //alert ("tmp_str = " + tmp_str);
    if(parm_data != "" || parm_data != " ")
    {
            al_get_object(parm_display_text_field).innerHTML = parm_data;
    }
    else
    {
        al_get_object(parm_display_text_field).innerHTML = "";
    }
                                    // get a reference to the parent td object

    cell_obj = al_get_object(parm_display_text_field).offsetParent;

    cell_obj.style.borderColor = '#000000';
    cell_obj.style.borderStyle = 'solid';
    cell_obj.style.borderWidth= '2px';
    
    return(1);
}







// this function gets a clist from the server using parm_url and replaces
// the clist with the id stored in parm_clist_wrapper_id with the one the server
// returns

function aljs_get_dynamic_clist(parm_clist_wrapper_id, parm_url)
{
    var xmlhttp;
    var existing_clist_wrapper;
    var clist_html;
    
    //alert("in aljs_test_xmlhttp, parm_url = [" + parm_url + "]\nparm_clist_wrapper_id = [" + parm_clist_wrapper_id + "]");

    existing_clist_wrapper = al_get_object(parm_clist_wrapper_id);


    existing_clist_wrapper.innerHTML = "<span color=\"red\" >Loading Choices... Please Wait...</span>";

                        // create the xmlhttp object and get the 
                        // new choicelist using it

    xmlhttp = new_xmlhttp_object();


    //alert(parm_url);
    //alert(parm_url+"&rdm="+Math.random());

                            // NOTE: the rdm random number is here to prevent this type of URL from being cached.
                            //       if the URL is cached, it does not function, even if every time you click it
                            //       would generate something different.
                            //       the setRequestHeader() calls below don't work.  I found no real working example of them
                            //       to use, so I followed this example instead, since it does work

    xmlhttp.open("GET", parm_url +"&rdm="+Math.random(), true);

    

    xmlhttp.onreadystatechange = 
    function() 
    {
        if(xmlhttp.readyState == 4)
        {
                                    // replace the data that is currently inside of the
                                    // wrapper element with the new clist that we
                                    // just got

            clist_html = xmlhttp.responseText;

            existing_clist_wrapper.innerHTML = clist_html;

            //alert("sent xmlhttp request, response code = [" + xmlhttp.status + "]\n"
                //+ "statusText = [" + xmlhttp.statusText + "]\n"    
                //+ "responseText = [" + xmlhttp.responseText + "]\n"    
                //+ "responseXML = [" + xmlhttp.responseXML + "]\n"    
            //);
        }
    };


                                    // NOTE: the rdm random number is here to prevent this type of URL from being cached.
                                    //       if the URL is cached, it does not function, even if every time you click it
                                    //       would generate something different.
                                    //       the setRequestHeader() calls below don't work.  I found no real working example of them
                                    //       to use, so I followed this example instead, since it does work

    //alert("Setting the http headers");

    //xmlhttp.setRequestHeader("Pragma", "no-cache");
    //xmlhttp.setRequestHeader("Pragma", "no-store");
    //xmlhttp.setRequestHeader("cache-request-directive", "no-cache");
    //xmlhttp.setRequestHeader("cache-request-directive", "no-store");
    //xmlhttp.setRequestHeader("cache-response-directive", "no-cache");
    //xmlhttp.setRequestHeader("cache-response-directive", "no-store");
    xmlhttp.setRequestHeader("Cache-Control", "no-store");
    xmlhttp.setRequestHeader("Cache-Control", "no-cache");
    xmlhttp.setRequestHeader("Cache-Control", "must-revalidate");
    xmlhttp.send("");
}

//
// aljs_thread_updated_record
//     
//   run an AJAX request to process the URL and then display a response for the user
//
function aljs_thread_update_record(parm_url, success_msg, error_msg, async_mode, success_flag, error_flag)
{
    var xmlhttp;
    var response;
    var ii;
    var post_url;
    var get_url;                        
    var use_async;
    var alert_success_flag;
    var alert_error_flag;

                                   // default asynchronous to false, and use a flag to enable it.
    if(async_mode == "TRUE")
    {
         use_async = true;
    }
    else
    { 
         use_async = false;
    }

                                // default the success flag to FALSE and then set to true only if set from parms
    if(success_flag == "TRUE")
    {
        alert_success_flag = true;
    }
    else
    {
        alert_success_flag = false;
    }
                                
                                // default the error flag to TRUE and then set to false only if set from parms
    if(error_flag == "FALSE")
    {
        alert_error_flag = false;
    }
    else
    {
        alert_error_flag = true;
    }




                // add to the URL the error message, so that the page it is handed to may
                // use it in log_die and log_error messages
    if(error_msg != "")
    {
        parm_url += "&submit_rjs_update_error_message=" + error_msg;
    }

                // if the URL is too long, it may get rejected by the webserver.  So convert the URL into 
                // an array of post-vars, which is unlimited in length
    if(parm_url.length > 200)
    {
        for(ii=200; ii>0; ii--)
        {
            if(parm_url.charAt(ii) == '&')
            {
                break;
            }
        }
        get_url = parm_url.substr(0, ii);
        post_url = parm_url.substr(ii+1, parm_url.length);
    }
    else
    {
        get_url = parm_url;
        post_url = "";
    }
    //alert("get=" + get_url + "\n post=" + post_url + "\n source=" + parm_url);

                        // create the xmlhttp object and get the 
                        // new choicelist using it

    xmlhttp = new_xmlhttp_object();

                            // NOTE: the rdm random number is here to prevent this type of URL from being cached.
                            //       if the URL is cached, it does not function, even if every time you click it
                            //       would generate something different.
                            //       the setRequestHeader() calls below don't work.  I found no real working example of them
                            //       to use, so I followed this example instead, since it does work

    retval = xmlhttp.open("POST", get_url +"&rdm="+Math.random(), use_async);

    //xmlhttp.open("GET", parm_url, true);

    //alert("sent the get url retval = " + retval);


    xmlhttp.onreadystatechange =
    function()
    {
                                        // if the remot javascript call has finished running
        if(xmlhttp.readyState == 4)
        {

            clist_html = xmlhttp.response;

            //alert("sent xmlhttp request, response code = [" + xmlhttp.status + "]\n"
                //+ "statusText = [" + xmlhttp.statusText + "]\n"   
                //+ "responseText = [" + xmlhttp.responseText + "]\n"   
                //+ "responseXML = [" + xmlhttp.responseXML + "]\n" 
            //);

            if(xmlhttp.responseText.substr(0, 5) == "AL_OK")
            {
                //alert("got a success");

                                    // if we got a success message, send that to the
                                    // user, otherwise just continue with no message

                if(alert_success_flag == true)
                {
                    if(success_msg != "")
                    {
                        alert(success_msg);
                    }
                    else
                    {
                        alert("Action Successful");
                    }
                }    

            }
                                    // otherwise if there wasn't success, print
                                    // the error message for the user
            else
            {
                //alert("got an error");

                if(alert_error_flag == true)
                {
                    if(error_msg != "")
                    {
                        alert(error_msg + "\n\n"+ xmlhttp.responseText.substr(8));
                    }
                    else
                    {
                        alert("Action Failed\n\n"+ xmlhttp.responseText.substr(8));
                    }
                }    

            }
        }
    };

    //xmlhttp.send("");
    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(post_url);

    //alert("sent the post url, done");

    return;
}



function execute_js_request_and_close_window(parm_url, async_mode)
{
    var xmlhttp;
    var get_url;
    var post_url;
    var ii;
    var use_async;

    //alert("in execute_js_request_and_close_window");
                        // create the xmlhttp object and get the 
                        // new choicelist using it

    //alert("parm_url = [" + parm_url + "]");

    if(parm_url.length > 200)
    {
        for(ii=200; ii>0; ii--)
        {
            if(parm_url.charAt(ii) == '&')
            {
                break;
            }
        }
        get_url = parm_url.substr(0, ii);
        post_url = parm_url.substr(ii+1, parm_url.length);
    }
    else
    {
        get_url = parm_url;
        post_url = "";
    }
    //alert("get=" + get_url + " post=" + post_url + " source=" + parm_url);

    xmlhttp = new_xmlhttp_object();

                                   // default asynchronous to false, and use a flag to enable it.
    if(async_mode == "TRUE")
    {
         use_async = true;
    }
    else
    { 
         use_async = false;
    }

    //xmlhttp.open("POST", get_url, true);
    xmlhttp.open("POST", get_url +"&rdm="+Math.random(), use_async);



    xmlhttp.onreadystatechange =
    function()
    {
        if(xmlhttp.readyState == 4)
        {
                                // run any code that needs to be done with the html that the script returns

            //alert("sent xmlhttp request, response code = [" + xmlhttp.status + "]\n"
                //+ "statusText = [" + xmlhttp.statusText + "]\n"   
                //+ "responseText = [" + xmlhttp.responseText + "]\n"   
                //+ "responseXML = [" + xmlhttp.responseXML + "]\n" 
            //);

                                // close the window that executed the http request
            top.close();
        }
    };

    xmlhttp.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
    xmlhttp.send(post_url);

    //alert("Please wait for the relationship to be created.  The window will close when this is done");

}


function new_xmlhttp_object()
{
    var xmlhttp;

    if(browser.isIE == true)
    {
        xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    }
    else
    {
        xmlhttp = new XMLHttpRequest();
    }

    return xmlhttp;
}

//
// aljs_append_form_tool_table
//    Run the specified URL out to traqone in async mode
//    get the return value from the request and append it
//    to the content of the parm_wrapper_id html object (div or whatever)
//
function aljs_append_form_tool_table(parm_wrapper_id, parm_url, parm_async)
{
    var xmlhttp;
    var existing_wrapper;
    var clist_html;
    var use_async;
    
    //alert("in aljs_append_form_tool_table, parm_url = [" + parm_url + "]\nparm_wrapper_id = [" + parm_wrapper_id + "]");

    existing_wrapper = al_get_object(parm_wrapper_id);


                        // create the xmlhttp object and get the 
                        // new choicelist using it

    xmlhttp = new_xmlhttp_object();


                                   // default asynchronous to trueljs_append_form_tool_table, and use a flag to enable it.
    use_async = true; 
    if(parm_async == "TRUE" || parm_async == true)
    {
         use_async = true; 
    }
    else if(parm_async == "FALSE" || parm_async == false)
    {
         use_async = false; 
    }

                            // NOTE: the rdm random number is here to prevent this type of URL from being cached.
                            //       if the URL is cached, it does not function, even if every time you click it
                            //       would generate something different.
                            //       the setRequestHeader() calls below don't work.  I found no real working example of them
                            //       to use, so I followed this example instead, since it does work

    xmlhttp.open("GET", parm_url +"&rdm="+Math.random(), use_async);

    

    xmlhttp.onreadystatechange = 
    function() 
    {
        if(xmlhttp.readyState == 4)
        {
                                    // replace the data that is currently inside of the
                                    // wrapper element with the new clist that we
                                    // just got

            new_html = xmlhttp.responseText;

            existing_wrapper.innerHTML = existing_wrapper.innerHTML + new_html;

            existing_wrapper.scrollTop = existing_wrapper.scrollHeight;

        }
    };


                                    // NOTE: the rdm random number is here to prevent this type of URL from being cached.
                                    //       if the URL is cached, it does not function, even if every time you click it
                                    //       would generate something different.
                                    //       the setRequestHeader() calls below don't work.  I found no real working example of them
                                    //       to use, so I followed this example instead, since it does work

    //alert("Setting the http headers");

    //xmlhttp.setRequestHeader("Pragma", "no-cache");
    //xmlhttp.setRequestHeader("Pragma", "no-store");
    //xmlhttp.setRequestHeader("cache-request-directive", "no-cache");
    //xmlhttp.setRequestHeader("cache-request-directive", "no-store");
    //xmlhttp.setRequestHeader("cache-response-directive", "no-cache");
    //xmlhttp.setRequestHeader("cache-response-directive", "no-store");
    xmlhttp.setRequestHeader("Cache-Control", "no-store");
    xmlhttp.setRequestHeader("Cache-Control", "no-cache");
    xmlhttp.setRequestHeader("Cache-Control", "must-revalidate");
    xmlhttp.send("");
}


//
// This method initiates the discussion chat loop.
// 
function aljs_dsc_chat_loop(parm_recnum_id, parm_check_url, parm_wrapper_id, parm_wrapper_url, parm_millisecond_interval)
{
    var xmlhttp;
    var recnum_wrapper;
    var fetch_url;
    var query_url;
    var extract_recnum;
    
    //alert("in aljs_dsc_chat_loop, parm_check_url = [" + parm_check_url + "]\nparm_recnum_id = [" + parm_recnum_id + "]");

    recnum_wrapper = al_get_object(parm_recnum_id);


    if(recnum_wrapper != null)
    {
         //while(true)
         {

              query_url = parm_check_url + "&ext_var_parm_last_chat_recnum=" + recnum_wrapper.value;

                        // create the xmlhttp object and get the 
                        // new choicelist using it

              xmlhttp = new_xmlhttp_object();


                            // NOTE: the rdm random number is here to prevent this type of URL from being cached.
                            //       if the URL is cached, it does not function, even if every time you click it
                            //       would generate something different.
                            //       the setRequestHeader() calls below don't work.  I found no real working example of them
                            //       to use, so I followed this example instead, since it does work

               xmlhttp.open("GET", query_url +"&rdm="+Math.random(), true);

    

               xmlhttp.onreadystatechange = 
                       function() 
                       {
                           if(xmlhttp.readyState == 4)
                           {
                                    // replace the data that is currently inside of the
                                    // wrapper element with the new clist that we
                                    // just got

                                new_html = xmlhttp.responseText;

                                extract_recnum = "";

                                //alert("Response = [" + new_html + "]");


                                // extract the record num returned in the response 
                                // and then use it in the next request

                                if(new_html.substr(0, 11) == "RECORD_NUM=")
                                {
                                    for(ii=0;ii<100;ii++)
                                    { 
                                                  // expect a newline to end the line
                                        if(new_html.substr(11+ii, 1) == "\n")
                                        {
                                            break;
                                        }
                                        extract_recnum += new_html.substr(11+ii, 1);
                                    }

                                    //alert("extract_recnum=[" + extract_recnum + "]");

                                    if(extract_recnum != "0")
                                    {
                                             // increment the recnum field
                                        recnum_wrapper.value = extract_recnum;

                                        //alert("going to get this record:" + extract_recnum);

                                        fetch_url = parm_wrapper_url + "&record_num=" + extract_recnum;

                                        //alert("wrapper_url = " + fetch_url);

                                        aljs_append_form_tool_table(parm_wrapper_id, fetch_url);
                                    }
                                }



                           } 
                       };


             xmlhttp.setRequestHeader("Cache-Control", "no-store");
             xmlhttp.setRequestHeader("Cache-Control", "no-cache");
             xmlhttp.setRequestHeader("Cache-Control", "must-revalidate");
             xmlhttp.send("");


//             setTimeout( 'aljs_dsc_chat_loop(\''+parm_recnum_id+'\', \''+parm_check_url+'\', \''+parm_wrapper_id+'\', \''+parm_wrapper_url+'\')', 7000);

             setTimeout( 'aljs_dsc_chat_loop(\''+parm_recnum_id+'\', \''+parm_check_url+'\', \''+parm_wrapper_id+'\', \''+parm_wrapper_url+'\')', parm_millisecond_interval);
           }
    }
}





//
// Javascript Code to cause a floating navigation bar
//
//

// to exclude: 
// 1. delete: <div something with layer>
// 2. delete: </div>
// 3. delete in head: <javasript src=float.js>
// 4. delete in <body: onLoad="start()"


window.onerror = null;
var ns6 = (!document.all && document.getElementById);
var ie4 = (document.all);
var ns4 = (document.layers);
    
function layerObject(id,left,top) {

    if (ns6) this.obj = document.getElementById(id).style;
    else if(ie4) this.obj = document.all[id].style;
    else if(ns4) this.obj = document.layers[id];
    else return;

    this.obj.left = left;
    this.obj.top = top;
    return this.obj;
}

function layerSetup() {
    floatLyr = new layerObject('floatLayer', 0,5); // left margin=0, top = 500
    window.setInterval("main()", 45);
}

function floatObject() {
    if (ns4 || ns6) {
        findHt = window.innerHeight;
    } else if(ie4) {
        findHt = document.body.clientHeight;
    }
}

function main() {

    var lock_state_obj = al_get_object('slidebar_lock_state');

    if(lock_state_obj == null)
    {
        return;
    }
    var lock_state = al_get_object('slidebar_lock_state').value;

                                // move the slidebar if it's not locked
    if(lock_state == 'unlocked')
    {
        var float_div = al_get_object('floatLayer');
        var div_height = parseInt(float_div.offsetHeight);

        var window_height;
        if(ns6||ns4) {
            window_height = parseInt(innerHeight);
        }
        else if(ie4) {
            window_height = document.body.clientHeight;
        }

        if(window_height < div_height) // if the slidebar doesn't fit on the page
        {
            aljs_toggle_slidebar_lock_state();
            float_div.style.top = 5
        }
        else
        {
            if (ns4) {
                this.currentY = document.layers["floatLayer"].top;
                this.scrollTop = window.pageYOffset;
                mainTrigger();
            }
            else if(ns6) {
                this.currentY = parseInt(document.getElementById('floatLayer').style.top);
                this.scrollTop = scrollY;
                mainTrigger();
            } else if(ie4) {
                this.currentY = floatLayer.style.pixelTop;
                this.scrollTop = document.body.scrollTop;
                mainTrigger();
            }
        }
    }
}


function mainTrigger() {
    topMargin = 0;
    var newTargetY; 
    var cell_top = al_get_object('slidebar_tc').style.scrollTop;

    var tc = al_get_object('slidebar_tc');    
    var tc_offset = parseInt(tc.offsetParent.offsetParent.offsetTop) + parseInt(tc.offsetParent.offsetParent.offsetParent.offsetTop);
    
    var float_div = al_get_object('floatLayer');
    var div_height = parseInt(float_div.offsetHeight);
    var window_height;

    if(ns6||ns4) {
        window_height = parseInt(innerHeight);
    }
    else if(ie4) {
        window_height = document.body.clientHeight;
    }

                                        // if page hasn't scrolled down far enough, put div at 
                                        // top of it's cell

    if(scrollTop < tc_offset -  (window_height - div_height) / 2 )
    {
        newTargetY = 5;
    }
    else
    {
        newTargetY = scrollTop - tc_offset + (window_height - div_height) / 2;

    }

    //newTargetY = this.scrollTop + this.topMargin;


    if(this.scrollTop<5){
        newTargetY = 5; //
    }
    if ( this.currentY != newTargetY ) {
        if ( newTargetY != this.targetY ) {

            this.targetY = newTargetY;
            floatStart();
        }
        animator();
    }
}

function floatStart() {
    slideTime = 300;
    var now = new Date();
    this.A = this.targetY - this.currentY;
    this.B = Math.PI / ( 2 * this.slideTime );
    this.C = now.getTime();
    if (Math.abs(this.A) > this.findHt) {
        this.D = this.A > 0 ? this.targetY - this.findHt : this.targetY + this.findHt;
        this.A = this.A > 0 ? this.findHt : -this.findHt;
    }
    else {
        this.D = this.currentY;
    }
}

function animator() {
    var now = new Date();
    var newY = this.A * Math.sin( this.B * ( now.getTime() - this.C ) ) + this.D;
    newY = Math.round(newY);
    if (( this.A > 0 && newY > this.currentY ) || ( this.A < 0 && newY < this.currentY )) {
        if ( ie4 )document.all.floatLayer.style.pixelTop = newY;
        if ( ns4 )document.layers["floatLayer"].top = newY;
        if ( ns6 )document.getElementById('floatLayer').style.top = newY + "px";
    }
}

function start() {
    if(ns6||ns4) {
        pageWidth = innerWidth;
        pageHeight = innerHeight;
        layerSetup();
        floatObject();
    }
    else if(ie4) {
        pageWidth = document.body.clientWidth;
        pageHeight = document.body.clientHeight;
        layerSetup();
        floatObject();
    }
}
function toggle_element_display(element_id) 
{ 
    var object = al_get_object(element_id);
    state = object.style.display;

     //alert("state = [" + state + "]");

            // note that if the state is not block, but the element IS showing
            // this code will not set it correctly on the first attempt
    if (state != 'block')
    {
        object.style.display='block';
        //alert("setting [" + element_id + "] display to block");
    }
    else //if (state != 'none')
    {
        object.style.display = 'none';
        //alert("setting [" + element_id + "] display to none");
    }
}








///
///
///
///
///  Functions related to tigra menus 
///
///
///
///
///
// wrap_child returns the html structure for a basic looking menu item with text and an optional icon

function wrap_child (text,icon) {
    
    var ret = [['<table cellpadding=1 cellspacing=0 border=0 width=100%><tr><td bgcolor=#EFEDDE><img height=16 src=', icon !=null ? '' + icon: 'classes/pixel.gif width=15', ' hspace=3></td><td width=100%><table cellpadding=1 cellspacing=0 border=0 width=100% height=22><tr><td class=a0>  ', text, '</td></tr></table></td></tr></table>'].join(''),
    ['<table cellpadding=1 cellspacing=0 border=0 width=100% bgcolor=#93A070><tr><td><table cellpadding=1 cellspacing=0 border=0 width=100% height=22 bgcolor=#CED1C3><tr><td><img height=16 src=', icon !=null ? '' + icon: 'classes/pixel.gif width=16', ' hspace=3></td><td width=99% class=a0>  ', text, '</td></tr></table></td></tr></table>'].join(''),
    ['<table cellpadding=1 cellspacing=0 border=0 width=100% bgcolor=#93A070><tr><td><table cellpadding=1 cellspacing=0 border=0 width=100% height=22 bgcolor=#CED1C3><tr><td><img height=16 src=', icon !=null ? '' + icon: 'classes/pixel.gif width=16', ' hspace=3></td><td width=99% class=a0>  ', text, '</td></tr></table></td></tr></table>'].join('')
    ];


    return ret;
}


// wrap_submenu returns the html structure for a basic looking menu item with text and an optional icon

function wrap_submenu (text,icon) {
    
    var ret = [['<table cellpadding=1 cellspacing=0 border=0 width=100%><tr><td bgcolor=#EFEDDE><img height=16 src=', icon !=null ? '' + icon: 'classes/pixel.gif width=15', ' hspace=3></td><td width=100%><table cellpadding=1 cellspacing=0 border=0 width=100% height=22><tr><td class=a0>  ', text, '</td></tr></table></td><td><img alt=""  border="0"  class="cell_reporthead" src="'+ code_base_pathname + '/images/tab_btn_report_on.gif"  style="cursor: pointer;" ></td></tr></table>'].join(''),
    ['<table cellpadding=1 cellspacing=0 border=0 width=100% bgcolor=#93A070><tr><td><table cellpadding=1 cellspacing=0 border=0 width=100% height=22 bgcolor=#CED1C3><tr><td><img height=16 src=', icon !=null ? '' + icon: 'classes/pixel.gif width=16', ' hspace=3></td><td width=99% class=a0>  ', text, '</td></tr></table></td><td><img alt=""  border="0"  class="cell_reporthead" src="'+ code_base_pathname + '/images/tab_btn_report_on.gif"  style="cursor: pointer;" ></td></tr></table>'].join(''),
    ['<table cellpadding=1 cellspacing=0 border=0 width=100% bgcolor=#93A070><tr><td><table cellpadding=1 cellspacing=0 border=0 width=100% height=22 bgcolor=#CED1C3><tr><td><img height=16 src=', icon !=null ? '' + icon: 'classes/pixel.gif width=16', ' hspace=3></td><td width=99% class=a0>  ', text, '</td></tr></table></td><td><img alt=""  border="0"  class="cell_reporthead" src="'+ code_base_pathname + '/images/tab_btn_report_on.gif"  style="cursor: pointer;" ></td></tr></table>'].join('')
    ];


    return ret;
}




function get_inactive_menu_icon (icon) {
var ret = ['<img alt=""  border="0"  class="cell_reporthead" src="'+ code_base_pathname + '/images/tab_btn_report.gif"  style="cursor: pointer;" >'].join('');
//alert("ret = [" + ret + "]\n"
    //+ "ret.length = [" + ret.length + "]");
return ret;
}

function get_active_menu_icon (icon) {
var ret = ['<img alt=""  border="0"  class="cell_reporthead" src="'+ code_base_pathname + '/images/tab_btn_report_on.gif"  style="cursor: pointer;" >'].join('');
//alert("ret = [" + ret + "]\n"
    //+ "ret.length = [" + ret.length + "]");
return ret;
}







//
//
//        END functions for tigra menus
//



//
// function textarea_resize_to_content()
//
// params:  event = object containing the source of the event, and event info
//
// description:   This method is used on an onkeyup or onmouseup or both, so that the textarea
//                  can grow with the content that is getting added to it.  So for example a Letter
//                  can keep growing to fit the content so the user can see the content as they write.
//
//
//
function textarea_resize_to_content(event, maxsize)
{
    var object_ptr;

         if(event == null)
         {
             return;
         }

    //alert("resize to content");
    if(browser.isIE == true)
    {
        object_ptr = window.event.srcElement;
    }
    else
    {
        object_ptr = event.target;
    }
                                    // if the element is not the element that the person is working in
                                    // then we do not want to attempt this code.
         if(object_ptr == null || (object_ptr.tagName != 'TEXTAREA' && object_ptr.tagName != 'TEXTINPUT') )
         {
               return;
         }

                                // count the number of carriage returns in the textarea
    var tmp_lines = object_ptr.value.split('\n');
    var resize_to;

    resize_to = 0;

    //alert("tmp_lines = " + tmp_lines.length);

                                    // for each line, calculate the number of rows the line wraps and
                                    // fills up
    for(ii=0; ii<tmp_lines.length; ii++)
    {
        if(tmp_lines[ii].length > object_ptr.cols)
        {
            resize_to += Math.ceil(tmp_lines[ii].length/object_ptr.cols);
        }
    }
                                    // add the number of lines in the textarea
    resize_to += tmp_lines.length

    //alert("resize_to = " + resize_to);
    //alert("object.rows = " + object_ptr.rows);
    //alert("maxsize="+maxsize);

            // if the resize_to is more than the number of rows, and less than max size
            // then resize the textarea
    if(maxsize > 0 && resize_to <= maxsize && resize_to > object_ptr.rows)
    {
        object_ptr.rows = resize_to;
    }
            // if the resize_to is more than the number of rows, and more than max size
            // then resize the textarea to the max size
    else if(maxsize > 0 && resize_to > maxsize && resize_to > object_ptr.rows)
    {
        object_ptr.rows = maxsize;
    }
            // if the resize_to is more than the number of rows, and no max size
            // then resize the textarea
    else if((maxsize <= 0 || maxsize == null) && resize_to > object_ptr.rows)
    {
        object_ptr.rows = resize_to;
    }
    else          // no resizing
    {}

}



//
// function field_size_check_max()
//
// params:  event = object containing the source of the event, and event info
//            maxsize = the max size allowed for the current field
//
// description:   this method is used to monitor the size of a field, so the user can see
//                  when it will have a validation error
//
function field_size_check_max(event, maxsize)
{
    var object_ptr;
    var span_ptr;

    if(event == null)
    {
        return;
    }
    //alert("content size monitor");
    if(browser.isIE == true)
    {
        object_ptr = window.event.srcElement;
    }
    else
    {
        object_ptr = event.target;
    }

    if(object_ptr == null)
    {
        return;
    }

    var spanid = "maxcharspan_" + object_ptr.id

    span_ptr = al_get_object(spanid);

    if(span_ptr == null)           // if the mouse moved out of the box on a release, this happens
                     {
                                return;
                     }
                            // count the number of carriage returns in the textarea
    var tmp_len = object_ptr.value.length

    //alert("tmp_len = " + tmp_len);


    if(tmp_len > maxsize)
    {
        //span_ptr.style.fontWeight = 'bold';
        //span_ptr.style.color = '#ff0000';
        //span_ptr.innerHTML = tmp_len + " is greater than " + maxsize + " maxchars";
                                          //span_ptr.innerHTML = "<br />" + tmp_len + " has exceeded " + maxsize + " maximum";

                                         // to fix an issue in IE with the UNDO queue getting wiped out when innerHTML is used,
                                         // we will be restricting this to a hide/show type of element 
                 span_ptr.style.display = 'block';
                 span_ptr.title = 'You have typed ' + tmp_len + ' characters.';
    }
    else
    {
        //span_ptr.style.fontWeight = 'normal';
        //span_ptr.style.color = '#000000';
        //span_ptr.innerHTML = " ";

                                         // to fix an issue in IE with the UNDO queue getting wiped out when innerHTML is used,
                                         // we will be restricting this to a hide/show type of element
                  span_ptr.style.display = 'none';
    }
}


//
// function al_date_calc_complete_fields()
//
// params:  fld_start_time        = A Submit fieldname for the start time
//            fld_end_time        = A Submit Fieldname for the end time
//            fld_duration_hrs    = A Submit Fieldname for the duration in hours
//            fld_duration_min    = A Submit Fieldname for the duration in minutes
//            fld_duration        = A Submit Fieldname for the duration (expressed in <hrs>.<decimal min>
//            fld_start_date        = OPTIONAL - A Submit Fieldname for the start date
//            fld_end_date        = OPTIONAL - A Submit Fieldname for the end date
//
// description:   If the start date and duration, then calculate the end date as an offset from the start.
//                  If the end date and duration, then calculate the start date as an offset from the end.
//                  If all three are present, validate the duration's value. Error on failure here.
//                  Else no action.
function al_date_calc_complete_fields(fld_start_time, fld_end_time, fld_duration_hrs, fld_duration_min, fld_duration, fld_start_date, fld_end_date)
{
    //alert("FCN Entry al_date_calc_complete_fields");

    var start_time;
    var end_time;
    var duration_hrs;
    var duration_min;
    var duration;
    var start_date;
    var start_time;

    var hours;
    var minutes;
    var ampm;


                                // start by validating that all the data required to process the
                                // date is present

                                // check the date fields for existence and matching dates
    if(fld_start_date != null && fld_end_date != null)
    {
        start_date = al_get_object(fld_start_date).value;
        end_date = al_get_object(fld_end_date).value;

        //alert("start_date = " + start_date + " end_date = " + end_date);

                                // non-matching start and end represent an error
        if(start_date != "" && end_date != "" && start_date != end_date)
        {
            alert("Start and End date are not on the Same Day.  Cannot calculate a duration."); 
            return false;
        }
    }

                                // require both a start time and an end time field to be on the page
    if(fld_start_time == null || fld_end_time == null)
    {
        //alert("Start and End time are not Fields on the page.  Cannot calculate a duration."); 
        return false;
    }
    else                        // get the values off the page
    {
        start_time = al_get_object(fld_start_time).value;
        end_time = al_get_object(fld_end_time).value;

        //alert("start_time = " + start_time + " end_time = " + end_time);
    }


                                // require the durations to be on the page
    if(fld_duration_hrs == null && fld_duration_min == null && fld_duration == null)
    {
        alert("Duration is not a Field on the page.  Cannot calculate a duration."); 
        return false;
    }

                                // get the values off the page
    if(fld_duration_hrs != null && fld_duration_min != null)
    {
        duration_hrs = al_get_object(fld_duration_hrs).value;
        duration_min = al_get_object(fld_duration_min).value;

        //alert("duration_hrs = " + duration_hrs + " duration_min = " + duration_min);
    }

    if(fld_duration != null)
    {
        duration = al_get_object(fld_duration).value;

        //alert("duration = " + duration);
    }
    else
    {
        duration = duration_hrs + (duration_min * 100 / 60);
        //alert("calced duration = " + duration);
    }

    //alert("All fields are now present");

                                // Switch on whether the start time or end time is set (or both)
                                // to calculate the duration, or the corresponding time which is
                                // missing from the page
        
                                // if start time and duration is set, then calculate the end time
    if(start_time != "" && duration != "" && end_time == "")
    {
        var start_date_obj = new Date("04/04/2005 " + start_time);

        //alert("start datetime = " + start_date_obj.toLocaleDateString() + " " + start_date_obj.toLocaleTimeString());

        var mil_start_date = start_date_obj.getTime();        // get miliseconds for this day

        //alert("mil_start_date ms = " + mil_start_date);

        var new_end_date = mil_start_date + (duration * 60 * 60 * 1000);


        //alert("new_end_date ms = " + new_end_date);

        var new_end_date_obj = new Date();

        //alert("end datetime = " + new_end_date_obj.toLocaleDateString() + " " + new_end_date_obj.toLocaleTimeString());

        new_end_date_obj.setTime(new_end_date);

        //alert("end datetime = " + new_end_date_obj.toLocaleDateString() + " " + new_end_date_obj.toLocaleTimeString());

        //al_get_object(fld_end_time).value = new_end_date_obj.getHours() + ":" + new_end_date_obj.getMinutes();
        hours = new_end_date_obj.getHours();

        if(hours == 12)
        {
            ampm = "PM";
        }
        else if(hours > 12)
        {
            hours = hours - 12;
            ampm = "PM";
        }
        else if(hours < 1)
        {
            hours = "12";
            ampm = "AM"
        }
        else
        {
            ampm = "AM"
        }

        minutes = new_end_date_obj.getMinutes();
        if(minutes == "0")
        {
            minutes = "00";
        }
        al_get_object(fld_end_time).value = hours + ":" + minutes + ampm;

    }

                                // if end time and duration is set, then calculate the start time
    else if(start_time == "" && duration != "" && end_time != "")
    {
        var end_date_obj = new Date("04/04/2005 " + end_time);

        var mil_end_date = end_date_obj.getTime();        // get miliseconds for this day

        //alert("mil_end_date = " + mil_end_date);

        var new_start_date = mil_end_date - (duration * 60 * 60 * 1000);


        //alert("new_start_date = " + new_start_date);

        new_start_date_obj = new Date();
        new_start_date_obj.setTime(new_start_date);

        //alert("new start time = " + new_start_date_obj.toLocaleDateString()  + " " + new_start_date_obj.toLocaleTimeString());

        //al_get_object(fld_start_time).value = new_start_date_obj.getHours() + ":" + new_start_date_obj.getMinutes();
        hours = new_start_date_obj.getHours();

        if(hours == 12)
        {
            ampm = "PM";
        }
        else if(hours > 12)
        {
            hours = hours - 12;
            ampm = "PM";
        }
        else if(hours < 1)
        {
            hours = "12";
            ampm = "AM"
        }
        else
        {
            ampm = "AM"
        }

        minutes = new_start_date_obj.getMinutes();
        if(minutes == "0")
        {
            minutes = "00";
        }

        al_get_object(fld_start_time).value = hours + ":" + minutes + ampm;
    }

                                // if start time and end time are set, then calculate the duration
    else if(start_time != "" && duration == "" && end_time != "")
    {
        var start_date_obj = new Date("04/04/2005 " + start_time);
        var end_date_obj = new Date("04/04/2005 " + end_time);

        //alert("start datetime = " + start_date_obj.toLocaleDateString() + " " + start_date_obj.toLocaleTimeString());
        //alert("end datetime = " + end_date_obj.toLocaleDateString() + " " + end_date_obj.toLocaleTimeString());

        var new_mil_duration = end_date_obj - start_date_obj

        //alert("new_mil_duration = " + new_mil_duration);

        divisor_for_hours = new_mil_duration%(1000*60*60*24);
        //alert("divisor_hours = " + divisor_for_hours);
        hours = Math.floor(divisor_for_hours / (1000 * 60 * 60));

        divisor_for_minutes = divisor_for_hours % (1000 * 60 * 60);
        //alert("divisor_minutes = " + divisor_for_minutes);
        minutes = Math.round(divisor_for_minutes / (1000 * 60));

        //alert("hours = " + hours);
        //alert("minutes = " + minutes);

        al_get_object(fld_duration).value = hours + "." + Math.round(minutes * 100/60);

    }

                                // if all three are set, then validate that they are accurate
    else if(start_time != "" && duration != "" && end_time != "")
    {
        var start_date_obj = new Date("04/04/2005 " + start_time);
        var end_date_obj = new Date("04/04/2005 " + end_time);

        var new_mil_duration = end_date_obj - start_date_obj

        //alert("new_mil_duration = " + new_mil_duration + " orig duration = " + duration);

        divisor_for_hours = new_mil_duration%(1000*60*60*24);
        //alert("divisor_hours = " + divisor_for_hours);
        hours = Math.floor(divisor_for_hours / (1000 * 60 * 60));

        divisor_for_minutes = divisor_for_hours % (1000 * 60 * 60);
        //alert("divisor_minutes = " + divisor_for_minutes);
        minutes = Math.round(divisor_for_minutes / (1000 * 60));

        //alert("hours = " + hours);
        //alert("minutes = " + minutes);

        if( (hours + "." + Math.round(minutes * 100/60)) != duration )
        {
            alert("The duration does not match to the start and end times.  Please remove the Duration value to recalculate it.");
        }
        else
        {
            //alert("The duration matches.");
        }
    }
    else
    {
        alert("Values are not available on the page.  Cannot calculate a duration."); 
        return false;
    }


}




//
// function al_date_make_sql_field()
//
// params:  fld_start_date        = A Submit fieldname for the start date
//            fld_end_date        = A Submit Fieldname for the end date
//            fld_obj_date        = A Submit Fieldname for the field-object for the date that the start and end are part of
//
// description:   make a calculated ==[date sql]== value for the field_object based on two other fields on the page
//                  which are represented as a start date and an end date
//                  in cases when one or both are blank, only the start date will be used
//
function al_date_make_sql_field(fld_start_date, fld_end_date, fld_obj_date, db_fieldname)
{
    alert("FCN Entry al_date_make_sql_field");

    alert("FCN Entry fld_start_date="+fld_start_date+", fld_end_date="+fld_end_date+", fld_obj_date="+fld_obj_date);

    var start_date;
    var end_date;
    var sql_date;

                                // require all arguments
    if(fld_start_date == null || fld_end_date == null || fld_obj_date == null)
    {
        alert("Start or End or Object date are not Fields on the page.  Cannot calculate submits."); 
        return false;
    }

    start_date = al_get_object(fld_start_date).value;

    end_date = al_get_object(fld_end_date).value;

    obj_date = al_get_object(fld_obj_date).value;

    alert("start_date = " + start_date + " end_date = " + end_date + " field_object's value = " + obj_date);

    if(start_date != "" && end_date == "")
    {
        var start_date_obj = new Date(start_date);
        alert("start date year = " + start_date_obj.getYear());

        if(start_date_obj.getYear() < "50")
        {
            start_date_obj.setYear(start_date_obj.getYear() + 2000);
        }
        else if(start_date_obj.getYear() < "1000")
        {
            start_date_obj.setYear(start_date_obj.getYear() + 1900);
        }

        alert("start datetime = " + start_date_obj.toLocaleDateString() + " " + start_date_obj.toLocaleTimeString());

        al_get_object(fld_obj_date).value = start_date;

    }

                                // if end time and duration is set, then calculate the start time
    else if(start_date == "" && end_date != "")
    {
        var end_date_obj = new Date(end_date);

        alert("end date year = " + end_date_obj.getYear());

        if(end_date_obj.getYear() < "50")
        {
            end_date_obj.setYear(end_date_obj.getYear() + 2000);
        }
        else if(end_date_obj.getYear() < "1000")
        {
            end_date_obj.setYear(end_date_obj.getYear() + 1900);
        }

        alert("end datetime = " + end_date_obj.toLocaleDateString() + " " + end_date_obj.toLocaleTimeString());

        al_get_object(fld_obj_date).value = end_date;

    }
    else
    {
        var start_date_obj = new Date(start_date);

        alert("start date year = " + start_date_obj.getYear());

        if(start_date_obj.getYear() < "50")
        {
            start_date_obj.setYear(start_date_obj.getYear() + 2000);
        }
        else if(start_date_obj.getYear() < "1000")
        {
            start_date_obj.setYear(start_date_obj.getYear() + 1900);
        }

        alert("start datetime = " + start_date_obj.toLocaleDateString() + " " + start_date_obj.toLocaleTimeString() + " year=" + start_date_obj.getYear() + " month=" + (start_date_obj.getMonth()+1) + " day=" + start_date_obj.getDate());

        var end_date_obj = new Date(end_date);

        alert("end date year = " + end_date_obj.getYear());
        
        if(end_date_obj.getYear() < "50")
        {
            end_date_obj.setYear(end_date_obj.getYear() + 2000);
        }
        else if(end_date_obj.getYear() < "1000")
        {
            end_date_obj.setYear(end_date_obj.getYear() + 1900);
        }

        alert("end datetime = " + end_date_obj.toLocaleDateString() + " " + end_date_obj.toLocaleTimeString() + " year=" + end_date_obj.getYear() + " month=" + (end_date_obj.getMonth()+1) + " day=" + end_date_obj.getDate());


        alert("start date = " + start_date_obj.toString() + " start_date = " + start_date_obj.toUTCString() + " end date = " + end_date_obj.toString() + " end date = " + end_date_obj.toUTCString());
        
        var field_obj = al_get_object(fld_obj_date);

        field_obj.value = "==[ " + db_fieldname + " between '";
        
        field_obj.value += start_date_obj.getYear() + "-";
        

        if(start_date_obj.getMonth()+1 < 10)
        {
            field_obj.value += "0" + (start_date_obj.getMonth()+1) + "-";
        }
        else
        {
            field_obj.value += (start_date_obj.getMonth()+1) + "-";
        }

        if(start_date_obj.getDate() < 10)
        {
            field_obj.value += "0" + start_date_obj.getDate();
        }
        else
        {
            field_obj.value += start_date_obj.getDate() + "-";
        }

        field_obj.value += "' and '" + end_date_obj.getYear() + "-";

        if((end_date_obj.getMonth() +1) < 10)
        {
            field_obj.value += "0" + (end_date_obj.getMonth()+1) + "-";
        }
        else
        {
            field_obj.value +=  (end_date_obj.getMonth()+1) + "-";
        }

        if(end_date_obj.getDate() < 10)
        {
            field_obj.value += "0" + end_date_obj.getDate() + "-";
        }
        else
        {
            field_obj.value += end_date_obj.getDate() + "-";
        }

        field_obj.value += "']==";
    }


    obj_date = al_get_object(fld_obj_date).value;

    alert("FCN_EXIT start_date = " + start_date + " end_date = " + end_date + " field_object's value = " + obj_date);

}


//
// function aljs_execute_button_onclick()
//
// params:  parse_arg        = an argument that has to be parsed to get an array of arguments from it
//
// description:   Get the parse_arg split up into an array of arguments
//                  the first argument is always the name of the button (id) on the webpage
//                  all other arguments on the line come in the form of ID=VALUE
//                  and are parsed into object id's/objects, and the value of the object is then set on the page
//
function aljs_execute_button_onclick(parse_arg)
{
    //alert("FCN Entry aljs_execute_button_onclick");

    //alert("parse_arg = [" + parse_arg + "]");

    tmp_parse_arg = decodeURIComponent(parse_arg);

    //alert("tmp_parse_arg = [" + tmp_parse_arg + "]");

    arglist = tmp_parse_arg.split("[[]]");
    /* ************ debug arg list


    for (ii = 0; ii < arglist.length; ii++)
    {
    
        alert("arglist[" + ii + "] = [" + arglist[ii] + "]");

    }
    ******************* */

    if(arglist.length > 1)            // if there is more than 1 argument, arg1 being the button name
    {
                                    // then iterate through the arguments and determine if the arguments
                                    // have Objects on the page associated with them.  If they do, then
                                    // set the value of the argument on the page from the value in the
                                    // passed argument
        for (ii = 1; ii < arglist.length; ii++)
        {
            tmp_arg = arglist[ii];
            //alert("tmp_arg=" + tmp_arg);

            tmp_arglist = tmp_arg.split("=");

            //alert("tmp_arglist[0] = " + tmp_arglist[0] + " tmp_arglist[1] = " + tmp_arglist[1]);

            tmp_field = al_get_object(tmp_arglist[0]);



            if(tmp_field != null)
            {
                

                tmp_field.value = tmp_arglist[1];
            }

        }
    }

    
    tmp_button = al_get_object(arglist[0]);

                     // handle the possibility that someone requested a submit-button
                     // because the system automatically adds ICBTN__ before the id on a submit-button
    if(tmp_button == null)
    {
        tmp_button = al_get_object("ICBTN__" + arglist[0]);
    }

    if(tmp_button != null)
    {
        if(tmp_button.type != null)
        {
            tmp_button.click();    // onclick executes the onclick action.  click executes as if the button clicked (submits, etc)
        }
        else
        {
            tmp_button.onclick();   // onclick on an element which is NOT a button (and cannot be submitted, so we don't depend on the button x/y being submitted)
        }
    }

    //alert("FCN_EXIT aljs_execute_button_onclick");

}


//
// function aljs_do_action_on_array()
//
// params:  element_id_array        = an array of element id's
// params:  action      = javascript of an action to execute
//
// description:   for each element in the array
//                do the action as a function for the element
//
function aljs_do_action_on_array(element_id_array, check_checkbox_flag, action)
{
    //alert("ENTRY-aljs_do_action_on_array");
    
    var ii;
    var element_id;
    var action;


    if(element_id_array != null)
    {
                            // loop through the array and call the action as a function

        for(ii = 0; ii < element_id_array.length; ii++)
        {
            element_id = element_id_array[ii];
            //alert("element_id=[" + element_id + "]");
     
                                    // split the id by _ so we can get the last element,
                                    // which we'll expect to be the recnum
            current_recnum = aljs_get_recnum_from_action_array(element_id);
            //alert("zCurrent Recnum = [" + current_recnum + "]");

                                    // in cases where we want to only update the checked items
                                    // we check the check_checkbox_flag first to see if it
                                    // is required before running the action.
            if(check_checkbox_flag != 1 || al_get_object(element_id).checked)
            {
                //alert("going to eval of action=[" + action + "] ii = " + ii);
                eval(action);
                //alert("done with action ii=" + ii);
            }
            //alert("end of loop");
        }
        //alert("out of loop");

    }
    //alert("EXIT-aljs_do_action_on_array");
}



//
// function aljs_load_page_splash()
//
// params:  none
//
// description:   if the div for page_splash exists, hide the main content of the page ('wrapper')
//                and then display the 'page_splash_wrapper'
//
function aljs_load_page_splash()
{
    //alert("ENTRY-aljs_load_page_splash");

    tmp_splash_div = al_get_object('page_splash_wrapper');
    tmp_content_div = al_get_object('wrapper');

    if(tmp_splash_div == null || tmp_content_div == null)
    {
        return true;
    }

 //   tmp_content_div.style.visibility='hidden';
 //   tmp_content_div.style.display='none';
 //   tmp_splash_div.style.visibility='visible';
 //   tmp_splash_div.style.display='block';

    tmp_content_div.className='content_wrapper_on_splash_action';
    tmp_splash_div.className='splash_wrapper_on_splash_action';

    //alert("EXIT-aljs_load_page_splash");

        return true;
}


//
// function aljs_get_recnum_from_action_array()
//
// params:  element_id      = the element id on a page, which is formatted as <string>_<recnum>
//
// description:   get back the recnum out of the element id
//
function aljs_get_recnum_from_action_array(element_id)
{
    var recnum;
    var tmp_arglist;

    //alert("ENTRY-aljs_get_recnum_from_action_array");

    if(element_id != null)
    {
                            // loop through the array and call the action as a function

        tmp_arglist = element_id.split("_");
        recnum = tmp_arglist[tmp_arglist.length-1];
        //alert("recnum from element id=[" + element_id + "], recnum=[" + recnum + "]");

    }
    //alert("EXIT-aljs_get_recnum_from_action_array");

    return(recnum);
}


//
// function aljs_capture_parm_pairs
//
// params: array of objects with 2 members: index and element_id
//
// description:  Take an array of any number of objects and for each object
//               build a tokenized string which library 68 will be able to parse
//               into a set of variables.
//               variable names are currently padded with "tqflow_parm_" 
//                      so that we know what these are generated from traqflows.
//               Currently we null-padd the array to 15.  Anything over 15 element is ignored.
//
function aljs_capture_parm_pairs()
{
    var return_value = '';
    var arg_obj;
    var element_value;
    var pairs_count;

    // get the list of arguments in array and store it in a variable
    var args_array = aljs_capture_parm_pairs.arguments;
    var arg_count = args_array.length;

    pairs_count = 0;

    // for each object in the array, locate the object on the page and get its value.
    for (var ii = 0; ii < arg_count; ii++)
    {
        aljs_debug_alert("ii=[" + ii + "]");
        arg_obj = args_array[ii];
        element_value = aljs_get_element_value(arg_obj.element_id);

        aljs_debug_alert("al_get_object=[" + al_get_object(arg_obj.element_id) + "] type=[" + al_get_object(arg_obj.element_id).type  + "]");

        aljs_debug_alert("Argument[" + ii + "].index=[" + arg_obj.index + "] .element_id=[" + arg_obj.element_id + "] .value=[" + element_value + "]");

        if(al_get_object(arg_obj.element_id).type == 'checkbox'  && !al_get_object(arg_obj.element_id).checked)
        {     
            aljs_debug_alert("Checkbox which is not checked - skipping");
            continue;
        }     

                //
                // The exception, which are checkboxes, has the actual value we want to get out of the checkbox
                // in the name portion of the element.  
                // The name is set to "<id>|value" and we need to extract that to the value
                //
        if(al_get_object(arg_obj.element_id).type == 'checkbox'  && al_get_object(arg_obj.element_id).checked)
        {     
            tmp_name = al_get_object(arg_obj.element_id).name;
            aljs_debug_alert("element found name=[" + tmp_name + "]"); 
            element_value = tmp_name.substring(arg_obj.element_id.length + 1, 50);
            aljs_debug_alert("checkbox_value=[" + element_value + "]"); 
        }     

        if( pairs_count > 0)
        {     
           return_value += "[**]";
        }
        return_value += "tqflow_parm_" + arg_obj.index + "[==]" + element_value;

        pairs_count ++;
    }

    // add in the null pairs so we have 15 total pairs in the pairs string.
    for(ii=pairs_count;ii<15;ii++)
    {
        return_value += "[**]parm_null_field=[==]NULL";
    }

    return(decodeURIComponent(return_value));
}





/* ******************** RAC function for adding line numbers to some text ****************** */
/* vvvvvvvvvvvvvvvvvvvv RAC function for adding line numbers to some text vvvvvvvvvvvvvvvvvv */
//converting a text to an array of lines
function getLineArray(sourceText) 
{
    var retArray = new Array();
    var arrayIndex = 0;
    var continueCicle = true;
    do 
    {
        endOfLine = findEndOfLine(sourceText);
        // find position of end of line
        retArray[arrayIndex] = sourceText.substring(0, endOfLine + 1);
        arrayIndex++;
        var newStart = endOfLine + 1;
        if (newStart < sourceText.length) 
        {
            sourceText = sourceText.substring(newStart, sourceText.length);
        } 
        else 
        {
            continueCicle = false;
        }
    } 
    while (continueCicle);

    return retArray;

    //finiding end of line
    function findEndOfLine(text) 
    {
        var CR = '\n', LF = '\r';
        var nextCR = text.indexOf(CR);
        var nextLF = text.indexOf(LF);
        if (nextCR == -1 && nextLF == -1) { // if there are no CR or LF symbols we renturn entire string
            return text.length;
        }
        else if (nextCR == -1) {          // if there is not CR symbol we return the place of next LF
            return nextLF;
        }
        else if (nextLF == -1) {          // if there is not LF symbol we return the place of next CR
            return nextCR;
        } 
        else {
            if (nextCR < nextLF) {
                if (nextCR + 1 == nextLF) {   //if we have both symbols as end of line then we biggest index
                    return nextLF;
                } else {                    //otherwise we return smaller index
                    return nextCR;
                }
            } 
            else {
                if (nextCR == nextLF + 1) {   //if we have both symbols as end of line then we biggest index
                    return nextCR;
                } 
                else {                    //otherwise we return smaller index
                    return nextLF;
                }
            }
        }
    }
}
function numberOfDigits(value) 
{
    return Math.floor(Math.log(value) / Math.log(10)) + 1;
}
function function_to_change(
        original_text_variable,
        new_text_variable,
        number_chars_for_linenum, // if not specified - count # lines in original and set in function - i.e. if there are 345 lines, then set this to be 3
        filler_character, // the character to use to fill non-significant empty positions. If not specified, use a space
        string_before_linenum, // place immediately to the left of the line# field - if not specified, use nothing
        string_after_linenum // place immediately to the right of the line# field - if not specified, use nothing
        )
{
    //getting one array with all the lines
    var lineArray = getLineArray(original_text_variable);

    //checking if variables were initialized
    if (number_chars_for_linenum == undefined) {
        number_chars_for_linenum = numberOfDigits(lineArray.length);
    }
    if (filler_character == undefined) {
        filler_character = ' ';
    }

    if (string_before_linenum == undefined) {
        string_before_linenum = '';
    }

    if (string_after_linenum == undefined) {
        string_after_linenum = '';
    }

    new_text_variable = '';

    //adding line numbers:
    for (var i = 0, oneLine; oneLine = lineArray[i]; i++) {
        lineNumber = fill(i, number_chars_for_linenum, filler_character);
        new_text_variable += string_before_linenum + lineNumber + string_after_linenum + oneLine;
    }

    return new_text_variable;

    // a special fill function which left fills an integer until the number of digits is reached
    function fill(number, number_chars, filler_character) {
        number = '' + number;
        while (number.length < number_chars) {
            number = filler_character + number;
        }
        return number;
    }
}
/* ^^^^^^^^^^^^^^^^^^^^ RAC function for adding line numbers to some text ^^^^^^^^^^^^^^^^^^ */
/* ******************** RAC function for adding line numbers to some text ****************** */

/* ******************** Below is from swishzone.com - ieupdate.js ****************** */

var bo_noscript_id = 0;

function isIE() {
  var strBrowser = navigator.userAgent.toLowerCase();
  return (strBrowser.indexOf("msie") > -1 && strBrowser.indexOf("mac") < 0);
}

function startIeFix() {
  if (isIE()) {
   document.write('<div style="display: none;" id="bo_noscript_id_' + bo_noscript_id + '">');
  }
}

function endIeFix() {
  if (isIE()) {
   document.write('</div>');
   var theObject = document.getElementById("bo_noscript_id_" + bo_noscript_id++);
   theObject.outerHTML = theObject.innerHTML;
  }
}


/* ** Clipboard functions * */

function al_objects_text_to_clipboard(tdObj) 

{
    var holdtext = document.all['holdtext'];
    holdtext.innerText = tdObj.innerText;
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
}

function al_any_text_to_clipboard(theText) 

{
    var holdtext = document.all['holdtext'];
    holdtext.innerText = theText;
    Copied = holdtext.createTextRange();
    Copied.execCommand("Copy");
}





/* ******************** Below is from swishzone.com - awstats_misc_tracker.js ****************** */

// awstats_misc_tracker.js
//-------------------------------------------------------------------
// You can add this file onto some of your web pages (main home page can
// be enough) by adding the following HTML code to your page body:
//
// <script language="javascript" type="text/javascript" src="/js/awstats_misc_tracker.js"></script>
// <noscript><img src="/js/awstats_misc_tracker.js?nojs=y" height="0" width="0" border="0" style="display: none"></noscript>
//
// * This must be added after the <body> tag, not placed within the
//   <head> tags, or the resulting tracking <img> tag will not be handled
//   correctly by all browsers.  Internet explorer will also not report
//   screen height and width attributes until it begins to render the
//   body.
//
// This allows AWStats to be enhanced with some miscellanous features:
// - Screen size detection (TRKscreen)
// - Browser size detection (TRKwinsize)
// - Screen color depth detection (TRKcdi)
// - Java enabled detection (TRKjava)
// - Macromedia Director plugin detection (TRKshk)
// - Macromedia Shockwave plugin detection (TRKfla)
// - Realplayer G2 plugin detection (TRKrp)
// - QuickTime plugin detection (TRKmov)
// - Mediaplayer plugin detection (TRKwma)
// - Acrobat PDF plugin detection (TRKpdf)
//-------------------------------------------------------------------

// If you use pslogger.php to generate your log, you can change this line with
// var awstatsmisctrackerurl="pslogger.php?loc=/js/awstats_misc_tracker.js";
var awstatsmisctrackerurl="/js/awstats_misc_tracker.js";

var TRKresult;
var TRKscreen, TRKwinsize, TRKcdi, TRKjava, TRKshk, TRKsvg, TRKfla;
var TRKrp, TRKmov, TRKwma, TRKpdf, TRKpdfver, TRKuserid, TRKsessionid;
var TRKnow, TRKbegin, TRKend;
var TRKnse, TRKn;

function awstats_setCookie(TRKNameOfCookie, TRKvalue, TRKexpirehours) {
    TRKExpireDate = new Date ();
      TRKExpireDate.setTime(TRKExpireDate.getTime() + (TRKexpirehours * 3600 * 1000));
      document.cookie = TRKNameOfCookie + "=" + escape(TRKvalue) + "; path=/" + ((TRKexpirehours == null) ? "" : "; expires=" + TRKExpireDate.toGMTString());
}

//function awstats_runvbscript() {
//    TRKresult = false;
//    p=false;
//    document.write('<SCRIPT LANGUAGE="VBScript">\non error resume next \n p = IsObject(CreateObject("PDF.PdfCtrl.5")) \n if (p) then \n msgbox("5") \n return true \n end if</SCRIPT>\n');
//    alert(p);
//    if (TRKresult) return 'y';
//    else return 'n';
//}

function awstats_detectIE(TRKClassID) {
    TRKresult = false;  // !!! Adding var in front of TRKresult break detection !!!
    document.write('<SCR' + 'IPT LANGUAGE="VBScript">\n on error resume next \n TRKresult = IsObject(CreateObject("' + TRKClassID + '")) \n </SCR' + 'IPT>\n');
    if (TRKresult) return 'y';
    else return 'n';
}

function awstats_detectNS(TRKClassID) {
    TRKn = "n";
    if (TRKnse.indexOf(TRKClassID) != -1) if (navigator.mimeTypes[TRKClassID].enabledPlugin != null) TRKn = "y";
    return TRKn;
}

function awstats_getCookie(TRKNameOfCookie){
    if (document.cookie.length > 0){
        TRKbegin = document.cookie.indexOf(TRKNameOfCookie+"=");
        if (TRKbegin != -1) {
            TRKbegin += TRKNameOfCookie.length+1; 
            TRKend = document.cookie.indexOf(";", TRKbegin);
            if (TRKend == -1) TRKend = document.cookie.length;
              return unescape(document.cookie.substring(TRKbegin, TRKend));
        }
        return null; 
      }
    return null; 
}

if (window.location.search == "" || window.location.search == "?") {
    // If no query string
    TRKnow = new Date();
    TRKscreen=screen.width+"x"+screen.height;
    if (navigator.appName != "Netscape") { TRKcdi=screen.colorDepth; }
    else {TRKcdi=screen.pixelDepth};
    TRKjava=navigator.javaEnabled();
    TRKuserid=awstats_getCookie("AWSUSER_ID");
    TRKsessionid=awstats_getCookie("AWSSESSION_ID");
    var TRKrandomnumber=Math.floor(Math.random()*10000);
    if (TRKuserid == null || (TRKuserid=="")) { TRKuserid = "awsuser_id" + TRKnow.getTime() +"r"+ TRKrandomnumber; }
    if (TRKsessionid == null || (TRKsessionid=="")) { TRKsessionid = "awssession_id" + TRKnow.getTime() +"r"+ TRKrandomnumber; }
    awstats_setCookie("AWSUSER_ID", TRKuserid, 10000);
    awstats_setCookie("AWSSESSION_ID", TRKsessionid, 1);
    TRKuserid=""; TRKuserid=awstats_getCookie("AWSUSER_ID");
    TRKsessionid=""; TRKsessionid=awstats_getCookie("AWSSESSION_ID");
    
    var TRKnav=navigator.appName.toLowerCase();     // "internet explorer" or "netscape"
    var TRKagt=navigator.userAgent.toLowerCase();   // "msie...", "mozilla...", "firefox..."
    //alert(TRKnav); alert(TRKagt);

    var TRKwin  = ((TRKagt.indexOf("win")!=-1) || (TRKagt.indexOf("32bit")!=-1));
    var TRKmac  = (TRKagt.indexOf("mac")!=-1);

    var TRKns   = (TRKnav.indexOf("netscape") != -1);
    var TRKopera= (TRKnav.indexOf("opera") != -1);
    var TRKie   = (TRKagt.indexOf("msie") != -1);

    // Detect the browser internal width and height
    var TRKwinsize;
    if (document.documentElement && document.documentElement.clientWidth)
        TRKwinsize = document.documentElement.clientWidth + 'x' + document.documentElement.clientHeight;
    else if (document.body && document.body.clientWidth)
        TRKwinsize = document.body.clientWidth + 'x' + document.body.clientHeight;
    else
        TRKwinsize = window.innerWidth + 'x' + window.innerHeight;
    
    if (TRKie && TRKwin) {
        // TRKshk = awstats_detectIE("SWCtl.SWCtl.1");
        // TRKsvg = awstats_detectIE("Adobe.SVGCtl");
    //    TRKfla = awstats_detectIE("ShockwaveFlash.ShockwaveFlash.1");
        // TRKrp  = awstats_detectIE("rmocx.RealPlayer G2 Control.1");
        // RG TRKmov = awstats_detectIE("QuickTimeCheckObject.QuickTimeCheck.1");
        // TRKwma = awstats_detectIE("MediaPlayer.MediaPlayer.1");
        // TRKpdf = 'n'; TRKpdfver='';
        // if (awstats_detectIE("PDF.PdfCtrl.1") == 'y') { TRKpdf = 'y'; TRKpdfver='4'; } // Acrobat 4
    //    if (awstats_detectIE('PDF.PdfCtrl.5') == 'y') { TRKpdf = 'y'; TRKpdfver='5'; } // Acrobat 5
    //    if (awstats_detectIE('PDF.PdfCtrl.6') == 'y') { TRKpdf = 'y'; TRKpdfver='6'; } // Acrobat 6
    //    if (awstats_detectIE('AcroPDF.PDF.1') == 'y') { TRKpdf = 'y'; TRKpdfver='7'; } // Acrobat 7
    }
    if (TRKns || !TRKwin) {
        TRKnse = "";
        for (var TRKi=0;TRKi<navigator.mimeTypes.length;TRKi++) TRKnse += navigator.mimeTypes[TRKi].type.toLowerCase();
        TRKshk = awstats_detectNS("application/x-director","");
          TRKsvg = awstats_detectNS("image/svg+xml","");
        if (document.implementation.hasFeature("org.w3c.dom.svg", "")) {TRKsvg = "y"; }
        TRKfla = awstats_detectNS("application/x-shockwave-flash"); // ou lire dans naviagtor.plugins si on trouve "Shockwave Flash" ou "Shockwav Flash 2.0"
        TRKrp  = awstats_detectNS("audio/x-pn-realaudio-plugin");
        TRKmov = awstats_detectNS("video/quicktime");
        TRKwma = awstats_detectNS("application/x-mplayer2");
        TRKpdf = awstats_detectNS("application/pdf");
        TRKpdfver='';
    }

    var imgsrc1 = awstatsmisctrackerurl+'?screen='+TRKscreen+'&win=' +TRKwinsize+'&cdi=' +TRKcdi+'&java='+TRKjava;
    var imgsrc2 = '&shk=' +TRKshk+'&svg='+TRKsvg+'&fla='+TRKfla+'&rp='+TRKrp+'&mov=' +TRKmov+'&wma=' +TRKwma+'&pdf='+TRKpdf+'&uid='+TRKuserid+'&sid='+TRKsessionid;
    //alert(imgsrc1);
    //alert(imgsrc2);
    var imgsrc=imgsrc1+imgsrc2;
    if( document.createElementNS ) {
        var l=document.createElementNS("http://www.w3.org/1999/xhtml","img");
        l.setAttribute("src", imgsrc );
        l.setAttribute("height", "0");
        l.setAttribute("width", "0");
        l.setAttribute("border", "0");
        document.getElementsByTagName("body")[0].appendChild(l);
    } else {
        document.write('<img style="display:none;" src="'+ imgsrc +'" height="0" width="0" border="0" />')
    }

}


