﻿var messageCounter = 0;

var global1;

var webcamMe;
var webcam1;
var webcam2;
var webcam3;
var webcam4;
var webcam5;
var webcam6;
var webcam7;
var webcam8;
var webcam9;
var webcam10;
var webcamMehandle;
var webcam1handle;
var webcam2handle;
var webcam3handle;
var webcam4handle;
var webcam5handle;
var webcam6handle;
var webcam7handle;
var webcam8handle;
var webcam9handle;
var webcam10handle;

function fInitialize(strRoomname) {
    if (strRoomname != 'Undefined') {
        Init(strRoomname);
        GetUserlist();
        try {
            var w = $('ChatInputFieldArea').offsetWidth - 5;
            $('ChatInputField').style.width = w + 'px';

            fScrollChatDown();
            setInterval("fGetNewMessages('" + strRoomname + "')", 5000);

            webcamMe = $("WebcamMe");
            webcamMehandle = $("WebcamMeHandle");
            webcam1 = $("Webcam1");
            webcam1handle = $("Webcam1Handle");
            webcam2 = $("Webcam2");
            webcam2handle = $("Webcam2Handle");
            webcam3 = $("Webcam3");
            webcam3handle = $("Webcam3Handle");
            webcam4 = $("Webcam4");
            webcam4handle = $("Webcam4Handle");
            webcam5 = $("Webcam5");
            webcam5handle = $("Webcam5Handle");
            webcam6 = $("Webcam6");
            webcam6handle = $("Webcam6Handle");
            webcam7 = $("Webcam7");
            webcam7handle = $("Webcam7Handle");
            webcam8 = $("Webcam8");
            webcam8handle = $("Webcam8Handle");
            webcam9 = $("Webcam9");
            webcam9handle = $("Webcam9Handle");
            webcam10 = $("Webcam10");
            webcam10handle = $("Webcam10Handle");
            Drag.init(webcamMehandle, webcamMe);
            Drag.init(webcam1handle, webcam1);
            Drag.init(webcam2handle, webcam2);
            Drag.init(webcam3handle, webcam3);
            Drag.init(webcam4handle, webcam4);
            Drag.init(webcam5handle, webcam5);
            Drag.init(webcam6handle, webcam6);
            Drag.init(webcam7handle, webcam7);
            Drag.init(webcam8handle, webcam8);
            Drag.init(webcam9handle, webcam9);
            Drag.init(webcam10handle, webcam10);

        } catch (e) {
            // user not signed into/viewing chat
        }
    }
}

function invite() {
    $('InviteDialog').style.visibility = 'visible';
    $('InviteDialog').style.display = 'block';
}
function fInviteDialogClose() {
    $('InviteDialog').style.visibility = 'hidden';
    $('InviteDialog').style.display = 'none';
}

function fSendMessage(strRoomname) {
    var bug = new Image();
    var date = new Date();
    var msg;
    msg = $('ChatInputField').value

    $('SendingNewMessageContent').innerHTML = msg;
    $('SendingNewMessage').style.visibility = 'visible';
    $('SendingNewMessage').style.display = 'block';
    fScrollChatDown();

    for (i = 1; i < 10; i++) {
        msg = msg.replace('¿', '&iquest;').replace('£', '&pound;').replace('¥', '&yen;').replace('¤', '&curren;').replace('¢', '&cent;').replace('ª', '&ordf;').replace('º', '&ordm;').replace('¦', '&brvbar;').replace('©', '&copy;').replace('®', '&reg;').replace('µ', '&micro;').replace('·', '&middot;').replace('°', '&deg;').replace('±', '&plusmn;').replace('×', '&times;').replace('÷', '&divide;').replace('¼', '&frac14;').replace('½', '&frac12;').replace('¾', '&frac34;').replace('¹', '&sup1;').replace('²', '&sup2;').replace('³', '&sup3;').replace('´', '&acute;').replace('¨', '&uml;').replace('¯', '&macr;').replace('¸', '&cedil').replace('À', '&Agrave;').replace('Á', '&Aacute;').replace('Â', '&Acirc;').replace('Ã', '&Atilde;').replace('Ä', '&Auml;').replace('Å', '&Aring;').replace('Æ', '&AElig;').replace('Ç', '&Ccedil;').replace('È', '&Egrave;').replace('É', '&Eacute;').replace('Ê', '&Ecirc;').replace('Ë', '&Euml;').replace('Ì', '&Igrave;').replace('Í', '&Iacute;').replace('Î', '&Icirc;').replace('Ï', '&Iuml;').replace('Ð', '&ETH;').replace('Ñ', '&Ntilde;').replace('Ò', '&Ograve;').replace('Ó', '&Oacute;').replace('Ô', '&Ocirc;').replace('Õ', '&Otilde;').replace('Ö', '&Ouml;').replace('Ø', '&Oslash;').replace('Ù', '&Ugrave;').replace('Ú', '&Uacute;').replace('Û', '&Ucirc;').replace('Ü', '&Uuml;').replace('Ý', '&Yacute;').replace('Þ', '&THORN;').replace('ß', '&szlig;').replace('à', '&agrave;').replace('á', '&aacute;').replace('â', '&acirc;').replace('ã', '&atilde;').replace('ä', '&auml;').replace('å', '&aring;').replace('æ', '&aelig;').replace('ç', '&ccedil;').replace('è', '&egrave;').replace('é', '&eacute;').replace('ê', '&ecirc;').replace('ë', '&euml;').replace('ì', '&igrave;').replace('í', '&iacute;').replace('î', '&icirc;').replace('ï', '&iuml;').replace('ð', '&eth;').replace('ñ', '&ntilde;').replace('ò', '&ograve;').replace('ó', '&oacute;').replace('ô', '&ocirc;').replace('õ', '&otilde;').replace('ö', '&ouml;').replace('ø', '&oslash;').replace('ù', '&ugrave;').replace('ú', '&uacute;').replace('û', '&ucirc;').replace('ü', '&uuml;').replace('ý', '&yacute;').replace('þ', '&thorn;').replace('ÿ', '&yuml;').replace('§', '&sect;').replace('¶', '&para;').replace('«', '&laquo;').replace('»', '&raquo;').replace('¡', '&iexcl;');
    }

    bug.src = 'http://yaychat.com/1/a/Save-Message.aspx?Roomname=' + strRoomname + '&Message=' + escape(msg.replace('+', '---YAYplus---')) + '&t=' + date.getTime();
    $('ChatInputField').value = '';
    $('ChatInputField').focus();
    setTimeout("fGetNewMessages('" + strRoomname + "')", 500);
}
function fInsertNickname(strNickname) {
    $('ChatInputField').focus();
    if ($('ChatInputField').value == '') {
        $('ChatInputField').value = $('ChatInputField').value + strNickname + ' ';
        //$('ChatInputField').value = $('ChatInputField').value.replace('  ', ' ');
    } else {
        $('ChatInputField').value = $('ChatInputField').value + ' ' + strNickname + ' ';
        $('ChatInputField').value = $('ChatInputField').value.replace('  ', ' ');
    }
}

var req; var reqBusy; reqBusy = "N";
var req2; var req2target; var req2Busy; req2Busy = "N";
function fGetDiv(strAJAXaspx, strAJAXparameters, strRoomname, strTarget) {
//    $('chat-input-roll').src = '/i/roll-div.gif';
    var date = new Date();
    var url = "http://yaychat.com/1/a/" + strAJAXaspx + ".aspx?Roomname=" + strRoomname + "&" + strAJAXparameters + "t=" + date.getTime();

    if (req2Busy == "N") {
        req2 = false;
        req2target = strTarget;
        req2Busy = "Y";
        if (window.XMLHttpRequest && !(window.ActiveXObject)) {
            try { req2 = new XMLHttpRequest(); } catch (e) { req2 = false; }
        } else if (window.ActiveXObject) {
            try { req2 = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req2 = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { req2 = false; } }
        }
        if (req2) { req2.onreadystatechange = processReqDiv; req2.open("GET", url, true); req2.send(""); }
    }
}
function processReqDiv() {
    if (req2.readyState == 4) {
        if (req2.status == 200) {
            req2Busy = "N";
            $(req2target).innerHTML = req2.responseText;
//            $('chat-input-roll').src = '/b.png';
        } else {
            req2Busy = "N"; // error > continue
            var status = req2.statusText
        }
    }
}

function fGetNewMessages(strRoomname) {
    try {$('chat-input-roll').src = '/i/roll-msg.gif'; } catch (e) { }
    var date = new Date();
    var url = "http://yaychat.com/1/a/Get-New-Messages.aspx?Roomname=" + strRoomname + "&t=" + date.getTime();

    if (reqBusy == "N") {
        req = false;
        reqBusy = "Y";
        if (window.XMLHttpRequest && !(window.ActiveXObject)) {
            try { req = new XMLHttpRequest(); } catch (e) { req = false; }
        } else if (window.ActiveXObject) {
            try { req = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try { req = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { req = false; } }
        }
        if (req) { req.onreadystatechange = processReqChangeNewMessages; req.open("GET", url, true); req.send(""); }
    }
}
var strFlashTitle = 'N';
var strOriginalTitle = document.title.replace("'", "\'");
var intFlashTitleState = 1;
function FlashTitle() {
    if (intFlashTitleState == 1) {
        document.title = 'YAYchat';  //'+ ' + strOriginalTitle;
        intFlashTitleState = 2;
    } else {
        document.title = strOriginalTitle;  //'- '+strOriginalTitle;
        intFlashTitleState = 1;
    }
    if (strFlashTitle == 'Y') {
        setTimeout('FlashTitle()', 500);
    } else {
        document.title = strOriginalTitle;
    }
}
function processReqChangeNewMessages() {
    var bug = new Image();
    var date = new Date();
    if (req.readyState == 4) {
        if (req.status == 200) {
            reqBusy = "N";
            if (req.responseText != '') {
                for (i = 50; i > 1; i--) {
                    try {
                        var strUseLine = $('Message' + (i - 1)).innerHTML;
                        //strUseLine = strUseLine.replace('#FFC', '#FFF');
                        //strUseLine = strUseLine.replace('#ffc', '#fff');
                        strUseLine = strUseLine.replace('#CFC', '#FFF');
                        strUseLine = strUseLine.replace('#cfc', '#fff');
                        //strUseLine = strUseLine.replace('rgb(255, 255, 204)', 'rgb(255, 255, 255)');
                        if ($('Message' + (i - 1)).style.visibility == "visible") {
                            $('Message' + i).style.visibility = "visible";
                            $('Message' + i).style.display = "block";
                        }
                        $('Message' + i).innerHTML = strUseLine;
                    } catch (err) {
                        //needs more details like url and i
                        //bug.src = 'http://yaychat.com/1/a/Send-Error.aspx?Error=/js.js processReqChangeNewMessages() 1: ' + escape(err) + '&t=' + date.getTime();
                    }
                }
                fHideHint();
                //if (req.responseText.toLowerCase().indexOf('google') > -1) { fShowHint('You can search Google here.', document.body.clientWidth-320, 37); }
                //if (req.responseText.toLowerCase().indexOf('my settings') > -1) { fShowHint('You can edit your settings here.', 30, 160); }
                //if (req.responseText.toLowerCase().indexOf('edit my profile') > -1) { fShowHint('You can edit your profile here.', 30, 140); }

                $('SendingNewMessageContent').innerHTML = '';
                $('SendingNewMessage').style.visibility = 'hidden';
                $('SendingNewMessage').style.display = 'none';

                $('Message1').innerHTML = req.responseText;

                messageCounter += 1;
                if (1==1) {
                if (document.title.indexOf(' ... ') > -1) {
                    var strTrimmedTitle = document.title.replace("'", "\'");
                    strTrimmedTitle = strTrimmedTitle.substring(strTrimmedTitle.indexOf(' ... ') + 5);
                    document.title = messageCounter + ' ... ' + strTrimmedTitle;
                } else {
                document.title = messageCounter + ' ... ' + document.title.replace("'", "\'");
                };
                }
                
                //new Effect.Highlight('Message1', { startcolor: '#ffcccc',endcolor: '#ccffcc'});
                new Effect.Highlight('Message1');
                fScrollChatDown();

                var soundText = req.responseText.toLowerCase();

                if (soundText.indexOf('*-explosion-*') > -1) { location.href = 'http://yaychat.com/YouExploded'; };

                if (soundText.indexOf('highlight-text') > -1) { PlaySound('beep') }
                else if (soundText.indexOf('*beep*') > -1) { PlaySound('beep') }
                else if (soundText.indexOf('*knock knock*') > -1) { PlaySound('knocks') }
                else if (soundText.indexOf('*fart*') > -1) { PlaySound('fart') }
                else if (soundText.indexOf('*burp*') > -1) { PlaySound('burp') }
                else if (soundText.indexOf('*sneeze*') > -1) { PlaySound('sneeze') }
                else if (soundText.indexOf('*gasps*') > -1) { PlaySound('gasps') }
                else if (soundText.indexOf('*gasp*') > -1) { PlaySound('gasp') }
                else if (soundText.indexOf('*hahaha*') > -1) { PlaySound('hahaha') }
                else if (soundText.indexOf('*hiccup*') > -1) { PlaySound('hiccup') }
                else if (soundText.indexOf('*smooch*') > -1) { PlaySound('smooch') }
                else if (soundText.indexOf('*snore*') > -1) { PlaySound('snore') }
                else if (soundText.indexOf('*tarzan*') > -1) { PlaySound('tarzan') }
                else if (soundText.indexOf('*short yawn*') > -1) { PlaySound('short yawn') }
                else if (soundText.indexOf('*yawn*') > -1) { PlaySound('yawn') }
                else if (soundText.indexOf('*beach*') > -1) { PlaySound('beach') }
                else if (soundText.indexOf('*booo*') > -1) { PlaySound('booo') }
                else if (soundText.indexOf('*coin*') > -1) { PlaySound('coin') }
                else if (soundText.indexOf('*ding dong*') > -1) { PlaySound('ding dong') }
                else if (soundText.indexOf('*fax*') > -1) { PlaySound('fax') }
                else if (soundText.indexOf('*ghost*') > -1) { PlaySound('ghost') }
                else if (soundText.indexOf('*heartbeat*') > -1) { PlaySound('heartbeat') }
                else if (soundText.indexOf('*hihihi*') > -1) { PlaySound('hihihi') }
                else if (soundText.indexOf('*howl*') > -1) { PlaySound('howl') }
                else if (soundText.indexOf('*jungle*') > -1) { PlaySound('jungle') }
                else if (soundText.indexOf('*marching*') > -1) { PlaySound('marching') }
                else if (soundText.indexOf('*miracle*') > -1) { PlaySound('miracle') }
                else if (soundText.indexOf('*missile*') > -1) { PlaySound('missile') }
                else if (soundText.indexOf('*monster*') > -1) { PlaySound('monster') }
                else if (soundText.indexOf('*police*') > -1) { PlaySound('police') }
                else if (soundText.indexOf('*punch*') > -1) { PlaySound('punch') }
                else if (soundText.indexOf('*raining*') > -1) { PlaySound('raining') }
                else if (soundText.indexOf('*shoot*') > -1) { PlaySound('shoot') }
                else if (soundText.indexOf('*slap*') > -1) { PlaySound('slap') }
                else if (soundText.indexOf('*spooky*') > -1) { PlaySound('spooky') }
                else if (soundText.indexOf('*storm*') > -1) { PlaySound('storm') }
                else if (soundText.indexOf('*telephone*') > -1) { PlaySound('telephone') }
                else if (soundText.indexOf('*thunder*') > -1) { PlaySound('thunder') }
                else if (soundText.indexOf('*aargh*') > -1) { PlaySound('aargh') }
                else if (soundText.indexOf('*attack*') > -1) { PlaySound('attack') }
                else if (soundText.indexOf('*blowkiss*') > -1) { PlaySound('blowkiss') }
                else if (soundText.indexOf('*children*') > -1) { PlaySound('children') }
                else if (soundText.indexOf('*clear throat*') > -1) { PlaySound('clear throat') }
                else if (soundText.indexOf('*cough cough*') > -1) { PlaySound('cough cough') }
                else if (soundText.indexOf('*har har*') > -1) { PlaySound('har har') }
                else if (soundText.indexOf('*huhuhu*') > -1) { PlaySound('huhuhu') }
                else if (soundText.indexOf('*laugh*') > -1) { PlaySound('laugh') }
                else if (soundText.indexOf('*muahaha*') > -1) { PlaySound('muahaha') }
                else if (soundText.indexOf('*danger*') > -1) { PlaySound('danger') }
                else if (soundText.indexOf('*omg*') > -1) { PlaySound('omg') }
                else if (soundText.indexOf('*pmsl*') > -1) { PlaySound('pmsl') }
                else if (soundText.indexOf('*scooby*') > -1) { PlaySound('scooby') }
                else if (soundText.indexOf('*sigh*') > -1) { PlaySound('sigh') }
                else if (soundText.indexOf('*sleeping*') > -1) { PlaySound('sleeping') }
                else if (soundText.indexOf('*slurp*') > -1) { PlaySound('slurp') }
                else if (soundText.indexOf('*teehee*') > -1) { PlaySound('teehee') }
                else if (soundText.indexOf('*thats funny*') > -1) { PlaySound('thats funny') }
                else if (soundText.indexOf('*tired*') > -1) { PlaySound('tired') }
                else if (soundText.indexOf('*vader*') > -1) { PlaySound('vader') }
                else if (soundText.indexOf('*whip*') > -1) { PlaySound('whip') }
                else if (soundText.indexOf('*witch*') > -1) { PlaySound('witch') }
                else if (soundText.indexOf('*yikes*') > -1) { PlaySound('yikes') }

                else if (soundText.indexOf('*baby*') > -1) { PlaySound('baby') }
                else if (soundText.indexOf('*busy*') > -1) { PlaySound('busy') }
                else if (soundText.indexOf('*come on*') > -1) { PlaySound('come on') }
                else if (soundText.indexOf('*dialing*') > -1) { PlaySound('dialing') }
                else if (soundText.indexOf('*digging*') > -1) { PlaySound('digging') }
                else if (soundText.indexOf('*dogs*') > -1) { PlaySound('dogs') }
                else if (soundText.indexOf('*drill*') > -1) { PlaySound('drill') }
                else if (soundText.indexOf('*dripping*') > -1) { PlaySound('dripping') }
                else if (soundText.indexOf('*freaking out*') > -1) { PlaySound('freaking out') }
                else if (soundText.indexOf('*lobby*') > -1) { PlaySound('lobby') }
                else if (soundText.indexOf('*matches*') > -1) { PlaySound('matches') }
                else if (soundText.indexOf('*off the hook*') > -1) { PlaySound('off the hook') }
                else if (soundText.indexOf('*scrap that*') > -1) { PlaySound('scrap that') }
                else if (soundText.indexOf('*shred*') > -1) { PlaySound('shred') }
                else if (soundText.indexOf('*static*') > -1) { PlaySound('static') }
                else if (soundText.indexOf('*very funny*') > -1) { PlaySound('very funny') }
                else if (soundText.indexOf('*weeping*') > -1) { PlaySound('weeping') }
                else if (soundText.indexOf('*woohoo*') > -1) { PlaySound('woohoo') }
                else if (soundText.indexOf('*write*') > -1) { PlaySound('write') }
                else if (soundText.indexOf('*zippit*') > -1) { PlaySound('zippit') }

                else if (soundText.indexOf('*beer*') > -1) { PlaySound('beer') }
                else if (soundText.indexOf('*car horn*') > -1) { PlaySound('car horn') }
                else if (soundText.indexOf('*church bells*') > -1) { PlaySound('church bells') }
                else if (soundText.indexOf('*cougar*') > -1) { PlaySound('cougar') }
                else if (soundText.indexOf('*gibbon*') > -1) { PlaySound('gibbon') }
                else if (soundText.indexOf('*horse*') > -1) { PlaySound('horse') }
                else if (soundText.indexOf('*roflol*') > -1) { PlaySound('roflol') }
                else if (soundText.indexOf('*seal*') > -1) { PlaySound('seal') }
                else if (soundText.indexOf('*train*') > -1) { PlaySound('train') }

                else if (soundText.indexOf('*pig*') > -1) { PlaySound('pig') }
                else if (soundText.indexOf('*pirate*') > -1) { PlaySound('pirate') }

                else { PlaySound('c1') }
                fScrollChatDown();

                if (soundText.indexOf('highlight-text') > -1) {
                    strFlashTitle = 'Y';
                    setTimeout('FlashTitle()', 500);
                }
            }
            try {$('chat-input-roll').src = '/b.png'; } catch (e) { }
        } else {
            reqBusy = "N"; // error > continue
            var status = req.statusText
            bug.src = 'http://yaychat.com/1/a/Send-Error.aspx?Error=/js.js processReqChangeNewMessages() 2 req.StatusText: ' + escape(status) + '&t=' + date.getTime();
        } 
    }
}

function fHideHint() {
    fHideDiv('Hint');
    fHideDiv('Hint_Arrow');
}
function fShowHint(strHint, x, y) {
    fShowDiv('Hint');
    fShowDiv('Hint_Arrow');
    $('Hint_Text').innerHTML = strHint;
    $('Hint').style.left = x + 'px';
    $('Hint').style.top = y + 'px';
    $('Hint_Arrow').style.left = (x+15) + 'px';
    $('Hint_Arrow').style.top = (y-10) + 'px';
}

function fCheckChatInput(e) {
    var characterCode //literal character code will be stored in this variable
    strFlashTitle = 'N';

    fScrollChatDown();
    if (e && e.which) { //if which property of event object is supported (NN4)
        e = e;
        characterCode = e.which; //character code is contained in NN4's which property
    } else {
        e = event;
        characterCode = e.keyCode; //character code is contained in IE's keyCode property
    }

    if (characterCode == 13) {
        $('FORM_Message').submit();
        return false;
    } else {
        return true;
    }
}

function fScrollChatDown() {
    try {
        //$('ChatOutput').scrollTop = 10000;
        var objDiv = $("ChatOutput");
        objDiv.scrollTop = objDiv.scrollHeight;
    } catch (err) {
        // not a chat room
    }
}

function fShowChatInputOptions() {
    fShowDiv('Chat_Input_Options_Webcam');
    fGetDiv("Get-Input-Options-Webcam", "", "", "Chat_Input_Options_Webcam_Content")
}
function fHideChatInputOptions() {
    fHideDiv('Chat_Input_Options_Webcam');
}

function fShowDiv(strDivId) {
    try {
        $(strDivId).style.visibility = "visible";
    } catch (err) {
        // div doesnt exist
    }
}
function fHideDiv(strDivId) {
    try {
        $(strDivId).style.visibility = "hidden";
    } catch (err) {
        // div doesnt exist
    }
}
function fShowDisplayDiv(strDivId) {
    try {
        $(strDivId).style.visibility = "visible";
        $(strDivId).style.display = "block";
    } catch (err) {
        // div doesnt exist
    }
}
function fHideDisplayDiv(strDivId) {
    try {
        $(strDivId).style.visibility = "hidden";
        $(strDivId).style.display = "none";
    } catch (err) {
        // div doesnt exist
    }
}

function fInputOptionsWebcamSelect(objSelect) {
    var bug = new Image();
    var date = new Date();
    bug.src = 'http://yaychat.com/1/a/Set-Input-Options-Webcam-Select.aspx?Selection=' + objSelect.value + '&t=' + date.getTime();
}
function fInputOptionsTextColorSelect(strColor) {
    var bug = new Image();
    var date = new Date();
    bug.src = 'http://yaychat.com/1/a/Set-Input-Options-Text-Color.aspx?Color=' + strColor + '&t=' + date.getTime();
    fHideDiv('Chat_Input_Options_Text');
    $('ChatInputField').focus();
}
function fInputOptionsTextStyleSelect(strStyle) {
    var bug = new Image();
    var date = new Date();
    bug.src = 'http://yaychat.com/1/a/Set-Input-Options-Text-Style.aspx?Style=' + strStyle + '&t=' + date.getTime();
    fHideDiv('Chat_Input_Options_Text');
    $('ChatInputField').focus();
}
function fInputOptionsTextFontSelect(strFont) {
    var bug = new Image();
    var date = new Date();
    bug.src = 'http://yaychat.com/1/a/Set-Input-Options-Text-Font.aspx?Font=' + strFont + '&t=' + date.getTime();
    fHideDiv('Chat_Input_Options_Font');
    $('ChatInputField').focus();
}
function fDockWebcam(strNickname) {
    var done;
    done = 'no';
    for (i = 1; i <= 10; i++) {
        if ($('Webcam' + i + 'Content').innerHTML == '' && done == 'no') {
            fShowDiv("Webcam" + i);
            $("Webcam" + i).style.left = 5 + (i * 20) + 'px';
            $("Webcam" + i).style.top = 5 + (i * 25) + 'px';
            fGetDiv("Get-Webcam", "Nickname=" + strNickname + "&Dock=" + i + "&", "", "Webcam" + i + "Content");
            done = 'yes';
        }
    }
}
function fDockMeWebcam() {
        if ($('WebcamMeContent').innerHTML == '') {
            fShowDiv("WebcamMe");
            $("WebcamMe").style.left = '150px';
            $("WebcamMe").style.top = '40px';
            fGetDiv("Get-My-Webcam", "", "", "WebcamMeContent");
        }
}
function fCloseDock(intDockNumber) {
    $('Webcam' + intDockNumber + 'Content').innerHTML = ""
    fHideDiv("Webcam" + intDockNumber);
}
function fCloseMeDock() {
    var bug = new Image();
    bug.src = "/1/a/Set-My-Webcam-Off.aspx";
    $('WebcamMeContent').innerHTML = ""
    fHideDiv("WebcamMe");
}


function fSetNavigator(strGroup, strOnOff) {
    var bug = new Image();
    var date = new Date();
    bug.src = "/1/a/Set-Navigator.aspx?Group=" + strGroup + "&On=" + strOnOff + "&t=" + date.getTime();
}

function fDeleteWallPost(strCommentNumber) {
    var bug = new Image();var date = new Date();
    bug.src = "/1/a/Delete-Comment.aspx?Number=" + strCommentNumber + "&t=" + date.getTime();
    fHideDisplayDiv('WallPost' + strCommentNumber);
}
function fDeleteWallReply(strReplyNumber) {
    var bug = new Image();var date = new Date();
    bug.src = "/1/a/Delete-Reply.aspx?Number=" + strReplyNumber + "&t=" + date.getTime();
    fHideDisplayDiv('WallReply' + strReplyNumber);
}

function fRepairWallPost(strCommentNumber) {
    var bug = new Image(); var date = new Date();
    bug.src = "/1/a/Repair-Comment.aspx?Number=" + strCommentNumber + "&t=" + date.getTime();
    setTimeout('location.href = location.href;', 2000);
}
function fRepairWallReply(strReplyNumber) {
    var bug = new Image(); var date = new Date();
    bug.src = "/1/a/Repair-Reply.aspx?Number=" + strReplyNumber + "&t=" + date.getTime();
    setTimeout('location.href = location.href;', 2000);
}

function fPrivateWallPost(strCommentNumber) {
    var bug = new Image(); var date = new Date();
    bug.src = "/1/a/Private-Comment.aspx?Number=" + strCommentNumber + "&t=" + date.getTime();
    setTimeout('location.href = location.href;', 2000);
}

// ### SETTINGS ###
function fSetOptionProfanity(objCheckbox) {
    var bug = new Image();
    var date = new Date();
    if (objCheckbox.checked == true) {
        bug.src = "/1/a/Set-Profanity.aspx?On=1&t=" + date.getTime();
    } else {
    bug.src = "/1/a/Set-Profanity.aspx?On=0&t=" + date.getTime();
    }
}
function fSetOptionChatFontStyles(objCheckbox) {
    var bug = new Image();
    var date = new Date();
    if (objCheckbox.checked == true) {
        bug.src = "/1/a/Set-Chat-Font-Styles.aspx?On=1&t=" + date.getTime();
    } else {
    bug.src = "/1/a/Set-Chat-Font-Styles.aspx?On=0&t=" + date.getTime();
    }
}
function fSetOptionEmoticonSet(objCombobox) {
    var bug = new Image();
    var date = new Date();
    bug.src = "/1/a/Set-Emoticon-Set.aspx?Set=" + objCombobox.value + "&t=" + date.getTime();
}
function fSetOptionWebcamSetup(objCombobox) {
    var bug = new Image();
    var date = new Date();
    bug.src = "/1/a/Set-Webcam.aspx?Setup=" + objCombobox.value + "&t=" + date.getTime();
}


function fSendVerification() {
    var bug = new Image();
    var date = new Date();
    bug.src = "/1/a/Send-Verification.aspx?t=" + date.getTime();
    $('Verify_eMail').innerHTML = "Your verification e-mail has been sent. Please, check your inbox (or junk mail) for this e-mail and follow the instructions provided. ;)";
}

function fShowUserlistDetails(strNickname, objImg){
    fShowDisplayDiv('User_Menu');
    //$('User_Menu').style.left = objImg.x-305+'px';
    //$('User_Menu').style.top = objImg.y+0+'px';
    fGetDiv("Get-User-Menu", "Nickname="+strNickname+"&", "", "User_Menu");
}
function fHideUserlistDetails() {
    fHideDisplayDiv('User_Menu');
}

function fToggleInfoPanel() {
    if ($("Info_Panel").style.visibility == "visible") {
        $("Info_Panel_Toggle").src = "http://16.yaychat.com/expand-bl.png";
        fHideDisplayDiv('Info_Panel');
    } else {
        $("Info_Panel_Toggle").src = "http://16.yaychat.com/collapse-bl.png";
        fShowDisplayDiv('Info_Panel');
    }
}

function fWallReply(intReplyToCommentNumber, strToNickname) {
    var msg;
    msg = $('EF_Wall_Message_' + intReplyToCommentNumber).value;
    for (i = 1; i<10; i++) {
        msg = msg.replace('¿', '&iquest;').replace('£', '&pound;').replace('¥', '&yen;').replace('¤', '&curren;').replace('¢', '&cent;').replace('ª', '&ordf;').replace('º', '&ordm;').replace('¦', '&brvbar;').replace('©', '&copy;').replace('®', '&reg;').replace('µ', '&micro;').replace('·', '&middot;').replace('°', '&deg;').replace('±', '&plusmn;').replace('×', '&times;').replace('÷', '&divide;').replace('¼', '&frac14;').replace('½', '&frac12;').replace('¾', '&frac34;').replace('¹', '&sup1;').replace('²', '&sup2;').replace('³', '&sup3;').replace('´', '&acute;').replace('¨', '&uml;').replace('¯', '&macr;').replace('¸', '&cedil').replace('À', '&Agrave;').replace('Á', '&Aacute;').replace('Â', '&Acirc;').replace('Ã', '&Atilde;').replace('Ä', '&Auml;').replace('Å', '&Aring;').replace('Æ', '&AElig;').replace('Ç', '&Ccedil;').replace('È', '&Egrave;').replace('É', '&Eacute;').replace('Ê', '&Ecirc;').replace('Ë', '&Euml;').replace('Ì', '&Igrave;').replace('Í', '&Iacute;').replace('Î', '&Icirc;').replace('Ï', '&Iuml;').replace('Ð', '&ETH;').replace('Ñ', '&Ntilde;').replace('Ò', '&Ograve;').replace('Ó', '&Oacute;').replace('Ô', '&Ocirc;').replace('Õ', '&Otilde;').replace('Ö', '&Ouml;').replace('Ø', '&Oslash;').replace('Ù', '&Ugrave;').replace('Ú', '&Uacute;').replace('Û', '&Ucirc;').replace('Ü', '&Uuml;').replace('Ý', '&Yacute;').replace('Þ', '&THORN;').replace('ß', '&szlig;').replace('à', '&agrave;').replace('á', '&aacute;').replace('â', '&acirc;').replace('ã', '&atilde;').replace('ä', '&auml;').replace('å', '&aring;').replace('æ', '&aelig;').replace('ç', '&ccedil;').replace('è', '&egrave;').replace('é', '&eacute;').replace('ê', '&ecirc;').replace('ë', '&euml;').replace('ì', '&igrave;').replace('í', '&iacute;').replace('î', '&icirc;').replace('ï', '&iuml;').replace('ð', '&eth;').replace('ñ', '&ntilde;').replace('ò', '&ograve;').replace('ó', '&oacute;').replace('ô', '&ocirc;').replace('õ', '&otilde;').replace('ö', '&ouml;').replace('ø', '&oslash;').replace('ù', '&ugrave;').replace('ú', '&uacute;').replace('û', '&ucirc;').replace('ü', '&uuml;').replace('ý', '&yacute;').replace('þ', '&thorn;').replace('ÿ', '&yuml;').replace('§', '&sect;').replace('¶', '&para;').replace('«', '&laquo;').replace('»', '&raquo;').replace('¡', '&iexcl;');
    }
    document.getElementById('EF_Wall_Reply_Area_' + intReplyToCommentNumber).innerHTML = '<img src=/i/roll-div.gif class=i16 />';
    req2Busy = 'N';
    GetDiv("Get-Wall-Replies", "To=" + strToNickname + "&Number=" + intReplyToCommentNumber + "&Message=" + escape(msg.replace('+', '---YAYplus---')) + "&", "", "Wall_Replies_" + intReplyToCommentNumber);
}

function CommentFromChat(strToNickname, msg) {
    var bug = new Image();
    var d = new Date();

    for (i = 1; i < 10; i++) {
        msg = msg.replace('¿', '&iquest;').replace('£', '&pound;').replace('¥', '&yen;').replace('¤', '&curren;').replace('¢', '&cent;').replace('ª', '&ordf;').replace('º', '&ordm;').replace('¦', '&brvbar;').replace('©', '&copy;').replace('®', '&reg;').replace('µ', '&micro;').replace('·', '&middot;').replace('°', '&deg;').replace('±', '&plusmn;').replace('×', '&times;').replace('÷', '&divide;').replace('¼', '&frac14;').replace('½', '&frac12;').replace('¾', '&frac34;').replace('¹', '&sup1;').replace('²', '&sup2;').replace('³', '&sup3;').replace('´', '&acute;').replace('¨', '&uml;').replace('¯', '&macr;').replace('¸', '&cedil').replace('À', '&Agrave;').replace('Á', '&Aacute;').replace('Â', '&Acirc;').replace('Ã', '&Atilde;').replace('Ä', '&Auml;').replace('Å', '&Aring;').replace('Æ', '&AElig;').replace('Ç', '&Ccedil;').replace('È', '&Egrave;').replace('É', '&Eacute;').replace('Ê', '&Ecirc;').replace('Ë', '&Euml;').replace('Ì', '&Igrave;').replace('Í', '&Iacute;').replace('Î', '&Icirc;').replace('Ï', '&Iuml;').replace('Ð', '&ETH;').replace('Ñ', '&Ntilde;').replace('Ò', '&Ograve;').replace('Ó', '&Oacute;').replace('Ô', '&Ocirc;').replace('Õ', '&Otilde;').replace('Ö', '&Ouml;').replace('Ø', '&Oslash;').replace('Ù', '&Ugrave;').replace('Ú', '&Uacute;').replace('Û', '&Ucirc;').replace('Ü', '&Uuml;').replace('Ý', '&Yacute;').replace('Þ', '&THORN;').replace('ß', '&szlig;').replace('à', '&agrave;').replace('á', '&aacute;').replace('â', '&acirc;').replace('ã', '&atilde;').replace('ä', '&auml;').replace('å', '&aring;').replace('æ', '&aelig;').replace('ç', '&ccedil;').replace('è', '&egrave;').replace('é', '&eacute;').replace('ê', '&ecirc;').replace('ë', '&euml;').replace('ì', '&igrave;').replace('í', '&iacute;').replace('î', '&icirc;').replace('ï', '&iuml;').replace('ð', '&eth;').replace('ñ', '&ntilde;').replace('ò', '&ograve;').replace('ó', '&oacute;').replace('ô', '&ocirc;').replace('õ', '&otilde;').replace('ö', '&ouml;').replace('ø', '&oslash;').replace('ù', '&ugrave;').replace('ú', '&uacute;').replace('û', '&ucirc;').replace('ü', '&uuml;').replace('ý', '&yacute;').replace('þ', '&thorn;').replace('ÿ', '&yuml;').replace('§', '&sect;').replace('¶', '&para;').replace('«', '&laquo;').replace('»', '&raquo;').replace('¡', '&iexcl;');
    }

    bug.src = "/1/a/Save-Comment-From-Chat.aspx?Nickname=" + strToNickname  + "&Comment=" + msg + "&t=" + d.getTime();
}


function fVideo(strVideo, strTitle, strSubtitle, strDescription) {
    fShowDisplayDiv('Video');
    $('Video').innerHTML = "<table class=hand width=100% style=height:100% cellpadding=0 cellspacing=0><tr><td style=text-align:center;vertical-align:middle><object width=480 height=295><param name=movie value=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0></param><param name=allowFullScreen value=true></param><param name=allowscriptaccess value=always></param><param name=wmode value=transparent></param><embed src=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0 type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true wmode=transparent width=480 height=295></embed></object></td></tr></table>";
}
function fVideoClose() {
    $('Video').innerHTML = "";
    hideddrivetip();
    fHideDisplayDiv('Video');
}

var win;
function fVideo2(strVideo) {
    var bug = new Image();
    var date = new Date();
    //    fShowDisplayDiv('Video2');
    //<object width=480 height=295><param name=movie value=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0></param><param name=allowFullScreen value=true></param><param name=allowscriptaccess value=always></param><param name=wmode value=transparent></param><embed src=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0 type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true wmode=transparent width=480 height=295></embed></object></td></tr></table>";

    //win = window.open("/bl.png", "Video", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=480,height=295');
    win = window.open("http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0&iv_load_policy=3", "Video", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=480,height=295');
    win.focus();

    bug.src = "/1/a/Update-Video.aspx?Video=" + strVideo + "&t=" + date.getTime();
}
var gamewinpoker;
function fGamePoker() {
    //var bug = new Image();
    //var date = new Date();

    try {
        gamewinpoker.focus();
    } catch (err) {
        //gamewin = window.open("/1/g/grid16.swf", "GamePoker", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=550,height=400');
        gamewinpoker = window.open("/app/poker/poker.aspx", "GamePoker", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=640,height=562');
        gamewinpoker.focus();
    }

    //bug.src = "/1/a/Update-Video.aspx?Video=" + strVideo + "&t=" + date.getTime();
}
var gamewinpool;
function fGamePool() {
    //var bug = new Image();
    //var date = new Date();

    try {
        gamewinpool.focus();
    } catch (err) {
        //gamewin = window.open("/1/g/grid16.swf", "GamePool", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=550,height=400');
        gamewinpool = window.open("/app/pool/pool.aspx", "GamePool", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=850,height=550');
        gamewinpool.focus();
    }

    //bug.src = "/1/a/Update-Video.aspx?Video=" + strVideo + "&t=" + date.getTime();
}
var gamewinbejeweled;
function fGameBejeweled() {
    //var bug = new Image();
    //var date = new Date();

    try {
        gamewinbejeweled.focus();
    } catch (err) {
        //gamewin = window.open("/1/g/grid16.swf", "GamePool", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=550,height=400');
        gamewinbejeweled = window.open("/app/bejeweled/bejeweled.aspx", "GameBejeweled", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=550,height=400');
        gamewinbejeweled.focus();
    }

    //bug.src = "/1/a/Update-Video.aspx?Video=" + strVideo + "&t=" + date.getTime();
}
function fVideo3(strVideo) {
    var bug = new Image();
    var date = new Date();
    fShowDisplayDiv('Video3');
    //$("Video3Content").innerHTML = "<table cellpadding=0 cellspacing=0 width=480><tr><td style=text-align:right><a href=javascript:fVideo3Close()>close</a></td></tr><tr><td><object width=480 height=295><param name=movie value=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0></param><param name=allowFullScreen value=true></param><param name=allowscriptaccess value=always></param><param name=wmode value=transparent></param><embed src=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0 type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true wmode=transparent width=480 height=295></embed></object></td></tr></table>";
    $("Video3Content").innerHTML = "<table cellpadding=0 cellspacing=0 width=480><tr><td><object width=480 height=295><param name=movie value=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0></param><param name=allowFullScreen value=true></param><param name=allowscriptaccess value=always></param><param name=wmode value=transparent></param><embed src=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=0 type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true wmode=transparent width=480 height=295></embed></object></td></tr></table>";
    //$("Video3").style.left = '100px';
    //$("Video3").style.top = '145px';

    bug.src = "/1/a/Update-Video.aspx?Video=" + strVideo + "&t=" + date.getTime();
}
function fShowVideoWindow() {
    try {
        win.focus();
    } catch (err) {
        win = window.open("/bl.png", "Video", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=480,height=295');
        win = window.open("http://www.youtube.com/v/FUgM105uN4c&showinfo=0&rel=0&autoplay=1&fs=1&color1=0x000000&color2=0x000000&border=0&loop=1&iv_load_policy=3", "Video", 'status=no,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=480,height=295');
        // 0UZbHyPvMzc
        win.focus();
    }
}

function fVideo2UserUpdate(strVideo, strNickname) {
    var bug = new Image();
    var date = new Date();
    bug.src = "/1/a/Update-User-Video.aspx?Video=" + strVideo + "&Nickname=" + strNickname + "&t=" + date.getTime();
}

function fVideo2Close() {
    $('Video2Content').innerHTML = "";
    ht();
    fHideDisplayDiv('Video2');
}
function fVideo3Close() {
    $('Video3Content').innerHTML = "";
    ht();
    fHideDisplayDiv('Video3');
}


function fStream3(strStream) {
    var bug = new Image();
    var date = new Date();
    fShowDisplayDiv('Stream3');
    //$("Stream3Content").innerHTML = "<table cellpadding=0 cellspacing=0 width=563><tr><td><object width=563 height=266><param name=movie value=http://www.ustream.tv/flash/irc.swf?channelId=825776&brandId=1&server=chat1.ustream.tv></param><param name=allowFullScreen value=true></param><param name=allowscriptaccess value=always></param><param name=wmode value=transparent></param><embed src=http://www.ustream.tv/flash/irc.swf?channelId=825776&brandId=1&server=chat1.ustream.tv type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true wmode=transparent width=563 height=266></embed></object></td></tr></table>";
    $("Stream3Content").innerHTML = "<iframe src=http://www.ustream.tv/channel-popup/"+strStream+" width=520 height=425 frameborder=0 marginwidth=0 marginheight=0 scrolling=no></iframe>"
}
function fStream3Close() {
    $('Stream3Content').innerHTML = "";
    ht();
    fHideDisplayDiv('Stream3');
}

function fShowVideoDetails(intShownProfileVideosCount, strYouTubeCode) {
    if ($("vid" + intShownProfileVideosCount).innerHTML == '') {
        fGetDiv("Show-Video-Details", "Video=" + strYouTubeCode + "&", "", "vid" + intShownProfileVideosCount);
    }
}

function fPhoto(strNickname, strPhoto, strTag) {
    try {
        fShowDisplayDiv('Photo');
        fGetDiv("Show-Profile-Photo", "Nickname=" + strNickname + "&Photo=" + strPhoto + "&Tag=" + strTag + "&", "", "Photo");
    } catch (err) {
        alert(err);
    }
}
function fPhotoClose() {
    fHideDisplayDiv('Photo');
}
function fPhotoClick(event) {
    pos_x = event.offsetX ? (event.offsetX) : event.pageX - $("Photo_Border").offsetLeft;
    pos_y = event.offsetY ? (event.offsetY) : event.pageY - $("Photo_Border").offsetTop;
    //alert(pos_x + ", " + pos_y);
    //FF adds 10,10 for the border
} 

function fLiveNavFeatured() { // ---
    fGetDiv("Live-Nav-Featured", "", "", "Live_Nav_Featured");
}
function fLiveNavActive1() { // ---
    fGetDiv("Live-Nav-Active-1", "", "", "Live_Nav_Active_1");
}

function fIM(strNickname, strRoomname) {
    var win;
    win = window.open('/IM/?To='+strNickname+'&Room='+strRoomname, strNickname+"_IM", 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=450,height=300');
    win.focus();
}
function fIMAccept(strCode) {
    var win;
    win = window.open('/IM/?Accept=' + strCode, strCode + "_IM", 'status=0,toolbar=0,location=0,menubar=0,directories=0,resizeable=1,scrollbars=0,width=450,height=300');
    win.focus();
}
function fIMDecline(strCode) {
    var bug = new Image();
    var date = new Date();
    bug.src = "/IM/Decline-IM.aspx?Code=" + strCode + "&t=" + date.getTime();
}
function fIMDisable() {
    var bug = new Image();
    var date = new Date();
    alert("IM requests are disabled now.")
    bug.src = "/IM/Disable-IMs.aspx?t=" + date.getTime();
}

