﻿function sm(a, b) {
    var c = "lto";
    var d = "mai";
    window.location = d + c + ":" + a.replace('~', '.') + "@" + b.replace('~', '.');
}

function sw() {
    return $(window).width();
}

function sh() {
    return $(window).height();
}

function LayerHeight() {
    if (sh() < 100) {
        return 100;
    }
    else {
        return sh() - 100;
    }
}

function LayerLeft() {
    if (sw() < 720) {
        return 0;
    }
    else {
        return (sw() - 720) / 2;
    }
}

function resizeWindow() {
    document.getElementById("ShadowLayer").style.width = sw() + "px";
    if (($("#LayerContentProduct").height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($("#LayerContentProduct").height() + 100) + "px";
    }
    else {
        if (($("#LayerContentNews").height() - 100) > sh()) {
            document.getElementById("ShadowLayer").style.height = ($("#LayerContentNews").height() + 100) + "px";
        }
        else {
            document.getElementById("ShadowLayer").style.height = sh() + "px";
        }
    }
    document.getElementById("LayerContentProduct").style.left = LayerLeft() + "px";
    document.getElementById("LayerProductDetail").style.left = LayerLeft() + "px";
    document.getElementById("LayerContentNews").style.left = LayerLeft() + "px";
    document.getElementById("GalleryDetail").style.left = LayerLeft() + "px";
}

function openProductLayer() {
    if (($("#LayerContentProduct").height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($("#LayerContentProduct").height() + 100) + "px";
        document.getElementById("ShadowLayer").style.width = sw() - 17 + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#ShadowLayer").fadeTo("slow", 0.7);
    $("#LayerContentProduct").fadeIn("slow");
}

function closeProductLayer() {
    $("#ShadowLayer").fadeOut("slow");
    $("#LayerContentProduct").fadeOut("slow");
}

function closeGalleryLayer() {
    $("#ShadowLayer").fadeOut("slow");
    $("#GalleryDetail").fadeOut("slow");
}

function openProductDetailLayer(openLayer, closeLayer, image, showBack) {
    if (showBack == 0) {
        $(".LayerBack").hide();
        $(".LayerClose").show();
    }
    else {
        $(".LayerBack").show();
        $(".LayerClose").hide();
    }

    if (sh() < 820) {
        document.getElementById("ShadowLayer").style.height = "820px";
        document.getElementById("ShadowLayer").style.width = sw() - 17 + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    if (closeLayer != "") {
        $("#LayerProductDetail").attr('style', 'background-image: url(/ResourceImage.aspx?raid=' + image + '); left: ' + LayerLeft() + 'px;');
        $("#LayerProductDetail").html($(openLayer).html());
        $(closeLayer).fadeOut("slow");
        $("#LayerProductDetail").fadeIn("slow");
    }
    else {
        $("#ShadowLayer").fadeTo("slow", 0.7);
        $("#LayerProductDetail").attr('style', 'background-image: url(/ResourceImage.aspx?raid=' + image + '); left: ' + LayerLeft() + 'px;');
        $("#LayerProductDetail").html($(openLayer).html());
        $("#LayerProductDetail").fadeIn("slow");
    }
}

function closeProductDetailLayer() {
    $("#ShadowLayer").fadeOut("slow");
    $("#LayerProductDetail").fadeOut("slow");
}

function toggleProductDetail() {
    $('#LayerProductDetail').find('div.LayerProductDetailBackground').css('opacity', 0.6).toggle('blind');
    $('#LayerProductDetail').find('div.LayerProductDetailContent').toggle('blind');
}

function backToProductLayer() {
    if (($("#LayerContentProduct").height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($("#LayerContentProduct").height() + 100) + "px";
        //document.getElementById("ShadowLayer").style.width = sw() - 17 + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#LayerProductDetail").fadeOut("slow");
    $("#LayerContentProduct").fadeIn("slow");
}

function openNewsLayer(openLayer) {
    if (($(openLayer).height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($(openLayer).height() + 100) + "px";
        document.getElementById("ShadowLayer").style.width = sw() - 17 + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#ShadowLayer").fadeTo("slow", 0.7);
    $("#LayerContentNews").html($(openLayer).html());
    $("#LayerContentNews").fadeIn("slow");
}

function closeNewsLayer() {
    $("#ShadowLayer").fadeOut("slow");
    $("#LayerContentNews").fadeOut("slow");
}

function openGalleryLayer(Image) {
    if (($("#GalleryDetail").height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($("#GalleryDetail").height() + 100) + "px";
        document.getElementById("ShadowLayer").style.width = sw() - 17 + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#ShadowLayer").fadeTo("slow", 0.7);
    $("#GalleryDetail").fadeIn("slow");
    $(".GalleryDetailItem").hide();
    if (Image != "") {
        $(Image).fadeIn("slow");
    }
}

function openGalleryImage(Image) {
    $(".GalleryDetailItem").hide();
    if (Image != "") {
        $(Image).fadeIn("slow");
    }
}

function openNewsArchivDetailLayer(openLayer) {
    if (($(openLayer).height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($(openLayer).height() + 100) + "px";
        document.getElementById("ShadowLayer").style.width = sw() - 17 + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#LayerContentNews").hide().html($(openLayer).html()).fadeIn("slow");
}

function openSearchResultLayer(openLayer) {
    if (($(openLayer).height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($(openLayer).height() + 100) + "px";
        document.getElementById("ShadowLayer").style.width = sw() - 17 + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#ShadowLayer").fadeTo("slow", 0.7);
    $("#LayerContentNews").html($(openLayer).html());
    $("#LayerContentNews").fadeIn("slow");
}

function openSearchItemLayer(openLayer) {
    if (($(openLayer).height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($(openLayer).height() + 100) + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#LayerContentNews").hide().html($(openLayer).html()).fadeIn("slow");
}

function openBackSearchResultLayer(openLayer) {
    if (($(openLayer).height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($(openLayer).height() + 100) + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#LayerContentNews").hide().html($(openLayer).html()).fadeIn("slow");
}

function GetRandom(min, max) {
    if (min > max) {
        return (1);
    }
    if (min == max) {
        return (min);
    }
    return (min + parseInt(Math.random() * (max - min + 1)));
}

function SelectOption(strValue, strText) {
    var strOption = "";
    if (strValue != "" && strText != "") {
        strOption = "<option value=\"" + strValue + "\">" + strText + "</option>";
    }
    return strOption;
}

function closeShadowLayer() {
    $("#ShadowLayer").fadeOut("slow");
    $("#LayerContentNews").fadeOut("slow");
    $("#LayerContentProduct").fadeOut("slow");
    $("#LayerProductDetail").fadeOut("slow");
    $("#SiteSearchLayer").fadeOut("slow");
    $("#GalleryDetail").fadeOut("slow");
}

function openURL(varURL) {
    if (varURL != "") {
        $.get(varURL + '/t-' + GetRandom(1, 9999999999) + '/', function (data) {
            if (data.indexOf("<!--DataOutput Start-->") > 0) {
                if (data.lastIndexOf("<!--DataOutput End-->") > data.indexOf("<!--DataOutput Start-->")) {
                    $('#LayerURL').html(data.substring(data.indexOf("<!--DataOutput Start-->"), data.lastIndexOf("<!--DataOutput End-->")));
                }
            }
            else {
                $('#LayerURL').html(data);
            }
        }).complete(function () {
            openLayerURL('#LayerURL');
        });
    }
}

function openLayerURL(openLayer) {
    if (($(openLayer).height() + 100) > sh()) {
        document.getElementById("ShadowLayer").style.height = ($(openLayer).height() + 100) + "px";
        document.getElementById("ShadowLayer").style.width = sw() - 17 + "px";
    }
    else {
        document.getElementById("ShadowLayer").style.height = sh() + "px";
        document.getElementById("ShadowLayer").style.width = sw() + "px";
    }

    $("#ShadowLayer").fadeTo("slow", 0.7);
    $("#LayerContentNews").html($(openLayer).html());
    $("#LayerContentNews").fadeIn("slow");
}

function open3DModel(strURL) {
    strURL = strURL.replace(/-/g, "");
    strWindow = window.open(strURL, "3DModel", "height=550,width=700,location=no,toolbar=no,menubar=no,status=no");
    strWindow.focus();
}

function getURLArchivDetail(varURL) {
    $.get(varURL + '/t-' + GetRandom(1, 9999999999) + '/', function (data) {
        if (data.indexOf("<!--DataOutputDetail Start-->") > 0) {
            if (data.lastIndexOf("<!--DataOutputDetail End-->") > data.indexOf("<!--DataOutputDetail Start-->")) {
                $('#NewsArchivDetailLayer').html(data.substring(data.indexOf("<!--DataOutputDetail Start-->"), data.lastIndexOf("<!--DataOutputDetail End-->")));
            }
        }
        else {
            $('#NewsArchivDetailLayer').html(data);
        }
    }).complete(function () {
        openNewsArchivDetailLayer('#NewsArchivDetailLayer');
    });
}

function getURLArchiv(varURL) {
    $.get(varURL + '/t-' + GetRandom(1, 9999999999) + '/', function (data) {
        if (data.indexOf("<!--DataOutput Start-->") > 0) {
            if (data.lastIndexOf("<!--DataOutput End-->") > data.indexOf("<!--DataOutput Start-->")) {
                $('#NewsArchivLayer').html(data.substring(data.indexOf("<!--DataOutput Start-->"), data.lastIndexOf("<!--DataOutput End-->")));
            }
        }
        else {
            $('#NewsArchivLayer').html(data);
        }
    }).complete(function () {
        openNewsLayer('#NewsArchivLayer');
    });
}

function openPage(varURL) {
    if (varURL != "") {
        document.location = varURL;
    }
}

window.onresize = resizeWindow;

