﻿/*!
* JavaScript File
* Created By: umer Qureshi
* Date: 28 June 2010
* Modify By Ayaz Tariq 2010
*/


var popUp = null;
var popUpParent = null;
var contentFrame = null;
var divFrame = null;
function OpenPopup(width, height, popUpElement, parent, frame, src, headingElement, heading, showCloseButton) {
    popUp = document.getElementById(popUpElement);
    popUpParent = document.getElementById(parent);
    contentFrame = document.getElementById(frame);
    divFrame = document.getElementById('divFrame');
    // popUp.style.width=width + "px";
    // popUp.style.height=height +  "px";
    // SetDivLocation(width, height, popUp);

    showdeadcenterdiv(width, height, popUp)

    popUp.style.display = "block";

    if (src != "") {
        contentFrame.src = src;
        contentFrame.width = width - 20;
        contentFrame.height = height - 90;
        divFrame.style.width = width - 20 + "px";
        divFrame.style.height = height - 90 + "px";
    }
    document.getElementById(headingElement).innerHTML = heading;

    /* if (showCloseButton!=true)
    {
    document.getElementById('btnClose').style.visibility="hidden";
    }
    else
    {
    document.getElementById('btnClose').style.visibility="visible";
    }
    */
    document.getElementById('MaskedDiv').style.visibility = 'visible';
    document.getElementById('MaskedDiv').style.display = 'block';
}
function ClosePopup() {
    if (popUp != null) {
        popUp.style.display = "none";
        popUpParent = null;
        contentFrame.src = getBaseURL() + 'general/Loading.aspx';
        contentFrame = null;
        popUp = null;

        document.getElementById('MaskedDiv').style.display = 'none';
        document.getElementById('MaskedDiv').style.visibility = 'hidden';

    }
}

function getBaseURL() {
    var url = location.href;  // entire url including querystring - also: window.location.href;
    var baseURL = url.substring(0, url.indexOf('/', 14));

    if ( (url.length-1)  <= baseURL.length) {
        return baseURL + "/";
    }
    else {

        var url = location.href;  // window.location.href;
        var pathname = location.pathname;  // window.location.pathname;
        var index1 = url.indexOf(pathname);
        var index2 = url.indexOf("/", index1 + 1);
        var baseLocalUrl = url.substr(0, index2);
        return baseLocalUrl + "/";
    }
}

function SetDivLocation(w, h, div) {
    var LeftPosition = 0;
    var TopPosition = 0;
    LeftPosition = (screen.width) ? (screen.width - w) / 2 : 100;
    TopPosition = (screen.height) ? (((screen.height - h) / 2)) : 100;

    if ((TopPosition + h) >= screen.height - 250) {
        TopPosition = TopPosition - (h / 4);
    }
    else {

        TopPosition = TopPosition - (h / 2);
    }
    div.style.left = LeftPosition + "px";
    div.style.top = TopPosition + "px";
}
function SetHeading(txt) {
    if (txt != null) {
        var head = document.getElementById('lblHeading');
        if (head != null)
            head.innerHTML = txt;
    }
}

function setSize(width, height) {
    if (contentFrame && divFrame) {
        // contentFrame.width=width;
        // divFrame.style.width=width + "px";
        // divFrame.style.height=height +"px";  

        contentFrame.width = width - 20;
        contentFrame.height = height - 90;
        divFrame.style.width = width - 20 + "px";
        divFrame.style.height = height - 90 + "px";

        //SetDivLocation(width, height, popUp);

        showdeadcenterdiv(width, height, popUp);
    }
}

function setSizeFrame(width, height) {
    if (contentFrame && divFrame) {

        contentFrame.width = width - 20;
        contentFrame.height = height - 90;

        divFrame.style.width = width - 20 + "px";
        divFrame.style.height = height - 90 + "px";

        showdeadcenterdivFrame(width, height, popUp);
    }
}

function showdeadcenterdivFrame(Xwidth, Yheight, divid) {

    // First, determine how much the visitor has scrolled

    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the 
    // div passed as arguments to the function: 
    var leftOffset = scrolledX + (centerX - Xwidth) / 2;
    var topOffset = scrolledY + (centerY - Yheight) / 2;
    // The initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 
    // var o = document.getElementById(divid);
    leftOffset = leftOffset - 10;

    //    if (Yheight < 330) {

    //        topOffset = topOffset - 50;
    //    } 

    divid.style.position = 'absolute';
    divid.style.top = (topOffset + 40) + 'px';
    //divid.style.left = (topOffset) + 'px';
    divid.style.display = "block";
}

function showdeadcenterdiv(Xwidth, Yheight, divid) {
    // First, determine how much the visitor has scrolled

    var scrolledX, scrolledY;
    if (self.pageYOffset) {
        scrolledX = self.pageXOffset;
        scrolledY = self.pageYOffset;
    } else if (document.documentElement && document.documentElement.scrollTop) {
        scrolledX = document.documentElement.scrollLeft;
        scrolledY = document.documentElement.scrollTop;
    } else if (document.body) {
        scrolledX = document.body.scrollLeft;
        scrolledY = document.body.scrollTop;
    }

    // Next, determine the coordinates of the center of browser's window

    var centerX, centerY;
    if (self.innerHeight) {
        centerX = self.innerWidth;
        centerY = self.innerHeight;
    } else if (document.documentElement && document.documentElement.clientHeight) {
        centerX = document.documentElement.clientWidth;
        centerY = document.documentElement.clientHeight;
    } else if (document.body) {
        centerX = document.body.clientWidth;
        centerY = document.body.clientHeight;
    }

    // Xwidth is the width of the div, Yheight is the height of the 
    // div passed as arguments to the function: 
    var leftOffset = scrolledX + (centerX - Xwidth) / 2;
    var topOffset = scrolledY + (centerY - Yheight) / 2;
    // The initial width and height of the div can be set in the 
    // style sheet with display:none; divid is passed as an argument to // the function 
    // var o = document.getElementById(divid);
    leftOffset = leftOffset - 10;

    //    if (Yheight < 330) {

    //        topOffset = topOffset - 50;
    //    } 

    divid.style.position = 'absolute';
    divid.style.top = topOffset + 'px';
    divid.style.left = leftOffset + 'px';
    divid.style.display = "block";
}

function ShowInlinePopupFrame() {

    $(document).ready(function () {
        if ($.browser.msie)
            $('#contentFrame').attr('allowTransparency', 'false');
        $('#popUp .corners_topleft').hide();
        $('#popUp .corners_bg').hide();
        $('#popUp .corners_topright').hide();
        $('#popUp .corners_bg2').hide();
        $('#popUp .corners_bottomleft').hide();
        $('#popUp .corners_bottomright').hide();
        $('#popUp .header').hide();
        $('#popUp .divbox').css('background-color', 'transparent');
        $('#popUp .divbox').css('border', 'none');
        $('#contentFrame').attr('scrolling', 'no');
        $('#contentFrame').css('overflow', 'hidden');
       
    });
}
function HideInlinePopupFrame() {

    $(document).ready(function () {
        if ($.browser.msie)
             $('#contentFrame').attr('allowTransparency','true');
        $('#popUp .corners_topleft').show();
        $('#popUp .corners_bg').show();
        $('#popUp .corners_topright').show();
        $('#popUp .corners_bg2').show();
        $('#popUp .corners_bottomleft').show();
        $('#popUp .corners_bottomright').show();
        $('#popUp .header').show();
        $('#popUp .divbox').css('background-color', '#FFFFFF');
        $('#popUp .divbox').css('border', '1px solid #555555');
        $('#contentFrame').attr('scrolling', 'auto');
        $('#contentFrame').css('overflow', 'auto');
    });
}
