
/**************************************************************************************
*                           COMPANION COMPUTERS LIMITED | CCL 
*           www.companioncomputers.co.uk | info@companioncomputers.co.uk
***************************************************************************************
*              www.compan.net | www.ccloe.co.uk | www.codebean.co.uk
***************************************************************************************
*   Application : DMO 
*        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 DMO 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 : DMO
*   Description : Class to wrap global references and application logic
***************************************************************************************/
function DMO(){}; _this = DMO.prototype = new Base();

/* Define Private variables */
_this.constructor		= DMO();
_this.ClassName			= "DMO";
_this.oPriceRef = null;

/**************************************************************************************
*        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(){
            oDMO.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(){


//if( typeof cPriceID != "undefined" ){
     /* The element exists on the page */
  //  this.oPriceRef = document.getElementById( cPriceID ); 
    //this.flashPrice(); 
//}

this.oPopupController.actionPopups();

}

/**************************************************************************************
*        Method : flashPrice
*   Description : Flashes the Price
***************************************************************************************/
_this.flashPrice = function(){

if( this.oPriceRef.className == "HighlightPrice" ){
   var self = this;
   setTimeout( function(){ self.unsetColour(); }, 2000); 
}

}

/**************************************************************************************
*        Method : unsetColour
*   Description : Removes the Colour
***************************************************************************************/
_this.unsetColour = function(){

this.oPriceRef.className = "Price";

}


/***************************************************************************************
*         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;

 //   var nPopupHeight = 460;
   // var nPopupWidth = 710;


    oPopup.style.display = "none";

    /* Position the Popup in the center */    
    with( this.eBGPopup.style){
        top     = "0px";
        height  = document.body.scrollHeight + "px"; 
        zIndex  = 80000;
        display = "block";
    }
    
    with( oPopup.style ){
        left    = ((document.body.offsetWidth - nPopupWidth)  / 2 ) + "px";
        top     = ( document.body.scrollTop + ( ( document.body.clientHeight - nPopupHeight )/ 2 ) + "px" );
        zIndex  = 90000;
        display = "block";
    }

   // if( !bFF ){ document.body.style.overflow = "hidden"; }
}


/**************************************************************************************
*        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 oDMO;

/**************************************************************************************
*      Function : __initDMO
*        Params : n/a
*       Returns : n/a
*   Description : Creates a new docherty onload
***************************************************************************************/
function __initDMO(){
    //__roundCorners();
    oDMO                   = new DMO();
    oDMO.Parent            = null;
    oDMO.ParentElement     = null;
    oDMO.Init();
    
}

/**************************************************************************************/
AddEvent(window, "load", __initDMO);    /* Start the application */
/**************************************************************************************
*                                   END OF FILE
***************************************************************************************
***************************************************************************************
***************************************************************************************/


window["rlc_defaults"] = function(){ return {
    showButtons: [{
        action: Close,
        html: "Close <img src=\"/images/icons/cancel.png\"/>",
        type: "<button>"
    }, {
        action: Send,
        text: "Send",
        type: "<button>"
    }, {   
        action: MinBR,
        html: "Minimise<img src=\"/images/icons/arrow_southeast.png\"/>",
        type: "<button>",
        minhtml: "<div>LIVE CHAT</div><img src=\"/images/icons/arrow_northwest.png\"/>"
    }],
    cChatReadyHTML:"<a href=\"\" style=\"color:#666666;text-decoration:none;\">Click here for LIVE CHAT</a>",
    cChatNotOkHTML: ""
};}

// position chat container for IE's Quirks mode
function __rlc_pos(){
    clearTimeout(window["rlc_hdl"]);
    setTimeout(function () {
        $("#ChatContainer").css({
            bottom: "-" + $(window).scrollTop() + "px"
        });
    }, 30);
};
window["rlc_hdl"] = null;
if( $(".old-ie").length > 0 ){
    $(window).unbind().scroll(__rlc_pos); 
    setTimeout(__rlc_pos, 2000);
}
