// HapPlayer410.js - version 4.10.27
// 20011130 - dsd / oxe

function UseVFE(DLFN, code)
{
        UseFile(DLFN, code);
}
       	
        	
        	
function UseFile(DLFN, code)
{
        if(code)
        {
                DLURL = MakeDLURL(DLFN, code);

                fn      =       JustFile(DLFN);
                grp     =       GetGrp();

                SendText("\\setgrouphypertext[action= [\\load [file= ["+fn+"]]] i0= "+grp+"] " + " \\setcachedownload[file= ["+DLURL+"] i0= "+grp+"] " + " \\startcachedownload[i0= "+grp+"]");
        }
        else
        {
                SendText("\\load [file= ["+DLFN+"]]");
        }
}

function UseBackground(DLFN, code)
{
        if(code)
        {
                DLURL = MakeDLURL(DLFN, code);

                fn      =       JustFile(DLFN);
                grp     =       GetGrp();

                CleanUp();

                here = HapQuery("status file "+fn);
                if(here != "")
                {
                        SendText("\\loadbackgrnd[file= ["+fn+"]]");
                }
                else
                {
                        SendText("\\setgrouphypertext[action= [ \\loadbackgrnd [file= ["+fn+"]]] i0= "+grp+"] " + " \\setcachedownload[file= ["+DLURL+"] i0= "+grp+"] " + " \\startcachedownload[i0= "+grp+"] ");
                }
        }
        else
        {
                SendText("\\loadbackgrnd [file= ["+DLFN+"]]");
        }
}

function UseTexture(DLFN, code)
{
        if(code)
        {
                DLURL = MakeDLURL(DLFN, code);

                fn      =       JustFile(DLFN);
                grp     =       GetGrp();


                CleanUp();
                here = HapQuery("status file "+fn);
                if(here != "")
                {
                        SendText("\\settexture[tex= ["+fn+"]]");
                }
                else
                {
                        SendText("\\setgrouphypertext[action= [ \\settexture [tex= ["+fn+"]]] i0= "+grp+"] " + " \\setcachedownload[file= ["+DLURL+"] i0= "+grp+"] " + " \\startcachedownload[i0= "+grp+"] ");
                }
        }
        else
        {
                SendText("\\settexture[tex= ["+DLFN+"]]");
        }
}

function UseMorph(DLFN, code)
{
        if(code)
        {
                DLURL = MakeDLURL(DLFN, code);


                fn      =       JustFile(DLFN);
                var tmpster = fn;
                mn      =       tmpster.slice(0, tmpster.length-4);
                grp     =       GetGrp();


                CleanUp();
                here = HapQuery("status file "+fn);
                if(here != "")
                {
                        SendText("\\load [file= ["+fn+"]] \\q[\\setswitch [switch= morphs state= ["+mn+"]]]");
                }
                else
                {
                        SendText("\\setgrouphypertext[action= [ \\load [file= ["+fn+"]] \\q[\\setswitch [switch= morphs state= ["+mn+"]]] ] i0= "+grp+"] " + " \\setcachedownload[file= ["+DLURL+"] i0= "+grp+"] " + " \\startcachedownload[i0= "+grp+"] ");
                }
        }
        else
        {
                SendText("\\setswitch [switch= morphs state="+DLFN+"]");
        }

}

function LoadMorph(DLFN, code)
{
        UseFile(DLFN, code);
}

function UseNaturalVoice(DLFNwav, DLFNphn, code)
{
        if      (code == "A"    ){
                DLURLwav        =       ""              + DLFNwav;
                DLURLphn        =       ""              + DLFNphn;}
        else if (code == "R"    ){
                DLURLwav        =       G_PageRoot      + DLFNwav;
                DLURLphn        =       G_PageRoot      + DLFNphn;}
        else if (code == "DB1"  ){
                DLURLwav        =       G_DB1           + DLFNwav;
                DLURLphn        =       G_DB1           + DLFNphn;}

        fnwav   =       JustFile(DLFNwav);
        fnphn   =       JustFile(DLFNphn);
        grp     =       GetGrp();

        SendText("\\setgrouphypertext[action= [\\load [file= ["+fnphn+"]] \\start [file=["+fnphn+"]] ] i0= "+grp+"] " + " \\setcachedownload[file= ["+DLURLwav+"] i0= "+grp+"] " + " \\setcachedownload[file= ["+DLURLphn+"] i0= "+grp+"] " + " \\startcachedownload[i0= "+grp+"] ");

}

function StartFile(thefile)
{
        fn      =       JustFile(thefile);

        SendText("\\start [file= ["+fn+"]]");
}

function LoadFile(thefile)
{
        fn      =       JustFile(thefile);

        SendText("\\load [file= ["+fn+"]]");
}

function GrabFile(DLFN, code)
{
        DLURL = MakeDLURL(DLFN, code);

        fn      =       JustFile(DLFN);
        grp     =       GetGrp();


        SendText("\\setcachedownload[file= ["+DLURL+"] i0= "+grp+"]" + " \\startcachedownload[i0= "+grp+"]");
}


function CleanUp(box)
{
        // if the box parameter is passed, it will be chosen
        if(box) VFBoxSelect(box);
        SendText('\\cleanup');
}

//////////////////////////////////////////////////////////////
// Material Properties
// i0 == 0  Ambient
// i0 == 1  Diffuse
// i0 == 2  Emissive
// i0 == 3  Specular
// i0 == 4  Specular Power
function SetMaterial(i0, f0, f1, f2, f3)
{
        SendText("\\setmaterial[i0= " + i0 + " r= " + f0 + " g= " + f1 +" b= " + f2 + "  a= " + f3 + " ]");
}

function SetAmbient(r, g, b, a)
{
        SetMaterial(0, r, g, b, a);
}

function SetDiffuse(r, g, b, a)
{
        SetMaterial(1, r, g, b, a);
}

function SetEmissive(r, g, b, a)
{
        SetMaterial(3, r, g, b, a);
}

function SetSpecular(r, g, b, a)
{
        SetMaterial(2, r, g, b, a);
}

function SetSpecularPower(power)
{
        SetMaterial(4, power, power, power, power);
}

function Rotate(x, y, z, t)
{
  SendText("\\rotate[ x="+x+" y="+y+" z="+z+" t="+t+"]");
}

function RotateQuat(x, y, z, w, t)
{
  SendText("\\rotate[ x="+x+" y="+y+" z="+z+" w="+w+" t="+t+"]");
}

function Translate(x, y, z, t)
{
  SendText("\\translate[ x="+x+" y="+y+" z="+z+" t="+t+"]");
}

// THE BASICS
function SendText(text, box)
{


       // check if optional parameter was passed
        if(box === undefined)
        	boxofchoice = G_HapPluginCurrent;
        else 
        	boxofchoice = box;
        	

        if(!G_HapPluginData.plugin_okay) return;

        var shortText = text.substr(0, 1400);
        if(G_HapDetection.browser       ==      "nav")
                eval("document.embeds['"+G_HapVFBoxes[boxofchoice].name+"'].HyperText(shortText);");
        if(G_HapDetection.browser       ==      "ie")
                eval("document."+G_HapVFBoxes[boxofchoice].name+".HyperText = shortText;");

        if(G_HapDebugger)
                SendDebug(shortText);

        if(G_HapDebuggingReservoir)
                AddToReservoir(shortText);

        if(G_SendTextCallback&&G_SendTextCallbackOK)
        {
                G_SendTextCallback(text);
        }

}

function HapQueryNoEcho(text, box)
{
       // check if optional parameter was passed
        if(box === undefined)
        	boxofchoice = G_HapPluginCurrent;
        else 
        	boxofchoice = box;
        	
  
        rtn = "";
        if(!G_HapPluginData.plugin_okay) return;

        if(!G_HapVFBoxes[boxofchoice].name) return;

        var shortText = text.substr(0, 1400);
        if(G_HapDetection.browser       ==      "nav")
                eval("rtn = document.embeds['"+G_HapVFBoxes[boxofchoice].name+"'].QueryPlugin(shortText);");
        if(G_HapDetection.browser       ==      "ie")
        {
                eval("document."+G_HapVFBoxes[boxofchoice].name+".Query = shortText;");
                eval("rtn = document."+G_HapVFBoxes[boxofchoice].name+".Query");
        }

        return rtn;
}

function HapQuery(text, box)
{
        rtn = HapQueryNoEcho(text, box);

        if(G_HapDebugger)
                SendDebug("A: " + rtn + "\nQ: " + text);

        if(G_HapDebuggingReservoir)
                AddToReservoir("A: " + rtn + "\nQ: " + text)

        return rtn;
}

function VFBoxSelect(box)
{
        G_HapPluginCurrent = box;
}

function VFBox(x, y, commandfile)
{
        G_DocumentDone                                  = false;

        G_HapVFBoxes[G_HapVFBoxes.length]               = new Object();
        G_HapVFBoxes[G_HapVFBoxes.length-1].name        = "vfbox" + (G_HapVFBoxes.length-1);
        G_HapVFBoxes[G_HapVFBoxes.length-1].path        = 'document';

        if (G_HapPluginData.plugin_okay)
        {

                if (G_HapDetection.browser      ==      "nav")
                {
                        document.write("<EMBED type=\""+G_HapPluginData.mimetype+"\" name=\""+ G_HapVFBoxes[G_HapVFBoxes.length-1].name+"\" width=\""+x+"\" height=\""+y+"\" border= \"0\" vspace= \"0\" hspace=\"0\"></EMBED>");
                }
                else
                {
                        document.write("\
                        <OBJECT id=\""+ G_HapVFBoxes[G_HapVFBoxes.length-1].name + "\" classid=\""+G_HapPluginData.CLSID+"\"\
                        align=\"baseline\" border=\"0\" width=\""+x+"\" height=\""+y+"\">\
                        </OBJECT>\
                        ");
                }
        }


        VFBoxSelect(G_HapVFBoxes.length-1);

        if(commandfile != "none")
        {
                AddToInitQueue("VFBoxSelect(" + (G_HapVFBoxes.length-1) + ");");

                //if(is_winnt && (!is_win2k) )
                //      AddToInitQueue("SendText('\\\\setsleepms [i0= 50]');");

                AddToInitQueue("SendText('\\\\load [file= "+G_HapStandardScene+"]');");
                AddToInitQueue("SendText('\\\\load [file= "+G_HapStandardPose+"]');");
                AddToInitQueue("WaitForFigures(1);");
        }

        AddToInitQueue("SendText('\\\\stop');");

        HapErrorDefault(true);
        G_DocumentDone                                  = true;
}

function AddToInitQueue(input)
{
        G_HapInitQueue[G_HapInitQueue.length] = input;
}

function HAPOnLoadInit()
{
        alert("HapOnLoadInit() is defunct. Please do not use this function.");
}

var G_HAPoldOnload = window.onload;                     // Record old onload
window.onload = HAP_loadHandler;                        // set new onload

function HAP_loadHandler()
{
        setTimeout("G_HapStartupInterval=setInterval('StartupStateMachinePulse();', 200);", 500);
        if(G_HAPoldOnload) G_HAPoldOnload();
}

// Downloader Object
// Handy for Scene Stuffers
function Downloader()
{
        this.cache_check = true;

        this.filelist = new Array();
        this.codelist = new Array();

        this.finished = "";

        this.SetCacheCheck      = Downloader_SetCacheCheck;
        this.AddFile            = Downloader_AddFile;
        this.FinishedString     = Downloader_FinishedString;
        this.DoIt                       = Downloader_DoIt;
}

function Downloader_SetCacheCheck(boolean_var)
{
        // not cache check will most likely not work when duplicate files
        // are used in the same Downloader.
        this.cache_check = boolean_var;
}

function Downloader_AddFile(name, code)
{
        this.filelist[this.filelist.length] = name;
        this.codelist[this.codelist.length] = code;
}

function Downloader_FinishedString(vf3_hypertext)
{
        this.finished = vf3_hypertext;
}

function Downloader_DoIt()
{
        var total_size = this.filelist.length;
        var group_id = GetGrp();
        var tmp_here = "";

        SendText("\\setgrouphypertext[action= [ "+this.finished+" ] i0= "+group_id+"] ");

        for(i=0; i<total_size; i++)
        {
                tmp_fn = JustFile(this.filelist[i]);
                tmp_DLURL = MakeDLURL(this.filelist[i], this.codelist[i]);
                if(this.cache_check) tmp_here = HapQuery("status file "+tmp_fn);
                if(tmp_here == "")
                {
                        SendText(" \\setcachedownload[file= ["+tmp_DLURL+"] i0= "+group_id+"] ");
                }
        }

        SendText(" \\startcachedownload[i0= "+group_id+"] ");
}

///////////////////
// GLOBAL VARIABLES

var     G_HapDetection          =       new Object();           // contains 'browser', 'platform', and respective *_okay
        G_HapDetection.browser_okay     =       false;
        G_HapDetection.platform_okay    =       false;
var     G_HapPluginData         =       new Object();           // contains 'plugin', 'plugin_version', 'language', and respective *_okay
        G_HapPluginData.Filename        =       "NPHapPlugIn.dll";
        G_HapPluginData.AXCTRL          =       "ACTIVEHAPTEKX.ActiveHaptekXCtrl.1";
        G_HapPluginData.CLSID           =       "CLSID:C6DC0AE5-A7BE-11D2-BDF1-0090271F4931";
        G_HapPluginData.mimetype        =       "fake/mime-type";
        G_HapPluginData.plugin_okay     =       false;
        G_HapPluginData.plugin_version_okay     =       false;
        G_HapPluginData.language        =       "us";

var     G_HapErrorHandlerOrig           =       null;
var     G_HapStartupInterval            =       null;
var     G_HapStartupState               =       1;
var     G_HapStartupTemp                =       0;
var     G_HapInitQueue                  =       new Array();
var     G_HapPluginCurrent              =       0;
var     G_HapVFBoxes                    =       new Array();

var     G_PageRoot                      =       JustPath(document.location.toString());
var     G_DB1                           =       "http://www.haptek.com/db1/";
var     G_GrpNum                        =       1;
var     G_GrpMax                        =       100;

var     G_PluginMin                     =       "4.10.48"
var     G_PluginMax                     =       "999999"

var     G_HapStandardScene      	=       "data\\\\standard\\\\standardScene.hap";
var     G_HapStandardPose               =       "data\\\\standard\\\\standardPose.hap";

var	G_Hap_ProdName			=	"The Haptek Player";
var     G_Hap_Errored           	=       false;
var     G_hap_bad_browser       	=       G_Hap_ProdName + " is only availible on Netscape 4.03+ and Internet Explorer 4.0+.";
var     G_hap_bad_platform      	=       G_Hap_ProdName + " is currently only supported on the Microsoft Windows platform.";
var     G_hap_no_plugin         	=       "You do not have " + G_Hap_ProdName + " installed, please download it by clicking the button.";
var     G_hap_upgrade_message   	=       "Your version of " + G_Hap_ProdName + "\nis not compatable with this page.\nIf you wish to upgrade, please click OK.\nOtherwise click on cancel.";
var     G_hap_download_message  	=       "You currently do not have a version of " + G_Hap_ProdName + " which\n   supports this page. Would you like to download one?";

var     G_HapNotPreQuery                =       false;
var     G_HapPluginToOld                =       null;

var     G_SendTextCallback      =       null;
var     G_SendTextCallbackOK    =       false;

var     G_DocumentDone          =       false;
var     G_HapUdef;

var     G_HapOnline                     =       true;


var     hapPluginVersionToDownload = "latest";

if      (G_HapDebugger == G_HapUdef)
                var     G_HapDebugger           =       false;


/////////////////////////////////////
// Functions below are generaly not
// of any use to a web designer

function StartupStateMachinePulse()
{

        switch(G_HapStartupState)
        {
         case 1:
                if(!G_HapVFBoxes) return;
                if(G_HapVFBoxes[0] == G_HapUdef) return;
                G_HapStartupTemp++;

                if(G_HapDetection.browser == "nav")
                {
                        for(hap_nombre in document.embeds['vfbox0'])
                        {
                                if(hap_nombre == "QueryPlugin")
                                {
                                        G_HapNotPreQuery = true;
                                }
                        }
                }

                if( (G_HapNotPreQuery == true) || (G_HapDetection.browser == "ie"))
                        var vers = HapQuery("release");
                else
                        var vers = 0.1;

                if(vers == "") return;
                if(vers == "release") vers = 0.1;
                if(G_HapStartupTemp == 500) vers = 0.1;
                if(vers != "haptek api not ready" && vers != "" && vers != "NULL Scene")
                {
                        if( (vers+" " >= G_PluginMin+" ") && (vers+" " <= G_PluginMax+" ") )
                        {
                                G_HapStartupState = 2;
                                G_HapPluginData.plugin_version  =       vers;
                                G_HapPluginData.plugin_version_okay     =       true;
                        }
                        else
                        {
                                if(G_HapPluginData.plugin_version_okay != true)
                                {
                                        G_HapStartupState = 1000;
                                        G_HapPluginData.plugin_version  =       vers;
                                        G_HapPluginData.plugin_version_okay     =       false;
                                }
                        }
                        HapErrorDefault(false);
                }
                break;
         case 2:
                if(G_HapInitQueue.length > 0)
                {
                        eval(G_HapInitQueue[0]);
                        G_HapInitQueue = G_HapInitQueue.slice(1);
                }
                else
                        G_HapStartupState = 1000;
                break;
         case -1:
                if(HapQueryNoEcho('current numfigures')+" " > 0+" ")
                {
                        G_HapStartupState       =       2;
                }
                break;
         case 1000:
                if(G_HapPluginData.plugin_version_okay ==       false)
                {
                        if(G_HapPluginToOld     != null)
                                G_HapPluginToOld();
                }
                clearInterval(G_HapStartupInterval);
                G_HapStartupState       =       1001;
                break;
         case 1001:
                break;
        }
}

function WaitForFigures(number)
{
        if(G_HapStartupState == 2)
                G_HapStartupState = -1;
        else
                alert("ERROR: WaitForFigures Not Called in Init Queue");
}

function HapErrorDefault(dw_okay)
{

        if(G_Hap_Errored) return;

        if(dw_okay)
        {
                if(!G_HapDetection.browser_okay)
                {
                        document.write(G_hap_bad_browser);
                        G_Hap_Errored = true;
                }
                else if(!G_HapDetection.platform_okay)
                {
                        document.write(G_hap_bad_platform);
                        G_Hap_Errored = true;
                }
                else if(!G_HapPluginData.plugin_okay)
                {
                        G_Hap_Errored = true;
                        document.write("<center>");
                        if(G_HapOnline) HapDrawButton(hapPluginVersionToDownload);
                        document.write("<br>"+G_hap_no_plugin+"<br></center>");
                        download = confirm(G_hap_download_message);
                        if(download) HapDownloadVF3('latest');
                }
        }
        else
        {
                if(!G_HapPluginData.plugin_version_okay)
                {
                        G_Hap_Errored = true;
                        upgrade = confirm(G_hap_upgrade_message);
                        if(upgrade) HapDownloadVF3('latest');
                }
        }

}

//////////////////
// HANDY FUNCTIONS

function        GetGrp()
{
        G_GrpNum++;
        if (G_GrpNum > G_GrpMax)
                G_GrpNum        =       1;
        return G_GrpNum;
}

function        JustPath(s)
{
        delimit = "/";
        sa      = s.split(delimit);
        rtn     = "";
        for (i = 0; i < sa.length - 1; i++)
                rtn = rtn + sa[i] + delimit;
        return rtn;
}

function        JustFile(s)
{
        delimit = "/";
        sa      = s.split(delimit);
        if (sa.length > 0)
                rtn     = sa[sa.length - 1];
        else
                rtn     = s;
        return rtn;
}

function        JustFileBS(s)
{
        delimit = "\\";
        sa      = s.split(delimit);
        if (sa.length > 0)
                rtn     = sa[sa.length - 1];
        else
                rtn     = s;
        return rtn;
}

function        Backslashify(s)
{
        // Regular Expression to globaly match '\'
        re = /\\/gi

        // Replace / with //
        rtn = s.replace(re, '\\\\');

        return rtn;
}

function        MakeDLURL(DLFN, code)
{
                if      (code == "A"    )
                        DLURL   =       ""              + DLFN;
                else if (code == "R"    )
                        DLURL   =       G_PageRoot      + DLFN;
                else if (code == "DB1"  )
                        DLURL   =       G_DB1           + DLFN;
                else
                        DLURL  =        G_PageRoot      + DLFN;

                return DLURL;

}

//      POPUP DEBUGGER

var orig_G_HapDebugger;
var orig_SendDebug;
var PopUpDebuggerWindow;
var PopUpDebugger_SendToBoth = false;

function startPopUpDebugger()
{
        PopUpDebuggerWindow = window.open("", "PopUpDebuggerWindow", "width=700,height=450,status=no,menubar=no,location=no")
        PopUpDebuggerWindow.document.open();
        PopUpDebuggerWindow.document.write("<html><body>");
        PopUpDebuggerWindow.document.write("<form  name=\"debug\"  onSubmit=\"opener.SendText(document.debug.TextInput1.value); return(false);\">");
        PopUpDebuggerWindow.document.write("<input type=\"input\"  size=\"50\" name=\"TextInput1\" value=\"Welcome to the debugger\">");
        PopUpDebuggerWindow.document.write("<input type=\"button\" value=\"Send\" onclick=\"opener.SendText(document.debug.TextInput1.value);\">");
        PopUpDebuggerWindow.document.write("<input type=\"button\" value=\"Stop\" onclick=\"opener.SendText('\\\\stop');\">");
        PopUpDebuggerWindow.document.write("<input type=\"button\" value=\"Query\" onclick=\"opener.HapQuery(document.debug.TextInput1.value);\">");
        PopUpDebuggerWindow.document.write("<input type=\"button\" value=\"Ev1\" onclick=\"opener.eval(document.debug.TextInput1.value);\">");
        PopUpDebuggerWindow.document.write("<input type=\"button\" value=\"Ev2\" onclick=\"opener.SendDebug(eval(document.debug.TextInput1.value));\">");
        PopUpDebuggerWindow.document.write("<input type=\"button\" value=\"Cl\" onclick=\"document.debug.outputbox.value = '';\">");
        PopUpDebuggerWindow.document.write("<input type=\"button\" value=\"Close\" onclick=\"window.close(); opener.stopPopUpDebugger();\">");
        PopUpDebuggerWindow.document.write("<br>");
        PopUpDebuggerWindow.document.write("<textarea name=\"outputbox\" cols=75 rows=20></textarea>");
        PopUpDebuggerWindow.document.write("</form>");
        PopUpDebuggerWindow.document.write("<script>if(opener.G_HapDebuggingReservoir){       document.debug.outputbox.value += opener.G_Reservoir; G_HapDebuggingReservoir = false;}</script>");
        PopUpDebuggerWindow.document.write("</body></html>");
        PopUpDebuggerWindow.document.close();

        if(G_HapDebugger)
                SendDebug("*** Pop-Up Debugger Stealing Control ***");

        orig_G_HapDebugger      = G_HapDebugger;
        if(G_HapDebugger)
                orig_SendDebug          = SendDebug;

        G_HapDebugger   = true;
        SendDebug               = sendToPopUpDebugger;

}

function sendToPopUpDebugger(s)
{

        // still send to original
        if(PopUpDebugger_SendToBoth == true)
                orig_SendDebug(s);

        if(PopUpDebuggerWindow.closed != true)
        {
                PopUpDebuggerWindow.document.debug.outputbox.value = s + "\n" + PopUpDebuggerWindow.window.document.debug.outputbox.value;
        }
}

// does not close debugger window,
// but should be called when debugger gets
// closed
function stopPopUpDebugger()
{
        // replace original debugger functions
        G_HapDebugger   = orig_G_HapDebugger;
        SendDebug               = orig_SendDebug;

        // clear the originials
        orig_G_HapDebugger      = G_HapUdef;
        orig_SendDebug          = G_HapUdef;

        // alert plain debugger user
        if(G_HapDebugger)
                SendDebug("*** Pop-Up Debugger Returning Control ***");

}
//

function ErrorHandler1(msg, url, line)
{
        if (msg == "Automation server can't create object")
        {
                document.write("<script>if(G_HapDetection.browser=='ie')window.onerror=G_HapErrorHandlerOrig;<\/script>");
                return true;
        }
        else
                return false;
}

// THIS ONLY WORKS FOR WIN32 PLATFORMS
var agt=navigator.userAgent.toLowerCase();
var is_major = parseInt(navigator.appVersion);
var is_minor = parseFloat(navigator.appVersion);

var is_nav  = ((agt.indexOf('mozilla')!=-1) && (agt.indexOf('spoofer')==-1)
        && (agt.indexOf('compatible') == -1) && (agt.indexOf('opera')==-1)
        && (agt.indexOf('webtv')==-1));
var is_nav4 = (is_nav && (is_major == 4));
var is_navVFREADY = (is_nav && (is_minor >= 4.03));


var is_ie   = (agt.indexOf("msie") != -1);
var is_ie3  = (is_ie && (is_major < 4));
var is_ie4  = (is_ie && (is_major == 4) && (agt.indexOf("msie 5.0")==-1) );
var is_ie4up  = (is_ie  && (is_major >= 4));

var is_win   = ( (agt.indexOf("win")!=-1) || (agt.indexOf("16bit")!=-1) );
var is_win95 = ((agt.indexOf("win95")!=-1) || (agt.indexOf("windows 95")!=-1));
var is_win98 = ((agt.indexOf("win98")!=-1) || (agt.indexOf("windows 98")!=-1));
var is_winnt = ((agt.indexOf("winnt")!=-1) || (agt.indexOf("windows nt")!=-1));
var is_win32 = (is_win95 || is_winnt || is_win98 ||
                ((is_major >= 4) && (navigator.platform == "Win32")) ||
                (agt.indexOf("win32")!=-1) || (agt.indexOf("32bit")!=-1));


// *** *** *** END EXTRACTED CODE FROM NETSCAPE COMMUNICATIONS *** *** ***

//BEGIN ENVIRONMENT DETECT

if(is_navVFREADY)
{
        G_HapDetection.browser          =       "nav";
        G_HapDetection.browser_okay     =       true;
}
else if(is_ie4up)
{
        G_HapDetection.browser          =       "ie";
        G_HapDetection.browser_okay     =       true;
}
else
{
        G_HapDetection.browser          =       "unknown";
        G_HapDetection.browser_okay     =       false;
}

if(is_win32)
{
        G_HapDetection.platform         =       "win";
        G_HapDetection.platform_okay    =       true;
}
else if(is_mac)
{
        G_HapDetection.platform         =       "mac";
        G_HapDetection.platform_okay    =       false;
}
else if(is_unix)
{
        G_HapDetection.platform         =       "unix";
        G_HapDetection.platform_okay    =       false;
}
else
{
        G_HapDetection.platform         =       "unknown";
        G_HapDetection.platform_okay    =       false;
}

// Check URL for some debugging flags

        var G_PopUpOnStartup = false;
        var G_URLueryString = location.search.substring(1);
        var G_pairs = G_URLueryString.split("&");
        for(tmpI = 0; tmpI < G_pairs.length; tmpI++)
        {
                // alert(G_pairs[tmpI]);
                if(G_pairs[tmpI] == "HapDebugger=POPUP")
                {
                        G_PopUpOnStartup = true;
                        AddToInitQueue("startPopUpDebugger();");
                }
                else if (G_pairs[tmpI] == "HapDebugger=PLAIN")
                {
                        document.write("\n<script src=\"http://www.haptek.com/javascript/3/20000817/vfdebug.js\"></script>\n");
                }
                else if (G_pairs[tmpI] == "HapDebugger=LOCALPLAIN")
                {
                        document.write("\n<script src=\"HapPlayerDebugger.js\"></script>\n");
                }
        }


// Debugging Reservoir
// Holds the first few debugging lines because Netscape
// is slow to open the PopUp debugger

if(G_PopUpOnStartup)
{
        var G_HapDebuggingReservoir = true;
        var G_Reservoir = "";

        function AddToReservoir(s)
        {
                G_Reservoir = s + "\n" + G_Reservoir;
        }
}

// AUTO DOWNLOAD TOOLS

var VF3AutoInstallDIRURL        = "http://vf3.haptek.com/autoinstall";
var HapDownloadWindow;

// set up alert

function HapDrawButton(type)
{
        document.write("<a href=\"javascript:HapDownloadVF3('"+type+"');\"><img src=\""+VF3AutoInstallDIRURL+"/images/logo.gif\" border=\"0\"></a>");
}

function HapDownloadVF3(type)
{
        var tmp_udef;
        if(type == tmp_udef || type == "" || type == "undefined") type = "latest";
        var HapDownloadWindow = window.open(VF3AutoInstallDIRURL+"/?version="+type, "vf3autoinstall", "height=320,width=500,scrollbars=no,toolbar=no,directories=no");
}

// PLUGIN DETECTION
if(G_HapDetection.platform_okay && G_HapDetection.browser_okay)
{
        if(G_HapDetection.browser       ==      "nav")
        {
                //if( is_navVFREADY && !(is_major == 5) )
                //{
                        //alert("...not netscrape 6...");
                        navigator.plugins.refresh();
                //}

                G_HapPluginData.plugin  =       "";
                for(i=0; i<navigator.plugins.length; i++)
                {

                        // get their description
                        // alert(navigator.plugins[i].description);

                        if(JustFileBS(navigator.plugins[i].filename) == G_HapPluginData.Filename)
                        {
                                G_HapPluginData.plugin  =       JustFileBS(navigator.plugins[i].filename);
                                G_HapPluginData.plugin_okay     =       true;

                        }
                }

        }

        if(G_HapDetection.browser       ==      "ie")
        {
                G_HapErrorHandlerOrig   =       window.onerror;
                window.onerror          =       ErrorHandler1;

                var MyObject            =       new ActiveXObject(G_HapPluginData.AXCTRL);

                if (MyObject)
                {
                        G_HapPluginData.plugin  =       G_HapPluginData.AXCTRL;
                        G_HapPluginData.plugin_okay     =       true;
                        delete MyObject;
                }
        }
}

