/* As written here, to support older browsers like IE 4, the emulation
   of getElementById MUST HAVE BEEN EXECUTED _PRIOR_ TO THE FIRST CALL
   TO THIS FUNCTION. If either of the alternative element retrieval
   methods are to be used the noted changes also need to be made to
   this function and the alternative method MUST have been set-up
   prior to the first use of this function.
*/
function DynWrite(id, S){ //Generates a successor when first called!
    /* Define local variables:-
    */
    var testH, newH, inH, testID;
    /* Set the default value for the body text of the function that
       will be created to replace this function as the DynWrite
       function:-
    */
    var funcBody = "return false;"
    /* This ensures that getElementById is available (or emulated)
       on this browser prior to calling it:-
    */
    var el = (document.getElementById)?document.getElementById(id):null;
    /* If one of the other element retrieval strategies was used,
       creating a getElementWithId function, then because that function
       will return null when an element cannot be found, it is
       practical to just call that function as -
       var el = getElementWithId(id);
       - as subsequent tests result in an appropriate response.
    */
    /* This ensures that the referenced element has been successfully
       retrieved and tests to verify that its innerHTML property is
       a string (as opposed to being undefined):-
    */
    if((el)&&(typeof el.innerHTML == 'string')){
        /* Arbitrary string to use as an ID for an element that
           should be created as a result of writing to the innerHTML
           value (The string itself and the result of concatenating it
           to itself (repeatedly) should follow the rules for valid
           HTML ID attributes):-
        */
        testID = "tSt";
        /* This ensures that the test ID is not in use on the page by
           modifying it until an element cannot be retrieved using it:-
        */
        while(document.getElementById(testID)){
            /* If the getElementWithId function is being used instead
               of the getElementById emulation then the preceding test
               must also use that function.
            */
            testID += testID;
        }
        inH = el.innerHTML;    //Read the original innerHTML value.
        /* The following mixed case HTML string is _not_ an error.
        */
        /* Note also that the STRONG element inserted in the page
           contains the text "test", which may momentarily be
           visible to the user. It would probably not be a good
           idea to have no contents in the STRONG at all but &nbsp;
           could be used to reduce the potential visual impact:-
        */
        newH = inH+"<sTrOnG  Id='"+testID+"'  >test<\/StRoNg    >";
        el.innerHTML = newH;     //Assumes synchronous update of DOM.
        testH = el.innerHTML;    //Read innerHTML back for examination.
        if((testH != newH)&&     //Apparently normalised or unchanged.
           (testH != inH)&&      //Not unchanged (Not read-only).
           (document.getElementById(testID))){ //Element found in DOM.
            /* If the getElementWithId function is being used instead
               of the getElementById emulation then the preceding test
               must also use that function.
            */
            /* TESTS PASSED! Replace the default function body string
               with code that will set the innerHTML property of the
               element and return true, based on the assumption that
               the assignment will be successful because this test was
               sucessful:-
            */
            funcBody = 
                "document.getElementById(id).innerHTML=S; return true";
            /* See additional notes[1] on the function body to use at
               this point.
            */
        }
    }
    /* Replace the DynWrite function with one determined by the results
       of the tests:-
    */
    DynWrite = new Function("id", "S", funcBody);
    /* Call the newly created DynWrite function and return its return
       value as the return value for this function call:-
    */
    return DynWrite(id, S);
}
/* [1] Notes on the body string to use if the tests are passed:-
   The existing function body string relies on the use of
   the getElementById emulation approach to retrieving DOM element
   with an ID. If the getElementWithId function was used the
   appropriate equivalent body string would be:-

"getElementWithId(id).innerHTML = S;return true;"

   However, if the ID passed as a parameter to DynWrite does not
   correspond with an existing IDed element then either of these two
   options would result in a function that would generate run-time
   errors. For development that is probably a good thing as the
   resulting error should be corrected in either the HTML or the
   script code by ensuring that the ID string provided does refer to a
   uniquely identified DOM element.  On the other hand, having fully
   tested the code, the body string might be best swapped in deployed
   code to a more cautious version that checked the result of the
   element retrieval call to ensure that it is a non-null object:-

"var el=document.getElementById(id);if(el){el.innerHTML=S;}return true;"

   - with the getElementById emulation or:-

"var el=getElementWithId(id);if(el){el.innerHTML=S;}return true;"

   - with the getElementWithId function.
   
   These function body strings are still returning true. How
   suited that is to the situation would depend on how the code
   intended to respond to the return value. The inability to resolve
   one ID does not indicate that innerHTML would not available on
   others if they could be resolved so code that decides to stop
   attempting to write to innerHTML upon the first false return
   value might be better off using the previous strings. Code that
   wanted to fall-back based on each attempt to write to innerHTML
   would be better using a function body string that returned
   true/false based on the success of each individual attempt. For
   the body string that tests to ensure that the element reference
   is recovered a boolean return value based on the success of the
   element retrieval would be best suited. That is simplest achieved
   with a double NOT operator - return !!el; - . A null value of
   - el - would return boolean false and an element reference would
   return true due to type-converting forced by the NOT operator:-

"var el=document.getElementById(id);if(el){el.innerHTML=S;}return !!el;"

   - with the getElementById emulation or:-

"var el=getElementWithId(id);if(el){el.innerHTML=S;}return !!el;"

   - with the getElementWithId function. 

*/

function LayerShow(layername)
{
  layer = document.getElementById(layername);
  if(layer!=null)
   layer.style.display = "";
}

function LayerHide(layername)
{
  layer = document.getElementById(layername);
  if(layer!=null)
    layer.style.display = "none";
}

function LayerDisplay(layername,visible)
{
 if(visible)
  LayerShow(layername);
 else
  LayerHide(layername);
}

function java_include(url) 
{
 document.write('<script language="javascript" type="text/javascript" src="'+url+'"></script>');
}

function Def(val,def_val)
{
 if((val==null) || (val==""))
   return def_val;
 else
   return val;
}

function IsEmpty(val)
{
 return (val==null) || (val=="") || (val=='undefined');
}

function IsNotEmpty(val)
{
 return (IsEmpty(val) == false);
}
