/***** slave.js **************************************************************
 *                                                                           *
 *  Creator: Bruce Herring                                                   *
 *  Created: 2/3/00                                                          *
 *                                                                           *
 *  Intended Use:  This file is inteneded to be used in conjuction with      *
 *                 the html files that are generated by Dave Whalley tool    *
 *                 that I modified.                                          *
 *                                                                           *
 *****************************************************************************/

/****** change_script ********************************************************
 *                                                                           *
 *  Changes the lower windows contents location to the location indicated    *
 *  by script                                                                *
 *                                                                           *
 *****************************************************************************/

var scriptWindowVar;

function change_script (script) {
    if (top.document.URL.indexOf ("$$$") != -1)
        parent.lower.document.location.href = script
    else if(top.document.URL.indexOf ("$@$") != -1) {
	scriptWindowVar = window.open(script,"scriptWindowVar","scrollbars=yes,resizable=yes,toolbar=no,statusbar=no,menubar=yes")
	scriptWindowVar.focus()
    }
}

/****** change_frames ********************************************************
 *                                                                           *
 *  Switches between framed and non framed environment.                      *
 *  If you start with the non-frame version and then go to frames            *
 *  their will always be a ? in the URL.  This is the way I intended         *
 *  the files to be used.  If you start with the framed version the first    *
 *  time you try to go to non-framed it will appear to do nothing.  The      *
 *  second time it will work.                                                *
 *                                                                           *
 *  Actualy this function simply returns the address of the appropriate      *
 *  page.  The .html file that recieves it will use it appropriately.        *
 *                                                                           *
 *****************************************************************************/
function change_frames () {
    if (top.document.URL.indexOf ("$$$") != -1)
        return self.document.URL
    else {
	path = document.URL.split ("/")
	newPath = path[path.length - 1].split("?")
	return ("index.html?$$$" + newPath[0] + "$$$")
    }
}

/****** script_viewable ******************************************************
 *                                                                           *
 *  Returns 'Script' if no script is viewable for frames or windows. And     *
 *  'NoScript' if the script is up currently.                                *
 *                                                                           *
 *****************************************************************************/

function script_viewable () {
    if ( (top.document.URL.indexOf ("$$$") != -1) || (top.document.URL.indexOf ("$@$") != -1) )
        return "Narrative Off"
    else {
        return "Narrative On"
    }
}
/****** get_upper_frame ******************************************************
 *                                                                           *
 *  Returns all the information between the $$$'s in the sites url. If there *
 *  is more than two $$$'s in the URL only the information between the first *
 *  and second $$$ will be returned.  If there are no $$$'s in the URL       *
 *  toc.html will be returned.                                               *
 *                                                                           *
 *****************************************************************************/
function get_upper_frame () {
    path = top.document.URL.split ("$$$")
    if (path[0].length != top.document.URL.length)
       return path[1]
    else
       return "toc.html"
}
/****** 9/5/00 additions  *****************************************************
 *  The following additions were made to this script to allow for the tool to *
 *  display the script in a window and this keeps track of wether or not the  *
 *  window is open or not.                                                    *
 *                                                                            *
 *  These modifications were made by Zach Kramer                              *
 ******************************************************************************/
function windowed_or_framed() {
    if ( (top.document.URL.indexOf ("@@@") != -1) || (top.document.URL.indexOf ("$@$") != -1) ) {
        return "Windows [ Frames ]"
    }
    else {
        return "Frames [ Windows ]"
    }
}
function windowed_or_framed_tag() {
    if (top.document.URL.indexOf ("@@@") != -1){
        return "?@@@"
    }
    else {
      if (top.document.URL.indexOf ("$@$") != -1)
        return "?$@$"
      else {
        return ""
      }
    }
}
function target_tag() {
    if (top.document.URL.indexOf ("$$$") != -1){
        return "upper"
    }
    else {
      return "_top"
    }
}
function windowed_or_framed_altTag() {
    if (top.document.URL.indexOf ("@@@") != -1){
        return "?@@@"
    }
    else {
      if (top.document.URL.indexOf ("$@$") != -1)
        return "?@@@"
      else {
        return ""
      }
    }
}
function swapWindowedFramed() {
    if (top.document.URL.indexOf ("@@@") != -1) {
       path = top.document.URL.split ("?")
       return path[0]
    }
    else if (top.document.URL.indexOf ("$$$") != -1) {
       var newURL = self.document.URL + "?$@$"
       return newURL
    }
    else if (top.document.URL.indexOf ("$@$") != -1) {
       var newURL = change_frames()
       return newURL
    }
    else {
       var newURL = self.document.URL + "?@@@"
       return newURL
    }
}
function swapScriptNoScript() {
    if (top.document.URL.indexOf ("@@@") != -1) {
       path = top.document.URL.split ("?")
       var newURLScript = (path[0] + "?$@$")
       return newURLScript
    }
    else if (top.document.URL.indexOf ("$$$") != -1) {
        return self.document.URL
    }
    else if (top.document.URL.indexOf ("$@$") != -1) {
       path = top.document.URL.split ("?")
       var newURLScript = (path[0] + "?@@@")
       return newURLScript
    }
    else {
       var newURLScript = change_frames()
       return newURLScript
    }
}
function scriptFunctionToCall() {
    var opening = "myOpenWindow()"
    var closing = "myCloseWindow()"
    var dummy = ""
    if (top.document.URL.indexOf ("@@@") != -1) {
       return opening
    }
    else if (top.document.URL.indexOf ("$$$") != -1) {
        return dummy
    }
    else if (top.document.URL.indexOf ("$@$") != -1) {
       return closing
    }
    else {
       return dummy
    }
}
function windowedFunctionToCall() {
    var opening = "myOpenWindow()"
    var closing = "myCloseWindow()"
    var dummy = ""
    if (top.document.URL.indexOf ("@@@") != -1) {
       return dummy
    }
    else if (top.document.URL.indexOf ("$$$") != -1) {
        return opening
    }
    else if (top.document.URL.indexOf ("$@$") != -1) {
       return closing
    }
    else {
       return dummy
    }
}
function myOpenWindow() {
	scriptWindowVar = window.open("","scriptWindowVar","height=350,width=400,scrollbars=yes,resizable=yes,toolbar=no,statusbar=no,menubar=yes")
}
function myCloseWindow() {
	scriptWindowVar = window.open("","scriptWindowVar","")
   scriptWindowVar.close()
}

