﻿// JScript File

window.onresize = cleanup; //Cleanup any windows if they try and resize

var zTime = null;
var divObject = null;
var divObjectFrame = null;
var curZoom = 0;
var ZoomTime = 1;
var MenuZoom = false;

function zIn()
{
    if (curZoom < 100)
    {
        document.getElementById(divObject).style.zoom = curZoom + '%';
        if (divObjectFrame != null)
        {
            document.getElementById(divObjectFrame).style.zoom = curZoom + '%';
        }
        curZoom += 10 - 1;
    }
    else
    {
        document.getElementById(divObject).style.zoom = '100%';
        if (divObjectFrame != null)
        {
            document.getElementById(divObjectFrame).style.zoom = '100%';
        }
        divObject = null;
        divObjectFrame = null;
        curZoom = 0;
        clearInterval(zTime);
        MenuZoom = false;
    }
}
function zOut()
{
    if (curZoom > 0)
    {
        document.getElementById(divObject).style.zoom = curZoom + '%';
        if (divObjectFrame != null)
        {
            document.getElementById(divObjectFrame).style.zoom = curZoom + '%';
        }
        if (curZoom != 100)
        {
	        curZoom -= 10 + 1;
	    }
	    else
	    {
	        curZoom -= 10;
	    }
    }
    else
    {
        document.getElementById(divObject).className='standardwindowHidden';
        if (divObjectFrame != null)
        {
            document.getElementById(divObjectFrame).className='standardwindowHidden';
        }
        document.getElementById(divObject).style.zoom = '1%';
    
        divObject = null;
        divObjectFrame = null;
        curZoom = 0;
	    clearInterval(zTime);
	    MenuZoom = false;
    }
}


function timeZoomIn(obj1, obj2)
{
    if (MenuZoom == false)
    {
        divObject = obj1;
        if (obj2 != null)
        {
            divObjectFrame = obj2;
        }
        else
        {
            divObjectFrame = null;
        }
        curZoom = 1
        MenuZoom = true;
        zTime = setInterval('zIn()',ZoomTime);
    }
}	
function timeZoomOut(obj1, obj2)
{
    if (MenuZoom == false)
    {
        divObject = obj1;
        if (obj2 != null)
        {
            divObjectFrame = obj2;
        }
        else
        {
            divObjectFrame = null;
        }
        curZoom = 100
        MenuZoom = true;
        zTime = setInterval('zOut()',ZoomTime);
    }
}
////////////////////////////////
// Pop Up Window Functions
////////////////////////////////
var Message;

function MessageOBJ(name, height, width)
{
    this.name = name;
    this.height = height;
    this.width = width;
}

function MessageRegister(_Message, height, width)
{
    if (height == null)
        height = 265;
    
    if (width == null)
        width = 500;
    
    if (IsObject(Message))
    {
        if (Message.name != _Message)
        {
            var loWindow = document.getElementById(Message.name);
            
            //Make sure it still exists as the AJAX may have removed the HTML
            if (loWindow != null)
                loWindow.className = 'standardwindowHidden';
        }
    }
    Message = new MessageOBJ(_Message, height, width);
    ShowMessage(Message);
}

// Assumption is the name that is passed in is the name of the window
// - the body portion is the name of the window plus the word Body
function ShowMessage(Message)
{
    var Left = (Utility_clientWidth() / 2) - (Message.width / 2) + Utility_scrollLeft();
    var Top = (Utility_clientHeight() / 2) - (Message.height / 2) + Utility_scrollTop();
    
    if (Left < 0)
        Left = 0;
        
    if (Top < 0)
        Top = 0;
        
    document.getElementById(Message.name).style.left = Left + 'px';
    document.getElementById(Message.name).style.top = Top + 'px';
	document.getElementById(Message.name).style.width = Message.width + 'px';
	document.getElementById(Message.name).style.height = Message.height + 'px';
    document.getElementById(Message.name + 'Body').style.height = (Message.height - 64) + 'px';
    
    document.getElementById('divDimBackground').className = 'standardwindowBackground';
    
    MenuActive = false;
    MenuShutDown();
}
function ShowMessage_Maximized(_this)
{
    var src = _this.src
    
    if (_this.alt == 'Window')
    {
        _this.alt = 'Maximize';
        src = src.replace('window','maximize');
        _this.src = src;
        ShowMessage(Message);
    }
    else
    {
        var Left = 20 + Utility_scrollLeft();
        var Top = 20 + Utility_scrollTop();
        _this.alt = 'Window';
        src = src.replace('maximize','window');
        _this.src = src;
        document.getElementById(Message.name).style.left = Left + 'px';
        document.getElementById(Message.name).style.top = Top + 'px';
	    document.getElementById(Message.name).style.width = (Utility_clientWidth() - 40) + 'px';
	    document.getElementById(Message.name).style.height = (Utility_clientHeight() - 40) + 'px';
	    document.getElementById(Message.name + 'Body').style.height = (Utility_clientHeight() - 104) + 'px';
    }
}

function CloseMessage()
{
    document.getElementById('divDimBackground').className = 'standardwindowHidden';
    return true;
}
////////////////////////////////
// Main Forum Menu Functions
////////////////////////////////

var MenuActive = false;
var cMenu;
var MenuArray = new Array();

function MenuMouseOver(_this, menu)
{
    var s = _this.id;
    MenuArray[s] = menu;

    if (MenuActive == true && cMenu != _this.id)
    {
        MenuShutDown();
        MenuTurnOn(_this, menu);
    }
}
function MenuDisplay(_this, menu)
{
    if (MenuActive == false)
    {
        MenuShutDown();
        MenuTurnOn(_this, menu);
        MenuActive = true;
    }
    else
    {
        MenuShutDown();
        MenuActive = false;
    }
}
function MenuShutDown()
{
    var i;
	
	document.getElementById('divMIframe').className = 'standardwindowHidden';
	document.getElementById('ifrMIframe').className = 'standardwindowHidden';
	
    for (var Menu in MenuArray)
    {
        document.getElementById(MenuArray[Menu]).className = 'standardwindowHidden';
    }
}

function MenuSizeAndLocation(_this)
{
    if (!IsObject(_this))
    {
        _this = document.getElementById(_this);
    }

    s = new Array();
    s['L'] = fetch_object_posleft(_this);
    s['T'] = fetch_object_postop(_this);	
    s['R'] = s['L'] + _this.offsetWidth;
    s['B'] = s['T'] + _this.offsetHeight;
    s['W'] = _this.offsetWidth;
    s['H'] = _this.offsetHeight;
    return s;
}
function MenuTurnOn(_this, menu)
{
    var s = MenuSizeAndLocation(_this);

    //Must be done first to get correct Measurements
    document.getElementById(menu).className='standardwindowVisible';
    
    var sm = MenuSizeAndLocation(menu);

    if (s['L'] + sm['W'] > Utility_clientWidth() + Utility_scrollLeft())
    {
        var left = Utility_clientWidth() + Utility_scrollLeft() - sm['W'];
        document.getElementById(menu).style.left = left + 'px';
        document.getElementById('divMIframe').style.left = left + 'px';
    }
    else
    {
        document.getElementById(menu).style.left = s['L'] + 'px';
        document.getElementById('divMIframe').style.left = s['L'] + 'px';
    }

    document.getElementById(menu).style.top = s['B'] + 'px';
    document.getElementById('divMIframe').style.top = s['B'] + 'px';
    document.getElementById('ifrMIframe').style.width = document.getElementById(menu).clientWidth + 3;
    document.getElementById('ifrMIframe').style.height = document.getElementById(menu).clientHeight + 3;
    document.getElementById('divMIframe').style.width = document.getElementById(menu).clientWidth + 3;
    document.getElementById('divMIframe').style.height = document.getElementById(menu).clientHeight + 3;
    document.getElementById('divMIframe').className='ifrPopUpPathVisible2';

    if (isIE())
    {
        document.getElementById('divMIframe').style.zoom = '1%';
        document.getElementById(menu).style.zoom = '1%';
        timeZoomIn(menu,'divMIframe');
    }
    cMenu = _this.id;
}

function cleanup()
{
    //Checks for activity in MenuFunctions.js file
    if(MenuActive == true)
    {
        MenuActive = false;
        MenuShutDown(); 
    }
}
