/* **********************************************************************************************************
Date Written : 08/22/2000
Company      : CRKMedia, LLC (732) 873-9300
Copyright    : (c) 2000, 2001 CRKMedia, LLC All Rights Reserved
Purpose      : Runtime libray for the PopupBox Object
Usage        : This js should be placed in the Dreamweaver Configuration\Shared\PopupBox\Scripts folder.
               At runtime this file should be accessed by the pages that use the Popup object.
Revisions    :
************************************************************************************************************/

/* **********************************************************************************************************
Variables - PopupBox variables
************************************************************************************************************/

/* **********************************************************************************************************
Objects - PopupBox Run Time Objects
************************************************************************************************************/
/* ----------------------------------------------------------------------------------------------------------
Object      : WindowOptions
Created on  : 10/07/2000
Programmer  : Peter R Lynch (plynch@crkmedia.com)
Description : WindowOptions object that holds information about the configurable parameters of a popup window
-----------------------------------------------------------------------------------------------------------*/
function WindowOptions()
{ //Make sure the object can be instanciated correctly
  var strErrors = "";
  if(!this.CanCreate(strErrors))
  { alert("Attempt to create a WindowOptions object has failed. " + strErrors);
    return this;
  }   

  //Property declarations
  this.width       = WindowOptions.arguments[0]  || 300;
  this.height      = WindowOptions.arguments[1]  || 300;
  this.screenx     = WindowOptions.arguments[2]  || 0;
  this.screeny     = WindowOptions.arguments[2]  || 0;
  this.left        = WindowOptions.arguments[3]  || 0;
  this.top         = WindowOptions.arguments[3]  || 0;
  this.menubar     = WindowOptions.arguments[4]  || "no";
  this.toolbar     = WindowOptions.arguments[5]  || "no";
  this.location    = WindowOptions.arguments[6]  || "no";
  this.status      = WindowOptions.arguments[7]  || "no";
  this.directories = WindowOptions.arguments[8]  || "no";
  this.scrollbars  = WindowOptions.arguments[9]  || "yes";
  this.resizable   = WindowOptions.arguments[10] || "yes";

  //Method declarations

  return this;
}
//Method definitions
function WindowOptions_GetOptionsSTR() //WindowOptions method that returns a window.open options string
{ return "toolbar="     + this.toolbar + "," +
         "location="    + this.location + "," +
         "directories=" + this.directories + "," +
         "status="      + this.status + "," +
         "menubar="     + this.menubar + "," +
         "scrollbars="  + this.scrollbars + "," +
         "resizable="   + this.resizable + "," +
         "width="       + this.width + "," +
         "height="      + this.height + "," +
         "screenx="     + this.screenx + "," +
         "screeny="     + this.screeny + "," +
         "left="        + this.left + "," +
         "top="         + this.top;
}
function WindowOptions_CanCreateBLN(strErrors) //Make sure object can be created
{ return true;
}

//Prototype objects - Used for inheritance

//Prototype properties - Used to create a single reference to a property that propagates to all instances

//Prototype methods - Used to create a single reference to a method that propagates to all instances
WindowOptions.prototype.CanCreate        = WindowOptions_CanCreateBLN;
WindowOptions.prototype.GetOptionsString = WindowOptions_GetOptionsSTR;

/* ----------------------------------------------------------------------------------------------------------
Object      : PopupBox
Created on  : 10/07/2000
Programmer  : Peter R Lynch (plynch@crkmedia.com)
Description : PopupBox object that holds information about the PopupBox
-----------------------------------------------------------------------------------------------------------*/
function PopupBox()
{ //Make sure the object can be created correctly
  var strErrors = "";
  if(!this.CanCreate(strErrors))
  { alert("Attempt to create a " + this.Name + " object has failed.\n\n" + strErrors);
    return this;
  }   

  //Property declarations
  this.ID       = PopupBox.arguments[0] || "PopupBox"; //ID to use when opening a popup box
  this.URL      = PopupBox.arguments[1] || null; //URL of the message popup box
  this.Options  = PopupBox.arguments[2] || new WindowOptions(); //WindowOptions object that holds all the configurable popup options
  this.Parent   = window || undefined; //Parent window object
  this.Window   = null; //Popup window object

  //Method declarations

  return this;
}
//Method definitions
function PopupBox_CanCreateBLN(strErrors) //Make sure object can be created
{ var blnCanCreate = true;
  if(parseFloat(CommonLibraryVersionSTR()) < 1)
  { strErrors += "This object requires version 1.0 of the common library (Current version - " + CommonLibraryVersionSTR() + ")\n\n";
    blnCanCreate = false;
  }
  if(parseFloat(WindowOptions.Version) < 1)
  { strErrors += "This object requires version 1.0 of the WindowOptions object (Current version - " + WindowOptions.Version() + ")";
    blnCanCreate = false;
  }
  if(blnCanCreate && !this.IsRegistered())
  { strErrors += "This application is not properly licensed. Please contact " + this.Company + " (" + this.Phone + ") for a valid registration key.\n\n";
    blnCanCreate = false;
  }
  return blnCanCreate;
}
function PopupBox_CloseBLN() //PopupBox method that closes the popup window
{ if(this.Window != null)
  { this.Window.close();
    this.Window = null;
    return true;
  }
  return false;
}
function PopupBox_DisplayBLN() //PopupBox method that displays the message box
{ if(this.URL != null)
  { this.Window = this.Parent.open(this.URL, this.ID, this.Options.GetOptionsString()); //Open the popup window
	  this.Window.focus(); //Bring the window into focus
	  //this.Window.PopupBox = this; //Assign the PopupBox to the new window
	  //this.Window.document.close(); //Close the window document
	  return true;
  }
  return false;
}

//Prototype objects - Used for inheritance
PopupBox.prototype = new ApplicationInfo;

//Prototype properties - Used to create a single reference to a property that propagates to all instances
PopupBox.prototype.Name        = "PopupBox";
PopupBox.prototype.Description = "The 'PopupBox' system allows web developers to create popup boxes that can display useful information to an end user. Though the use of built in DreamWeaver Behaviors, Objects, Actions, and Commands, web developers can build in a standard method of communicating with their users via popup windows.";
PopupBox.prototype.Version     = "1.0";

//Prototype methods - Used to create a single reference to a method that propagates to all instances
PopupBox.prototype.CanCreate = PopupBox_CanCreateBLN;
PopupBox.prototype.Close     = PopupBox_CloseBLN;
PopupBox.prototype.Display   = PopupBox_DisplayBLN;

/* **********************************************************************************************************
Functions - PopupBox Run Time functions
************************************************************************************************************/
/* ----------------------------------------------------------------------------------------------------------
Routine Name : PopupBox_Show()
Date Written : 03/13/02
Author       : Peter R Lynch (plynch@crkinteractive.com)
Purpose      : To popup a browser window
Parameters   : Popup box attributes
Returns      : none
Revisions    :
-----------------------------------------------------------------------------------------------------------*/
function PopupBox_Show(strID, strURL, intWidth, intHeight, strPosV, strPosH, strMenubar, strToolbar, strLocation, strStatus, strDirectories, strScrollbars, strResizable)
{ var objWO = new WindowOptions(intWidth, intHeight, strPosV, strPosH, strMenubar, strToolbar, strLocation, strStatus, strDirectories, strScrollbars, strResizable);
  var objPB = new PopupBox(strID, strURL, objWO);
  objPB.Display();
}
