/*
  - script.js
  -
  - Version: $Revision: 0.01 $
  -
  - Date: $Date: 2005/07/20 02:10:02 $
  -
  - Copyright (c) 2005, Joseph Lee
  - New York University
  - Faculty Technology Center. Division of ITS.  
  - All rights reserved.
  -
  - Redistribution and use in source and binary forms, with or without
  - modification, are permitted provided that the following conditions are
  - met:
  -
  - - Redistributions of source code must retain the above copyright
  - notice, this list of conditions and the following disclaimer.
  -
  - - Redistributions in binary form must reproduce the above copyright
  - notice, this list of conditions and the following disclaimer in the
  - documentation and/or other materials provided with the distribution.
  -
  - - Neither the name of the Hewlett-Packard Company nor the name of the
  - Massachusetts Institute of Technology nor the names of their
  - contributors may be used to endorse or promote products derived from
  - this software without specific prior written permission.
  -
  - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  - ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  - LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  - A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  - HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  - INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  - BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  - OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  - ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
  - TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  - USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  - DAMAGE.


*/


/*
 * Show and hide forms for mediation layers
 * When the user chooses a format for the mediation layer they
 * are about to submit, this function is called to find the correct
 * form to display.  If the specified form is not found, "Other" is 
 * displayed as the default.
 *
 */
function switchDiv(div_id)
{
    var style_sheet = getStyleObject(div_id);
    if (style_sheet)
    {
        hideAll();
        changeObjectVisibility(div_id, "block");
    }
    else 
    {
        
        hideAll();
        changeObjectVisibility("Other", "block");        
    }
}


/*
 * Gets the style of the div_id specified
 */

function getStyleObject(objectId) {
    // checkW3C DOM, then MSIE 4, then NN 4.

    if(document.getElementById && document.getElementById(objectId)) 
    {
	    return document.getElementById(objectId).style;
    }
    else if (document.all && document.all(objectId)) 
    {  
        return document.all(objectId).style;
    } 
    else if (document.layers && document.layers[objectId]) 
    { 
        return document.layers[objectId];
    } 
    else 
    {
        return false;
    }
}

/*
 * Changes the visibility of a div block.
 * It must be given a div_id, and the new visibility of that block
 */
function changeObjectVisibility(objectId, newVisibility) {
    // first get the object's stylesheet
    var styleObject = getStyleObject(objectId);

    // then if we find a stylesheet, set its visibility
    // as requested
    if (styleObject) 
    {
        styleObject.display = newVisibility;
        return true;
    } 
    else 
    {
        return false;
    }
}

/*
 * Hides all the mediation forms on the page, usually used before
 * before displaying a new form
 */
function hideAll()
{
    changeObjectVisibility("Other","none");
}


                
/*
 * When the user submits a mediation layer, the format of the layer
 * is specified in the drop down, but is not included within the <form>
 * tags.  This function finds that information and adds it as
 * a hidden parameter.
 */
function addType( form ) 
{
    // first get the type the user has chosen
    paramValue = document.typeForm.type.options[document.typeForm.type.selectedIndex].value;

    if (document.getElementById) 
    {
        var input = document.createElement('INPUT');
        if (document.all) 
        {   // what follows should work 
            // with NN6 but doesn't in M14
            input.type = 'HIDDEN';
            input.name = 'value_type_00';
            input.value = paramValue;
        }
        else if (document.getElementById) { // so here is the
                                          // NN6 workaround
            input.setAttribute('type', 'HIDDEN');
            input.setAttribute('name', 'value_type_00');
            input.setAttribute('value', paramValue);
        }
        form.appendChild(input);
    }
}                
                
                
                