﻿
    var _tabBase, _siteBaseUrl;
    var _stWindow = false;
    
    function setTabBase(tabBase) {
        _tabBase = tabBase;
    }
    
    function setSiteBase (siteBase) {
        _siteBaseUrl = siteBase;
    }
    
    function swapTabImage(e, imageName)
    {
        e.src = _tabBase + imageName;
    }
    
    function setPageAnchor (anchorId) {
        document.forms[0].action += '#' + anchorId;
    }
    
    function showMembershipMessage(value) {
        document.getElementById('ppMembershipDescription').innerHTML = MembershipMessage[value];
    }

    function addTabImageSwitch (elementId, TabName) {
    
        var element = document.getElementById(elementId);
        
        if (element) {
            element.onmouseover = function() { swapTabImage(this, TabName + '_Hover.gif'); }
            element.onmouseout  = function() { swapTabImage(this, TabName + '_Unselected.gif'); }
        }
        
    }
    
    var popupWindow;

    function openMailReport(postId) {
        if (popupWindow) { popupWindow.close(); }
        popupWindow = window.open (_siteBaseUrl + 'members/report/report.aspx?mail_uid=' + postId, null, 'width=690,height=310,toolbars=off');
    }

    function openForumReport(postId) {
        if (popupWindow) { popupWindow.close(); }
        popupWindow = window.open (_siteBaseUrl + 'members/report/report.aspx?post_uid=' + postId, null, 'width=690,height=310,toolbars=off');
        return false;
    }

	function openChatroom(postId) {
        if (popupWindow) { popupWindow.close(); }
        popupWindow = window.open (_siteBaseUrl + 'members/chat/chat.aspx?room=' + postId, null, 'width=820,height=630,toolbars=off');
        return false;
	}
	
	function closeChatroom() {
		window.close();
	}
	
    function openChatroomReport(postId) {
        if (popupWindow) { popupWindow.close(); }
        popupWindow = window.open (_siteBaseUrl + 'members/report/report.aspx?room_uid=' + postId, null, 'width=690,height=310,toolbars=off');
        return false;
    }

    function openUserReport(postId) {
        if (popupWindow) { popupWindow.close(); }
        popupWindow = window.open (_siteBaseUrl + 'members/report/report.aspx?user_uid=' + postId, null, 'width=690,height=310,toolbars=off');
        return false;
    }

    function loadSmileyTalk (talkUrl, talkId, usertype) {
        if (_stWindow) { _stWindow.close(); }
        _stWindow = window.open (talkUrl + '?talkId=' + talkId + '&userType=' + usertype, null, 'width=720,height=550');
        return false;
    }
    
    function loadOneToOneChat(talkUrl, otoId, usertype) {
        if (popupWindow) { popupWindow.close(); }
        //popupWindow = window.open (_siteBaseUrl + 'members/chat/oneToOneChat.aspx?otoid=' + otoId, null, 'width=530,height=630,toolbars=off');
        popupWindow = window.open (talkUrl + '?otoid=' + otoId + '&userType=' + usertype, null, 'width=530,height=630,toolbars=off');
        return false;
    }
    
    function highlightRow(row) {
        row.className = 'TableRowNormal TableRowSelected';
    }
    
    function highlightCells(cell1, cell2) {
        document.getElementById(cell1).className = 'TableCellNormal TableCellSelected';
        document.getElementById(cell2).className = 'TableCellNormal TableCellSelected';
    }
    
    function unhighlightRow(row) {
        row.className = 'TableRowNormal';
    }
    
    function unhighlightCells(cell1, cell2) {
        document.getElementById(cell1).className = 'TableCellNormal';
        document.getElementById(cell2).className = 'TableCellNormal';
    }
    
    function selectMailRow(mailId) {
        window.location.href = 'read.aspx?message=' + mailId;
    }
    
    function onloadPage() {
    
        var lnkMsg = document.getElementById('ctl00_ucMemberLeftNav_lnkMessages')
        var lnkMod = false; 
        var lnkChat = document.getElementById('ctl00_ucMemberLeftNav_lnkChat')
        
        if (document.getElementById('ctl00_ucMemberLeftNav_LoginView1_lnkSuperUsers')) { 
            lnkMod = document.getElementById('ctl00_ucMemberLeftNav_LoginView1_lnkSuperUsers')
        } else {
            lnkMod = document.getElementById('ctl00_ucMemberLeftNav_LoginView1_lnkModerators')
        }
    
		if (document.getElementById('hiddenMessageCount')) {
			if (document.getElementById('hiddenMessageCount').value != '0') {
				lnkMsg.className = 'masterUserNav-messagesFlashing';
			} else {
				lnkMsg.className = 'masterUserNav-messages';
			}
		}
		
		if (lnkMod && document.getElementById('hiddenAdminMessageCount')) {
			if (document.getElementById('hiddenAdminMessageCount').value != '0') {
				lnkMod.className = 'masterUserNav-myhomepageFlashing';
			} else {
				lnkMod.className = 'masterUserNav-myhomepage';
			}
		}
		
		if (document.getElementById('hiddenChatCount')) {
			if (document.getElementById('hiddenChatCount').value != '0') {
				lnkChat.className = 'masterUserNav-chatroomFlashing';
			} else {
				lnkChat.className = 'masterUserNav-chatroom';
			}
		}
    }
    
    function showPhoto(PhotoID, Height, Width, Caption) {
    
        
        var maxImageHeight = screen.Height - 250;
        var maxImageWidth = screen.Width - 150;
        var ratioHeights = Height / maxImageHeight;
        var ratioWidths = Width / maxImageWidth;
        
        if (maxImageHeight < Height) {
            Height = Height / ratioHeights;
            Width = Width / ratioHeights;
        }
        if (maxImageWidth < Width) {
            Height = Height / ratioWidths;
            Width = Width / ratioWidths;
        }
        
        var windowHeight = Height + 120;
        var windowWidth = Width + 50; 
        var popupUrl = "popups/showPicture.aspx?id=" + PhotoID + "&height=" + Height + "&Width=" + Width + "&Caption=" + Caption;
        window.open (popupUrl, "photo", "height=" + windowHeight + ",width=" + windowWidth + ",toolbars=no");
    
    }
    
	if(window.addEventListener) {
		window.addEventListener('onload', onloadPage, false);
	} else if (window.attachEvent) {
		window.attachEvent('onload', onloadPage);
	}
 