﻿// Utilities function to be used in conjunction with the modal window script.

/** closes the popup window from inside; it assumes that the parent still has a reference to it
 *  the reference id is declared in parent like: 
 *     var elemList = {} //the list of popup windows, empty at first
 *     elemList['elem_<--here goes the id-->']=dhtmlmodal.open(...)
 *  where text between <-- and -->, including them, should be replaced with the id
 */
function close_popup(id) {
    if (parent!=null) 
        if ( parent.elemList!=null ) 
            if ( parent.elemList['elem_'+id]!=null ) {
                parent.elemList['elem_'+id].hide();
                //alert("hiding elem"+id);
            }
            //else alert("parent has no elem"+id)
        //else alert("parent has no elem list");
    //else alert("no parent");
    //also add the reshow of comboboxes
    //change_dropdown( true, true);
}

function parent_redirect(new_page) {
    parent.window.location=new_page;
}

function close_and_redirect(id, new_page) {
    close_popup(id);
    parent_redirect(new_page);
}

/** IE 6 bug: the dropdown list (select html element) appears on top of all other elements,
 *  so hiding it before showing the popup seems a good ideea
 *  if doVisible is true, show element, otherwise hide it
 *  if isChild is true, look for the element in parent
 */
function change_dropdown( doVisible, isChild) {
//should check for browser type ... TODO
//if no id given, should hide all dropdowns from page ... TODO
    var ie=document.all && !window.opera;
    //if ( !ie )
    //    return;
    //id = 'Header1_Login1_dlLoginActions';
    page = this;
    if ( isChild )
        page = parent;
    if ( page!=null && page.document!=null ) {
        //get all elements that are of type select
        elements = page.document.getElementsByTagName('select');
        for (var i = 0; i < elements.length; i++) { 
            combo = elements[i];
            //combo = page.document.getElementById(id);
            if ( combo!=null )
                if ( doVisible )
                    combo.style.display = 'inline';//block';
                else
                    combo.style.display = 'none';
        }
    }
}