﻿/**.......................start of Online Modal Popup specification......................**/
//   Global namespace to hold OnlineModalJSLibrary
//   Refers modal_popup.css
var OnlineModalJSLibrary = new Object();
OnlineModalJSLibrary.Framework = new Object();
OnlineModalJSLibrary.Framework.Modalpopup = function()
{
    this.version					= '1.0';
    this.type						= 'Modalpopup';    
}
// ....................   Global var to hold instance of MLCustomViewjsLib Utility class ..................
var OnlineModalJSFunctions; //this var must be unique...
// ....................................................................................................

//....................... prototype ......................
OnlineModalJSLibrary.Framework.Modalpopup.prototype = {
//function to create Black Transparent background Div
createMaskedBody:function(strDeleteHTML){
        var maskedBody = document.createElement('DIV');// Black Transparent background Div 
        maskedBody.id = 'pageMask';
        maskedBody.className = 'pageMask';
        maskedBody.style.visibility = 'visible';
        //maskedBody.style.height = document.getElementsByTagName('BODY')[0].clientHeight + 'px'; // Height is set to height of screen to fill the background
        maskedBody.style.width = document.body.clientWidth+ 'px';
        maskedBody.style.height = document.body.clientHeight+ 'px';
        //maskedBody.style.height = Math.max(document.body.scrollHeight,Control.Modal.getWindowHeight())+ 'px'; // Height is set to height of screen to fill the background
        document.getElementsByTagName('BODY')[0].appendChild(maskedBody);
        OnlineModalJSFunctions.createModalPopup('dvModal',strDeleteHTML);
},
createMaskedAllImageBody:function(strDeleteHTML)
{
        var maskedBody = document.createElement('DIV');// Black Transparent background Div 
        maskedBody.id = 'pageMask';
        maskedBody.className = 'pageMask';
        maskedBody.style.visibility = 'visible';
        //maskedBody.style.height = document.getElementsByTagName('BODY')[0].clientHeight + 'px'; // Height is set to height of screen to fill the background
        maskedBody.style.width = document.body.clientWidth+ 'px';
        maskedBody.style.height = Math.max(document.body.scrollHeight,Control.Modal.getWindowHeight())+ 'px'; // Height is set to height of screen to fill the background
        document.getElementsByTagName('BODY')[0].appendChild(maskedBody);
        OnlineModalJSFunctions.createImageModalPopUp('dvImgModal',strDeleteHTML);
},
createImageModalPopUp : function()
{
    if(arguments.length>0)
    {
        var modalPopup = document.createElement('DIV');
        modalPopup.className = 'modalimagepopup';
        if(arguments[0])
        modalPopup.id = arguments[0];
        var body = document.createElement('DIV');
        body.className = 'imagebody';
        //body.style.overflow='auto';
        body.innerHTML = arguments[1];
        modalPopup.appendChild(body);
               
        document.getElementsByTagName('BODY')[0].appendChild(modalPopup);
        document.getElementById('ZoomImgDv').style.display ='none';
        document.getElementById('dvLoadContent').style.display ='block';
        setCenterPosition(document.getElementById('dvLoadContent')); 
        
       document.getElementById('ZoomImgDv').style.display ='block'; 
        //Check for the center of the browser area currently in picture and set the div to it
//        var center = OnlineModalJSFunctions.setCenterPosition($get(arguments[0]));
//        $get(arguments[0]).style.left = center.left + 'px';
//        $get(arguments[0]).style.top = center.top + 'px';
          //setCenterPosition($get(arguments[0]));
          setCenterPosition(document.getElementById(arguments[0]));
    }
},
//function to create Popup Div (Takes the Id and the innerHTML as arguments)
createModalPopup:function()
{
    if(arguments.length>0)
    {
        var modalPopup = document.createElement('DIV');
        modalPopup.className = 'modalpopup';
        if(arguments[0])
        modalPopup.id = arguments[0];
        var head = document.createElement('DIV');
        head.className = 'head';
        head.innerHTML = _headText;
        var body = document.createElement('DIV');
        body.className = 'body';
        body.innerHTML = arguments[1];
        //modalPopup.appendChild(head);
        modalPopup.appendChild(body);
        document.getElementsByTagName('BODY')[0].appendChild(modalPopup);
        OnlineModalJSFunctions.setCenterPosition(document.getElementById(arguments[0]),true);

//        document.getElementById('ZoomImgDv').style.display ='none';
//        document.getElementById('dvLoadContent').style.display ='block';
//        OnlineModalJSFunctions.setCenterPosition(document.getElementById('dvLoadContent'),true); 
        
        //setTimeout('OnlineModalJSFunctions.HidewatingImage()',1000);
        //Check for the center of the browser area currently in picture and set the div to it
        //var center = OnlineModalJSFunctions.setCenterPosition($get(arguments[0]));
        //OnlineModalJSFunctions.setCenterPosition($get(arguments[0]),true);
        
//        $get(arguments[0]).style.left = center.left + 'px';
//        $get(arguments[0]).style.top = center.top + 'px';
    }
},
//HidewatingImage : function HidewatingImage()
//{
//document.getElementById('dvLoadContent').style.display ='none'; 
//document.getElementById('ZoomImgDv').style.display ='block'; 
//OnlineModalJSFunctions.setCenterPosition(document.getElementById(arguments[0]),true);
//},

setCenterPosition: function(element, isRepostionVertically) 
{//window.onscroll=function() { OnlineModalJSFunctions.setCenterPosition('dvModal'); }
        var clientBound = OnlineModalJSFunctions.getClientBounds();

        var x = (clientBound.width - element.offsetWidth) / 2;
        var y = (clientBound.height - element.offsetHeight) / 2;

        if (navigator.userAgent.toLowerCase() != "safari") {
            scrollTop = document.documentElement.scrollTop;
            scrollLeft = document.documentElement.scrollLeft;
        }
        else {
            scrollTop = document.body.scrollTop;
            scrollLeft = document.body.scrollLeft;
        }
        if (scrollTop && (clientBound.height > element.offsetHeight))
            y = (scrollTop + y);

        if (scrollLeft && (clientBound.width > element.offsetWidth))
            x = (scrollLeft + x);
        if (y + element.offsetHeight >= document.body.offsetHeight)
            y = y - element.offsetHeight;
        y = y > 0 ? y : scrollTop;
        x = x > 0 ? x : 0;
        if (typeof (isRepostionVertically) == 'undefined' || isRepostionVertically == true) {
            //Sys.UI.DomElement.setLocation(element, Math.floor(x), Math.floor(y));
            element.style.left = "300px";
            element.style.top =  y + "px";
        }
        else {
            element.style.left = "300px";
        }
    },

getClientBounds : function()
 {
        /// <summary>
        /// Gets the width and height of the browser client window (excluding scrollbars)
        /// </summary>
        /// <returns type="Sys.UI.Bounds">
        /// Browser's client width and height
        /// </returns>
    try
        { 
            var clientWidth;
            var clientHeight;
            var bounds = {};
//            switch(Sys.Browser.agent) {
//                case Sys.Browser.InternetExplorer:
                    clientWidth = document.documentElement.clientWidth;
                    clientHeight = document.documentElement.clientHeight;
                   // break;
//                case Sys.Browser.Safari:
//                    clientWidth = window.innerWidth;
//                    clientHeight = window.innerHeight;
//                    break;
//                case Sys.Browser.Opera:
//                    clientWidth = Math.min(window.innerWidth, document.body.clientWidth);
//                    clientHeight = Math.min(window.innerHeight, document.body.clientHeight);
//                    break;
//                default:  // Sys.Browser.Firefox, etc.
//                    clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
//                    clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
//                    break;
//            }
            bounds.x=0;
            bounds.y=0;
            bounds.width=clientWidth;
            bounds.height= clientHeight;
  return bounds;
//            return new Sys.UI.Bounds(0, 0, clientWidth, clientHeight);
        }
        catch(ex){//g_tcs_ic_jsLib_1_0.LogError(ex,'getClientBounds');
        }
    },

//Gets the width and height of the browser client window (excluding scrollbars)
//getClientBounds:function()
//{
//        var clientWidth;
//        var clientHeight;
//        switch(Sys.Browser.agent) {
//            case Sys.Browser.InternetExplorer:
//                clientWidth = document.documentElement.clientWidth;
//                clientHeight = document.documentElement.clientHeight;
//                break;
//            case Sys.Browser.Safari:
//                clientWidth = window.innerWidth;
//                clientHeight = window.innerHeight;
//                break;
//            case Sys.Browser.Opera:
//            default:  // Sys.Browser.Firefox, etc.
//                clientWidth = Math.min(window.innerWidth, document.documentElement.clientWidth);
//                clientHeight = Math.min(window.innerHeight, document.documentElement.clientHeight);
//                break;
//        }
//        return {width:clientWidth, height:clientHeight};
//},
//setCenterPosition:function(element)
//    {
//        var clientBound = OnlineModalJSFunctions.getClientBounds();      
//        var xpos = (clientBound.width - element.offsetWidth)/2;
//        var ypos = (clientBound.height - element.offsetHeight)/2;
//        if (Sys.Browser.agent == Sys.Browser.InternetExplorer || Sys.Browser.agent == Sys.Browser.Firefox) 
//        {    
//            scrollTop = document.documentElement.scrollTop;
//            scrollLeft =  document.documentElement.scrollLeft;
//        }    
//        else 
//        {
//            scrollTop =  document.body.scrollTop;      
//            scrollLeft =  document.body.scrollLeft;
//        }   
//        if(scrollTop)
//            ypos = (scrollTop + ypos);
//        if(scrollLeft)
//            xpos = (scrollLeft + xpos);
//        if(ypos + element.offsetHeight >= document.body.offsetHeight)
//            ypos = ypos - element.offsetHeight;
//        ypos = ypos > 0? ypos : 0;
//        xpos = xpos > 0? xpos : 0; 
//        return {top:ypos,left:xpos};         
//},
setModalHead : function(headText)
{
	_headText = headText;
},
setModalBody : function(bodyText)
{
	_bodyText = bodyText;
}
}
var _headText = null;
var _bodyText = null;
OnlineModalJSFunctions = new OnlineModalJSLibrary.Framework.Modalpopup();

function CloseWindow()
{
  var pageMask=document.getElementById('pageMask');
  pageMask.visibility='hidden';pageMask.style.visibility = 'hidden';
  pageMask.parentNode.removeChild(pageMask);
  var dvModal = document.getElementById('dvModal');
  dvModal.parentNode.removeChild(dvModal);
}
