function MM_findObj(n, d) 
      // d is a document
      // you can pass it for example if you are using frames to tell which doc
      // if you do not pass a doc the one in which this script is running is used
      // n is the name or index of the object you look for.
{ //v4.01
 var p,i,x;  
 if(!d) d=document; // in case  you didn't pass a doc assign the current one
 if((p=n.indexOf("?")) > 0 && //if there is a ? inside the string and
     parent.frames.length)    //you have several frames in the parent window
 {
   d=parent.frames[n.substring(p+1)].document; // assign the frame with the name
                                              // of the string after the ?
                                             // Ex: myobj?frame1 => assign frame 1 as new doc
   n=n.substring(0,p);                      // set the new name to the string before the ?
                                           // in this case myobj
 }
 if(!(x = d[n]) && d.all) x=d.all[n];      // try to assign the object with name n to x
                                           // directly as child of the document
 for (i=0; !x && i<d.forms.length; i++) x=d.forms[i][n]; //If it was not possible to assign the
                                                         // object then loop throug all forms
                                                         // of the document and look for the object
 for(i=0; !x && d.layers && i<d.layers.length; i++) x=MM_findObj(n,d.layers[i].document);
                                               // if the object was still not found and when there are
                                               // layers inside the document then loop trough all
                                               // layers and look for the object
                                               // They do it by setting the document to the layer and
                                               // call this function again
 if(!x && d.getElementById) x=d.getElementById(n);
                                            // if it was still not found than trie it by calling the
                                            // getElementById function because you may passed the id
 return x;                                  // return the element
}

