/*******************************************************************************
____________________________ API DOCUMENTATION BEGIN ___________________________
````````````````````````````````````````````````````````````````````````````````
Provides framework for classes, methods and properties.

````````````````````````````````````````````````````````````````````````````````
_____________________________ API DOCUMENTATION END ____________________________
*******************************************************************************/

//------------------------------------------------------------------------------
// CLASS CONSTRUCTORS BEGIN
//------------------------------------------------------------------------------

//CLASS CONSTRUCTOR-- the super class
function Class_Super() {}

//Prototype derive/extend (single inheritance only)
Spawn_Object.prototype = new Class_Super;

//Prototype properties
//Class_Super.prototype.zIndexCounter = 500; //global index counter for all elements in a page

//------------------------------------------------------------------------------

//CLASS CONSTRUCTOR-- creates an generic object
function Spawn_Object(argDivID) {
 this.objDivID = argDivID; //set element ID
}

//------------------------------------------------------------------------------

menus = new Array(); 

//CLASS CONSTRUCTOR-- creates an menu object with foundation properties
function menu(argID, argPage, argParentMenu, argSubMenu, argMenuOnClass) {
 this.id = argID;
 this.page = argPage;
 this.parentMenu = argParentMenu;   
 this.subMenu = argSubMenu; 
 this.menuOnClass = argMenuOnClass;

 menus.push(this);
}

//------------------------------------------------------------------------------
// CLASS CONSTRUCTORS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// METHODS BEGIN
//------------------------------------------------------------------------------

//METHOD-- init Core properties
function _initCoreProperties() {
 if(this.objDivID)
 {
  this.objCss = document.getElementById(this.objDivID).style; //create reference to [object CSSStyleDeclaration]
  this.objDivElement = document.getElementById(this.objDivID); //create reference to [object HTMLDivElement]
  //eval(this.obj + "=this"); //for methods using setTimeouts, setInterval, or eval's to call itself
 }
 else alert("Element ID Not Found");
}

Class_Super.prototype.m_initCoreProperties = _initCoreProperties;

//------------------------------------------------------------------------------

//METHOD-- set height property of object
function _setHeight(argHeight, argSynch) {
 this.objH = argHeight;
 if(argSynch) this.m_synchHeightProperty(); //synch to element property
}

Class_Super.prototype.m_setHeight = _setHeight;

//------------------------------------------------------------------------------

//METHOD-- set width property of object
function _setWidth(argWidth, argSynch) {
 this.objW = argWidth;
 if(argSynch) this.m_synchWidthProperty(); //synch to element property
}

Class_Super.prototype.m_setWidth = _setWidth;

//------------------------------------------------------------------------------

//METHOD-- get height of element
function _getHeight() {
 return this.objDivElement.offsetHeight;
}

Class_Super.prototype.m_getHeight = _getHeight;

//------------------------------------------------------------------------------

//METHOD-- get width of element
function _getWidth() {
 return this.objDivElement.offsetWidth;
}

Class_Super.prototype.m_getWidth = _getWidth;

//------------------------------------------------------------------------------

//METHOD-- synchs elements height property with objects height property
function _synchHeightProperty() {
 this.objCss.height = this.objH+"px";
}

Class_Super.prototype.m_synchHeightProperty = _synchHeightProperty;

//------------------------------------------------------------------------------

//METHOD-- synchs elements width property with objects width property
function _synchWidthProperty() {
 this.objCss.width = this.objW+"px";
}

Class_Super.prototype.m_synchWidthProperty = _synchWidthProperty;

//------------------------------------------------------------------------------

//METHOD-- set top property of object
function _setTop(argTop) {
 this.objY = argTop; 
 this.m_synchTopProperty();
}

Class_Super.prototype.m_setTop = _setTop;

//------------------------------------------------------------------------------

//METHOD-- set left property of object
function _setLeft(argLeft) {
 this.objX = argLeft; 
 this.m_synchLeftProperty();
}

Class_Super.prototype.m_setLeft = _setLeft;

//------------------------------------------------------------------------------

//METHOD-- get top property of object
function _getTop(argTop) {
 return this.objDivElement.offsetTop; 
}

Class_Super.prototype.m_getTop = _getTop;

//------------------------------------------------------------------------------

//METHOD-- get left property of object
function _getLeft(argLeft) {
 return this.objDivElement.offsetLeft; 
}

Class_Super.prototype.m_getLeft = _getLeft;

//------------------------------------------------------------------------------

//METHOD-- synchs elements top property with objects top property
function _synchTopProperty() {
 if(document.all) {this.objCss.pixelTop = this.objY;}
 else {this.objCss.top = this.objY+"px";} 
}

Class_Super.prototype.m_synchTopProperty = _synchTopProperty;

//------------------------------------------------------------------------------

//METHOD-- synchs elements left property with objects left property
function _synchLeftProperty() {
 if(document.all) {this.objCss.pixelLeft = this.objX;}
 else {this.objCss.left = this.objX+"px";} 
}

Class_Super.prototype.m_synchLeftProperty = _synchLeftProperty;

//------------------------------------------------------------------------------

//METHOD-- sets display property to block
function _displayBlock() {
 this.objCss.display = "block";
}

Class_Super.prototype.m_displayBlock = _displayBlock;

//------------------------------------------------------------------------------

//METHOD-- sets display property to none
function _displayNone() {
 this.objCss.display = "none";
}

Class_Super.prototype.m_displayNone = _displayNone;

//------------------------------------------------------------------------------

//METHOD-- returns display property of object
function _getDisplay() {
 return this.objCss.display;
}

Class_Super.prototype.m_getDisplay = _getDisplay;

//------------------------------------------------------------------------------

//METHOD-- sets background image
function _setBackgroundImage(argImagePath) {
 this.objCss.backgroundImage = "url("+argImagePath+")";
}

Class_Super.prototype.m_setBackgroundImage = _setBackgroundImage;

//------------------------------------------------------------------------------

//METHOD-- sets Alpha background image (IE only)
function _setAlphaImage(argImagePath) {
 if(document.all) this.objCss.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='"+argImagePath+"', sizingMethod='scale')";
 else this.m_setBackgroundImage(argImagePath);
}

Class_Super.prototype.m_setAlphaImage = _setAlphaImage;

//------------------------------------------------------------------------------

//METHOD-- moves object to new coordinates
function _moveTo(argY, argX) {
 this.objX = parseInt(argX);
 this.objY = parseInt(argY);
 this.m_synchTopProperty();
 this.m_synchLeftProperty();
}

Class_Super.prototype.m_moveTo = _moveTo;

//------------------------------------------------------------------------------

//METHOD-- sets height and width of mask
function _setMask() {
 this.m_setHeight(50, true);
 this.m_setWidth(50, true);
 
 //get height
 var theWindowHeight = getBrowserWindowHeight();
 var theBodyHeight = getBodyHeight();
  
 //get width
 var theWindowWidth = getBrowserWindowWidth();
 var theBodyWidth = getBodyWidth();
 
 //alert("Window: " + theWindowHeight + " " + theWindowWidth + "\n" + "Body: " + theBodyHeight + " " + theBodyWidth + "\n" + window.scrollMaxY);

 //set mask height
 if(theWindowHeight >= theBodyHeight) {this.m_setHeight(theWindowHeight, true);}
 else {this.m_setHeight(theBodyHeight, true);}

 //set mask width
 if(theWindowWidth >= theBodyWidth) {this.m_setWidth(theWindowWidth, true);}
 else {this.m_setWidth(theBodyWidth, true);}
 
 this.m_displayBlock(); //display the mask
}

Class_Super.prototype.m_setMask = _setMask;

//------------------------------------------------------------------------------

//METHOD-- centers an object vertically and horizontally within the browser window
function _centerObj(argPageWidth) {
 var theBrowserWinWidth = getBrowserWindowWidth();
 var theBrowserWinHeight = getBrowserWindowHeight();
 
 if(argPageWidth != false) //if website is fixed width (not liquid)
 {
	if(theBrowserWinWidth > argPageWidth) theBrowserWinWidth = argPageWidth;
 }
 
 var leftPosition = getObjectPositionLeft(theBrowserWinWidth, this.objW);
  
 if(this.fixedTop) var topPosition = 0;
 else var topPosition = getObjectPositionTop(theBrowserWinHeight, this.objH);
 
 if(this.offSetHeight) this.m_moveTo((topPosition + this.offSetHeight), leftPosition);
 else this.m_moveTo(topPosition, leftPosition);
}

Class_Super.prototype.m_centerObj = _centerObj;

//------------------------------------------------------------------------------
// METHODS END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// DIALOG BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- perform mask initialization
function initMask(argID, argImage) {
 var maskObj;
 if(document.all)
 {
  maskObj = new Spawn_Object(argID+"Iframe");
  maskObj.m_initCoreProperties();
 }
 else 
 {
  maskObj = new Spawn_Object(argID+"Div");
  maskObj.m_initCoreProperties();
  maskObj.m_setAlphaImage(argImage);
 }
 maskObj.m_setHeight(50, true);
 maskObj.m_setWidth(50, true);
 maskObj.m_setTop(0);
 maskObj.m_setLeft(0);
 return maskObj; //return mask object
}

//------------------------------------------------------------------------------

//METHOD-- init dailog properties
function _initDialogProperties(argMask, argDialogType, argStackMode) {
 this.m_initCoreProperties();
 this.m_setHeight(this.m_getHeight(), false);
 this.m_setWidth(this.m_getWidth(), false);
 this.m_setTop(0);
 this.m_setLeft(-2000);
 if(argMask) this.mask = argMask;
 this.dialogType = argDialogType;
 this.stackMode = argStackMode || false;
 this.objInit = true;
}

Spawn_Object.prototype.m_initDialogProperties = _initDialogProperties;

//------------------------------------------------------------------------------

//METHOD-- show Dialog
function _showDialog() {
 if(this.mask) this.mask.m_setMask();
 this.m_setHeight(this.m_getHeight(), false);
 this.m_centerObj(false);
 if(this.stackMode) activeStackDialog = this; //sets active stack dialog
 else activeDialog = this; //sets active dialog
}

Spawn_Object.prototype.m_showDialog = _showDialog;

//------------------------------------------------------------------------------

//METHOD-- hide Dialog
function _hideDialog() {
 this.m_moveTo(0, -2000);
 activeDialog = null; //clear active dialog
 if(this.stackMode) activeStackDialog = null; //clear activeStack dialog
 if(this.mask) 
 {
  if(activeStackDialog == null) this.mask.m_displayNone();
  else if(activeStackDialog) {activeStackDialog.objCss.zIndex = 500;}
 }
}

Spawn_Object.prototype.m_hideDialog = _hideDialog;

//------------------------------------------------------------------------------

//METHOD-- adjust dialog position and mask dimensions when window is resized
function adjustDialog() {
 if(activeDialog)
 {
  if(activeDialog.mask && activeDialog.mask.m_getDisplay() == "block") activeDialog.mask.m_setMask(); //if dialog has mask and is showing
  activeDialog.m_setHeight(activeDialog.m_getHeight(), false);
  activeDialog.m_centerObj(false);
 }

 if(activeStackDialog)
 {
  if(activeStackDialog.mask && activeStackDialog.mask.m_getDisplay() == "block") activeStackDialog.mask.m_setMask(); //if dialog has mask and is showing
  activeStackDialog.m_setHeight(activeStackDialog.m_getHeight(), false);
  activeStackDialog.m_centerObj(false);
 }
}

//------------------------------------------------------------------------------

//FUNCTION-- sets flag for viewing dialog
function setDialogMessage() {
 if(document.dialogForm.showme.checked) setCookie("dme", 1, 183);
 else deleteCookie("dme");
}

//------------------------------------------------------------------------------

//FUNCTION-- checks if dialog is enabled
function isDialogEnabled() {
 if(getCookie("dme")) return false;
 else return true;
}

//------------------------------------------------------------------------------

//METHOD-- sets various resource properties
function _setResource(argLink, argMetric, argTarget, argDCS1, argDomain, argDCS2, argPage, argWt, argPageTitle) {
 if(this.objInit)
 { 
/*   alert("argLink = " + argLink + "\n" +
         "argMetric = " + argMetric + "\n" +
         "argTarget = " + argTarget + "\n" +
         "argDCS1 = " + argDCS1 + "\n" +
         "argDomain = " + argDomain + "\n" +
         "argDCS2  = " + argDCS2 + "\n" +
         "argPage = " + argPage + "\n" +
         "argWt = " + argWt + "\n" +
         "argPageTitle = " + argPageTitle);*/
  if(activeStackDialog && activeDialog) {activeDialog.m_moveTo(0, -2000);}
  else if(activeStackDialog) {activeStackDialog.objCss.zIndex = 400;} //set z-index of dialog behind mask
  else if(activeDialog) {activeDialog.m_hideDialog();}    

  if(isObject(argLink)) {this.url = argLink.href;} //set url href
  else {this.url = argLink;} //set url string
  if(this.metric) this.metric = null; //reset metric
  if(argMetric) this.metric = true; //set metric if arg is present
  if(argTarget) this.target = argTarget; //set target for url [if no arg open new window | if arg load existing window]

  switch(this.dialogType)
  {
   case "pdf": //pdf dialog
    if(argMetric)
    {
     if(argDCS1) this.metricDCS1 = argDCS1;
     if(argDomain) this.metricDomain = argDomain;
     if(argDCS2) this.metricDCS2 = argDCS2;
     if(argPage) this.metricPage = argPage;
     if(argWt) this.metricWt = argWt;
     if(argPageTitle) this.metricPageTitle = argPageTitle;
    }
    if(isDialogEnabled())
    {
     document.dialogForm.showme.checked = 0; //checkbox should be unchecked when dialog is first shown
     this.m_showDialog();  
    }
    else this.m_loadResource(); //open pdf (user disabled dialog)
    break;
   case "siteExit": //leaving site dialog
    this.m_showDialog();
    break;
   case "siteExitSC": //leaving site savings card dialog
    if(argMetric)
    {
     if(argDCS1) this.metricDCS1 = argDCS1;
     if(argDomain) this.metricDomain = argDomain;
     if(argDCS2) this.metricDCS2 = argDCS2;
     if(argPage) this.metricPage = argPage;
     if(argWt) this.metricWt = argWt;
     if(argPageTitle) this.metricPageTitle = argPageTitle;
    }
    this.m_showDialog();
    break;
   case "image": //image dialog
    if(this.metric) metricsManager(this.metric); //log the metric
    if(isObject(argLink)) {this.imgId = argLink.childNodes[0].id;} //set id of thumbnail image
    else {alert("_setResource: argLink is not an object");}
    _loadImage();
    break;
   case "media": //media dialog
    if(this.metric) metricsManager(this.metric); //log the metric
    if(this.flashObj.write("compareChartDiv") == false) this.stackMode = false;
    else this.flashObj.write("compareChartDiv"); //load media
    this.m_setWidth(this.m_getWidth(), false); //set width
    this.m_showDialog();
    break;
   default:
    alert("_setResource: dialogType NOT FOUND");
  }
 }
}

Spawn_Object.prototype.m_setResource = _setResource;

//------------------------------------------------------------------------------

//METHOD-- sets various resource properties
function _loadResource() {
 if(this.objInit)
 {
  if(activeDialog) activeDialog.m_hideDialog(); //hide current dialog
  if(activeStackDialog) activeStackDialog.objCss.zIndex = 500; //set z-index of dialog behind mask

  switch(this.dialogType)
  {
   case "pdf": //pdf resource
    if(this.metric) this.m_metricsManagerExternalLinkClickthroughs(); //log the metric
    if(!this.target) newPDFWin(this.url); //load in new window
    else window.location.href = this.url; //load in current window
    break;
   case "siteExit": //general resource
    if(this.metric) metricsManager(this.metric); //log the metric
    if(!this.target) openExternalWin(this.url); //load in new window
    else window.location.href = this.url; //load in current window
    break;
   case "siteExitSC":  //leaving site savings card dialog
    if(this.metric) this.m_metricsManagerExternalLinkClickthroughs(); //log the metric
    if(!this.target) openExternalWin(this.url); //load in new window
    else window.location.href = this.url; //load in current window
    break;
   default:
    alert("_showDialog: dialogType NOT FOUND");
  }
 }
}

Spawn_Object.prototype.m_loadResource = _loadResource;

//------------------------------------------------------------------------------
// DIALOG END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// METRICS MANAGER BEGIN
//------------------------------------------------------------------------------

//METHOD-- manages metrics for exit link clickthroughs (user clicks on link and clicks continue in dialog)
function _metricsManagerExternalLinkClickthroughs() {
 //alert(this.metricDCS1+"\n"+this.metricDomain+"\n"+this.metricDCS2+"\n"+this.metricPage+"\n"+this.metricWt+"\n"+this.metricPageTitle);
 dcsMultiTrack(this.metricDCS1, this.metricDomain, this.metricDCS2, this.metricPage, this.metricWt, this.metricPageTitle);
}

Spawn_Object.prototype.m_metricsManagerExternalLinkClickthroughs = _metricsManagerExternalLinkClickthroughs;

//------------------------------------------------------------------------------
// METRICS MANAGER END
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
// FUNCTIONS BEGIN
//------------------------------------------------------------------------------

//FUNCTION-- validate if object
function isObject(argObjType) {
 if(typeof(argObjType) == "object") return true;
 else return false;
}

//------------------------------------------------------------------------------

//FUNCTION-- adds onload events
function addOnLoadEvent(func) {
 var oldonload = window.onload;
 if(typeof window.onload != "function") {window.onload = func;}
 else {window.onload = function() {if(oldonload) {oldonload();} func();}}
}

//------------------------------------------------------------------------------
// FUNCTIONS END
//------------------------------------------------------------------------------