var sns_js_pragma_once;
if (sns_js_pragma_once == null) {
sns_js_pragma_once = 0;


var _chatId = null;

function getchatId()
{
    if (_chatId == null) {
        _chatId = retrieveGetParameter("chatId");
        if (_chatId == null) {
            _chatId = Math.floor(Math.random() * 0x7FFFFFFF);
        }
    }
    return _chatId;
}

/* Sns-specific */

function getDisplayCode(needDisplay)
{
    return (needDisplay ? '' : 'none');
}

function setDisplayElement(elementName, disp) // {{{
{
    var element = document.getElementById(elementName);
    if (element == null) {
        return false;
    }
    try {
        element.style.display = disp;
    } catch (err) {
        alert(elementName + ": " + err.description + "\nTried to set display to \"" + disp + "\"");
        return false;
    }
    return true;
} // }}}

function setDisplayElementGroup(groupName, display) // {{{
{
    setDisplayElement(groupName, display);
    
    var i = 1;
    while (setDisplayElement((groupName + i), display)) {
        i++;
    }
} // }}}

function hideElement(elementId) // {{{
{
    return setDisplayElement(elementId, 'none');
} // }}}

function showElement(elementId) // {{{
{
    return setDisplayElement(elementId, '');
} // }}}

function hideElementGroup(groupName) // {{{
{
    setDisplayElementGroup(groupName, 'none');
} // }}}

function showElementGroup(groupName) // {{{
{
    setDisplayElementGroup(groupName, '');
} // }}}

/* Misc */

function getCookie(cookiename)
{
    var cookiestring = "" + document.cookie;
    var index1 = cookiestring.indexOf(cookiename + "=");
    if (index1 == -1) return "";
    var index2 = cookiestring.indexOf(';', index1);
    if (index2 == -1) index2 = cookiestring.length;
    return cookiestring.substring(index1 + cookiename.length + 1, index2);
}

function escapeForHtml(str) // {{{
{
    str = str.replace(/&/g, '&amp;');
    str = str.replace(/</g, '&lt;');
    str = str.replace(/>/g, '&gt;');
    str = str.replace(/\r\n/g, '<br>');
    str = str.replace(/\n/g, '<br>');
    return str;
} // }}}

function getEmailRegex()
{
    return /[^\s,:]+@[^\s,:]{2,}[^\s,:.]/;
}

function getUrlRegex()
{
    return /(((((H|h)(T|t)|(F|f))(T|t)(P|p)((S|s)?))\:\/\/)?(www.|[a-zA-Z0-9].)[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,6}(\:[0-9]{1,5})*(\/($|[a-zA-Z0-9\.\,\;\?\'\\\+&%\$#\=~_\-]+))*)/;
}

function underlineLinks(html)
{
    var position = 0;
    var emailRegex = getEmailRegex();
    var urlRegex = getUrlRegex();

    var fReplaceOnce = function (string, search, replace, startIndex) {
        if (search.length == 0) return string;
        if (string.length == 0) return string;

        var index = string.indexOf(search, startIndex);
        if (index == -1) return string;
        if (index == 0) return replace + string.substring(index + search.length, string.length);

        return string.substring(0, index) + replace + string.substring(index + search.length, string.length);
    };

    var fDecorateUrl = function (url) {
        var linkText = url;
        if (url.indexOf('://') == -1) {
            url = 'http://' + url;
        }
        if (window.opener) {
            return '<a href="#" onclick="window.opener.open(\'' + url + '\',\'_blank\'); return true;">' + linkText + '</a>';
        } else {
            return '<a target="_blank" href="' + url + '">' + linkText + '</a>';
        }
    };

    var fDecorateEmail = function (email) {
        return '<a href="mailto:' + email + '">' + email + '</a>';
    };

    var fDecorate = function (range, substring, fDecorator) {
        var original = toTest.substring(range.index, range.lastIndex);
        var decorated = fDecorator(original);
        html = fReplaceOnce(html, original, decorated, position);
        position += range.index + decorated.length;
    };

    var fExecRegex = function (regex, string) {
        var range = regex.exec(string);
        if (range != null) {
            range.lastIndex = range.index + range[0].length;
        }

        return range;
    };

    while (position < html.length) {
        var toTest = html.substring(position, html.length);
        var emailRange = fExecRegex(emailRegex, toTest);
        var urlRange = fExecRegex(urlRegex, toTest);

        if (emailRange != null && urlRange != null) {
            if (urlRange.index >= emailRange.index) {
                fDecorate(emailRange, toTest, fDecorateEmail);
            } else {
                fDecorate(urlRange, toTest, fDecorateUrl);
            }
        } else if (emailRange != null) {
            fDecorate(emailRange, toTest, fDecorateEmail);
        } else if (urlRange != null) {
            fDecorate(urlRange, toTest, fDecorateUrl);
        } else {
            return html;
        }
    }

    return html;
}

function isEmail(string) // {{{
{
    return string.search(getEmailRegex()) != -1;
} // }}}

function openURL(url, width, height) // {{{
{
    var win = window.open(url, "_blank", "status=yes,toolbar=no,menubar=no,location=no,width=" + width + ",height=" + height);
    
    return (win != null);
} // }}}

function getIFrameDocument(ifrm) // {{{
{
    var doc;
    if (ifrm.contentDocument) {
        doc = ifrm.contentDocument;
    } else if (ifrm.contentWindow) {
        doc = ifrm.contentWindow.document;
    } else if (ifrm.document) {
        doc = ifrm.document;
    } else {
        alert('IFRAME document was not found');
    }

    return doc;
} // }}}

function getKeyCode(event) // {{{
{
    var keyCode;
    if (event) {
        keyCode = event.keyCode;
    } else if (window.event) {
        keyCode = window.event.keyCode;
    }
    return keyCode;
} // }}}

/* Browser detection */

function isReadyStateAvailable() // {{{
{
    var f = document.createElement("IMG");
    return f.readyState == "uninitialized";
} // }}}

function isAgentIE() // {{{
{
    return navigator.appName == "Microsoft Internet Explorer";
} // }}}

function isAgentOpera() // {{{
{
    return navigator.userAgent.indexOf("Opera") >= 0;
} // }}}

function isIE() // {{{
{
    return isAgentIE() && isReadyStateAvailable();
} // }}}

function isOpera() // {{{
{
    // By default Opera is running in IE6 emulation mode, we need to detect it
    return isAgentOpera() || (isAgentIE() && !isReadyStateAvailable());
} // }}}

function isNetscape() // {{{
{
    return navigator.userAgent.indexOf("Netscape") != -1;
} // }}}

function isFireFox() // {{{
{
    return navigator.userAgent.indexOf("Firefox") != -1;
} // }}}

function isMozilla() // {{{
{
    return !isAgentIE() && navigator.userAgent.indexOf("Mozilla") != -1;
} // }}}

function isGecko() // {{{
{
    return navigator.userAgent.indexOf("Gecko") != -1;
} // }}}

function isWindows32() // {{{
{
    return navigator.platform == 'Win32';
} // }}}

/* SCRIPT tag - related */
// Initialization {{{
var scriptUpdateIntervals;

if (scriptUpdateIntervals == null) {
    scriptUpdateIntervals = new Array();
    scriptUpdateURLs = new Array();
    scriptTagNames = new Array();
    abortUpdateScripts = new Array();
    scriptLastIndex = 0;
} // }}}

function retrieveGetParameter(paramName)
{
    var search = document.location.search;
    if (search == null || search == '') return null;
    if (search.charAt(0) == '?') search = search.substr(1);
    var params = search.split('&');
    for (var paramIndex in params) {
        var data = params[paramIndex].split('=');
        if (data[0] == paramName) return unescape(data[1]);
    }

    return null;
}

function appendUrlSeparationChar(url)
{
    var href = url;
    var lastChar = href.charAt(href.length - 1);
    var containsQ = href.indexOf('?') != -1;
    var containsA = href.indexOf('&') != -1;

    if (!containsQ) {
        href += '?';
    } else {
        if ((!containsA && lastChar != '?') ||
            (containsA && lastChar != '&')) {

            href += '&';
        }
    }

    return href;
}

function appendTemplateSetHint(url)
{
    var hint = retrieveGetParameter('tsh');
    if (hint == null) return url;
    return appendUrlSeparationChar(url) + 'tsh=' + hint;
}

function reportMessagesSent()
{
    var count = 0;
    while (count++ < 5) {
        try {
            window.parent.messagesSent();
            return true;
        } catch (err) {}
    }
    return false;
}

function openSkypeChat(skypeId)
{
    window.opener.openSkypeLink(skypeId);
}

function openSkypeLink(skypeId)
{
    window.location = 'skype:' + skypeId + '?call';
}

function centerWindow(wnd)
{
    if (wnd == null) wnd = window;

    var width = window.innerWidth == null
        ? window.document.body.clientWidth
        : window.innerWidth;

    var height = window.innerHeight == null
        ? window.document.body.clientHeight :
        window.innerHeight;

    var left = (screen.width - width) / 2;
    var top = (screen.height - height) / 2;

    wnd.moveTo(left, top);
}

function Is_Skype_Available()
{
    var cantDetect = ((navigator.userAgent.indexOf('Safari')  != -1) || (navigator.userAgent.indexOf('Opera')  != -1));

    if (cantDetect) return true;

    var activex = ((navigator.userAgent.indexOf('Win')  != -1) && (navigator.userAgent.indexOf('MSIE') != -1) && (parseInt(navigator.appVersion) >= 4 ));

    if (activex) {
        try {
            new ActiveXObject("Skype.Detection");
            return true;
        } catch (err) {
            return false;
        }
    } else {
        var skypeMime = navigator.mimeTypes["application/x-skype"];
        detected = true;
        return typeof(skypeMime) == "object";
    }
}
} // if (pragma_once == null) ends

