﻿// JavaScript Document
var modalOpen = null;

if (!window.console) {
    window.console = {
        debug: function (o) {
            alert(o);
        }
    }
}
function popModal() {

  
    var width = 800;
    $("#modal2").css('left', (width - 400) / 2);
    $("#modal2").show();

}
function killModal2() {

    $("#modal2").hide();

}

function displaySizedModal(h, w, u, sender) {
    sizeModal(h, w);


    var src = ""; //  encodeURIComponent(window.location.pathname); //+ window.location.search);
    var cls = $("#modal").attr("class");

    u = u + '&parentURL=' + src + "&mh=" + h + "&mw=" + w + "&mcls=" + cls;

    if (sender) {
        sender.attr("href", u);
    }
    showModal(u);


}
function sizeModal(h, w) {
    $("#modal").css('height', h + 'px');
    $("#modal").css('width', w + 'px');
    $("#ifr_modal").css('height', h + 'px');
    $("#ifr_modal").css('width', w + 'px');

    var myWidth = $(window).width();
    var margin = parseInt((myWidth - w) / 2);
    var scrollTop = $(window).scrollTop();
    var marginTop = scrollTop + parseInt(($(window).height() - h) / 2) - 30;

    // $('html, body').animate({ scrollTop: 0 }, 'fast');
    $("#modal").css('marginLeft', margin + 'px');
    $("#modal").css('marginTop', marginTop + 'px');
}
function showModal(x) {

    modalOpen = $("#modal");

    $("#ifr_modal").attr('src', x);
    $("#fade").show();
    $("#modal").fadeIn('fast');
}
function hideModal() {
    modalOpen = null;
    $("#fade").hide();
    $("#modal").fadeOut('fast');
    $("#modal").removeClass('shareModal');
    $("#ifr_modal").src = "about:blank";
}


function closemodal() {

    if (modalOpen != null) {
        hideModal();
        modalOpen = null;
    }
}

function SelectImage(imageObject, path) {

    if ($("#" + CurrentImageObject)) {
        var o = $("#" + CurrentImageObject);
        o.attr('src', path);
        closemodal();

        var f = $("#" + CurrentFormObject);
        f.val(path);
    }
}


var viewWindow;

function repurposeWindow(width, height, xLeft, yTop) {
    viewWindow.moveTo(xLeft, yTop);
    if (viewWindow.resizeTo || navigator.userAgent.indexOf('Gecko') == -1) {
        viewWindow.resizeTo(width, height);
    } else {
        viewWindow.outerWidth = width;
        viewWindow.outerHeight = height;
    }
    viewWindow.moveTo(xLeft, yTop); //This must be done twice so browser doesn't override setting for window being off screen.
    setTimeout('viewWindow.focus();', 100);
}

function openWindow(fileName, width, height) {
    if (!height) height = 500;
    if (!width) width = 310;
    xLeft = (screen.width) ? (screen.width - width) / 2 : 0;
    yTop = (screen.height) ? (screen.height - height) / 2 : 0;
    if (window.locationbar) height += 50;
    if (viewWindow && !viewWindow.closed) {
        viewWindow.location = fileName;
    } else {
        viewWindow = 'window.open("' + fileName + '", "viewWindow", "height=' + height + ',width=' + width + ',' +
		'status=no,scrollbars=1,resizable=no,toolbar=no,copyhistory=no,location=no,left=' + xLeft + ',top=' + yTop + ',screenX=' + xLeft + ',screenY=' + yTop + '")';
        viewWindow = eval(viewWindow);
    }
    repurposeWindow(width, height, xLeft, yTop);
}


function getScreenWidth() {

    var myWidth = 0, myHeight = 0;
    if (typeof (window.innerWidth) == 'number') {
        //Non-IE
        myWidth = window.innerWidth;
        myHeight = window.innerHeight;
    } else if (document.documentElement && (document.documentElement.clientWidth || document.documentElement.clientHeight)) {
        //IE 6+ in 'standards compliant mode'
        myWidth = document.documentElement.clientWidth;
        myHeight = document.documentElement.clientHeight;
    } else if (document.body && (document.body.clientWidth || document.body.clientHeight)) {
        //IE 4 compatible
        myWidth = document.body.clientWidth;
        myHeight = document.body.clientHeight;
    }
    return myWidth;
}        

