﻿function showPopWin(url, width, height, showCloseBox, returnFunc) {
    showPopWin2(url, width, height, showCloseBox, returnFunc);
}

function showPopWin2(url, width, height, showCloseBox, beforeCloseFunc) {
    showPopWinTop(url, width, height, showCloseBox, beforeCloseFunc, null);
}

var win;
var tur;
function showPopWinTop(url, width, height, showCloseBox, beforeCloseFunc, title) {
    var windowConfig = {
        id: "WindowCommon",
        autoShow: false,
        modal: true,
        width: width,
        height: height,
        resizable: false,
        title: title,
        hidden: false,
        closeAction: "close",
        listeners: {
            hide: function () {
                if (beforeCloseFunc != null)
                    eval(beforeCloseFunc);
            }
        },
        autoLoad: {
            url: url,
            mode: "iframe",
            showMask: true,
            maskMsg: "Lütfen Bekleyiniz...",
            nocache: true,
            triggerEvent: "show",
            reloadOnEvent: true
        }
    };

    var parent;
    if (title == null)
        parent = Ext;
    else {
        parent = window.top.Ext;
        tur = "TOP";
    }

    win = parent.getCmp(windowConfig.id);
    if (!win)
        win = new parent.Window(windowConfig);
    else
        win.show();

    window.setTimeout('setTitle()', 1000);
}

function setTitle() {
    try {
        if (win) {
            var title = "";

            if (tur == "TOP")
                title = window.top.WindowCommon_IFrame.document.title;
            else
                title = WindowCommon_IFrame.document.title;
            win.setTitle(title);
        }
    }
    catch (e) { }
}

function hidePopWin(callReturnFunc) {
    if (win) {
        win.close();
    }
}


//function hidePopWin(callReturnFunc) {

//    var div = document.getElementById("generated_div");
//    $(div).dialog("close");
//}

//function showPopWin2(url, width, height, showCloseBox, beforeCloseFunc) {
//    var div = createDiv(width, height);
//    var frm = createIframe(div.id, url, width, height);

//    $(div).dialog({
//        autoOpen: false,
//        modal: true,
//        width: width,
//        height: height,
//        resizable: false,
//        title:'',
//        beforeClose: function () {
//            if (beforeCloseFunc != null)
//                eval(beforeCloseFunc);

//            var iframe = document.getElementById("generated_ifrm");
//            iframe.src = "../OrtakSayfa/bekle.htm";
//        }
//    });

//    $(div).dialog("open");

//    window.setTimeout('setTitle()', 1000);
//}

//function showPopPanel(panel, width, height, showOnTop, beforeCloseFunc, title) {
//    alert(panel);
//    var windowConfig = {
//        id: "WindowCommon",
//        autoShow: false,
//        modal: true,
//        width: width,
//        height: height,
//        resizable: false,
//        title: title,
//        hidden: false,
//        closeAction: "close",
//        listeners: {
//            hide: function () {
//                if (beforeCloseFunc != null)
//                    eval(beforeCloseFunc);
//            }
//        }
//    };

//    var parent;
//    if (!showOnTop)
//        parent = Ext;
//    else
//        parent = window.top.Ext;

//    var win = parent.getCmp(windowConfig.id);
//    if (!win)
//        win = new parent.Window(windowConfig);
//    else
//        win.show();
//    win.items.add(panel);
//}

//function setTitle() {
//    alert(win);
//    try {
//        //var title = $(generated_ifrm.document).attr('title');
//        var title = $(WindowCommon_IFrame.document).attr('title');
//        
//        if (title == "") title = ".";
//        $("span.ui-dialog-title").text(title);
//    }
//    catch (e) { }
//}

//function createDiv(width, height) {
//    var divId = "generated_div";
//    var div = document.getElementById(divId);
//    if (div == null) {
//        if (document.createElement && (div = document.createElement('div'))) {
//            div.name = div.id = divId;
//            document.body.appendChild(div);
//        }
//    }

//    div.style.width = width + "px";
//    div.style.height = height + "px";
//    return div;
//}

//function createIframe(parentDivId, url, width, height) {
//    var iframeId = "generated_ifrm";
//    var iframe = document.getElementById(iframeId);
//    if (iframe == null) {
//        if (document.createElement && (iframe = document.createElement('iframe'))) {
//            iframe.name = iframe.id = iframeId;
//            iframe.frameBorder = "0";
//            iframe.scroll = "no";
//            iframe.marginWidth = "0";
//            iframe.marginHeight = "0"

//            document.getElementById(parentDivId).appendChild(iframe);
//        }
//    }

//    iframe.src = url;
//    //    iframe.style.width = (width - 37) + "px";
//    //    iframe.style.height = (height - 27) + "px";
//    iframe.style.width = (width - 7) + "px";
//    iframe.style.height = (height - 27) + "px";

//    return iframe;
//}

function bilgiYaz(msg) {
    var adminStatus = $("[id$='bilgiKutusu']");
    var sayfa = '<div style="float:left; width:90%;">' + msg + '</div>' +
                '<div style="float:left; width:10%; font-weight:bold; text-align:right; vertical-align:top; ">' +
                    '<a href="javascript:HideStatus()" style="text-decoration:none; color:Red;">[kapat]</a>' +
                '</div>';

    adminStatus.html(sayfa);
    adminStatus.fadeIn(1000);
    //    window.setTimeout(function () {
    //        $("[id$='bilgiYaz']").fadeOut(1000);
    //    }, 5000);
}

function hataYaz(msg) {
    var adminStatus = $("[id$='bilgiKutusu']");
    var sayfa = '<div style="float:left; width:90%;">' + msg + '</div>' +
                '<div style="float:left; width:10%; font-weight:bold; text-align:right; vertical-align:top; ">' +
                    '<a href="javascript:HideStatus()" style="text-decoration:none; color:Red;">[kapat]</a>' +
                '</div>';

    adminStatus.html(sayfa);
    adminStatus.fadeIn(1000);
    //    window.setTimeout(function () {
    //        $("[id$='bilgiYaz']").fadeOut(1000);
    //    }, 5000);
}

function HideStatus() {
    $("[id$='bilgiKutusu']").slideUp('normal', function () { });
}

function MaxLength(control, maxlength) {
    maxlength -= 1;
    var text = control.value; //$("[id$='" + control.id + "']").val();
    if (text.length > maxlength)
        control.value = text.substring(0, maxlength);
}
