﻿function LogOrReg(action) {
    openDialog(action, RootUrl + "/register.html?v=03&t=" + action);
}

function openDialog(size, url, closeCF, isLoginRequire) {
    if (isLoginRequire && !IsAuthenticated) {
        LogOrReg('login');
        return false;
    }
    var _height, _width;

    var dimension = GetWindowDimensions(size);

    _height = dimension.height;
    _width = dimension.width;

    modalWindow.windowId = "myModal";
    modalWindow.content = "<iframe onload='parent.HideWaiting(\"" + size + "\"); modalWindow.setCloseButton();' width='0px' height='0px' id='modalFrame' frameborder='0' scrolling='no' allowtransparency='true' src='" + url + "'></iframe>";
    modalWindow.width = _width;
    modalWindow.height = _height;
    modalWindow.open(closeCF);

    SetIFrameContainerSize(size);
}

function openDialogWithSetHTML(HTML) {
    var size = "dialog";

    var dimension = GetWindowDimensions(size);


    modalWindow.windowId = "myModal";
    modalWindow.content = HTML;

    modalWindow.width = dimension.width;
    modalWindow.height = dimension.height; ;

    modalWindow.open();
    $("#spnLoad").hide();
	
}

function HideWaiting(size) {
    // setTimeout('SetWindowSize("' + size + '")', 100);
    SetWindowSize(size);
}

function Dimension(width, height) {
    this.width = width;
    this.height = height;
}

function GetWindowDimensions(size) {
    var dimension; ;
    switch (size) {
        case "login": dimension = new Dimension("565px", "270px"); break;
        case "forgot": dimension = new Dimension("565px", "256px"); break;
        case "register": dimension = new Dimension("565px", "390px"); break;
        case "crop": dimension = new Dimension("800px", "456px"); break;
        case "alert": dimension = new Dimension("200px", "50px"); break;
        case "edit": dimension = new Dimension("100px", "100px"); break;
        case "uploadvideo": dimension = new Dimension("625px", "363px"); break;
        case "updatevideo": dimension = new Dimension("565px", "299px"); break;
        case "deletevideo": dimension = new Dimension("565px", "154px"); break;
        case "detailvideo": dimension = new Dimension("565px", "243px"); break;
        case "updatephoto": dimension = new Dimension("565px", "269px"); break;
        case "deletephoto": dimension = new Dimension("550px", "154px"); break;
        case "updateprofile": dimension = new Dimension("565px", "387px"); break;
        case "sendmessage": dimension = new Dimension("565px", "217px"); break;
        case "sendtofriends": dimension = new Dimension("565px", "360px"); break;
        case "contact": dimension = new Dimension("565px", "254px"); break;
        case "inform": dimension = new Dimension("565px", "189px"); break;
		case "okmsgsize": dimension = new Dimension("565px", "150px"); break;

		case "okmsgsizebig": dimension = new Dimension("565px", "210px"); break;
        case "sharevideo": dimension = new Dimension("563px", "220px"); break;
        case "dialog": dimension = new Dimension("420px", "auto"); break;
        case "uploadcontent": dimension = new Dimension("496px", "317px"); break;
    }
    return dimension;
}



function JSONCALL(url) {
    var newelem = document.createElement("script");
    newelem.setAttribute("language", "javascript");
    newelem.setAttribute("type", "text\/javascript");
    newelem.setAttribute("src", url);
    document.getElementsByTagName("head")[0].appendChild(newelem);
}

$(document).ready(function() {
    // JSONCALL(RootUrl + "/ajax/AjaxPublic.ashx?action=insertvisited&url=" + encodeURIComponent(window.location.href));
});

function SetWindowSize(size) {
    $("#spnLoad").hide();
	$("#playerdiv").hide();
    var dimension = GetWindowDimensions(size);
    SetIFrameContainerSize(size);
    var mWindow = document.getElementById("modalFrame");
    if (mWindow != null) { // mWindow is null when HTML is inserted without iframe
        mWindow.style.width = dimension.width;
        mWindow.style.height = dimension.height;
    }
    var mWindow = document.getElementById("myModal");
    if (mWindow != null) { // mWindow is null when HTML is inserted without iframe
        mWindow.style.width = dimension.width;
        mWindow.style.height = dimension.height;
    }
}


function SetIFrameContainerSize(size) {
    var dimension = GetWindowDimensions(size);
    var mWindow = document.getElementById("modalFrame");
	var mWindow = document.getElementById("myModal");
	var mWindow = document.getElementById("spnLoad");
    if (mWindow != null) {
        mWindow.style.width = dimension.width;
        mWindow.style.height = dimension.height;
    }
}

var modalWindow = {
    parent: "body",
    windowId: null,
    content: null,
    width: null,
    height: null,
    lock: "0",
    closeCF: null,
    close: function () {
        $(".modal-window").remove();
        $(".modal-overlay").remove();
        if (this.closeCF != undefined && this.closeCF != '' && this.closeCF != null) {
            eval(this.closeCF);
        }
        this.lock = "0";
    },
    waitAndClose: function (waitTime) {
        setTimeout('$(".modal-window").fadeOut(500,function(){modalWindow.close();});', waitTime);
    },
    SetContent: function (windowId, content) {
        $('#' + windowId).html(content);
    },
    open: function (closeCF) {

        if (this.lock == "0") {
            this.lock = "1";
            var modal = "";
            modal += "<div class=\"modal-overlay\"></div>";
            modal += "<div id=\"" + this.windowId + "\" style=\"width:" + this.width + ";height:" + this.height + " \" class=\"modal-window fix\">";
            modal += "<div class=\"tableContain\">";

            modal += "<div id='iframeContainer' class=\"modalContent fix\">";
            modal += "<table id='spnLoad' cellpadding=\"0\" cellspacing=\"0\" width=\"100%\" height=\"100%\"><tr><td valign=\"middle\" align=\"center\"><div>Yükleniyor</div><div><img src=\"/images/new/greyLoad.gif\" border=\"0\" /></div></td></tr></table>";
            modal += this.content;
            modal += "</div>";

            modal += "</div>";
            modal += "</div>";


            $(this.parent).append(modal);

            //$(".modal-window").append("<a class=\"close-window\"></a>");

            $(".close-window").click(function () {
                modalWindow.close();
            });

            $(".modal-closer").click(function () {
                modalWindow.close();
            });

            var west = ($(window).width() - $("#myModal").width()) / 2;

            var scrollTop = f_scrollTop();
            var midvert = ($(window).height() - $("#myModal").height()) / 3 + scrollTop;

            $("#myModal").css({ top: midvert, left: west })

            $(document).keyup(function (event) {
                if (event.keyCode == 27 || event.keyCode == '27') {
                    event.cancel;
                    modalWindow.close();
                    $("#playerdiv").show();
                }
            });

            //   setTimeout("modalWindow.setCloseButton()", 1000);

        }
    },
    setCloseButton: function () {
        $('#modalframe').contents().find(".modal-closer").click(function () {
            parent.modalWindow.close();
            $("#playerdiv").show();
        });
    }
};

var IsThumSaved = 0; //call by iframe
function RELOAD() {
    if (IsThumSaved == 1) {
        location.reload(true);
    }
}

function f_clientWidth() {
    return f_filterResults(
		window.innerWidth ? window.innerWidth : 0,
		document.documentElement ? document.documentElement.clientWidth : 0,
		document.body ? document.body.clientWidth : 0
	);
}
function f_clientHeight() {
    return f_filterResults(
		window.innerHeight ? window.innerHeight : 0,
		document.documentElement ? document.documentElement.clientHeight : 0,
		document.body ? document.body.clientHeight : 0
	);
}
function f_scrollLeft() {
    return f_filterResults(
		window.pageXOffset ? window.pageXOffset : 0,
		document.documentElement ? document.documentElement.scrollLeft : 0,
		document.body ? document.body.scrollLeft : 0
	);
}
function f_scrollTop() {
    return f_filterResults(
		window.pageYOffset ? window.pageYOffset : 0,
		document.documentElement ? document.documentElement.scrollTop : 0,
		document.body ? document.body.scrollTop : 0
	);
}
function f_filterResults(n_win, n_docel, n_body) {
    var n_result = n_win ? n_win : 0;
    if (n_docel && (!n_result || (n_result > n_docel)))
        n_result = n_docel;
    return n_body && (!n_result || (n_result > n_body)) ? n_body : n_result;
}