// last update at 2009-11-20 20:33:42
var _dc_mv = new Array();
var _dc_tv = new Array();
_dc_mv[0] = "http://movie.video.sina.com.cn/movie/jgdy/detail.html";
_dc_mv[1] = "http://movie.video.sina.com.cn/movie/yt/detail.html";
_dc_mv[2] = "http://movie.video.sina.com.cn/movie/cbx/detail.html";
_dc_mv[3] = "http://movie.video.sina.com.cn/movie/zb/detail.html";
_dc_tv[0] = "http://movie.video.sina.com.cn/teleplay/ch/detail.html";
_dc_tv[1] = "http://movie.video.sina.com.cn/teleplay/jf/detail.html";
_dc_tv[2] = "http://movie.video.sina.com.cn/teleplay/qf/detail.html";
_dc_tv[3] = "http://movie.video.sina.com.cn/teleplay/rjzhdshcs/detail.html";

// get_opsubject_id
function dc_video_get_opsubject_id() {
    // for rank
    var m = window.location.href.match(/.+\/o\.shtml(\?.*)?$/);
    if (m != undefined) {
        return "prevent";
    }

    // for rank
    m = window.location.href.match(/(http.+)\/[^\/]*\.s?html?/);
    if (m != undefined) {
        var r = _dc_mv.toString().indexOf(m[1]);
        if (r >= 0) {
            return "movie_home_movielist";
        }
        var r = _dc_tv.toString().indexOf(m[1]);
        if (r >= 0) {
            return "movie_home_tvlist";
        }
    }
    
    // normal
    var p = window.location.search.match(/opsubject_id=([^&]+)/);
    if (p != undefined) {
        return p[1];
    }
    return "";
}

// utility function called by _dc_video_get_cookie()
function _dc_video_get_cookie_val(offset)
{
    var endstr = document.cookie.indexOf(";", offset);
    if(endstr == -1)
    {
        endstr = document.cookie.length;
    }
    return unescape(document.cookie.substring(offset, endstr));
}

// primary function to retrieve cookie by name
function _dc_video_get_cookie(name)
{
    var arg = name + "=";
    var alen = arg.length;
    var clen = document.cookie.length;
    var i = 0;
    while(i < clen)
    {
        var j = i + alen;
        if (document.cookie.substring(i, j) == arg)
        {
            return _dc_video_get_cookie_val(j);
        }
        i = document.cookie.indexOf(" ", i) + 1;
        if(i == 0) break;
    }
    return "";
}

// get_user_id
function dc_video_get_user_id() {
    if (arguments.length >= 1) {
        if (arguments[0] == '1') {
            var s = _dc_video_get_cookie('SUP');
            if (s == "") {
                return "";
            }
            var p = s.match(/uid=([^&]+)/);
            if (p != undefined) {
                return p[1];
            }
            return "";
        }
    }
    return _dc_video_get_cookie('ADVERTISER_ID');
}

// get_channel_id
function dc_video_get_channe_id() {
    //var p = window.location.host.match(/([^\.]+)\.sina\.com\.cn/);
    var p = window.location.pathname.match(/([^\/]+)\//);
    if (p != undefined) {
        return p[1];
    }
    return "";
}

// get_topic_id
function dc_video_get_topic_id() {
    // for category
    var p = window.location.href.match(/http:\/\/movie\.video\.sina\.com\.cn\/category\/([^\/]+)/);
    if (p != undefined) {
        return p[1];
    }
    
    // normal
    var metas = document.getElementsByTagName("meta");
    for (var i = 0; i < metas.length; i++) {
        if (metas[i].name == "topicName") {
            //return encodeURI(metas[i].content);
            return metas[i].content;
        }
    }
    return "";
}
