/**
* COMMON DHTML FUNCTIONS
* These are handy functions I use all the time.
*
* By Seth Banks (webmaster at subimage dot com)
* http://www.subimage.com/
*
* Up to date code can be found at http://www.subimage.com/dhtml/
*
* This code is free for you to use anywhere, just keep this comment block.
*/

/**
* X-browser event handler attachment and detachment
*
* @argument obj - the object to attach event to
* @argument evType - name of the event - DONT ADD "on", pass only "mouseover", etc
* @argument fn - function to call
*/
var boldTag = '|b|';
var italicTag = '|i|';
var underlineTag = '|u|';

function addEvent(obj, evType, fn) {
    if (obj.addEventListener) {
        obj.addEventListener(evType, fn, true);
        return true;
    } else if (obj.attachEvent) {
        var r = obj.attachEvent("on" + evType, fn);
        return r;
    } else {
        return false;
    }
}
function removeEvent(obj, evType, fn, useCapture) {
    if (obj.removeEventListener) {
        obj.removeEventListener(evType, fn, useCapture);
        return true;
    } else if (obj.detachEvent) {
        var r = obj.detachEvent("on" + evType, fn);
        return r;
    } else {
        alert("Handler could not be removed");
    }
}

/**
* Code below taken from - http://www.evolt.org/article/document_body_doctype_switching_and_more/17/30655/
*
* Modified 4/22/04 to work with Opera/Moz (by webmaster at subimage dot com)
*
* Gets the full width/height because it's different for most browsers.
*/
function getViewportHeight() {
    if (window.innerHeight != window.undefined) return window.innerHeight;
    if (document.compatMode == 'CSS1Compat') return document.documentElement.clientHeight;
    if (document.body) return document.body.clientHeight;
    return window.undefined;
}
function getViewportWidth() {
    if (window.innerWidth != window.undefined) return window.innerWidth;
    if (document.compatMode == 'CSS1Compat') return document.documentElement.clientWidth;
    if (document.body) return document.body.clientWidth;
    return window.undefined;
}
function popup(url, name, width, height) {
    var win = window.open(url, name, 'menubar = no, location = no,height = ' + height + ',width = ' + width, true);
    
    win.focus();
}
function charcount(src1, destId, maxChars) {
    var dest = document.getElementById(destId);

    if (dest) {
        dest.innerHTML = maxChars - src1.value.length;
    }
}
function addSmily(key) {
    var textBox = document.getElementById('txtSendMessage');
    textBox.value = textBox.value + key;
}
function bold() {
    addSmily(boldTag);
    
    if(boldTag=='|b|')
    {
        boldTag = '|/b|';
        document.getElementById('boldButton').src='../Images/b_active.gif';
    }
    else
    {
        boldTag = '|b|';
        document.getElementById('boldButton').src='../Images/b.gif';
    }
}

function italic() {
    addSmily(italicTag);

    if(italicTag == '|i|')
    {
        italicTag = '|/i|';
        document.getElementById('italicButton').src='../Images/i_active.gif';
    }
    else
    {
        italicTag = '|i|';
        document.getElementById('italicButton').src='../Images/i.gif';
    }
}

function underline() {
    addSmily(underlineTag);

    if(underlineTag == '|u|')
    {
        underlineTag =  '|/u|';
        document.getElementById('underlineButton').src='../Images/u_active.gif';
    }
    else
    {
        underlineTag =  '|u|';
        document.getElementById('underlineButton').src='../Images/u.gif';
    }
}

function toggleDisplay(id) {

    var obj = document.getElementById(id);

    if (obj) {
        if (obj.style.display == 'none') {
            obj.style.display = '';
        }
        else {
            obj.style.display = 'none';
        }
    }

}

function openChat(toUsername) {
    var win = window.open("/AjaxChat/ChatWindow.aspx?toUsername=" + escape(toUsername),  "chat_" + toUsername.replace(' ', '___'), 'menubar = no, location = no,height = ' + 710 + ',width = ' + 790, true);
    
    win.focus();
}
