// Disclaimer
// disclaimer.js
// Ron Lau 2009
// Copyright Netcast Platform 2009
//
// Created       : 10/03/2009
// <script>

function initScpt()
{
    var tmp = document.createElement('script');
    tmp.type = 'text/javascript';
    tmp.src = '/netcast/ajaxfunc.js';
    //tmp.onload = function onload() { chkLogin(); };
    initScpt.interval = setInterval(function() { if(typeof getXMLHttpRequest != 'undefined') { clearInterval(initScpt.interval); chkLogin(); } }, 50);
    document.getElementsByTagName('head')[0].appendChild(tmp);
}

function chkLogin()
{
    realChkLogin.req = getXMLHttpRequest();
    if(realChkLogin.req)
        reqData(realChkLogin.req, '/userinfo.php', '', realChkLogin);
    else
        displayDisclaimer();
}

function realChkLogin()
{
    var req = realChkLogin.req;
    if(req === undefined)
        return;
    else
    {
        if(req.readyState == 4)
        {
            if(req.status == 200)
            {
                var resp = req.responseXML;
                var ele = resp.getElementsByTagName('userinfo')[0];
                ele = ele.getElementsByTagName('discuz_uid')[0];
                var uid = ele.firstChild.nodeValue;

                var exdate = new Date();
                exdate.setDate(exdate.getDate() + (uid > 0 ? 365 : -1));
                document.cookie = 'dcmr=' + (uid > 0 ? 'true' : 'false') +
                                  ';expires=' + exdate.toGMTString();
                displayDisclaimer();
            }

            realChkLogin.req = null;
            req = null;
        }
    }
}

function showDisclaimer()
{
    if(getCookie('dcmr') == 'true')
        return;
    initScpt();
}

function displayDisclaimer()
{
    if(getCookie('dcmr') == 'true')
        return;
    var tmp = document.createElement('div');
    tmp.id = 'dis_layer';
    tmp.style.width = '100%';
    tmp.style.height = '100%';
    //tmp.style.height = document.body.clientHeight + 'px';
    tmp.style.padding = '0px 10px 10px';
    tmp.style.zIndex = 1000;
    if(typeof tmp.style.filter != 'undefined')
    {
        tmp.style.filter = 'alpha(opacity=95)';
        tmp.style.backgroundColor = '#000000';
    }
    else
        tmp.style.backgroundColor = 'rgba(0,0,0,.85)';
    tmp.style.position = 'absolute';
    tmp.style.left = 0;
    tmp.style.top = 0;
    tmp.style.textAlign = 'center';

    var cont = document.createElement('div');
    if(typeof tmp.style.filter != 'undefined')
    {
        cont.style.filter = 'alpha(opacity=100)';
        cont.style.backgroundColor = '#FFFFFF';
    }
    else
        cont.style.backgroundColor = 'rgba(255,255,255,1)';
    cont.style.top = '0px'; // '1em';
    cont.style.margin = 'auto auto auto auto';
    cont.style.border = '1px solid #C0C0C0';
    cont.style.width = '900px';
    cont.style.backgroundImage = 'none';
    cont.style.position = 'relative';
    cont.style.verticalAlign = 'middle';
    cont.innerHTML = '<table width="100%" border="0" align="center"><tr><td align="center" valign="top" class="systemfont"><table width="100%" border="0" cellspacing="0" cellpadding="0"><tr><td align="center" valign="top"><img src="/images/imageposter.jpg" width="800" border="0"></td></tr></table><table width="450" align="center" border="0" cellspacing="0" cellpadding="0"><tr><td align="left" class="systemfont"><img src="/images/space5x5px.gif" width="5" height="5"><br><img src="/images/caution.gif" width="20" height="20" align="absmiddle"> 請注意，你即將進入 gayradio.hk，本網站及其節目部份內容可能令人不安。<br><img src="/images/space5x5px.gif" width="5" height="5"><br><a href="javascript:;" onclick="dismissDisclaimer()"><img src="/images/yes.gif" width="20" height="20" border="0" align="absmiddle"> 知悉並同意進入 gayradio.hk 請按這裡。</a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a target="_parent" href="http://home.disney.go.com/"><img src="/images/no.gif" width="20" height="20" border="0" align="absmiddle"> 不同意請按這裡離開。</a></td></tr></table><br><div align="center">若你已擁有 Gay Radio 賬戶並設定為自動登入，本訊息將不再顯示<br>Gay Radio Hong Kong</div><br></td></tr></table>';

    tmp.appendChild(cont);
    var bodytag = document.getElementsByTagName('body')[0];
    bodytag.appendChild(tmp);
    window.onresize = function onresize() { document.getElementById('dis_layer').style.height = document.body.clientHeight + 'px'; };
    showDisclaimer.ofState = (bodytag.style.overflow ? bodytag.style.overflow : 'auto');
    bodytag.style.overflow = 'hidden';
    resizeDisclaimer.tmr = setInterval("resizeDisclaimer()", 200);
    return;
}

function dismissDisclaimer()
{
    document.getElementById('dis_layer').style.display='none';
    document.cookie = 'dcmr=true';
    var bodytag = document.getElementsByTagName('body')[0];
    bodytag.onresize = null;
    //bodytag.height = "";
    bodytag.style.overflow = showDisclaimer.ofState;
}

function getCookie(name)
{
    var regex_str = new RegExp("(?:^|; )" + name + "=([^;]+)(?:$|;)");
    var res = document.cookie.match(regex_str);
    return (res == null ? null : res[1]);
}

function resizeDisclaimer()
{
    if(document.body.clientHeight)
    {
        //alert(document.body.clientHeight);
        var tmp = document.getElementById('dis_layer');
        tmp.style.height = document.body.clientHeight + 'px';
        if(resizeDisclaimer.lastVal == document.body.clientHeight && resizeDisclaimer.lastlastVal == document.body.clientHeight)
            clearInterval(resizeDisclaimer.tmr);
        else
        {
            resizeDisclaimer.lastlastVal = resizeDisclaimer.lastVal;
            resizeDisclaimer.lastVal = document.body.clientHeight;
        }
    }
    return;
    if(typeof(window.innerHeight) == 'number')
        tmp.style.height = window.innerHeight;
    else if(document.documentElement && document.documentElement.clientHeight)
        tmp.style.height = document.documentElement.clientHeight;
    else if(document.body && document.body.clientHeight)
        tmp.style.height = document.body.clientHeight;
}

// </script>

