﻿var cHeight;
var cWidth;
var myMediaType;
var myPageSize;
var myPageScroll;
var xScroll;
var yScroll;
var myWidth;
var myHeight;
var myOverlay;
var myLightBox;
var myBody;
var myIFrame;

function ShowReservation(pId)
{
    myControl = pId.split('_')[0] + "_" + pId.split('_')[1] + "_";

    window.open("http://reservation.lesottomans.com?Q1=" + document.getElementById(myControl + "txtArrivalDate").value + "&Q2=" + document.getElementById(myControl + "txtDepartureDate").value);
}


function ShowLightBox(pLink, pHeight, pWidth) 
{
    cHeight = pHeight;
    cWidth = pWidth;

    InitLightBox()

    myOverlay = document.getElementById("myOverlay");
    myLightBox = document.getElementById("myLightBox");

    myOverlay.style.display = 'block';
    myLightBox.style.top = myPageScroll[1] + ((myPageSize[3] - cHeight) / 2) + "px";
    myLightBox.style.left = ((myPageSize[0] - cWidth) / 2) + "px";
    myLightBox.style.display = 'block';

    LoadPage(pLink);
}

function InitLightBox() 
{
    myPageSize = PageSize();
    myPageScroll = PageScroll();

    myBody = document.getElementsByTagName("body").item(0);

    // -------
    // Overlay
    // -------
    myOverlay = document.createElement('div');
    myOverlay.setAttribute('id', 'myOverlay');
    myOverlay.onclick = function () { CloseLightBox(); return false; }
    myOverlay.style.display = 'none';
    myOverlay.style.position = 'absolute';
    myOverlay.style.top = '0';
    myOverlay.style.left = '0';
    myOverlay.style.zIndex = '100';
    myOverlay.style.width = '100%';
    myOverlay.style.height = myPageSize[1] + 'px';
    myBody.insertBefore(myOverlay, myBody.firstChild);

    // --------
    // LightBox
    // --------
    myLightBox = document.createElement("div");
    myLightBox.setAttribute('id', 'myLightBox');
    myLightBox.style.display = 'none';
    myLightBox.style.position = 'absolute';
    myLightBox.style.zIndex = '120';
    myLightBox.style.width = cWidth + 'px';
    myLightBox.style.height = cHeight + 'px';
    myBody.insertBefore(myLightBox, myOverlay.nextSibling);

    // ----
    // Link
    // ----
    myLink = document.createElement("a");
    myLink.setAttribute('href', '#');
    myLink.setAttribute('title', 'Click to close');
    myLink.onclick = function () { CloseLightBox(); return false; }
    myLightBox.appendChild(myLink);

    // -----------
    // Close Image
    // -----------
    myCloseButton = document.createElement("img");
    //myCloseButton.src = 'http://www.hotellesottomansinistanbul.com/Tools/Images/Close.gif';
    myCloseButton.src = 'http://www.lesottomans.com/Tools/Images/Close.gif';
    myCloseButton.setAttribute('id', 'closeButton');
    myCloseButton.style.position = 'absolute';
    myCloseButton.style.zIndex = '200';
    myLink.appendChild(myCloseButton);
}

function PageSize() 
{
    if (window.innerHeight && window.scrollMaxY) 
    {
        xScroll = document.body.scrollWidth;
        yScroll = window.innerHeight + window.scrollMaxY;
    }
    else if (document.body.scrollHeight > document.body.offsetHeight) 
    {
        xScroll = document.body.scrollWidth;
        yScroll = document.body.scrollHeight;
    }
    else if (document.body) 
    {
        xScroll = document.body.offsetWidth;
        yScroll = document.body.offsetHeight;
    }

    if (self.innerHeight) 
    {
        myWidth = self.innerWidth;
        myHeight = self.innerHeight;
    }
    else if (document.documentElement && document.documentElement.clientHeight) 
    {
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    }
    else if (document.body)
    {
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }

    if (yScroll < myHeight) 
    {
        pHeight = myHeight;
    }
    else 
    {
        pHeight = yScroll;
    }

    if (xScroll < myWidth) 
    {
        pWidth = myWidth;
    }
    else 
    {
        pWidth = xScroll;
    }

    myPageSize = new Array(pWidth, pHeight, myWidth, myHeight)

    return myPageSize;
}

function PageScroll() 
{
    yScroll;

    if (self.pageYOffset) 
    {
        yScroll = self.pageYOffset;
    }
    else if (document.documentElement && document.documentElement.scrollTop) 
    {
        yScroll = document.documentElement.scrollTop;
    }
    else if (document.body) 
    {
        yScroll = document.body.scrollTop;
    }

    myPageScroll = new Array('', yScroll)

    return myPageScroll;
}

function CloseLightBox() 
{
    myOverlay.style.display = 'none';
    myLightBox.style.display = 'none';
    myLightBox.removeChild(myIFrame);
}

function LoadPage(pLink) 
{
    myIFrame = document.createElement("iframe");
    myIFrame.src = pLink;
    myIFrame.setAttribute('width', cWidth);
    myIFrame.setAttribute('height', cHeight);
    myIFrame.setAttribute('frameborder', '0');
    myIFrame.setAttribute('scrolling', 'auto');
    myIFrame.setAttribute('id', 'myIFrame');
    myLightBox.appendChild(myIFrame)
}



