﻿var i16 = 'http://16.yaychat.com/';
var root = 'http://yaychat.com/';
var AJAXroot = 'http://yaychat.com/1/a/';
var AJAXroot10 = 'http://yaychat.com/1.0/1/';
var SOUNDroot = 'http://yaychat.com/1/s/';
var room = '';

function CommentLike(strCommentNumber) {
    var bug = new Image(); var d = new Date()
    bug.src = AJAXroot + 'Comment-Like.aspx?n=' + strCommentNumber + '&t=' + d.getTime();
    ShowDisplayDiv('CommentLike' + strCommentNumber);
}
function CommentDislike(strCommentNumber) {
    var bug = new Image(); var d = new Date()
    bug.src = AJAXroot + 'Comment-Dislike.aspx?n=' + strCommentNumber + '&t=' + d.getTime();
    ShowDisplayDiv('CommentDislike' + strCommentNumber);
}

function detectCommentLanguage(intCommentNumber) {
    var language = '';
    
    var text = '';
    try {
        text = $('CommentComment' + intCommentNumber).innerHTML;
    } catch (err) { };
    var intCommentNumber2 = intCommentNumber;
    var strShow = 'N';
    google.language.detect(text, function(result) {
        if (!result.error) {
            for (l in google.language.Languages) {
                if (google.language.Languages[l] == result.language) {
                    language = l;
                    break;
                }
            }
        } else {
            //language = result.error;
        }
        if (language == 'ENGLISH') { language = '' };
        if (language == 'DUTCH') { language = 'nl'; strShow = 'Y'; };
        if (language == 'GERMAN') { language = 'de'; strShow = 'Y'; };
        if (language == 'SPANISH') { language = 'es'; strShow = 'Y'; };
        if (language == 'ITALIAN') { language = 'it'; strShow = 'Y'; };
        if (language == 'FRENCH') { language = 'fr'; strShow = 'Y'; };
        if (language == 'TURKISH') { language = 'tr'; strShow = 'Y'; };

        if (strShow == 'Y') { $('CommentLanguage' + intCommentNumber2).innerHTML = '<img id=CommentFlag' + intCommentNumber2 + ' onclick=translateComment(\'' + language + '\',' + intCommentNumber2 + ') style=cursor:pointer;margin-right:5px src=http://f.yaychat.com/16/' + language + '.png class=i16 alt=Flag title=Translate />'; }
    });
}

function translateComment(language, intCommentNumber) {
    $('CommentFlag' + intCommentNumber).src = '/i/roll-div.gif';
    var strTranslation = '';

    var text;
    try {
        text = $('CommentComment' + intCommentNumber).innerHTML;
    } catch (err) { };

    //alert(text);

    google.language.translate(text, language, "en", function(result) {
        if (!result.error) {
            strTranslation = result.translation;
            $('CommentComment' + intCommentNumber).innerHTML = '<div style=\'background:#FFC\'><span class=bold><img src=http://f.yaychat.com/16/language-'+language+'.png class=i16 alt=Flag title=English />&nbsp;2&nbsp;<img style=margin-right:5px src=http://f.yaychat.com/16/us.png class=i16 alt=Flag title=English /></span> ' + strTranslation+'</div>';
            $('CommentFlag' + intCommentNumber).style.visibility = 'hidden';
            $('CommentFlag' + intCommentNumber).style.display = 'none';
        } else {
            //strTranslation = result.error;
        }
    });
}

function YErr(e) { var bug = new Image(); var d = new Date(); bug.src = AJAXroot + 'Send-Error.aspx?Error=' + escape(e) + '&t=' + d.getTime(); }
function YLoading(d) {try { $(d).innerHTML = '<div style="margin:5px;color:#CCC"><img src="/i/roll.gif" class="i16"> Loading ...</div>'; } catch (err) { }  }

// ===============================================================================================

// ajax div
var r; var rTarget; var rBusy = 'N';
function processR() {
    if (r.readyState == 4) {
        if (r.status == 200) {
            rBusy = 'N';
            if ($(rTarget) !== null) {
                if (rTarget == 'Broadcast' && r.responseText.indexOf('*broadcast*') != -1 && $(rTarget).innerHTML.indexOf('*broadcast*') == -1) { PlaySound('broadcast'); };
                if (rTarget == 'Broadcast' && r.responseText.indexOf('*fart*') != -1 && $(rTarget).innerHTML.indexOf('*fart*') == -1) { PlaySound('fart'); };
                if (rTarget == 'Broadcast' && r.responseText.indexOf('*gasps*') != -1 && $(rTarget).innerHTML.indexOf('*gasps*') == -1) { PlaySound('gasps'); };
                $(rTarget).innerHTML = r.responseText;
                try {$(rTarget).style.opacity = '1.0'; } catch (err) { };
                if (rTarget != 'Broadcast' && rTarget != 'Nav_Live_Active_Chats' && rTarget != 'Nav_Live_Featured_Chats' && rTarget != 'ChatScore') { p = new Effect.Highlight(rTarget); }
            }
            if ($('chat-input-roll') !== null) { $('chat-input-roll').src = '/b.png'; }
        } else { rBusy = 'N'; var status = r.statusText; var strErr = '1.0 processR() status: ' + status; YErr(strErr); }
    }
} // ??? exception handling
function GetDiv(strAJAXaspx, strAJAXparameters, strRoomname, strTarget) { // ??? exception handling
    if ($('chat-input-roll') !== null) { $('chat-input-roll').src = '/i/roll-div.gif'; }
    var d = new Date();
    var url = AJAXroot + strAJAXaspx + '.aspx?Roomname=' + strRoomname + '&' + strAJAXparameters + 't=' + d.getTime();

    if (rBusy == 'N') {
        try {$(strTarget).style.opacity = '0.5'; } catch (err) { };
        r = false;
        rTarget = strTarget;
        rBusy = 'Y';
        if (window.XMLHttpRequest && !(window.ActiveXObject)) {
            try { r = new XMLHttpRequest(); } catch (errR) { r = false; }
        } else if (window.ActiveXObject) {
        try { r = new ActiveXObject('Msxml2.XMLHTTP'); } catch (errR2) { try { r = new ActiveXObject('Microsoft.XMLHTTP'); } catch (errR3) { r = false; } }
        }
        if (r) { r.onreadystatechange = processR; r.open('GET', url, true); r.send(''); }
    }
}
function GetDiv10(strAJAXaspx, strAJAXparameters, strRoomname, strTarget) { // ??? exception handling
    if ($('chat-input-roll') !== null) { $('chat-input-roll').src = '/i/roll-div.gif'; }
    var d = new Date();
    var url = AJAXroot10 + strAJAXaspx + '.aspx?Roomname=' + strRoomname + '&' + strAJAXparameters + 't=' + d.getTime();

    if (rBusy == 'N') {
        r = false;
        rTarget = strTarget;
        rBusy = 'Y';
        if (window.XMLHttpRequest && !(window.ActiveXObject)) {
            try { r = new XMLHttpRequest(); } catch (errR) { r = false; }
        } else if (window.ActiveXObject) {
            try { r = new ActiveXObject('Msxml2.XMLHTTP'); } catch (errR2) { try { r = new ActiveXObject('Microsoft.XMLHTTP'); } catch (errR3) { r = false; } }
        }
        if (r) { r.onreadystatechange = processR; r.open('GET', url, true); r.send(''); }
    }
}

// ### UL START ### 
var rUL; var rULBusy = 'N';
function processRUL() {
    if (rUL.readyState == 4) {
        if (rUL.status == 200) {
            rULBusy = 'N';
            if (rUL.responseText !== '') {$('Userlist').innerHTML = rUL.responseText;}
            if ($('chat-input-roll') !== null) { $('chat-input-roll').src = '/b.png'; }
        } else {rULBusy = 'N'; var status = rUL.statusText; var strErr = '1.0 processRUL() status: ' + status;YErr(strErr);}
    }
}

function GetUserlist() {
    if($('chat-input-roll') !== null) {$('chat-input-roll').src = '/i/roll-ul.gif'; }
    var d = new Date();
    var url = "http://yaychat.com/1/a/Get-Userlist.aspx?Roomname=" + room + "&t=" + d.getTime();

    if (rULBusy == "N") {
        rUL = false;
        rULBusy = "Y";
        if (window.XMLHttpRequest && !(window.ActiveXObject)) {
            try { rUL = new XMLHttpRequest(); } catch (errR) { rUL = false; }
        } else if (window.ActiveXObject) {
            try { rUL = new ActiveXObject("Msxml2.XMLHTTP"); } catch (errR2) { try { rUL = new ActiveXObject("Microsoft.XMLHTTP"); } catch (errR3) { rUL = false; } }
        }
        if (rUL) { rUL.onreadystatechange = processRUL; rUL.open("GET", url, true); rUL.send(""); }
    }
}
function ULPhoto() {var bug = new Image(); var date = new Date();bug.src = "/1/a/Set-Userlist-Mode.aspx?Mode=Photo&t=" + date.getTime();GetUserlist();}
function ULFlag() {var bug = new Image(); var date = new Date();bug.src = "/1/a/Set-Userlist-Mode.aspx?Mode=Flag&t=" + date.getTime();GetUserlist();}
function ULGender() {var bug = new Image(); var date = new Date();bug.src = "/1/a/Set-Userlist-Mode.aspx?Mode=Gender&t=" + date.getTime();GetUserlist();}
function ULBrowser() {var bug = new Image();var date = new Date();bug.src = "/1/a/Set-Userlist-Mode.aspx?Mode=Browser&t=" + date.getTime(); GetUserlist();}
// ### UL END ###

// ajax nav ??? all 3 need exception handling
function NavLiveActive() { try { GetDiv('Nav-Live-Active-Chats', '', '', 'Nav_Live_Active_Chats');p = new Effect.Highlight('Nav_Live_Active_Chats', { startcolor: '#E0E1E3', endcolor: '#E6E7E9' }); } catch (e) {var strErr = '1.0 NavLiveActive() ' + e;YErr(strErr); } }
function NavLiveFeatured() { try { GetDiv('Nav-Live-Featured-Chats', '', '', 'Nav_Live_Featured_Chats');p = new Effect.Highlight('Nav_Live_Featured_Chats', { startcolor: '#E0E1E3', endcolor: '#E6E7E9' }); } catch (e) { var strErr = '1.0 NavLiveFeatured() ' + e;YErr(strErr); } }
function NavSet(strGroup, strOnOff) {var bug = new Image();var d = new Date();bug.src = AJAXroot + 'Nav-Set.aspx?Group=' + strGroup + '&On=' + strOnOff + '&t=' + d.getTime();}

// sound
var chatSound = 'Y';
function ToggleChatSound() {
    try { if (chatSound == 'Y') { $('Chat-Sound-Option').src = i16 + 'sound-off.png';chatSound = 'N'; } else { $('Chat-Sound-Option').src = i16 + 'sound-on.png';chatSound = 'Y'; }} catch (e) {YErr('ToggleChatSound()'); }}
function PlaySound(strMP3File) {try {
    //$('Chat-Sound-Option').style.background = '#CCC'; // ??? blink style for sound option on
    $('Chat-Sound-Option').highlight();
    if (chatSound == 'Y') {
        mysound.loadSound(SOUNDroot + strMP3File + '.mp3', true); mysound.start();
        $('ChatInputField').focus(); } // ??? focus on sound playing lost and regained
        //setTimeout('PlaySoundBackgroundClear()', 200)
        } catch (e) {YErr('PlaySound(' + strMP3File + ')'); }} // ??? blink style for sound option off timeout
    //function PlaySoundBackgroundClear() { try { $('Chat-Sound-Option').style.background = '' } catch (e) { YErr('PlaySoundBackgroundClear()') } } // ??? blink style for sound option off

// div
function ShowDiv(id) { try {$(id).style.visibility = 'visible'; } catch (e) {YErr('ShowDiv(' + id + ')'); } }
function HideDiv(id) { try {$(id).style.visibility = 'hidden'; } catch (e) {YErr('HideDiv(' + id + ')'); } }
function ShowDisplayDiv(id) { try { $(id).style.visibility = 'visible';$(id).style.display = 'block'; } catch (e) {YErr('ShowDisplayDiv(' + id + ')'); } }
function HideDisplayDiv(id) { try { $(id).style.visibility = 'hidden';$(id).style.display = 'none'; } catch (e) {YErr('HideDisplayDiv(' + id + ')'); } }

// profile tabs
function ProfileTabWall(n) {
    $('Profile-Tab-Wall').className = 'tab-on'; ShowDisplayDiv('Profile-Wall');
    $('Profile-Tab-Info').className = 'tab-off'; HideDisplayDiv('Profile-Info');
    //$('Profile-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Profile-Chat');
    $('Profile-Tab-Photos').className = 'tab-off'; HideDisplayDiv('Profile-Photos');
    $('Profile-Tab-Videos').className = 'tab-off'; HideDisplayDiv('Profile-Videos');
}
function ProfileTabInfo(n) {
    $('Profile-Tab-Wall').className = 'tab-off'; HideDisplayDiv('Profile-Wall');
    $('Profile-Tab-Info').className = 'tab-on'; ShowDisplayDiv('Profile-Info');
    //$('Profile-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Profile-Chat');
    $('Profile-Tab-Photos').className = 'tab-off'; HideDisplayDiv('Profile-Photos');
    $('Profile-Tab-Videos').className = 'tab-off'; HideDisplayDiv('Profile-Videos');
}
function ProfileTabChat(n) {
    $('Profile-Tab-Wall').className = 'tab-off'; HideDisplayDiv('Profile-Wall');
    $('Profile-Tab-Info').className = 'tab-off'; HideDisplayDiv('Profile-Info');
    //$('Profile-Tab-Chat').className = 'tab-on'; ShowDisplayDiv('Profile-Chat');
    $('Profile-Tab-Photos').className = 'tab-off'; HideDisplayDiv('Profile-Photos');
    $('Profile-Tab-Videos').className = 'tab-off'; HideDisplayDiv('Profile-Videos');
}
function ProfileTabPhotos(n) {
    $('Profile-Tab-Wall').className = 'tab-off'; HideDisplayDiv('Profile-Wall');
    $('Profile-Tab-Info').className = 'tab-off'; HideDisplayDiv('Profile-Info');
    //$('Profile-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Profile-Chat');
    $('Profile-Tab-Photos').className = 'tab-on'; ShowDisplayDiv('Profile-Photos');
    $('Profile-Tab-Videos').className = 'tab-off'; HideDisplayDiv('Profile-Videos');
    if ($('Profile-Photos').innerHTML === '') {$('Profile-Photos').innerHTML = '<div class=""loading""><img src="/i/roll.gif" class="icon-16" alt="Loading ..." title="Loading Photos ..." /> Loading Photos ...</div>';}
    GetDiv('Show-Profile-Photos', 'Nickname=' + n + '&', '', 'Profile-Photos');
}
function ProfileTabVideos(n) {
    $('Profile-Tab-Wall').className = 'tab-off'; HideDisplayDiv('Profile-Wall');
    $('Profile-Tab-Info').className = 'tab-off'; HideDisplayDiv('Profile-Info');
    //$('Profile-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Profile-Chat');
    $('Profile-Tab-Photos').className = 'tab-off'; HideDisplayDiv('Profile-Photos');
    $('Profile-Tab-Videos').className = 'tab-on'; ShowDisplayDiv('Profile-Videos');
    //if ($('Profile-Videos').innerHTML === '') {$('Profile-Videos').innerHTML = '<div class=""loading""><img src="http://yaychat.com/i/roll.gif" class="icon-16" alt="Loading ..." title="Loading Videos ..." /> Loading Videos ...</div>'; }
    //GetDiv('Show-Profile-Videos', 'Nickname=' + n + '&', '', 'Profile-Videos');
}
function Subscribe(n) {
    //$('ProfileFollowButton').style.background = '#F5F5F5';
    //$('ProfileFollowButton').style.color = '#CCC';
    $('ProfileFollowButton').innerHTML = 'Following '+n+' ...';
    var bug = new Image(); var d = new Date();
    bug.src = AJAXroot + 'Set-Subscription.aspx?to=' + n + '&subscribe=Y&t=' + d.getTime();
}
function Unsubscribe(n) {
    //$('ProfileFollowButton').style.background = '#FFC';
    $('ProfileFollowButton').innerHTML = 'You have stopped following '+n+'.';
    var bug = new Image(); var d = new Date();
    bug.src = AJAXroot + 'Set-Subscription.aspx?to=' + n + '&subscribe=N&t=' + d.getTime();
}
function BecomeChild(n) {
    $('ProfileChildButton').innerHTML = 'You Joined ' + n + ' ...';
    var bug = new Image(); var d = new Date();
    bug.src = AJAXroot + 'Set-Parent.aspx?to=' + n + '&t=' + d.getTime();
}

// home tabs
function HomeTabHome() {
    $('Home-Tab-Home').className = 'tab-on'; ShowDisplayDiv('Home-Home');
    $('Home-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Home-Chat');
    $('Home-Tab-Live').className = 'tab-off'; HideDisplayDiv('Home-Live');
    try { $('Home-Tab-Me').className = 'tab-off'; HideDisplayDiv('Home-Me'); } catch (ex) { }
    $('Home-Tab-News').className = 'tab-off'; HideDisplayDiv('Home-News');
    $('Home-Tab-About').className = 'tab-off'; HideDisplayDiv('Home-About');
}
function HomeTabChat() {
    $('Home-Tab-Home').className = 'tab-off'; HideDisplayDiv('Home-Home');
    $('Home-Tab-Chat').className = 'tab-on'; ShowDisplayDiv('Home-Chat');
    $('Home-Tab-Live').className = 'tab-off'; HideDisplayDiv('Home-Live');
    try { $('Home-Tab-Me').className = 'tab-off'; HideDisplayDiv('Home-Me'); } catch (ex) { }
    $('Home-Tab-News').className = 'tab-off'; HideDisplayDiv('Home-News');
    $('Home-Tab-About').className = 'tab-off'; HideDisplayDiv('Home-About');
}
function HomeTabLive() {
    $('Home-Tab-Home').className = 'tab-off'; HideDisplayDiv('Home-Home');
    $('Home-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Home-Chat');
    $('Home-Tab-Live').className = 'tab-on'; ShowDisplayDiv('Home-Live');StartUpDatingLive();
    try { $('Home-Tab-Me').className = 'tab-off'; HideDisplayDiv('Home-Me'); } catch (ex) { }
    $('Home-Tab-News').className = 'tab-off'; HideDisplayDiv('Home-News');
    $('Home-Tab-About').className = 'tab-off'; HideDisplayDiv('Home-About');
}
function HomeTabMe() {
    $('Home-Tab-Home').className = 'tab-off'; HideDisplayDiv('Home-Home');
    $('Home-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Home-Chat');
    $('Home-Tab-Live').className = 'tab-off'; HideDisplayDiv('Home-Live');
    try { $('Home-Tab-Me').className = 'tab-on'; HideDisplayDiv('Home-Me'); } catch (ex) { }
    $('Home-Tab-News').className = 'tab-off'; HideDisplayDiv('Home-News');
    $('Home-Tab-About').className = 'tab-off'; HideDisplayDiv('Home-About');
}
function HomeTabNews() {
    $('Home-Tab-Home').className = 'tab-off'; HideDisplayDiv('Home-Home');
    $('Home-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Home-Chat');
    $('Home-Tab-Live').className = 'tab-off'; HideDisplayDiv('Home-Live');
    try { $('Home-Tab-Me').className = 'tab-off'; HideDisplayDiv('Home-Me'); } catch (ex) {}
    $('Home-Tab-News').className = 'tab-on'; ShowDisplayDiv('Home-News');
    $('Home-Tab-About').className = 'tab-off'; HideDisplayDiv('Home-About');
}
function HomeTabAbout() {
    $('Home-Tab-Home').className = 'tab-off'; HideDisplayDiv('Home-Home');
    $('Home-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Home-Chat');
    $('Home-Tab-Live').className = 'tab-off'; HideDisplayDiv('Home-Live');
    try { $('Home-Tab-Me').className = 'tab-off'; HideDisplayDiv('Home-Me'); } catch (ex) { }
    $('Home-Tab-News').className = 'tab-off'; HideDisplayDiv('Home-News');
    $('Home-Tab-About').className = 'tab-on'; ShowDisplayDiv('Home-About');
}
var strUpdatingLiveAlready = 'N';
function StartUpDatingLive() {
    if (strUpdatingLiveAlready == 'N') {
        setInterval(function() { GetDiv('Get-Live', '', '', 'Live'); }, 60000);
        strUpdatingLiveAlready = 'Y';
    }
}

// help tabs
// home tabs
function HelpTabGeneral() {
    $('Help-Tab-General').className = 'tab-on'; ShowDisplayDiv('Help-General');
    $('Help-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Help-Chat');
    $('Help-Tab-Profiles').className = 'tab-off'; HideDisplayDiv('Help-Profiles');
    $('Help-Tab-Settings').className = 'tab-off'; HideDisplayDiv('Help-Settings');
    $('Help-Tab-Messages').className = 'tab-off'; HideDisplayDiv('Help-Messages');
    $('Help-Tab-Apps').className = 'tab-off'; HideDisplayDiv('Help-Apps');
}
function HelpTabChat() {
    $('Help-Tab-General').className = 'tab-off'; HideDisplayDiv('Help-General');
    $('Help-Tab-Chat').className = 'tab-on'; ShowDisplayDiv('Help-Chat');
    $('Help-Tab-Profiles').className = 'tab-off'; HideDisplayDiv('Help-Profiles');
    $('Help-Tab-Settings').className = 'tab-off'; HideDisplayDiv('Help-Settings');
    $('Help-Tab-Messages').className = 'tab-off'; HideDisplayDiv('Help-Messages');
    $('Help-Tab-Apps').className = 'tab-off'; HideDisplayDiv('Help-Apps');
}
function HelpTabProfiles() {
    $('Help-Tab-General').className = 'tab-off'; HideDisplayDiv('Help-General');
    $('Help-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Help-Chat');
    $('Help-Tab-Profiles').className = 'tab-on'; ShowDisplayDiv('Help-Profiles');
    $('Help-Tab-Settings').className = 'tab-off'; HideDisplayDiv('Help-Settings');
    $('Help-Tab-Messages').className = 'tab-off'; HideDisplayDiv('Help-Messages');
    $('Help-Tab-Apps').className = 'tab-off'; HideDisplayDiv('Help-Apps');
}
function HelpTabSettings() {
    $('Help-Tab-General').className = 'tab-off'; HideDisplayDiv('Help-General');
    $('Help-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Help-Chat');
    $('Help-Tab-Profiles').className = 'tab-off'; HideDisplayDiv('Help-Profiles');
    $('Help-Tab-Settings').className = 'tab-on'; ShowDisplayDiv('Help-Settings');
    $('Help-Tab-Messages').className = 'tab-off'; HideDisplayDiv('Help-Messages');
    $('Help-Tab-Apps').className = 'tab-off'; HideDisplayDiv('Help-Apps');
}
function HelpTabMessages() {
    $('Help-Tab-General').className = 'tab-off'; HideDisplayDiv('Help-General');
    $('Help-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Help-Chat');
    $('Help-Tab-Profiles').className = 'tab-off'; HideDisplayDiv('Help-Profiles');
    $('Help-Tab-Settings').className = 'tab-off'; HideDisplayDiv('Help-Settings');
    $('Help-Tab-Messages').className = 'tab-on'; ShowDisplayDiv('Help-Messages');
    $('Help-Tab-Apps').className = 'tab-off'; HideDisplayDiv('Help-Apps');
}
function HelpTabApps() {
    $('Help-Tab-General').className = 'tab-off'; HideDisplayDiv('Help-General');
    $('Help-Tab-Chat').className = 'tab-off'; HideDisplayDiv('Help-Chat');
    $('Help-Tab-Profiles').className = 'tab-off'; HideDisplayDiv('Help-Profiles');
    $('Help-Tab-Settings').className = 'tab-off'; HideDisplayDiv('Help-Settings');
    $('Help-Tab-Messages').className = 'tab-off'; HideDisplayDiv('Help-Messages');
    $('Help-Tab-Apps').className = 'tab-on'; ShowDisplayDiv('Help-Apps');
}

// wall
function SetWallTimespan(ts, n) {
    var bug = new Image(); var d = new Date(); bug.src = AJAXroot + 'Set-Wall-Timespan.aspx?ts=' + ts + '&t=' + d.getTime();
    $('Wall_Time_Span_Loading').style.visibility = 'visible'; //YLoading('Wall');
    GetDiv('Get-Wall', 'n=' + n + '&', '', 'Wall');
    }

// heartbeat
setInterval(function Pulse() {
    try { GetDiv("Get-Broadcast", "", "", "Broadcast"); } catch (e) { }
    if ($('invite') !== null) { $('invite').src = '/1/i/toolbar/invite-glow.png'; }
    setTimeout(function() { if ($('invite') !== null) { $('invite').src = '/1/i/toolbar/invite.png'; } }, 1000);
}, 30000);

// dialog
function ShowDialog(strTitle, strAJAX) { showDialog(strTitle, strAJAX); }
function showDialog(strTitle, strAJAX) {
    $('dialog').style.visibility = 'visible';
    $('dialog-title').innerHTML = strTitle;
    $('dialog-content').innerHTML = '<img src=/i/roll.gif class=i16 /> <a href=javascript:showDialog("'+strTitle+'","'+strAJAX+'") style="border:0px none;color:#CCC">Loading ...</a>';
    rBusy = 'N';
    GetDiv10(strAJAX, "", "", "dialog-content");
}
function ShowDialogParameter(strTitle, strAJAX, strParameter) { showDialogParameter(strTitle, strAJAX, strParameter); }
function showDialogParameter(strTitle, strAJAX, strParameter) {
    $('dialog').style.visibility = 'visible';
    $('dialog-title').innerHTML = strTitle;
    $('dialog-content').innerHTML = '<img src=/i/roll.gif class=i16 /> <a href=javascript:showDialog("' + strTitle + '","' + strAJAX + '") style="border:0px none;color:#CCC">Loading ...</a>';
    rBusy = 'N';
    GetDiv10(strAJAX, strParameter + "&", "", "dialog-content");
}
function HideDialog() { hideDialog(); }
function hideDialog() {
    $('dialog-title').innerHTML = '';
    $('dialog-content').innerHTML = '';
    $('dialog').style.visibility = 'hidden';
}
function showDialogTab(intTab) {
    for (i = 1; i < 20; i++) {
        try {
            if (i == intTab) {
                $('DialogTab' + i).className = 'tab-on'; ShowDisplayDiv('DialogDiv' + i);
            } else {
                $('DialogTab' + i).className = 'tab-off'; HideDisplayDiv('DialogDiv' + i);
            }
        } catch (err) {
            // tab doesnt exist (yet)
        }
    }
}

function showContentTab(intTab) {
    for (i = 1; i < 20; i++) {
        try {
            if (i == intTab) {
                $('ContentTab' + i).className = 'tab-on'; ShowDisplayDiv('ContentDiv' + i);
            } else {
                $('ContentTab' + i).className = 'tab-off'; HideDisplayDiv('ContentDiv' + i);
            }
        } catch (err) {
            // tab doesnt exist (yet)
        }
    }
}

// nav

var scroll = 'N';
var scrollDirection = '';
function ScrollNavDown() {
    scroll = 'Y';
    scrollDirection = 'down';
    setTimeout('ScrollNav()', 50);
}

function ScrollNavUp() {
    scroll = 'Y';
    scrollDirection = 'up';
    setTimeout('ScrollNav()', 50);
}

function ScrollNavStop() {
    scroll = 'N';
}

function ScrollNav() {
    if (scrollDirection == 'up' && scroll == 'Y') {
        if ($('nav').scrollTop > 0) {
            $('nav').scrollTop = $('nav').scrollTop-10
        }
        setTimeout('ScrollNav()', 50);
    }
    if (scrollDirection == 'down' && scroll == 'Y') {
            $('nav').scrollTop = $('nav').scrollTop + 10
        setTimeout('ScrollNav()', 50);
    }
}

// video

function KeepVideo(strYouTubeCode, strThisProfileNickname) {
    var bug = new Image(); var d = new Date();
    bug.src = "/1/a/Keep-Video.aspx?Video=" + strYouTubeCode + "&Nickname=" + strThisProfileNickname + "&t=" + d.getTime();
}

function VideoDock(strVideo) {
    var bug = new Image(); var d = new Date();
    ShowDisplayDiv('VideoDock');
    $("VideoDock").innerHTML = "<table cellpadding=0 cellspacing=0 width=240 style='border-top:1px solid #959799;margin-top:5px'><tr><td style=background:#DCDDDF><object width=240 height=205><param name=movie value=http://www.youtube.com/v/" + strVideo + "&rel=0&autoplay=1&fs=1&color1=0xE6E7E9&color2=0xE6E7E9&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=0xE6E7E9&color2=0xE6E7E9&border=0&loop=0 type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true wmode=transparent width=240 height=205></embed></object></td></tr><tr><td style=text-align:right;padding-right:5px><a class=small href='javascript:VideoDockClose()'>Close Video</a></td></tr></table>";

    bug.src = "/1/a/Update-Video.aspx?Video=" + strVideo + "&t=" + d.getTime();
}
function VimeoDock(strVideo) {
    var bug = new Image(); var d = new Date();
    ShowDisplayDiv('VideoDock');
    $("VideoDock").innerHTML = "<table cellpadding=0 cellspacing=0 width=240 style='border-top:1px solid #959799;margin-top:5px'><tr><td style=background:#DCDDDF><object width=240 height=185><param name=allowfullscreen value=true /><param name=allowscriptaccess value=always /><param name=movie value=http://vimeo.com/moogaloop.swf?clip_id=" + strVideo + "&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1&amp;autoplay=1&amp;hd_off=1 /><embed src=http://vimeo.com/moogaloop.swf?clip_id=" + strVideo + "&amp;server=vimeo.com&amp;show_title=1&amp;show_byline=1&amp;show_portrait=0&amp;color=&amp;fullscreen=1&amp;autoplay=1&amp;hd_off=1 type=application/x-shockwave-flash allowfullscreen=true allowscriptaccess=always width=240 height=185></embed></object></td></tr><tr><td><div style=text-align:right;width:240px><a style=display:inline target=_blank class=small href='http://vimeo.com/" + strVideo + "'>vimeo.com</a>&nbsp;·&nbsp;<a style=display:inline class=small href='javascript:VideoDockClose()'>Close Video</a>&nbsp;</div></td></tr></table>";
}
function VeohDock(strVideo) {
    var bug = new Image(); var d = new Date();
    ShowDisplayDiv('VideoDock');
    $("VideoDock").innerHTML = "<table cellpadding=0 cellspacing=0 width=240 style='border-top:1px solid #959799;margin-top:5px'><tr><td style=background:#DCDDDF><object width=240 height=205 id=veohFlashPlayer name=veohFlashPlayer><param name=movie value=http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.4.8.1006&permalinkId=" + strVideo + "&player=videodetailsembedded&videoAutoPlay=1&id=anonymous></param><param name=allowFullScreen value=true></param><param name=allowscriptaccess value=always></param><embed src=http://www.veoh.com/static/swf/webplayer/WebPlayer.swf?version=AFrontend.5.4.8.1006&permalinkId=" + strVideo + "&player=videodetailsembedded&videoAutoPlay=1&id=anonymous type=application/x-shockwave-flash allowscriptaccess=always allowfullscreen=true width=240 height=205 id=veohFlashPlayerEmbed name=veohFlashPlayerEmbed></embed></object></td></tr><tr><td><div style=text-align:right;width:240px><a style=display:inline target=_blank class=small href='http://www.veoh.com/browse/videos#watch%3D" + strVideo + "'>veoh.com</a>&nbsp;·&nbsp;<a style=display:inline class=small href='javascript:VideoDockClose()'>Close Video</a>&nbsp;</div></td></tr></table>";
}
function VideoDockClose() {
    var bug = new Image(); var d = new Date();
    $("VideoDock").innerHTML = "";
    HideDisplayDiv('VideoDock');
}

var intArtistsTagCount = 0;
function ShowHideTaggedArtists(strQ) {
    for (i=1; i <= intArtistsTagCount; i++) {
        if ($('TaggedArtistContent' + i).innerHTML.indexOf(strQ) > -1 ) {
            $('TaggedArtist' + i).style.visibility='visible';
            $('TaggedArtist' + i).style.display='block';
        } else {
            $('TaggedArtist' + i).style.visibility='hidden';
            $('TaggedArtist' + i).style.display='none';
        }
    }
}

var scrollTaggedArtists = 'N';
var scrollTaggedArtistsDirection = '';
function ScrollTaggedArtistsDown() {
    scrollTaggedArtists = 'Y';
    scrollTaggedArtistsDirection = 'down';
    setTimeout('ScrollTaggedArtists()', 30);
}

function ScrollTaggedArtistsUp() {
    scrollTaggedArtists = 'Y';
    scrollTaggedArtistsDirection = 'up';
    setTimeout('ScrollTaggedArtists()', 30);
}

function ScrollTaggedArtistsStop() {
    scrollTaggedArtists = 'N';
}

function ScrollTaggedArtists() {
    if (scrollTaggedArtistsDirection == 'up' && scrollTaggedArtists == 'Y') {
        if ($('TaggedArtistContainer').scrollTop > 0) {
            $('TaggedArtistContainer').scrollTop = $('TaggedArtistContainer').scrollTop - 2;
        }
        setTimeout('ScrollTaggedArtists()', 30);
    }
    if (scrollTaggedArtistsDirection == 'down' && scrollTaggedArtists == 'Y') {
        $('TaggedArtistContainer').scrollTop = $('TaggedArtistContainer').scrollTop + 2;
        setTimeout('ScrollTaggedArtists()', 30);
    }
}


// blocks

function Block(strNickname, strRoomname) {
    var bug = new Image();
    var d = new Date();
    if (confirm("Are you sure you want to block " + strNickname + "? You can unblock " + strNickname + " via the menu Chat > Unblock Peeps or by clicking the block/unblock icon again.")) {
        bug.src = "/1.0/1/Block.aspx?Nickname=" + strNickname + "&t=" + d.getTime();
        try {
            YLoading('Userlist');
            GetUserlist(strRoomname);
        } catch (err) { };
        alert(strNickname + " is blocked now.");
    }
}

function Unblock(strNickname, strRoomname) {
    var bug = new Image();
    var d = new Date();
    bug.src = "/1.0/1/Unblock.aspx?Nickname=" + strNickname + "&t=" + d.getTime();
    HideDisplayDiv(strNickname + "_Block");
    try {
        YLoading('Userlist');
        GetUserlist(strRoomname);
    } catch (err) { }
    alert(strNickname + " is unblocked now.");
}

// ===============================================================================================

function Init(r) {
    room = r;
    if ($('Userlist') !== null && room !== '') { GetUserlist(); }
    if ($('Userlist') !== null && room !== '') { setInterval(function() { GetUserlist(); }, 15100); }
    if ($('Nav_Live_Active_Chats')!== null){setInterval('NavLiveActive()', 30000);}
    if ($('Nav_Live_Featured_Chats')!== null){setInterval('NavLiveFeatured()', 31000);}
}

function UpdateChatScore() {
    GetDiv10('Chat-Score', '', '', 'ChatScore');
}

// *** prototype samples
// $(element1, element2).each(function(elem) { elem.style.background = '#f00' });

// === EXTERNAL FUNCTIONS ========================================================================

// Facebook Sharing
function fbs_click() { u = location.href; t = document.title; window.open('http://www.facebook.com/sharer.php?u=' + encodeURIComponent(u) + '&t=' + encodeURIComponent(t), 'sharer', 'toolbar=0,status=0,width=626,height=436'); return false; }

// scroll left-right
scrollStep = 1

timerLeft1 = ""
timerRight1 = ""
timerLeft2 = ""
timerRight2 = ""

function toLeft(id) {
    document.getElementById(id).scrollLeft = 0
}

function scrollDivLeft(id, timer) {
    if (document.getElementById(id).scrollLeft == document.getElementById(id).scrollWidth) { toLeft(id); }
    if (timer == 1) {
        clearTimeout(timerRight1);
    } else {
        clearTimeout(timerRight2);
    }
    document.getElementById(id).scrollLeft += scrollStep;
    if (timer == 1) {
        timerRight1 = setTimeout("scrollDivLeft('" + id + "', 1)", 40);
    } else {
        timerRight2 = setTimeout("scrollDivLeft('" + id + "', 2)", 40);
    }
}

function scrollDivRight(id, timer) {
    if (document.getElementById(id).scrollLeft == 0) { toRight(id); }
    if (timer == 1) {
        clearTimeout(timerLeft1);
    } else {
        clearTimeout(timerLeft2);
    }
    document.getElementById(id).scrollLeft -= scrollStep;
    if (timer == 1) {
        timerLeft1 = setTimeout("scrollDivRight('" + id + "', 1)", 40);
    } else {
        timerLeft2 = setTimeout("scrollDivRight('" + id + "', 2)", 40);
    }
}

function toRight(id) {
    document.getElementById(id).scrollLeft = document.getElementById(id).scrollWidth
}

function stopMe(timer) {
    if (timer == 1) {
        clearTimeout(timerRight1);
        clearTimeout(timerLeft1);
    } else {
        clearTimeout(timerRight2);
        clearTimeout(timerLeft2);
    }
}