﻿/**************************************************************************************
*                           COMPANION COMPUTERS LIMITED | CCL 
*           www.companioncomputers.co.uk | info@companioncomputers.co.uk
***************************************************************************************
*              www.compan.net | www.ccloe.co.uk | www.codebean.co.uk
***************************************************************************************
*   Application : CompanionComputers 
*        Author : Andrew Scott (andrew@compan.net) | km0|km0ti0n (km0ti0n@gmail.com)
*          Date : 01/03/2007
*       Version : 0.0.1
*   Description : Standard script for use with CompanionComputers web site
*     Copyright : Companion Computers Ltd. | CCL (c) 1987 / 2008 All rights Reserved.
***************************************************************************************
*       Licence : The duplication, distribution and modification for this code is  
*               : prohibited under international, and UK, law.  This code can only be 
*               : used with prior written persission and concent of CCL.  This header
*               : header must be retained, with the sole exception of compression,
*               : where any peer javascript libs / files too must be compressed.
***************************************************************************************
*    Dependancy : Core / Base / XAP
***************************************************************************************

***************************************************************************************
*         Class : CompanionComputers
*   Description : Class to wrap global references and application logic
***************************************************************************************/
function CompanionComputers(){}; _this = CompanionComputers.prototype = new Base();

/* Define Private variables */
_this.constructor		= CompanionComputers();
_this.ClassName			= "CompanionComputers";

_this.bUpdateCustomerListingView = false;
_this.bUpdateCustomerContactListingView = false;

_this.bUpdateListingView = false;


/**************************************************************************************
*        Method : Init
*        Params : n/a
*       Returns : n/a
*   Description : Standard Method to be called when the new Object of the
*               : class is instantiated.
***************************************************************************************/
_this.Init = function(){
    this.PreInit();
    this.referenceStaticElements();
    this.attachToAJAX();
    this.attachToPopupController();
    
    // stick non AJAX onload stuff here.
}



/**************************************************************************************
*        Method : attachToAJAX
*   Description : Attaches to the .net AJAX (equlivant to onload)
***************************************************************************************/ 
_this.attachToAJAX = function(){
    Sys.WebForms.PageRequestManager.getInstance().add_endRequest(
        function(){
            oCompanionComputers.CCL_endRequestHandler();
        }
    );
}   

/**************************************************************************************
*        Method : attachToPopupController
*   Description : Attaches to Popup Controller
***************************************************************************************/ 
_this.attachToPopupController = function(){
    
    this.oPopupController = new PopupController();
    this.oPopupController.Parent = this;
    this.Controls.Add( this.oPopupController );
}



/**************************************************************************************
*        Method : referenceStaticElements
*        Params : n/a
*       Returns : n/a
*   Description : Load up custom HTML elements
***************************************************************************************/
_this.referenceStaticElements = function(){

}


/**************************************************************************************
*        Method : CCL_endRequestHandler
*   Description : The AJAX onload
***************************************************************************************/
_this.CCL_endRequestHandler = function(){

    /* Check for new Popups that need to be displaied */
    this.oPopupController.actionPopups();
    
    
    /* Does the CustomerListing View need to be updated? */
    if( this.bUpdateCustomerListingView ){
        this.UpdateCustomerListingView(); 
    }
    
    /* Does the CustomerListing View need to be updated? */
    if( this.bUpdateCustomerContactListingView ){
        this.UpdateCustomerContactListingView(); 
    }
    
    if( this.bUpdateListingView ){
        this.UpdateListingView(); 
    }
    
}


/**************************************************************************************
*        Method : UpdateCustomerListingView
*   Description : Triggers c/b to server to update the CustomerLsiting View
***************************************************************************************/
_this.UpdateCustomerListingView = function(){
    this.bUpdateCustomerListingView = false;
    UpdateCustomerListingView(); 
}

/**************************************************************************************
*        Method : UpdateCustomerListingView
*   Description : Triggers c/b to server to update the CustomerLsiting View
***************************************************************************************/
_this.UpdateCustomerContactListingView = function(){
    this.bUpdateCustomerContactListingView = false;
    UpdateCustomerContactListingView(); 
}

/**************************************************************************************
*        Method : UpdateListingView
*   Description : Triggers c/b to server to update the CustomerLsiting View
***************************************************************************************/
_this.UpdateListingView = function(){
        this.bUpdateListingView = false;
    UpdateListingView(); 
}



/**************************************************************************************
*                                     END CLASS
***************************************************************************************/



/**************************************************************************************
*                                    START CLASS
***************************************************************************************
*         Class : PopupController
*   Description : Class to wrap global references and application logic
***************************************************************************************/
function PopupController(){}; _this = PopupController.prototype = new Base();

/* Define Private variables */
_this.constructor		= PopupController();
_this.ClassName			= "PopupController";
_this.oPopupController  = null;

/**************************************************************************************
*        Method : Init
*   Description : Standard Method to be called when the new Object of the
*               : class is instantiated.
***************************************************************************************/
_this.Init = function(){
    this.referenceStaticElements();
}


/**************************************************************************************
*        Method : referenceStaticElements
*   Description : Load up custom HTML elements
***************************************************************************************/
_this.referenceStaticElements = function(){
    this.eBGPopup = document.getElementById( "CCL_bgOverlay" ); 
}

/**************************************************************************************
*        Method : actionPopups
*   Description : Checks for and shows any popups
***************************************************************************************/
_this.actionPopups = function(){
    if( this.hasPopups() ){
        this.showPopups();
    }else{
        this.hidePopups();
    }
}


/**************************************************************************************
*        Method : hidePopups
*   Description : Ensures that if no popups are in view none of 
*               : the supporting CSS is active
***************************************************************************************/
_this.hidePopups = function(){
    with( this.eBGPopup.style){
        display = "none";
        if( !bFF ){ document.body.style.overflow = ""; }
    }
}


/**************************************************************************************
*        Method : showPopups
*   Description : Displays and positions first found Popup and 
*               : the supporting CSS is set active
***************************************************************************************/
_this.showPopups = function(){
    if( this.aPopups.length <= 0 ){ return; }
    oPopup = this.aPopups[0]; 
    
    oPopup.style.left = "-1000px";
    oPopup.style.top = "-1000px";    
    oPopup.style.display = "block";
    
    var nPopupHeight = oPopup.offsetHeight;
    var nPopupWidth = oPopup.offsetWidth;

   
      /* IE7 or later uses .body all others use documentElement */
    var nScrollTop      =  document.body.scrollTop;
    var nClientHeight   =  document.body.clientHeight;
    var nOffsetWidth    =  document.body.offsetWidth;
    var nScrollHeight   =  document.body.scrollHeight;
    /*
    alert(nScrollTop);
    alert(nOffsetWidth);
    alert(nScrollHeight);
    alert(nClientHeight);
    
    
    
    /* Position the Popup in the center */    
    with( this.eBGPopup.style){
        top     = "0px";
        //height  = nScrollHeight + "px"; 
        zIndex  = 980000;
        display = "block";
    }
    
    with( oPopup.style ){
        left    = ((nOffsetWidth - nPopupWidth)  / 2 ) + "px";
        top     = ( nScrollTop + ( ( nClientHeight - nPopupHeight )/ 2 ) + "px" );
        zIndex  = 990000;
        display = "block";
    }
}


/**************************************************************************************
*        Method : hasPopups
*   Description : Checks for and references any CCL_Popups
***************************************************************************************/
_this.hasPopups = function(){
    this.aPopups = document.getElementsByClassName( "CCL_popup" ); 
    if( this.aPopups.length > 0 ){ return true; }else {return false;}
    
}


/**************************************************************************************
*                           PUBLIC METHODS & VARIABLES
***************************************************************************************/
var oCompanionComputers;

/**************************************************************************************
*      Function : __initCompanionComputers
*        Params : n/a
*       Returns : n/a
*   Description : Creates a new docherty onload
***************************************************************************************/
function __initCompanionComputers(){
    oCompanionComputers                   = new CompanionComputers();
    oCompanionComputers.Parent            = null;
    oCompanionComputers.ParentElement     = null;
    oCompanionComputers.Init();
}

/**************************************************************************************/
AddEvent(window, "load", __initCompanionComputers);    /* Start the application */
/**************************************************************************************
*                                   END OF FILE
***************************************************************************************
***************************************************************************************
***************************************************************************************/
