﻿function openText() {
    var myDiv = document.getElementById('textView');

    var height = getViewPortHeight();
    var width = getViewPortWidth();

    height = (height / 2) - 600 / 2;
    width = (width / 2) - 200 / 2;
    myDiv.style.top = height + "px";
    myDiv.style.left = width + "px";
    myDiv.style.display = 'inline';
}
var maxHeight = 450;
var maxWidth = 450;
function getViewPortWidth() {
    var viewportwidth;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerWidth != 'undefined') {
        viewportwidth = window.innerWidth;
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientWidth !=
	     'undefined' && document.documentElement.clientWidth != 0) {
        viewportwidth = document.documentElement.clientWidth;
    }

    // older versions of IE

    else {
        viewportwidth = document.getElementsByTagName('body')[0].clientWidth;
    }
    return viewportwidth;
}
function getViewPortHeight() {
    var viewportheight;

    // the more standards compliant browsers (mozilla/netscape/opera/IE7) use window.innerWidth and window.innerHeight

    if (typeof window.innerHeight != 'undefined') {
        viewportheight = window.innerHeight;
    }

    // IE6 in standards compliant mode (i.e. with a valid doctype as the first line in the document)

    else if (typeof document.documentElement != 'undefined'
	     && typeof document.documentElement.clientHeight !=
	     'undefined' && document.documentElement.clientHeight != 0) {
        viewportheight = document.documentElement.clientHeight;
    }

    // older versions of IE

    else {
        viewportheight = document.getElementsByTagName('body')[0].clientHeight;
    }
    return viewportheight;
}
function closeWindow() {
    closeSpesWindow('ImageView');
}
function closeSpesWindow(divId) {
    var myDiv = document.getElementById(divId);
    myDiv.style.display = 'none';
}
function $(v) {
    return (document.getElementById(v));
}
function agent(v) {
    return (Math.max(navigator.userAgent.toLowerCase().indexOf(v), 0));
}
function xy(e, v) {
    return (v ? (agent('msie') ? event.clientY + document.body.scrollTop : e.pageY) : (agent('msie') ? event.clientX + document.body.scrollTop : e.pageX));
}

function dragOBJ(d, e) {
    function drag(e) {
        if (!stop) {
            d.style.top = (tX = xy(e, 1) + oY - eY + 'px'); d.style.left = (tY = xy(e) + oX - eX + 'px');
        }
    }
    var oX = parseInt(d.style.left), oY = parseInt(d.style.top), eX = xy(e), eY = xy(e, 1), tX, tY, stop;
    document.onmousemove = drag; document.onmouseup = function () { stop = 1; document.onmousemove = ''; document.onmouseup = ''; };
}
function changePhoto(theImage, img) {
    img.src = theImage.src;
    var width = theImage.width;
    var height = theImage.height;
    var newx = 450; // set to whatever you want the images max width to be.
    var newy = 450; // whatever you want the images maximum height to be.
    if (width >= height) {
        // landscape
        var tmpy = height * maxWidth / width;
        if (tmpy <= maxHeight) {
            newy = tmpy;
            newx = maxWidth;
        }
        else {
            newx = width * maxHeight / height;
            newy = maxHeight;
        }
    }
    else {
        // portrait
        var tmpx = width * maxHeight / height;
        if (tmpx <= maxWidth) {
            newx = tmpx;
            newy = maxWidth;
        }
        else {
            newy = height * maxWidth / width;
            newx = maxWidth;
        }
    }
    img.width = newx;
    img.height = newy;
}
