﻿var modalCount = 0;
var dragStarted = false;
var iframeTemplate = '';
iframeTemplate += '<table cellpadding="0" cellspacing="0" border="0">';
iframeTemplate += '    <tr height="27" onmousedown="HeaderHolded();" onmouseup="HeaderReleased();">';
iframeTemplate += '        <td style="width: 6px">';
iframeTemplate += '            <img src="/Images/Left.gif" style="width: 6px">';
iframeTemplate += '        </td>';
iframeTemplate += '        <td background="/Images/Middle.gif" valign="middle" width="#frameWidth#">';
iframeTemplate += '            <img src="/Images/CloseRed.gif" align="right" style="cursor: pointer;" title="Pencereyi Kapat" onclick="window.top.CloseModal(#modalCount#);" />';
iframeTemplate += '            <div style="width: 100%; padding-top: 10px; color: #c92f2f; font-size: 9pt; font-family: Arial; font-weight: bold">#title#</div>';
iframeTemplate += '        </td>';
iframeTemplate += '        <td background="/Images/Right.gif" style="width: 6px">&nbsp;</td>';
iframeTemplate += '    </tr>';
iframeTemplate += '    <tr>';
iframeTemplate += '        <td colspan="3">';
iframeTemplate += '            <table cellspacing="5" cellpadding="0" width="100%" height="100%" style="border-left: solid 1px #809AA9;border-right: solid 1px #809AA9; border-bottom: solid 1px #809AA9; border-top: none none none;"bgcolor="#F0F5F8">';
iframeTemplate += '                <tr>';
iframeTemplate += '                    <td style="border-bottom: solid 1px #809AA9; border-left: solid 1px #809AA9; border-right: solid 1px #809AA9;border-top: solid 1px #809AA9; background-color: White; padding: 2px 2px 2px 2px"valign="top">';
iframeTemplate += '                        <iframe src="#url#" width="#width#" height="#height#" scrolling="no" onload="window.top.SetPopupDivSize(this,this.width,this.height)" frameborder="0" id="#frameID#"></iframe>';
iframeTemplate += '                    </td>';
iframeTemplate += '                </tr>';
iframeTemplate += '            </table>';
iframeTemplate += '        </td>';
iframeTemplate += '    </tr>';
iframeTemplate += '</table>';
//window.top.document.onmousemove = MouseMove;
function ShowModal(url, width, height, title) {
    window.top.modalCount++;
    // once maski gosterelim
    if (!ft('popupMask' + window.top.modalCount)) {
        CreateMask(window.top.modalCount);
    }
    var mask = ft('popupMask' + window.top.modalCount);
    mask.style.display = 'block'

    // simdi conteyniri gosterelim
    if (!ft('popupContainer' + window.top.modalCount)) {
        CreateContainer(window.top.modalCount);
    }
    var container = ft('popupContainer' + window.top.modalCount);

    var tmp = iframeTemplate.replace('#url#', url);
    tmp = tmp.replace('#width#', width);
    tmp = tmp.replace('#height#', height);
    tmp = tmp.replace('#modalCount#', window.top.modalCount);
    tmp = tmp.replace('#title#', title);
    tmp = tmp.replace('#frameWidth#', width + 20);
    tmp = tmp.replace('#frameID#', 'frame' + window.top.modalCount);
    container.innerHTML = tmp;
    container.style.display = 'block';
    container.style.marginLeft = (-1 * (width / 2)) + 'px';
    container.style.marginTop = (-1 * (height / 2)) + 'px';
    container.setAttribute('w', width);
    container.setAttribute('h', height);
    container.style.width = (width + 18) + 'px';
    

    SetMaskSize();
}

function SetMaskSize() {
    var docWidth = getDocWidth();
    var docHeight = getDocHeight();
    var mask = null;
    for (var i = 1; i <= window.top.modalCount; i++) {
        mask = ft('popupMask' + i);
    }
}
function CloseModal(count) {
    ft('popupMask' + count).style.display = 'none';
    ft('popupContainer' + count).style.display = 'none';
    window.top.modalCount--;
}
function CreateMask(mc) {
    var popMask = window.top.document.createElement('div');
    popMask.id = 'popupMask' + mc;
    popMask.style.display = 'none';
    popMask.className = 'popupMask';
    popMask.style.zIndex = 50 * mc;
    popMask.style.position = 'fixed';
    popMask.style.top = '0';
    popMask.style.left = '0';
    popMask.style.width = '100%';
    popMask.style.height = '100%';
    popMask.style.backgroundColor = '#C5D5D6';
    popMask.style.verticalAlign = 'middle';
    popMask.style.opacity = 0.30;
    popMask.style.filter = 'alpha(opacity=30)';
    popMask.style.MozOpacity = 0.30;
    window.top.document.body.appendChild(popMask);
}
function CreateContainer(mc) {
    var popContainer = window.top.document.createElement('div');
    popContainer.id = 'popupContainer' + mc;
    popContainer.className = 'popupContainer';
    popContainer.style.zIndex = (50 * mc) + 1;
    popContainer.style.display = 'none';
    popContainer.style.position = 'fixed';
    popContainer.style.padding = '0px';
    popContainer.style.left = '50%';
    popContainer.style.top = '50%';
    window.top.document.body.appendChild(popContainer);
}
function f(id)// find
{
    return document.getElementById(id);
}
function ft(id)// top da find
{
    return window.top.document.getElementById(id);
}
function fp(id) //  parent ta find, 4. seviyedeki popupdan 3. seviyedeki popupa erisme
{
    if (window.top.modalCount == 1) {
        return window.parent.document.getElementById(id)
    }
    else {
        return eval('window.top.frame' + (window.top.modalCount - 1) + '.document;').getElementById(id);
    }
}
function SetPopupDivSize(frame, width, heigth) {
    var divContainer = eval('window.top.' + frame.id + '.document;').getElementById('divPageContainer');
    if (divContainer) {
        divContainer.style.width = width + 'px';
        divContainer.style.height = heigth + 'px';
    }
}
function getDocHeight() {
    return window.top.document.documentElement.offsetHeight;
}
function getDocWidth() {
    return window.top.document.documentElement.offsetWidth;
}
function MouseMove(e) {


}
function HeaderHolded() {
    dragStarted = true;
    window.top.document.body.style.cursor = 'move';
}
function HeaderReleased() {
    dragStarted = false;
    window.top.document.body.style.cursor = 'default';
}


